33#include " util.h"
44#include < lodepng.h>
55
6+ #include < fstream>
67#include < algorithm>
78#include < climits>
89#include < cfloat>
@@ -429,6 +430,20 @@ int ConverterGLTF::insertIndices(std::vector<BYTE>& buffer, rw::Split* split, in
429430 return bytesLength;
430431}
431432
433+ bool ConverterGLTF::convert (char * output, char * inputDff, char * inputTxd)
434+ {
435+ std::ifstream dff (inputDff, std::ios::binary);
436+ std::ifstream txd (inputTxd, std::ios::binary);
437+
438+ rw::Clump dffStruct;
439+ rw::TextureDictionary txdStruct;
440+
441+ dffStruct.read (dff);
442+ txdStruct.read (txd);
443+
444+ return convert (output, dffStruct, txdStruct);
445+ }
446+
432447bool ConverterGLTF::convert (char * output, rw::Clump& dff)
433448{
434449 rw::TextureDictionary emptyTXD;
@@ -464,6 +479,11 @@ bool ConverterGLTF::convert(char* output, rw::Clump& dff, rw::TextureDictionary&
464479 int splits = geometry->splits .size ();
465480 int curBytesOffset = 0 ;
466481
482+ int positionsIndex = -1 ;
483+ int normalsIndex = -1 ;
484+ int texCoordIndex = -1 ;
485+
486+
467487 materials.clear ();
468488
469489 // TEXTURES
@@ -499,10 +519,19 @@ bool ConverterGLTF::convert(char* output, rw::Clump& dff, rw::TextureDictionary&
499519
500520 // VERTICI
501521 curBytesOffset += insertVertices (buffer.data , indeces, geometry, curBytesOffset);
522+ positionsIndex = currentAccessor - 1 ;
502523 // COORDINATE UV
503- curBytesOffset += insertUVTexture (buffer.data , indeces, geometry, curBytesOffset);
524+ if (materials.size () > 0 )
525+ {
526+ curBytesOffset += insertUVTexture (buffer.data , indeces, geometry, curBytesOffset);
527+ texCoordIndex = currentAccessor - 1 ;
528+ }
504529 // NORMALI
505530 curBytesOffset += insertNormals (buffer.data , indeces, geometry, curBytesOffset);
531+ normalsIndex = currentAccessor - 1 ;
532+
533+
534+
506535 // OSSA DELLO SCHELETRO
507536 // curBytesOffset += insertBones(buffer.data, mesh, geometry, curBytesOffset);
508537
@@ -522,17 +551,20 @@ bool ConverterGLTF::convert(char* output, rw::Clump& dff, rw::TextureDictionary&
522551 primitive.indices = currentAccessor - 1 ;
523552
524553 // VERTICI
525- primitive.attributes [" POSITION" ] = 0 ;
554+ primitive.attributes [" POSITION" ] = positionsIndex ;
526555
527556 // NORMALI
528557 if (geometry->hasNormals )
529- primitive.attributes [" NORMAL" ] = 2 ;
558+ primitive.attributes [" NORMAL" ] = normalsIndex ;
530559
531560 // COORDINATE UV
532- std::string texCoord = " TEXCOORD_0" ;
533- primitive.attributes [texCoord] = 1 ;
561+ if (texCoordIndex >= 0 )
562+ {
563+ std::string texCoord = " TEXCOORD_0" ;
564+ primitive.attributes [texCoord] = 1 ;
565+ primitive.material = material;
566+ }
534567
535- primitive.material = material;
536568 primitive.mode = TINYGLTF_MODE_TRIANGLES;
537569
538570 mesh.primitives .push_back (primitive);
0 commit comments