SWBF-msh-Blender-IO/addons/io_scene_swbf_msh/msh_model.py

77 lines
2.0 KiB
Python
Raw Normal View History

2019-11-11 10:03:52 +00:00
""" Contains Model and dependent types for constructing a scene hierarchy easilly
saved to a .msh file. """
from dataclasses import dataclass, field
from typing import List
from enum import Enum
from mathutils import Vector, Quaternion
class ModelType(Enum):
NULL = 0
SKIN = 1
CLOTH = 2
BONE = 3
STATIC = 4
class CollisionPrimitiveShape(Enum):
SPHERE = 0
# ELLIPSOID = 1
CYLINDER = 2
# MESH = 3
2019-11-15 09:40:47 +00:00
BOX = 4
2019-11-11 10:03:52 +00:00
@dataclass
class ModelTransform:
""" Class representing a `TRAN` section in a .msh file. """
translation: Vector = field(default_factory=Vector)
rotation: Quaternion = field(default_factory=Quaternion)
2019-11-11 10:03:52 +00:00
2020-10-16 00:40:27 +00:00
@dataclass
class VertexWeight:
""" Class representing a vertex weight in a .msh file. """
weight: float = 1.0
bone: int = 0
2019-11-11 10:03:52 +00:00
@dataclass
class GeometrySegment:
""" Class representing a 'SEGM' section in a .msh file. """
2020-10-16 00:40:27 +00:00
material_name: str = field(default_factory=str)
2019-11-11 10:03:52 +00:00
positions: List[Vector] = field(default_factory=list)
normals: List[Vector] = field(default_factory=list)
colors: List[List[float]] = None
texcoords: List[Vector] = field(default_factory=list)
2020-10-16 00:40:27 +00:00
weights: List[List[VertexWeight]] = None
2019-11-11 10:03:52 +00:00
polygons: List[List[int]] = field(default_factory=list)
triangles: List[List[int]] = field(default_factory=list)
triangle_strips: List[List[int]] = None
@dataclass
class CollisionPrimitive:
""" Class representing a 'SWCI' section in a .msh file. """
2019-11-15 09:40:47 +00:00
shape: CollisionPrimitiveShape = CollisionPrimitiveShape.SPHERE
radius: float = 0.0
height: float = 0.0
length: float = 0.0
2019-11-11 10:03:52 +00:00
@dataclass
class Model:
""" Class representing a 'MODL' section in a .msh file. """
name: str = "Model"
parent: str = ""
model_type: ModelType = ModelType.NULL
hidden: bool = True
transform: ModelTransform = field(default_factory=ModelTransform)
2019-11-11 10:03:52 +00:00
2020-10-16 00:40:27 +00:00
bone_map: List[str] = None
2019-11-11 10:03:52 +00:00
geometry: List[GeometrySegment] = None
collisionprimitive: CollisionPrimitive = None