MetaFusion/scripts/model.py

175 lines
3.8 KiB
Python
Raw Normal View History

2025-02-07 07:22:22 +08:00
from dataclasses import dataclass, field
from typing import Dict, List
@dataclass
class Point3:
"""
2025-02-07 13:36:59 +08:00
表示三维空间中的点的模型类
2025-02-07 07:22:22 +08:00
2025-02-07 13:36:59 +08:00
属性
2025-02-07 07:22:22 +08:00
----------
@type x: float
2025-02-07 13:36:59 +08:00
@param x: x坐标值
2025-02-07 07:22:22 +08:00
@type y: float
2025-02-07 13:36:59 +08:00
@param y: y坐标值
2025-02-07 07:22:22 +08:00
@type z: float
2025-02-07 13:36:59 +08:00
@param z: z坐标值
2025-02-07 07:22:22 +08:00
"""
x: float = field(default=0.0)
y: float = field(default=0.0)
z: float = field(default=0.0)
@dataclass
class UV:
"""
2025-02-07 13:36:59 +08:00
用于保存UV数据的模型类
2025-02-07 07:22:22 +08:00
2025-02-07 13:36:59 +08:00
属性
2025-02-07 07:22:22 +08:00
----------
@type u: float
2025-02-07 13:36:59 +08:00
@param u: u坐标值
2025-02-07 07:22:22 +08:00
@type v: float
2025-02-07 13:36:59 +08:00
@param v: v坐标值
2025-02-07 07:22:22 +08:00
"""
u: float = field(default=0.0)
v: float = field(default=0.0)
@dataclass
class Layout:
"""
2025-02-07 13:36:59 +08:00
用于保存单个Layout数据的模型类
2025-02-07 07:22:22 +08:00
2025-02-07 13:36:59 +08:00
属性
2025-02-07 07:22:22 +08:00
----------
@type position_index: int
2025-02-07 13:36:59 +08:00
@param position_index: 表示位置的索引
2025-02-07 07:22:22 +08:00
@type texture_coordinate_index: int
2025-02-07 13:36:59 +08:00
@param texture_coordinate_index: 表示纹理坐标的索引值
2025-02-07 07:22:22 +08:00
"""
position_index: int = field(default=0)
texture_coordinate_index: int = field(default=0)
@dataclass
class Topology:
"""
2025-02-07 13:36:59 +08:00
用于保存拓扑数据的模型类
2025-02-07 07:22:22 +08:00
2025-02-07 13:36:59 +08:00
属性
2025-02-07 07:22:22 +08:00
----------
@type positions: List[Point3]
2025-02-07 13:36:59 +08:00
@param positions: 表示位置的空间点列表
2025-02-07 07:22:22 +08:00
@type texture_coordinates: List[UV]
2025-02-07 13:36:59 +08:00
@param texture_coordinates: 表示UV位置的列表
2025-02-07 07:22:22 +08:00
@type layouts: List[Layout]
2025-02-07 13:36:59 +08:00
@param layouts: Layout映射列表
2025-02-07 07:22:22 +08:00
@type face_vertex_layouts: List[List[int]]
2025-02-07 13:36:59 +08:00
@param face_vertex_layouts: 按面索引排列的面顶点Layout索引列表
2025-02-07 07:22:22 +08:00
"""
positions: List[Point3] = field(default_factory=list)
texture_coordinates: List[UV] = field(default_factory=list)
layouts: List[Layout] = field(default_factory=list)
face_vertex_layouts: List[List[int]] = field(default_factory=list)
@dataclass
class BlendShape:
"""
2025-02-07 13:36:59 +08:00
用于保存BlendShape数据的模型类
2025-02-07 07:22:22 +08:00
2025-02-07 13:36:59 +08:00
属性
2025-02-07 07:22:22 +08:00
----------
@type channel: int
2025-02-07 13:36:59 +08:00
@param channel: 指向BlendShape名称的索引
2025-02-07 07:22:22 +08:00
@type deltas: Dict[int, Point3]
2025-02-07 13:36:59 +08:00
@param deltas: BlendShape索引到坐标差值的映射
2025-02-07 07:22:22 +08:00
"""
channel: int = field(default=None)
deltas: Dict[int, Point3] = field(default_factory=dict)
@dataclass
class SkinWeightsData:
"""
2025-02-07 13:36:59 +08:00
用于保存蒙皮权重数据的模型类
2025-02-07 07:22:22 +08:00
2025-02-07 13:36:59 +08:00
属性
2025-02-07 07:22:22 +08:00
----------
@type values: List[List[float]]
2025-02-07 13:36:59 +08:00
@param values: 每个顶点索引的蒙皮权重值
2025-02-07 07:22:22 +08:00
@type joint_indices: List[List[int]]
2025-02-07 13:36:59 +08:00
@param joint_indices: 每个顶点索引的关节索引
2025-02-07 07:22:22 +08:00
"""
values: List[List[float]] = field(default_factory=list)
joint_indices: List[List[int]] = field(default_factory=list)
@dataclass
class Mesh:
"""
2025-02-07 13:36:59 +08:00
用于保存网格数据的模型类
2025-02-07 07:22:22 +08:00
2025-02-07 13:36:59 +08:00
属性
2025-02-07 07:22:22 +08:00
----------
@type name: str
2025-02-07 13:36:59 +08:00
@param name: 网格名称
2025-02-07 07:22:22 +08:00
@type topology: Topology
2025-02-07 13:36:59 +08:00
@param topology: 包含网格拓扑数据
2025-02-07 07:22:22 +08:00
@type skin_weights: SkinWeightsData
2025-02-07 13:36:59 +08:00
@param skin_weights: 表示蒙皮权重的数据
2025-02-07 07:22:22 +08:00
@type blend_shapes: List[BlendShape]
2025-02-07 13:36:59 +08:00
@param blend_shapes: 网格的BlendShape列表
2025-02-07 07:22:22 +08:00
"""
name: str = field(default=None)
topology: Topology = field(default_factory=Topology)
skin_weights: SkinWeightsData = field(default_factory=SkinWeightsData)
blend_shapes: List[BlendShape] = field(default_factory=list)
@dataclass
class Joint:
"""
2025-02-07 13:36:59 +08:00
用于保存单个关节数据的模型类
2025-02-07 07:22:22 +08:00
2025-02-07 13:36:59 +08:00
属性
2025-02-07 07:22:22 +08:00
----------
@type name: str
2025-02-07 13:36:59 +08:00
@param name: 关节名称
2025-02-07 07:22:22 +08:00
@type translation: Point3
2025-02-07 13:36:59 +08:00
@param translation: 表示关节位移的三维空间点
2025-02-07 07:22:22 +08:00
@type orientation: Point3
2025-02-07 13:36:59 +08:00
@param orientation: 表示关节方向的三维空间点
2025-02-07 07:22:22 +08:00
@type parent_name: str
2025-02-07 13:36:59 +08:00
@param parent_name: 父关节名称
2025-02-07 07:22:22 +08:00
"""
name: str = field(default=None)
translation: Point3 = field(default_factory=Point3)
orientation: Point3 = field(default_factory=Point3)
parent_name: str = field(default=None)