PeriDyno 1.2.1
Loading...
Searching...
No Matches
GltfLoader.h
Go to the documentation of this file.
1
16
17#pragma once
19#include "Topology/TriangleSet.h"
21
23
24#include "GLPointVisualModule.h"
26
27#include "Field/FilePath.h"
28#include "Topology/SkinInfo.h"
29#include "Topology/JointInfo.h"
30
31
32namespace dyno
33{
38 {
40 public:
42
43 DEF_VAR(uint, ShapeId, 0, "");
44
45 DEF_VAR(Vec3f, Center, Vec3f(0), "");
46
47 DEF_VAR(Vec3f, LowerBound, Vec3f(0), "");
48
49 DEF_VAR(Vec3f, UpperBound, Vec3f(0), "");
50
51 public:
53
55
56 private:
57 void compute() override;
58
60 };
61
62
63 template<typename TDataType>
64 class GltfLoader : virtual public ParametricModel<TDataType>
65 {
67
68 public:
69 typedef typename TDataType::Real Real;
70 typedef typename TDataType::Coord Coord;
71 typedef typename TDataType::Matrix Matrix;
72
74
75
76 typedef unsigned char byte;
77 typedef int joint;
78 typedef int shape;
79 typedef int mesh;
80 typedef int primitive;
81 typedef int scene;
82
85
86 std::string getNodeType() override { return "IO"; }
87
88 public:
89
90 DEF_VAR(FilePath, FileName, "", "");
91 DEF_VAR(bool, ImportAnimation, false, "");
92 DEF_VAR(Real,AnimationSpeed,1,"AnimationSpeed");
93 DEF_VAR(Real, JointRadius, 0.01, "");
94
95 DEF_VAR(bool, UseInstanceTransform, true, "");
96 //DefaultChannel
97 DEF_ARRAY_STATE(Vec2f, TexCoord_0, DeviceType::GPU, "UVSet 0");
98 DEF_ARRAY_STATE(Vec2f, TexCoord_1, DeviceType::GPU, "UVSet 1");
99 DEF_ARRAY_STATE(Mat4f, InitialMatrix, DeviceType::GPU, "");
100
101 //CustomChannel
102
103 DEF_VAR_STATE(Mat4f, Transform, Mat4f::identityMatrix(), "Transform");
104
105 DEF_INSTANCE_STATE(SkinInfo, Skin, "SkinInfo");
106
107 DEF_ARRAY_STATE(Mat4f, JointInverseBindMatrix, DeviceType::GPU, "JointInverseBindMatrix");
108 DEF_ARRAY_STATE(Mat4f, JointLocalMatrix, DeviceType::GPU, "JointLocalMatrix");
109 DEF_ARRAY_STATE(Mat4f, JointWorldMatrix, DeviceType::GPU, "JointWorldMatrix");
110
111 DEF_INSTANCE_STATE(JointInfo,JointsData,"JointsInfo");
112
114
116
118
119 protected:
120 void resetStates() override
121 {
123 }
124
125 void updateStates() override;
126
127
128
129 public:
130
131 std::map<int, std::string> node_Name;
132
133 private:
134
139
141 bool ToCenter = false;
142
143 std::map<joint, Quat<float>> joint_rotation;
144 std::map<joint, Vec3f> joint_scale;
145 std::map<joint, Vec3f> joint_translation;
146 std::map<joint, Mat4f> joint_matrix;
147 std::map<joint, std::vector<int>> jointId_joint_Dir;
148
149
150
151
152
153 std::map<joint, Mat4f> joint_inverseBindMatrix;
154 std::map<joint, Mat4f> joint_AnimaMatrix;
155
156 std::vector<std::string> Scene_Name;
157 std::map<joint, std::string> joint_Name;
158
159 std::map<joint, Vec3i> joint_output; // Vec3i[0] translation ,Vec3i[1] scale ,Vec3i[2] rotation ,
160 std::map<joint, Vec3f> joint_input; // time Vec3f[0] translation ,Vec3f[1] scale ,Vec3f[2] rotation ,
161
162
163 std::vector<joint> all_Joints;
164
165
166
167 std::map<int, std::vector<int>> meshId_Dir;
168
169
170 std::map<int, Mat4f> node_matrix;
171
172
173 std::shared_ptr<GLWireframeVisualModule> jointLineRender;
174 std::shared_ptr<GLPointVisualModule> jointPointRender;
175
176 int maxMeshId = -1;
177 int maxJointId = -1;
178
179
180
183
184
185 private:
186
187
189
191
193
195
196 void updateAnimation(int frameNumber);
197
199
200 Vec3f getVertexLocationWithJointTransform(joint jointId, Vec3f inPoint, std::map<joint, Mat4f> jMatrix);
201
202 void buildInverseBindMatrices(const std::vector<joint>& all_Joints);
203
204 Vec3f getmeshPointDeformByJoint(joint jointId, Coord worldPosition, std::map<joint, Mat4f> jMatrix);
205
207 };
208
209
210
212}
#define IMPLEMENT_TCLASS(name, T1)
Definition Object.h:103
DEF_VAR(Vec3f, LowerBound, Vec3f(0), "")
DECLARE_CLASS(BoundingBoxOfTextureMesh)
DEF_VAR(uint, ShapeId, 0, "")
DEF_INSTANCE_OUT(EdgeSet< DataType3f >, BoundingBox, "")
DEF_VAR(Vec3f, Center, Vec3f(0), "")
DEF_INSTANCE_IN(TextureMesh, TextureMesh, "")
DEF_VAR(Vec3f, UpperBound, Vec3f(0), "")
DArray< Coord > d_ShapeCenter
Definition GltfLoader.h:140
std::map< joint, Vec3f > joint_scale
Definition GltfLoader.h:144
std::map< joint, Vec3i > joint_output
Definition GltfLoader.h:159
void updateAnimation(int frameNumber)
DArray< Mat4f > d_mesh_Matrix
Definition GltfLoader.h:181
DEF_ARRAY_STATE(Mat4f, JointLocalMatrix, DeviceType::GPU, "JointLocalMatrix")
DEF_ARRAY_STATE(Mat4f, InitialMatrix, DeviceType::GPU, "")
Vec3f getVertexLocationWithJointTransform(joint jointId, Vec3f inPoint, std::map< joint, Mat4f > jMatrix)
void updateTransform()
DArray< Coord > initialNormal
Definition GltfLoader.h:137
std::map< joint, std::vector< int > > jointId_joint_Dir
Definition GltfLoader.h:147
DECLARE_TCLASS(GltfLoader, TDataType)
std::map< joint, std::string > joint_Name
Definition GltfLoader.h:157
DEF_INSTANCE_STATE(JointAnimationInfo, Animation,"")
DEF_ARRAY_STATE(Vec2f, TexCoord_0, DeviceType::GPU, "UVSet 0")
std::map< int, Mat4f > node_matrix
Definition GltfLoader.h:170
DEF_VAR(bool, ImportAnimation, false, "")
DEF_VAR(FilePath, FileName, "", "")
std::map< joint, Vec3f > joint_translation
Definition GltfLoader.h:145
DEF_ARRAY_STATE(Mat4f, JointWorldMatrix, DeviceType::GPU, "JointWorldMatrix")
DEF_INSTANCE_STATE(TextureMesh, TextureMesh, "")
TDataType::Real Real
Definition GltfLoader.h:69
DEF_VAR(bool, UseInstanceTransform, true, "")
std::map< joint, Vec3f > joint_input
Definition GltfLoader.h:160
std::string getNodeType() override
Definition GltfLoader.h:86
DArray< int > d_joints
Definition GltfLoader.h:138
TDataType::Coord Coord
Definition GltfLoader.h:70
Vec3f getmeshPointDeformByJoint(joint jointId, Coord worldPosition, std::map< joint, Mat4f > jMatrix)
std::map< joint, Quat< float > > joint_rotation
Definition GltfLoader.h:143
DEF_ARRAY_STATE(Mat4f, JointInverseBindMatrix, DeviceType::GPU, "JointInverseBindMatrix")
DEF_VAR(Real, AnimationSpeed, 1,"AnimationSpeed")
void InitializationData()
TopologyModule::Triangle Triangle
Definition GltfLoader.h:73
DEF_ARRAY_STATE(Vec2f, TexCoord_1, DeviceType::GPU, "UVSet 1")
void varRenderChanged()
std::map< joint, Mat4f > joint_inverseBindMatrix
Definition GltfLoader.h:153
DEF_INSTANCE_STATE(SkinInfo, Skin, "SkinInfo")
DEF_INSTANCE_STATE(EdgeSet< TDataType >, JointSet, "")
DArray< Coord > unCenterPosition
Definition GltfLoader.h:136
std::map< joint, Mat4f > joint_matrix
Definition GltfLoader.h:146
std::vector< std::string > Scene_Name
Definition GltfLoader.h:156
std::shared_ptr< GLWireframeVisualModule > jointLineRender
Definition GltfLoader.h:173
std::map< int, std::vector< int > > meshId_Dir
Definition GltfLoader.h:167
DEF_VAR_STATE(Mat4f, Transform, Mat4f::identityMatrix(), "Transform")
DArray< Coord > initialPosition
Definition GltfLoader.h:135
std::shared_ptr< GLPointVisualModule > jointPointRender
Definition GltfLoader.h:174
void resetStates() override
Definition GltfLoader.h:120
TDataType::Matrix Matrix
Definition GltfLoader.h:71
std::map< joint, Mat4f > joint_AnimaMatrix
Definition GltfLoader.h:154
std::vector< joint > all_Joints
Definition GltfLoader.h:163
unsigned char byte
Definition GltfLoader.h:76
void updateStates() override
void updateTransformState()
DEF_INSTANCE_STATE(JointInfo, JointsData,"JointsInfo")
DEF_VAR(Real, JointRadius, 0.01, "")
void buildInverseBindMatrices(const std::vector< joint > &all_Joints)
DArray< int > d_shape_meshId
Definition GltfLoader.h:182
std::map< int, std::string > node_Name
Definition GltfLoader.h:131
Vector< PointType, 3 > Triangle
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Array< T, DeviceType::GPU > DArray
Definition Array.inl:89
Vector< float, 2 > Vec2f
Definition Vector2D.h:81
Vector< float, 3 > Vec3f
Definition Vector3D.h:93
unsigned int uint
Definition VkProgram.h:14
SquareMatrix< float, 4 > Mat4f
Definition Matrix4x4.h:85