Merge branch 'blender-v2.90-release' into master

This commit is contained in:
Campbell Barton 2020-08-05 11:31:31 +10:00
commit 7ec0ca45ac
4 changed files with 118 additions and 36 deletions

View File

@ -190,43 +190,45 @@ def append_particle_system(file_name, obnames=[], location=(0, 0, 0), link=False
def append_objects(file_name, obnames=[], location=(0, 0, 0), link=False, **kwargs):
'''append objects into scene individually'''
#simplified version of append
scene = bpy.context.scene
sel = utils.selection_get()
bpy.ops.object.select_all(action='DESELECT')
if kwargs.get('name'):
# by now used for appending into scene
scene = bpy.context.scene
sel = utils.selection_get()
bpy.ops.object.select_all(action='DESELECT')
path = file_name + "\\Collection\\"
object_name = kwargs.get('name')
fc = utils.get_fake_context(bpy.context, area_type='VIEW_3D')
bpy.ops.wm.append(fc,filename=object_name, directory=path)
path = file_name + "\\Collection\\"
object_name = kwargs.get('name')
fc = utils.get_fake_context(bpy.context, area_type='VIEW_3D')
bpy.ops.wm.append(fc, filename=object_name, directory=path)
return_obs = []
for ob in bpy.context.scene.objects:
if ob.select_get():
return_obs.append(ob)
if not ob.parent:
main_object = ob
ob.location = location
return_obs = []
for ob in bpy.context.scene.objects:
if ob.select_get():
return_obs.append(ob)
if not ob.parent:
main_object = ob
ob.location = location
if kwargs.get('rotation'):
main_object.rotation_euler = kwargs['rotation']
if kwargs.get('rotation'):
main_object.rotation_euler = kwargs['rotation']
if kwargs.get('parent') is not None:
main_object.parent = bpy.data.objects[kwargs['parent']]
main_object.matrix_world.translation = location
if kwargs.get('parent') is not None:
main_object.parent = bpy.data.objects[kwargs['parent']]
main_object.matrix_world.translation = location
bpy.ops.object.select_all(action='DESELECT')
utils.selection_set(sel)
return main_object, return_obs
bpy.ops.object.select_all(action='DESELECT')
utils.selection_set(sel)
return main_object, return_obs
#this is used for uploads:
with bpy.data.libraries.load(file_name, link=link, relative=True) as (data_from, data_to):
sobs = []
for col in data_from.collections:
if col == kwargs.get('name'):
for ob in col.objects:
if ob in obnames or obnames == []:
sobs.append(ob)
# for col in data_from.collections:
# if col == kwargs.get('name'):
for ob in data_from.objects:
if ob in obnames or obnames == []:
sobs.append(ob)
data_to.objects = sobs
# data_to.objects = data_from.objects#[name for name in data_from.objects if name.startswith("house")]
@ -260,6 +262,8 @@ def append_objects(file_name, obnames=[], location=(0, 0, 0), link=False, **kwar
for ob in hidden_objects:
ob.hide_viewport = True
print(return_obs)
print(main_object)
if kwargs.get('rotation') is not None:
main_object.rotation_euler = kwargs['rotation']

View File

@ -316,6 +316,18 @@ def append_asset(asset_data, **kwargs): # downloaders=[], location=None,
al = 'LINK'
else:
al = 'APPEND'
if asset_data['assetType'] == 'model':
source_parent = get_asset_in_scene(asset_data)
parent, new_obs = duplicate_asset(source=source_parent, **kwargs)
parent.location = kwargs['model_location']
parent.rotation_euler = kwargs['model_rotation']
# this is a case where asset is already in scene and should be duplicated instead.
# there is a big chance that the duplication wouldn't work perfectly(hidden or unselectable objects)
# so here we need to check and return if there was success
# also, if it was successful, no other operations are needed , basically all asset data is already ready from the original asset
if new_obs:
bpy.ops.wm.undo_push_context(message='add %s to scene' % asset_data['name'])
return
# first get conditions for append link
link = al == 'LINK'
@ -333,7 +345,7 @@ def append_asset(asset_data, **kwargs): # downloaders=[], location=None,
return
if link:
parent, newobs = append_link.link_collection(file_names[-1],
parent, new_obs = append_link.link_collection(file_names[-1],
location=downloader['location'],
rotation=downloader['rotation'],
link=link,
@ -342,7 +354,7 @@ def append_asset(asset_data, **kwargs): # downloaders=[], location=None,
else:
parent, newobs = append_link.append_objects(file_names[-1],
parent, new_obs = append_link.append_objects(file_names[-1],
location=downloader['location'],
rotation=downloader['rotation'],
link=link,
@ -356,21 +368,21 @@ def append_asset(asset_data, **kwargs): # downloaders=[], location=None,
elif kwargs.get('model_location') is not None:
if link:
parent, newobs = append_link.link_collection(file_names[-1],
parent, new_obs = append_link.link_collection(file_names[-1],
location=kwargs['model_location'],
rotation=kwargs['model_rotation'],
link=link,
name=asset_data['name'],
parent=kwargs.get('parent'))
else:
parent, newobs = append_link.append_objects(file_names[-1],
parent, new_obs = append_link.append_objects(file_names[-1],
location=kwargs['model_location'],
rotation=kwargs['model_rotation'],
link=link,
name=asset_data['name'],
parent=kwargs.get('parent'))
#scale Empty for assets, so they don't clutter the scene.
# scale Empty for assets, so they don't clutter the scene.
if parent.type == 'EMPTY' and link:
bmin = asset_data['bbox_min']
bmax = asset_data['bbox_max']
@ -733,6 +745,66 @@ def try_finished_append(asset_data, **kwargs): # location=None, material_target
return done
def get_asset_in_scene(asset_data):
'''tries to find an appended copy of particular asset and duplicate it - so it doesn't have to be appended again.'''
scene = bpy.context.scene
for ob in bpy.context.scene.objects:
ad1 = ob.get('asset_data')
if not ad1:
continue
if ad1.get('assetBaseId') == asset_data['assetBaseId']:
return ob
return None
def check_all_visible(obs):
'''checks all objects are visible, so they can be manipulated/copied.'''
for ob in obs:
if not ob.visible_get():
return False
return True
def check_selectible(obs):
'''checks if all objects can be selected and selects them if possible.
this isn't only select_hide, but all possible combinations of collections e.t.c. so hard to check otherwise.'''
for ob in obs:
ob.select_set(True)
if not ob.select_get():
return False
return True
def duplicate_asset(source, **kwargs):
'''Duplicate asset when it's already appended in the scene, so that blender's append doesn't create duplicated data.'''
# we need to save selection
sel = utils.selection_get()
bpy.ops.object.select_all(action='DESELECT')
# check visibility
obs = utils.get_hierarchy(source)
if not check_all_visible(obs):
return None
# check selectability and select in one run
if not check_selectible(obs):
return None
# duplicate the asset objects
bpy.ops.object.duplicate(linked=True)
nobs = bpy.context.selected_objects[:]
#get parent
for ob in nobs:
if ob.parent not in nobs:
parent = ob
break
# restore original selection
utils.selection_set(sel)
return parent , nobs
def asset_in_scene(asset_data):
'''checks if the asset is already in scene. If yes, modifies asset data so the asset can be reached again.'''
scene = bpy.context.scene
@ -746,10 +818,10 @@ def asset_in_scene(asset_data):
asset_data['file_name'] = ad['file_name']
asset_data['url'] = ad['url']
#browse all collections since linked collections can have same name.
# browse all collections since linked collections can have same name.
for c in bpy.data.collections:
if c.name == ad['name']:
#there can also be more linked collections with same name, we need to check id.
# there can also be more linked collections with same name, we need to check id.
if c.library and c.library.get('asset_data') and c.library['asset_data']['assetBaseId'] == id:
return 'LINKED'
return 'APPENDED'

View File

@ -349,6 +349,9 @@ class FastRateMenu(Operator):
('20', '20', ''),
('50', '50', ''),
('100', '100', ''),
('150', '100', ''),
('200', '100', ''),
('250', '100', ''),
],
default='0', update=update_ratings_work_hours_ui
)

View File

@ -1019,9 +1019,12 @@ def is_rating_possible():
# crawl parents to reach active asset. there could have been parenting so we need to find the first onw
ao_check = ao
while ad is None or (ad is None and ao_check.parent is not None):
s = bpy.context.scene
ad = ao_check.get('asset_data')
if ad is not None:
rated = bpy.context.scene['assets rated'].get(ad['assetBaseId'])
s['assets rated'] = s.get('assets rated',{})
rated = s['assets rated'].get(ad['assetBaseId'])
# originally hidden for already rated assets
return True, rated, ao_check, ad
elif ao_check.parent is not None: