JunkBox_Lib++ (for Windows) 1.10.1
Loading...
Searching...
No Matches
GLTFDataTool.h
Go to the documentation of this file.
1#ifndef __JBXL_CPP_GLTF_TOOL_H_
2#define __JBXL_CPP_GLTF_TOOL_H_
3
11#include "tools++.h"
12#include "txml.h"
13#include "tjson.h"
14
15#include "TriBrep.h"
16#include "Rotation.h"
17#include "ContourBaseData.h"
18#include "MaterialParam.h"
19#include "MeshObjectData.h"
20
21
22namespace jbxl {
23
24#define JBXL_GLTF_COPYRIGHT "glTF/glb"
25#define JBXL_GLTF_GENERATOR "JBXL glTF/glb Tool Library (C) 2024 v1.0 by Fumi.Iseki and Austin Tate"
26#define JBXL_GLTF_VERSION "2.0"
27
28#define JBXL_GLB_HEADER "glTF"
29#define JBXL_GLB_VERSION 2.0
30#define JBXL_GLB_TYPE_JSON "JSON"
31#define JBXL_GLB_TYPE_BIN "BIN\0"
32
33#define JBXL_GLTF_BIN_AOS 1
34#define JBXL_GLTF_BIN_SOA 2
35
36
37// accessors
38#define JBXL_GLB_ACCESSORS_PNG_IMAGE "{\"bufferView\":%d,\"mimeType\":\"image/png\"}"
39#define JBXL_GLB_ACCESSORS_JPEG_IMAGE "{\"bufferView\":%d,\"mimeType\":\"image/jpeg\"}"
40
41#define JBXL_GLTF_BUFFERS_BIN "{\"uri\":\"%s\",\"byteLength\":%u}"
42#define JBXL_GLTF_BUFFERS_B64 "{\"uri\":\"data:application/octet-stream;base64,%s\",\"byteLength\":%u}"
43
44#define JBXL_GLTF_VIEWS "{\"buffer\":%d,\"byteOffset\":%u,\"byteLength\":%u,\"byteStride\":%u,\"target\":34962}"
45#define JBXL_GLTF_VIEWS_ELEMENT "{\"buffer\":%d,\"byteOffset\":%u,\"byteLength\":%u,\"target\":34963}"
46//#define JBXL_GLTF_VIEWS_IBM "{\"buffer\":%d,\"byteOffset\":%u,\"byteLength\":%u,\"byteStride\":%u}"
47#define JBXL_GLTF_VIEWS_DATA "{\"buffer\":%d,\"byteOffset\":%u,\"byteLength\":%u}"
48
49#define JBXL_GLTF_ACCESSORS "{\"bufferView\":%d,\"byteOffset\":%u,\"componentType\":%d,\"count\":%d,\"type\":\"%s\"}"
50#define JBXL_GLTF_ACCESSORS_S "{\"bufferView\":%d,\"byteOffset\":%u,\"componentType\":%d,\"count\":%d,\"type\":\"%s\",\"max\":[%d],\"min\":[%d]}"
51#define JBXL_GLTF_ACCESSORS_V2 "{\"bufferView\":%d,\"byteOffset\":%u,\"componentType\":%d,\"count\":%d,\"type\":\"%s\",\"max\":[%f,%f],\"min\":[%f,%f]}"
52#define JBXL_GLTF_ACCESSORS_V3 "{\"bufferView\":%d,\"byteOffset\":%u,\"componentType\":%d,\"count\":%d,\"type\":\"%s\",\"max\":[%f,%f,%f],\"min\":[%f,%f,%f]}"
53
54#define JBXL_GLTF_NODES_ROOT "{\"name\":\"Root\"}"
55#define JBXL_GLTF_NODES_ARMATURE "{\"name\":\"Armature\"}"
56#define JBXL_GLTF_NODES_MESH "{\"name\":\"%s\",\"mesh\":%d}"
57#define JBXL_GLTF_NODES_SKIN "{\"skin\":%d}"
58#define JBXL_GLTF_NODES_SKLTN "{\"name\":%s}" // It doesn't have to be \"%s\"
59
60#define JBXL_GLTF_MESHES_PRIM "{\"indices\":%d,\"attributes\":{\"POSITION\":%d,\"NORMAL\":%d,\"TEXCOORD_0\":%d},\"material\":%d,\"mode\":4}"
61#define JBXL_GLTF_MESHES_PRIM_JW "{\"indices\":%d,\"attributes\":{\"POSITION\":%d,\"NORMAL\":%d,\"TEXCOORD_0\":%d,\"JOINTS_0\":%d,\"WEIGHTS_0\":%d},\"material\":%d,\"mode\":4}"
62#define JBXL_GLTF_SKINS "{\"inverseBindMatrices\":%d,\"skeleton\":%d}"
63//#define JBXL_GLTF_MTLS "{\"name\":\"%s\",\"pbrMetallicRoughness\":{\"baseColorFactor\":[%f,%f,%f,%f],\"baseColorTexture\":{\"index\":%d,\"texCoord\":0}}}"
64
65#define JBXL_GLTF_TEXTURES "{\"source\":%d}"
66//#define JBXL_GLTF_TEXTURES "{\"source\":%d, \"sampler\":%d}"
67#define JBXL_GLTF_IMAGES "{\"uri\":\"%s\"}"
68
69#define JBXL_GLTF_MTLS_NAME_PBR "{\"name\":\"%s\",\"pbrMetallicRoughness\":{\"baseColorTexture\":{\"index\":%d,\"texCoord\":0}}}"
70#define JBXL_GLTF_MTLS_BCOLORF "{\"baseColorFactor\":[%f,%f,%f,%f]}"
71#define JBXL_GLTF_MTLS_METALF "{\"metallicFactor\":%f}"
72#define JBXL_GLTF_MTLS_ROUGHF "{\"roughnessFactor\":%f}"
73
74#define JBXL_GLTF_MTLS_CUTOFF "{\"alphaCutoff\":%f}"
75#define JBXL_GLTF_MTLS_EMISSIVE "{\"emissiveFactor\":[%f,%f,%f]}"
76
77
78
99
100
101typedef struct _glb_file_header {
106
107
108typedef struct _glb_data_chunk {
109 uDWord length; // データサイズ + PAD
111 uDWord pad; // 4Byte 境界のパッド
114
115
116typedef struct _glb_texture_info {
117 uDWord length; // 画像データのサイズ
118 uDWord pad; // 4Byte 境界のパッド
121 struct _glb_texture_info* next;
123
124
125
127//
132{
133public:
134 GLTFShellNode() { this->init();}
135 virtual ~GLTFShellNode(void) { this->free();}
136
137public:
138 unsigned int shell_indexes; // この SHELL での vi の総数
139 unsigned int shell_vertexes; // この SHELL での vv の総数 (vn, vu に対しても同じ数)
140
142
143 unsigned int num_facets; // この SHELL での FACET の総数
144 unsigned int* facet_index; // 各 FACET での vi の数を格納した配列
145 unsigned int* facet_vertex; // 各 FACET での vv (vn, vu) の数を格納した配列
146
147 unsigned int* vi; // インデックス (shell_indexes 個)
148 Vector<float>* vv; // 頂点座標 (shell_vertexes 個)
149 Vector<float>* vn; // 法線ベクトル (shell_vertexes 個)
150 UVMap<float>* vu; // UVマップ (shell_vertexes 個)
151 Vector4<short unsigned>* vj; // 重み付けされたジョイント (shell_vertexes 個)
152 Vector4<float>* vw; // ジョイントの重み (shell_vertexes 個)
153 float* vm; // Inverse Bind Matrix (num_joints x 16 個)
154
155 GLTFShellNode* next; // 次の SHELL ノードへのポインタ
156
157public:
158 void init(void);
159 void free(void);
160 void delete_next(void); // 次の SHELLノードを再帰的に呼び出して削除する
161};
162
163
164
166//
172{
173public:
174 GLTFData(void) { this->init();}
175 virtual ~GLTFData(void);
176
177public:
182
183 int bin_mode; // JBXL_GLTF_BIN_AOS or JBXL_GLTF_BIN_SOA
184 bool bin_seq; // binデータを逐次的に作成.false の場合,createShellGeoData() で一度に binデータを生成.
185
186 bool glb_out; // glb ファイルを出力.
187
189 bool forUE;
191
195
198
201
203 unsigned int bin_offset;
204 //
205 //Buffer matrix_buffer;
206 //unsigned int matrix_offset;
207
208 // counter
209 unsigned int shell_no; // shell の通し番号(addShellが呼ばれた回数)
210 unsigned int node_no; // nodes の要素(node)の通し番号
211 unsigned int mesh_no; // meshes の要素(mesh)の通し番号
212 unsigned int mesh_prim_no; // meshe の primitive 要素の通し番号
213 unsigned int skin_no; // skins の要素(skin)の通し番号
214 unsigned int view_no; // bufferViews の要素(bufferView)の通し番号
215 unsigned int accessor_no; // accessors の要素(accessor)の通し番号
216 unsigned int material_no; // materials の要素(material)の通し番号
217 unsigned int image_no; // images の要素(image)の通し番号. material.index -> texture.source -> image
218
219 unsigned int num_joints;
220 unsigned int node_offset;
221 unsigned int joint_offset;
222
236
238
240
241public:
242 void init(void);
243 void free(void);
244 void initGLTF(void);
245
246 void setUnity(bool b) { this->forUnity = b;}
247 void setUE(bool b) { this->forUE = b;}
248 void setEngine(int);
249
250 void addShell(MeshObjectData* meshdata, bool collider, SkinJointData* skin_joint=NULL, tList* joints_info=NULL);
251
252 void addScenes(void);
253 void addRootNode(AffineTrans<double>* affine);
254 void addSkeletonNodes(SkinJointData* skin_joint, AffineTrans<double>* affin);
255 void addNodes(AffineTrans<double>* affine);
256
257 void addTextures(MeshFacetNode* facet);
258 void addMeshes(MeshFacetNode* facet);
259 void addSkins(void);
260 void addMaterials(MeshFacetNode* facet);
261 void addMaterialParameters(tJson* pbr, MeshFacetNode* facet);
262
263 void closeSolid(void);
264
265 // Affine Transfer
268
269 // AoS
270 void addBufferViewsAoS(MeshFacetNode* facet);
271 void addAccessorsAoS(MeshFacetNode* facet);
272 void createBinDataSeqAoS(MeshFacetNode* facet, int shell_indexes, int shell_vertexes);
273
274 // SoA
275 void addBufferViewsSoA(MeshFacetNode* facet);
276 void addAccessorsSoA(MeshFacetNode* facet);
277 void createBinDataSeqSoA(MeshFacetNode* facet, int shell_indexes, int shell_vertexes);
278
279 // create bin data at onece
280 void createShellGeometryData(MeshFacetNode* facet, int shell_indexes, int shell_vertexes, SkinJointData* skin_joint=NULL, AffineTrans<double>* ue_trans=NULL);
281 void createBinDataAoS(void);
282 void createBinDataSoA(void);
283
284 // IBM
285 void addBufferViewsIBM(void);
286 void addAccessorsIBM(void);
287 void createBinDataIBM(SkinJointData* skin_joint, AffineTrans<double>* ue_trans=NULL);
288
289 // output
290 void outputFile (const char* fn, const char* out_dirn, const char* tex_dirn, const char* bin_dirn);
291 void output_gltf(char* fn, char* out_dirn, char* tex_dirn, char* bin_dirn);
292 void output_glb (char* fn, char* out_dirn, char* tex_dirn, char* bin_dirn);
293 void convertJson_TexturePath(char* tex_dirn);
294
296
297 // GLB
299 glbTextureInfo* getGLBTextureInfo(const char* tex_dirn);
300 void freeGLBTextureInfo(glbTextureInfo* tex_info);
301};
302
303
304inline void freeGLTFData(GLTFData* gltf) { if(gltf!=NULL) { gltf->free(); delete gltf; gltf=NULL;} }
305
306
307}
308
309#endif
回転・クォータニオン ライブラリ ヘッダ
三角Contour(Facet)用ライブラリ ヘッダ for BREP
void setUE(bool b)
void addScenes(void)
unsigned int image_no
void addRootNode(AffineTrans< double > *affine)
void createBinDataSeqSoA(MeshFacetNode *facet, int shell_indexes, int shell_vertexes)
unsigned int view_no
GLTFShellNode * shellNode
void addShell(MeshObjectData *meshdata, bool collider, SkinJointData *skin_joint=NULL, tList *joints_info=NULL)
AffineTrans< double > affineRoot
glbTextureInfo * getGLBTextureInfo(const char *tex_dirn)
void init(void)
void freeGLBTextureInfo(glbTextureInfo *tex_info)
tJson * nodes_children
void addMeshes(MeshFacetNode *facet)
tJson * scenes_nodes
unsigned int num_joints
AffineTrans< double > getAffineBaseTrans4Engine(void)
void execAffineUVMap(MeshFacetNode *facet, AffineTrans< double > *affine)
unsigned int skin_no
void addAccessorsAoS(MeshFacetNode *facet)
uDWord convertJson_gltf2glb(glbTextureInfo *tex_info)
unsigned int bin_offset
void createBinDataAoS(void)
Vector< double > center
void addAccessorsSoA(MeshFacetNode *facet)
void createBinDataIBM(SkinJointData *skin_joint, AffineTrans< double > *ue_trans=NULL)
gltfFacetMinMax getFacetMinMax(MeshFacetNode *facet)
void closeSolid(void)
unsigned int material_no
void convertJson_TexturePath(char *tex_dirn)
unsigned int mesh_prim_no
void outputFile(const char *fn, const char *out_dirn, const char *tex_dirn, const char *bin_dirn)
void addMaterials(MeshFacetNode *facet)
void createShellGeometryData(MeshFacetNode *facet, int shell_indexes, int shell_vertexes, SkinJointData *skin_joint=NULL, AffineTrans< double > *ue_trans=NULL)
void addTextures(MeshFacetNode *facet)
tList * material_list
virtual ~GLTFData(void)
void initGLTF(void)
unsigned int shell_no
void addMaterialParameters(tJson *pbr, MeshFacetNode *facet)
unsigned int joint_offset
void addBufferViewsIBM(void)
unsigned int node_offset
void addBufferViewsSoA(MeshFacetNode *facet)
void createBinDataSoA(void)
void setEngine(int)
void output_glb(char *fn, char *out_dirn, char *tex_dirn, char *bin_dirn)
tJson * scenes_name
void createBinDataSeqAoS(MeshFacetNode *facet, int shell_indexes, int shell_vertexes)
unsigned int mesh_no
void setUnity(bool b)
void addSkins(void)
unsigned int accessor_no
void addNodes(AffineTrans< double > *affine)
void addBufferViewsAoS(MeshFacetNode *facet)
unsigned int node_no
void addAccessorsIBM(void)
void addSkeletonNodes(SkinJointData *skin_joint, AffineTrans< double > *affin)
void output_gltf(char *fn, char *out_dirn, char *tex_dirn, char *bin_dirn)
tList * joints_list
unsigned int shell_vertexes
Vector< float > * vn
unsigned int shell_indexes
unsigned int * facet_index
Vector4< short unsigned > * vj
unsigned int num_facets
unsigned int * vi
Vector< float > * vv
unsigned int * facet_vertex
GLTFShellNode * next
UVMap< float > * vu
Vector4< float > * vw
virtual ~GLTFShellNode(void)
MeshObject の Polygonデータ(1面)を格納するクラス.リスト構造を取る.
unsigned int uDWord
4Byte
Definition common.h:336
unsigned char uByte
1Byte
Definition common.h:332
Definition Brep.h:29
void freeGLTFData(GLTFData *gltf)
struct _glb_texture_info * next
Tiny JSON ライブラリヘッダ
ツールライブラリ ヘッダ for C++
Tiny XML ライブラリヘッダ