work
save startup blend for animation tab & whatnot
This commit is contained in:
@@ -299,7 +299,7 @@ def append_material(file_name, matname=None, link=False, fake_user=True):
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
bk_logger.error(f"{e} - failed to open the asset file")
|
||||
bk_logger.error("%s - failed to open the asset file", e)
|
||||
# we have to find the new material , due to possible name changes
|
||||
mat = None
|
||||
for m in bpy.data.materials:
|
||||
@@ -532,7 +532,7 @@ def append_particle_system(
|
||||
total_max_threshold = 2000000
|
||||
# emitting too many parent particles just kills blender now.
|
||||
|
||||
# this part tuned child count, we'll leave children to artists only.
|
||||
# this part tuned child count, we'll leave children to authors only.
|
||||
# if count > total_max_threshold:
|
||||
# ratio = round(count / total_max_threshold)
|
||||
#
|
||||
@@ -621,14 +621,18 @@ def append_objects(
|
||||
|
||||
return_obs = []
|
||||
to_hidden_collection = []
|
||||
hidden_objects = []
|
||||
appended_collection = None
|
||||
main_object = None
|
||||
# get first at least one parent for sure
|
||||
# first get at least one parent for sure
|
||||
for ob in bpy.context.scene.objects: # type: ignore[union-attr]
|
||||
if ob.select_get():
|
||||
if not ob.parent:
|
||||
main_object = ob
|
||||
ob.location = location
|
||||
if ob.select_get() and not ob.parent:
|
||||
main_object = ob
|
||||
ob.location = location
|
||||
if (
|
||||
ob.hide_viewport or ob.hide_render
|
||||
): # saved assets only retain hide render state
|
||||
hidden_objects.append(ob)
|
||||
# do once again to ensure hidden objects are hidden
|
||||
for ob in bpy.context.scene.objects: # type: ignore[union-attr]
|
||||
if ob.select_get():
|
||||
@@ -654,7 +658,7 @@ def append_objects(
|
||||
main_object.matrix_world.translation = location
|
||||
|
||||
# move objects that should be hidden to a sub collection
|
||||
if len(to_hidden_collection) > 0 and appended_collection is not None:
|
||||
if to_hidden_collection and appended_collection is not None:
|
||||
hidden_collections = []
|
||||
scene_collection = bpy.context.scene.collection # type: ignore[union-attr]
|
||||
for ob in to_hidden_collection:
|
||||
@@ -682,7 +686,7 @@ def append_objects(
|
||||
if hide_collection in hidden_collections:
|
||||
continue
|
||||
# All other collections are moved to be children of the model collection
|
||||
bk_logger.info(f"{hide_collection}, {appended_collection}")
|
||||
bk_logger.info("%s, %s", hide_collection, appended_collection)
|
||||
# If target collection is specified, move collections there instead
|
||||
if collection and bpy.data.collections.get(collection):
|
||||
utils.move_collection(
|
||||
@@ -707,6 +711,12 @@ def append_objects(
|
||||
if orig_active_collection:
|
||||
bpy.context.view_layer.active_layer_collection = orig_active_collection # type: ignore[union-attr]
|
||||
|
||||
if hidden_objects:
|
||||
# only unique objects
|
||||
hidden_objects = list(set(hidden_objects))
|
||||
for ob in hidden_objects:
|
||||
ob.hide_set(True)
|
||||
|
||||
utils.selection_set(sel)
|
||||
# let collection also store info that it was created by BlenderKit, for purging reasons
|
||||
|
||||
@@ -753,16 +763,18 @@ def append_objects(
|
||||
obj.select_set(True)
|
||||
# we need to unhide object so make_local op can use those too.
|
||||
if link == True:
|
||||
if obj.hide_viewport:
|
||||
if (
|
||||
obj.hide_viewport or obj.hide_render
|
||||
): # saved assets only retain hide render state
|
||||
hidden_objects.append(obj)
|
||||
obj.hide_viewport = False
|
||||
obj.hide_set(False)
|
||||
return_obs.append(obj)
|
||||
|
||||
# Only after all objects are in scene! Otherwise gets broken relationships
|
||||
if link == True:
|
||||
bpy.ops.object.make_local(type="SELECT_OBJECT")
|
||||
for ob in hidden_objects:
|
||||
ob.hide_viewport = True
|
||||
ob.hide_set(True)
|
||||
|
||||
if kwargs.get("rotation") is not None:
|
||||
main_object.rotation_euler = kwargs["rotation"] # type: ignore[union-attr]
|
||||
|
||||
Reference in New Issue
Block a user