Browse Source

update scene info

Sergiu 10 months ago
parent
commit
8d16a6f55c

+ 61 - 0
03_blender/sd_blender/__init__.py

@@ -41,7 +41,12 @@ bl_info = {
 def load_scene():
     print("Loading Scene")
     # load scene data
+    # create parent collections
+    create_parent_collections("01_Products")
+    create_parent_collections("02_Elements")
+    create_parent_collections("03_Shapes")
     # append products
+
     # append elements
     # append shapes
     # set lighting
@@ -54,6 +59,61 @@ def append_objects():
     # set transforms
 
 
+def create_parent_collections(group_name: str):
+
+    if collection_exists(group_name):
+
+        remove_collection_and_objects(group_name)
+    else:
+        create_collection(group_name)
+
+
+def remove_collection_and_objects(collection_name):
+    oldObjects = list(bpy.data.collections[collection_name].all_objects)
+    for obj in oldObjects:
+        bpy.data.objects.remove(obj, do_unlink=True)
+
+    old_collection = bpy.data.collections[collection_name]
+    if old_collection is not None:
+        old_collection_names = get_subcollection_names(old_collection)
+    else:
+        print("Collection not found.")
+
+    # print line break
+    print("-----------------------------------------------------------------")
+    print(old_collection_names)
+    print("-----------------------------------------------------------------")
+    for old_collection_name in old_collection_names:
+        for collection in bpy.data.collections:
+            if collection.name == old_collection_name:
+                bpy.data.collections.remove(collection)
+
+    bpy.ops.outliner.orphans_purge(
+        do_local_ids=True, do_linked_ids=True, do_recursive=True
+    )
+
+
+def get_subcollection_names(collection):
+    subcollection_names = []
+
+    for child in collection.children:
+        subcollection_names.append(child.name)
+        subcollection_names.extend(get_subcollection_names(child))
+
+    return subcollection_names
+
+
+# function that checks if a collection exists
+def collection_exists(collection_name):
+    return collection_name in bpy.data.collections
+
+
+# function that creates a new collection and adds it to the scene
+def create_collection(collection_name):
+    new_collection = bpy.data.collections.new(collection_name)
+    bpy.context.scene.collection.children.link(new_collection)
+
+
 # -------------------------------------------------------------------
 # Operators
 # -------------------------------------------------------------------
@@ -103,6 +163,7 @@ class ZSSD_PT_Main(ZSSDPanel, bpy.types.Panel):
 # modify after making products
 blender_classes = [
     ZSSD_PT_Main,
+    ZSSD_OT_LoadScene,
 ]
 
 

BIN
03_blender/sd_blender/__pycache__/__init__.cpython-310.pyc


+ 212 - 0
03_blender/sd_blender/sample_scene/scene_info.json

@@ -0,0 +1,212 @@
+{
+    "scene": {
+        "objects": [
+            {
+                "name": "LNG SleepingMask",
+                "type": "group",
+                "group_type": "product",
+                "id": "",
+                "properties": {
+                    "transform": {
+                        "position": [
+                            0,
+                            0,
+                            0
+                        ],
+                        "rotation": [
+                            0,
+                            0,
+                            0
+                        ],
+                        "scale": [
+                            1,
+                            1,
+                            1
+                        ]
+                    },
+                    "visible": true
+                }
+            },
+            {
+                "name": "LNG SleepingMask 2",
+                "type": "group",
+                "group_type": "product",
+                "id": "",
+                "properties": {
+                    "transform": {
+                        "position": [
+                            0,
+                            0,
+                            0
+                        ],
+                        "rotation": [
+                            0,
+                            0,
+                            0
+                        ],
+                        "scale": [
+                            1,
+                            1,
+                            1
+                        ]
+                    },
+                    "visible": true
+                }
+            },
+            {
+                "name": "LNG Serum",
+                "type": "group",
+                "group_type": "product",
+                "id": "",
+                "properties": {
+                    "transform": {
+                        "position": [
+                            0,
+                            0,
+                            0
+                        ],
+                        "rotation": [
+                            0,
+                            0,
+                            0
+                        ],
+                        "scale": [
+                            1,
+                            1,
+                            1
+                        ]
+                    },
+                    "visible": true
+                }
+            },
+            {
+                "name": "Flower",
+                "type": "group",
+                "group_type": "asset",
+                "id": "",
+                "properties": {
+                    "transform": {
+                        "position": [
+                            0,
+                            0,
+                            0
+                        ],
+                        "rotation": [
+                            0,
+                            0,
+                            0
+                        ],
+                        "scale": [
+                            1,
+                            1,
+                            1
+                        ]
+                    },
+                    "visible": true
+                }
+            },
+            {
+                "name": "Cube",
+                "type": "group",
+                "group_type": "shape",
+                "id": "",
+                "properties": {
+                    "transform": {
+                        "position": [
+                            0,
+                            0,
+                            0
+                        ],
+                        "rotation": [
+                            0,
+                            0,
+                            0
+                        ],
+                        "scale": [
+                            1,
+                            1,
+                            1
+                        ]
+                    },
+                    "visible": true,
+                    "color": {
+                        "r": 0.5,
+                        "g": 0.5,
+                        "b": 0.5
+                    }
+                }
+            }
+        ],
+        "cameras": [
+            {
+                "name": "Camera",
+                "type": "camera",
+                "properties": {
+                    "transform": {
+                        "position": [
+                            0,
+                            0,
+                            0
+                        ],
+                        "rotation": [
+                            0,
+                            0,
+                            0
+                        ]
+                    },
+                    "lens": {
+                        "type": "perspective",
+                        "fov": 60,
+                        "near": 0.1,
+                        "far": 100
+                    },
+                    "active": true
+                }
+            },
+            {
+                "name": "Camera 2",
+                "type": "camera",
+                "properties": {
+                    "transform": {
+                        "position": [
+                            0,
+                            0,
+                            0
+                        ],
+                        "rotation": [
+                            0,
+                            0,
+                            0
+                        ]
+                    },
+                    "lens": {
+                        "type": "perspective",
+                        "fov": 60,
+                        "near": 0.1,
+                        "far": 100
+                    },
+                    "active": false
+                }
+            }
+        ],
+        "environment": {
+            "background": {
+                "type": "color",
+                "color": {
+                    "r": 0.5,
+                    "g": 0.5,
+                    "b": 0.5
+                }
+            },
+            "lighting": {
+                "type": "image",
+                "id": "",
+                "intensity": 1,
+                "rotation": 0,
+                "flip_horizontal": false,
+                "flip_vertical": false,
+                "visible": true
+            }
+        }
+    }
+}