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
|
2020-12-04 08:33:46 +00:00
|
|
|
from typing import List, Tuple, Dict
|
2019-11-11 10:03:52 +00:00
|
|
|
from enum import Enum
|
|
|
|
from mathutils import Vector, Quaternion
|
|
|
|
|
|
|
|
class ModelType(Enum):
|
|
|
|
NULL = 0
|
|
|
|
SKIN = 1
|
|
|
|
CLOTH = 2
|
|
|
|
BONE = 3
|
|
|
|
STATIC = 4
|
2022-01-18 20:16:49 +00:00
|
|
|
|
|
|
|
# Maybe there are only for BF1 models (http://www.secretsociety.com/forum/downloads/BF1/BF1%20Mesh%20File%20Format.txt)?
|
|
|
|
# According to that link #3 is envelope, not bone, maybe that's for TCW or smthg
|
|
|
|
# CHILDSKIN = 5 # I didnt bother with these, never encountered one and they might need adjustments to vertex data
|
|
|
|
SHADOWVOLUME = 6 # Pretty common
|
2019-11-11 10:03:52 +00:00
|
|
|
|
|
|
|
class CollisionPrimitiveShape(Enum):
|
|
|
|
SPHERE = 0
|
2020-11-01 23:11:26 +00:00
|
|
|
ELLIPSOID = 1
|
2019-11-11 10:03:52 +00:00
|
|
|
CYLINDER = 2
|
2020-11-01 23:11:26 +00:00
|
|
|
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. """
|
|
|
|
|
2019-11-18 12:33:55 +00:00
|
|
|
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
|
|
|
|
|
2023-01-07 02:30:16 +00:00
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class ShadowGeometry:
|
|
|
|
""" Class representing 'SHDW' chunks. """
|
|
|
|
|
|
|
|
# Perhaps I could just use the positions list in the segment
|
|
|
|
# class, but I don't know if SHDW info can coexist with
|
|
|
|
# a normal geometry segment...
|
|
|
|
positions: List[Vector] = field(default_factory=list)
|
|
|
|
|
|
|
|
# The second two entries may not be necessary...
|
|
|
|
edges: List[Tuple[int,int,int,int]] = field(default_factory=list)
|
|
|
|
|
|
|
|
|
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-14 20:06:04 +00:00
|
|
|
|
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
|
|
|
|
|
2023-01-07 02:30:16 +00:00
|
|
|
shadow_geometry: ShadowGeometry = None
|
2020-11-26 04:10:14 +00:00
|
|
|
|
2019-11-11 10:03:52 +00:00
|
|
|
@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
|
2022-10-09 01:31:08 +00:00
|
|
|
hidden: bool = False
|
2019-11-11 10:03:52 +00:00
|
|
|
|
2019-11-17 11:03:53 +00:00
|
|
|
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
|
2020-10-11 16:11:15 +00:00
|
|
|
|
2020-11-30 01:27:46 +00:00
|
|
|
|
2020-11-29 20:45:32 +00:00
|
|
|
@dataclass
|
|
|
|
class RotationFrame:
|
|
|
|
|
|
|
|
index : int = 0
|
|
|
|
rotation : Quaternion = field(default_factory=Quaternion)
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class TranslationFrame:
|
|
|
|
|
|
|
|
index : int = 0
|
|
|
|
translation : Vector = field(default_factory=Vector)
|
|
|
|
|
|
|
|
|
2020-10-11 16:11:15 +00:00
|
|
|
@dataclass
|
|
|
|
class Animation:
|
|
|
|
""" Class representing 'CYCL' + 'KFR3' sections in a .msh file """
|
|
|
|
|
2020-10-20 03:18:08 +00:00
|
|
|
name: str = "fullanimation"
|
2020-12-05 05:53:59 +00:00
|
|
|
bone_frames: Dict[int, Tuple[List[TranslationFrame], List[RotationFrame]]] = field(default_factory=dict)
|
2020-10-20 03:18:08 +00:00
|
|
|
|
2020-11-23 15:15:22 +00:00
|
|
|
framerate: float = 29.97
|
2020-10-20 03:18:08 +00:00
|
|
|
start_index : int = 0
|
|
|
|
end_index : int = 0
|