from typing import Any, Mapping from .vec import Vec2, VEC2_ZERO, Vec3, VEC3_ZERO, Vec4, VEC4_ZERO from .number import number class BoolToInt: @classmethod def INPUT_TYPES(cls) -> Mapping[str, Any]: return {"required": {"a": ("BOOL", {"default": False})}} RETURN_TYPES = ("INT",) FUNCTION = "op" CATEGORY = "math/conversion" def op(self, a: bool) -> tuple[int]: return (int(a),) class IntToBool: @classmethod def INPUT_TYPES(cls) -> Mapping[str, Any]: return {"required": {"a": ("INT", {"default": 0})}} RETURN_TYPES = ("BOOL",) FUNCTION = "op" CATEGORY = "math/conversion" def op(self, a: int) -> tuple[bool]: return (a != 0,) class FloatToInt: @classmethod def INPUT_TYPES(cls) -> Mapping[str, Any]: return {"required": {"a": ("FLOAT", {"default": 0.0})}} RETURN_TYPES = ("INT",) FUNCTION = "op" CATEGORY = "math/conversion" def op(self, a: float) -> tuple[int]: return (int(a),) class IntToFloat: @classmethod def INPUT_TYPES(cls) -> Mapping[str, Any]: return {"required": {"a": ("INT", {"default": 0})}} RETURN_TYPES = ("FLOAT",) FUNCTION = "op" CATEGORY = "math/conversion" def op(self, a: int) -> tuple[float]: return (float(a),) class IntToNumber: @classmethod def INPUT_TYPES(cls) -> Mapping[str, Any]: return {"required": {"a": ("INT", {"default": 0})}} RETURN_TYPES = ("NUMBER",) FUNCTION = "op" CATEGORY = "math/conversion" def op(self, a: int) -> tuple[number]: return (a,) class NumberToInt: @classmethod def INPUT_TYPES(cls) -> Mapping[str, Any]: return {"required": {"a": ("NUMBER", {"default": 0.0})}} RETURN_TYPES = ("INT",) FUNCTION = "op" CATEGORY = "math/conversion" def op(self, a: number) -> tuple[int]: return (int(a),) class FloatToNumber: @classmethod def INPUT_TYPES(cls) -> Mapping[str, Any]: return {"required": {"a": ("FLOAT", {"default": 0.0})}} RETURN_TYPES = ("NUMBER",) FUNCTION = "op" CATEGORY = "math/conversion" def op(self, a: float) -> tuple[number]: return (a,) class NumberToFloat: @classmethod def INPUT_TYPES(cls) -> Mapping[str, Any]: return {"required": {"a": ("NUMBER", {"default": 0.0})}} RETURN_TYPES = ("FLOAT",) FUNCTION = "op" CATEGORY = "math/conversion" def op(self, a: number) -> tuple[float]: return (float(a),) class ComposeVec2: @classmethod def INPUT_TYPES(cls) -> Mapping[str, Any]: return { "required": { "x": ("FLOAT", {"default": 0.0}), "y": ("FLOAT", {"default": 0.0}), } } RETURN_TYPES = ("VEC2",) FUNCTION = "op" CATEGORY = "math/conversion" def op(self, x: float, y: float) -> tuple[Vec2]: return ((x, y),) class FillVec2: @classmethod def INPUT_TYPES(cls) -> Mapping[str, Any]: return { "required": { "a": ("FLOAT", {"default": 0.0}), } } RETURN_TYPES = ("VEC2",) FUNCTION = "op" CATEGORY = "math/conversion" def op(self, a: float) -> tuple[Vec2]: return ((a, a),) class BreakoutVec2: @classmethod def INPUT_TYPES(cls) -> Mapping[str, Any]: return {"required": {"a": ("VEC2", {"default": VEC2_ZERO})}} RETURN_TYPES = ("FLOAT", "FLOAT") FUNCTION = "op" CATEGORY = "math/conversion" def op(self, a: Vec2) -> tuple[float, float]: return (a[0], a[1]) class ComposeVec3: @classmethod def INPUT_TYPES(cls) -> Mapping[str, Any]: return { "required": { "x": ("FLOAT", {"default": 0.0}), "y": ("FLOAT", {"default": 0.0}), "z": ("FLOAT", {"default": 0.0}), } } RETURN_TYPES = ("VEC3",) FUNCTION = "op" CATEGORY = "math/conversion" def op(self, x: float, y: float, z: float) -> tuple[Vec3]: return ((x, y, z),) class FillVec3: @classmethod def INPUT_TYPES(cls) -> Mapping[str, Any]: return { "required": { "a": ("FLOAT", {"default": 0.0}), } } RETURN_TYPES = ("VEC3",) FUNCTION = "op" CATEGORY = "math/conversion" def op(self, a: float) -> tuple[Vec3]: return ((a, a, a),) class BreakoutVec3: @classmethod def INPUT_TYPES(cls) -> Mapping[str, Any]: return {"required": {"a": ("VEC3", {"default": VEC3_ZERO})}} RETURN_TYPES = ("FLOAT", "FLOAT", "FLOAT") FUNCTION = "op" CATEGORY = "math/conversion" def op(self, a: Vec3) -> tuple[float, float, float]: return (a[0], a[1], a[2]) class ComposeVec4: @classmethod def INPUT_TYPES(cls) -> Mapping[str, Any]: return { "required": { "x": ("FLOAT", {"default": 0.0}), "y": ("FLOAT", {"default": 0.0}), "z": ("FLOAT", {"default": 0.0}), "w": ("FLOAT", {"default": 0.0}), } } RETURN_TYPES = ("VEC4",) FUNCTION = "op" CATEGORY = "math/conversion" def op(self, x: float, y: float, z: float, w: float) -> tuple[Vec4]: return ((x, y, z, w),) class FillVec4: @classmethod def INPUT_TYPES(cls) -> Mapping[str, Any]: return { "required": { "a": ("FLOAT", {"default": 0.0}), } } RETURN_TYPES = ("VEC4",) FUNCTION = "op" CATEGORY = "math/conversion" def op(self, a: float) -> tuple[Vec4]: return ((a, a, a, a),) class BreakoutVec4: @classmethod def INPUT_TYPES(cls) -> Mapping[str, Any]: return {"required": {"a": ("VEC4", {"default": VEC4_ZERO})}} RETURN_TYPES = ("FLOAT", "FLOAT", "FLOAT", "FLOAT") FUNCTION = "op" CATEGORY = "math/conversion" def op(self, a: Vec4) -> tuple[float, float, float, float]: return (a[0], a[1], a[2], a[3]) NODE_CLASS_MAPPINGS = { "CM_BoolToInt": BoolToInt, "CM_IntToBool": IntToBool, "CM_FloatToInt": FloatToInt, "CM_IntToFloat": IntToFloat, "CM_IntToNumber": IntToNumber, "CM_NumberToInt": NumberToInt, "CM_FloatToNumber": FloatToNumber, "CM_NumberToFloat": NumberToFloat, "CM_ComposeVec2": ComposeVec2, "CM_ComposeVec3": ComposeVec3, "CM_ComposeVec4": ComposeVec4, "CM_BreakoutVec2": BreakoutVec2, "CM_BreakoutVec3": BreakoutVec3, "CM_BreakoutVec4": BreakoutVec4, }