PeriDyno 1.0.0
Loading...
Searching...
No Matches
GltfFunc.h
Go to the documentation of this file.
1#pragma once
2#include "Array/Array.h"
3#include "Topology/TriangleSet.h"
4#include "Matrix.h"
5#include "Vector.h"
6
9#include "tinygltf/tiny_gltf.h"
10#include "FilePath.h"
11#include "SkinInfo.h"
12
13#define NULL_TIME (-9599.99)
14
15namespace dyno
16{
17
18 typedef unsigned char byte;
19 typedef int joint;
20 typedef int scene;
21
22
23 void getBoundingBoxByName(tinygltf::Model& model,const tinygltf::Primitive& primitive,const std::string& attributeName,TAlignedBox3D<Real>& bound,Transform3f& transform);
24
25 void getVec3fByAttributeName(tinygltf::Model& model, const tinygltf::Primitive& primitive, const std::string& attributeName, std::vector<Vec3f>& vertices);
26
27 void getVec4ByAttributeName(tinygltf::Model& model, const tinygltf::Primitive& primitive, const std::string& attributeName, std::vector<Vec4f>& vec4Data);
28
29 void getRealByIndex(tinygltf::Model& model, int index, std::vector<Real>& result);
30
31 void getVec3fByIndex(tinygltf::Model& model, int index, std::vector<Vec3f>& result);
32
33 void getQuatByIndex(tinygltf::Model& model, int index, std::vector<Quat<float>>& result);
34
35 void getTriangles(tinygltf::Model& model, const tinygltf::Primitive& primitive, std::vector<TopologyModule::Triangle>& triangles, int pointOffest);
36
37 std::string getTexUri(const std::vector<tinygltf::Texture>& textures, const std::vector<tinygltf::Image>& images, int index);
38
39 void getVertexBindJoint(tinygltf::Model& model, const tinygltf::Primitive& primitive, const std::string& attributeName, std::vector<Vec4f>& vec4Data, const std::vector<int>& skinJoints);
40
41
42 void getNodesAndHierarchy(tinygltf::Model& model, std::map<scene, std::vector<int>> Scene_JointsNodesId, std::vector<joint>& all_Nodes, std::map<joint, std::vector<int>>& id_Dir);
43
44 void traverseNode(tinygltf::Model& model, joint id, std::vector<joint>& joint_nodes, std::map<joint, std::vector<int>>& dir, std::vector<joint> currentDir);
45
47 const std::vector<int>& all_Joints,
48 std::vector<std::vector<int>>& joint_child,
49 std::map<int, Quat<float>>& joint_rotation,
50 std::map<int, Vec3f>& joint_scale,
51 std::map<int, Vec3f>& joint_translation,
52 std::map<int, Mat4f>& joint_matrix,
53 tinygltf::Model model
54 );
55
57 tinygltf::Model model,
58 std::map<joint, Vec3i>& joint_output,
59 std::map<joint, Vec3f>& joint_input,
60 std::map<joint, std::vector<Vec3f>>& joint_T_f_anim,
61 std::map<joint, std::vector<Real>>& joint_T_Time,
62 std::map<joint, std::vector<Vec3f>>& joint_S_f_anim,
63 std::map<joint, std::vector<Real>>& joint_S_Time,
64 std::map<joint, std::vector<Quat<float>>>& joint_R_f_anim,
65 std::map<joint, std::vector<Real>>& joint_R_Time
66 );
67
69 const std::vector<joint>& all_Joints,
70 std::map<joint, Mat4f>& joint_matrix, int& maxJointId,
71 tinygltf::Model& model,
72 std::map<joint, Quat<float>>& joint_rotation,
73 std::map<joint, Vec3f>& joint_translation,
74 std::map<joint, Vec3f>& joint_scale,
75 std::map<joint, Mat4f>& joint_inverseBindMatrix,
76 std::map<joint, std::vector<int>> jointId_joint_Dir
77 );
78
80 tinygltf::Model& model,
81 int& jointNum,
82 int& meshNum,
83 std::map<joint, std::vector<int>>& jointId_joint_Dir,
84 std::vector<joint>& all_Joints,
85 std::vector<int>& all_Nodes,
86 std::map<joint, std::vector<int>> nodeId_Dir,
87 std::map<int, std::vector<int>>& meshId_Dir,
88 std::vector<int>& all_Meshs,
89 int& maxJointId
90 );
91
92 std::vector<int> getJointDirByJointIndex(int Index, std::map<joint, std::vector<int>> jointId_joint_Dir);
93
95 tinygltf::Model& model,
96 const std::vector<int>& all_MeshNodeIDs,
97 int& maxMeshId,
98 CArray<Mat4f>& mesh_Matrix
99 );
100
101 template< typename Vec3f, typename Vec4f, typename Mat4f, typename Vec2u>
103 DArray<Vec3f>& intialPosition,
104 DArray<Vec3f>& worldPosition,
105 DArray<Mat4f>& joint_inverseBindMatrix,
106 DArray<Mat4f>& WorldMatrix,
107
108 DArray<Vec4f>& bind_joints_0,
109 DArray<Vec4f>& bind_joints_1,
110 DArray<Vec4f>& weights_0,
111 DArray<Vec4f>& weights_1,
112
113 Mat4f transform,
114 bool isNormal,
115
116 Vec2u range
117 );
118
119 void loadGLTFTextureMesh(std::shared_ptr<TextureMesh> texMesh, const std::string& filepath);
120
121 void loadGLTFMaterial(tinygltf::Model& model, std::shared_ptr<TextureMesh> texMesh, FilePath filename);
122
124 tinygltf::Model& model,
125 std::shared_ptr<TextureMesh> texMesh,
126 const std::string& filepath,
127 DArray<Vec3f>* initialPosition = nullptr,
128 DArray<Vec3f>* initialNormal = nullptr,
129 DArray<Mat4f>* d_mesh_Matrix =nullptr,
130 DArray<int>* d_shape_meshId = nullptr,
131 std::shared_ptr<SkinInfo> skinData = nullptr
132 );
133
134
135
136 template< typename Triangle>
138 DArray<Triangle>& triangle,
139 DArray<uint>& ID_shapeId,
140 int& shapeId,
141 int size
142 );
143
144 template<typename Mat4f, typename Vec3f >
146 DArray<Vec3f>& intialPosition,
147 DArray<Vec3f>& worldPosition,
148 DArray<Vec3f>& intialNormal,
149 DArray<Vec3f>& Normal,
150 DArray<Mat4f>& WorldMatrix,
151 DArray<uint>& vertexId_shape,
152 DArray<int>& shapeId_MeshId
153 );
154
155
156
157 template<typename Vec3f>
159 DArray<Vec3f>& newPos,
160 DArray<Vec3f>& pos,
161 DArray<int>& radix
162 );
163
164 template<typename uint>
166 DArray<int>& counter,
167 DArray<uint>& point_ShapeIds,
168 uint& target
169 );
170
171 template< typename Vec3f, typename uint>
173 DArray<Vec3f>& iniPos,
174 DArray<Vec3f>& finalPos,
175 DArray<uint>& shapeId,
177 );
178
179}
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
int joint
Definition GltfFunc.h:19
void getVertexBindJoint(tinygltf::Model &model, const tinygltf::Primitive &primitive, const std::string &attributeName, std::vector< Vec4f > &vec4Data, const std::vector< int > &skinJoints)
void loadGLTFMaterial(tinygltf::Model &model, std::shared_ptr< TextureMesh > texMesh, FilePath filename)
unsigned char byte
Definition GltfFunc.h:18
void buildInverseBindMatrices(const std::vector< joint > &all_Joints, std::map< joint, Mat4f > &joint_matrix, int &maxJointId, tinygltf::Model &model, std::map< joint, Quat< float > > &joint_rotation, std::map< joint, Vec3f > &joint_translation, std::map< joint, Vec3f > &joint_scale, std::map< joint, Mat4f > &joint_inverseBindMatrix, std::map< joint, std::vector< int > > jointId_joint_Dir)
void skinAnimation(DArray< Vec3f > &intialPosition, DArray< Vec3f > &worldPosition, DArray< Mat4f > &joint_inverseBindMatrix, DArray< Mat4f > &WorldMatrix, DArray< Vec4f > &bind_joints_0, DArray< Vec4f > &bind_joints_1, DArray< Vec4f > &weights_0, DArray< Vec4f > &weights_1, Mat4f transform, bool isNormal, Vec2u range)
Array< T, DeviceType::GPU > DArray
Definition Array.inl:89
void loadGLTFShape(tinygltf::Model &model, std::shared_ptr< TextureMesh > texMesh, const std::string &filepath, DArray< Vec3f > *initialPosition=nullptr, DArray< Vec3f > *initialNormal=nullptr, DArray< Mat4f > *d_mesh_Matrix=nullptr, DArray< int > *d_shape_meshId=nullptr, std::shared_ptr< SkinInfo > skinData=nullptr)
void Shape_PointCounter(DArray< int > &counter, DArray< uint > &point_ShapeIds, uint &target)
void importAnimation(tinygltf::Model model, std::map< joint, Vec3i > &joint_output, std::map< joint, Vec3f > &joint_input, std::map< joint, std::vector< Vec3f > > &joint_T_f_anim, std::map< joint, std::vector< Real > > &joint_T_Time, std::map< joint, std::vector< Vec3f > > &joint_S_f_anim, std::map< joint, std::vector< Real > > &joint_S_Time, std::map< joint, std::vector< Quat< float > > > &joint_R_f_anim, std::map< joint, std::vector< Real > > &joint_R_Time)
int scene
Definition GltfFunc.h:20
void getRealByIndex(tinygltf::Model &model, int index, std::vector< Real > &result)
void loadGLTFTextureMesh(std::shared_ptr< TextureMesh > texMesh, const std::string &filepath)
void shapeTransform(DArray< Vec3f > &intialPosition, DArray< Vec3f > &worldPosition, DArray< Vec3f > &intialNormal, DArray< Vec3f > &Normal, DArray< Mat4f > &WorldMatrix, DArray< uint > &vertexId_shape, DArray< int > &shapeId_MeshId)
void getVec3fByAttributeName(tinygltf::Model &model, const tinygltf::Primitive &primitive, const std::string &attributeName, std::vector< Vec3f > &vertices)
Vector< uint32_t, 2 > Vec2u
Definition Vector2D.h:83
void getTriangles(tinygltf::Model &model, const tinygltf::Primitive &primitive, std::vector< TopologyModule::Triangle > &triangles, int pointOffest)
void getMeshMatrix(tinygltf::Model &model, const std::vector< int > &all_MeshNodeIDs, int &maxMeshId, CArray< Mat4f > &mesh_Matrix)
std::vector< int > getJointDirByJointIndex(int Index, std::map< joint, std::vector< int > > jointId_joint_Dir)
Transform< float, 3 > Transform3f
void updateJoint_Mesh_Camera_Dir(tinygltf::Model &model, int &jointNum, int &meshNum, std::map< joint, std::vector< int > > &jointId_joint_Dir, std::vector< joint > &all_Joints, std::vector< int > &all_Nodes, std::map< joint, std::vector< int > > nodeId_Dir, std::map< int, std::vector< int > > &meshId_Dir, std::vector< int > &all_Meshs, int &maxJointId)
void getBoundingBoxByName(tinygltf::Model &model, const tinygltf::Primitive &primitive, const std::string &attributeName, TAlignedBox3D< Real > &bound, Transform3f &transform)
void shapeToCenter(DArray< Vec3f > &iniPos, DArray< Vec3f > &finalPos, DArray< uint > &shapeId, DArray< Vec3f > &t)
void getQuatByIndex(tinygltf::Model &model, int index, std::vector< Quat< float > > &result)
void getNodesAndHierarchy(tinygltf::Model &model, std::map< scene, std::vector< int > > Scene_JointsNodesId, std::vector< joint > &all_Nodes, std::map< joint, std::vector< int > > &id_Dir)
void getVec4ByAttributeName(tinygltf::Model &model, const tinygltf::Primitive &primitive, const std::string &attributeName, std::vector< Vec4f > &vec4Data)
Array< T, DeviceType::CPU > CArray
Definition Array.h:151
unsigned int uint
Definition VkProgram.h:14
void getVec3fByIndex(tinygltf::Model &model, int index, std::vector< Vec3f > &result)
std::string getTexUri(const std::vector< tinygltf::Texture > &textures, const std::vector< tinygltf::Image > &images, int index)
void setupPoints(DArray< Vec3f > &newPos, DArray< Vec3f > &pos, DArray< int > &radix)
SquareMatrix< float, 4 > Mat4f
Definition Matrix4x4.h:85
void getJointsTransformData(const std::vector< int > &all_Joints, std::vector< std::vector< int > > &joint_child, std::map< int, Quat< float > > &joint_rotation, std::map< int, Vec3f > &joint_scale, std::map< int, Vec3f > &joint_translation, std::map< int, Mat4f > &joint_matrix, tinygltf::Model model)
void updateVertexIdShape(DArray< Triangle > &triangle, DArray< uint > &ID_shapeId, int &shapeId, int size)
void traverseNode(tinygltf::Model &model, joint id, std::vector< joint > &joint_nodes, std::map< joint, std::vector< int > > &dir, std::vector< joint > currentDir)