|
@@ -179,9 +179,9 @@ def load_scene_data():
|
|
|
else:
|
|
|
scene_data = json.loads(bpy.context.scene.shot_info_ai)
|
|
|
|
|
|
- invert_scene_data = invert_id_name(scene_data)
|
|
|
+ # invert_scene_data = invert_id_name(scene_data)
|
|
|
|
|
|
- return invert_scene_data
|
|
|
+ return scene_data
|
|
|
|
|
|
|
|
|
def load_objects_data(scene_data, object_type: str):
|
|
@@ -192,10 +192,13 @@ def load_objects_data(scene_data, object_type: str):
|
|
|
if object["group_type"] == object_type:
|
|
|
# get additional object data by id and combine with object data
|
|
|
object_data = get_object_data_by_id(object["id"])
|
|
|
- # temporary fix
|
|
|
- # object_data = get_object_data_by_id(object["name"])
|
|
|
- object.update(object_data)
|
|
|
- objects_data.append(object)
|
|
|
+ if object_data:
|
|
|
+ # temporary fix
|
|
|
+ # object_data = get_object_data_by_id(object["name"])
|
|
|
+ object.update(object_data)
|
|
|
+ objects_data.append(object)
|
|
|
+ else:
|
|
|
+ print("Object not found in database", object["id"], object["name"])
|
|
|
return objects_data
|
|
|
|
|
|
# to be replaced with actual data
|
|
@@ -423,66 +426,56 @@ def create_cameras(scene_data):
|
|
|
else:
|
|
|
return
|
|
|
|
|
|
+ # Assuming `scene_data` and `collection` are already defined
|
|
|
+ for camera_data in scene_data["scene"]["cameras"]:
|
|
|
+ # Create a new camera object
|
|
|
+ bpy.ops.object.camera_add()
|
|
|
+
|
|
|
+ # Get the newly created camera
|
|
|
+ camera = bpy.context.object
|
|
|
+
|
|
|
+ # Set the camera's name
|
|
|
+ camera.name = camera_data["name"]
|
|
|
+
|
|
|
+ # Set the camera's position
|
|
|
+ position = camera_data["properties"]["transform"]["position"]
|
|
|
+ camera.location.x = position[0]
|
|
|
+ camera.location.y = -position[2]
|
|
|
+ camera.location.z = position[1]
|
|
|
+
|
|
|
+ # Set the camera's rotation
|
|
|
+ rotation = camera_data["properties"]["transform"]["rotation"]
|
|
|
+ rotation_euler = Euler(
|
|
|
+ (
|
|
|
+ math.radians(rotation[0]),
|
|
|
+ math.radians(rotation[2]),
|
|
|
+ math.radians(rotation[1]),
|
|
|
+ ),
|
|
|
+ "XYZ",
|
|
|
+ )
|
|
|
|
|
|
-# Assuming `scene_data` and `collection` are already defined
|
|
|
-for camera_data in scene_data["scene"]["cameras"]:
|
|
|
- # Create a new camera object
|
|
|
- bpy.ops.object.camera_add()
|
|
|
-
|
|
|
- # Get the newly created camera
|
|
|
- camera = bpy.context.object
|
|
|
-
|
|
|
- # Set the camera's name
|
|
|
- camera.name = camera_data["name"]
|
|
|
-
|
|
|
- # Set the camera's position
|
|
|
- position = camera_data["properties"]["transform"]["position"]
|
|
|
- camera.location.x = position[0]
|
|
|
- camera.location.y = -position[2]
|
|
|
- camera.location.z = position[1]
|
|
|
-
|
|
|
- # Set the camera's rotation
|
|
|
- rotation = camera_data["properties"]["transform"]["rotation"]
|
|
|
- local_rotation = Euler(
|
|
|
- (
|
|
|
- math.radians(rotation[0]),
|
|
|
- math.radians(rotation[1]),
|
|
|
- math.radians(rotation[2]),
|
|
|
- ),
|
|
|
- "XYZ",
|
|
|
- )
|
|
|
-
|
|
|
- # Apply the local rotation to the camera
|
|
|
- camera.rotation_euler = local_rotation
|
|
|
-
|
|
|
- # Update the camera's matrix_world to apply the local transformation
|
|
|
- camera.matrix_world = camera.matrix_basis
|
|
|
-
|
|
|
- # Calculate the global rotation
|
|
|
- global_rotation = camera.matrix_world.to_euler()
|
|
|
-
|
|
|
- # Set the camera's rotation to the global rotation
|
|
|
- camera.rotation_euler = global_rotation
|
|
|
-
|
|
|
- # Set the camera's lens properties
|
|
|
- lens = camera_data["properties"]["lens"]
|
|
|
- type_mapping = {
|
|
|
- "PERSPECTIVE": "PERSP",
|
|
|
- "ORTHOGRAPHIC": "ORTHO",
|
|
|
- "PANORAMIC": "PANO",
|
|
|
- }
|
|
|
- camera.data.type = type_mapping.get(lens["type"].upper(), "PERSP")
|
|
|
- camera.data.angle = math.radians(lens["fov"])
|
|
|
- camera.data.clip_start = lens["near"]
|
|
|
- camera.data.clip_end = lens["far"]
|
|
|
-
|
|
|
- # Add the camera to the 05_Cameras collection
|
|
|
- collection.objects.link(camera)
|
|
|
- bpy.context.scene.collection.objects.unlink(camera)
|
|
|
-
|
|
|
- # Set the camera as the active camera if "active" is true
|
|
|
- if camera_data["properties"]["active"]:
|
|
|
- bpy.context.scene.camera = camera
|
|
|
+ # Apply the local rotation to the camera
|
|
|
+ camera.rotation_euler = rotation_euler
|
|
|
+
|
|
|
+ # Set the camera's lens properties
|
|
|
+ lens = camera_data["properties"]["lens"]
|
|
|
+ type_mapping = {
|
|
|
+ "PERSPECTIVE": "PERSP",
|
|
|
+ "ORTHOGRAPHIC": "ORTHO",
|
|
|
+ "PANORAMIC": "PANO",
|
|
|
+ }
|
|
|
+ camera.data.type = type_mapping.get(lens["type"].upper(), "PERSP")
|
|
|
+ camera.data.angle = math.radians(lens["fov"])
|
|
|
+ camera.data.clip_start = lens["near"]
|
|
|
+ camera.data.clip_end = lens["far"]
|
|
|
+
|
|
|
+ # Add the camera to the 05_Cameras collection
|
|
|
+ collection.objects.link(camera)
|
|
|
+ bpy.context.scene.collection.objects.unlink(camera)
|
|
|
+
|
|
|
+ # Set the camera as the active camera if "active" is true
|
|
|
+ if camera_data["properties"]["active"]:
|
|
|
+ bpy.context.scene.camera = camera
|
|
|
|
|
|
|
|
|
def set_output_paths(base_path, project_name):
|