Browse Source

fix rotation for objects

Sergiu 8 months ago
parent
commit
d80d7c5ee2

+ 46 - 8
03_blender/sd_blender/__init__.py

@@ -295,19 +295,57 @@ def append_active_layers(newCollectionName, product_info, asset_data: AssetData)
                 #     "transform"
                 # ]["rotation"]
 
-                rotation_in_degrees = product_info["properties"]["transform"][
-                    "rotation"
-                ]
+                # set object rotation
+
+                # rotation_in_degrees = product_info["properties"]["transform"][
+                #     "rotation"
+                # ]
+
+                # rotation_in_degrees[0] = rotation_in_degrees[0] + 90
 
-                rotation_in_degrees[0] = rotation_in_degrees[0] + 90
+                # # set object rotation in euler from radians
+                # collection.objects[0].rotation_euler = (
+                #     math.radians(rotation_in_degrees[0]),
+                #     math.radians(rotation_in_degrees[2]),
+                #     math.radians(rotation_in_degrees[1]),
+                # )
+
+                rotation_data_euler = product_info["properties"]["transform"][
+                    "rotationEuler"
+                ]
 
-                # set object rotation in euler from radians
                 collection.objects[0].rotation_euler = (
-                    math.radians(rotation_in_degrees[0]),
-                    math.radians(rotation_in_degrees[2]),
-                    math.radians(rotation_in_degrees[1]),
+                    math.radians(
+                        rotation_data_euler[0]
+                    ),  # Add 90 degrees to the first element
+                    math.radians(rotation_data_euler[2]),
+                    math.radians(rotation_data_euler[1]),
                 )
 
+                # # set rotation using quaternion
+
+                # rotation_quat_data = product_info["properties"]["transform"]["rotation"]
+
+                # converted_quat = Quaternion(
+                #     [
+                #         rotation_quat_data[3],
+                #         rotation_quat_data[0],
+                #         rotation_quat_data[1],
+                #         rotation_quat_data[2],
+                #     ]
+                # )
+
+                # # Define the camera correction quaternion (from GLTF file)
+                # rotation_correction = Quaternion((2**0.5 / 2, 2**0.5 / 2, 0.0, 0.0))
+
+                # # Apply the camera correction to the converted quaternion
+                # corrected_quat = rotation_correction @ converted_quat
+
+                # # Apply the corrected quaternion to the camera's rotation
+                # collection.objects[0].rotation_mode = "QUATERNION"
+                # collection.objects[0].rotation_quaternion = rotation_correction
+
+                # set object scale
                 collection.objects[0].scale = product_info["properties"]["transform"][
                     "scale"
                 ]

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


+ 19 - 0
03_blender/sd_blender/decode_base64

@@ -0,0 +1,19 @@
+import base64
+
+
+def convert_base64_string_to_object(base64_string):
+    bytes = base64.b64decode(base64_string)
+    string = bytes.decode("ascii")
+    # return json.loads(string)
+    return string
+
+
+if __name__ == "__main__":
+    # Prompt the user for a base64 string
+    user_input = input("Enter a base64 encoded string: ")
+
+    # Call the function with the user's input
+    result = convert_base64_string_to_object(user_input)
+
+    # Print the result
+    print("Decoded string:", result)

+ 7 - 1
03_blender/sd_blender/sample_scene/assets_database.json

@@ -17,6 +17,12 @@
     "web_path": "https://www.laneige.com/SWS_TablesAndDisplay_CircularCover_0001.glb",
     "type": "asset"
   },
+  {
+    "id": "2",
+    "name": "SWS_TablesAndDisplay_RectangularPilon_0001",
+    "web_path": "https://www.laneige.com/BasicShapes_Cube_0001.glb",
+    "type": "asset"
+  },
   {
     "id": "15a314a1-8ba1-4e0e-ad0c-f605b06f89h2",
     "name": "BasicShapes_Cube_0001",
@@ -24,7 +30,7 @@
     "type": "shape"
   },
   {
-    "id": "Sphere",
+    "id": "15a314a1-8ba1-4e0e-ad0c-f605b06f89h3",
     "name": "BasicShapes_Sphere_0001",
     "web_path": "https://www.laneige.com/BasicShapes_Cube_0001.glb",
     "type": "shape"

+ 20 - 20
03_blender/sd_blender/sample_scene/scene_info.json

@@ -2,26 +2,26 @@
   "scene": {
     "objects": [
       {
-        "name": "LNG PerfectRenew",
+        "name": "LNG Sleeping Mask",
         "type": "group",
         "group_type": "product",
-        "id": "15a314a1-8ba1-4e0e-ad0c-f605b06f89f8",
+        "id": "f8761a95-c28a-47ec-9254-e76cc3b693c7",
         "properties": {
           "transform": {
             "position": [
               0,
               0,
-              0
+              0.519598166935061
             ],
             "rotation": [
               0,
+              0.12817129804363972,
               0,
-              0,
-              1
+              0.9917520447963839
             ],
             "rotationEuler": [
               0,
-              0,
+              14.72786275800494,
               0
             ],
             "scale": [
@@ -36,31 +36,31 @@
     ],
     "cameras": [
       {
-        "name": "Camera",
+        "name": "Camera 2",
         "type": "camera",
         "properties": {
           "transform": {
             "position": [
-              2.1541220170510824,
-              0.9446412195038136,
-              -2.5454586143216757
+              0.49552484017494647,
+              1.0530401961219118,
+              -4.070571190590582
             ],
             "rotation": [
-              -3.623,
-              0.942,
-              -1.29,
-              0.33
+              0,
+              1,
+              0,
+              6.123233995736766e-17
             ],
             "rotationEuler": [
-              180,
-              39.236164794715414,
-              180
+              -180,
+              7.016709298534876e-15,
+              -180
             ]
           },
           "lens": {
             "type": "perspective",
-            "fov": 38.58009243837747,
-            "focalLength": 50,
+            "fov": 53.13010235415598,
+            "focalLength": 35,
             "near": 0.1,
             "far": 100
           },
@@ -89,5 +89,5 @@
     }
   },
   "user_id": "1125441",
-  "project_id": "2eda9202-086f-4152-9f9a-cf01f78351ae"
+  "project_id": "8f365a77-8d80-47fa-8c3e-47c69717c192"
 }

+ 10 - 10
04_stable_diffusion/ai_scene_info.json

@@ -1,19 +1,19 @@
 {
+    "user_id": "1125441",
+    "project_id": "8f365a77-8d80-47fa-8c3e-47c69717c192",
+    "rendered_image_id": "",
     "ai_scene": {
         "workflow": "canvas_3d_to_img_standard_V1.json",
         "prompt": {
-            "positive_prompt": "placeholder text",
-            "negative_prompt": "placeholder text"
+            "positive_prompt": "product photo of a power tool, placed on a workbench in a construction site, surrounded by other tools and exuding excellence",
+            "negative_prompt": "Negative prompt text"
         },
         "settings": {
-            "checkpoint": "",
-            "sampler": "",
-            "cfg": 5,
-            "steps": 5
+            "checkpoint": "juggernautXL_juggXIByRundiffusion",
+            "sampler": "dpmpp_2m_karras",
+            "cfg": 7.9,
+            "steps": 20
         }
     },
-    "project_id": "15a314a1-8ba1-4e0e-ad0c-f605b06f89f8",
-    "user_id": "1125441",
-    "rendered_image_id": "00bb64d51647486392fabc361ec69b7d",
-    "image_id": "00bb64d516"
+    "image_id": "42f919046764448488c4239218c7a78e"
 }