JunkBox_Lib++ (for Windows) 1.10.1
Loading...
Searching...
No Matches
GLTFData Class Reference

#include <GLTFDataTool.h>

Collaboration diagram for GLTFData:

Public Member Functions

 GLTFData (void)
 
virtual ~GLTFData (void)
 
void init (void)
 
void free (void)
 
void initGLTF (void)
 
void setUnity (bool b)
 
void setUE (bool b)
 
void setEngine (int)
 
void addShell (MeshObjectData *meshdata, bool collider, SkinJointData *skin_joint=NULL, tList *joints_info=NULL)
 
void addScenes (void)
 
void addRootNode (AffineTrans< double > *affine)
 
void addSkeletonNodes (SkinJointData *skin_joint, AffineTrans< double > *affin)
 
void addNodes (AffineTrans< double > *affine)
 
void addTextures (MeshFacetNode *facet)
 
void addMeshes (MeshFacetNode *facet)
 
void addSkins (void)
 
void addMaterials (MeshFacetNode *facet)
 
void addMaterialParameters (tJson *pbr, MeshFacetNode *facet)
 
void closeSolid (void)
 
AffineTrans< double > getAffineBaseTrans4Engine (void)
 
void execAffineUVMap (MeshFacetNode *facet, AffineTrans< double > *affine)
 
void addBufferViewsAoS (MeshFacetNode *facet)
 
void addAccessorsAoS (MeshFacetNode *facet)
 
void createBinDataSeqAoS (MeshFacetNode *facet, int shell_indexes, int shell_vertexes)
 
void addBufferViewsSoA (MeshFacetNode *facet)
 
void addAccessorsSoA (MeshFacetNode *facet)
 
void createBinDataSeqSoA (MeshFacetNode *facet, int shell_indexes, int shell_vertexes)
 
void createShellGeometryData (MeshFacetNode *facet, int shell_indexes, int shell_vertexes, SkinJointData *skin_joint=NULL, AffineTrans< double > *ue_trans=NULL)
 
void createBinDataAoS (void)
 
void createBinDataSoA (void)
 
void addBufferViewsIBM (void)
 
void addAccessorsIBM (void)
 
void createBinDataIBM (SkinJointData *skin_joint, AffineTrans< double > *ue_trans=NULL)
 
void outputFile (const char *fn, const char *out_dirn, const char *tex_dirn, const char *bin_dirn)
 
void output_gltf (char *fn, char *out_dirn, char *tex_dirn, char *bin_dirn)
 
void output_glb (char *fn, char *out_dirn, char *tex_dirn, char *bin_dirn)
 
void convertJson_TexturePath (char *tex_dirn)
 
gltfFacetMinMax getFacetMinMax (MeshFacetNode *facet)
 
uDWord convertJson_gltf2glb (glbTextureInfo *tex_info)
 
glbTextureInfogetGLBTextureInfo (const char *tex_dirn)
 
void freeGLBTextureInfo (glbTextureInfo *tex_info)
 

Public Attributes

Buffer gltf_name
 
Buffer alt_name
 
bool phantom_out
 
bool no_offset
 
int bin_mode
 
bool bin_seq
 
bool glb_out
 
bool forUnity
 
bool forUE
 
int engine
 
bool has_joints
 
bool has_skeleton_node
 
tListjoints_list
 
tListimage_list
 
tListmaterial_list
 
Vector< double > center
 
AffineTrans< double > affineRoot
 
Buffer bin_buffer
 
unsigned int bin_offset
 
unsigned int shell_no
 
unsigned int node_no
 
unsigned int mesh_no
 
unsigned int mesh_prim_no
 
unsigned int skin_no
 
unsigned int view_no
 
unsigned int accessor_no
 
unsigned int material_no
 
unsigned int image_no
 
unsigned int num_joints
 
unsigned int node_offset
 
unsigned int joint_offset
 
tJsonjson_data
 
tJsonscenes
 
tJsonscenes_name
 
tJsonscenes_nodes
 
tJsonnodes
 
tJsonmeshes
 
tJsonskins
 
tJsonbuffers
 
tJsonbuffviews
 
tJsonaccessors
 
tJsonmaterials
 
tJsontextures
 
tJsonimages
 
tJsonnodes_children
 
GLTFShellNodeshellNode
 

Detailed Description

GLTFデータ GLTF のデータを格納するクラス

Definition at line 171 of file GLTFDataTool.h.

Constructor & Destructor Documentation

◆ GLTFData()

GLTFData ( void )
inline

Definition at line 174 of file GLTFDataTool.h.

174{ this->init();}
void init(void)

References GLTFData::init().

Here is the call graph for this function:

◆ ~GLTFData()

~GLTFData ( void )
virtual

Definition at line 84 of file GLTFDataTool.cpp.

85{
86 DEBUG_MODE PRINT_MESG("GLTFData::DESTRUCTOR:\n");
87 this->free();
88}
#define PRINT_MESG(...)
環境依存用の出力関数.MS Windows用は未実装
Definition tools.h:469
#define DEBUG_MODE
Definition tools.h:502

References DEBUG_MODE, GLTFData::free(), and PRINT_MESG.

Here is the call graph for this function:

Member Function Documentation

◆ addAccessorsAoS()

void addAccessorsAoS ( MeshFacetNode * facet)

AoS I(1)xn, {V(3), N(3), U(3), J(4), W(4)}xm ....... facet I(1)xn, {V(3), N(3), U(3), J(4), W(4)}xm ....... facet ...................................................... I(1)xn, {V(3), N(3), U(3), J(4), W(4)}xm ....... facet

Definition at line 931 of file GLTFDataTool.cpp.

