dl
dl_model_data.h
浏览该文件的文档.
1
12#pragma once
13
14#include <vector>
15#include <limits>
16
19#include "math/dl_matrix.h"
20#include "dl_model_common.h"
21#include "vk/dl_vertex.h"
22#include "base/dl_tree.h"
23
24namespace dl
25{
26// 模型节点变换
28{
30 Position4 _r; // 四元数
34 _t{},
35 _r{ 1,0,0,0 },
36 _s{ 1,1,1 }
37 {
39 }
40
42 {
46 return mat_t * mat_r * mat_s * _mat;
47 }
48};
49
50
51//
53{
56 bool _vaild;
57public:
59 _vaild{ false }
60 {
61 }
63 _min{ min },
64 _max{ max },
65 _vaild{ true }
66 {
67 }
68
69 void Add(const BoundingBox& b);
70
72};
73
74// 模型节点子网格
76{
78 size_t _indexMaterial;//材质下标,-1代表没有
79
81 _indexMaterial{ (size_t)-1 }
82 {
83 }
84};
85
96
97// 模型网格
99{
100 std::vector<ModelPrimitive> _primitives;
102};
103
104struct ModelSkin;
105// 模型节点
107{
108 int _index; // 自己id
109 int _indexSkin; // 皮肤下标
111 ModelMesh _mesh; // 网格
112 ModelNode* _parent; // 父节点
113
114
116 _index{ -1 },
117 _indexSkin{ -1 },
118 _parent{ nullptr }
119 {
120 }
121};
122
123class ModelAnimationInstance;
126{
128 int _indexSkin; // 整个骨骼是在一个节点上
129 int _indexParent; // 父节点索引
130 ModelNodeTransform _trans2Parent; // 到父节点的变换(具有初始值,动画只改变srt)
132
137
139 _index{ -1 },
140 _indexSkin{ -1 },
141 _indexParent{ -1 },
144 {
145 }
146
149
150 // 返回局部矩阵(到父节点,动画设置)
152
153 // 返回世界矩阵
155
156 void Update(const std::vector<ModelSkin>& all_skin, ModelAnimationInstance* instance);
157};
158
160{
161 std::string name;
162 int skeletonRoot = -1;
163 std::vector<Matrix4> _allOffsetMatrix; // 偏移矩阵(世界坐标系->节点)
164 std::vector<int> _allJoint; // 夹具所控制的节点
165
167 {
168 for (size_t i = 0; i < _allJoint.size(); ++i)
169 {
170 if (index == _allJoint[i])
171 return _allOffsetMatrix[i];
172 }
173 return Mat::CreateIdentity();
174 }
175
178};
179
180// 动画通道
189// 动画采样
191{
193
195 std::vector<float> inputs;
196 std::vector<Position4> outputsVec4;
197 std::vector<float> outputs;
198
199 Position4 cubicSplineInterpolation(size_t index, float time, uint32_t stride) const;
200 void translate(size_t index, float time, ModelNodeRt* node) const;
201 void scale(size_t index, float time, ModelNodeRt* node) const;
202 void rotate(size_t index, float time, ModelNodeRt* node) const;
203
206};
207
209{
210 std::string _name;
211 std::vector<ModelAnimationSampler> _allSampler;
212 std::vector<ModelAnimationChannel> _allChannel;
213 float start;
214 float end;
215
218};
219
220// 模型材质
222{
223 // 最后转为Model时,变为可以用的着色器资源
225 std::string _materialName;
226 // 路径为空,则表示没有(VK加载时会返回0)
227 std::string _pathTexDiffuse;
228 std::string _pathTexPhysical;
229 std::string _pathTexNormal;
230 std::string _pathTexAo;
231 std::string _pathTexEmissvie;
232
235};
236
237
238// 模型数据
240{
242 std::vector<ModelAnimation> _allAnimation; // 所有动画
243 std::vector<ModelSkin> _allSkin; // 所有蒙皮
244 std::vector<ModelMaterial> _allMaterial; // 所有材质
245 std::vector<ModelDrawCall> _allSub; // 所有网格
246 std::vector<uint32_t> _allIndex; // 索引
247 std::vector<Vertex> _allVertex; // 顶点
248 std::vector<VertexBone> _allVertexSkin; // 顶点
249 size_t _indexPos;
251
253 _indexPos{},
254 _vertexPos{}
255 {
256 }
257
259 {
260 for (auto& iter : _allNode)
261 {
262 delete iter->GetValue();
263 }
264 }
265
266 void Update();
267};
268
269
270
271}
N叉树
二进制输入流
二进制输出流
矩阵(列存储)
N叉树
Matrix4 CreateRotation(const Position3 &axis, Float angle)
创建旋转矩阵
Matrix4 CreateTranslation(const Position3 &t)
创建平移矩阵
Matrix4 CreateScaling(const Position3 &s)
创建缩放矩阵
Matrix4 CreateIdentity()
创建单位矩阵
Matrix< Float, 4, 4 > Matrix4
Array< Float, 3 > Position3
Array< Float, 4 > Position4
void Add(const BoundingBox &b)
BoundingBox getAABB(Matrix4 m)
BoundingBox(Position3 min, Position3 max)
材质(pbr 金属度/粗糙度)
std::vector< ModelAnimationSampler > _allSampler
void Load(StreamInput &s)
std::vector< ModelAnimationChannel > _allChannel
void Save(StreamOutput &s)
void Load(StreamInput &s)
void translate(size_t index, float time, ModelNodeRt *node) const
void scale(size_t index, float time, ModelNodeRt *node) const
void rotate(size_t index, float time, ModelNodeRt *node) const
void Save(StreamOutput &s)
std::vector< Position4 > outputsVec4
Position4 cubicSplineInterpolation(size_t index, float time, uint32_t stride) const
NTree< ModelNode * > _allNode
std::vector< VertexBone > _allVertexSkin
std::vector< ModelAnimation > _allAnimation
std::vector< uint32_t > _allIndex
std::vector< ModelSkin > _allSkin
std::vector< ModelMaterial > _allMaterial
std::vector< Vertex > _allVertex
std::vector< ModelDrawCall > _allSub
ModelTriangleRange _range
void Load(StreamInput &s)
void Save(StreamOutput &s)
std::vector< ModelPrimitive > _primitives
ModelNodeTransform _trans2Parent
运行时节点树
ModelNodeTransform _trans2Parent
void Save(StreamOutput &s)
void Load(StreamInput &s)
Matrix4 GetMatrixWorld(ModelAnimationInstance *instance)
Matrix4 GetMatrixLocal()
void Update(const std::vector< ModelSkin > &all_skin, ModelAnimationInstance *instance)
Matrix4 GetOffsetMatrix(int index)
std::vector< Matrix4 > _allOffsetMatrix
void Load(StreamInput &s)
std::vector< int > _allJoint
void Save(StreamOutput &s)