浏览代码

fix collection linking

Sergiu 9 月之前
父节点
当前提交
236148ccc0

+ 24 - 5
03_blender/sd_blender/__init__.py

@@ -114,6 +114,8 @@ def append_objects(productInfo, index):
 
     # replace_switch_materials(shotInfo, productInfo["ActiveMaterials"])
 
+    link_collection_to_collection("01_Products", bpy.data.collections[collectionName])
+
 
 def append_active_layers(newCollectionName, product_info):
     utility_collections = ["MaterialLibrary", "Animation_Controller", "Animation_Rig"]
@@ -144,10 +146,10 @@ def append_active_layers(newCollectionName, product_info):
 
     # link appended colections to newCollection
     for collection in data_to.collections:
-        try:
-            bpy.context.scene.collection.children.link(collection)
-        except:
-            print(collection)
+        # try:
+        #     bpy.context.scene.collection.children.link(collection)
+        # except:
+        #     print(collection)
         link_collection_to_collection(newCollectionName, collection)
 
         # hide utility collections
@@ -223,9 +225,26 @@ def get_subcollection_names(collection):
     return subcollection_names
 
 
-# link collection to collection
 def link_collection_to_collection(parentCollectionName, childCollection):
 
+    if bpy.context.scene.collection.children:
+        parentCollection = bpy.context.scene.collection.children.get(
+            parentCollectionName
+        )
+        # Add it to the main collection
+
+        # childCollection = bpy.context.scene.collection.children.get(childCollection)
+
+        parentCollection.children.link(childCollection)
+        # if child collection is in scene collection unlink it
+        if bpy.context.scene.collection.children.get(childCollection.name):
+            bpy.context.scene.collection.children.unlink(childCollection)
+        # bpy.context.scene.collection.children.unlink(childCollection)
+
+
+# link collection to collection
+def link_collection_to_collection_old(parentCollectionName, childCollection):
+
     if bpy.context.scene.collection.children:
         parentCollection = bpy.context.scene.collection.children.get(
             parentCollectionName

二进制
03_blender/sd_blender/__pycache__/__init__.cpython-310.pyc


+ 2 - 2
03_blender/sd_blender/sample_scene/assets_database.json

@@ -6,7 +6,7 @@
     },
     {
         "id": "15a314a1-8ba1-4e0e-ad0c-f605b06f89f8",
-        "name": "LNG_AntiAging_Serum_MY2023",
-        "path": "sample_scene//Products//LNG_AntiAging_Serum_MY2023"
+        "name": "LNG_PerfectRenew_Serum_MY2023",
+        "path": "sample_scene//Products//LNG_PerfectRenew_Serum_MY2023"
     }
 ]