Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sean1832 committed Oct 4, 2024
2 parents db0f989 + 714bde3 commit 417d794
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
10 changes: 6 additions & 4 deletions portal/data_struct/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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":
Expand All @@ -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}")
Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
5 changes: 3 additions & 2 deletions portal/data_struct/material.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

import bpy
from bpy.types import Material as BlenderMaterial

from .color import Color

Expand All @@ -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."""
Expand Down Expand Up @@ -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."""
Expand Down
16 changes: 10 additions & 6 deletions portal/handlers/string_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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):
Expand Down
8 changes: 6 additions & 2 deletions portal/utils/crypto.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 417d794

Please sign in to comment.