diff --git a/portal/data_struct/light.py b/portal/data_struct/light.py index bbd4596..492ebd8 100644 --- a/portal/data_struct/light.py +++ b/portal/data_struct/light.py @@ -84,6 +84,7 @@ def _replace_light(self, existing_obj: Any) -> None: elif self.type == "SUN": pass elif self.type == "AREA": + light_data.shape = "RECTANGLE" light_data.size = self.size[0] light_data.size_y = self.size[1] light_data.use_custom_distance = True @@ -93,8 +94,8 @@ def _replace_light(self, existing_obj: Any) -> None: raise ValueError(f"Unsupported light type: {self.type}") def _create_new(self, layer_path: Optional[str] = None) -> None: - name = self.name if self.name else f"{self.object_name}_{type}" - light_data = bpy.data.lights.new(name, type) + name = self.name if self.name else f"{self.object_name}_{self.type}" + light_data = bpy.data.lights.new(name, self.type) light_data.color = self.rgb_color light_data.energy = self.energy if self.type == "SPOT": @@ -105,9 +106,11 @@ def _create_new(self, layer_path: Optional[str] = None) -> None: elif self.type == "SUN": pass elif self.type == "AREA": + light_data.shape = "RECTANGLE" light_data.size = self.size[0] light_data.size_y = self.size[1] + light_data.use_custom_distance = True light_data.cutoff_distance = self.distance else: raise ValueError(f"Unsupported light type: {self.type}") @@ -118,7 +121,6 @@ def _create_new(self, layer_path: Optional[str] = None) -> None: light_object.rotation_euler = self.rotation_euler if self.type == "AREA": light_object.rotation_euler = self.rotation_euler - light_object.use_cutoff_distance = True self._link_object_to_collection(light_object, layer_path) @@ -165,7 +167,7 @@ def from_dict(data: dict) -> "Light": energy: float = data.get("Intensity") pos: dict = data.get("Position") if not all([type, energy, pos]): - raise ValueError("Missing required light data") + raise ValueError(f"Missing required light data. Got: {data}") location = (pos["X"], pos["Y"], pos["Z"]) light._set_light_data(name, color, energy, type, location) diff --git a/portal/data_struct/material.py b/portal/data_struct/material.py index 018dceb..40bdfe8 100644 --- a/portal/data_struct/material.py +++ b/portal/data_struct/material.py @@ -1,6 +1,7 @@ import os import bpy +from bpy.types import Material as BlenderMaterial from .color import Color @@ -11,7 +12,7 @@ def __init__(self): self.name = None self.diffuse_color = None self.textures = [] - self.material = None + self.material:BlenderMaterial = None def set_data(self, diffuse_color, textures=[]): """Set the material data.""" @@ -83,7 +84,7 @@ def _set_diffuse_color(self): """Set the base color of the material.""" self.material.diffuse_color = Color.from_hex( self.diffuse_color - ).to_tuple(type='rgb',normalize=True) + ).to_tuple(type='rgba',normalize=True) def _apply_textures(self): """Apply textures to the material.""" diff --git a/portal/handlers/string_handler.py b/portal/handlers/string_handler.py index 8d5093e..008c297 100644 --- a/portal/handlers/string_handler.py +++ b/portal/handlers/string_handler.py @@ -2,9 +2,9 @@ from typing import Tuple from ..data_struct.camera import Camera +from ..data_struct.light import Light from ..data_struct.material import Material from ..data_struct.mesh import Mesh -from ..data_struct.light import Light from .custom_handler import CustomHandler @@ -29,11 +29,15 @@ def handle_string(payload, data_type, uuid, channel_name, handler_src): @staticmethod def _handle_light_data(payload): """Handle light data payload.""" - light_data = json.loads(payload) - if not light_data: - raise ValueError("Light data is empty.") - light = Light.from_dict(light_data) - light.create_or_replace("Light") + light_dict = json.loads(payload) + if not light_dict: + raise ValueError("Light dict is empty.") + light_datas = light_dict.get("Lights") + if not light_datas: + raise ValueError("Light dict does not contain `Lights` key.") + for i, light_data in enumerate(light_datas): + light = Light.from_dict(light_data) + light.create_or_replace(f"Light_{i}") @staticmethod def _handle_custom_data(payload, channel_name, uuid, handler_src): diff --git a/portal/utils/crypto.py b/portal/utils/crypto.py index bb704ec..47a7a5c 100644 --- a/portal/utils/crypto.py +++ b/portal/utils/crypto.py @@ -1,11 +1,16 @@ import ctypes +import os from ctypes import POINTER, c_size_t, c_ubyte, c_uint16 class Crc16: def __init__(self) -> None: + # get the full path of the DLL + root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + dll_path = os.path.abspath(os.path.join(root, "bin/crc16-ccitt.dll")) + # load the DLL - self.dll = ctypes.CDLL("portal/bin/crc16-ccitt.dll") + self.dll = ctypes.CDLL(dll_path) # initialize function prototype self.dll.crc_init.restype = c_uint16 @@ -18,7 +23,6 @@ def __init__(self) -> None: self.dll.crc_finalize.argtypes = [c_uint16] self.dll.crc_finalize.restype = c_uint16 - def compute_checksum(self, byte_array: bytes) -> int: # initialize the crc crc = self.dll.crc_init()