932{
933 if (facet==NULL) return;
934 char buf[LBUF];
935
936 unsigned int float_size = (unsigned int)sizeof(float);
937 unsigned int shortu_size = (unsigned int)sizeof(short unsigned int);
938
939 while (facet!=NULL) {
941
942 // accessor of indexies
943 memset(buf, 0, LBUF);
944 snprintf(buf, LBUF-1, JBXL_GLTF_ACCESSORS, this->view_no, 0U, 5125, facet->num_index, "SCALAR"); // 5125: unsigned int
945 json_insert_parse(this->accessors, buf);
946 this->view_no++;
947 this->accessor_no++;
948
949 // accessors of vertex/normal/uvmap
950 unsigned int offset = 0;
951 memset(buf, 0, LBUF);
952 snprintf(buf, LBUF-1, JBXL_GLTF_ACCESSORS_V3, this->view_no, 0U, 5126, facet->num_vertex, "VEC3",
954 json_insert_parse(this->accessors, buf);
955 offset += float_size*3U;
956 this->accessor_no++;
957 //
958 memset(buf, 0, LBUF);
959 snprintf(buf, LBUF-1, JBXL_GLTF_ACCESSORS, this->view_no, offset, 5126, facet->num_vertex, "VEC3"); // 5126: float
960 json_insert_parse(this->accessors, buf);
961 offset += float_size*3U;
962 this->accessor_no++;
963 //
964 memset(buf, 0, LBUF);
965 snprintf(buf, LBUF-1, JBXL_GLTF_ACCESSORS, this->view_no, offset, 5126, facet->num_vertex, "VEC2");
966 json_insert_parse(this->accessors, buf);
967 offset += float_size*2U;
968 this->accessor_no++;
969 //
970 if (this->has_joints) {
971 // weighted joints
972 memset(buf, 0, LBUF);
973 snprintf(buf, LBUF-1, JBXL_GLTF_ACCESSORS, this->view_no, offset, 5123, facet->num_vertex, "VEC4"); // 5123: short unsigned int
974 json_insert_parse(this->accessors, buf);
975 offset += shortu_size*4U;
976 this->accessor_no++;
977 // weight value
978 memset(buf, 0, LBUF);
979 snprintf(buf, LBUF-1, JBXL_GLTF_ACCESSORS, this->view_no, offset, 5126, facet->num_vertex, "VEC4");
980 json_insert_parse(this->accessors, buf);
981 offset += float_size*4U;
982 this->accessor_no++;
983 }
984 this->view_no++;
985 facet = facet->next;
986 }
987 return;
988}
#define JBXL_GLTF_ACCESSORS
#define JBXL_GLTF_ACCESSORS_V3
unsigned int view_no
gltfFacetMinMax getFacetMinMax(MeshFacetNode *facet)
unsigned int accessor_no
int num_index
頂点の延べ数.num_polygon*MeshObjectData::num_vcount (num_polygon*3)(data_index の要素数)
MeshFacetNode * next
int num_vertex
頂点のデータ数.(vertex_value, normal_value の要素数)
#define LBUF
Definition common.h:146
#define snprintf
Definition common.h:56
tJson * json_insert_parse(tJson *json, const char *str)
str をパースして繋げる.str は { または [ で始まる必要がある.
Definition tjson.cpp:1053

References GLTFData::accessor_no, GLTFData::accessors, GLTFData::getFacetMinMax(), GLTFData::has_joints, JBXL_GLTF_ACCESSORS, JBXL_GLTF_ACCESSORS_V3, json_insert_parse(), LBUF, MeshFacetNode::next, MeshFacetNode::num_index, MeshFacetNode::num_vertex, snprintf, gltfFacetMinMax::vertex_x_max, gltfFacetMinMax::vertex_x_min, gltfFacetMinMax::vertex_y_max, gltfFacetMinMax::vertex_y_min, gltfFacetMinMax::vertex_z_max, gltfFacetMinMax::vertex_z_min, and GLTFData::view_no.

Referenced by GLTFData::addShell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addAccessorsIBM()

void addAccessorsIBM ( void )

Definition at line 1787 of file GLTFDataTool.cpp.

1788{
1789 char buf[LBUF];
1790
1791 memset(buf, 0, LBUF);
1792 snprintf(buf, LBUF-1, JBXL_GLTF_ACCESSORS, this->view_no, 0U, 5126, this->num_joints, "MAT4");
1793 json_insert_parse(this->accessors, buf);
1794
1795 this->accessor_no++;
1796 this->mesh_prim_no++;
1797 this->view_no++;
1798}
unsigned int num_joints
unsigned int mesh_prim_no

References GLTFData::accessor_no, GLTFData::accessors, JBXL_GLTF_ACCESSORS, json_insert_parse(), LBUF, GLTFData::mesh_prim_no, GLTFData::num_joints, snprintf, and GLTFData::view_no.

Referenced by GLTFData::addShell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addAccessorsSoA()

void addAccessorsSoA ( MeshFacetNode * facet)

Definition at line 1189 of file GLTFDataTool.cpp.

1190{
1191 if (facet==NULL) return;
1192 char buf[LBUF];
1193
1194 while (facet!=NULL) {
1195 gltfFacetMinMax mm = getFacetMinMax(facet);
1196
1197 // accessor of indexies
1198 memset(buf, 0, LBUF);
1199 snprintf(buf, LBUF-1, JBXL_GLTF_ACCESSORS, this->view_no, 0U, 5125, facet->num_index, "SCALAR"); // 5125: unsigned int
1200 json_insert_parse(this->accessors, buf);
1201 this->view_no++;
1202 this->accessor_no++;
1203
1204 // accessors of vertex/normal/uvmap
1205 memset(buf, 0, LBUF);
1206 snprintf(buf, LBUF-1, JBXL_GLTF_ACCESSORS_V3, this->view_no, 0U, 5126, facet->num_vertex, "VEC3",
1208 json_insert_parse(this->accessors, buf);
1209 this->view_no++;
1210 this->accessor_no++;
1211 //
1212 memset(buf, 0, LBUF);
1213 snprintf(buf, LBUF-1, JBXL_GLTF_ACCESSORS, this->view_no, 0U, 5126, facet->num_vertex, "VEC3"); // 5126: floaat
1214 json_insert_parse(this->accessors, buf);
1215 this->view_no++;
1216 this->accessor_no++;
1217 //
1218 memset(buf, 0, LBUF);
1219 snprintf(buf, LBUF-1, JBXL_GLTF_ACCESSORS, this->view_no, 0U, 5126, facet->num_vertex, "VEC2");
1220 json_insert_parse(this->accessors, buf);
1221 this->view_no++;
1222 this->accessor_no++;
1223
1224 if (this->has_joints) {
1225 // weighted joints
1226 memset(buf, 0, LBUF);
1227 snprintf(buf, LBUF-1, JBXL_GLTF_ACCESSORS, this->view_no, 0U, 5123, facet->num_vertex, "VEC4"); // 5123: short unsigned int
1228 json_insert_parse(this->accessors, buf);
1229 this->view_no++;
1230 this->accessor_no++;
1231 // weight value
1232 memset(buf, 0, LBUF);
1233 snprintf(buf, LBUF-1, JBXL_GLTF_ACCESSORS, this->view_no, 0U, 5126, facet->num_vertex, "VEC4");
1234 json_insert_parse(this->accessors, buf);
1235 this->view_no++;
1236 this->accessor_no++;
1237 }
1238
1239 facet = facet->next;
1240 }
1241 return;
1242}

References GLTFData::accessor_no, GLTFData::accessors, GLTFData::getFacetMinMax(), GLTFData::has_joints, JBXL_GLTF_ACCESSORS, JBXL_GLTF_ACCESSORS_V3, json_insert_parse(), LBUF, MeshFacetNode::next, MeshFacetNode::num_index, MeshFacetNode::num_vertex, snprintf, gltfFacetMinMax::vertex_x_max, gltfFacetMinMax::vertex_x_min, gltfFacetMinMax::vertex_y_max, gltfFacetMinMax::vertex_y_min, gltfFacetMinMax::vertex_z_max, gltfFacetMinMax::vertex_z_min, and GLTFData::view_no.

Referenced by GLTFData::addShell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addBufferViewsAoS()

void addBufferViewsAoS ( MeshFacetNode * facet)

AoS I(1)xn, {V(3), N(3), U(3), J(4), W(4)}xm ....... facet I(1)xn, {V(3), N(3), U(3), J(4), W(4)}xm ....... facet ...................................................... I(1)xn, {V(3), N(3), U(3), J(4), W(4)}xm ....... facet

Definition at line 881 of file GLTFDataTool.cpp.

882{
883 if (facet==NULL) return;
884
885 char buf[LBUF];
886 unsigned int float_size = (unsigned int)sizeof(float);
887 unsigned int uint_size = (unsigned int)sizeof(unsigned int);
888 unsigned int shortu_size = (unsigned int)sizeof(short unsigned int);
889
890 unsigned int v_stride = float_size*8U; // V(3), N(3), U(2)
891 unsigned int j_stride = v_stride + shortu_size*4U + float_size*4U; // V(3), N(3), u(2) + J(4), W(4)
892
893 while (facet!=NULL) {
894 // bufferview of indexies
895 unsigned int i_length = (unsigned int)facet->num_index*uint_size; // I(1) x n
896 memset(buf, 0, LBUF);
897 snprintf(buf, LBUF-1, JBXL_GLTF_VIEWS_ELEMENT, 0, this->bin_offset, i_length);
898 json_insert_parse(this->buffviews, buf);
899 this->bin_offset += i_length;
900
901 if (this->has_joints){
902 // bufferview of vertex/normal/uvmap/weighted joints/weight
903 unsigned int j_length = (unsigned int)facet->num_vertex*j_stride; // (V, N, U, J, W) x n
904 memset(buf, 0, LBUF);
905 snprintf(buf, LBUF-1, JBXL_GLTF_VIEWS, 0, this->bin_offset, j_length, j_stride);
906 json_insert_parse(this->buffviews, buf);
907 this->bin_offset += j_length;
908 }
909 else {
910 // bufferview of vertex/normal/uvmap
911 unsigned int v_length = (unsigned int)facet->num_vertex*v_stride; // (V, N, U) x n
912 memset(buf, 0, LBUF);
913 snprintf(buf, LBUF-1, JBXL_GLTF_VIEWS, 0, this->bin_offset, v_length, v_stride);
914 json_insert_parse(this->buffviews, buf);
915 this->bin_offset += v_length;
916 }
917 facet = facet->next;
918 }
919 return;
920}
#define JBXL_GLTF_VIEWS_ELEMENT
#define JBXL_GLTF_VIEWS
unsigned int bin_offset

References GLTFData::bin_offset, GLTFData::buffviews, GLTFData::has_joints, JBXL_GLTF_VIEWS, JBXL_GLTF_VIEWS_ELEMENT, json_insert_parse(), LBUF, MeshFacetNode::next, MeshFacetNode::num_index, MeshFacetNode::num_vertex, and snprintf.

Referenced by GLTFData::addShell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addBufferViewsIBM()

void addBufferViewsIBM ( void )

Definition at line 1773 of file GLTFDataTool.cpp.

1774{
1775 char buf[LBUF];
1776 unsigned int float_size = (unsigned int)sizeof(float);
1777
1778 // 4x4 matrix
1779 unsigned int length = float_size*16U*this->num_joints;
1780 memset(buf, 0, LBUF);
1781 snprintf(buf, LBUF-1, JBXL_GLTF_VIEWS_DATA, 0, this->bin_offset, length);
1782 json_insert_parse(this->buffviews, buf);
1783 this->bin_offset += length;
1784}
#define JBXL_GLTF_VIEWS_DATA

References GLTFData::bin_offset, GLTFData::buffviews, JBXL_GLTF_VIEWS_DATA, json_insert_parse(), LBUF, GLTFData::num_joints, and snprintf.

Referenced by GLTFData::addShell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addBufferViewsSoA()

void addBufferViewsSoA ( MeshFacetNode * facet)

SoA Ixn, Vxm, Nxm, Uxm, Jxm ,Wxm ...... facet Ixn, Vxm, Nxm, Uxm, Jxm ,Wxm ...... facet ......................................... Ixn, Vxm, Nxm, Uxm, Jxm ,Wxm ...... facet

Definition at line 1129 of file GLTFDataTool.cpp.

1130{
1131 if (facet==NULL) return;
1132 char buf[LBUF];
1133
1134 unsigned int length = 0;
1135 unsigned int float_size = (unsigned int)sizeof(float);
1136 unsigned int uint_size = (unsigned int)sizeof(unsigned int);
1137 unsigned int shortu_size = (unsigned int)sizeof(short unsigned int);
1138
1139 while (facet!=NULL) {
1140 // bufferview of indexies
1141 length = (unsigned int)facet->num_index*uint_size;
1142 memset(buf, 0, LBUF);
1143 snprintf(buf, LBUF-1, JBXL_GLTF_VIEWS_ELEMENT, 0, this->bin_offset, length);
1144 json_insert_parse(this->buffviews, buf);
1145 this->bin_offset += length;
1146
1147 // bufferview of vertex
1148 length = (unsigned int)facet->num_vertex*float_size*3U;
1149 memset(buf, 0, LBUF);
1150 snprintf(buf, LBUF-1, JBXL_GLTF_VIEWS, 0, this->bin_offset, length, float_size*3U);
1151 json_insert_parse(this->buffviews, buf);
1152 this->bin_offset += length;
1153
1154 // bufferview of normal
1155 length = (unsigned int)facet->num_vertex*float_size*3U;
1156 memset(buf, 0, LBUF);
1157 snprintf(buf, LBUF-1, JBXL_GLTF_VIEWS, 0, this->bin_offset, length, float_size*3U);
1158 json_insert_parse(this->buffviews, buf);
1159 this->bin_offset += length;
1160
1161 // bufferview of uvmap
1162 length = (unsigned int)facet->num_vertex*float_size*2U;
1163 memset(buf, 0, LBUF);
1164 snprintf(buf, LBUF-1, JBXL_GLTF_VIEWS, 0, this->bin_offset, length, float_size*2U);
1165 json_insert_parse(this->buffviews, buf);
1166 this->bin_offset += length;
1167
1168 if (this->has_joints) {
1169 // weighted joint number
1170 length = (unsigned int)facet->num_vertex*shortu_size*4U;
1171 memset(buf, 0, LBUF);
1172 snprintf(buf, LBUF-1, JBXL_GLTF_VIEWS, 0, this->bin_offset, length, shortu_size*4U);
1173 json_insert_parse(this->buffviews, buf);
1174 this->bin_offset += length;
1175
1176 // weight value
1177 length = (unsigned int)facet->num_vertex*float_size*4U;
1178 memset(buf, 0, LBUF);
1179 snprintf(buf, LBUF-1, JBXL_GLTF_VIEWS, 0, this->bin_offset, length, float_size*4U);
1180 json_insert_parse(this->buffviews, buf);
1181 this->bin_offset += length;
1182 }
1183 facet = facet->next;
1184 }
1185 return;
1186}

References GLTFData::bin_offset, GLTFData::buffviews, GLTFData::has_joints, JBXL_GLTF_VIEWS, JBXL_GLTF_VIEWS_ELEMENT, json_insert_parse(), LBUF, MeshFacetNode::next, MeshFacetNode::num_index, MeshFacetNode::num_vertex, and snprintf.

Referenced by GLTFData::addShell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addMaterialParameters()

void addMaterialParameters ( tJson * pbr,
MeshFacetNode * facet )

void GLTFData::addMaterialParameters(tJson* pbr, MeshFacetNode* facet)

マテリアルのパラメータを設定する.

glTF-2.0.html 5.19. Material

Definition at line 718 of file GLTFDataTool.cpp.

719{
720 char buf[LBUF];
721
722 MaterialParam param = facet->material_param;
723 TextureParam texture = param.texture;
724
725 char kind_obj = param.getKind();
726 bool hasAlpha = texture.hasAlphaChannel();
727 int alpha_mode = texture.getAlphaMode();
728
729 float red = (float)texture.getColor(0);
730 float green = (float)texture.getColor(1);
731 float blue = (float)texture.getColor(2);
732 float transp = (float)texture.getColor(3);
733 memset(buf, 0, LBUF);
734 snprintf(buf, LBUF-1, JBXL_GLTF_MTLS_BCOLORF, red, green, blue, transp);
735 json_insert_parse(pbr, buf);
736
737 if (kind_obj!='E') { // !Earth
738 float shininess = (float)param.getShininess();
739 memset(buf, 0, LBUF);
740 snprintf(buf, LBUF-1, JBXL_GLTF_MTLS_ROUGHF, 1.0f - shininess);
741 json_insert_parse(pbr, buf);
742 }
743
744 //
745 // bright(0 or 1), light(?)
746 //
747 if (kind_obj=='T' || kind_obj=='G') { // Tree and Grass
748 json_insert_parse(pbr->prev, "{\"alphaMode\":\"BLEND\"}");
749 }
750 else if (alpha_mode==MATERIAL_ALPHA_NONE) {
751 json_insert_parse(pbr->prev, "{\"alphaMode\":\"OPAQUE\"}");
752 }
753 else if (alpha_mode==MATERIAL_ALPHA_BLENDING && hasAlpha) {
754 json_insert_parse(pbr->prev, "{\"alphaMode\":\"BLEND\"}");
755 }
756 else if (alpha_mode==MATERIAL_ALPHA_MASKING && hasAlpha) {
757 json_insert_parse(pbr->prev, "{\"alphaMode\":\"MASK\"}");
758 float cutoff = (float)texture.getAlphaCutoff();
759 memset(buf, 0, LBUF);
760 snprintf(buf, LBUF-1, JBXL_GLTF_MTLS_CUTOFF, cutoff);
761 json_insert_parse(pbr->prev, buf);
762 }
763 //else if (alpha_mode==MATERIAL_ALPHA_EMISSIVE) {
764 //}
765 else {
766 if (transp<=0.99) {
767 json_insert_parse(pbr->prev, "{\"alphaMode\":\"BLEND\"}");
768 }
769 else {
770 json_insert_parse(pbr->prev, "{\"alphaMode\":\"OPAQUE\"}");
771 }
772 }
773
774 float glow = (float)param.getGlow();
775 if (glow>0.0) {
776 memset(buf, 0, LBUF);
777 snprintf(buf, LBUF-1, JBXL_GLTF_MTLS_EMISSIVE, glow*red, glow*green, glow*blue);
778 json_insert_parse(pbr->prev, buf);
779 }
780
781 DEBUG_MODE param.printParam(stderr);
782 return;
783}
#define JBXL_GLTF_MTLS_BCOLORF
#define JBXL_GLTF_MTLS_CUTOFF
#define JBXL_GLTF_MTLS_ROUGHF
#define JBXL_GLTF_MTLS_EMISSIVE
#define MATERIAL_ALPHA_MASKING
#define MATERIAL_ALPHA_NONE
#define MATERIAL_ALPHA_BLENDING
void printParam(FILE *fp)
TextureParam texture
テクスチャ
double getShininess(void)
MaterialParam material_param
マテリアルパラメータ
double getAlphaCutoff(void)
bool hasAlphaChannel(void)
Vector< double > getColor(void)

References DEBUG_MODE, TextureParam::getAlphaCutoff(), TextureParam::getAlphaMode(), TextureParam::getColor(), MaterialParam::getGlow(), MaterialParam::getKind(), MaterialParam::getShininess(), TextureParam::hasAlphaChannel(), JBXL_GLTF_MTLS_BCOLORF, JBXL_GLTF_MTLS_CUTOFF, JBXL_GLTF_MTLS_EMISSIVE, JBXL_GLTF_MTLS_ROUGHF, json_insert_parse(), LBUF, MATERIAL_ALPHA_BLENDING, MATERIAL_ALPHA_MASKING, MATERIAL_ALPHA_NONE, MeshFacetNode::material_param, MaterialParam::printParam(), snprintf, and MaterialParam::texture.

Referenced by GLTFData::addMaterials().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addMaterials()

void addMaterials ( MeshFacetNode * facet)

Definition at line 666 of file GLTFDataTool.cpp.

667{
668 if (facet==NULL) return;
669 char buf[LBUF];
670
671 while (facet!=NULL) {
672 if (!facet->same_material) {
673 char* material_name = (char*)facet->material_id.buf;
674 if (material_name[0]=='#') material_name++;
675 //
676 tList* lt = search_key_tList(this->material_list, material_name, 1);
677 if (lt==NULL) {
678 tList* ltend = find_tList_end(this->material_list);
679 add_tList_node_bystr(ltend, this->material_no, 0, material_name, NULL, NULL, 0);
680 //
681 char* image_name = (char*)facet->material_param.texture.getName();
682 Buffer file_name = make_Buffer_bystr(image_name);
683 canonical_filename_Buffer(&file_name, TRUE);
684 int img_no = 0;
685 lt = search_key_tList(this->image_list, (char*)file_name.buf, 1);
686 if (lt!=NULL) {
687 img_no = lt->ldat.id;
688 }
689 else {
690 PRINT_MESG("GLTFData::addMaterials: ERROR: lost image file (%s). this is coding miss!\n", (char*)file_name.buf);
691 }
692 free_Buffer(&file_name);
693 //
694 memset(buf, 0, LBUF);
695 snprintf(buf, LBUF-1, JBXL_GLTF_MTLS_NAME_PBR, material_name, img_no);
696 json_insert_parse(this->materials, buf);
697 tJson* pbr = search_key_json(this->materials, "pbrMetallicRoughness", FALSE, this->material_no + 1);
698 if (pbr!=NULL) {
699 this->addMaterialParameters(pbr, facet);
700 }
701 this->material_no++;
702 }
703 }
704 facet = facet->next;
705 }
706 return;
707}
#define JBXL_GLTF_MTLS_NAME_PBR
void free_Buffer(Buffer *buf)
Buffer型変数のバッファ部を解放する
Definition buffer.cpp:128
#define make_Buffer_bystr(str)
set_Buffer()
Definition buffer.h:57
unsigned int material_no
tList * material_list
void addMaterialParameters(tJson *pbr, MeshFacetNode *facet)
bool same_material
他の Node が既に同じマテリアルを使用している.
Buffer material_id
マテリアルを識別するID.JBXL_MATERIAL_PREFIX で始まる.
char * getName(void)
#define TRUE
Definition common.h:226
#define FALSE
Definition common.h:223
unsigned char * buf
バッファの先頭へのポインタ.str[bufsz]は必ず 0x00となる.
Definition buffer.h:39
tJson * search_key_json(tJson *pp, const char *key, int needval, int nn)
名前(属性名)が key である nn番目のノードへのポインタを返す
Definition tjson.cpp:1378
tList * find_tList_end(tList *pl)
リストの最後のノードを探す.
Definition tlist.cpp:1023
tList * add_tList_node_bystr(tList *pp, int id, int lv, const char *key, const char *val, void *ptr, int sz)
文字列データからリスト用ノードを生成し(new),それをリストに追加.
Definition tlist.cpp:462
tList * search_key_tList(tList *pl, const char *key, int no)
リストの中から no番目の keyノード(ldat.key)を探し出し,tListへのポインタを返す.大文字小文字を無視.
Definition tlist.cpp:1571
void canonical_filename_Buffer(Buffer *fname, int no_dir)
fname の問題になりそうな ASCII文字を '_' に変換する.
Definition xtools.cpp:2057

References add_tList_node_bystr(), GLTFData::addMaterialParameters(), Buffer::buf, canonical_filename_Buffer(), FALSE, find_tList_end(), free_Buffer(), TextureParam::getName(), GLTFData::image_list, JBXL_GLTF_MTLS_NAME_PBR, json_insert_parse(), LBUF, make_Buffer_bystr, MeshFacetNode::material_id, GLTFData::material_list, GLTFData::material_no, MeshFacetNode::material_param, GLTFData::materials, MeshFacetNode::next, PRINT_MESG, MeshFacetNode::same_material, search_key_json(), search_key_tList(), snprintf, MaterialParam::texture, and TRUE.

Referenced by GLTFData::addShell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addMeshes()

void addMeshes ( MeshFacetNode * facet)

Definition at line 786 of file GLTFDataTool.cpp.

787{
788 if (facet==NULL) return;
789 char buf[LBUF];
790 int acsr_no = 0;
791
792 tJson* primitives = json_append_array_key(this->meshes, "primitives");
793 while (facet!=NULL) {
794 char* material_name = (char*)facet->material_id.buf;
795 if (material_name[0]=='#') material_name++;
796 //
797 int mtl_no = 0;
798 tList* lt = search_key_tList(this->material_list, material_name, 1);
799 if (lt!=NULL) {
800 mtl_no = lt->ldat.id;
801 }
802 else {
803 PRINT_MESG("GLTFData::addMeshes: ERROR: lost material (%s). this is coding miss!\n", material_name);
804 }
805 //
806 memset(buf, 0, LBUF);
807 if (this->has_joints) {
808 acsr_no = this->mesh_prim_no;
809 snprintf(buf, LBUF-1, JBXL_GLTF_MESHES_PRIM_JW, acsr_no, acsr_no+1, acsr_no+2, acsr_no+3, acsr_no+4, acsr_no+5, mtl_no);
810 this->mesh_prim_no += 6;
811 }
812 else {
813 acsr_no = this->mesh_prim_no;
814 snprintf(buf, LBUF-1, JBXL_GLTF_MESHES_PRIM, acsr_no, acsr_no+1, acsr_no+2, acsr_no+3, mtl_no);
815 this->mesh_prim_no += 4;
816 }
817 json_insert_parse(primitives, buf);
818
819 this->mesh_no++;
820 facet = facet->next;
821 }
822 return;
823}
#define JBXL_GLTF_MESHES_PRIM
#define JBXL_GLTF_MESHES_PRIM_JW
unsigned int mesh_no
tJson * json_append_array_key(tJson *json, const char *key)
値(value)なしの配列 "key":[] を追加する.
Definition tjson.cpp:1115

References Buffer::buf, GLTFData::has_joints, JBXL_GLTF_MESHES_PRIM, JBXL_GLTF_MESHES_PRIM_JW, json_append_array_key(), json_insert_parse(), LBUF, MeshFacetNode::material_id, GLTFData::material_list, GLTFData::mesh_no, GLTFData::mesh_prim_no, GLTFData::meshes, MeshFacetNode::next, PRINT_MESG, search_key_tList(), and snprintf.

Referenced by GLTFData::addShell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addNodes()

void addNodes ( AffineTrans< double > * affine)

Definition at line 474 of file GLTFDataTool.cpp.

475{
476 char buf[LBUF];
477
478 // nodes
479 Buffer node_name = init_Buffer();
480 if (this->alt_name.buf!=NULL) {
481 node_name = dup_Buffer(this->alt_name);
482 }
483 else {
484 node_name = make_Buffer_bystr("Node_#");
485 cat_i2Buffer(this->node_no, &node_name);
486 }
487
488 memset(buf, 0, LBUF);
489 snprintf(buf, LBUF-1, JBXL_GLTF_NODES_MESH, (char*)node_name.buf, this->shell_no);
490 tJson* mesh = json_insert_parse(this->nodes, buf);
491 free_Buffer(&node_name);
492
493 if (this->has_joints) {
494 // skins
495 memset(buf, 0, LBUF);
497 json_insert_parse(mesh, buf);
498 }
499 //else {
500 if (!this->has_joints || this->engine==JBXL_3D_ENGINE_UE) { // for UE5 Bug
501 // affine translarion
502 tJson* matrix = json_append_array_key(mesh, "matrix");
503 if (affine!=NULL) {
506 bstrans.affineMatrixAfter(*affine);
507 bstrans.affineMatrixBefore(invroot);
508 bstrans.computeMatrix();
509
510 for (int j=1; j<=4; j++) {
511 for (int i=1; i<=4; i++) {
512 float element = (float)bstrans.element(i, j);
514 }
515 }
516 bstrans.free();
517 invroot.free();
518 }
519 }
520
522 this->node_no++;
523
524 return;
525}
#define JBXL_GLTF_NODES_SKIN
#define JBXL_GLTF_NODES_MESH
Buffer init_Buffer()
初期化したBuffer型変数を返す.
Definition buffer.cpp:47
Buffer dup_Buffer(Buffer buf)
Buffer型変数のコピーをつくる.
Definition buffer.cpp:211
int cat_i2Buffer(int src, Buffer *dst)
整数 srcを文字列に変換して,dstへ catする.
Definition buffer.cpp:678
void computeMatrix(bool with_scale=true)
AffineTrans< T > getInverseAffine(void)
void affineMatrixAfter(AffineTrans< T > a)
void element(int i, int j, T v)
Definition AffineTrans.h:88
void affineMatrixBefore(AffineTrans< T > a)
void free(void)
Definition AffineTrans.h:49
AffineTrans< double > affineRoot
tJson * nodes_children
AffineTrans< double > getAffineBaseTrans4Engine(void)
unsigned int skin_no
unsigned int node_no
#define JBXL_3D_ENGINE_UE
Definition common.h:311
void json_append_array_real_val(tJson *json, float val)
配列 [] の要素として 実数 val を追加する.
Definition tjson.cpp:1280
void json_append_array_int_val(tJson *json, int val)
配列 [] の要素として 整数 val を追加する.
Definition tjson.cpp:1257

References AffineTrans< T >::affineMatrixAfter(), AffineTrans< T >::affineMatrixBefore(), GLTFData::affineRoot, GLTFData::alt_name, Buffer::buf, cat_i2Buffer(), AffineTrans< T >::computeMatrix(), dup_Buffer(), AffineTrans< T >::element(), GLTFData::engine, AffineTrans< T >::free(), free_Buffer(), GLTFData::getAffineBaseTrans4Engine(), AffineTrans< T >::getInverseAffine(), GLTFData::has_joints, init_Buffer(), JBXL_3D_ENGINE_UE, JBXL_GLTF_NODES_MESH, JBXL_GLTF_NODES_SKIN, json_append_array_int_val(), json_append_array_key(), json_append_array_real_val(), json_insert_parse(), LBUF, make_Buffer_bystr, GLTFData::node_no, GLTFData::nodes, GLTFData::nodes_children, GLTFData::skin_no, and snprintf.

Referenced by GLTFData::addShell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addRootNode()

void addRootNode ( AffineTrans< double > * affine)

Definition at line 441 of file GLTFDataTool.cpp.

442{
443 // Root node of model
445 this->nodes_children = json_append_array_key(nodes_root, "children");
446
447 if (affine!=NULL) {
448 affine->computeMatrix();
450 this->affineRoot.affineMatrixAfter(*affine);
452
453 for (int j=1; j<=3; j++) {
454 for (int i=1; i<=4; i++) {
455 if (i==j) this->affineRoot.element(i, j, 1.0f);
456 else this->affineRoot.element(i, j, 0.0f);
457 }
458 }
460 //
461 tJson* root_matrix = json_append_array_key(nodes_root, "matrix");
462 for (int j=1; j<=4; j++) {
463 for (int i=1; i<=4; i++) {
464 json_append_array_real_val(root_matrix, (float)this->affineRoot.element(i, j));
465 }
466 }
467 }
468
469 this->node_no++;
470 return;
471}
#define JBXL_GLTF_NODES_ROOT
void computeComponents(void)

References AffineTrans< T >::affineMatrixAfter(), GLTFData::affineRoot, AffineTrans< T >::computeComponents(), AffineTrans< T >::computeMatrix(), AffineTrans< T >::element(), GLTFData::getAffineBaseTrans4Engine(), JBXL_GLTF_NODES_ROOT, json_append_array_key(), json_append_array_real_val(), json_insert_parse(), GLTFData::node_no, GLTFData::nodes, and GLTFData::nodes_children.

Referenced by GLTFData::addShell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addScenes()

void addScenes ( void )

Definition at line 430 of file GLTFDataTool.cpp.

431{
432 if (this->node_no==0) {
433 json_set_str_val(this->scenes_name, (char*)this->gltf_name.buf);
435 this->node_offset = 1;
436 }
437 return;
438}
tJson * scenes_nodes
unsigned int node_offset
tJson * scenes_name
void json_set_str_val(tJson *json, const char *val)
json ノード "key":val に文字列の属性値(value)を設定する.
Definition tjson.cpp:888

References Buffer::buf, GLTFData::gltf_name, json_append_array_int_val(), json_set_str_val(), GLTFData::node_no, GLTFData::node_offset, GLTFData::scenes_name, and GLTFData::scenes_nodes.

Referenced by GLTFData::addShell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addShell()

void addShell ( MeshObjectData * shelldata,
bool collider,
SkinJointData * skin_joint = NULL,
tList * joints_connection = NULL )

void GLTFData::addShell(MeshObjectData* shelldata, bool collider, SkinJointData* skin_joint, tList* joints_connection)

この関数は SOLID毎に複数回呼ばれ,SOLIDに SHELLを追加する.

Parameters
shelldataSHELLデータ.複数の FACETを含む.
colliderコライダーのサポート
skin_jointジョイントデータ.デフォルトは NULL
joints_connectionジョイントの連結情報.デフォルトは NULL

Definition at line 301 of file GLTFDataTool.cpp.

302{
303 if (shelldata==NULL) return;
304
305 if (this->shell_no==0 && this->gltf_name.buf==NULL) {
306 if (shelldata->data_name.buf!=NULL) this->gltf_name = dup_Buffer(shelldata->data_name);
307 else this->gltf_name = make_Buffer_bystr("Object");
308 }
309 if (shelldata->alt_name.buf!=NULL) {
310 this->alt_name = dup_Buffer(shelldata->alt_name);
311 }
312
313 this->has_joints = false;
314 this->num_joints = 0;
315 if (skin_joint!=NULL) {
316 this->has_joints = true;
317 this->num_joints = skin_joint->num_joints;
318 if (joints_connection!=NULL) {
319 if (this->joints_list==NULL) {
320 this->joints_list = joints_connection;
321 }
322 else {
323 if (this->joints_list!=NULL) del_tList(&this->joints_list);
324 this->joints_list = NULL;
325 if (this->has_joints) {
326 this->joints_list = joints_connection;
327 }
328 }
329 }
330 }
331
332 MeshFacetNode* facet = shelldata->facet;
333 int shell_indexes = 0;
334 int shell_vertexes = 0;
335 while (facet!=NULL) {
336 shell_indexes += facet->num_index;
337 shell_vertexes += facet->num_vertex;
338 facet = facet->next;
339 }
340
341 AffineTrans<double>* affine = shelldata->affineTrans;
342 if (no_offset && affine!=NULL) {
343 if (this->shell_no==0) {
344 this->center = affine->getShift();
345 }
346 affine->setShift(affine->getShift() - this->center);
347 affine->computeMatrix();
348 }
349 facet = shelldata->facet;
350
351 //
352 this->addScenes();
353 if (this->node_no==0) {
354 this->addRootNode(affine);
355 }
356 if (this->has_joints && !this->has_skeleton_node) {
357 this->addSkeletonNodes(skin_joint, affine);
358 this->has_skeleton_node = true;
359 }
360 this->addNodes(affine);
361
362 this->addTextures(facet);
363 this->addMaterials(facet);
364
365 this->addMeshes(facet);
366 this->execAffineUVMap(facet, affine);
367
368 // for bin data
369 if (this->bin_mode==JBXL_GLTF_BIN_AOS) {
370 this->addBufferViewsAoS(facet);
371 this->addAccessorsAoS(facet);
372 }
373 else {
374 this->addBufferViewsSoA(facet);
375 this->addAccessorsSoA(facet);
376 }
377
378 if (this->has_joints) {
379 this->addSkins();
380 this->addBufferViewsIBM();
381 this->addAccessorsIBM();
382 }
383 else {
384 //del_json_node(&this->skins); // --> closeSolid()
385 }
386
387 // for UE5 Bug
388 AffineTrans<double> ue_trans;
389 ue_trans.init();
390 if (affine!=NULL && this->engine==JBXL_3D_ENGINE_UE) {
393 bstrans.affineMatrixAfter(*affine);
394 bstrans.affineMatrixBefore(invroot);
395 ue_trans = bstrans.getInverseAffine();
396 ue_trans.computeMatrix();
397 bstrans.free();
398 invroot.free();
399 }
400
401 // BINデータ作成
402 if (this->bin_seq) {
403 // その都度 BINデータを作成していく
404 if (this->bin_mode==JBXL_GLTF_BIN_AOS) {
405 this->createBinDataSeqAoS(facet, shell_indexes, shell_vertexes);
406 }
407 else {
408 this->createBinDataSeqSoA(facet, shell_indexes, shell_vertexes);
409 }
410 if (this->has_joints) this->createBinDataIBM(skin_joint, &ue_trans);
411 }
412 else {
413 // データを一旦 GLTFShellNodeに保存.最後に closeSolid() で一気に BINデータを作成
414 this->createShellGeometryData(facet, shell_indexes, shell_vertexes, skin_joint, &ue_trans);
415 }
416 ue_trans.free();
417
418 //
419 this->phantom_out = true;
420 if (collider) {
421 this->phantom_out = false;
422 }
423 //
424 free_Buffer(&this->alt_name);
425 this->shell_no++;
426 return;
427}
#define JBXL_GLTF_BIN_AOS
void setShift(T x, T y, T z)
Definition AffineTrans.h:70
void init(void)
Definition AffineTrans.h:44
Vector< T > getShift(void)
void addScenes(void)
void addRootNode(AffineTrans< double > *affine)
void createBinDataSeqSoA(MeshFacetNode *facet, int shell_indexes, int shell_vertexes)
void addMeshes(MeshFacetNode *facet)
void execAffineUVMap(MeshFacetNode *facet, AffineTrans< double > *affine)
void addAccessorsAoS(MeshFacetNode *facet)
Vector< double > center
void addAccessorsSoA(MeshFacetNode *facet)
void createBinDataIBM(SkinJointData *skin_joint, AffineTrans< double > *ue_trans=NULL)
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)
unsigned int shell_no
void addBufferViewsIBM(void)
void addBufferViewsSoA(MeshFacetNode *facet)
void createBinDataSeqAoS(MeshFacetNode *facet, int shell_indexes, int shell_vertexes)
void addSkins(void)
void addNodes(AffineTrans< double > *affine)
void addBufferViewsAoS(MeshFacetNode *facet)
void addAccessorsIBM(void)
void addSkeletonNodes(SkinJointData *skin_joint, AffineTrans< double > *affin)
tList * joints_list
MeshObject の Polygonデータ(1面)を格納するクラス.リスト構造を取る.
Buffer data_name
データ名
AffineTrans< double > * affineTrans
アフィン変換.ここで使用するのは,shift, rotate, scale(size) のみ
MeshFacetNode * facet
FACETデータ(1面のポリゴンデータ)のリストへのポインタ
int num_joints
Jointの数.
tList * del_tList(tList **pp)
指定したリストノード以降のリストを削除.
Definition tlist.cpp:735

References GLTFData::addAccessorsAoS(), GLTFData::addAccessorsIBM(), GLTFData::addAccessorsSoA(), GLTFData::addBufferViewsAoS(), GLTFData::addBufferViewsIBM(), GLTFData::addBufferViewsSoA(), GLTFData::addMaterials(), GLTFData::addMeshes(), GLTFData::addNodes(), GLTFData::addRootNode(), GLTFData::addScenes(), GLTFData::addSkeletonNodes(), GLTFData::addSkins(), GLTFData::addTextures(), AffineTrans< T >::affineMatrixAfter(), AffineTrans< T >::affineMatrixBefore(), GLTFData::affineRoot, MeshObjectData::affineTrans, GLTFData::alt_name, MeshObjectData::alt_name, GLTFData::bin_mode, GLTFData::bin_seq, Buffer::buf, GLTFData::center, AffineTrans< T >::computeMatrix(), GLTFData::createBinDataIBM(), GLTFData::createBinDataSeqAoS(), GLTFData::createBinDataSeqSoA(), GLTFData::createShellGeometryData(), MeshObjectData::data_name, del_tList(), dup_Buffer(), GLTFData::engine, GLTFData::execAffineUVMap(), MeshObjectData::facet, AffineTrans< T >::free(), free_Buffer(), GLTFData::getAffineBaseTrans4Engine(), AffineTrans< T >::getInverseAffine(), AffineTrans< T >::getShift(), GLTFData::gltf_name, GLTFData::has_joints, GLTFData::has_skeleton_node, AffineTrans< T >::init(), JBXL_3D_ENGINE_UE, JBXL_GLTF_BIN_AOS, GLTFData::joints_list, make_Buffer_bystr, MeshFacetNode::next, GLTFData::no_offset, GLTFData::node_no, MeshFacetNode::num_index, SkinJointData::num_joints, GLTFData::num_joints, MeshFacetNode::num_vertex, GLTFData::phantom_out, AffineTrans< T >::setShift(), and GLTFData::shell_no.

Here is the call graph for this function:

◆ addSkeletonNodes()

void addSkeletonNodes ( SkinJointData * skin_joint,
AffineTrans< double > * affin )

Definition at line 528 of file GLTFDataTool.cpp.

529{
530 char buf[LBUF];
531 memset(buf, 0, LBUF);
532
533 this->node_offset++;
534 this->joint_offset = this->node_no - 1;
536
537 // Root node of skeletons
538 tJson* skeleton_root = json_insert_parse(this->nodes, JBXL_GLTF_NODES_ARMATURE);
539 tJson* skeleton_children = json_append_array_key(skeleton_root, "children");
540 json_append_array_int_val(skeleton_children, this->node_offset + this->joint_offset);
541 this->node_no++;
542
543 if (affine!=NULL) {
544 int pelvis_num = -1;
545 if (this->joints_list!=NULL && this->joints_list->next!=NULL) {
546 pelvis_num = this->joints_list->next->ldat.id;
547 }
548 if (pelvis_num>=0) {
550 pelvis.x = skin_joint->alt_inverse_bind[pelvis_num].element(1, 4);
551 pelvis.y = skin_joint->alt_inverse_bind[pelvis_num].element(2, 4);
552 pelvis.z = skin_joint->alt_inverse_bind[pelvis_num].element(3, 4);
553
554 AffineTrans<double> joint_space = skin_joint->inverse_bind[pelvis_num] * skin_joint->bind_shape;
555 AffineTrans<double> joint_trans = joint_space.getInverseAffine();
556 Vector<double> shift = joint_trans.execRotationScale(pelvis);
557 joint_trans.setShift(joint_trans.getShift() - shift);
558
561 trans.affineMatrixAfter(*affine);
562 trans.affineMatrixBefore(invroot);
563 //
564 joint_trans.computeMatrix();
565 trans.affineMatrixAfter(joint_trans);
566 trans.computeMatrix();
567
569 tJson* skeleton_matrix = json_append_array_key(skeleton_root, "matrix");
570 for (int j=1; j<=4; j++) {
571 for (int i=1; i<=4; i++) {
572 float element = (float)trans.element(i, j);
573 json_append_array_real_val(skeleton_matrix, element);
574 }
575 }
576
577 trans.free();
578 invroot.free();
579 joint_space.free();
580 joint_trans.free();
581 }
582 }
583
584 //
585 tList* jl = this->joints_list;
586 if (jl!=NULL) jl = jl->next; // top is Json ACKHOR
587 tList* jt = jl;
588
589 while (jl!=NULL) {
590 int jnt = jl->ldat.id;
591 // order check!
592 if (strncmp((char*)jl->ldat.val.buf+1, skin_joint->joint_names.get_value(jnt), strlen(skin_joint->joint_names.get_value(jnt)))) {
593 PRINT_MESG("GLTFData::addSkeletonNodes: ERROR: Joint is not in the correct order. %s != \"%s\"\n",
594 (char*)jl->ldat.val.buf, skin_joint->joint_names.get_value(jnt));
595 }
596 //
597 memset(buf, 0, LBUF);
598 snprintf(buf, LBUF-1, JBXL_GLTF_NODES_SKLTN, (char*)jl->ldat.val.buf);
599 tJson* skltn = json_insert_parse(this->nodes, buf);
600 tJson* children = json_append_array_key(skltn, "children");
601 //
602 int count = 0;
603 int lnum = 0; // リストのノードの位置(順番)
604 tList* jp = jt; // top
605 while (jp!=NULL) {
606 if (jp->ldat.lv==jl->ldat.id) {
607 //json_append_array_int_val(children, jp->ldat.id + this->node_offset);
608 json_append_array_int_val(children, lnum + this->node_offset + joint_offset);
609 count++;
610 }
611 lnum++;
612 jp = jp->next;
613 }
614 if (count==0) {
615 del_json_node(&children);
616 }
617
618 skin_joint->alt_inverse_bind[jnt].computeComponents();
619 tJson* shift = json_append_array_key(skltn, "translation");
620 json_append_array_real_val(shift, (float)skin_joint->alt_inverse_bind[jnt].getShiftX());
621 json_append_array_real_val(shift, (float)skin_joint->alt_inverse_bind[jnt].getShiftY());
622 json_append_array_real_val(shift, (float)skin_joint->alt_inverse_bind[jnt].getShiftZ());
623
624 this->node_no++;
625 jl = jl->next;
626 }
627 return;
628}
#define JBXL_GLTF_NODES_ARMATURE
#define JBXL_GLTF_NODES_SKLTN
Vector< T > execRotationScale(Vector< T > v)
T get_value(int n)
Definition tools++.h:96
unsigned int joint_offset
AffineTrans< double > bind_shape
AffineTrans< double > * alt_inverse_bind
AffineTrans< double > * inverse_bind
ArrayParam< char * > joint_names
Joint名の配列.
#define del_json_node(j)
JSONデータのノード削除 del_tTree_node()
Definition tjson.h:62

References AffineTrans< T >::affineMatrixAfter(), AffineTrans< T >::affineMatrixBefore(), GLTFData::affineRoot, SkinJointData::alt_inverse_bind, SkinJointData::bind_shape, AffineTrans< T >::computeComponents(), AffineTrans< T >::computeMatrix(), del_json_node, AffineTrans< T >::element(), AffineTrans< T >::execRotationScale(), AffineTrans< T >::free(), ArrayParam< T >::get_value(), GLTFData::getAffineBaseTrans4Engine(), AffineTrans< T >::getInverseAffine(), AffineTrans< T >::getShift(), AffineTrans< T >::getShiftX(), AffineTrans< T >::getShiftY(), AffineTrans< T >::getShiftZ(), SkinJointData::inverse_bind, JBXL_GLTF_NODES_ARMATURE, JBXL_GLTF_NODES_SKLTN, SkinJointData::joint_names, GLTFData::joint_offset, GLTFData::joints_list, json_append_array_int_val(), json_append_array_key(), json_append_array_real_val(), json_insert_parse(), LBUF, GLTFData::node_no, GLTFData::node_offset, GLTFData::nodes, GLTFData::nodes_children, PRINT_MESG, AffineTrans< T >::setShift(), snprintf, Vector< T >::x, Vector< T >::y, and Vector< T >::z.

Referenced by GLTFData::addShell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addSkins()

void addSkins ( void )

Definition at line 826 of file GLTFDataTool.cpp.

827{
828 if (!this->has_joints) return;
829 char buf[LBUF];
830
831 memset(buf, 0, LBUF);
832 snprintf(buf, LBUF-1, JBXL_GLTF_SKINS, this->accessor_no, this->node_offset + this->joint_offset - 1);
833 tJson* skn = json_insert_parse(skins, buf);
834 tJson* jnt = json_append_array_key(skn, "joints");
835 for (unsigned int j=0; j<this->num_joints; j++) {
836 json_append_array_int_val(jnt, (int)j + this->node_offset + this->joint_offset);
837 }
838 this->skin_no++;
839 return;
840}
#define JBXL_GLTF_SKINS

References GLTFData::accessor_no, GLTFData::has_joints, JBXL_GLTF_SKINS, GLTFData::joint_offset, json_append_array_int_val(), json_append_array_key(), json_insert_parse(), LBUF, GLTFData::node_offset, GLTFData::num_joints, GLTFData::skin_no, GLTFData::skins, and snprintf.

Referenced by GLTFData::addShell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addTextures()

void addTextures ( MeshFacetNode * facet)

Definition at line 631 of file GLTFDataTool.cpp.

632{
633 if (facet==NULL) return;
634 char buf[LBUF];
635
636 while (facet!=NULL) {
637 if (!facet->same_material) {
638 char* image_name = (char*)facet->material_param.texture.getName();
639 tList* lt = search_key_tList(this->image_list, image_name, 1);
640 //
641 if (lt==NULL) {
642 Buffer file_name = make_Buffer_str(image_name);
643 canonical_filename_Buffer(&file_name, TRUE);
644 tList* ltend = find_tList_end(this->image_list);
645 add_tList_node_bystr(ltend, this->image_no, 0, (char*)file_name.buf, NULL, NULL, 0);
646 // images
647 memset(buf, 0, LBUF);
648 snprintf(buf, LBUF-1, JBXL_GLTF_IMAGES, (char*)file_name.buf);
649 json_insert_parse(this->images, buf);
650
651 // textures
652 memset(buf, 0, LBUF);
654 json_insert_parse(this->textures, buf);
655
656 free_Buffer(&file_name);
657 this->image_no++;
658 }
659 }
660 facet = facet->next;
661 }
662 return;
663}
#define JBXL_GLTF_IMAGES
#define JBXL_GLTF_TEXTURES
#define make_Buffer_str(str)
set_Buffer()
Definition buffer.h:61
unsigned int image_no

References add_tList_node_bystr(), Buffer::buf, canonical_filename_Buffer(), find_tList_end(), free_Buffer(), TextureParam::getName(), GLTFData::image_list, GLTFData::image_no, GLTFData::images, JBXL_GLTF_IMAGES, JBXL_GLTF_TEXTURES, json_insert_parse(), LBUF, make_Buffer_str, MeshFacetNode::material_param, MeshFacetNode::next, MeshFacetNode::same_material, search_key_tList(), snprintf, MaterialParam::texture, GLTFData::textures, and TRUE.

Referenced by GLTFData::addShell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ closeSolid()

void closeSolid ( void )

Definition at line 843 of file GLTFDataTool.cpp.

844{
845 if (this->bin_buffer.buf==NULL && !this->bin_seq) {
847 else createBinDataSoA();
848 }
849
850 if (this->skins->next==NULL) del_json_node(&this->skins);
851
852 return;
853}
void createBinDataAoS(void)
void createBinDataSoA(void)

References GLTFData::bin_buffer, GLTFData::bin_mode, Buffer::buf, GLTFData::createBinDataAoS(), GLTFData::createBinDataSoA(), del_json_node, JBXL_GLTF_BIN_AOS, and GLTFData::skins.

Here is the call graph for this function:

◆ convertJson_gltf2glb()

uDWord convertJson_gltf2glb ( glbTextureInfo * tex_info)

uDWord GLTFData::convertJson_gltf2glb(glbTextureInfo* tex_info)

glTFの Jsonデータを glbの Jsonデータに変換する.

Parameters
tex_infoテクスチャ情報を格納したデータへのポインタ
Return values
テクスチャデータの合計サイズ.PADを含む.uDWord(unsigned4Byte int)

Definition at line 2136 of file GLTFDataTool.cpp.

2137{
2138 char buf[LBUF];
2139
2140 uDWord tex_size = 0;
2141 while (tex_info!=NULL) {
2142 // bufferViews
2143 memset(buf, 0, LBUF);
2144 uDWord length = tex_info->length + tex_info->pad;
2145 snprintf(buf, LBUF-1, JBXL_GLTF_VIEWS_DATA, 0, this->bin_offset, length);
2146 json_insert_parse(this->buffviews, buf);
2147 // images
2148 memset(buf, 0, LBUF);
2150 json_insert_parse(this->images, buf);
2151 del_json(&(tex_info->json->prev));
2152 //
2153 this->bin_offset += length;
2154 this->view_no++;
2155 this->accessor_no++;
2156 tex_size = tex_size + length;
2157 tex_info = tex_info->next;
2158 }
2159
2160 // buffers
2161 uDWord bin_len = this->bin_buffer.vldsz + tex_size;
2162 uDWord bin_pad = (4 - bin_len%4)%4;
2163
2164 tJson* buffer_uri = search_key_json(this->buffers, "uri", FALSE, 1);
2165 tJson* buffer_len = buffer_uri->ysis;
2166 del_json(&buffer_uri);
2167 json_set_int_val(buffer_len, bin_len + bin_pad);
2168
2169 return tex_size;
2170}
#define JBXL_GLB_ACCESSORS_PNG_IMAGE
unsigned int uDWord
4Byte
Definition common.h:336
int vldsz
データの長さ.バイナリデータの場合も使用可能.文字列の場合は 0x00 を含まない.
Definition buffer.h:37
struct _glb_texture_info * next
void json_set_int_val(tJson *json, int val)
json ノード "key":val に整数の属性値(value)を設定する.
Definition tjson.cpp:922
#define del_json(j)
JSONデータの削除 del_tTree()
Definition tjson.h:60

References GLTFData::accessor_no, GLTFData::bin_buffer, GLTFData::bin_offset, GLTFData::buffers, GLTFData::buffviews, del_json, FALSE, GLTFData::images, JBXL_GLB_ACCESSORS_PNG_IMAGE, JBXL_GLTF_VIEWS_DATA, glbTextureInfo::json, json_insert_parse(), json_set_int_val(), LBUF, glbTextureInfo::length, glbTextureInfo::next, glbTextureInfo::pad, search_key_json(), snprintf, GLTFData::view_no, and Buffer::vldsz.

Referenced by GLTFData::output_glb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ convertJson_TexturePath()

void convertJson_TexturePath ( char * tex_dirn)

Definition at line 2025 of file GLTFDataTool.cpp.

2026{
2027 if (tex_dirn==NULL) return;
2028
2029 tJson* json = this->images;
2030 if (json!=NULL) json = json->next;
2031 if (json!=NULL) {
2032 while (json->esis!=NULL) json = json->esis;
2033 }
2034 //
2035 while (json!=NULL) { // here is {
2036 tJson* uri = search_key_json(json, "uri", FALSE, 1);
2037 if (uri!=NULL) {
2038 Buffer* tex = new_Buffer((int)strlen(tex_dirn) + uri->ldat.val.vldsz + 5); // ../ + \0 + 1(予備)
2039 cat_s2Buffer("\"", tex);
2041 cat_s2Buffer(tex_dirn, tex);
2042 cat_s2Buffer(&(uri->ldat.val.buf[1]), tex);
2043 free_Buffer(&uri->ldat.val);
2044 uri->ldat.val = *tex;
2045 }
2046 json = json->ysis;
2047 }
2048 return;
2049}
Buffer * new_Buffer(int sz)
空のBuffer型変数を生成する.
Definition buffer.cpp:23
#define cat_s2Buffer(src, dst)
cat_b2Buffer()
Definition buffer.h:122

References cat_s2Buffer, FALSE, free_Buffer(), GLTFData::images, new_Buffer(), and search_key_json().

Referenced by GLTFData::output_gltf().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createBinDataAoS()

void createBinDataAoS ( void )

void GLTFData::createBinDataAoS(void)

GLTFの this->shell_node に格納された Geometoryデータを AoS形式で this->bin_bufferに格納する. this->shell_node 中の Geometory データは,予め createShellGeometryData() で計算しておく必要がある. this->bin_buffer はそのまま出力できる.

Definition at line 1596 of file GLTFDataTool.cpp.

1597{
1598 unsigned int float_size = (unsigned int)sizeof(float);
1599 unsigned int uint_size = (unsigned int)sizeof(unsigned int);
1600 unsigned int shortu_size = (unsigned int)sizeof(short unsigned int);
1601
1602 unsigned int j_length = shortu_size*4U;
1603 unsigned int w_length = float_size*4U;
1604 unsigned int f_length = float_size*16U*this->num_joints;
1605
1606 unsigned int solid_indexes = 0;
1607 unsigned int solid_vertexes = 0;
1608 GLTFShellNode* shell_node = this->shellNode;
1609 while (shell_node!=NULL) {
1610 solid_indexes += shell_node->shell_indexes;
1611 solid_vertexes += shell_node->shell_vertexes;
1612 shell_node = shell_node->next;
1613 }
1614
1615 unsigned int buffer_len = solid_indexes*uint_size + solid_vertexes*float_size*8U; // I, V, N, U of the Shell
1616 if (this->has_joints) {
1617 buffer_len += solid_vertexes*(j_length + w_length) + this->shell_no*f_length; //+ J, W, M of the Shell
1618 }
1619 this->bin_buffer = make_Buffer(buffer_len);
1620 if (this->bin_buffer.buf==NULL) {
1621 PRINT_MESG("GLTFData::createBinDataAoS: ERROR: No more memory.\n");
1622 return;
1623 }
1624
1625 shell_node = this->shellNode;
1626 while (shell_node!=NULL) { // 全SHELL
1627 unsigned int i_offset = 0;
1628 unsigned int v_offset = 0;
1629 for (unsigned int f=0; f<shell_node->num_facets; f++) { // SHELL中の FACET
1630 // binary of indexies
1631 unsigned int i_length = shell_node->facet_index[f] * uint_size;
1632 cat_b2Buffer(shell_node->vi + i_offset, &(this->bin_buffer), i_length);
1633 i_offset += shell_node->facet_index[f];
1634
1635 for (unsigned int i=0; i<shell_node->facet_vertex[f]; i++) {
1636 // vertex
1637 cat_b2Buffer(&shell_node->vv[v_offset + i].x, &(this->bin_buffer), float_size);
1638 cat_b2Buffer(&shell_node->vv[v_offset + i].y, &(this->bin_buffer), float_size);
1639 cat_b2Buffer(&shell_node->vv[v_offset + i].z, &(this->bin_buffer), float_size);
1640 // normal
1641 cat_b2Buffer(&shell_node->vn[v_offset + i].x, &(this->bin_buffer), float_size);
1642 cat_b2Buffer(&shell_node->vn[v_offset + i].y, &(this->bin_buffer), float_size);
1643 cat_b2Buffer(&shell_node->vn[v_offset + i].z, &(this->bin_buffer), float_size);
1644 // uvmap
1645 cat_b2Buffer(&shell_node->vu[v_offset + i].u, &(this->bin_buffer), float_size);
1646 cat_b2Buffer(&shell_node->vu[v_offset + i].v, &(this->bin_buffer), float_size);
1647
1648 if (this->has_joints) {
1649 // weighted joint
1650 for (int j=1; j<=4; j++) {
1651 cat_b2Buffer(&shell_node->vj[v_offset + i].element(j), &(this->bin_buffer), shortu_size);
1652 }
1653 // weight value
1654 for (int j=1; j<=4; j++) {
1655 cat_b2Buffer(&shell_node->vw[v_offset + i].element(j), &(this->bin_buffer), float_size);
1656 }
1657 }
1658 }
1659 v_offset += shell_node->facet_vertex[f];
1660 }
1661
1662 if (this->has_joints) {
1663 // Inverse Bind Matrix
1664 for (unsigned int i=0; i<this->num_joints*16; i++) {
1665 cat_b2Buffer(&shell_node->vm[(int)i], &(this->bin_buffer), float_size);
1666 }
1667 }
1668
1669 shell_node = shell_node->next;
1670 }
1671 return;
1672}
Buffer make_Buffer(int sz)
Buffer型変数のバッファ部をつくり出す.
Definition buffer.cpp:71
int cat_b2Buffer(void *src, Buffer *dst, int len)
任意のバイナリデータsrcを Buffer型変数dstへ lenバイト catする.
Definition buffer.cpp:585
GLTFShellNode * shellNode
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
T & element(int i)
Definition Vector.h:734

References GLTFData::bin_buffer, Buffer::buf, cat_b2Buffer(), Vector4< T >::element(), GLTFShellNode::facet_index, GLTFShellNode::facet_vertex, GLTFData::has_joints, make_Buffer(), GLTFShellNode::next, GLTFShellNode::num_facets, GLTFData::num_joints, PRINT_MESG, GLTFShellNode::shell_indexes, GLTFData::shell_no, GLTFShellNode::shell_vertexes, GLTFData::shellNode, UVMap< T >::u, UVMap< T >::v, GLTFShellNode::vi, GLTFShellNode::vj, GLTFShellNode::vm, GLTFShellNode::vn, GLTFShellNode::vu, GLTFShellNode::vv, GLTFShellNode::vw, Vector< T >::x, Vector< T >::y, and Vector< T >::z.

Referenced by GLTFData::closeSolid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createBinDataIBM()

void createBinDataIBM ( SkinJointData * skin_joint,
AffineTrans< double > * ue_trans = NULL )

Definition at line 1801 of file GLTFDataTool.cpp.

1802{
1803 if (skin_joint==NULL) return;
1804 unsigned int float_size = (unsigned int)sizeof(float);
1805
1806 tList* jl = this->joints_list;
1807 if (jl!=NULL) jl = jl->next;
1808 while (jl!=NULL) {
1809 int jnt = jl->ldat.id;
1810 // IBM
1811 AffineTrans<double> ibm_trans = skin_joint->inverse_bind[jnt] * skin_joint->bind_shape;
1812 if (this->engine==JBXL_3D_ENGINE_UE && ue_trans!=NULL) ibm_trans.affineMatrixAfter(*ue_trans); // for UE5 Bug
1813 ibm_trans.computeMatrix();
1814
1815 for (int j=1; j<=4; j++) {
1816 for (int i=1; i<=4; i++) {
1817 float ibm = (float)ibm_trans.element(i, j);
1818 cat_b2Buffer(&ibm, &(this->bin_buffer), float_size);
1819 }
1820 }
1821 ibm_trans.free();
1822 jl = jl->next;
1823 }
1824 return;
1825}

References AffineTrans< T >::affineMatrixAfter(), GLTFData::bin_buffer, SkinJointData::bind_shape, cat_b2Buffer(), AffineTrans< T >::computeMatrix(), AffineTrans< T >::element(), GLTFData::engine, AffineTrans< T >::free(), SkinJointData::inverse_bind, JBXL_3D_ENGINE_UE, and GLTFData::joints_list.

Referenced by GLTFData::addShell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createBinDataSeqAoS()

void createBinDataSeqAoS ( MeshFacetNode * facet,
int shell_indexes,
int shell_vertexes )

void GLTFData::createBinDataSeqAoS(MeshFacetNode* facet, int shell_indexes, int shell_vertexes)

GLTFの Geometoryデータを AoS形式で 逐次作成し,this->bin_bufferに追加していく. 最終的に作成された this->bin_buffer はそのまま出力できる. this->shellNode は使用しない.

Definition at line 998 of file GLTFDataTool.cpp.

999{
1000 if (facet==NULL) return;
1001
1002 unsigned int float_size = (unsigned int)sizeof(float);
1003 unsigned int uint_size = (unsigned int)sizeof(unsigned int);
1004 unsigned int shortu_size = (unsigned int)sizeof(short unsigned int);
1005
1006 unsigned int j_length = shortu_size*4U;
1007 unsigned int w_length = float_size*4U;
1008
1009 unsigned int temp_len = (unsigned int)shell_indexes*uint_size + (unsigned int)shell_vertexes*float_size*8U; // I, V, N, U of the Shell
1010 if (this->has_joints) {
1011 temp_len += (unsigned int)shell_vertexes*(j_length + w_length); // + J, W of the Shell
1012 }
1013 unsigned char* temp_buffer = (unsigned char*)malloc(temp_len);
1014 if (temp_buffer==NULL) {
1015 PRINT_MESG("GLTFData::createBinDataSeqAoS: ERROR: temp_buffer. no more memory.\n");
1016 return;
1017 }
1018 //
1019 if (this->bin_buffer.buf==NULL) {
1020 this->bin_buffer = make_Buffer(temp_len);
1021 if (this->bin_buffer.bufsz<=0) {
1022 PRINT_MESG("GLTFData::createBinDataSeqAoS: ERROR: bin_buffer. no more memory.\n");
1023 ::free(temp_buffer);
1024 return;
1025 }
1026 }
1027 //
1028 unsigned int offset = 0U;
1029
1030 while (facet!=NULL) {
1031 // binary of indexies
1032 unsigned int i_length = (unsigned int)facet->num_index*uint_size;
1033 memcpy((void*)(temp_buffer + offset), (void*)facet->data_index, i_length);
1034 offset += i_length;
1035
1036 // binary of vertex/normal/uvmap
1037 float temp;
1038 for (int i=0; i<facet->num_vertex; i++) { // x n
1039 temp = (float)facet->vertex_value[i].x;
1040 memcpy((void*)(temp_buffer + offset), (void*)&temp, float_size);
1041 offset += float_size;
1042 temp = (float)facet->vertex_value[i].y;
1043 memcpy((void*)(temp_buffer + offset), (void*)&temp, float_size);
1044 offset += float_size;
1045 temp = (float)facet->vertex_value[i].z;
1046 memcpy((void*)(temp_buffer + offset), (void*)&temp, float_size);
1047 offset += float_size;
1048 temp = (float)facet->normal_value[i].x;
1049 memcpy((void*)(temp_buffer + offset), (void*)&temp, float_size);
1050 offset += float_size;
1051 temp = (float)facet->normal_value[i].y;
1052 memcpy((void*)(temp_buffer + offset), (void*)&temp, float_size);
1053 offset += float_size;
1054 temp = (float)facet->normal_value[i].z;
1055 memcpy((void*)(temp_buffer + offset), (void*)&temp, float_size);
1056 offset += float_size;
1057 temp = (float)facet->texcrd_value[i].u;
1058 memcpy((void*)(temp_buffer + offset), (void*)&temp, float_size);
1059 offset += float_size;
1060 temp = 1.0f - (float)facet->texcrd_value[i].v;
1061 memcpy((void*)(temp_buffer + offset), (void*)&temp, float_size);
1062 offset += float_size;
1063
1064 if (this->has_joints) {
1065 unsigned int total = 0;
1066 unsigned int jnum = (unsigned int)facet->weight_value[i].get_size();
1067 int wcount = 0;
1068 for (unsigned int j=0; j<jnum; j++) { // j: joint番号
1069 unsigned int w = (unsigned int)facet->weight_value[i].get_value(j);
1070 if (w!=0) wcount++;
1071 total += w;
1072 }
1073 if (wcount>4) PRINT_MESG("GLTFData::createBinDataSeqAoS: WARNING: more than 4 weighted joints (%d)\n", wcount);
1074
1075 short unsigned int weight_index[4];
1076 float weight_value[4];
1077 memset(weight_index, 0, j_length);
1078 memset(weight_value, 0, w_length);
1079
1080 if (total!=0) {
1081 unsigned int jcnt = 0;
1082 int jord = 0;
1083 tList* jl = this->joints_list;
1084 if (jl!=NULL) jl = jl->next;
1085 //
1086 while (jl!=NULL) {
1087 int jnt = jl->ldat.id;
1088 if (jnt<facet->weight_value[i].get_size()) {
1089 unsigned int w = (unsigned int)facet->weight_value[i].get_value(jnt);
1090 if (w!=0) {
1091 weight_index[jcnt] = (short unsigned int)(jord);
1092 weight_value[jcnt] = (float)w/(float)total;
1093 jcnt++;
1094 if (jcnt>=4) break;
1095 }
1096 }
1097 jord++;
1098 jl = jl->next;
1099 }
1100 }
1101 memcpy((void*)(temp_buffer + offset), (void*)weight_index, j_length);
1102 offset += j_length;
1103 memcpy((void*)(temp_buffer + offset), (void*)weight_value, w_length);
1104 offset += w_length;
1105 }
1106 }
1107 facet = facet->next;
1108 }
1109 //
1110 cat_b2Buffer(temp_buffer, &(this->bin_buffer), temp_len);
1111 ::free(temp_buffer);
1112
1113 return;
1114}
int get_size(void)
Definition tools++.h:43
Vector< double > * normal_value
法線ベクトルデータの並び.要素数は num_vertex
ArrayParam< int > * weight_value
頂点の重み.Jointを持つデータに使用される.要素数は num_vertex. 各 weight_value[i] の値は トータルで正規化される必要がある.
int * data_index
インデックスデータ.要素数は num_index
UVMap< double > * texcrd_value
テクスチャマップの並び.要素数は num_texcrd
Vector< double > * vertex_value
頂点データの並び.要素数は num_vertex
int bufsz
確保してあるバッファの大きさ - 1.
Definition buffer.h:36

References GLTFData::bin_buffer, Buffer::buf, Buffer::bufsz, cat_b2Buffer(), MeshFacetNode::data_index, GLTFData::free(), ArrayParam< T >::get_size(), ArrayParam< T >::get_value(), GLTFData::has_joints, GLTFData::joints_list, make_Buffer(), MeshFacetNode::next, MeshFacetNode::normal_value, MeshFacetNode::num_index, MeshFacetNode::num_vertex, PRINT_MESG, MeshFacetNode::texcrd_value, UVMap< T >::u, UVMap< T >::v, MeshFacetNode::vertex_value, MeshFacetNode::weight_value, Vector< T >::x, Vector< T >::y, and Vector< T >::z.

Referenced by GLTFData::addShell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createBinDataSeqSoA()

void createBinDataSeqSoA ( MeshFacetNode * facet,
int shell_indexes,
int shell_vertexes )

void GLTFData::createBinDataSeqSoA(MeshFacetNode* facet, int shell_indexes, int shell_vertexes)

GLTFの Geometoryデータを SoA形式で 逐次作成し,this->bin_bufferに追加していく. 最終的に作成された this->bin_buffer はそのまま出力できる. this->shellNode は使用しない.

SoA Ixn, Vxm, Nxm, Uxm, Jxm ,Wxm ...... facet Ixn, Vxm, Nxm, Uxm, Jxm ,Wxm ...... facet ......................................... Ixn, Vxm, Nxm, Uxm, Jxm ,Wxm ...... facet

Definition at line 1259 of file GLTFDataTool.cpp.

1260{
1261 if (facet==NULL) return;
1262
1263 unsigned int float_size = (unsigned int)sizeof(float);
1264 unsigned int uint_size = (unsigned int)sizeof(unsigned int);
1265 unsigned int shortu_size = (unsigned int)sizeof(short unsigned int);
1266
1267 unsigned int j_length = shortu_size*4U;
1268 unsigned int w_length = float_size*4U;
1269
1270 unsigned int temp_len = (unsigned int)shell_indexes*uint_size + (unsigned int)shell_vertexes*float_size*8U; // I, V, N, U of the Shell
1271 if (this->has_joints) {
1272 temp_len += (unsigned int)shell_vertexes*(j_length + w_length); // + J, W of the Shell
1273 }
1274 unsigned char* temp_buffer = (unsigned char*)malloc(temp_len);
1275 if (temp_buffer==NULL) {
1276 PRINT_MESG("GLTFData::createBinDataSeqSoA: ERROR: temp_buffer. no more memory.\n");
1277 return;
1278 }
1279 //
1280 if (this->bin_buffer.buf==NULL) {
1281 this->bin_buffer = make_Buffer(temp_len);
1282 if (this->bin_buffer.bufsz<=0) {
1283 PRINT_MESG("GLTFData::createBinDataSeqSoA: ERROR: bin_buffer. no more memory.\n");
1284 ::free(temp_buffer);
1285 return;
1286 }
1287 }
1288 //
1289 unsigned int offset = 0U;
1290
1291 while (facet!=NULL) {
1292 // binary of indexies
1293 unsigned int i_length = (unsigned int)facet->num_index*sizeof(unsigned int);
1294 memcpy((void*)(temp_buffer + offset), (void*)facet->data_index, i_length);
1295 offset += i_length;
1296
1297 // binary of vertex/normal/uvmap
1298 float temp;
1299 for (int i=0; i<facet->num_vertex; i++) { // x n
1300 temp = (float)facet->vertex_value[i].x;
1301 memcpy((void*)(temp_buffer + offset), (void*)&temp, float_size);
1302 offset += float_size;
1303 temp = (float)facet->vertex_value[i].y;
1304 memcpy((void*)(temp_buffer + offset), (void*)&temp, float_size);
1305 offset += float_size;
1306 temp = (float)facet->vertex_value[i].z;
1307 memcpy((void*)(temp_buffer + offset), (void*)&temp, float_size);
1308 offset += float_size;
1309 }
1310
1311 for (int i=0; i<facet->num_vertex; i++) {
1312 temp = (float)facet->normal_value[i].x;
1313 memcpy((void*)(temp_buffer + offset), (void*)&temp, float_size);
1314 offset += float_size;
1315 temp = (float)facet->normal_value[i].y;
1316 memcpy((void*)(temp_buffer + offset), (void*)&temp, float_size);
1317 offset += float_size;
1318 temp = (float)facet->normal_value[i].z;
1319 memcpy((void*)(temp_buffer + offset), (void*)&temp, float_size);
1320 offset += float_size;
1321 }
1322
1323 for (int i=0; i<facet->num_texcrd; i++) {
1324 temp = (float)facet->texcrd_value[i].u;
1325 memcpy((void*)(temp_buffer + offset), (void*)&temp, float_size);
1326 offset += float_size;
1327 temp = 1.0f - (float)facet->texcrd_value[i].v;
1328 memcpy((void*)(temp_buffer + offset), (void*)&temp, float_size);
1329 offset += float_size;
1330 }
1331
1332 if (this->has_joints) {
1333 // weighted joints
1334 for (int i=0; i<facet->num_vertex; i++) {
1335 unsigned int total = 0;
1336 unsigned int jnum = (unsigned int)facet->weight_value[i].get_size();
1337 int wcount = 0;
1338 for (unsigned int j=0; j<jnum; j++) {
1339 unsigned int w = (unsigned int)facet->weight_value[i].get_value(j);
1340 if (w!=0) wcount++;
1341 total += w;
1342 }
1343 if (wcount>4) PRINT_MESG("GLTFData::createBinDataSeqSoA: WARNING: more than 4 weighted joints (%d)\n", wcount);
1344
1345 short unsigned int weight_index[4];
1346 memset(weight_index, 0, j_length);
1347
1348 if (total!=0) {
1349 unsigned int jcnt = 0;
1350 int jord = 0;
1351 tList* jl = this->joints_list;
1352 if (jl!=NULL) jl = jl->next;
1353 //
1354 while (jl!=NULL) {
1355 int jnt = jl->ldat.id;
1356 if (jnt<facet->weight_value[i].get_size()) {
1357 unsigned int w = (unsigned int)facet->weight_value[i].get_value(jnt);
1358 if (w!=0) {
1359 weight_index[jcnt] = (short unsigned int)(jord);
1360 jcnt++;
1361 if (jcnt>=4) break;
1362 }
1363 }
1364 jord++;
1365 jl = jl->next;
1366 }
1367 }
1368 memcpy((void*)(temp_buffer + offset), (void*)weight_index, j_length);
1369 offset += j_length;
1370 }
1371 // weight value
1372 for (int i=0; i<facet->num_vertex; i++) {
1373 unsigned int total = 0;
1374 unsigned int jnum = (unsigned int)facet->weight_value[i].get_size();
1375 for (unsigned int j=0; j<jnum; j++) {
1376 total += (unsigned int)facet->weight_value[i].get_value(j);
1377 }
1378 float weight_value[4];
1379 memset(weight_value, 0, w_length);
1380
1381 if (total!=0) {
1382 unsigned int jcnt = 0;
1383 tList* jl = this->joints_list;
1384 if (jl!=NULL) jl = jl->next;
1385 //
1386 while (jl!=NULL) {
1387 int jnt = jl->ldat.id;
1388 if (jnt<facet->weight_value[i].get_size()) {
1389 unsigned int w = (unsigned int)facet->weight_value[i].get_value(jnt);
1390 if (w!=0) {
1391 weight_value[jcnt] = (float)w/(float)total;
1392 jcnt++;
1393 if (jcnt>=4) break;
1394 }
1395 }
1396 jl = jl->next;
1397 }
1398 }
1399 memcpy((void*)(temp_buffer + offset), (void*)weight_value, w_length);
1400 offset += w_length;
1401 }
1402 }
1403 facet = facet->next;
1404 }
1405 //
1406 cat_b2Buffer(temp_buffer, &(this->bin_buffer), temp_len);
1407 ::free(temp_buffer);
1408
1409 return;
1410}
int num_texcrd
テクスチャ画像の座標数.通常は num_vertex に等しい.(texcrd_value の要素数)

References GLTFData::bin_buffer, Buffer::buf, Buffer::bufsz, cat_b2Buffer(), MeshFacetNode::data_index, GLTFData::free(), ArrayParam< T >::get_size(), ArrayParam< T >::get_value(), GLTFData::has_joints, GLTFData::joints_list, make_Buffer(), MeshFacetNode::next, MeshFacetNode::normal_value, MeshFacetNode::num_index, MeshFacetNode::num_texcrd, MeshFacetNode::num_vertex, PRINT_MESG, MeshFacetNode::texcrd_value, UVMap< T >::u, UVMap< T >::v, MeshFacetNode::vertex_value, MeshFacetNode::weight_value, Vector< T >::x, Vector< T >::y, and Vector< T >::z.

Referenced by GLTFData::addShell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createBinDataSoA()

void createBinDataSoA ( void )

void GLTFData::createBinDataSoA(void)

GLTFの this->shell_node に格納された Geometoryデータを SoA形式で this->bin_bufferに格納する. this->shell_node 中の Geometory データは,予め createShellGeometryData() で計算しておく必要がある. this->bin_buffer はそのまま出力できる.

Definition at line 1682 of file GLTFDataTool.cpp.

1683{
1684 unsigned int float_size = (unsigned int)sizeof(float);
1685 unsigned int uint_size = (unsigned int)sizeof(unsigned int);
1686 unsigned int shortu_size = (unsigned int)sizeof(short unsigned int);
1687
1688 unsigned int j_length = shortu_size*4U;
1689 unsigned int w_length = float_size*4U;
1690
1691 unsigned int solid_indexes = 0;
1692 unsigned int solid_vertexes = 0;
1693 GLTFShellNode* shell_node = this->shellNode;
1694 while (shell_node!=NULL) {
1695 solid_indexes += shell_node->shell_indexes;
1696 solid_vertexes += shell_node->shell_vertexes;
1697 shell_node = shell_node->next;
1698 }
1699
1700 unsigned int buffer_len = (unsigned int)solid_indexes*uint_size + (unsigned int)solid_vertexes*float_size*8U; // I, V, N, U of the Shell
1701 if (this->has_joints) {
1702 buffer_len += (unsigned int)solid_vertexes*(j_length + w_length) + (unsigned int)this->num_joints*float_size*16U; //+ J, W, M of the Shell
1703 }
1704 this->bin_buffer = make_Buffer(buffer_len);
1705 if (this->bin_buffer.buf==NULL) {
1706 PRINT_MESG("GLTFData::createBinDataSoA: ERROR: No more memory.\n");
1707 return;
1708 }
1709
1710 shell_node = this->shellNode;
1711 while (shell_node!=NULL) { // 全SHELL
1712 unsigned int i_offset = 0;
1713 unsigned int v_offset = 0;
1714 for (unsigned int f=0; f<shell_node->num_facets; f++) { // SHELL中の FACET
1715 // binary of indexies
1716 unsigned int i_length = shell_node->facet_index[f] * uint_size;
1717 cat_b2Buffer(shell_node->vi + i_offset, &(this->bin_buffer), i_length);
1718 i_offset += shell_node->facet_index[f];
1719
1720 // vertex
1721 for (unsigned int i=0; i<shell_node->facet_vertex[f]; i++) {
1722 cat_b2Buffer(&shell_node->vv[v_offset + i].x, &(this->bin_buffer), float_size);
1723 cat_b2Buffer(&shell_node->vv[v_offset + i].y, &(this->bin_buffer), float_size);
1724 cat_b2Buffer(&shell_node->vv[v_offset + i].z, &(this->bin_buffer), float_size);
1725 }
1726 // normal
1727 for (unsigned int i=0; i<shell_node->facet_vertex[f]; i++) {
1728 cat_b2Buffer(&shell_node->vn[v_offset + i].x, &(this->bin_buffer), float_size);
1729 cat_b2Buffer(&shell_node->vn[v_offset + i].y, &(this->bin_buffer), float_size);
1730 cat_b2Buffer(&shell_node->vn[v_offset + i].z, &(this->bin_buffer), float_size);
1731 }
1732 // uvmap
1733 for (unsigned int i=0; i<shell_node->facet_vertex[f]; i++) {
1734 cat_b2Buffer(&shell_node->vu[v_offset + i].u, &(this->bin_buffer), float_size);
1735 cat_b2Buffer(&shell_node->vu[v_offset + i].v, &(this->bin_buffer), float_size);
1736 }
1737
1738 if (this->has_joints) {
1739 // weighted joints
1740 for (unsigned int i=0; i<shell_node->facet_vertex[f]; i++) {
1741 for (int j=1; j<=4; j++) {
1742 short unsigned int jnt = shell_node->vj[v_offset + i].element(j);
1743 cat_b2Buffer(&jnt, &(this->bin_buffer), shortu_size);
1744 }
1745 }
1746 // weight value
1747 for (unsigned int i=0; i<shell_node->facet_vertex[f]; i++) {
1748 for (int j=1; j<=4; j++) {
1749 float wgt = (float)shell_node->vw[v_offset + i].element(j);
1750 cat_b2Buffer(&wgt, &(this->bin_buffer), float_size);
1751 }
1752 }
1753 }
1754 v_offset += shell_node->facet_vertex[f];
1755 }
1756
1757 if (this->has_joints) {
1758 // Inverse Bind Matrix
1759 for (unsigned int i=0; i<this->num_joints*16U; i++) {
1760 cat_b2Buffer(&shell_node->vm[(int)i], &(this->bin_buffer), float_size);
1761 }
1762 }
1763
1764 shell_node = shell_node->next;
1765 }
1766 return;
1767}

References GLTFData::bin_buffer, Buffer::buf, cat_b2Buffer(), Vector4< T >::element(), GLTFShellNode::facet_index, GLTFShellNode::facet_vertex, GLTFData::has_joints, make_Buffer(), GLTFShellNode::next, GLTFShellNode::num_facets, GLTFData::num_joints, PRINT_MESG, GLTFShellNode::shell_indexes, GLTFShellNode::shell_vertexes, GLTFData::shellNode, UVMap< T >::u, UVMap< T >::v, GLTFShellNode::vi, GLTFShellNode::vj, GLTFShellNode::vm, GLTFShellNode::vn, GLTFShellNode::vu, GLTFShellNode::vv, GLTFShellNode::vw, Vector< T >::x, Vector< T >::y, and Vector< T >::z.

Referenced by GLTFData::closeSolid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createShellGeometryData()

void createShellGeometryData ( MeshFacetNode * facet,
int shell_indexes,
int shell_vertexes,
SkinJointData * skin_joint = NULL,
AffineTrans< double > * ue_trans = NULL )

void GLTFData::createShellGeometryData(MeshFacetNode* facet, int shell_indexes, int shell_vertexes, SkinJointData* skin_joint, AffineTrans<double>* ue_trans)

SHELL毎に呼び出され,SHELL中の全FACETのジオメトリ情報を this->shellNode に格納する.

Parameters
facetSHELL中の FACETの先頭データ.
shell_indexesSHELL中の indexデータの総数.
shell_vetexesSHELL中の vertexデータの総数.
skin_jointSHELLの Joint情報へのポインタ.
ue_transUE5 Bug 修正用 Affine変換行列.addNode() で変換した分を元に戻すための逆行列.

Definition at line 1428 of file GLTFDataTool.cpp.

1429{
1430 unsigned int float_size = (unsigned int)sizeof(float);
1431 unsigned int uint_size = (unsigned int)sizeof(unsigned int);
1432 unsigned int shortu_size = (unsigned int)sizeof(short unsigned int);
1433
1434 unsigned int j_length = shortu_size*4U;
1435 unsigned int w_length = float_size*4U;
1436
1437 GLTFShellNode* shell_node = new GLTFShellNode();
1438 shell_node->shell_indexes = shell_indexes;
1439 shell_node->shell_vertexes = shell_vertexes;
1440
1441 shell_node->vi = (unsigned int*) malloc(uint_size*shell_indexes);
1442 shell_node->vv = (Vector<float>*)malloc(sizeof(Vector<float>)*shell_vertexes);
1443 shell_node->vn = (Vector<float>*)malloc(sizeof(Vector<float>)*shell_vertexes);
1444 shell_node->vu = (UVMap<float>* )malloc(sizeof(UVMap<float> )*shell_vertexes);
1445 if (this->has_joints) {
1446 shell_node->vj = (Vector4<short unsigned int>*)malloc(sizeof(Vector4<short unsigned int>)*shell_vertexes);
1447 shell_node->vw = (Vector4<float>*)malloc(sizeof(Vector4<float>)*shell_vertexes);
1448 shell_node->vm = (float*)malloc(float_size*16U*this->num_joints);
1449 }
1450 //
1451 if (shell_node->vi==NULL || shell_node->vv==NULL || shell_node->vn==NULL || shell_node->vu==NULL) {
1452 delete(shell_node);
1453 return;
1454 }
1455 if (this->has_joints) {
1456 if (shell_node->vj==NULL || shell_node->vw==NULL || shell_node->vm==NULL) {
1457 delete(shell_node);
1458 return;
1459 }
1460 }
1461
1462 //
1463 MeshFacetNode* temp_facet = facet;
1464 while (temp_facet!=NULL) {
1465 shell_node->num_facets++; // この SHELLにある FACETの数を数える
1466 temp_facet = temp_facet->next;
1467 }
1468 shell_node->facet_index = (unsigned int*)malloc(shell_node->num_facets*uint_size);
1469 shell_node->facet_vertex = (unsigned int*)malloc(shell_node->num_facets*uint_size);
1470
1471 float mag_fac = 1.0f;
1472 if (this->engine==JBXL_3D_ENGINE_UNITY) {
1473 mag_fac = 1.0f;
1474 }
1475
1476 unsigned int index_offset = 0;
1477 unsigned int vertex_offset = 0;
1478 unsigned int facet_no = 0;
1479
1480 while (facet!=NULL) {
1481 // save index and vertex number
1482 shell_node->facet_index [facet_no] = facet->num_index;
1483 shell_node->facet_vertex[facet_no] = facet->num_vertex;
1484 facet_no++;
1485
1486 // indexies
1487 for (int i=0; i<facet->num_index; i++) {
1488 shell_node->vi[index_offset + i] = facet->data_index[i];
1489 }
1490 index_offset += facet->num_index;
1491
1492 // vertex/normal/uvmap
1493 for (int i=0; i<facet->num_vertex; i++) {
1494 shell_node->vv[vertex_offset + i] = facet->vertex_value[i] * mag_fac;
1495 shell_node->vn[vertex_offset + i] = facet->normal_value[i];
1496 shell_node->vu[vertex_offset + i].u = (float)facet->texcrd_value[i].u;
1497 shell_node->vu[vertex_offset + i].v = 1.0f - (float)facet->texcrd_value[i].v;
1498 }
1499
1500 if (this->has_joints) {
1501 for (int i=0; i<facet->num_vertex; i++) {
1502 unsigned int total = 0;
1503 unsigned int jnum = (unsigned int)facet->weight_value[i].get_size();
1504 int wcount = 0;
1505 for (unsigned int j=0; j<jnum; j++) {
1506 unsigned int w = (unsigned int)facet->weight_value[i].get_value(j);
1507 if (w>0) wcount++;
1508 total += w;
1509 }
1510 if (wcount>4) {
1511 PRINT_MESG("GLTFData::createShellGeomertyData: WARNING: more than 4 weighted joints (%d)\n", wcount);
1512 }
1513 //
1514 short unsigned int weight_index[4];
1515 float weight_value[4];
1516 memset(weight_index, 0, j_length);
1517 memset(weight_value, 0, w_length);
1518 if (total!=0) {
1519 unsigned int jcnt = 0;
1520 int jord = 0;
1521 tList* jl = this->joints_list;
1522 if (jl!=NULL) jl = jl->next;
1523 //
1524 while (jl!=NULL) {
1525 int jnt = (unsigned int)jl->ldat.id;
1526 if (jnt<facet->weight_value[i].get_size()) {
1527 unsigned int w = (unsigned int)facet->weight_value[i].get_value(jnt);
1528 if (w!=0) {
1529 weight_index[jcnt] = (short unsigned int)(jord);
1530 weight_value[jcnt] = (float)w/(float)total;
1531 jcnt++;
1532 if (jcnt>=4) break;
1533 }
1534 }
1535 jord++;
1536 jl = jl->next;
1537 }
1538 }
1539
1540 // weighted joints and weight value
1541 for (int j=0; j<4; j++) {
1542 shell_node->vj[vertex_offset + i].element(j+1) = weight_index[j];
1543 shell_node->vw[vertex_offset + i].element(j+1) = weight_value[j];
1544 }
1545 }
1546 }
1547 vertex_offset += facet->num_vertex;
1548 facet = facet->next;
1549 }
1550
1551 // Inverse Bind Matrix
1552 if (this->has_joints) {
1553 int jord = 0;
1554 tList* jl = this->joints_list;
1555 if (jl!=NULL) jl = jl->next;
1556 while (jl!=NULL) {
1557 int jnt = jl->ldat.id;
1558 // IBM
1559 AffineTrans<double> ibm_trans = skin_joint->inverse_bind[jnt] * skin_joint->bind_shape;
1560 if (this->engine==JBXL_3D_ENGINE_UE && ue_trans!=NULL) ibm_trans.affineMatrixAfter(*ue_trans); // for UE5 Bug
1561 ibm_trans.computeMatrix();
1562
1563 int ks = (int)jord*16;
1564 for (int j=1; j<=4; j++) {
1565 int js = (j-1)*4;
1566 for (int i=1; i<=4; i++) {
1567 shell_node->vm[ks + js + i - 1] = (float)ibm_trans.element(i, j);
1568 }
1569 }
1570 ibm_trans.free();
1571 jord++;
1572 jl = jl->next;
1573 }
1574 }
1575
1576 // shell_node をリストの最後に繋げる
1577 GLTFShellNode* prv = NULL;
1578 GLTFShellNode* ptr = this->shellNode;
1579 while(ptr!=NULL) {
1580 prv = ptr;
1581 ptr = ptr->next;
1582 }
1583 if (prv==NULL) this->shellNode = shell_node;
1584 else prv->next = shell_node;
1585 return;
1586}
#define JBXL_3D_ENGINE_UNITY
Definition common.h:310

References AffineTrans< T >::affineMatrixAfter(), SkinJointData::bind_shape, AffineTrans< T >::computeMatrix(), MeshFacetNode::data_index, Vector4< T >::element(), AffineTrans< T >::element(), GLTFData::engine, GLTFShellNode::facet_index, GLTFShellNode::facet_vertex, AffineTrans< T >::free(), ArrayParam< T >::get_size(), ArrayParam< T >::get_value(), GLTFData::has_joints, SkinJointData::inverse_bind, JBXL_3D_ENGINE_UE, JBXL_3D_ENGINE_UNITY, GLTFData::joints_list, GLTFShellNode::next, MeshFacetNode::next, MeshFacetNode::normal_value, GLTFShellNode::num_facets, MeshFacetNode::num_index, GLTFData::num_joints, MeshFacetNode::num_vertex, PRINT_MESG, GLTFShellNode::shell_indexes, GLTFShellNode::shell_vertexes, GLTFData::shellNode, MeshFacetNode::texcrd_value, UVMap< T >::u, UVMap< T >::v, MeshFacetNode::vertex_value, GLTFShellNode::vi, GLTFShellNode::vj, GLTFShellNode::vm, GLTFShellNode::vn, GLTFShellNode::vu, GLTFShellNode::vv, GLTFShellNode::vw, and MeshFacetNode::weight_value.

Referenced by GLTFData::addShell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ execAffineUVMap()

void execAffineUVMap ( MeshFacetNode * facet,
AffineTrans< double > * affine )

UV Map を処理する

Definition at line 256 of file GLTFDataTool.cpp.

257{
258 while (facet!=NULL) {
259 // UV Map and PLANAR Texture
260 /*
261 size_t len = facet->num_texcrd*sizeof(UVMap<double>);
262 UVMap<double>* uvmap = (UVMap<double>*)malloc(len);
263 if (uvmap!=NULL) {
264 memcpy(uvmap, facet->texcrd_value, len);
265 //
266 if (facet->material_param.mapping==MATERIAL_MAPPING_PLANAR) {
267 Vector<double> scale(1.0, 1.0, 1.0);
268 if (affine!=NULL) scale = affine->scale;
269 facet->generatePlanarUVMap(scale, uvmap);
270 }
271 facet->execAffineTransUVMap(uvmap, facet->num_texcrd);
272 }
273 */
274
276 Vector<double> scale(1.0, 1.0, 1.0);
277 if (affine!=NULL) scale = affine->getScale();
278 facet->generatePlanarUVMap(scale, facet->texcrd_value);
279 }
280 facet->execAffineTransUVMap(facet->texcrd_value, facet->num_texcrd);
281
282 facet = facet->next;
283 }
284 return;
285}
#define MATERIAL_MAPPING_PLANAR
Vector< T > getScale(void)
int mapping
マッピング方法
void execAffineTransUVMap(UVMap< double > *uvmap=NULL, int num=-1)
UVMap< double > * generatePlanarUVMap(Vector< double > scale, UVMap< double > *uvmap=NULL)

References MeshFacetNode::execAffineTransUVMap(), MeshFacetNode::generatePlanarUVMap(), AffineTrans< T >::getScale(), MaterialParam::mapping, MATERIAL_MAPPING_PLANAR, MeshFacetNode::material_param, MeshFacetNode::next, MeshFacetNode::num_texcrd, and MeshFacetNode::texcrd_value.

Referenced by GLTFData::addShell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free()

void free ( void )

Definition at line 159 of file GLTFDataTool.cpp.

160{
161 free_Buffer(&(this->gltf_name));
162 free_Buffer(&(this->alt_name));
163 //free_Buffer(&(this->matrix_buffer));
164 free_Buffer(&(this->bin_buffer));
165
166 del_tList(&(this->image_list));
167 del_tList(&(this->material_list));
168 del_json(&(this->json_data));
169
170 if (this->shellNode!=NULL) {
171 this->shellNode->delete_next();
172 this->shellNode = NULL;
173 }
174
175 if (this->joints_list!=NULL) del_tList(&this->joints_list);
176 this->joints_list = NULL; // unnecessary. just to be sure
177
178 this->affineRoot.free();
179}

References GLTFData::affineRoot, GLTFData::alt_name, GLTFData::bin_buffer, del_json, del_tList(), GLTFShellNode::delete_next(), AffineTrans< T >::free(), free_Buffer(), GLTFData::gltf_name, GLTFData::image_list, GLTFData::joints_list, GLTFData::json_data, GLTFData::material_list, and GLTFData::shellNode.

Referenced by GLTFData::createBinDataSeqAoS(), GLTFData::createBinDataSeqSoA(), GLTFData::freeGLBTextureInfo(), jbxl::freeGLTFData(), GLTFData::output_glb(), GLTFData::outputFile(), and GLTFData::~GLTFData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ freeGLBTextureInfo()

void freeGLBTextureInfo ( glbTextureInfo * tex_info)

Definition at line 2225 of file GLTFDataTool.cpp.

2226{
2227 glbTextureInfo* tinfo = texture_info;
2228 while (tinfo!=NULL) {
2229 glbTextureInfo* next = tinfo->next;
2230 free_Buffer(tinfo->fname);
2231 ::free(tinfo);
2232 tinfo = next;
2233 }
2234 return;
2235}

References glbTextureInfo::fname, GLTFData::free(), free_Buffer(), and glbTextureInfo::next.

Referenced by GLTFData::output_glb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAffineBaseTrans4Engine()

AffineTrans< double > getAffineBaseTrans4Engine ( void )

AffineTrans<double> GLTFData::getAffineBaseTrans4Engine(void)

×使用するエンジンに合わせて.... (UNITY と UE で同じ? GLTFの規格のせい?)

FACET毎の Affine変換のパラメータを変更する.

Definition at line 237 of file GLTFDataTool.cpp.

238{
240 for (int i=1; i<=4; i++) trans.element(i, i, 1.0);
241 //
242 trans.element(2, 2, 0.0);
243 trans.element(3, 3, 0.0);
244 trans.element(3, 2, -1.0); // y -> -z
245 trans.element(2, 3, 1.0); // z -> y
246
247 trans.computeComponents();
248
249 return trans;
250}

References AffineTrans< T >::computeComponents(), and AffineTrans< T >::element().

Referenced by GLTFData::addNodes(), GLTFData::addRootNode(), GLTFData::addShell(), and GLTFData::addSkeletonNodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFacetMinMax()

gltfFacetMinMax getFacetMinMax ( MeshFacetNode * facet)

Definition at line 2057 of file GLTFDataTool.cpp.

2058{
2059 gltfFacetMinMax min_max;
2060
2061 //min_max.index_max = facet->data_index[0];
2062 //min_max.index_min = facet->data_index[0];
2063 min_max.vertex_x_max = (float)facet->vertex_value[0].x;
2064 min_max.vertex_x_min = (float)facet->vertex_value[0].x;
2065 min_max.vertex_y_max = (float)facet->vertex_value[0].y;
2066 min_max.vertex_y_min = (float)facet->vertex_value[0].y;
2067 min_max.vertex_z_max = (float)facet->vertex_value[0].z;
2068 min_max.vertex_z_min = (float)facet->vertex_value[0].z;
2069/*
2070 min_max.normal_x_max = (float)facet->normal_value[0].x;
2071 min_max.normal_x_min = (float)facet->normal_value[0].x;
2072 min_max.normal_y_max = (float)facet->normal_value[0].y;
2073 min_max.normal_y_min = (float)facet->normal_value[0].y;
2074 min_max.normal_z_max = (float)facet->normal_value[0].z;
2075 min_max.normal_z_min = (float)facet->normal_value[0].z;
2076 min_max.texcrd_u_max = (float)facet->texcrd_value[0].u;
2077 min_max.texcrd_u_min = (float)facet->texcrd_value[0].u;
2078 min_max.texcrd_v_max = 1.0f - (float)facet->texcrd_value[0].v;
2079 min_max.texcrd_v_min = 1.0f - (float)facet->texcrd_value[0].v;
2080
2081 for (int i=1; i<facet->num_index; i++) {
2082 i_temp = facet->data_index[i];
2083 if (min_max.index_max < i_temp) min_max.index_max = i_temp;
2084 if (min_max.index_min > i_temp) min_max.index_min = i_temp;
2085 }
2086*/
2087
2088 float f_temp;
2089 for (int i=1; i<facet->num_vertex; i++) {
2090 f_temp = (float)facet->vertex_value[i].x;
2091 if (min_max.vertex_x_max < f_temp) min_max.vertex_x_max = f_temp;
2092 if (min_max.vertex_x_min > f_temp) min_max.vertex_x_min = f_temp;
2093 f_temp = (float)facet->vertex_value[i].y;
2094 if (min_max.vertex_y_max < f_temp) min_max.vertex_y_max = f_temp;
2095 if (min_max.vertex_y_min > f_temp) min_max.vertex_y_min = f_temp;
2096 f_temp = (float)facet->vertex_value[i].z;
2097 if (min_max.vertex_z_max < f_temp) min_max.vertex_z_max = f_temp;
2098 if (min_max.vertex_z_min > f_temp) min_max.vertex_z_min = f_temp;
2099/*
2100 f_temp = (float)facet->normal_value[i].x;
2101 if (min_max.normal_x_max < f_temp) min_max.normal_x_max = f_temp;
2102 if (min_max.normal_x_min > f_temp) min_max.normal_x_min = f_temp;
2103 f_temp = (float)facet->normal_value[i].y;
2104 if (min_max.normal_y_max < f_temp) min_max.normal_y_max = f_temp;
2105 if (min_max.normal_y_min > f_temp) min_max.normal_y_min = f_temp;
2106 f_temp = (float)facet->normal_value[i].z;
2107 if (min_max.normal_z_max < f_temp) min_max.normal_z_max = f_temp;
2108 if (min_max.normal_z_min > f_temp) min_max.normal_z_min = f_temp;
2109
2110 f_temp = (float)facet->texcrd_value[i].u;
2111 if (min_max.texcrd_u_max < f_temp) min_max.texcrd_u_max = f_temp;
2112 if (min_max.texcrd_u_min > f_temp) min_max.texcrd_u_min = f_temp;
2113 f_temp = 1.0f - (float)facet->texcrd_value[i].v;
2114 if (min_max.texcrd_v_max < f_temp) min_max.texcrd_v_max = f_temp;
2115 if (min_max.texcrd_v_min > f_temp) min_max.texcrd_v_min = f_temp;
2116*/
2117 }
2118
2119 return min_max;
2120}

References MeshFacetNode::num_vertex, MeshFacetNode::vertex_value, gltfFacetMinMax::vertex_x_max, gltfFacetMinMax::vertex_x_min, gltfFacetMinMax::vertex_y_max, gltfFacetMinMax::vertex_y_min, gltfFacetMinMax::vertex_z_max, gltfFacetMinMax::vertex_z_min, Vector< T >::x, Vector< T >::y, and Vector< T >::z.

Referenced by GLTFData::addAccessorsAoS(), and GLTFData::addAccessorsSoA().

Here is the caller graph for this function:

◆ getGLBTextureInfo()

glbTextureInfo * getGLBTextureInfo ( const char * tex_dirn)

Definition at line 2173 of file GLTFDataTool.cpp.

2174{
2175 // Search Texture Top
2176 tJson* tjsn = this->images;
2177 if (tjsn!=NULL) tjsn = tjsn->next;
2178 if (tjsn!=NULL) {
2179 while (tjsn->esis!=NULL) tjsn = tjsn->esis;
2180 }
2181
2182 // Texture Data
2183 glbTextureInfo* p_tex_info = NULL;
2184 glbTextureInfo** n_info = &p_tex_info;
2185 //
2186 while (tjsn!=NULL) { // here is {
2187 tJson* texture_uri = search_key_json(tjsn, "uri", FALSE, 1);
2188 if (texture_uri!=NULL) {
2189 *n_info = (glbTextureInfo*)malloc(sizeof(glbTextureInfo));
2190 (*n_info)->length = 0;
2191 (*n_info)->pad = 0;
2192 (*n_info)->fname = new_Buffer((int)strlen(tex_dirn) + texture_uri->ldat.val.vldsz + 2); // \0 + 1(予備)
2193 (*n_info)->json = texture_uri;
2194 (*n_info)->next = NULL;
2195 //
2196 cat_s2Buffer(tex_dirn, (*n_info)->fname);
2197 if (texture_uri->ldat.val.buf[0]=='"') { // 最初の " を避ける
2198 cat_s2Buffer(&(texture_uri->ldat.val.buf[1]), (*n_info)->fname);
2199 }
2200 if ((*n_info)->fname->buf[(*n_info)->fname->vldsz-1]=='"') { // 最期の " を避ける
2201 (*n_info)->fname->buf[(*n_info)->fname->vldsz-1] = '\0';
2202 (*n_info)->fname->vldsz--;
2203 }
2204 //
2205 uDWord len = file_size((char*)(*n_info)->fname->buf);
2206 (*n_info)->length = len;
2207 (*n_info)->pad = (4 - len%4)%4;
2208 //
2209 n_info = &((*n_info)->next);
2210 }
2211 tjsn = tjsn->ysis;
2212 }
2213
2214 /*
2215 glbTextureInfo* info = p_tex_info;
2216 while (info!=NULL) {
2217 print_message("======> %s %d %d\n", (char*)info->fname->buf, info->length, info->pad);
2218 info = info->next;
2219 }
2220 */
2221 return p_tex_info;
2222}
unsigned long int file_size(const char *fn)
ファイルの大きさを返す.
Definition tools.cpp:2309

References cat_s2Buffer, FALSE, file_size(), GLTFData::images, glbTextureInfo::length, new_Buffer(), and search_key_json().

Referenced by GLTFData::output_glb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init()

void init ( void )

Definition at line 91 of file GLTFDataTool.cpp.

92{
93 //this->bin_mode = JBXL_GLTF_BIN_AOS;
95 //this->bin_seq = false;
96 this->bin_seq = true;
97
98 this->gltf_name = init_Buffer();
99 this->alt_name = init_Buffer();
100 this->phantom_out = true;
101 this->no_offset = false;
102 this->glb_out = false;
103 this->center = Vector<double>(0.0, 0.0, 0.0);
104
105 this->has_joints = false;
106 this->has_skeleton_node = false;
107 this->joints_list = NULL;
108
109 this->forUnity = true;
110 this->forUE = false;
112
115
116 this->affineRoot.init();
117
118 this->bin_buffer = init_Buffer();
119 this->bin_offset = 0;
120 //this->matrix_buffer = init_Buffer();
121 //this->matrix_offset = 0;
122
123 this->shell_no = 0;
124 this->node_no = 0;
125 this->mesh_no = 0;
126 this->mesh_prim_no = 0;
127 this->skin_no = 0;
128 this->view_no = 0;
129 this->accessor_no = 0;
130 this->material_no = 0;
131 this->image_no = 0;
132
133 this->num_joints = 0;
134 this->node_offset = 0;
135 this->joint_offset = 0;
136
137 this->json_data = NULL;
138 this->scenes = NULL;
139 this->scenes_name = NULL;
140 this->scenes_nodes = NULL;
141 this->nodes = NULL;
142 this->meshes = NULL;
143 this->skins = NULL;
144 this->buffers = NULL;
145 this->buffviews = NULL;
146 this->accessors = NULL;
147 this->materials = NULL;
148 this->textures = NULL;
149 this->images = NULL;
150
151 this->nodes_children = NULL;
152
153 this->shellNode = NULL;
154
155 initGLTF();
156}
#define JBXL_GLTF_BIN_SOA
void initGLTF(void)
tList * new_tList_anchor_node(void)
リスト用の ANCHORノードを動的に生成.
Definition tlist.cpp:371

References GLTFData::accessor_no, GLTFData::accessors, GLTFData::affineRoot, GLTFData::alt_name, GLTFData::bin_buffer, GLTFData::bin_mode, GLTFData::bin_offset, GLTFData::bin_seq, GLTFData::buffers, GLTFData::buffviews, GLTFData::center, GLTFData::engine, GLTFData::forUE, GLTFData::forUnity, GLTFData::glb_out, GLTFData::gltf_name, GLTFData::has_joints, GLTFData::has_skeleton_node, GLTFData::image_list, GLTFData::image_no, GLTFData::images, AffineTrans< T >::init(), init_Buffer(), GLTFData::initGLTF(), JBXL_3D_ENGINE_UNITY, JBXL_GLTF_BIN_SOA, GLTFData::joint_offset, GLTFData::joints_list, GLTFData::json_data, GLTFData::material_list, GLTFData::material_no, GLTFData::materials, GLTFData::mesh_no, GLTFData::mesh_prim_no, GLTFData::meshes, new_tList_anchor_node(), GLTFData::no_offset, GLTFData::node_no, GLTFData::node_offset, GLTFData::nodes, GLTFData::nodes_children, GLTFData::num_joints, GLTFData::phantom_out, GLTFData::scenes, GLTFData::scenes_name, GLTFData::scenes_nodes, GLTFData::shell_no, GLTFData::shellNode, GLTFData::skin_no, GLTFData::skins, GLTFData::textures, and GLTFData::view_no.

Referenced by GLTFData::GLTFData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initGLTF()

void initGLTF ( void )

Definition at line 195 of file GLTFDataTool.cpp.

196{
197 char asset[] = "{\"asset\": {\"copyright\", \"generator\", \"version\"}}";
198 this->json_data = json_parse(asset, 99);
199
200 tJson* temp;
201 temp = search_double_key_json(this->json_data, "asset", "copyright", FALSE);
202 if (temp!=NULL) json_set_str_val(temp, JBXL_GLTF_COPYRIGHT);
203 temp = search_double_key_json(this->json_data, "asset", "generator", FALSE);
204 if (temp!=NULL) json_set_str_val(temp, JBXL_GLTF_GENERATOR);
205 temp = search_double_key_json(this->json_data, "asset", "version", FALSE);
206 if (temp!=NULL) json_set_str_val(temp, JBXL_GLTF_VERSION);
207
208 json_insert_parse(this->json_data, "{\"scene\":0}");
209 this->scenes = json_append_array_key(this->json_data, "scenes");
210 this->scenes_name = json_insert_parse(this->scenes, "{\"name\":}");
211 this->scenes_nodes = json_append_array_key(this->scenes->next, "nodes");
212 this->nodes = json_append_array_key(this->json_data, "nodes");
213 this->skins = json_append_array_key(this->json_data, "skins");
214 this->meshes = json_append_array_key(this->json_data, "meshes");
215
216 this->materials = json_append_array_key(this->json_data, "materials");
217 this->textures = json_append_array_key(this->json_data, "textures");
218 this->images = json_append_array_key(this->json_data, "images");
219
220 this->buffers = json_append_array_key(this->json_data, "buffers");
221 this->buffviews = json_append_array_key(this->json_data, "bufferViews");
222 this->accessors = json_append_array_key(this->json_data, "accessors");
223}
#define JBXL_GLTF_GENERATOR
#define JBXL_GLTF_VERSION
#define JBXL_GLTF_COPYRIGHT
tJson * search_double_key_json(tJson *pp, const char *key1, const char *key2, int needval)
属性名が key1 -> key2 の親子関係を持つ,key2ノードのポインタを返す.
Definition tjson.cpp:1524
tJson * json_parse(const char *str, int num)
文字列のJSONデータを解釈して,tJsonのツリーを生成する.ANCHOR付き.
Definition tjson.cpp:51

References GLTFData::accessors, GLTFData::buffers, GLTFData::buffviews, FALSE, GLTFData::images, JBXL_GLTF_COPYRIGHT, JBXL_GLTF_GENERATOR, JBXL_GLTF_VERSION, json_append_array_key(), GLTFData::json_data, json_insert_parse(), json_parse(), json_set_str_val(), GLTFData::materials, GLTFData::meshes, GLTFData::nodes, GLTFData::scenes, GLTFData::scenes_name, GLTFData::scenes_nodes, search_double_key_json(), GLTFData::skins, and GLTFData::textures.

Referenced by GLTFData::init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ output_glb()

void output_glb ( char * fn,
char * out_dirn,
char * tex_dirn,
char * bin_dirn )

Definition at line 1922 of file GLTFDataTool.cpp.

1923{
1924 UNUSED(bin_dirn);
1925
1926 // update buffers
1927 char buf[LBUF];
1928 memset(buf, 0, LBUF);
1929 snprintf(buf, LBUF-1, JBXL_GLTF_BUFFERS_BIN, "", 0);
1930 json_insert_parse(this->buffers, buf);
1931
1932 Buffer out_path = make_Buffer_bystr(out_dirn);
1933 cat_s2Buffer(fn, &out_path);
1934 change_file_extension_Buffer(&out_path, ".glb");
1935
1936 Buffer tex_path = make_Buffer_bystr(out_dirn);
1937 cat_s2Buffer(tex_dirn, &tex_path);
1938
1939 glbFileHeader header;
1940 memcpy((void*)&(header.magic), (void*)JBXL_GLB_HEADER, 4);
1941 header.version = 2;
1942 header.length = 0;
1943
1944 glbTextureInfo* texture_info = getGLBTextureInfo((char*)tex_path.buf);
1945 uDWord tex_size = convertJson_gltf2glb(texture_info);
1946
1947 DEBUG_MODE {
1948 glbTextureInfo* info = texture_info;
1949 while (info!=NULL) {
1950 PRINT_MESG("GLTFData::output_glb: Texture File = %s, Length = %d, Pad = %d\n", (char*)info->fname->buf, info->length, info->pad);
1951 info = info->next;
1952 }
1953 }
1954
1955 // JSON Data
1956 glbDataChunk json_chunk;
1958 uDWord len = json_out.vldsz; // + sizeof(uDWord)*2;
1959 uDWord pad = (4 - len%4)%4; // len -> pad: 0->0, 1->3, 2->2, 3->1
1960 json_chunk.length = len + pad;
1961 json_chunk.pad = pad;
1962 json_chunk.data = (uByte*)json_out.buf;
1963 memcpy((void*)&(json_chunk.type), (void*)JBXL_GLB_TYPE_JSON, 4);
1964
1965 // BIN Data
1966 glbDataChunk bin_chunk;
1967 len = this->bin_buffer.vldsz + tex_size; // + sizeof(uDWord)*2;
1968 pad = (4 - len%4)%4;
1969 bin_chunk.length = len + pad;
1970 bin_chunk.pad = pad;
1971 bin_chunk.data = (uByte*)bin_buffer.buf;
1972 memcpy((void*)&(bin_chunk.type), (void*)JBXL_GLB_TYPE_BIN, 4);
1973 //
1974 header.length = sizeof(glbFileHeader) + json_chunk.length + bin_chunk.length + sizeof(uDWord)*4;
1975
1976 // output
1977 FILE* fp = fopen((char*)out_path.buf, "wb");
1978 if (fp!=NULL) {
1979 fwrite((void*)(&header), sizeof(glbFileHeader), 1, fp);
1980 // Json
1981 fwrite((void*)(&json_chunk), sizeof(uDWord)*2, 1, fp);
1982 fwrite((void*)(json_chunk.data), json_out.vldsz, 1, fp);
1983 for (uDWord i=0; i<json_chunk.pad; i++) fwrite((void*)" ", 1, 1, fp);
1984 // Bin
1985 fwrite((void*)(&bin_chunk), sizeof(uDWord)*2, 1, fp);
1986 fwrite((void*)(bin_chunk.data), bin_buffer.vldsz, 1, fp);
1987 for (uDWord i=0; i<bin_chunk.pad; i++) fwrite((void*)"\0", 1, 1, fp);
1988 // Texrure
1989 glbTextureInfo* tex_info = texture_info;
1990 while (tex_info!=NULL) {
1991 FILE* tp = fopen((char*)tex_info->fname->buf, "rb");
1992 if (tp!=NULL) {
1993 uByte* tex_buf = (uByte*)malloc(tex_info->length);
1994 if (tex_buf!=NULL) {
1995 size_t ret = fread(tex_buf, 1, tex_info->length, tp);
1996 if (ret==0) {
1997 PRINT_MESG("GLTFData::output_glb: ERROR: Texture file read Error! (%s)\n", (char*)tex_info->fname->buf);
1998 }
1999 fwrite((void*)tex_buf, tex_info->length, 1, fp);
2000 for (uDWord i=0; i<tex_info->pad; i++) fwrite((void*)"\0", 1, 1, fp);
2001 ::free(tex_buf);
2002 }
2003 fclose(tp);
2004 }
2005 else {
2006 PRINT_MESG("GLTFData::output_glb: ERROR: Texture file open Error! (%s)\n", (char*)tex_info->fname->buf);
2007 }
2008 tex_info = tex_info->next;
2009 }
2010 fclose(fp);
2011 }
2012 else {
2013 PRINT_MESG("GLTFData::output_glb: ERROR: GLB file open Error! (%s)\n", (char*)out_path.buf);
2014 }
2015
2016 free_Buffer(&out_path);
2017 free_Buffer(&tex_path);
2018 free_Buffer(&json_out);
2019 freeGLBTextureInfo(texture_info);
2020 return;
2021}
#define JBXL_GLB_TYPE_JSON
#define JBXL_GLB_TYPE_BIN
#define JBXL_GLB_HEADER
#define JBXL_GLTF_BUFFERS_BIN
glbTextureInfo * getGLBTextureInfo(const char *tex_dirn)
void freeGLBTextureInfo(glbTextureInfo *tex_info)
uDWord convertJson_gltf2glb(glbTextureInfo *tex_info)
#define UNUSED(x)
Definition common.h:264
unsigned char uByte
1Byte
Definition common.h:332
Buffer json_inverse_parse(tJson *pp, int mode)
tJsonデータをmodeに従って元の書式に戻して Bufferに格納する.
Definition tjson.cpp:616
#define JSON_ONELINE_FORMAT
改行なしの一行にする.
Definition tjson.h:44
void change_file_extension_Buffer(Buffer *path, const char *ext)
ファイルの拡張子を extにする.ファイルに拡張子が無い場合は extを付加する
Definition xtools.cpp:1960

References GLTFData::bin_buffer, Buffer::buf, GLTFData::buffers, cat_s2Buffer, change_file_extension_Buffer(), GLTFData::convertJson_gltf2glb(), glbDataChunk::data, DEBUG_MODE, glbTextureInfo::fname, GLTFData::free(), free_Buffer(), GLTFData::freeGLBTextureInfo(), GLTFData::getGLBTextureInfo(), JBXL_GLB_HEADER, JBXL_GLB_TYPE_BIN, JBXL_GLB_TYPE_JSON, JBXL_GLTF_BUFFERS_BIN, GLTFData::json_data, json_insert_parse(), json_inverse_parse(), JSON_ONELINE_FORMAT, LBUF, glbFileHeader::length, glbDataChunk::length, glbTextureInfo::length, glbFileHeader::magic, make_Buffer_bystr, glbTextureInfo::next, glbDataChunk::pad, glbTextureInfo::pad, PRINT_MESG, snprintf, glbDataChunk::type, UNUSED, glbFileHeader::version, and Buffer::vldsz.

Referenced by GLTFData::outputFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ output_gltf()

void output_gltf ( char * fn,
char * out_dirn,
char * tex_dirn,
char * bin_dirn )

Definition at line 1855 of file GLTFDataTool.cpp.

1856{
1857 Buffer out_path = make_Buffer_bystr(out_dirn);
1858 cat_s2Buffer(fn, &out_path);
1859 change_file_extension_Buffer(&out_path, ".gltf");
1860
1861 Buffer bin_path = make_Buffer_bystr(out_dirn);
1862 cat_s2Buffer(bin_dirn, &bin_path);
1863 cat_s2Buffer(fn, &bin_path);
1864 change_file_extension_Buffer(&bin_path, ".bin");
1865
1866 Buffer tex_path = make_Buffer_bystr(tex_dirn);
1867 Buffer rel_path = make_Buffer_bystr(bin_dirn);
1868 cat_s2Buffer(fn, &rel_path);
1869 change_file_extension_Buffer(&rel_path, ".bin");
1870#ifdef WIN32
1871 replace_char(rel_path.buf, rel_path.vldsz, '\\', '/');
1872 replace_char(tex_path.buf, tex_path.vldsz, '\\', '/');
1873#endif
1874 convertJson_TexturePath((char*)tex_path.buf);
1875
1876 // update buffers
1877 char buf[LBUF];
1878 memset(buf, 0, LBUF);
1879 snprintf(buf, LBUF-1, JBXL_GLTF_BUFFERS_BIN, (char*)rel_path.buf, this->bin_buffer.vldsz);
1880 json_insert_parse(this->buffers, buf);
1881
1882/*
1883 if (this->has_joints && this->matrix_buffer.vldsz>0) {
1884 Buffer base64 = encode_base64_Buffer(this->matrix_buffer);
1885 unsigned int len = base64.vldsz + LBUF;
1886 char* big_buf = (char*)malloc(len);
1887 memset(big_buf, 0, len);
1888 snprintf(big_buf, len-1, JBXL_GLTF_BUFFERS_B64, (char*)base64.buf, this->matrix_buffer.vldsz);
1889 json_insert_parse(this->buffers, big_buf);
1890 free_Buffer(&base64);
1891 ::free(big_buf);
1892 }
1893*/
1894 // output json data
1895 FILE* fp = fopen((char*)out_path.buf, "w");
1896 if (fp!=NULL) {
1898 fclose(fp);
1899 }
1900 else {
1901 PRINT_MESG("GLTFData::output_gltf: ERROR: Json file open Error! (%s)\n", (char*)out_path.buf);
1902 }
1903
1904 // output binary data
1905 fp = fopen((char*)bin_path.buf, "wb");
1906 if (fp!=NULL) {
1907 fwrite((void*)(this->bin_buffer.buf), this->bin_buffer.vldsz, 1, fp);
1908 fclose(fp);
1909 }
1910 else {
1911 PRINT_MESG("GLTFData::output_gltf: ERROR: Binary file open Error! (%s)\n", (char*)bin_path.buf);
1912 }
1913
1914 free_Buffer(&tex_path);
1915 free_Buffer(&rel_path);
1916 free_Buffer(&out_path);
1917 free_Buffer(&bin_path);
1918 return;
1919}
void convertJson_TexturePath(char *tex_dirn)
void print_json(FILE *fp, tJson *json, int mode)
tJsonデータをmodeに従って fp に出力する.
Definition tjson.cpp:818
#define JSON_INDENT_FORMAT
先頭にインデント(TAB)をつけ,ノードごとに改行する.
Definition tjson.h:46
void replace_char(unsigned char *buf, int len, unsigned char frm, unsigned char toc)
データbuf 中のバイトデータ frm を tocに変更する.
Definition tools.cpp:1252

References GLTFData::bin_buffer, Buffer::buf, GLTFData::buffers, cat_s2Buffer, change_file_extension_Buffer(), GLTFData::convertJson_TexturePath(), free_Buffer(), JBXL_GLTF_BUFFERS_BIN, GLTFData::json_data, JSON_INDENT_FORMAT, json_insert_parse(), LBUF, make_Buffer_bystr, print_json(), PRINT_MESG, replace_char(), snprintf, and Buffer::vldsz.

Referenced by GLTFData::outputFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ outputFile()

void outputFile ( const char * fn,
const char * out_dirn,
const char * tex_dirn,
const char * bin_dirn )

Definition at line 1833 of file GLTFDataTool.cpp.

1834{
1835 char* packname = pack_head_tail_char(get_file_name(fname), ' ');
1836 Buffer file_name = make_Buffer_bystr(packname);
1837 ::free(packname);
1838 //
1839 canonical_filename_Buffer(&file_name, TRUE);
1840 if (file_name.buf[0]=='.') file_name.buf[0] = '_';
1841
1842 //
1843 if (this->glb_out) {
1844 this->output_glb ((char*)file_name.buf, (char*)out_dirn, (char*)tex_dirn, (char*)bin_dirn);
1845 }
1846 else {
1847 this->output_gltf((char*)file_name.buf, (char*)out_dirn, (char*)tex_dirn, (char*)bin_dirn);
1848 }
1849
1850 free_Buffer(&file_name);
1851 return;
1852}
void output_glb(char *fn, char *out_dirn, char *tex_dirn, char *bin_dirn)
void output_gltf(char *fn, char *out_dirn, char *tex_dirn, char *bin_dirn)
char * get_file_name(const char *str)
フルパスからファイル名へのポインタを取り出す.free() してはいけない.
Definition tools.cpp:2066
char * pack_head_tail_char(char *mesg, char cc)
文字の先頭のcc(複数),TAB, CR, LF.終わりのcc(複数),TAB, CR, LF を削除.要 free()
Definition tools.cpp:1092

References Buffer::buf, canonical_filename_Buffer(), GLTFData::free(), free_Buffer(), get_file_name(), GLTFData::glb_out, make_Buffer_bystr, GLTFData::output_glb(), GLTFData::output_gltf(), pack_head_tail_char(), and TRUE.

Here is the call graph for this function:

◆ setEngine()

void setEngine ( int e)

Definition at line 182 of file GLTFDataTool.cpp.

183{
184 this->setUnity(false);
185 this->setUE(false);
186 //
187 this->engine = e;
188 if (e==JBXL_3D_ENGINE_UNITY) this->setUnity(true);
189 else if (e==JBXL_3D_ENGINE_UE) this->setUE(true);
190
191 return;
192}
void setUE(bool b)
void setUnity(bool b)

References GLTFData::engine, JBXL_3D_ENGINE_UE, JBXL_3D_ENGINE_UNITY, GLTFData::setUE(), and GLTFData::setUnity().

Here is the call graph for this function:

◆ setUE()

void setUE ( bool b)
inline

Definition at line 247 of file GLTFDataTool.h.

247{ this->forUE = b;}

Referenced by GLTFData::setEngine().

Here is the caller graph for this function:

◆ setUnity()

void setUnity ( bool b)
inline

Definition at line 246 of file GLTFDataTool.h.

246{ this->forUnity = b;}

Referenced by GLTFData::setEngine().

Here is the caller graph for this function:

Member Data Documentation

◆ accessor_no

◆ accessors

◆ affineRoot

◆ alt_name

Buffer alt_name

◆ bin_buffer

◆ bin_mode

int bin_mode

Definition at line 183 of file GLTFDataTool.h.

Referenced by GLTFData::addShell(), GLTFData::closeSolid(), and GLTFData::init().

◆ bin_offset

◆ bin_seq

bool bin_seq

Definition at line 184 of file GLTFDataTool.h.

Referenced by GLTFData::addShell(), and GLTFData::init().

◆ buffers

◆ buffviews

◆ center

Vector<double> center

Definition at line 199 of file GLTFDataTool.h.

Referenced by GLTFData::addShell(), and GLTFData::init().

◆ engine

◆ forUE

bool forUE

Definition at line 189 of file GLTFDataTool.h.

Referenced by GLTFData::init().

◆ forUnity

bool forUnity

Definition at line 188 of file GLTFDataTool.h.

Referenced by GLTFData::init().

◆ glb_out

bool glb_out

Definition at line 186 of file GLTFDataTool.h.

Referenced by GLTFData::init(), and GLTFData::outputFile().

◆ gltf_name

Buffer gltf_name

◆ has_joints

◆ has_skeleton_node

bool has_skeleton_node

Definition at line 193 of file GLTFDataTool.h.

Referenced by GLTFData::addShell(), and GLTFData::init().

◆ image_list

tList* image_list

◆ image_no

unsigned int image_no

Definition at line 217 of file GLTFDataTool.h.

Referenced by GLTFData::addTextures(), and GLTFData::init().

◆ images

◆ joint_offset

unsigned int joint_offset

Definition at line 221 of file GLTFDataTool.h.

Referenced by GLTFData::addSkeletonNodes(), GLTFData::addSkins(), and GLTFData::init().

◆ joints_list

◆ json_data

◆ material_list

tList* material_list

◆ material_no

unsigned int material_no

Definition at line 216 of file GLTFDataTool.h.

Referenced by GLTFData::addMaterials(), and GLTFData::init().

◆ materials

tJson* materials

Definition at line 233 of file GLTFDataTool.h.

Referenced by GLTFData::addMaterials(), GLTFData::init(), and GLTFData::initGLTF().

◆ mesh_no

unsigned int mesh_no

Definition at line 211 of file GLTFDataTool.h.

Referenced by GLTFData::addMeshes(), and GLTFData::init().

◆ mesh_prim_no

unsigned int mesh_prim_no

Definition at line 212 of file GLTFDataTool.h.

Referenced by GLTFData::addAccessorsIBM(), GLTFData::addMeshes(), and GLTFData::init().

◆ meshes

tJson* meshes

Definition at line 228 of file GLTFDataTool.h.

Referenced by GLTFData::addMeshes(), GLTFData::init(), and GLTFData::initGLTF().

◆ no_offset

bool no_offset

Definition at line 181 of file GLTFDataTool.h.

Referenced by GLTFData::addShell(), and GLTFData::init().

◆ node_no

◆ node_offset

unsigned int node_offset

◆ nodes

◆ nodes_children

tJson* nodes_children

◆ num_joints

◆ phantom_out

bool phantom_out

Definition at line 180 of file GLTFDataTool.h.

Referenced by GLTFData::addShell(), and GLTFData::init().

◆ scenes

tJson* scenes

Definition at line 224 of file GLTFDataTool.h.

Referenced by GLTFData::init(), and GLTFData::initGLTF().

◆ scenes_name

tJson* scenes_name

Definition at line 225 of file GLTFDataTool.h.

Referenced by GLTFData::addScenes(), GLTFData::init(), and GLTFData::initGLTF().

◆ scenes_nodes

tJson* scenes_nodes

Definition at line 226 of file GLTFDataTool.h.

Referenced by GLTFData::addScenes(), GLTFData::init(), and GLTFData::initGLTF().

◆ shell_no

unsigned int shell_no

Definition at line 209 of file GLTFDataTool.h.

Referenced by GLTFData::addShell(), GLTFData::createBinDataAoS(), and GLTFData::init().

◆ shellNode

◆ skin_no

unsigned int skin_no

Definition at line 213 of file GLTFDataTool.h.

Referenced by GLTFData::addNodes(), GLTFData::addSkins(), and GLTFData::init().

◆ skins

◆ textures

tJson* textures

Definition at line 234 of file GLTFDataTool.h.

Referenced by GLTFData::addTextures(), GLTFData::init(), and GLTFData::initGLTF().

◆ view_no


The documentation for this class was generated from the following files: