2024-02-19 14:28:35 +01:00
|
|
|
import typing as typ
|
|
|
|
|
2024-02-19 16:03:32 +01:00
|
|
|
import bpy
|
2024-02-19 14:28:35 +01:00
|
|
|
import pydantic as pyd
|
|
|
|
|
|
|
|
from .. import base
|
|
|
|
from ... import contracts
|
|
|
|
|
|
|
|
####################
|
|
|
|
# - Blender Socket
|
|
|
|
####################
|
|
|
|
class PhysicalAccelBLSocket(base.BLSocket):
|
|
|
|
socket_type = contracts.SocketType.PhysicalAccel
|
|
|
|
bl_label = "PhysicalAccel"
|
2024-02-19 16:03:32 +01:00
|
|
|
use_units = True
|
|
|
|
|
|
|
|
####################
|
|
|
|
# - Properties
|
|
|
|
####################
|
|
|
|
raw_value: bpy.props.FloatProperty(
|
|
|
|
name="Unitless Acceleration",
|
|
|
|
description="Represents the unitless part of the acceleration",
|
|
|
|
default=0.0,
|
|
|
|
precision=6,
|
|
|
|
)
|
|
|
|
|
|
|
|
####################
|
|
|
|
# - Socket UI
|
|
|
|
####################
|
|
|
|
def draw_label_row(self, label_col_row: bpy.types.UILayout, text: str) -> None:
|
|
|
|
label_col_row.label(text=text)
|
|
|
|
label_col_row.prop(self, "raw_unit", text="")
|
|
|
|
|
|
|
|
def draw_value(self, col: bpy.types.UILayout) -> None:
|
|
|
|
col_row = col.row(align=True)
|
|
|
|
col_row.prop(self, "raw_value", text="")
|
2024-02-19 14:28:35 +01:00
|
|
|
|
|
|
|
####################
|
|
|
|
# - Default Value
|
|
|
|
####################
|
|
|
|
@property
|
|
|
|
def default_value(self) -> None:
|
2024-02-19 16:03:32 +01:00
|
|
|
return self.raw_value * self.unit
|
2024-02-19 14:28:35 +01:00
|
|
|
|
|
|
|
@default_value.setter
|
|
|
|
def default_value(self, value: typ.Any) -> None:
|
2024-02-19 16:03:32 +01:00
|
|
|
self.raw_value = self.value_as_unit(value)
|
2024-02-19 14:28:35 +01:00
|
|
|
|
|
|
|
####################
|
|
|
|
# - Socket Configuration
|
|
|
|
####################
|
|
|
|
class PhysicalAccelSocketDef(pyd.BaseModel):
|
|
|
|
socket_type: contracts.SocketType = contracts.SocketType.PhysicalAccel
|
|
|
|
label: str
|
|
|
|
|
|
|
|
def init(self, bl_socket: PhysicalAccelBLSocket) -> None:
|
|
|
|
pass
|
|
|
|
|
|
|
|
####################
|
|
|
|
# - Blender Registration
|
|
|
|
####################
|
|
|
|
BL_REGISTER = [
|
|
|
|
PhysicalAccelBLSocket,
|
|
|
|
]
|