PeriDyno 1.0.0
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 "FilePath.h"
28#include "SkinInfo.h"
29#include "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
117
119
120 protected:
121 void resetStates() override
122 {
124 }
125
126 void updateStates() override;
127
128
129
130 public:
131
132 std::map<int, std::string> node_Name;
133
134 private:
135
140
142 bool ToCenter = false;
143
144 std::map<joint, Quat<float>> joint_rotation;
145 std::map<joint, Vec3f> joint_scale;
146 std::map<joint, Vec3f> joint_translation;
147 std::map<joint, Mat4f> joint_matrix;
148 std::map<joint, std::vector<int>> jointId_joint_Dir;
149
150
151
152
153
154 std::map<joint, Mat4f> joint_inverseBindMatrix;
155 std::map<joint, Mat4f> joint_AnimaMatrix;
156
157 std::vector<std::string> Scene_Name;
158 std::map<joint, std::string> joint_Name;
159
160 std::map<joint, Vec3i> joint_output; // Vec3i[0] translation ,Vec3i[1] scale ,Vec3i[2] rotation ,
161 std::map<joint, Vec3f> joint_input; // time Vec3f[0] translation ,Vec3f[1] scale ,Vec3f[2] rotation ,
162
163
164 std::vector<joint> all_Joints;
165
166
167
168 std::map<int, std::vector<int>> meshId_Dir;
169
170
171 std::map<int, Mat4f> node_matrix;
172
173
174 std::shared_ptr<GLWireframeVisualModule> jointLineRender;
175 std::shared_ptr<GLPointVisualModule> jointPointRender;
176
177 int maxMeshId = -1;
178 int maxJointId = -1;
179
180
181
184
185
186 private:
187
188
190
192
194
196
197 void updateAnimation(int frameNumber);
198
200
201 Vec3f getVertexLocationWithJointTransform(joint jointId, Vec3f inPoint, std::map<joint, Mat4f> jMatrix);
202
203 void buildInverseBindMatrices(const std::vector<joint>& all_Joints);
204
205 Vec3f getmeshPointDeformByJoint(joint jointId, Coord worldPosition, std::map<joint, Mat4f> jMatrix);
206
208 };
209
210
211
213}
#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:141
std::map< joint, Vec3f > joint_scale
Definition GltfLoader.h:145
std::map< joint, Vec3i > joint_output
Definition GltfLoader.h:160
void updateAnimation(int frameNumber)
DArray< Mat4f > d_mesh_Matrix
Definition GltfLoader.h:182
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:138
std::map< joint, std::vector< int > > jointId_joint_Dir
Definition GltfLoader.h:148
DEF_INSTANCE_STATE(PointSet< TDataType >, ShapeCenter, "")
DECLARE_TCLASS(GltfLoader, TDataType)
std::map< joint, std::string > joint_Name
Definition GltfLoader.h:158
DEF_INSTANCE_STATE(JointAnimationInfo, Animation,"")
DEF_ARRAY_STATE(Vec2f, TexCoord_0, DeviceType::GPU, "UVSet 0")
std::map< int, Mat4f > node_matrix
Definition GltfLoader.h:171
DEF_VAR(bool, ImportAnimation, false, "")
DEF_VAR(FilePath, FileName, "", "")
std::map< joint, Vec3f > joint_translation
Definition GltfLoader.h:146
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:161
std::string getNodeType() override
Definition GltfLoader.h:86
DArray< int > d_joints
Definition GltfLoader.h:139
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:144
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:154
DEF_INSTANCE_STATE(SkinInfo, Skin, "SkinInfo")
DEF_INSTANCE_STATE(EdgeSet< TDataType >, JointSet, "")
DArray< Coord > unCenterPosition
Definition GltfLoader.h:137
std::map< joint, Mat4f > joint_matrix
Definition GltfLoader.h:147
std::vector< std::string > Scene_Name
Definition GltfLoader.h:157
std::shared_ptr< GLWireframeVisualModule > jointLineRender
Definition GltfLoader.h:174
std::map< int, std::vector< int > > meshId_Dir
Definition GltfLoader.h:168
DEF_VAR_STATE(Mat4f, Transform, Mat4f::identityMatrix(), "Transform")
DArray< Coord > initialPosition
Definition GltfLoader.h:136
std::shared_ptr< GLPointVisualModule > jointPointRender
Definition GltfLoader.h:175
void resetStates() override
Definition GltfLoader.h:121
TDataType::Matrix Matrix
Definition GltfLoader.h:71
std::map< joint, Mat4f > joint_AnimaMatrix
Definition GltfLoader.h:155
std::vector< joint > all_Joints
Definition GltfLoader.h:164
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:183
std::map< int, std::string > node_Name
Definition GltfLoader.h:132
A PointSet stores the coordinates for a set of independent points.
Definition PointSet.h:8
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