From 60c990c1d973e3ca1960b1dc38a5bafb4c125aa3 Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Mon, 6 Jun 2022 16:13:32 +0200 Subject: [PATCH] gltf2 -> idMapFile fixes. dmap and map commands work --- neo/framework/CmdSystem.h | 2 +- neo/idlib/Lexer.cpp | 32 +- neo/idlib/Lexer.h | 5 +- neo/idlib/MapFile.cpp | 14 +- neo/idlib/MapFile.h | 15 +- neo/idlib/containers/List.h | 24 +- neo/idlib/gltfExtras.cpp | 20 +- neo/idlib/gltfExtras.h | 11 +- neo/idlib/gltfParser.cpp | 1533 ++++++++++++++++++++------------- neo/idlib/gltfParser.h | 269 ++++-- neo/idlib/gltfProperties.h | 487 +++++++---- neo/renderer/ModelManager.cpp | 13 +- neo/renderer/Model_gltf.cpp | 495 ++++++----- neo/renderer/Model_gltf.h | 57 +- neo/renderer/Model_local.h | 4 +- 15 files changed, 1840 insertions(+), 1141 deletions(-) diff --git a/neo/framework/CmdSystem.h b/neo/framework/CmdSystem.h index 76f51537..bdd6ee3b 100644 --- a/neo/framework/CmdSystem.h +++ b/neo/framework/CmdSystem.h @@ -243,7 +243,7 @@ ID_INLINE void idCmdSystem::ArgCompletion_FileName( const idCmdArgs& args, void( ID_INLINE void idCmdSystem::ArgCompletion_MapName( const idCmdArgs& args, void( *callback )( const char* s ) ) { - cmdSystem->ArgCompletion_FolderExtension( args, callback, "maps/", true, ".map", ".json",".gltf",".glb", NULL ); + cmdSystem->ArgCompletion_FolderExtension( args, callback, "maps/", true, ".map", ".json", ".gltf", ".glb", NULL ); } ID_INLINE void idCmdSystem::ArgCompletion_MapNameNoJson( const idCmdArgs& args, void( *callback )( const char* s ) ) diff --git a/neo/idlib/Lexer.cpp b/neo/idlib/Lexer.cpp index 677fc43d..b885bcba 100644 --- a/neo/idlib/Lexer.cpp +++ b/neo/idlib/Lexer.cpp @@ -1507,31 +1507,43 @@ Skips until a matching close brace is found. Internal brace depths are properly skipped. ================= */ -int idLexer::SkipBracedSection( bool parseFirstBrace, braceSkipMode_t skipMode/* = BRSKIP_BRACE */, int * skipped /*= nullptr*/) { +int idLexer::SkipBracedSection( bool parseFirstBrace, braceSkipMode_t skipMode/* = BRSKIP_BRACE */, int* skipped /*= nullptr*/ ) +{ idToken token; int depth; idStr openTokens[2] = { "{" , "[" }; idStr closeTokens[2] = { "}" , "]" }; - if ( skipped != nullptr ) + if( skipped != nullptr ) + { *skipped = 0; + } int scopeCount = 0; depth = parseFirstBrace ? 0 : 1; - do { - if ( !ReadToken( &token ) ) { + do + { + if( !ReadToken( &token ) ) + { return false; } - if ( token.type == TT_PUNCTUATION ) { - if ( token == openTokens[skipMode] ) { + if( token.type == TT_PUNCTUATION ) + { + if( token == openTokens[skipMode] ) + { depth++; - if ( skipped != nullptr ) - (*skipped)++; - } else if ( token == closeTokens[skipMode] ) { + if( skipped != nullptr ) + { + ( *skipped )++; + } + } + else if( token == closeTokens[skipMode] ) + { depth--; } } - } while( depth ); + } + while( depth ); return true; } diff --git a/neo/idlib/Lexer.h b/neo/idlib/Lexer.h index a1172fb0..09fff719 100644 --- a/neo/idlib/Lexer.h +++ b/neo/idlib/Lexer.h @@ -64,7 +64,8 @@ typedef enum LEXFL_ONLYSTRINGS = BIT( 13 ) // parse as whitespace deliminated strings (quoted strings keep quotes) } lexerFlags_t; -typedef enum { +typedef enum +{ BRSKIP_BRACES, BRSKIP_BRACKET } braceSkipMode_t; @@ -188,7 +189,7 @@ public: // skip the rest of the current line int SkipRestOfLine(); // skip the braced section - int SkipBracedSection( bool parseFirstBrace = true , braceSkipMode_t skipMode = BRSKIP_BRACES,int * skipped = nullptr); + int SkipBracedSection( bool parseFirstBrace = true , braceSkipMode_t skipMode = BRSKIP_BRACES, int* skipped = nullptr ); // skips spaces, tabs, C-like comments etc. Returns false if there is no token left to read. bool SkipWhiteSpace( bool currentLine ); // unread the given token diff --git a/neo/idlib/MapFile.cpp b/neo/idlib/MapFile.cpp index fb5edb13..37154ece 100644 --- a/neo/idlib/MapFile.cpp +++ b/neo/idlib/MapFile.cpp @@ -1574,11 +1574,12 @@ bool idMapFile::Parse( const char* filename, bool ignoreRegion, bool osPath ) } bool isGTLF = false; - if ( !src.IsLoaded( ) ) { + if( !src.IsLoaded( ) ) + { // HVG: try loading a .gltf/glb second fullName.SetFileExtension( "glb" ); isGTLF = src.LoadFile( fullName, osPath ); - if ( !isGTLF ) + if( !isGTLF ) { fullName.SetFileExtension( "gltf" ); isGTLF = src.LoadFile( fullName, osPath ); @@ -1601,7 +1602,7 @@ bool idMapFile::Parse( const char* filename, bool ignoreRegion, bool osPath ) fileTime = src.GetFileTime(); entities.DeleteContents( true ); - if(!isGTLF && !src.ReadToken( &token ) ) + if( !isGTLF && !src.ReadToken( &token ) ) { return false; } @@ -1668,11 +1669,12 @@ bool idMapFile::Parse( const char* filename, bool ignoreRegion, bool osPath ) } } } - else if ( isGTLF ) + else if( isGTLF ) { gltfParser->Load( fullName ); - idMapEntity::GetEntities(gltfParser->currentAsset,entities,0); - }else + idMapEntity::GetEntities( gltfParser->currentAsset, entities, 0 ); + } + else { if( token == "Version" ) { diff --git a/neo/idlib/MapFile.h b/neo/idlib/MapFile.h index 46ba3794..e20f5427 100644 --- a/neo/idlib/MapFile.h +++ b/neo/idlib/MapFile.h @@ -349,7 +349,7 @@ public: void ConvertFromBrush( const idMapBrush* brush, int entityNum, int primitiveNum ); void ConvertFromPatch( const idMapPatch* patch, int entityNum, int primitiveNum ); - void ConvertFromMeshGltf( const gltfMesh * mesh , gltfData * data ); + void ConvertFromMeshGltf( const gltfMesh* mesh , gltfData* data ); static MapPolygonMesh* Parse( idLexer& src, const idVec3& origin, float version = CURRENT_MAP_VERSION ); bool Write( idFile* fp, int primitiveNum, const idVec3& origin ) const; @@ -368,7 +368,8 @@ public: return verts.Append( v ); } - int AddVertices( const idList &v ) { + int AddVertices( const idList& v ) + { return verts.Append( v ); } @@ -426,9 +427,9 @@ protected: class idMapEntity { - typedef idList EntityList; - typedef idList &EntityListRef; - typedef idList *EntityListPtr; + typedef idList EntityList; + typedef idList& EntityListRef; + typedef idList* EntityListPtr; friend class idMapFile; @@ -446,10 +447,10 @@ public: primitives.DeleteContents( true ); } // HVG check gltf scene for entities - static int GetEntities( gltfData * data, EntityListRef entities, int scene = 0 ); + static int GetEntities( gltfData* data, EntityListRef entities, int scene = 0 ); static idMapEntity* Parse( idLexer& src, bool worldSpawn = false, float version = CURRENT_MAP_VERSION ); bool Write( idFile* fp, int entityNum, bool valve220 ) const; - + // HVG NOTE: this is not compatible with gltf (extra) json! // RB begin static idMapEntity* ParseJSON( idLexer& src ); diff --git a/neo/idlib/containers/List.h b/neo/idlib/containers/List.h index 4bc0f967..d7ec5f86 100644 --- a/neo/idlib/containers/List.h +++ b/neo/idlib/containers/List.h @@ -203,19 +203,29 @@ public: memTag = ( byte )tag_; }; - struct Iterator { - _type_ *p; - _type_ &operator*( ) { return *p; } - bool operator != ( const Iterator &rhs ) { + struct Iterator + { + _type_* p; + _type_& operator*( ) + { + return *p; + } + bool operator != ( const Iterator& rhs ) + { return p != rhs.p; } - void operator ++( ) { ++p; } + void operator ++( ) + { + ++p; + } }; - auto begin( ) const { // const version + auto begin( ) const // const version + { return Iterator{list}; }; - auto end( ) const { // const version + auto end( ) const // const version + { return Iterator{list + Num( )}; }; diff --git a/neo/idlib/gltfExtras.cpp b/neo/idlib/gltfExtras.cpp index 3f9ee909..78459708 100644 --- a/neo/idlib/gltfExtras.cpp +++ b/neo/idlib/gltfExtras.cpp @@ -4,32 +4,34 @@ extern idCVar gltf_parseVerbose; -void gltfExtra_Scatter::parse( idToken &token, idLexer * parser ) { +void gltfExtra_Scatter::parse( idToken& token, idLexer* parser ) +{ parser->UnreadToken( &token ); gltfItemArray scatterInfo; GLTFARRAYITEM( scatterInfo, emitter, gltfObject ); - scatterInfo.Parse( parser,true ); + scatterInfo.Parse( parser, true ); } -void gltfExtra_cvar::parse( idToken &token, idLexer *parser ) { +void gltfExtra_cvar::parse( idToken& token, idLexer* parser ) +{ parser->UnreadToken( &token ); gltfItemArray cvarInfo; - idStr n,t,v,d; - GLTFARRAYITEMREF( cvarInfo, name, gltfItem , n); - GLTFARRAYITEMREF( cvarInfo, type, gltfItem , t); + idStr n, t, v, d; + GLTFARRAYITEMREF( cvarInfo, name, gltfItem , n ); + GLTFARRAYITEMREF( cvarInfo, type, gltfItem , t ); GLTFARRAYITEMREF( cvarInfo, value, gltfItem, v ); - GLTFARRAYITEMREF( cvarInfo, desc, gltfItem , d); + GLTFARRAYITEMREF( cvarInfo, desc, gltfItem , d ); int total = cvarInfo.Parse( parser ); assert( total == 3 ); - idCVar * gltExtra_cvar = new idCVar( + idCVar* gltExtra_cvar = new idCVar( n.c_str(), v.c_str(), CVAR_SYSTEM | CVAR_BOOL, d.c_str() ); - cvarSystem->Register(gltExtra_cvar); + cvarSystem->Register( gltExtra_cvar ); } \ No newline at end of file diff --git a/neo/idlib/gltfExtras.h b/neo/idlib/gltfExtras.h index 69c785f7..34f559fe 100644 --- a/neo/idlib/gltfExtras.h +++ b/neo/idlib/gltfExtras.h @@ -10,7 +10,7 @@ virtual idStr &Name( ) { return name; } \ private: \ idStr name;} -#pragma endregion +#pragma endregion #endif //Helper macros for gltf data deserialize @@ -19,9 +19,10 @@ #ifndef GLTF_EXTRAS_H #define GLTF_EXTRAS_H -class test { -public: - test(){ } +class test +{ +public: + test() { } }; @@ -31,5 +32,5 @@ gltfExtraParser( cvar, idCVar ); #endif // GLTF_EXTRAS_H #ifndef gltfExternalParser -#undef gltfExtraParser + #undef gltfExtraParser #endif \ No newline at end of file diff --git a/neo/idlib/gltfParser.cpp b/neo/idlib/gltfParser.cpp index 05ab3aa9..63f0b43b 100644 --- a/neo/idlib/gltfParser.cpp +++ b/neo/idlib/gltfParser.cpp @@ -24,7 +24,7 @@ idCVar gltfParser_PrefixNodeWithID( "gltfParser_PrefixNodeWithID", "0", CVAR_SYS //gltf_sampler_mag_type_map s_samplerMagTypeMap[] = { // //9728 NEAREST //mag/min // 9728 , BGFX_SAMPLER_MIN_ANISOTROPIC -// //9729 LINEAR // mag/min +// //9729 LINEAR // mag/min // // // //9984 NEAREST_MIPMAP_NEAREST //min // // @@ -49,8 +49,9 @@ idCVar gltfParser_PrefixNodeWithID( "gltfParser_PrefixNodeWithID", "0", CVAR_SYS // return flags; //} - -gltf_mesh_attribute_map s_meshAttributeMap[] = { + +gltf_mesh_attribute_map s_meshAttributeMap[] = +{ "POSITION", gltfMesh_Primitive_Attribute::Type::Position, 3, "NORMAL", gltfMesh_Primitive_Attribute::Type::Normal, 3, "TANGENT", gltfMesh_Primitive_Attribute::Type::Tangent, 3, @@ -62,7 +63,7 @@ gltf_mesh_attribute_map s_meshAttributeMap[] = { "TEXCOORD_5", gltfMesh_Primitive_Attribute::Type::TexCoord5, 2, "TEXCOORD_6", gltfMesh_Primitive_Attribute::Type::TexCoord6, 2, "TEXCOORD_7", gltfMesh_Primitive_Attribute::Type::TexCoord7, 2, - "COLOR_0", gltfMesh_Primitive_Attribute::Type::Color0, 4, + "COLOR_0", gltfMesh_Primitive_Attribute::Type::Color0, 4, "COLOR_1", gltfMesh_Primitive_Attribute::Type::Color1, 4, "COLOR_2", gltfMesh_Primitive_Attribute::Type::Color2, 4, "COLOR_3", gltfMesh_Primitive_Attribute::Type::Color3, 4, @@ -71,17 +72,20 @@ gltf_mesh_attribute_map s_meshAttributeMap[] = { "", gltfMesh_Primitive_Attribute::Type::Count }; -gltfMesh_Primitive_Attribute::Type GetAttributeEnum( const char *str , uint * elementSize = nullptr) { - int i = -1; - while ( s_meshAttributeMap[++i].attib != gltfMesh_Primitive_Attribute::Type::Count ) - if ( !idStr::Icmp( s_meshAttributeMap[i].stringID, str ) ) +gltfMesh_Primitive_Attribute::Type GetAttributeEnum( const char* str , uint* elementSize = nullptr ) +{ + int i = -1; + while( s_meshAttributeMap[++i].attib != gltfMesh_Primitive_Attribute::Type::Count ) + if( !idStr::Icmp( s_meshAttributeMap[i].stringID, str ) ) + { + if( elementSize != nullptr ) { - if (elementSize != nullptr) - *elementSize = s_meshAttributeMap[i].elementSize; - return s_meshAttributeMap[i].attib; + *elementSize = s_meshAttributeMap[i].elementSize; } - - return gltfMesh_Primitive_Attribute::Type::Count; + return s_meshAttributeMap[i].attib; + } + + return gltfMesh_Primitive_Attribute::Type::Count; } //https://github.com/KhronosGroup/glTF/issues/832 @@ -90,13 +94,14 @@ gltfMesh_Primitive_Attribute::Type GetAttributeEnum( const char *str , uint * el // "unsigned byte", 5121, bgfx::AttribType::Uint8, 1 , // "signed short", 5122, bgfx::AttribType::Int16, 2 , // "unsigned short", 5123, bgfx::AttribType::Count, 2 , -// "unsigned int", 5125, bgfx::AttribType::Count, 4 , +// "unsigned int", 5125, bgfx::AttribType::Count, 4 , // "float", 5126, bgfx::AttribType::Float, 4 , // "double", 5130, bgfx::AttribType::Float, 8 , // "", 0, bgfx::AttribType::Count, 0 //}; // -gltf_accessor_component_type_map s_nativeComponentTypeMap[] = { +gltf_accessor_component_type_map s_nativeComponentTypeMap[] = +{ "signed byte", 5120, gltf_accessor_component::Type::_byte, 1 , "unsigned byte", 5121, gltf_accessor_component::Type::_uByte, 1 , "signed short", 5122, gltf_accessor_component::Type::_short, 2 , @@ -107,23 +112,27 @@ gltf_accessor_component_type_map s_nativeComponen "", 0, gltf_accessor_component::Type::Count, 0 }; // -gltf_accessor_component::Type GetComponentTypeEnum( int id , uint * sizeInBytes = nullptr) { +gltf_accessor_component::Type GetComponentTypeEnum( int id , uint* sizeInBytes = nullptr ) +{ int i = -1; - while ( s_nativeComponentTypeMap[++i].id != 0) - if ( s_nativeComponentTypeMap[i].id == id ) { - if (sizeInBytes != nullptr ) + while( s_nativeComponentTypeMap[++i].id != 0 ) + if( s_nativeComponentTypeMap[i].id == id ) + { + if( sizeInBytes != nullptr ) + { *sizeInBytes = s_nativeComponentTypeMap[i].sizeInBytes; + } return s_nativeComponentTypeMap[i].type; } - + return gltf_accessor_component::Type::Count; } //some arbitrary amount for now. #define GLTF_MAX_CHUNKS 32 -idList gltfData::dataList; +idList gltfData::dataList; idHashIndex gltfData::fileDataHash; gltfItemArray* gltfItem_Extra::items = new gltfItemArray(); @@ -138,24 +147,29 @@ idCVar gltf_parseVerbose( "gltf_parseVerbose", "0", CVAR_RENDERER | CVAR_ARCHIVE // name->Set (&target->name); #define GLTFARRAYITEMREF(target,name) name->Set(&target->name) -void gltfPropertyArray::Iterator::operator ++( ) { +void gltfPropertyArray::Iterator::operator ++( ) +{ //check if by modification, we are iterating again. //custom not AOS things can do this since it is not nicely guarded by braces - if ( array->dirty && (!array->iterating && !array->isArrayOfStructs) ) { + if( array->dirty && ( !array->iterating && !array->isArrayOfStructs ) ) + { array->iterating = array->parser->PeekTokenString( "," ); - if ( array->iterating ) { + if( array->iterating ) + { array->properties.AssureSizeAlloc( array->properties.Num( ) + 1, idListNewElement ); array->parser->ExpectTokenString( "," ); - } + } } - if ( array->iterating ) + if( array->iterating ) { p = array->properties[array->properties.Num( ) - 1]; p->array = array; - if (array->isArrayOfStructs ) + if( array->isArrayOfStructs ) + { array->parser->ParseBracedSection( p->item ); + } else { idToken token; @@ -163,87 +177,107 @@ void gltfPropertyArray::Iterator::operator ++( ) { p->item = token; } array->iterating = array->parser->PeekTokenString( "," ); - if ( array->iterating ) { + if( array->iterating ) + { array->properties.AssureSizeAlloc( array->properties.Num( ) + 1, idListNewElement ); array->parser->ExpectTokenString( "," ); - } - }else + } + } + else { - if ( array->dirty ){ + if( array->dirty ) + { p = array->endPtr; array->dirty = false; } - else if ( array->index + 1 < array->properties.Num() ) + else if( array->index + 1 < array->properties.Num() ) + { p = array->properties[++array->index]; + } else + { p = array->endPtr; + } } } gltfPropertyArray::~gltfPropertyArray() { delete endPtr; - properties.DeleteContents(true); + properties.DeleteContents( true ); } -gltfPropertyArray::gltfPropertyArray( idLexer *Parser, bool AoS/* = true */) - : parser( Parser ), iterating( true ), dirty( true ), index( 0 ), isArrayOfStructs(AoS) +gltfPropertyArray::gltfPropertyArray( idLexer* Parser, bool AoS/* = true */ ) + : parser( Parser ), iterating( true ), dirty( true ), index( 0 ), isArrayOfStructs( AoS ) { - properties.AssureSizeAlloc(32, idListNewElement ); - properties.SetNum(0); + properties.AssureSizeAlloc( 32, idListNewElement ); + properties.SetNum( 0 ); endPtr = new gltfPropertyItem(); endPtr->array = this; } -gltfPropertyArray::Iterator gltfPropertyArray::begin( ) { - if ( iterating ) +gltfPropertyArray::Iterator gltfPropertyArray::begin( ) +{ + if( iterating ) { - if ( isArrayOfStructs && !parser->PeekTokenString( "{" ) ) { - if ( !parser->ExpectTokenString( "[" ) && parser->PeekTokenString( "{" ) ) + if( isArrayOfStructs && !parser->PeekTokenString( "{" ) ) + { + if( !parser->ExpectTokenString( "[" ) && parser->PeekTokenString( "{" ) ) + { common->FatalError( "Malformed gltf array" ); - }else if ( !isArrayOfStructs && !parser->ExpectTokenString( "[") ) + } + } + else if( !isArrayOfStructs && !parser->ExpectTokenString( "[" ) ) + { common->FatalError( "Malformed gltf array" ); + } - properties.AssureSizeAlloc( properties.Num() + 1,idListNewElement ); - gltfPropertyItem *start = properties[0]; - start->array = this; - if (isArrayOfStructs ) + properties.AssureSizeAlloc( properties.Num() + 1, idListNewElement ); + gltfPropertyItem* start = properties[0]; + start->array = this; + if( isArrayOfStructs ) + { parser->ParseBracedSection( start->item ); + } else { idToken token; - parser->ExpectAnyToken(&token); + parser->ExpectAnyToken( &token ); start->item = token; } iterating = parser->PeekTokenString( "," ); - if ( iterating ) + if( iterating ) { - properties.AssureSizeAlloc( properties.Num() + 1,idListNewElement ); + properties.AssureSizeAlloc( properties.Num() + 1, idListNewElement ); parser->ExpectTokenString( "," ); - } + } return Iterator{ this , start }; } index = 0; - return Iterator{ this ,properties[index]}; + return Iterator{ this , properties[index]}; } -gltfPropertyArray::Iterator gltfPropertyArray::end( ) { +gltfPropertyArray::Iterator gltfPropertyArray::end( ) +{ return Iterator{ this , endPtr}; } -int gltfItemArray::Fill( idLexer *lexer, idDict *strPairs ) { +int gltfItemArray::Fill( idLexer* lexer, idDict* strPairs ) +{ idToken token; bool parsing = true; int parseCount = 0; lexer->ExpectTokenString( "{" ); - while ( parsing && !lexer->PeekTokenString( "}" ) && lexer->ExpectAnyToken( &token ) ) { + while( parsing && !lexer->PeekTokenString( "}" ) && lexer->ExpectAnyToken( &token ) ) + { lexer->ExpectTokenString( ":" ); idStr key = token; idStr value; key.StripTrailingWhitespace( ); - if ( lexer->PeekTokenString( "{" )) + if( lexer->PeekTokenString( "{" ) ) { - lexer->ParseBracedSectionExact(value); + lexer->ParseBracedSectionExact( value ); value.StripTrailingWhitespace( ); strPairs->Set( key, value ); - }else + } + else { lexer->ExpectAnyToken( &token ); value = token; @@ -251,55 +285,68 @@ int gltfItemArray::Fill( idLexer *lexer, idDict *strPairs ) { key.StripTrailingWhitespace( ); strPairs->Set( key, token ); } - + parseCount++; parsing = lexer->PeekTokenString( "," ); - if ( parsing ) + if( parsing ) + { lexer->ExpectTokenString( "," ); + } } lexer->ExpectTokenString( "}" ); return parseCount; } -int gltfItemArray::Parse(idLexer * lexer, bool forwardLexer/* = false*/) { +int gltfItemArray::Parse( idLexer* lexer, bool forwardLexer/* = false*/ ) +{ idToken token; bool parsing = true; int parseCount = 0; lexer->ExpectTokenString( "{" ); - while ( parsing && !lexer->PeekTokenString( "}" ) && lexer->ExpectAnyToken( &token ) ) + while( parsing && !lexer->PeekTokenString( "}" ) && lexer->ExpectAnyToken( &token ) ) { lexer->ExpectTokenString( ":" ); bool parsed = false; - for ( auto item : items ) + for( auto item : items ) { - if ( item->Name( ) == token ) + if( item->Name( ) == token ) { lexer->ExpectAnyToken( &token ); - if ( forwardLexer ) + if( forwardLexer ) + { item->parse( token , lexer ); + } else + { item->parse( token ); + } parsed = true; break; } } - if (!parsed) + if( !parsed ) + { lexer->SkipBracedSection(); + } else + { parseCount++; + } parsing = lexer->PeekTokenString( "," ); - if ( parsing ) + if( parsing ) + { lexer->ExpectTokenString( "," ); + } } lexer->ExpectTokenString( "}" ); return parseCount; } -byte * gltfData::AddData(int size, int * bufferID/*=nullptr*/) +byte* gltfData::AddData( int size, int* bufferID/*=nullptr*/ ) { - if (totalChunks == -1 ) + if( totalChunks == -1 ) { - json = (byte*) Mem_ClearedAlloc(size,TAG_IDLIB_GLTF); + json = ( byte* ) Mem_ClearedAlloc( size, TAG_IDLIB_GLTF ); totalChunks++; jsonDataLength = size; return json; @@ -307,44 +354,53 @@ byte * gltfData::AddData(int size, int * bufferID/*=nullptr*/) int id = totalChunks; - if (data == nullptr ) - data = ( byte ** ) Mem_ClearedAlloc( GLTF_MAX_CHUNKS * sizeof( byte * ),TAG_IDLIB_GLTF ); - data[totalChunks++] = (byte*) Mem_ClearedAlloc(size,TAG_IDLIB_GLTF); - - if ( bufferID ) - *bufferID = id; + if( data == nullptr ) + { + data = ( byte** ) Mem_ClearedAlloc( GLTF_MAX_CHUNKS * sizeof( byte* ), TAG_IDLIB_GLTF ); + } + data[totalChunks++] = ( byte* ) Mem_ClearedAlloc( size, TAG_IDLIB_GLTF ); + + if( bufferID ) + { + *bufferID = id; + } return data[id]; } -bool gltfItem_uri::Convert( ) { +bool gltfItem_uri::Convert( ) +{ //HVG_TODO // uri cache. //read data int length = fileSystem->ReadFile( item->c_str( ), NULL ); - idFile *file = fileSystem->OpenFileRead( item->c_str() ); + idFile* file = fileSystem->OpenFileRead( item->c_str() ); //create buffer - gltfBuffer *buffer = data->Buffer( ); + gltfBuffer* buffer = data->Buffer( ); buffer->parent = data; buffer->name = item->c_str( ); buffer->byteLength = length; int bufferID = -1; - byte * dest = data->AddData( length, &bufferID ); + byte* dest = data->AddData( length, &bufferID ); - if (file->Read( dest, length ) != length) - common->FatalError("Could not read %s",item->c_str() ); - - if (gltf_parseVerbose.GetBool() ) - common->Warning("gltf Uri %s loaded into buffer[ %i ]",buffer->name.c_str(),bufferID ); + if( file->Read( dest, length ) != length ) + { + common->FatalError( "Could not read %s", item->c_str() ); + } + + if( gltf_parseVerbose.GetBool() ) + { + common->Warning( "gltf Uri %s loaded into buffer[ %i ]", buffer->name.c_str(), bufferID ); + } //create bufferview //if bufferview is not set, this is an buffer.uri. //A bufferview should aready be defined if the buffer is used. - if (bufferView != nullptr ) + if( bufferView != nullptr ) { *bufferView = data->BufferViewList().Num(); - gltfBufferView * newBufferView = data->BufferView( ); + gltfBufferView* newBufferView = data->BufferView( ); newBufferView->buffer = bufferID; newBufferView->byteLength = length; newBufferView->parent = data; @@ -355,59 +411,68 @@ bool gltfItem_uri::Convert( ) { return false; } -void gltfItem_Extra::parse( idToken &token ) { +void gltfItem_Extra::parse( idToken& token ) +{ parser->UnreadToken( &token ); - parser->ParseBracedSectionExact(item->json); + parser->ParseBracedSectionExact( item->json ); idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ); lexer.LoadMemory( item->json, item->json.Size( ), "gltfItem_Extra", 0 ); - items->Fill(&lexer,&item->strPairs); + items->Fill( &lexer, &item->strPairs ); lexer.Reset(); items->Parse( &lexer , true ); - - if ( gltf_parseVerbose.GetBool( ) ) + + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", item->json.c_str( ) ); + } } -void gltfItem_Extra::Register( parsable *extra ) { - common->DPrintf("...Registering gltf Extra \"%s\" total(%i)\n",extra->Name().c_str(),items->Num() ); +void gltfItem_Extra::Register( parsable* extra ) +{ + common->DPrintf( "...Registering gltf Extra \"%s\" total(%i)\n", extra->Name().c_str(), items->Num() ); items->AddItemDef( extra ); } -void gltfItem_animation_sampler::parse( idToken &token ) { +void gltfItem_animation_sampler::parse( idToken& token ) +{ gltfItemArray animSampler; - GLTFARRAYITEM( animSampler, input, gltfItem_integer); + GLTFARRAYITEM( animSampler, input, gltfItem_integer ); GLTFARRAYITEM( animSampler, interpolation, gltfItem ); - GLTFARRAYITEM( animSampler, output, gltfItem_integer); + GLTFARRAYITEM( animSampler, output, gltfItem_integer ); GLTFARRAYITEM( animSampler, extensions, gltfItem ); - GLTFARRAYITEM( animSampler, extras, gltfItem_Extra); + GLTFARRAYITEM( animSampler, extras, gltfItem_Extra ); gltfPropertyArray array = gltfPropertyArray( parser ); - for ( auto &prop : array ) { + for( auto& prop : array ) + { idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ); lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfAnimation_Sampler", 0 ); item->AssureSizeAlloc( item->Num( ) + 1, idListNewElement ); - gltfAnimation_Sampler *gltfAnimSampler = ( *item )[item->Num( ) - 1]; + gltfAnimation_Sampler* gltfAnimSampler = ( *item )[item->Num( ) - 1]; GLTFARRAYITEMREF( gltfAnimSampler, input ); GLTFARRAYITEMREF( gltfAnimSampler, interpolation ); GLTFARRAYITEMREF( gltfAnimSampler, output ); GLTFARRAYITEMREF( gltfAnimSampler, extensions ); - extras->Set ( &gltfAnimSampler->extras, &lexer ); + extras->Set( &gltfAnimSampler->extras, &lexer ); animSampler.Parse( &lexer ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", prop.item.c_str( ) ); + } - gltfAnimSampler->intType = gltfAnimation_Sampler::resolveType(gltfAnimSampler->interpolation); + gltfAnimSampler->intType = gltfAnimation_Sampler::resolveType( gltfAnimSampler->interpolation ); } parser->ExpectTokenString( "]" ); } -void gltfItem_animation_channel_target::parse( idToken &token ) { +void gltfItem_animation_channel_target::parse( idToken& token ) +{ parser->UnreadToken( &token ); gltfItemArray animChannelTarget; - GLTFARRAYITEM( animChannelTarget, node, gltfItem_integer); + GLTFARRAYITEM( animChannelTarget, node, gltfItem_integer ); GLTFARRAYITEM( animChannelTarget, path, gltfItem ); GLTFARRAYITEM( animChannelTarget, extensions, gltfItem ); GLTFARRAYITEM( animChannelTarget, extras, gltfItem_Extra ); @@ -415,16 +480,19 @@ void gltfItem_animation_channel_target::parse( idToken &token ) { GLTFARRAYITEMREF( item, node ); GLTFARRAYITEMREF( item, path ); GLTFARRAYITEMREF( item, extensions ); - extras->Set ( &item->extras, parser ); + extras->Set( &item->extras, parser ); animChannelTarget.Parse( parser ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", token.c_str( ) ); + } - item->TRS = gltfAnimation_Channel_Target::resolveType(item->path); + item->TRS = gltfAnimation_Channel_Target::resolveType( item->path ); } -void gltfItem_animation_channel::parse( idToken &token ) { +void gltfItem_animation_channel::parse( idToken& token ) +{ //parser->UnreadToken( &token ); gltfItemArray anim; GLTFARRAYITEM( anim, sampler, gltfItem_integer ); @@ -433,216 +501,267 @@ void gltfItem_animation_channel::parse( idToken &token ) { GLTFARRAYITEM( anim, extras, gltfItem_Extra ); gltfPropertyArray array = gltfPropertyArray( parser ); - for ( auto &prop : array ) { + for( auto& prop : array ) + { idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ); lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfAnimation_Channel", 0 ); item->AssureSizeAlloc( item->Num( ) + 1, idListNewElement ); - gltfAnimation_Channel *gltfAnimationChannel = ( *item )[item->Num( ) - 1]; + gltfAnimation_Channel* gltfAnimationChannel = ( *item )[item->Num( ) - 1]; GLTFARRAYITEMREF( gltfAnimationChannel, sampler ); - target->Set (&gltfAnimationChannel->target,&lexer ); + target->Set( &gltfAnimationChannel->target, &lexer ); GLTFARRAYITEMREF( gltfAnimationChannel, extensions ); - extras->Set (&gltfAnimationChannel->extras,&lexer); + extras->Set( &gltfAnimationChannel->extras, &lexer ); anim.Parse( &lexer ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", token.c_str( ) ); + } } parser->ExpectTokenString( "]" ); } -void gltfItem_mesh_primitive::parse( idToken &token ) -{ +void gltfItem_mesh_primitive::parse( idToken& token ) +{ gltfItemArray prim; GLTFARRAYITEM( prim, attributes, gltfItem_mesh_primitive_attribute ); GLTFARRAYITEM( prim, indices, gltfItem_integer ); GLTFARRAYITEM( prim, material, gltfItem_integer ); GLTFARRAYITEM( prim, mode, gltfItem_integer ); - GLTFARRAYITEM( prim, target, gltfItem ); + GLTFARRAYITEM( prim, target, gltfItem ); GLTFARRAYITEM( prim, extensions, gltfItem ); GLTFARRAYITEM( prim, extras, gltfItem_Extra ); gltfPropertyArray array = gltfPropertyArray( parser ); - for ( auto &prop : array ) { + for( auto& prop : array ) + { idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ); lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfItem_mesh_primitiveB", 0 ); - item->AssureSizeAlloc(item->Num() + 1,idListNewElement); - gltfMesh_Primitive *gltfMeshPrim =(*item)[item->Num() - 1]; + item->AssureSizeAlloc( item->Num() + 1, idListNewElement ); + gltfMesh_Primitive* gltfMeshPrim = ( *item )[item->Num() - 1]; - attributes->Set ( &gltfMeshPrim->attributes, &lexer ); + attributes->Set( &gltfMeshPrim->attributes, &lexer ); GLTFARRAYITEMREF( gltfMeshPrim, indices ); GLTFARRAYITEMREF( gltfMeshPrim, material ); GLTFARRAYITEMREF( gltfMeshPrim, mode ); GLTFARRAYITEMREF( gltfMeshPrim, target ); GLTFARRAYITEMREF( gltfMeshPrim, extensions ); - extras->Set ( &gltfMeshPrim->extras, &lexer ); + extras->Set( &gltfMeshPrim->extras, &lexer ); prim.Parse( &lexer ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", prop.item.c_str( ) ); + } } parser->ExpectTokenString( "]" ); } -void gltfItem_mesh_primitive_attribute::parse( idToken &token ) { +void gltfItem_mesh_primitive_attribute::parse( idToken& token ) +{ bool parsing = true; - while ( parsing && parser->ExpectAnyToken( &token ) ) { - + while( parsing && parser->ExpectAnyToken( &token ) ) + { + item->AssureSizeAlloc( item->Num( ) + 1, idListNewElement ); - gltfMesh_Primitive_Attribute *attr = ( *item )[item->Num( ) - 1]; + gltfMesh_Primitive_Attribute* attr = ( *item )[item->Num( ) - 1]; parser->ExpectTokenString( ":" ); attr->attributeSemantic = token; attr->type = GetAttributeEnum( attr->attributeSemantic.c_str(), &attr->elementSize ); parser->ExpectAnyToken( &token ); attr->accessorIndex = token.GetIntValue(); parsing = parser->PeekTokenString( "," ); - if ( parsing ) + if( parsing ) + { parser->ExpectTokenString( "," ); + } } parser->ExpectTokenString( "}" ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", token.c_str( ) ); + } } -void gltfItem_integer_array::parse( idToken &token ) { - +void gltfItem_integer_array::parse( idToken& token ) +{ + parser->UnreadToken( &token ); gltfPropertyArray array = gltfPropertyArray( parser, false ); - for ( auto &prop : array ) { + for( auto& prop : array ) + { idStr neg; - int &value = item->Alloc( ); + int& value = item->Alloc( ); value = prop.item.GetIntValue(); - if ( prop.item.type == TT_PUNCTUATION && prop.item == "-" ) { + if( prop.item.type == TT_PUNCTUATION && prop.item == "-" ) + { parser->ExpectTokenType( TT_NUMBER, 0, &prop.item ); value = -( prop.item.GetIntValue( ) ); neg = "-"; - } else if ( prop.item.type == TT_NUMBER ) { + } + else if( prop.item.type == TT_NUMBER ) + { value = prop.item.GetIntValue( ); - } else + } + else + { common->FatalError( "parse error" ); + } - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s%s", neg.c_str( ), prop.item.c_str( ) ); + } } parser->ExpectTokenString( "]" ); } -void gltfItem_number_array::parse( idToken &token ) { +void gltfItem_number_array::parse( idToken& token ) +{ - parser->UnreadToken(&token); + parser->UnreadToken( &token ); gltfPropertyArray array = gltfPropertyArray( parser, false ); - for ( auto &prop : array ) { + for( auto& prop : array ) + { idStr neg; double& value = item->Alloc( ); - if ( prop.item.type == TT_PUNCTUATION && prop.item == "-" ) { + if( prop.item.type == TT_PUNCTUATION && prop.item == "-" ) + { parser->ExpectTokenType( TT_NUMBER, 0, &prop.item ); - value = -(prop.item.GetDoubleValue()); + value = -( prop.item.GetDoubleValue() ); neg = "-"; - } else if ( prop.item.type == TT_NUMBER ) { + } + else if( prop.item.type == TT_NUMBER ) + { value = prop.item.GetDoubleValue( ); - }else - common->FatalError("parse error" ); + } + else + { + common->FatalError( "parse error" ); + } - if ( gltf_parseVerbose.GetBool( ) ) - common->Printf( "%s%s", neg.c_str(),prop.item.c_str( ) ); + if( gltf_parseVerbose.GetBool( ) ) + { + common->Printf( "%s%s", neg.c_str(), prop.item.c_str( ) ); + } } parser->ExpectTokenString( "]" ); } -void gltfItem_vec4::parse( idToken &token ) { +void gltfItem_vec4::parse( idToken& token ) +{ - auto *numbers = new gltfItem_number_array( "" ); + auto* numbers = new gltfItem_number_array( "" ); idList numberarray; numbers->Set( &numberarray, parser ); numbers->parse( token ); - if ( numbers->item->Num( ) != 4 ) + if( numbers->item->Num( ) != 4 ) + { common->FatalError( "gltfItem_vec4 : missing arguments, expected 4, got %i", numbers->item->Num( ) ); + } - double *val = numbers->item->Ptr( ); + double* val = numbers->item->Ptr( ); *item = idVec4( val[0], val[1], val[2], val[3] ); } -void gltfItem_vec3::parse( idToken &token ) { - auto *numbers = new gltfItem_number_array( "" ); +void gltfItem_vec3::parse( idToken& token ) +{ + auto* numbers = new gltfItem_number_array( "" ); idList numberarray; numbers->Set( &numberarray, parser ); numbers->parse( token ); - if ( numbers->item->Num( ) != 3 ) + if( numbers->item->Num( ) != 3 ) + { common->FatalError( "gltfItem_vec3 : missing arguments, expected 3, got %i", numbers->item->Num( ) ); + } - double *val = numbers->item->Ptr( ); + double* val = numbers->item->Ptr( ); *item = idVec3( val[0], val[1], val[2] ); } -void gltfItem_vec2::parse( idToken &token ) { - auto *numbers = new gltfItem_number_array( "" ); +void gltfItem_vec2::parse( idToken& token ) +{ + auto* numbers = new gltfItem_number_array( "" ); idList numberarray; numbers->Set( &numberarray, parser ); numbers->parse( token ); - if ( numbers->item->Num( ) != 2 ) + if( numbers->item->Num( ) != 2 ) + { common->FatalError( "gltfItem_vec3 : missing arguments, expected 2, got %i", numbers->item->Num( ) ); + } - double *val = numbers->item->Ptr( ); + double* val = numbers->item->Ptr( ); *item = idVec2( val[0], val[1] ); } -void gltfItem_quat::parse( idToken &token ) { - auto * numbers = new gltfItem_number_array(""); +void gltfItem_quat::parse( idToken& token ) +{ + auto* numbers = new gltfItem_number_array( "" ); idList numberarray; numbers->Set( &numberarray, parser ); numbers->parse( token ); - if (numbers->item->Num() != 4 ) - common->FatalError("gltfItem_quat : missing arguments, expectd 4, got %i", numbers->item->Num( ) ); + if( numbers->item->Num() != 4 ) + { + common->FatalError( "gltfItem_quat : missing arguments, expectd 4, got %i", numbers->item->Num( ) ); + } - double * val = numbers->item->Ptr(); + double* val = numbers->item->Ptr(); *item = idQuat( val[0] , val[1] , val[2] , val[3] ); } -void gltfItem_mat4::parse( idToken &token ) { - auto *numbers = new gltfItem_number_array( "" ); +void gltfItem_mat4::parse( idToken& token ) +{ + auto* numbers = new gltfItem_number_array( "" ); idList numberarray; numbers->Set( &numberarray, parser ); numbers->parse( token ); - if ( numbers->item->Num( ) != 16 ) + if( numbers->item->Num( ) != 16 ) + { common->FatalError( "gltfItem_mat4 : missing arguments, expectd 16, got %i", numbers->item->Num( ) ); + } - double *val = numbers->item->Ptr( ); - *item = idMat4( - val[0], val[1], val[2], val[3], - val[4], val[5], val[6], val[7], - val[8], val[9], val[10], val[11], - val[12], val[13], val[14], val[15] - ); + double* val = numbers->item->Ptr( ); + *item = idMat4( + val[0], val[1], val[2], val[3], + val[4], val[5], val[6], val[7], + val[8], val[9], val[10], val[11], + val[12], val[13], val[14], val[15] + ); } -void gltfItem_accessor_sparse::parse( idToken &token ) { - parser->Warning("%s is untested!", "gltfItem_accessor_sparse" ); +void gltfItem_accessor_sparse::parse( idToken& token ) +{ + parser->Warning( "%s is untested!", "gltfItem_accessor_sparse" ); gltfItemArray sparse; GLTFARRAYITEM( sparse, count, gltfItem_integer ); - GLTFARRAYITEM( sparse, indices, gltfItem_accessor_sparse_indices); + GLTFARRAYITEM( sparse, indices, gltfItem_accessor_sparse_indices ); GLTFARRAYITEM( sparse, values, gltfItem_accessor_sparse_values ); GLTFARRAYITEM( sparse, extensions, gltfItem ); GLTFARRAYITEM( sparse, extras, gltfItem_Extra ); GLTFARRAYITEMREF( item, count ); - indices->Set ( &item->indices, parser ); - values->Set ( &item->values, parser ); + indices->Set( &item->indices, parser ); + values->Set( &item->values, parser ); GLTFARRAYITEMREF( item, extensions ); - extras->Set ( &item->extras, parser ); + extras->Set( &item->extras, parser ); sparse.Parse( parser ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", token.c_str( ) ); + } } -void gltfItem_accessor_sparse_values::parse( idToken &token ) { +void gltfItem_accessor_sparse_values::parse( idToken& token ) +{ parser->Warning( "%s is untested!", "gltfItem_accessor_sparse_values" ); gltfItemArray values; @@ -654,13 +773,16 @@ void gltfItem_accessor_sparse_values::parse( idToken &token ) { GLTFARRAYITEMREF( item, bufferView ); GLTFARRAYITEMREF( item, byteOffset ); GLTFARRAYITEMREF( item, extensions ); - extras->Set ( &item->extras, parser ); + extras->Set( &item->extras, parser ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", token.c_str( ) ); + } } -void gltfItem_accessor_sparse_indices::parse( idToken &token ) { +void gltfItem_accessor_sparse_indices::parse( idToken& token ) +{ parser->Warning( "%s is untested!", "gltfItem_accessor_sparse_indices" ); gltfItemArray indices; @@ -674,22 +796,26 @@ void gltfItem_accessor_sparse_indices::parse( idToken &token ) { GLTFARRAYITEMREF( item, byteOffset ); GLTFARRAYITEMREF( item, componentType ); GLTFARRAYITEMREF( item, extensions ); - extras->Set ( &item->extras, parser ); + extras->Set( &item->extras, parser ); indices.Parse( parser ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", token.c_str( ) ); + } } -void gltfItem_camera_orthographic::parse( idToken &token ) +void gltfItem_camera_orthographic::parse( idToken& token ) { gltfPropertyArray array = gltfPropertyArray( parser ); - for ( auto &prop : array ) + for( auto& prop : array ) + { common->Printf( "%s", prop.item.c_str( ) ); + } parser->ExpectTokenString( "]" ); } -void gltfItem_camera_perspective::parse( idToken &token ) +void gltfItem_camera_perspective::parse( idToken& token ) { parser->UnreadToken( &token ); gltfItemArray cameraPerspective; @@ -705,117 +831,133 @@ void gltfItem_camera_perspective::parse( idToken &token ) GLTFARRAYITEMREF( item, zfar ); GLTFARRAYITEMREF( item, znear ); GLTFARRAYITEMREF( item, extensions ); - extras->Set ( &item->extras, parser ); + extras->Set( &item->extras, parser ); cameraPerspective.Parse( parser ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", token.c_str( ) ); + } } -void gltfItem_occlusion_texture::parse( idToken &token ) { +void gltfItem_occlusion_texture::parse( idToken& token ) +{ parser->UnreadToken( &token ); gltfItemArray textureInfo; - GLTFARRAYITEM( textureInfo, index, gltfItem_integer); + GLTFARRAYITEM( textureInfo, index, gltfItem_integer ); GLTFARRAYITEM( textureInfo, texCoord, gltfItem_integer ); - GLTFARRAYITEM( textureInfo, strength, gltfItem_number); + GLTFARRAYITEM( textureInfo, strength, gltfItem_number ); GLTFARRAYITEM( textureInfo, extensions, gltfItem_texture_info_extensions ); GLTFARRAYITEM( textureInfo, extras, gltfItem_Extra ); GLTFARRAYITEMREF( item, index ); GLTFARRAYITEMREF( item, texCoord ); GLTFARRAYITEMREF( item, strength ); - extensions->Set ( &item->extensions, parser ); - extras->Set ( &item->extras, parser ); + extensions->Set( &item->extensions, parser ); + extras->Set( &item->extras, parser ); textureInfo.Parse( parser ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", token.c_str( ) ); + } } -void gltfItem_normal_texture::parse( idToken &token ) { +void gltfItem_normal_texture::parse( idToken& token ) +{ parser->UnreadToken( &token ); gltfItemArray textureInfo; - GLTFARRAYITEM( textureInfo, index, gltfItem_integer); + GLTFARRAYITEM( textureInfo, index, gltfItem_integer ); GLTFARRAYITEM( textureInfo, texCoord, gltfItem_integer ); - GLTFARRAYITEM( textureInfo, scale, gltfItem_number); + GLTFARRAYITEM( textureInfo, scale, gltfItem_number ); GLTFARRAYITEM( textureInfo, extensions, gltfItem_texture_info_extensions ); GLTFARRAYITEM( textureInfo, extras, gltfItem_Extra ); GLTFARRAYITEMREF( item, index ); GLTFARRAYITEMREF( item, texCoord ); GLTFARRAYITEMREF( item, scale ); - extensions->Set ( &item->extensions, parser ); - extras->Set ( &item->extras, parser ); + extensions->Set( &item->extensions, parser ); + extras->Set( &item->extras, parser ); textureInfo.Parse( parser ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", token.c_str( ) ); + } } -void gltfItem_texture_info::parse( idToken &token ) { +void gltfItem_texture_info::parse( idToken& token ) +{ parser->UnreadToken( &token ); gltfItemArray textureInfo; - GLTFARRAYITEM( textureInfo, index, gltfItem_integer); + GLTFARRAYITEM( textureInfo, index, gltfItem_integer ); GLTFARRAYITEM( textureInfo, texCoord, gltfItem_integer ); GLTFARRAYITEM( textureInfo, extensions, gltfItem_texture_info_extensions ); GLTFARRAYITEM( textureInfo, extras, gltfItem_Extra ); GLTFARRAYITEMREF( item, index ); GLTFARRAYITEMREF( item, texCoord ); - extensions->Set ( &item->extensions, parser ); - extras->Set ( &item->extras, parser ); + extensions->Set( &item->extensions, parser ); + extras->Set( &item->extras, parser ); textureInfo.Parse( parser ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", token.c_str( ) ); + } } -void gltfItem_pbrMetallicRoughness::parse( idToken &token ) +void gltfItem_pbrMetallicRoughness::parse( idToken& token ) { parser->UnreadToken( &token ); gltfItemArray pbrMetallicRoughness; - GLTFARRAYITEM( pbrMetallicRoughness, baseColorFactor, gltfItem_vec4); - GLTFARRAYITEM( pbrMetallicRoughness, baseColorTexture, gltfItem_texture_info); + GLTFARRAYITEM( pbrMetallicRoughness, baseColorFactor, gltfItem_vec4 ); + GLTFARRAYITEM( pbrMetallicRoughness, baseColorTexture, gltfItem_texture_info ); GLTFARRAYITEM( pbrMetallicRoughness, metallicFactor, gltfItem_number ); GLTFARRAYITEM( pbrMetallicRoughness, roughnessFactor, gltfItem_number ); GLTFARRAYITEM( pbrMetallicRoughness, metallicRoughnessTexture, gltfItem_texture_info ); GLTFARRAYITEM( pbrMetallicRoughness, extensions, gltfItem ); GLTFARRAYITEM( pbrMetallicRoughness, extras, gltfItem_Extra ); - - baseColorFactor->Set ( &item->baseColorFactor, parser ); - baseColorTexture->Set ( &item->baseColorTexture, parser ); - GLTFARRAYITEMREF ( item, metallicFactor ); - GLTFARRAYITEMREF ( item, roughnessFactor ); + + baseColorFactor->Set( &item->baseColorFactor, parser ); + baseColorTexture->Set( &item->baseColorTexture, parser ); + GLTFARRAYITEMREF( item, metallicFactor ); + GLTFARRAYITEMREF( item, roughnessFactor ); metallicRoughnessTexture->Set( &item->metallicRoughnessTexture, parser ); - GLTFARRAYITEMREF ( item, extensions ); - extras->Set ( &item->extras, parser ); + GLTFARRAYITEMREF( item, extensions ); + extras->Set( &item->extras, parser ); pbrMetallicRoughness.Parse( parser ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", token.c_str( ) ); + } } -void gltfItem_TextureInfo_KHR_texture_transform::parse( idToken &token ) { +void gltfItem_TextureInfo_KHR_texture_transform::parse( idToken& token ) +{ parser->UnreadToken( &token ); gltfItemArray texureTransform; GLTFARRAYITEM( texureTransform, offset, gltfItem_vec2 ); - GLTFARRAYITEM( texureTransform, rotation, gltfItem_number); + GLTFARRAYITEM( texureTransform, rotation, gltfItem_number ); GLTFARRAYITEM( texureTransform, scale, gltfItem_vec2 ); GLTFARRAYITEM( texureTransform, texCoord, gltfItem_integer ); item->KHR_texture_transform = new gltfExt_KHR_texture_transform( ); - offset->Set ( &item->KHR_texture_transform->offset, parser ); - GLTFARRAYITEMREF ( item->KHR_texture_transform, rotation ); - scale->Set ( &item->KHR_texture_transform->scale, parser ); - GLTFARRAYITEMREF ( item->KHR_texture_transform, texCoord ); + offset->Set( &item->KHR_texture_transform->offset, parser ); + GLTFARRAYITEMREF( item->KHR_texture_transform, rotation ); + scale->Set( &item->KHR_texture_transform->scale, parser ); + GLTFARRAYITEMREF( item->KHR_texture_transform, texCoord ); texureTransform.Parse( parser ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", token.c_str( ) ); + } } -void gltfItem_Material_KHR_materials_pbrSpecularGlossiness::parse( idToken &token ) +void gltfItem_Material_KHR_materials_pbrSpecularGlossiness::parse( idToken& token ) { parser->UnreadToken( &token ); gltfItemArray khrPbr; @@ -824,25 +966,28 @@ void gltfItem_Material_KHR_materials_pbrSpecularGlossiness::parse( idToken &toke GLTFARRAYITEM( khrPbr, specularFactor, gltfItem_vec3 ); GLTFARRAYITEM( khrPbr, glossinessFactor, gltfItem_number ); GLTFARRAYITEM( khrPbr, specularGlossinessTexture, gltfItem_texture_info ); - GLTFARRAYITEM( khrPbr, extensions, gltfItem); + GLTFARRAYITEM( khrPbr, extensions, gltfItem ); GLTFARRAYITEM( khrPbr, extras, gltfItem_Extra ); item->KHR_materials_pbrSpecularGlossiness = new gltfExt_KHR_materials_pbrSpecularGlossiness( ); - diffuseFactor->Set ( &item->KHR_materials_pbrSpecularGlossiness->diffuseFactor, parser ); - diffuseTexture->Set ( &item->KHR_materials_pbrSpecularGlossiness->diffuseTexture, parser ); - specularFactor->Set ( &item->KHR_materials_pbrSpecularGlossiness->specularFactor, parser ); - GLTFARRAYITEMREF ( item->KHR_materials_pbrSpecularGlossiness, glossinessFactor); - specularGlossinessTexture->Set ( &item->KHR_materials_pbrSpecularGlossiness->specularGlossinessTexture, parser ); - GLTFARRAYITEMREF ( item->KHR_materials_pbrSpecularGlossiness, extensions ); - extras->Set ( &item->KHR_materials_pbrSpecularGlossiness->extras, parser ); + diffuseFactor->Set( &item->KHR_materials_pbrSpecularGlossiness->diffuseFactor, parser ); + diffuseTexture->Set( &item->KHR_materials_pbrSpecularGlossiness->diffuseTexture, parser ); + specularFactor->Set( &item->KHR_materials_pbrSpecularGlossiness->specularFactor, parser ); + GLTFARRAYITEMREF( item->KHR_materials_pbrSpecularGlossiness, glossinessFactor ); + specularGlossinessTexture->Set( &item->KHR_materials_pbrSpecularGlossiness->specularGlossinessTexture, parser ); + GLTFARRAYITEMREF( item->KHR_materials_pbrSpecularGlossiness, extensions ); + extras->Set( &item->KHR_materials_pbrSpecularGlossiness->extras, parser ); khrPbr.Parse( parser ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", token.c_str( ) ); + } } -void gltfItem_Node_KHR_lights_punctual::parse( idToken &token ) { +void gltfItem_Node_KHR_lights_punctual::parse( idToken& token ) +{ parser->UnreadToken( &token ); gltfItemArray xlight; @@ -851,11 +996,14 @@ void gltfItem_Node_KHR_lights_punctual::parse( idToken &token ) { light->Set( &item->KHR_lights_punctual->light ); xlight.Parse( parser ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", token.c_str( ) ); + } } -void gltfItem_KHR_lights_punctual::parse( idToken &token ) { +void gltfItem_KHR_lights_punctual::parse( idToken& token ) +{ idToken localToken; parser->ExpectTokenString( "lights" ); parser->ExpectTokenString( ":" ); @@ -864,14 +1012,15 @@ void gltfItem_KHR_lights_punctual::parse( idToken &token ) { GLTFARRAYITEM( light, color, gltfItem_vec3 ); GLTFARRAYITEM( light, intensity, gltfItem_number ); //GLTFARRAYITEM( light, spot, gltfItem ); - GLTFARRAYITEM( light, type, gltfItem ); + GLTFARRAYITEM( light, type, gltfItem ); GLTFARRAYITEM( light, range, gltfItem_number ); GLTFARRAYITEM( light, name, gltfItem ); GLTFARRAYITEM( light, extensions, gltfItem ); GLTFARRAYITEM( light, extras, gltfItem_Extra ); gltfPropertyArray array = gltfPropertyArray( parser ); - for ( auto &prop : array ) { + for( auto& prop : array ) + { idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ); lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfNode_light", 0 ); @@ -879,45 +1028,50 @@ void gltfItem_KHR_lights_punctual::parse( idToken &token ) { item->KHR_lights_punctual.Num( ) + 1, idListNewElement ); - gltfExt_KHR_lights_punctual *gltfLight = + gltfExt_KHR_lights_punctual* gltfLight = item->KHR_lights_punctual[item->KHR_lights_punctual.Num( ) - 1]; - color->Set (&gltfLight->color,&lexer ); - GLTFARRAYITEMREF (gltfLight, intensity ); + color->Set( &gltfLight->color, &lexer ); + GLTFARRAYITEMREF( gltfLight, intensity ); //GLTFARRAYITEMREF (gltfLight, spot ); - GLTFARRAYITEMREF (gltfLight, type ); - GLTFARRAYITEMREF (gltfLight, range ); - GLTFARRAYITEMREF (gltfLight, name ); - GLTFARRAYITEMREF (gltfLight, extensions ); - extras->Set (&gltfLight->extras,&lexer ); + GLTFARRAYITEMREF( gltfLight, type ); + GLTFARRAYITEMREF( gltfLight, range ); + GLTFARRAYITEMREF( gltfLight, name ); + GLTFARRAYITEMREF( gltfLight, extensions ); + extras->Set( &gltfLight->extras, &lexer ); light.Parse( &lexer ); - gltfLight->intType = gltfExt_KHR_lights_punctual::resolveType(gltfLight->type); + gltfLight->intType = gltfExt_KHR_lights_punctual::resolveType( gltfLight->type ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", prop.item.c_str( ) ); + } } parser->ExpectTokenString( "]" ); parser->ExpectTokenString( "}" ); } -void gltfItem_node_extensions::parse( idToken &token ) +void gltfItem_node_extensions::parse( idToken& token ) { parser->UnreadToken( &token ); gltfItemArray extensions; GLTFARRAYITEM( extensions, KHR_lights_punctual, gltfItem_Node_KHR_lights_punctual ); - KHR_lights_punctual->Set( item, parser); + KHR_lights_punctual->Set( item, parser ); extensions.Parse( parser ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", token.c_str( ) ); + } } -void gltfItem_material_extensions::parse( idToken &token ) { +void gltfItem_material_extensions::parse( idToken& token ) +{ parser->UnreadToken( &token ); gltfItemArray extensions; @@ -926,11 +1080,14 @@ void gltfItem_material_extensions::parse( idToken &token ) { KHR_materials_pbrSpecularGlossiness->Set( item, parser ); extensions.Parse( parser ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", token.c_str( ) ); + } } -void gltfItem_texture_info_extensions::parse( idToken &token ) { +void gltfItem_texture_info_extensions::parse( idToken& token ) +{ parser->UnreadToken( &token ); gltfItemArray extensions; @@ -939,58 +1096,65 @@ void gltfItem_texture_info_extensions::parse( idToken &token ) { KHR_texture_transform->Set( item, parser ); extensions.Parse( parser ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", token.c_str( ) ); + } } -void GLTF_Parser::Shutdown( ) { +void GLTF_Parser::Shutdown( ) +{ parser.FreeSource(); currentFile.FreeData(); } GLTF_Parser::GLTF_Parser() - : parser( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ) , buffersDone(false), bufferViewsDone( false ) { } + : parser( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ) , buffersDone( false ), bufferViewsDone( false ) { } -void GLTF_Parser::Parse_ASSET( idToken &token ) +void GLTF_Parser::Parse_ASSET( idToken& token ) { idStr section; parser.ParseBracedSection( section ); - common->Printf( "%s\n",section.c_str( ) ); + common->Printf( "%s\n", section.c_str( ) ); } -void GLTF_Parser::Parse_SCENE( idToken &token ) +void GLTF_Parser::Parse_SCENE( idToken& token ) { currentAsset->DefaultScene( ) = parser.ParseInt( ); - if ( gltf_parseVerbose.GetBool( ) ) - common->Printf( " ^1 %s scene ^6 : ^8 %i", token.c_str( ),currentAsset->DefaultScene( ) ); + if( gltf_parseVerbose.GetBool( ) ) + { + common->Printf( " ^1 %s scene ^6 : ^8 %i", token.c_str( ), currentAsset->DefaultScene( ) ); + } } -void GLTF_Parser::Parse_SCENES( idToken &token ) +void GLTF_Parser::Parse_SCENES( idToken& token ) { gltfItemArray scene; - GLTFARRAYITEM( scene, nodes, gltfItem_integer_array ); + GLTFARRAYITEM( scene, nodes, gltfItem_integer_array ); GLTFARRAYITEM( scene, name, gltfItem ); GLTFARRAYITEM( scene, extensions, gltfItem ); GLTFARRAYITEM( scene, extras, gltfItem_Extra ); - gltfPropertyArray array = gltfPropertyArray(&parser); - for (auto & prop : array ) + gltfPropertyArray array = gltfPropertyArray( &parser ); + for( auto& prop : array ) { idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ); lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfScene", 0 ); - gltfScene * gltfscene = currentAsset->Scene(); - nodes->Set ( &gltfscene->nodes, &lexer ); + gltfScene* gltfscene = currentAsset->Scene(); + nodes->Set( &gltfscene->nodes, &lexer ); GLTFARRAYITEMREF( gltfscene, name ); GLTFARRAYITEMREF( gltfscene, extensions ); - extras->Set ( &gltfscene->extras, &lexer ); + extras->Set( &gltfscene->extras, &lexer ); scene.Parse( &lexer ); - if ( gltf_parseVerbose.GetBool( ) ) - common->Printf("%s", prop.item.c_str()); + if( gltf_parseVerbose.GetBool( ) ) + { + common->Printf( "%s", prop.item.c_str() ); + } } parser.ExpectTokenString( "]" ); } -void GLTF_Parser::Parse_CAMERAS( idToken &token ) +void GLTF_Parser::Parse_CAMERAS( idToken& token ) { gltfItemArray camera; GLTFARRAYITEM( camera, orthographic, gltfItem_camera_orthographic ); @@ -1001,30 +1165,32 @@ void GLTF_Parser::Parse_CAMERAS( idToken &token ) GLTFARRAYITEM( camera, extras, gltfItem_Extra ); gltfPropertyArray array = gltfPropertyArray( &parser ); - for ( auto &prop : array ) + for( auto& prop : array ) { idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ); lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfCamera", 0 ); - gltfCamera *item = currentAsset->Camera( ); + gltfCamera* item = currentAsset->Camera( ); orthographic->Set( &item->orthographic, &lexer ); - perspective->Set ( &item->perspective, &lexer ); + perspective->Set( &item->perspective, &lexer ); GLTFARRAYITEMREF( item, type ); GLTFARRAYITEMREF( item, name ); GLTFARRAYITEMREF( item, extensions ); - extras->Set ( &item->extras, &lexer ); + extras->Set( &item->extras, &lexer ); camera.Parse( &lexer ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", prop.item.c_str( ) ); + } } parser.ExpectTokenString( "]" ); } -void GLTF_Parser::Parse_NODES( idToken &token ) +void GLTF_Parser::Parse_NODES( idToken& token ) { - + gltfItemArray node; GLTFARRAYITEM( node, camera, gltfItem_integer ); GLTFARRAYITEM( node, children, gltfItem_integer_array ); @@ -1040,38 +1206,41 @@ void GLTF_Parser::Parse_NODES( idToken &token ) GLTFARRAYITEM( node, extras, gltfItem_Extra ); gltfPropertyArray array = gltfPropertyArray( &parser ); - for ( auto &prop : array ) { + for( auto& prop : array ) + { idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ); lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfNode", 0 ); - gltfNode *gltfnode = currentAsset->Node( ); - + gltfNode* gltfnode = currentAsset->Node( ); + GLTFARRAYITEMREF( gltfnode, camera ); - matrix->Set ( &gltfnode->matrix,&lexer); - children->Set ( &gltfnode->children,&lexer); + matrix->Set( &gltfnode->matrix, &lexer ); + children->Set( &gltfnode->children, &lexer ); GLTFARRAYITEMREF( gltfnode, skin ); - matrix->Set ( &gltfnode->matrix,&lexer); + matrix->Set( &gltfnode->matrix, &lexer ); GLTFARRAYITEMREF( gltfnode, mesh ); - rotation->Set ( &gltfnode->rotation, &lexer ); - scale->Set ( &gltfnode->scale,&lexer); + rotation->Set( &gltfnode->rotation, &lexer ); + scale->Set( &gltfnode->scale, &lexer ); translation->Set( &gltfnode->translation, &lexer ); - weights->Set ( &gltfnode->weights,&lexer); + weights->Set( &gltfnode->weights, &lexer ); GLTFARRAYITEMREF( gltfnode, name ); - extensions->Set ( &gltfnode->extensions, &lexer ); - extras->Set (&gltfnode->extras,&lexer); + extensions->Set( &gltfnode->extensions, &lexer ); + extras->Set( &gltfnode->extras, &lexer ); node.Parse( &lexer ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", prop.item.c_str( ) ); + } } parser.ExpectTokenString( "]" ); } -void GLTF_Parser::Parse_MATERIALS( idToken &token ) +void GLTF_Parser::Parse_MATERIALS( idToken& token ) { gltfItemArray material; GLTFARRAYITEM( material, pbrMetallicRoughness, gltfItem_pbrMetallicRoughness ); GLTFARRAYITEM( material, normalTexture, gltfItem_normal_texture ); - GLTFARRAYITEM( material, occlusionTexture, gltfItem_occlusion_texture); + GLTFARRAYITEM( material, occlusionTexture, gltfItem_occlusion_texture ); GLTFARRAYITEM( material, emissiveTexture, gltfItem_texture_info ); GLTFARRAYITEM( material, emissiveFactor, gltfItem_vec3 ); GLTFARRAYITEM( material, alphaMode, gltfItem ); @@ -1079,63 +1248,69 @@ void GLTF_Parser::Parse_MATERIALS( idToken &token ) GLTFARRAYITEM( material, doubleSided, gltfItem_boolean ); GLTFARRAYITEM( material, name, gltfItem ); GLTFARRAYITEM( material, extensions, gltfItem_material_extensions ); - GLTFARRAYITEM( material, extras, gltfItem_Extra); + GLTFARRAYITEM( material, extras, gltfItem_Extra ); gltfPropertyArray array = gltfPropertyArray( &parser ); - for ( auto &prop : array ) { + for( auto& prop : array ) + { idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ); lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfMaterial", 0 ); - gltfMaterial * gltfmaterial = currentAsset->Material( ); + gltfMaterial* gltfmaterial = currentAsset->Material( ); - pbrMetallicRoughness->Set ( &gltfmaterial->pbrMetallicRoughness, &lexer ); - normalTexture->Set ( &gltfmaterial->normalTexture, &lexer ); - occlusionTexture->Set ( &gltfmaterial->occlusionTexture, &lexer ); - emissiveTexture->Set ( &gltfmaterial->emissiveTexture, &lexer ); - emissiveFactor->Set ( &gltfmaterial->emissiveFactor, &lexer ); - GLTFARRAYITEMREF ( gltfmaterial, alphaMode ); - GLTFARRAYITEMREF ( gltfmaterial, alphaCutoff ); - GLTFARRAYITEMREF ( gltfmaterial, doubleSided ); - GLTFARRAYITEMREF ( gltfmaterial, name ); - extensions->Set ( &gltfmaterial->extensions, &lexer ); - extras->Set ( &gltfmaterial->extras, &lexer ); + pbrMetallicRoughness->Set( &gltfmaterial->pbrMetallicRoughness, &lexer ); + normalTexture->Set( &gltfmaterial->normalTexture, &lexer ); + occlusionTexture->Set( &gltfmaterial->occlusionTexture, &lexer ); + emissiveTexture->Set( &gltfmaterial->emissiveTexture, &lexer ); + emissiveFactor->Set( &gltfmaterial->emissiveFactor, &lexer ); + GLTFARRAYITEMREF( gltfmaterial, alphaMode ); + GLTFARRAYITEMREF( gltfmaterial, alphaCutoff ); + GLTFARRAYITEMREF( gltfmaterial, doubleSided ); + GLTFARRAYITEMREF( gltfmaterial, name ); + extensions->Set( &gltfmaterial->extensions, &lexer ); + extras->Set( &gltfmaterial->extras, &lexer ); material.Parse( &lexer ); gltfmaterial->intType = gltfMaterial::resolveAlphaMode( gltfmaterial->alphaMode ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", prop.item.c_str( ) ); + } } parser.ExpectTokenString( "]" ); } -void GLTF_Parser::Parse_MESHES( idToken &token ) +void GLTF_Parser::Parse_MESHES( idToken& token ) { gltfItemArray mesh; GLTFARRAYITEM( mesh, primitives, gltfItem_mesh_primitive ); // object GLTFARRAYITEM( mesh, weights, gltfItem_number_array ); //number[1 - *] - GLTFARRAYITEM( mesh, name, gltfItem ); + GLTFARRAYITEM( mesh, name, gltfItem ); GLTFARRAYITEM( mesh, extensions, gltfItem ); GLTFARRAYITEM( mesh, extras, gltfItem_Extra ); gltfPropertyArray array = gltfPropertyArray( &parser ); - for ( auto &prop : array ) { + for( auto& prop : array ) + { idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ); lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfMesh", 0 ); - gltfMesh *gltfmesh = currentAsset->Mesh( ); + gltfMesh* gltfmesh = currentAsset->Mesh( ); - primitives->Set ( &gltfmesh->primitives, &lexer); - weights->Set ( &gltfmesh->weights, &lexer ); + primitives->Set( &gltfmesh->primitives, &lexer ); + weights->Set( &gltfmesh->weights, &lexer ); GLTFARRAYITEMREF( gltfmesh, name ); GLTFARRAYITEMREF( gltfmesh, extensions ); - extras->Set (&gltfmesh->extras,&lexer); + extras->Set( &gltfmesh->extras, &lexer ); mesh.Parse( &lexer ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", prop.item.c_str( ) ); + } } parser.ExpectTokenString( "]" ); } -void GLTF_Parser::Parse_TEXTURES( idToken &token ) +void GLTF_Parser::Parse_TEXTURES( idToken& token ) { gltfItemArray texture; GLTFARRAYITEM( texture, sampler, gltfItem_integer ); @@ -1145,60 +1320,71 @@ void GLTF_Parser::Parse_TEXTURES( idToken &token ) GLTFARRAYITEM( texture, extras, gltfItem_Extra ); gltfPropertyArray array = gltfPropertyArray( &parser ); - for ( auto &prop : array ) { + for( auto& prop : array ) + { idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ); lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfTexture", 0 ); - gltfTexture *gltftexture = currentAsset->Texture( ); + gltfTexture* gltftexture = currentAsset->Texture( ); GLTFARRAYITEMREF( gltftexture, sampler ); GLTFARRAYITEMREF( gltftexture, source ); GLTFARRAYITEMREF( gltftexture, name ); - extensions->Set ( &gltftexture->extensions, &lexer ); - extras->Set ( &gltftexture->extras, &lexer ); + extensions->Set( &gltftexture->extensions, &lexer ); + extras->Set( &gltftexture->extras, &lexer ); texture.Parse( &lexer ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", prop.item.c_str( ) ); + } } parser.ExpectTokenString( "]" ); } -void GLTF_Parser::Parse_IMAGES( idToken &token ) +void GLTF_Parser::Parse_IMAGES( idToken& token ) { //reference impl gltfPropertyArray array = gltfPropertyArray( &parser ); gltfItemArray propItems; - auto uri = new gltfItem_uri ("uri"); propItems.AddItemDef((parsable*)uri); - auto mimeType = new gltfItem ("mimeType"); propItems.AddItemDef((parsable*)mimeType); - auto bufferView = new gltfItem_integer ("bufferView"); propItems.AddItemDef((parsable*)bufferView ); - auto name = new gltfItem ("name"); propItems.AddItemDef((parsable*)name); - auto extensions = new gltfItem ("extensions"); propItems.AddItemDef((parsable*)extensions); - auto extras = new gltfItem_Extra ("extras" ); propItems.AddItemDef( ( parsable * ) extras ); + auto uri = new gltfItem_uri( "uri" ); + propItems.AddItemDef( ( parsable* )uri ); + auto mimeType = new gltfItem( "mimeType" ); + propItems.AddItemDef( ( parsable* )mimeType ); + auto bufferView = new gltfItem_integer( "bufferView" ); + propItems.AddItemDef( ( parsable* )bufferView ); + auto name = new gltfItem( "name" ); + propItems.AddItemDef( ( parsable* )name ); + auto extensions = new gltfItem( "extensions" ); + propItems.AddItemDef( ( parsable* )extensions ); + auto extras = new gltfItem_Extra( "extras" ); + propItems.AddItemDef( ( parsable* ) extras ); - for ( auto &prop : array ) + for( auto& prop : array ) { idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ); - lexer.LoadMemory(prop.item.c_str(),prop.item.Size(),"gltfImage",0); + lexer.LoadMemory( prop.item.c_str(), prop.item.Size(), "gltfImage", 0 ); - gltfImage *image = currentAsset->Image(); - uri->Set (&image->uri, &image->bufferView,currentAsset); - mimeType->Set (&image->mimeType); - bufferView->Set (&image->bufferView); - name->Set (&image->name); - extensions->Set (&image->extensions); - extras->Set (&image->extras,&lexer); - propItems.Parse (&lexer); + gltfImage* image = currentAsset->Image(); + uri->Set( &image->uri, &image->bufferView, currentAsset ); + mimeType->Set( &image->mimeType ); + bufferView->Set( &image->bufferView ); + name->Set( &image->name ); + extensions->Set( &image->extensions ); + extras->Set( &image->extras, &lexer ); + propItems.Parse( &lexer ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", prop.item.c_str( ) ); + } //automate.. //image->bgfxTexture.handle.idx = UINT16_MAX; } parser.ExpectTokenString( "]" ); } -void GLTF_Parser::Parse_ACCESSORS( idToken &token ) +void GLTF_Parser::Parse_ACCESSORS( idToken& token ) { gltfItemArray accessor; GLTFARRAYITEM( accessor, bufferView, gltfItem_integer ); @@ -1209,41 +1395,43 @@ void GLTF_Parser::Parse_ACCESSORS( idToken &token ) GLTFARRAYITEM( accessor, type, gltfItem ); GLTFARRAYITEM( accessor, max, gltfItem_number_array ); GLTFARRAYITEM( accessor, min, gltfItem_number_array ); - GLTFARRAYITEM( accessor, sparse, gltfItem_accessor_sparse); + GLTFARRAYITEM( accessor, sparse, gltfItem_accessor_sparse ); GLTFARRAYITEM( accessor, name, gltfItem ); GLTFARRAYITEM( accessor, extensions, gltfItem ); GLTFARRAYITEM( accessor, extras, gltfItem_Extra ); gltfPropertyArray array = gltfPropertyArray( &parser ); - for ( auto & prop : array ) + for( auto& prop : array ) { idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ); lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfAccessor", 0 ); - gltfAccessor * item = currentAsset->Accessor(); - GLTFARRAYITEMREF( item, bufferView); - GLTFARRAYITEMREF( item, byteOffset); - GLTFARRAYITEMREF( item, componentType); - GLTFARRAYITEMREF( item, normalized); - GLTFARRAYITEMREF( item, count); + gltfAccessor* item = currentAsset->Accessor(); + GLTFARRAYITEMREF( item, bufferView ); + GLTFARRAYITEMREF( item, byteOffset ); + GLTFARRAYITEMREF( item, componentType ); + GLTFARRAYITEMREF( item, normalized ); + GLTFARRAYITEMREF( item, count ); GLTFARRAYITEMREF( item, type ); - max->Set ( &item->max, &lexer ); - min->Set ( &item->min, &lexer ); - sparse->Set ( &item->sparse, &lexer ); - GLTFARRAYITEMREF( item, name); - GLTFARRAYITEMREF( item, extensions); - extras->Set ( &item->extras, &lexer ); + max->Set( &item->max, &lexer ); + min->Set( &item->min, &lexer ); + sparse->Set( &item->sparse, &lexer ); + GLTFARRAYITEMREF( item, name ); + GLTFARRAYITEMREF( item, extensions ); + extras->Set( &item->extras, &lexer ); accessor.Parse( &lexer ); GetComponentTypeEnum( item->componentType, &item->typeSize ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", prop.item.c_str( ) ); + } } parser.ExpectTokenString( "]" ); } -void GLTF_Parser::Parse_BUFFERVIEWS( idToken &token ) -{ +void GLTF_Parser::Parse_BUFFERVIEWS( idToken& token ) +{ gltfItemArray bv; GLTFARRAYITEM( bv, buffer, gltfItem_integer ); GLTFARRAYITEM( bv, byteLength, gltfItem_integer ); @@ -1255,29 +1443,31 @@ void GLTF_Parser::Parse_BUFFERVIEWS( idToken &token ) GLTFARRAYITEM( bv, extras, gltfItem_Extra ); gltfPropertyArray array = gltfPropertyArray( &parser ); - for ( auto &prop : array ) + for( auto& prop : array ) { idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ); lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfBufferView", 0 ); - gltfBufferView * gltfBV = currentAsset->BufferView(); + gltfBufferView* gltfBV = currentAsset->BufferView(); GLTFARRAYITEMREF( gltfBV, buffer ); - GLTFARRAYITEMREF( gltfBV, byteLength); - GLTFARRAYITEMREF( gltfBV, byteStride); - GLTFARRAYITEMREF( gltfBV, byteOffset); + GLTFARRAYITEMREF( gltfBV, byteLength ); + GLTFARRAYITEMREF( gltfBV, byteStride ); + GLTFARRAYITEMREF( gltfBV, byteOffset ); GLTFARRAYITEMREF( gltfBV, target ); - GLTFARRAYITEMREF( gltfBV, name ); - GLTFARRAYITEMREF( gltfBV, extensions); - extras->Set ( &gltfBV->extras, &lexer ); - bv.Parse(&lexer); + GLTFARRAYITEMREF( gltfBV, name ); + GLTFARRAYITEMREF( gltfBV, extensions ); + extras->Set( &gltfBV->extras, &lexer ); + bv.Parse( &lexer ); gltfBV->parent = currentAsset; - if (gltf_parseVerbose.GetBool()) + if( gltf_parseVerbose.GetBool() ) + { common->Printf( "%s", prop.item.c_str( ) ); + } } parser.ExpectTokenString( "]" ); } -void GLTF_Parser::Parse_SAMPLERS( idToken &token ) +void GLTF_Parser::Parse_SAMPLERS( idToken& token ) { gltfItemArray sampl; GLTFARRAYITEM( sampl, magFilter, gltfItem_integer ); @@ -1289,27 +1479,29 @@ void GLTF_Parser::Parse_SAMPLERS( idToken &token ) GLTFARRAYITEM( sampl, extras, gltfItem_Extra ); gltfPropertyArray array = gltfPropertyArray( &parser ); - for ( auto &prop : array ) + for( auto& prop : array ) { idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ); lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfSampler", 0 ); - gltfSampler * gltfSampl = currentAsset->Sampler(); + gltfSampler* gltfSampl = currentAsset->Sampler(); GLTFARRAYITEMREF( gltfSampl, magFilter ); GLTFARRAYITEMREF( gltfSampl, minFilter ); GLTFARRAYITEMREF( gltfSampl, wrapS ); GLTFARRAYITEMREF( gltfSampl, wrapT ); - GLTFARRAYITEMREF( gltfSampl, name ); - GLTFARRAYITEMREF( gltfSampl, extensions); - extras->Set ( &gltfSampl->extras, &lexer ); - sampl.Parse(&lexer); + GLTFARRAYITEMREF( gltfSampl, name ); + GLTFARRAYITEMREF( gltfSampl, extensions ); + extras->Set( &gltfSampl->extras, &lexer ); + sampl.Parse( &lexer ); - if (gltf_parseVerbose.GetBool()) + if( gltf_parseVerbose.GetBool() ) + { common->Printf( "%s", prop.item.c_str( ) ); + } } parser.ExpectTokenString( "]" ); } -void GLTF_Parser::Parse_BUFFERS( idToken &token ) +void GLTF_Parser::Parse_BUFFERS( idToken& token ) { gltfItemArray buf; GLTFARRAYITEM( buf, uri, gltfItem_uri ); @@ -1319,84 +1511,94 @@ void GLTF_Parser::Parse_BUFFERS( idToken &token ) GLTFARRAYITEM( buf, extras, gltfItem_Extra ); gltfPropertyArray array = gltfPropertyArray( &parser ); - for ( auto &prop : array ) { + for( auto& prop : array ) + { idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ); lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfBuffer", 0 ); - gltfBuffer *gltfBuf = currentAsset->Buffer( ); + gltfBuffer* gltfBuf = currentAsset->Buffer( ); gltfBuf->parent = currentAsset; uri->Set( &gltfBuf->uri, nullptr , currentAsset ); GLTFARRAYITEMREF( gltfBuf, byteLength ); GLTFARRAYITEMREF( gltfBuf, name ); GLTFARRAYITEMREF( gltfBuf, extensions ); - extras->Set ( &gltfBuf->extras, &lexer ); + extras->Set( &gltfBuf->extras, &lexer ); buf.Parse( &lexer ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", prop.item.c_str( ) ); + } } parser.ExpectTokenString( "]" ); } -void GLTF_Parser::Parse_ANIMATIONS( idToken &token ) +void GLTF_Parser::Parse_ANIMATIONS( idToken& token ) { gltfItemArray anim; GLTFARRAYITEM( anim, channels, gltfItem_animation_channel ); //channel[1 - *] GLTFARRAYITEM( anim, samplers, gltfItem_animation_sampler ); //sampler[1 - *] - GLTFARRAYITEM( anim, name, gltfItem ); + GLTFARRAYITEM( anim, name, gltfItem ); GLTFARRAYITEM( anim, extensions, gltfItem ); GLTFARRAYITEM( anim, extras, gltfItem_Extra ); gltfPropertyArray array = gltfPropertyArray( &parser ); - for ( auto &prop : array ) { + for( auto& prop : array ) + { idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ); lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfAnimation", 0 ); - gltfAnimation *gltfanim= currentAsset->Animation( ); + gltfAnimation* gltfanim = currentAsset->Animation( ); - channels->Set ( &gltfanim->channels, &lexer); - samplers->Set ( &gltfanim->samplers, &lexer ); + channels->Set( &gltfanim->channels, &lexer ); + samplers->Set( &gltfanim->samplers, &lexer ); GLTFARRAYITEMREF( gltfanim, name ); GLTFARRAYITEMREF( gltfanim, extensions ); - extras->Set ( &gltfanim->extras, &lexer ); + extras->Set( &gltfanim->extras, &lexer ); anim.Parse( &lexer ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", prop.item.c_str( ) ); + } } parser.ExpectTokenString( "]" ); } -void GLTF_Parser::Parse_SKINS( idToken &token ) { +void GLTF_Parser::Parse_SKINS( idToken& token ) +{ gltfItemArray skin; - GLTFARRAYITEM( skin, inverseBindMatrices, gltfItem_integer ); + GLTFARRAYITEM( skin, inverseBindMatrices, gltfItem_integer ); GLTFARRAYITEM( skin, skeleton, gltfItem_integer ); - GLTFARRAYITEM( skin, joints, gltfItem_integer_array ); + GLTFARRAYITEM( skin, joints, gltfItem_integer_array ); GLTFARRAYITEM( skin, name, gltfItem ); GLTFARRAYITEM( skin, extensions, gltfItem ); GLTFARRAYITEM( skin, extras, gltfItem_Extra ); gltfPropertyArray array = gltfPropertyArray( &parser ); - for ( auto &prop : array ) { + for( auto& prop : array ) + { idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ); lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfSkin", 0 ); - gltfSkin *gltfSkin = currentAsset->Skin( ); + gltfSkin* gltfSkin = currentAsset->Skin( ); GLTFARRAYITEMREF( gltfSkin, inverseBindMatrices ); GLTFARRAYITEMREF( gltfSkin, skeleton ); - joints->Set ( &gltfSkin->joints, &lexer ); + joints->Set( &gltfSkin->joints, &lexer ); GLTFARRAYITEMREF( gltfSkin, name ); GLTFARRAYITEMREF( gltfSkin, extensions ); - extras->Set ( &gltfSkin->extras, &lexer ); + extras->Set( &gltfSkin->extras, &lexer ); skin.Parse( &lexer ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", prop.item.c_str( ) ); + } } parser.ExpectTokenString( "]" ); } -void GLTF_Parser::Parse_EXTENSIONS( idToken &token ) +void GLTF_Parser::Parse_EXTENSIONS( idToken& token ) { idStr json; parser.ParseBracedSection( json ); @@ -1407,75 +1609,94 @@ void GLTF_Parser::Parse_EXTENSIONS( idToken &token ) idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ); lexer.LoadMemory( json.c_str( ), json.Size( ), "Extensions", 0 ); - gltfExtensions * gltfextension = currentAsset->Extensions(); + gltfExtensions* gltfextension = currentAsset->Extensions(); //KHR_materials_pbrSpecularGlossiness->Set( &gltfextensions, &lexer ); - KHR_lights_punctual->Set(gltfextension, &lexer ); + KHR_lights_punctual->Set( gltfextension, &lexer ); extensions.Parse( &lexer ); - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", json.c_str( ) ); + } } -void GLTF_Parser::Parse_EXTENSIONS_USED( idToken &token ) +void GLTF_Parser::Parse_EXTENSIONS_USED( idToken& token ) { - gltfPropertyArray array = gltfPropertyArray( &parser,false ); - for ( auto &prop : array ) { - gltfExtensionsUsed * ext = currentAsset->ExtensionsUsed( ); + gltfPropertyArray array = gltfPropertyArray( &parser, false ); + for( auto& prop : array ) + { + gltfExtensionsUsed* ext = currentAsset->ExtensionsUsed( ); ext->extension = prop.item; - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "%s", prop.item.c_str( ) ); + } } parser.ExpectTokenString( "]" ); } -void GLTF_Parser::Parse_EXTENSIONS_REQUIRED( idToken &token ) { +void GLTF_Parser::Parse_EXTENSIONS_REQUIRED( idToken& token ) +{ parser.ExpectTokenString( "[" ); idStrList exts; idToken item; bool parsing = true; - while ( parsing && parser.ExpectAnyToken( &item ) ) { - if ( item.type != TT_STRING ) + while( parsing && parser.ExpectAnyToken( &item ) ) + { + if( item.type != TT_STRING ) + { common->FatalError( "malformed extensions_used array" ); - idStr &extension = exts.Alloc( ); + } + idStr& extension = exts.Alloc( ); extension = item.c_str( ); parsing = parser.PeekTokenString( "," ); - if ( parsing ) + if( parsing ) + { parser.ExpectTokenString( "," ); + } } parser.ExpectTokenString( "]" ); - for ( auto &out : exts ) + for( auto& out : exts ) + { common->Printf( "%s", out.c_str( ) ); + } } -gltfProperty GLTF_Parser::ParseProp( idToken & token ) +gltfProperty GLTF_Parser::ParseProp( idToken& token ) { parser.ExpectTokenString( ":" ); gltfProperty prop = ResolveProp( token ); bool skipping = false; - if (!buffersDone || !bufferViewsDone) + if( !buffersDone || !bufferViewsDone ) { - if (prop == BUFFERS && !buffersDone) + if( prop == BUFFERS && !buffersDone ) { Parse_BUFFERS( token ); return prop; } - if ( prop == BUFFERVIEWS && !bufferViewsDone ) { + if( prop == BUFFERVIEWS && !bufferViewsDone ) + { Parse_BUFFERVIEWS( token ); return prop; } skipping = true; - if ( gltf_parseVerbose.GetBool( ) ) - common->DPrintf( "Searching for buffer tag. Skipping %s.", token.c_str()); - }else + if( gltf_parseVerbose.GetBool( ) ) + { + common->DPrintf( "Searching for buffer tag. Skipping %s.", token.c_str() ); + } + } + else { - if (( prop == BUFFERS && buffersDone) || (prop == BUFFERVIEWS && bufferViewsDone )) + if( ( prop == BUFFERS && buffersDone ) || ( prop == BUFFERVIEWS && bufferViewsDone ) ) { skipping = true; - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->DPrintf( "Skipping %s , already done.", token.c_str( ) ); + } } } - if (skipping ) + if( skipping ) { //1. search for {} scope. //2. search for [] scope. @@ -1483,17 +1704,23 @@ gltfProperty GLTF_Parser::ParseProp( idToken & token ) idToken skipTok; int sectionsSkipped = 0; - if (parser.PeekTokenString("{")) - parser.SkipBracedSection( true,BRSKIP_BRACES, §ionsSkipped ); - if ( !sectionsSkipped && parser.PeekTokenString( "[" ) ) + if( parser.PeekTokenString( "{" ) ) + { + parser.SkipBracedSection( true, BRSKIP_BRACES, §ionsSkipped ); + } + if( !sectionsSkipped && parser.PeekTokenString( "[" ) ) + { parser.SkipBracedSection( true, BRSKIP_BRACKET, §ionsSkipped ); - if ( !sectionsSkipped ) + } + if( !sectionsSkipped ) + { parser.ExpectAnyToken( &skipTok ); + } return gltfProperty::INVALID; } - - switch ( prop ) + + switch( prop ) { case ASSET: Parse_ASSET( token ); @@ -1527,15 +1754,19 @@ gltfProperty GLTF_Parser::ParseProp( idToken & token ) break; case BUFFERVIEWS: //Parse_BUFFERVIEWS( token ); - if ( !bufferViewsDone ) + if( !bufferViewsDone ) + { common->FatalError( "Bufferviews should already be parsed!" ); + } break; case SAMPLERS: Parse_SAMPLERS( token ); break; case BUFFERS: - if ( !buffersDone ) + if( !buffersDone ) + { common->FatalError( "Buffers should already be parsed!" ); + } break; case ANIMATIONS: Parse_ANIMATIONS( token ); @@ -1553,69 +1784,108 @@ gltfProperty GLTF_Parser::ParseProp( idToken & token ) Parse_EXTENSIONS_REQUIRED( token ); break; default: - common->FatalError("UnImplemented GLTF property : %s",token.c_str()); + common->FatalError( "UnImplemented GLTF property : %s", token.c_str() ); } return prop; } -gltfProperty GLTF_Parser::ResolveProp( idToken & token ) +gltfProperty GLTF_Parser::ResolveProp( idToken& token ) { - if ( !idStr::Icmp( token.c_str( ), "asset" ) ) + if( !idStr::Icmp( token.c_str( ), "asset" ) ) + { return gltfProperty::ASSET; - else if ( !idStr::Icmp( token.c_str( ), "cameras" ) ) + } + else if( !idStr::Icmp( token.c_str( ), "cameras" ) ) + { return gltfProperty::CAMERAS; - else if ( !idStr::Icmp( token.c_str( ), "scene" ) ) + } + else if( !idStr::Icmp( token.c_str( ), "scene" ) ) + { return gltfProperty::SCENE; - else if ( !idStr::Icmp( token.c_str( ), "scenes" ) ) + } + else if( !idStr::Icmp( token.c_str( ), "scenes" ) ) + { return gltfProperty::SCENES; - else if ( !idStr::Icmp( token.c_str( ), "nodes" ) ) + } + else if( !idStr::Icmp( token.c_str( ), "nodes" ) ) + { return gltfProperty::NODES; - else if ( !idStr::Icmp( token.c_str( ), "materials" ) ) + } + else if( !idStr::Icmp( token.c_str( ), "materials" ) ) + { return gltfProperty::MATERIALS; - else if ( !idStr::Icmp( token.c_str( ), "meshes" ) ) + } + else if( !idStr::Icmp( token.c_str( ), "meshes" ) ) + { return gltfProperty::MESHES; - else if ( !idStr::Icmp( token.c_str( ), "textures" ) ) + } + else if( !idStr::Icmp( token.c_str( ), "textures" ) ) + { return gltfProperty::TEXTURES; - else if ( !idStr::Icmp( token.c_str( ), "images" ) ) + } + else if( !idStr::Icmp( token.c_str( ), "images" ) ) + { return gltfProperty::IMAGES; - else if ( !idStr::Icmp( token.c_str( ), "accessors" ) ) + } + else if( !idStr::Icmp( token.c_str( ), "accessors" ) ) + { return gltfProperty::ACCESSORS; - else if ( !idStr::Icmp( token.c_str( ), "bufferViews" ) ) + } + else if( !idStr::Icmp( token.c_str( ), "bufferViews" ) ) + { return gltfProperty::BUFFERVIEWS; - else if ( !idStr::Icmp( token.c_str( ), "samplers" ) ) + } + else if( !idStr::Icmp( token.c_str( ), "samplers" ) ) + { return gltfProperty::SAMPLERS; - else if ( !idStr::Icmp( token.c_str( ), "buffers" ) ) + } + else if( !idStr::Icmp( token.c_str( ), "buffers" ) ) + { return gltfProperty::BUFFERS; - else if ( !idStr::Icmp( token.c_str( ), "animations" ) ) + } + else if( !idStr::Icmp( token.c_str( ), "animations" ) ) + { return gltfProperty::ANIMATIONS; - else if ( !idStr::Icmp( token.c_str( ), "skins" ) ) + } + else if( !idStr::Icmp( token.c_str( ), "skins" ) ) + { return gltfProperty::SKINS; - else if ( !idStr::Icmp( token.c_str( ), "extensions" ) ) + } + else if( !idStr::Icmp( token.c_str( ), "extensions" ) ) + { return gltfProperty::EXTENSIONS; - else if ( !idStr::Icmp( token.c_str( ), "extensionsused" ) ) + } + else if( !idStr::Icmp( token.c_str( ), "extensionsused" ) ) + { return gltfProperty::EXTENSIONS_USED; - else if ( !idStr::Icmp( token.c_str( ), "extensionsrequired") ) + } + else if( !idStr::Icmp( token.c_str( ), "extensionsrequired" ) ) + { return gltfProperty::EXTENSIONS_REQUIRED; + } return gltfProperty::INVALID; } -bool GLTF_Parser::loadGLB(idStr filename ) +bool GLTF_Parser::loadGLB( idStr filename ) { - idFile * file = fileSystem->OpenFileRead( filename ); + idFile* file = fileSystem->OpenFileRead( filename ); - if ( file->Length() < 20 ) { - common->FatalError("Too short data size for glTF Binary." ); + if( file->Length() < 20 ) + { + common->FatalError( "Too short data size for glTF Binary." ); return false; } - idStr gltfMagic("glTF"); + idStr gltfMagic( "glTF" ); unsigned char fileMagic[5]; - - file->Read((void*)&fileMagic,4 ); - fileMagic[4]=0; - if (gltfMagic.Icmp( (const char*)&fileMagic ) == 0) + + file->Read( ( void* )&fileMagic, 4 ); + fileMagic[4] = 0; + if( gltfMagic.Icmp( ( const char* )&fileMagic ) == 0 ) + { + common->Printf( "reading %s...\n", filename.c_str() ); + } + else { - common->Printf("reading %s...\n",filename.c_str() ); - } else { common->Error( "invalid magic" ); return false; } @@ -1629,84 +1899,103 @@ bool GLTF_Parser::loadGLB(idStr filename ) file->ReadUnsignedInt( length ); length -= 12; // header size - unsigned int chunk_type=0; // 4 bytes - unsigned int chunk_length=0; // 4 bytes - byte * data = nullptr; - gltfData *dataCache = gltfData::Data( filename ); + unsigned int chunk_type = 0; // 4 bytes + unsigned int chunk_length = 0; // 4 bytes + byte* data = nullptr; + gltfData* dataCache = gltfData::Data( filename ); currentAsset = dataCache; int chunkCount = 0; - while ( length ) { + while( length ) + { unsigned int prev_length = chunk_length; length -= file->ReadUnsignedInt( chunk_length ); length -= file->ReadUnsignedInt( chunk_type ); - - data = dataCache->AddData( chunk_length ); - dataCache->FileName(filename); - int read = file->Read((void*)data, chunk_length ); - if (read != chunk_length) - common->FatalError("Could not read full chunk (%i bytes) in file %s",chunk_length, filename ); + data = dataCache->AddData( chunk_length ); + dataCache->FileName( filename ); + + int read = file->Read( ( void* )data, chunk_length ); + if( read != chunk_length ) + { + common->FatalError( "Could not read full chunk (%i bytes) in file %s", chunk_length, filename ); + } length -= read; - if (chunk_type == gltfChunk_Type_JSON) + if( chunk_type == gltfChunk_Type_JSON ) { currentFile = filename + "[JSON CHUNK]"; - parser.LoadMemory((const char*)data,chunk_length,"gltfJson",0); - }else if ( !chunkCount ) - common->FatalError("first chunk was not a json chunk"); - else { - common->Printf("BINCHUNK %i %i bytes\n",chunkCount, chunk_length ); + parser.LoadMemory( ( const char* )data, chunk_length, "gltfJson", 0 ); + } + else if( !chunkCount ) + { + common->FatalError( "first chunk was not a json chunk" ); + } + else + { + common->Printf( "BINCHUNK %i %i bytes\n", chunkCount, chunk_length ); + } + if( chunkCount++ && length ) + { + common->FatalError( "corrupt glb file." ); } - if (chunkCount++ && length ) - common->FatalError("corrupt glb file." ); } Parse(); return true; } -bool GLTF_Parser::Parse( ) { +bool GLTF_Parser::Parse( ) +{ bool parsing = true; parser.ExpectTokenString( "{" ); - while ( parsing && parser.ExpectAnyToken( &token ) ) { - if ( token.type != TT_STRING ) + while( parsing && parser.ExpectAnyToken( &token ) ) + { + if( token.type != TT_STRING ) + { common->FatalError( "Expected an \"string\" " ); + } - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( token.c_str( ) ); + } gltfProperty prop = ParseProp( token ); - if (( prop == BUFFERS && !buffersDone )) + if( ( prop == BUFFERS && !buffersDone ) ) { parser.Reset(); parser.ExpectTokenString( "{" ); buffersDone = true; continue; } - if ((prop == BUFFERVIEWS && !bufferViewsDone)) + if( ( prop == BUFFERVIEWS && !bufferViewsDone ) ) { parser.Reset( ); parser.ExpectTokenString( "{" ); bufferViewsDone = true; continue; } - if ( gltf_parseVerbose.GetBool( ) ) + if( gltf_parseVerbose.GetBool( ) ) + { common->Printf( "\n" ); + } parsing = parser.PeekTokenString( "," ); - if ( parsing ) + if( parsing ) + { parser.ExpectTokenString( "," ); + } else { //we are at the end, and no bufferview or buffer has been found. - if ( !buffersDone || !bufferViewsDone ) + if( !buffersDone || !bufferViewsDone ) { - if ( !buffersDone ) + if( !buffersDone ) { buffersDone = true; common->Printf( "no %s found", "buffers" ); } - if ( !bufferViewsDone ) - { + if( !bufferViewsDone ) + { common->Printf( "no %s found", "bufferviews" ); bufferViewsDone = true; } @@ -1722,17 +2011,21 @@ bool GLTF_Parser::Parse( ) { } //parser should be at end. parser.ReadToken( &token ); - if ( parser.EndOfFile( ) ) + if( parser.EndOfFile( ) ) + { common->Printf( "%s ^2loaded\n", currentFile.c_str( ) ); + } else + { common->FatalError( "%s not fully loaded.", currentFile ); - + } + buffersDone = false; bufferViewsDone = false; return true; } - -bool GLTF_Parser::Load(idStr filename ) + +bool GLTF_Parser::Load( idStr filename ) { //seriously fix this; proper gltf data cache. //.. and destroy it properly too!! @@ -1742,73 +2035,93 @@ bool GLTF_Parser::Load(idStr filename ) //gfx is not updated on command common->SetRefreshOnPrint( true ); - if (lastFile == filename ) { - common->Warning("Did not parse %s again",filename.c_str()); + if( lastFile == filename ) + { + common->Warning( "Did not parse %s again", filename.c_str() ); return true; } lastFile = filename; currentFile = filename; - if ( filename.CheckExtension( ".glb" ) ) { - if ( !loadGLB( filename ) ) + if( filename.CheckExtension( ".glb" ) ) + { + if( !loadGLB( filename ) ) + { return false; + } } - else if ( filename.CheckExtension( ".gltf" ) ) { - int length = fileSystem->ReadFile(filename,NULL); - if (!length) - common->FatalError("Failed to read file"); + else if( filename.CheckExtension( ".gltf" ) ) + { + int length = fileSystem->ReadFile( filename, NULL ); + if( !length ) + { + common->FatalError( "Failed to read file" ); + } - gltfData * data = gltfData::Data( filename ); - data->FileName(filename); - byte* dataBuff = data->AddData(length); + gltfData* data = gltfData::Data( filename ); + data->FileName( filename ); + byte* dataBuff = data->AddData( length ); currentAsset = data; - + idFile* file = fileSystem->OpenFileRead( filename ); - if ( file->Read(dataBuff,length)!=length) - common->FatalError("Cannot read file, %s",filename.c_str() ); + if( file->Read( dataBuff, length ) != length ) + { + common->FatalError( "Cannot read file, %s", filename.c_str() ); + } - fileSystem->CloseFile(file); + fileSystem->CloseFile( file ); - if ( !parser.LoadMemory((const char*)dataBuff,length,"GLTF_ASCII_JSON",0)) + if( !parser.LoadMemory( ( const char* )dataBuff, length, "GLTF_ASCII_JSON", 0 ) ) + { return false; - + } + Parse(); - }else + } + else + { return false; + } parser.Reset(); parser.FreeSource(); common->SetRefreshOnPrint( false ); - - //fix up node hierarchy - auto &nodeList = currentAsset->NodeList( ); - for ( auto &scene : currentAsset->SceneList( ) ) - for ( auto &node : scene->nodes ) - SetNodeParent( nodeList[node] ); - //prefix with id - if ( gltfParser_PrefixNodeWithID.GetBool() ) - for (int i = 0; i < nodeList.Num(); i++) - nodeList[i]->name = "[" + idStr( i ) + "]" + nodeList[i]->name; - + //fix up node hierarchy + auto& nodeList = currentAsset->NodeList( ); + for( auto& scene : currentAsset->SceneList( ) ) + for( auto& node : scene->nodes ) + { + SetNodeParent( nodeList[node] ); + } + + //prefix with id + if( gltfParser_PrefixNodeWithID.GetBool() ) + for( int i = 0; i < nodeList.Num(); i++ ) + { + nodeList[i]->name = "[" + idStr( i ) + "]" + nodeList[i]->name; + } + //CreateBgfxData(); return true; } -void GLTF_Parser::SetNodeParent( gltfNode *node, gltfNode *parent) +void GLTF_Parser::SetNodeParent( gltfNode* node, gltfNode* parent ) { node->parent = parent; - for ( auto & child : node->children ) + for( auto& child : node->children ) + { SetNodeParent( currentAsset->NodeList()[child], node ); + } } /* void GLTF_Parser::CreateBgfxData( ) { //buffers - for ( auto mesh : currentAsset->MeshList( ) ) + for ( auto mesh : currentAsset->MeshList( ) ) { - for ( auto prim : mesh->primitives ) + for ( auto prim : mesh->primitives ) { //gltfAccessor -> idList; //vertex indices accessor @@ -1820,7 +2133,7 @@ void GLTF_Parser::CreateBgfxData( ) uint idxDataSize = sizeof( uint ) * accessor->count; uint * indices = ( uint *)Mem_ClearedAlloc( idxDataSize ); - idFile_Memory idxBin = idFile_Memory( "gltfChunkIndices", + idFile_Memory idxBin = idFile_Memory( "gltfChunkIndices", ( const char * ) ((data->GetData( bv->buffer ) + bv->byteOffset + accessor->byteOffset )), bv->byteLength ); for ( int i = 0; i < accessor->count; i++ ) { @@ -1832,7 +2145,7 @@ void GLTF_Parser::CreateBgfxData( ) Mem_Free( indices ); - //vertex attribs + //vertex attribs pbrVertex * vtxData = NULL; uint vtxDataSize = 0; bgfx::VertexLayout vtxLayout; @@ -1851,7 +2164,7 @@ void GLTF_Parser::CreateBgfxData( ) vtxDataSize = sizeof( pbrVertex ) * attrAcc->count; vtxData = ( pbrVertex * ) Mem_ClearedAlloc( vtxDataSize ); } - + switch (attrib->bgfxType) { case bgfx::Attrib::Enum::Position : { @@ -1952,13 +2265,13 @@ void GLTF_Parser::CreateBgfxData( ) } auto & samplerList = currentAsset->SamplerList( ); - //Samplers -> this should move to read/parse sampler call + //Samplers -> this should move to read/parse sampler call for ( auto &sampler : samplerList ) sampler->bgfxSamplerFlags = GetSamplerFlags(sampler); - + auto & imgList = currentAsset->ImageList( ); //textures - for ( auto &texture : currentAsset->TextureList( ) ) + for ( auto &texture : currentAsset->TextureList( ) ) { auto * image = imgList[texture->source]; if ( image->bgfxTexture.handle.idx == UINT16_MAX ) { @@ -1980,131 +2293,155 @@ void GLTF_Parser::CreateBgfxData( ) } */ -idList &gltfData::GetAccessorView(gltfAccessor * accessor ) { - idList *&floatView = accessor->floatView;; - - if ( floatView == nullptr ) +idList& gltfData::GetAccessorView( gltfAccessor* accessor ) +{ + idList*& floatView = accessor->floatView;; + + if( floatView == nullptr ) { - gltfBufferView *attrBv = bufferViews[accessor->bufferView]; - gltfData *attrData = attrBv->parent; - gltfBuffer *attrbuff = attrData->BufferList( )[attrBv->buffer]; - assert(sizeof(float) == accessor->typeSize ); + gltfBufferView* attrBv = bufferViews[accessor->bufferView]; + gltfData* attrData = attrBv->parent; + gltfBuffer* attrbuff = attrData->BufferList( )[attrBv->buffer]; + assert( sizeof( float ) == accessor->typeSize ); idFile_Memory bin = idFile_Memory( "GetAccessorView(float)", - ( const char * ) ( ( attrData->GetData( attrBv->buffer ) + attrBv->byteOffset + accessor->byteOffset ) ), attrBv->byteLength ); + ( const char* )( ( attrData->GetData( attrBv->buffer ) + attrBv->byteOffset + accessor->byteOffset ) ), attrBv->byteLength ); floatView = new idList( 16 ); floatView->AssureSize( accessor->count ); - for ( int i = 0; i < accessor->count; i++ ) { - bin.Read( ( void * ) &( *floatView )[i] , accessor->typeSize ); + for( int i = 0; i < accessor->count; i++ ) + { + bin.Read( ( void* ) & ( *floatView )[i] , accessor->typeSize ); } - if ( attrBv->byteStride ) + if( attrBv->byteStride ) + { bin.Seek( attrBv->byteStride - ( accessor->typeSize ), FS_SEEK_CUR ); + } } return *floatView; } -idList &gltfData::GetAccessorViewMat( gltfAccessor *accessor ) { - idList *&matView = accessor->matView; - if ( matView == nullptr ) { - gltfBufferView *attrBv = bufferViews[accessor->bufferView]; - gltfData *attrData = attrBv->parent; - gltfBuffer *attrbuff = attrData->BufferList( )[attrBv->buffer]; +idList& gltfData::GetAccessorViewMat( gltfAccessor* accessor ) +{ + idList*& matView = accessor->matView; + if( matView == nullptr ) + { + gltfBufferView* attrBv = bufferViews[accessor->bufferView]; + gltfData* attrData = attrBv->parent; + gltfBuffer* attrbuff = attrData->BufferList( )[attrBv->buffer]; assert( sizeof( float ) == accessor->typeSize ); idFile_Memory bin = idFile_Memory( "GetAccessorView(idMat4*)", - ( const char * ) ( ( attrData->GetData( attrBv->buffer ) + attrBv->byteOffset + accessor->byteOffset ) ), attrBv->byteLength ); + ( const char* )( ( attrData->GetData( attrBv->buffer ) + attrBv->byteOffset + accessor->byteOffset ) ), attrBv->byteLength ); size_t elementSize = accessor->typeSize * 16; matView = new idList( 16 ); matView->AssureSize( accessor->count ); - for ( int i = 0; i < accessor->count; i++ ) { - bin.Read( ( void * ) &( *matView )[i] , elementSize); + for( int i = 0; i < accessor->count; i++ ) + { + bin.Read( ( void* ) & ( *matView )[i] , elementSize ); } - if ( attrBv->byteStride ) + if( attrBv->byteStride ) + { bin.Seek( attrBv->byteStride - elementSize, FS_SEEK_CUR ); + } } return *matView; } template <> -idList &gltfData::GetAccessorView( gltfAccessor *accessor ) { - idList *&vecView = accessor->vecView; +idList& gltfData::GetAccessorView( gltfAccessor* accessor ) +{ + idList*& vecView = accessor->vecView; - if ( vecView == nullptr ) { - gltfBufferView *attrBv = bufferViews[accessor->bufferView]; - gltfData *attrData = attrBv->parent; - gltfBuffer *attrbuff = attrData->BufferList( )[attrBv->buffer]; - assert(sizeof(float) == accessor->typeSize ); + if( vecView == nullptr ) + { + gltfBufferView* attrBv = bufferViews[accessor->bufferView]; + gltfData* attrData = attrBv->parent; + gltfBuffer* attrbuff = attrData->BufferList( )[attrBv->buffer]; + assert( sizeof( float ) == accessor->typeSize ); idFile_Memory bin = idFile_Memory( "GetAccessorView(idVec3*)", - ( const char * ) ( ( attrData->GetData( attrBv->buffer ) + attrBv->byteOffset + accessor->byteOffset ) ), attrBv->byteLength ); + ( const char* )( ( attrData->GetData( attrBv->buffer ) + attrBv->byteOffset + accessor->byteOffset ) ), attrBv->byteLength ); - vecView = new idList( 16 ); + vecView = new idList( 16 ); vecView->AssureSizeAlloc( accessor->count, idListNewElement ); - for ( int i = 0; i < accessor->count; i++ ) { - idVec3 & vec = *(*vecView)[i]; - bin.Read( ( void * ) &vec.x , accessor->typeSize ); - bin.Read( ( void * ) &vec.y , accessor->typeSize ); - bin.Read( ( void * ) &vec.z , accessor->typeSize ); + for( int i = 0; i < accessor->count; i++ ) + { + idVec3& vec = *( *vecView )[i]; + bin.Read( ( void* ) &vec.x , accessor->typeSize ); + bin.Read( ( void* ) &vec.y , accessor->typeSize ); + bin.Read( ( void* ) &vec.z , accessor->typeSize ); } - if ( attrBv->byteStride ) + if( attrBv->byteStride ) + { bin.Seek( attrBv->byteStride - ( 3 * accessor->typeSize ), FS_SEEK_CUR ); + } } return *vecView; } template <> -idList &gltfData::GetAccessorView( gltfAccessor *accessor ) { - idList *&quatView = accessor->quatView; +idList& gltfData::GetAccessorView( gltfAccessor* accessor ) +{ + idList*& quatView = accessor->quatView; - if ( quatView == nullptr ) { - gltfBufferView *attrBv = bufferViews[accessor->bufferView]; - gltfData *attrData = attrBv->parent; - gltfBuffer *attrbuff = attrData->BufferList( )[attrBv->buffer]; + if( quatView == nullptr ) + { + gltfBufferView* attrBv = bufferViews[accessor->bufferView]; + gltfData* attrData = attrBv->parent; + gltfBuffer* attrbuff = attrData->BufferList( )[attrBv->buffer]; assert( sizeof( float ) == accessor->typeSize ); idFile_Memory bin = idFile_Memory( "GetAccessorView(idQuat*)", - ( const char * ) ( ( attrData->GetData( attrBv->buffer ) + attrBv->byteOffset + accessor->byteOffset ) ), attrBv->byteLength ); + ( const char* )( ( attrData->GetData( attrBv->buffer ) + attrBv->byteOffset + accessor->byteOffset ) ), attrBv->byteLength ); - quatView = new idList( 16 ); + quatView = new idList( 16 ); quatView->AssureSizeAlloc( accessor->count, idListNewElement ); - for ( int i = 0; i < accessor->count; i++ ) { - idQuat &vec = *( *quatView )[i]; - bin.Read( ( void * ) &vec.x, accessor->typeSize ); - bin.Read( ( void * ) &vec.y, accessor->typeSize ); - bin.Read( ( void * ) &vec.z, accessor->typeSize ); - bin.Read( ( void * ) &vec.w, accessor->typeSize ); + for( int i = 0; i < accessor->count; i++ ) + { + idQuat& vec = *( *quatView )[i]; + bin.Read( ( void* ) &vec.x, accessor->typeSize ); + bin.Read( ( void* ) &vec.y, accessor->typeSize ); + bin.Read( ( void* ) &vec.z, accessor->typeSize ); + bin.Read( ( void* ) &vec.w, accessor->typeSize ); } - if ( attrBv->byteStride ) + if( attrBv->byteStride ) + { bin.Seek( attrBv->byteStride - ( 4 * accessor->typeSize ), FS_SEEK_CUR ); + } } return *quatView; } -gltfData::~gltfData() { +gltfData::~gltfData() +{ //hvg_todo //delete data, not only pointer - common->Warning("GLTF DATA NOT FREED" ); - if (data) + common->Warning( "GLTF DATA NOT FREED" ); + if( data ) + { delete[] data; - + } + //delete cameraManager; } GLTF_Parser localGltfParser; -GLTF_Parser * gltfParser = &localGltfParser; +GLTF_Parser* gltfParser = &localGltfParser; #undef GLTFARRAYITEM #undef GLTFARRAYITEMREF -CONSOLE_COMMAND_COMPILE( LoadGLTF, "Loads an .gltf or .glb file",idCmdSystem::ArgCompletion_MapName ) { +CONSOLE_COMMAND_COMPILE( LoadGLTF, "Loads an .gltf or .glb file", idCmdSystem::ArgCompletion_MapName ) +{ - if ( args.Argc( ) > 1 ) { - gltfParser->Load( args.Argv( 1 ) ); + if( args.Argc( ) > 1 ) + { + gltfParser->Load( args.Argv( 1 ) ); } } diff --git a/neo/idlib/gltfParser.h b/neo/idlib/gltfParser.h index 73ec046a..a729f049 100644 --- a/neo/idlib/gltfParser.h +++ b/neo/idlib/gltfParser.h @@ -6,75 +6,125 @@ #pragma region GLTF Types parsing #pragma region Parser interfaces -struct parsable { +struct parsable +{ public: - virtual void parse(idToken & token )=0; - virtual void parse(idToken & token , idLexer * parser){}; - virtual idStr &Name( ) = 0; + virtual void parse( idToken& token ) = 0; + virtual void parse( idToken& token , idLexer* parser ) {}; + virtual idStr& Name( ) = 0; }; template -class parseType { +class parseType +{ public: - void Set(T * type ) { item = type; } - virtual ~parseType() { delete item; } + void Set( T* type ) + { + item = type; + } + virtual ~parseType() + { + delete item; + } T* item; }; class gltfItem : public parsable, public parseType { public: - gltfItem( idStr Name) : name( Name ) { item = nullptr; } - virtual void parse( idToken &token ) { *item = token; }; - virtual idStr &Name( ) {return name;} - ~gltfItem(){} + gltfItem( idStr Name ) : name( Name ) + { + item = nullptr; + } + virtual void parse( idToken& token ) + { + *item = token; + }; + virtual idStr& Name( ) + { + return name; + } + ~gltfItem() {} private: idStr name; }; -class gltfObject : public parsable, public parseType { +class gltfObject : public parsable, public parseType +{ public: - gltfObject( idStr Name ) : name( Name ), object("null"){} - virtual void parse( idToken &token ) {} - virtual void parse(idToken & token , idLexer * parser){ - parser->UnreadToken( &token );parser->ParseBracedSection( object ); + gltfObject( idStr Name ) : name( Name ), object( "null" ) {} + virtual void parse( idToken& token ) {} + virtual void parse( idToken& token , idLexer* parser ) + { + parser->UnreadToken( &token ); + parser->ParseBracedSection( object ); + } + virtual idStr& Name( ) + { + return name; } - virtual idStr &Name( ) { return name; } private: idStr name; idStr object; }; class gltfItemArray; -class gltfItem_Extra : public parsable, public parseType { +class gltfItem_Extra : public parsable, public parseType +{ public: - gltfItem_Extra( idStr Name ) : name( Name ), data(nullptr),parser(nullptr) { item = nullptr; } - virtual void parse( idToken &token ) ; - virtual idStr &Name( ) { return name; } - void Set( gltfExtra *type, idLexer *lexer ) { parseType::Set( type ); parser = lexer; } - static void Register(parsable * extra); + gltfItem_Extra( idStr Name ) : name( Name ), data( nullptr ), parser( nullptr ) + { + item = nullptr; + } + virtual void parse( idToken& token ) ; + virtual idStr& Name( ) + { + return name; + } + void Set( gltfExtra* type, idLexer* lexer ) + { + parseType::Set( type ); + parser = lexer; + } + static void Register( parsable* extra ); private: idStr name; - gltfData *data; + gltfData* data; idLexer* parser; - static gltfItemArray*items; + static gltfItemArray* items; }; -class gltfItem_uri : public parsable, public parseType { +class gltfItem_uri : public parsable, public parseType +{ public: - gltfItem_uri( idStr Name ) : name( Name ) { item = nullptr; } - virtual void parse( idToken &token ) { *item = token; Convert(); }; - virtual idStr &Name( ) { return name; } - void Set( idStr *type,int * targetBufferview,gltfData* dataDestination ) { parseType::Set(type); bufferView = targetBufferview; data = dataDestination; } + gltfItem_uri( idStr Name ) : name( Name ) + { + item = nullptr; + } + virtual void parse( idToken& token ) + { + *item = token; + Convert(); + }; + virtual idStr& Name( ) + { + return name; + } + void Set( idStr* type, int* targetBufferview, gltfData* dataDestination ) + { + parseType::Set( type ); + bufferView = targetBufferview; + data = dataDestination; + } // read data from uri file, and push it at end of current data buffer for this GLTF File // bufferView will be set accordingly to the generated buffer. bool Convert( ); private: idStr name; - int * bufferView; - gltfData * data; + int* bufferView; + gltfData* data; }; -#pragma endregion +#pragma endregion #pragma region helper macro to define gltf data types with extra parsing context forced to be implemented externally #define gltfItemClassParser(className,ptype) \ @@ -87,15 +137,15 @@ class gltfItem_##className : public parsable, public parseType \ private: \ idStr name; \ idLexer *parser;} -#pragma endregion +#pragma endregion gltfItemClassParser( animation_sampler, idList ); gltfItemClassParser( animation_channel_target, gltfAnimation_Channel_Target ); -gltfItemClassParser( animation_channel, idList); -gltfItemClassParser( mesh_primitive, idList); -gltfItemClassParser( mesh_primitive_attribute, idList ); -gltfItemClassParser( integer_array, idList); -gltfItemClassParser( number_array, idList);//does float suffice? +gltfItemClassParser( animation_channel, idList ); +gltfItemClassParser( mesh_primitive, idList ); +gltfItemClassParser( mesh_primitive_attribute, idList ); +gltfItemClassParser( integer_array, idList ); +gltfItemClassParser( number_array, idList ); //does float suffice? gltfItemClassParser( mat4, idMat4 ); gltfItemClassParser( vec4, idVec4 ); gltfItemClassParser( vec3, idVec3 ); @@ -107,8 +157,8 @@ gltfItemClassParser( accessor_sparse_values, gltfAccessor_Sparse_Values ); gltfItemClassParser( camera_perspective, gltfCamera_Perspective ); gltfItemClassParser( camera_orthographic, gltfCamera_Orthographic ); gltfItemClassParser( pbrMetallicRoughness, gltfMaterial_pbrMetallicRoughness ); -gltfItemClassParser( texture_info, gltfTexture_Info); -gltfItemClassParser( normal_texture, gltfNormalTexture_Info); +gltfItemClassParser( texture_info, gltfTexture_Info ); +gltfItemClassParser( normal_texture, gltfNormalTexture_Info ); gltfItemClassParser( occlusion_texture, gltfOcclusionTexture_Info ); gltfItemClassParser( node_extensions, gltfNode_Extensions ); gltfItemClassParser( material_extensions, gltfMaterial_Extensions ); @@ -131,104 +181,135 @@ class gltfItem_##className : public parsable, public parseType \ virtual idStr &Name( ) { return name; } \ private: \ idStr name;} -#pragma endregion +#pragma endregion -gltfItemClass(integer, int, *item = token.GetIntValue( ); ); -gltfItemClass(number, float, *item = token.GetFloatValue( ); ); -gltfItemClass(boolean, bool, if (token.Icmp("true") == 0 ) *item=true; else{ if(token.Icmp("false") == 0)*item=false; else idLib::FatalError("parse error");}); +gltfItemClass( integer, int, *item = token.GetIntValue( ); ); +gltfItemClass( number, float, *item = token.GetFloatValue( ); ); +gltfItemClass( boolean, bool, if( token.Icmp( "true" ) == 0 ) *item = true; else +{ + if( token.Icmp( "false" ) == 0 ) + { + *item = false; + } + else + { + idLib::FatalError( "parse error" ); + } + } ); #undef gltfItemClass class gltfItemArray { public: - ~gltfItemArray( ) { items.DeleteContents(true); } + ~gltfItemArray( ) + { + items.DeleteContents( true ); + } gltfItemArray( ) { }; - int Num() { return items.Num(); } - void AddItemDef( parsable *item ) { items.Alloc( ) = item;} - int Fill(idLexer * lexer , idDict * strPairs ); - int Parse(idLexer * lexer , bool forwardLexer = false ); + int Num() + { + return items.Num(); + } + void AddItemDef( parsable* item ) + { + items.Alloc( ) = item; + } + int Fill( idLexer* lexer , idDict* strPairs ); + int Parse( idLexer* lexer , bool forwardLexer = false ); template - T* Get(idStr name ){ for ( auto * item : items) if (item->Name() == name) return static_cast(item); return nullptr; } + T* Get( idStr name ) + { + for( auto* item : items ) if( item->Name() == name ) + { + return static_cast( item ); + } + return nullptr; + } private: idList items; }; -#pragma endregion +#pragma endregion #pragma region GLTF Object parsing class gltfPropertyArray; -class gltfPropertyItem +class gltfPropertyItem { public: - gltfPropertyItem( ) : array(nullptr){ } - gltfPropertyArray * array; - idToken item; + gltfPropertyItem( ) : array( nullptr ) { } + gltfPropertyArray* array; + idToken item; }; class gltfPropertyArray { public: - gltfPropertyArray( idLexer *Parser,bool AoS = true ); + gltfPropertyArray( idLexer* Parser, bool AoS = true ); ~gltfPropertyArray( ); - struct Iterator { - gltfPropertyArray * array; - gltfPropertyItem *p; - gltfPropertyItem &operator*( ) {return *p;} - bool operator != ( Iterator &rhs ) { - return p != rhs.p; + struct Iterator + { + gltfPropertyArray* array; + gltfPropertyItem* p; + gltfPropertyItem& operator*( ) + { + return *p; + } + bool operator != ( Iterator& rhs ) + { + return p != rhs.p; } void operator ++( ); - }; + }; gltfPropertyArray::Iterator begin( ); gltfPropertyArray::Iterator end( ); private: bool iterating; bool dirty; int index; - idLexer * parser; + idLexer* parser; idList properties; - gltfPropertyItem * endPtr; + gltfPropertyItem* endPtr; bool isArrayOfStructs; }; #pragma endregion -class GLTF_Parser +class GLTF_Parser { public: GLTF_Parser(); void Shutdown(); bool Parse(); - bool Load(idStr filename ); - bool loadGLB(idStr filename ); + bool Load( idStr filename ); + bool loadGLB( idStr filename ); //current/last loaded gltf asset and index offsets - gltfData *currentAsset; + gltfData* currentAsset; private: - void SetNodeParent( gltfNode *node, gltfNode *parent = nullptr ); + void SetNodeParent( gltfNode* node, gltfNode* parent = nullptr ); //void CreateBgfxData( ); - void Parse_ASSET( idToken &token ); - void Parse_CAMERAS( idToken &token ); - void Parse_SCENE( idToken &token ); - void Parse_SCENES( idToken &token ); - void Parse_NODES( idToken &token ); - void Parse_MATERIALS( idToken &token ); - void Parse_MESHES( idToken &token ); - void Parse_TEXTURES( idToken &token ); - void Parse_IMAGES( idToken &token ); - void Parse_ACCESSORS( idToken &token ); - void Parse_BUFFERVIEWS( idToken &token ); - void Parse_SAMPLERS( idToken &token ); - void Parse_BUFFERS( idToken &token ); - void Parse_ANIMATIONS( idToken &token ); - void Parse_SKINS( idToken &token ); - void Parse_EXTENSIONS( idToken &token ); - void Parse_EXTENSIONS_USED( idToken &token ); - void Parse_EXTENSIONS_REQUIRED( idToken &token ); - + void Parse_ASSET( idToken& token ); + void Parse_CAMERAS( idToken& token ); + void Parse_SCENE( idToken& token ); + void Parse_SCENES( idToken& token ); + void Parse_NODES( idToken& token ); + void Parse_MATERIALS( idToken& token ); + void Parse_MESHES( idToken& token ); + void Parse_TEXTURES( idToken& token ); + void Parse_IMAGES( idToken& token ); + void Parse_ACCESSORS( idToken& token ); + void Parse_BUFFERVIEWS( idToken& token ); + void Parse_SAMPLERS( idToken& token ); + void Parse_BUFFERS( idToken& token ); + void Parse_ANIMATIONS( idToken& token ); + void Parse_SKINS( idToken& token ); + void Parse_EXTENSIONS( idToken& token ); + void Parse_EXTENSIONS_USED( idToken& token ); + void Parse_EXTENSIONS_REQUIRED( idToken& token ); + + + gltfProperty ParseProp( idToken& token ); + gltfProperty ResolveProp( idToken& token ); - gltfProperty ParseProp( idToken &token ); - gltfProperty ResolveProp( idToken &token ); - idLexer parser; idToken token; idStr currentFile; @@ -237,4 +318,4 @@ private: bool bufferViewsDone; }; -extern GLTF_Parser * gltfParser; \ No newline at end of file +extern GLTF_Parser* gltfParser; \ No newline at end of file diff --git a/neo/idlib/gltfProperties.h b/neo/idlib/gltfProperties.h index 5e160f7f..007eca26 100644 --- a/neo/idlib/gltfProperties.h +++ b/neo/idlib/gltfProperties.h @@ -5,7 +5,8 @@ #include "Lib.h" #include "containers/List.h" -enum gltfProperty { +enum gltfProperty +{ INVALID, ASSET, ACCESSOR, @@ -33,7 +34,8 @@ class gltfData; struct gltf_accessor_component { - enum Type { + enum Type + { _byte, _uByte, _short, @@ -46,7 +48,8 @@ struct gltf_accessor_component }; template< class T > -struct gltf_accessor_component_type_map { +struct gltf_accessor_component_type_map +{ idStr stringID; int id; T type; @@ -62,38 +65,43 @@ public: //str:str pairs of each item idDict strPairs; //specialized parsers - idList extras; + idList extras; }; class gltfExt_KHR_lights_punctual; -class gltfExtensions { +class gltfExtensions +{ public: gltfExtensions( ) { } - idList KHR_lights_punctual; + idList KHR_lights_punctual; }; -class gltfNode_KHR_lights_punctual { +class gltfNode_KHR_lights_punctual +{ public: - int light; + int light; }; -class gltfNode_Extensions { +class gltfNode_Extensions +{ public: - gltfNode_Extensions( ) : - KHR_lights_punctual( nullptr) { } + gltfNode_Extensions( ) : + KHR_lights_punctual( nullptr ) { } gltfNode_KHR_lights_punctual* KHR_lights_punctual; }; class gltfExt_KHR_materials_pbrSpecularGlossiness; -class gltfMaterial_Extensions { +class gltfMaterial_Extensions +{ public: gltfMaterial_Extensions( ) : KHR_materials_pbrSpecularGlossiness( nullptr ) { } - gltfExt_KHR_materials_pbrSpecularGlossiness *KHR_materials_pbrSpecularGlossiness; + gltfExt_KHR_materials_pbrSpecularGlossiness* KHR_materials_pbrSpecularGlossiness; }; -class gltfNode { +class gltfNode +{ public: gltfNode( ) : camera( -1 ), skin( -1 ), matrix( mat4_zero ), mesh( -1 ), rotation( 0.f, 0.f, 0.f, 1.f ), scale( 1.f, 1.f, 1.f ), @@ -112,16 +120,18 @@ public: gltfExtra extras; // - gltfNode * parent; + gltfNode* parent; bool dirty; }; -struct gltfCameraNodePtrs { - gltfNode *translationNode = nullptr; - gltfNode *orientationNode = nullptr; +struct gltfCameraNodePtrs +{ + gltfNode* translationNode = nullptr; + gltfNode* orientationNode = nullptr; }; -class gltfScene { +class gltfScene +{ public: gltfScene( ) { } idList nodes; @@ -130,9 +140,11 @@ public: gltfExtra extras; }; -class gltfMesh_Primitive_Attribute { +class gltfMesh_Primitive_Attribute +{ public: - enum Type { + enum Type + { Position, Normal, Tangent, @@ -153,7 +165,7 @@ public: Count }; - gltfMesh_Primitive_Attribute( ) : accessorIndex( -1 ), elementSize( 0 ), type( gltfMesh_Primitive_Attribute::Type::Count ){ } + gltfMesh_Primitive_Attribute( ) : accessorIndex( -1 ), elementSize( 0 ), type( gltfMesh_Primitive_Attribute::Type::Count ) { } idStr attributeSemantic; int accessorIndex; uint elementSize; @@ -161,16 +173,18 @@ public: Type type; }; -struct gltf_mesh_attribute_map { +struct gltf_mesh_attribute_map +{ idStr stringID; gltfMesh_Primitive_Attribute::Type attib; uint elementSize; }; -class gltfMesh_Primitive { +class gltfMesh_Primitive +{ public: gltfMesh_Primitive( ) : indices( -1 ), material( -1 ), mode( -1 ) { } - idList attributes; + idList attributes; int indices; int material; int mode; @@ -179,18 +193,20 @@ public: gltfExtra extras; }; -class gltfMesh { +class gltfMesh +{ public: gltfMesh( ) { }; - idList primitives; // gltfMesh_Primitive[1,*] + idList primitives; // gltfMesh_Primitive[1,*] idList weights; // number[1,*] idStr name; idStr extensions; gltfExtra extras; }; -class gltfCamera_Orthographic { +class gltfCamera_Orthographic +{ public: gltfCamera_Orthographic( ) : xmag( 0.0f ), ymag( 0.0f ), zfar( 0.0f ), znear( 0.0f ) { }; float xmag; @@ -201,7 +217,8 @@ public: gltfExtra extras; }; -class gltfCamera_Perspective { +class gltfCamera_Perspective +{ public: gltfCamera_Perspective( ) : aspectRatio( 0.0f ), yfov( 0.0f ), zfar( 0.0f ), znear( 0.0f ) { }; float aspectRatio; @@ -212,7 +229,8 @@ public: gltfExtra extras; }; -class gltfCamera { +class gltfCamera +{ public: gltfCamera( ) { }; gltfCamera_Orthographic orthographic; @@ -223,7 +241,8 @@ public: gltfExtra extras; }; -class gltfAnimation_Channel_Target { +class gltfAnimation_Channel_Target +{ public: gltfAnimation_Channel_Target( ) : node( -1 ), TRS( gltfTRS::count ) { }; int node; @@ -231,7 +250,8 @@ public: idStr extensions; gltfExtra extras; - enum gltfTRS { + enum gltfTRS + { none, rotation, translation, @@ -242,20 +262,30 @@ public: gltfTRS TRS; - static gltfTRS resolveType( idStr type ) { - if ( type == "translation" ) + static gltfTRS resolveType( idStr type ) + { + if( type == "translation" ) + { return gltfTRS::translation; - else if ( type == "rotation" ) + } + else if( type == "rotation" ) + { return gltfTRS::rotation; - else if ( type == "scale" ) + } + else if( type == "scale" ) + { return gltfTRS::scale; - else if ( type == "weights" ) + } + else if( type == "weights" ) + { return gltfTRS::weights; + } return gltfTRS::count; } }; -class gltfAnimation_Channel { +class gltfAnimation_Channel +{ public: gltfAnimation_Channel( ) : sampler( -1 ) { }; int sampler; @@ -264,16 +294,18 @@ public: gltfExtra extras; }; -class gltfAnimation_Sampler { +class gltfAnimation_Sampler +{ public: - gltfAnimation_Sampler( ) : input( -1 ), interpolation("LINEAR"),output( -1 ), intType(gltfInterpType::count) { }; + gltfAnimation_Sampler( ) : input( -1 ), interpolation( "LINEAR" ), output( -1 ), intType( gltfInterpType::count ) { }; int input; idStr interpolation; int output; idStr extensions; gltfExtra extras; - enum gltfInterpType { + enum gltfInterpType + { linear, step, cubicSpline, @@ -282,23 +314,31 @@ public: gltfInterpType intType; - static gltfInterpType resolveType( idStr type ) { - if ( type == "LINEAR" ) + static gltfInterpType resolveType( idStr type ) + { + if( type == "LINEAR" ) + { return gltfInterpType::linear; - else if ( type == "STEP" ) + } + else if( type == "STEP" ) + { return gltfInterpType::step; - else if ( type == "CUBICSPLINE" ) + } + else if( type == "CUBICSPLINE" ) + { return gltfInterpType::cubicSpline; + } return gltfInterpType::count; } }; -class gltfAnimation { +class gltfAnimation +{ public: - gltfAnimation( ) : maxTime (0.0f),numFrames(0) { }; - idList channels; - idList samplers; + gltfAnimation( ) : maxTime( 0.0f ), numFrames( 0 ) { }; + idList channels; + idList samplers; idStr name; idStr extensions; gltfExtra extras; @@ -308,16 +348,39 @@ public: //id specific mutable int ref_count; int numFrames; - void DecreaseRefs() const {ref_count--;}; - void IncreaseRefs() const {ref_count++;}; - bool GetBounds( idBounds &bnds, int time, int cyclecount ) const { return false;} - bool GetOriginRotation( idQuat &rotation, int time, int cyclecount ) const { return false;} - bool GetOrigin( idVec3 &offset, int time, int cyclecount ) const { return false;} - const idVec3 &TotalMovementDelta( void ) const {static idVec3 temp; return temp; } - int NumFrames() const {return numFrames;} + void DecreaseRefs() const + { + ref_count--; + }; + void IncreaseRefs() const + { + ref_count++; + }; + bool GetBounds( idBounds& bnds, int time, int cyclecount ) const + { + return false; + } + bool GetOriginRotation( idQuat& rotation, int time, int cyclecount ) const + { + return false; + } + bool GetOrigin( idVec3& offset, int time, int cyclecount ) const + { + return false; + } + const idVec3& TotalMovementDelta( void ) const + { + static idVec3 temp; + return temp; + } + int NumFrames() const + { + return numFrames; + } }; -class gltfAccessor_Sparse_Values { +class gltfAccessor_Sparse_Values +{ public: gltfAccessor_Sparse_Values( ) : bufferView( -1 ), byteOffset( -1 ) { }; int bufferView; @@ -326,7 +389,8 @@ public: gltfExtra extras; }; -class gltfAccessor_Sparse_Indices { +class gltfAccessor_Sparse_Indices +{ public: gltfAccessor_Sparse_Indices( ) : bufferView( -1 ), byteOffset( -1 ), componentType( -1 ) { }; int bufferView; @@ -336,7 +400,8 @@ public: gltfExtra extras; }; -class gltfAccessor_Sparse { +class gltfAccessor_Sparse +{ public: gltfAccessor_Sparse( ) : count( -1 ) { }; int count; @@ -346,10 +411,11 @@ public: gltfExtra extras; }; -class gltfAccessor { +class gltfAccessor +{ public: gltfAccessor( ) : bufferView( -1 ), byteOffset( 0 ), componentType( -1 ), normalized( false ), count( -1 ) , - floatView(nullptr),vecView(nullptr),quatView(nullptr),matView(nullptr){ } + floatView( nullptr ), vecView( nullptr ), quatView( nullptr ), matView( nullptr ) { } int bufferView; int byteOffset; int componentType; @@ -365,13 +431,14 @@ public: uint typeSize; - idList * floatView; - idList * vecView; - idList * quatView; - idList * matView; + idList* floatView; + idList* vecView; + idList* quatView; + idList* matView; }; -class gltfBufferView { +class gltfBufferView +{ public: gltfBufferView( ) : buffer( -1 ), byteLength( -1 ), byteStride( 0 ), byteOffset( 0 ), target( -1 ) { }; int buffer; @@ -383,10 +450,11 @@ public: idStr extensions; gltfExtra extras; // - gltfData *parent; + gltfData* parent; }; -class gltfBuffer { +class gltfBuffer +{ public: gltfBuffer( ) : byteLength( -1 ), parent( nullptr ) { }; idStr uri; @@ -395,10 +463,11 @@ public: idStr extensions; gltfExtra extras; // - gltfData * parent; + gltfData* parent; }; -class gltfSampler { +class gltfSampler +{ public: gltfSampler( ) : magFilter( 0 ), minFilter( 0 ), wrapS( 10497 ), wrapT( 10497 ) { }; int magFilter; @@ -412,7 +481,8 @@ public: uint bgfxSamplerFlags; }; -class gltfImage { +class gltfImage +{ public: gltfImage( ) : bufferView( -1 ) { } idStr uri; @@ -423,9 +493,10 @@ public: gltfExtra extras; }; -class gltfSkin { +class gltfSkin +{ public: - gltfSkin( ) : inverseBindMatrices(-1),skeleton(-1),name("unnamedSkin"){ }; + gltfSkin( ) : inverseBindMatrices( -1 ), skeleton( -1 ), name( "unnamedSkin" ) { }; int inverseBindMatrices; int skeleton; idList joints; // integer[1,*] @@ -435,14 +506,16 @@ public: }; class gltfExt_KHR_texture_transform; -class gltfTexture_Info_Extensions { +class gltfTexture_Info_Extensions +{ public: gltfTexture_Info_Extensions( ) : KHR_texture_transform( nullptr ) { } - gltfExt_KHR_texture_transform *KHR_texture_transform; + gltfExt_KHR_texture_transform* KHR_texture_transform; }; -class gltfOcclusionTexture_Info { +class gltfOcclusionTexture_Info +{ public: gltfOcclusionTexture_Info( ) : index( -1 ), texCoord( 0 ), strength( 1.0f ) { } int index; @@ -452,7 +525,8 @@ public: gltfExtra extras; }; -class gltfNormalTexture_Info { +class gltfNormalTexture_Info +{ public: gltfNormalTexture_Info( ) : index( -1 ), texCoord( 0 ), scale( 1.0f ) { } int index; @@ -462,7 +536,8 @@ public: gltfExtra extras; }; -class gltfTexture_Info { +class gltfTexture_Info +{ public: gltfTexture_Info( ) : index( -1 ), texCoord( 0 ) { } int index; @@ -472,17 +547,19 @@ public: }; -class gltfTexture { +class gltfTexture +{ public: gltfTexture( ) : sampler( -1 ), source( -1 ) { } int sampler; int source; idStr name; gltfTexture_Info_Extensions extensions; - gltfExtra extras; + gltfExtra extras; }; -class gltfMaterial_pbrMetallicRoughness { +class gltfMaterial_pbrMetallicRoughness +{ public: gltfMaterial_pbrMetallicRoughness( ) : baseColorFactor( vec4_one ), metallicFactor( 1.0f ), roughnessFactor( 1.0f ) { } idVec4 baseColorFactor; @@ -494,9 +571,11 @@ public: gltfExtra extras; }; -class gltfMaterial { +class gltfMaterial +{ public: - enum gltfAlphaMode { + enum gltfAlphaMode + { gltfOPAQUE, gltfMASK, gltfBLEND, @@ -518,18 +597,26 @@ public: gltfAlphaMode intType; - static gltfAlphaMode resolveAlphaMode( idStr type ) { - if ( type == "OPAQUE" ) + static gltfAlphaMode resolveAlphaMode( idStr type ) + { + if( type == "OPAQUE" ) + { return gltfAlphaMode::gltfOPAQUE; - else if ( type == "MASK" ) + } + else if( type == "MASK" ) + { return gltfAlphaMode::gltfMASK; - else if ( type == "BLEND" ) + } + else if( type == "BLEND" ) + { return gltfAlphaMode::gltfBLEND; + } return gltfAlphaMode::count; } }; -class gltfAsset { +class gltfAsset +{ public: gltfAsset( ) { } idStr copyright; @@ -542,7 +629,8 @@ public: //this is not used. //if an extension is found, it _will_ be used. (if implemented) -class gltfExtensionsUsed { +class gltfExtensionsUsed +{ public: gltfExtensionsUsed( ) { } idStr extension; @@ -565,9 +653,10 @@ public: //KHR_lights_punctual_spot //https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_lights_punctual/schema/light.spot.schema.json -class gltfExt_KHR_lights_punctual_spot { +class gltfExt_KHR_lights_punctual_spot +{ public: - gltfExt_KHR_lights_punctual_spot( ) : innerConeAngle(0.0f), outerConeAngle( idMath::ONEFOURTH_PI ){ } + gltfExt_KHR_lights_punctual_spot( ) : innerConeAngle( 0.0f ), outerConeAngle( idMath::ONEFOURTH_PI ) { } float innerConeAngle; float outerConeAngle; idStr extensions; @@ -577,9 +666,10 @@ typedef gltfExt_KHR_lights_punctual_spot spot; //KHR_lights_punctual //https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_lights_punctual/schema/light.schema.json -class gltfExt_KHR_lights_punctual { +class gltfExt_KHR_lights_punctual +{ public: - gltfExt_KHR_lights_punctual( ) : color(vec3_one),intensity(1.0f),range(-1.0f),intType(-1) { } + gltfExt_KHR_lights_punctual( ) : color( vec3_one ), intensity( 1.0f ), range( -1.0f ), intType( -1 ) { } idVec3 color; float intensity; spot spot; @@ -591,28 +681,36 @@ public: int intType; - static int resolveType( idStr type ) { - if (type == "directional" ) + static int resolveType( idStr type ) + { + if( type == "directional" ) + { return 0; - else if (type == "point" ) + } + else if( type == "point" ) + { return 1; - else if (type == "spot" ) + } + else if( type == "spot" ) + { return 2; + } return -1; } }; //KHR_texture_transform //https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_transform/schema/KHR_texture_transform.textureInfo.schema.json -class gltfExt_KHR_texture_transform { +class gltfExt_KHR_texture_transform +{ public: - gltfExt_KHR_texture_transform( ) : offset( vec2_zero ), rotation( 0.0f ), scale( vec2_one ), texCoord( -1 ),index(0),resolved(false) { } + gltfExt_KHR_texture_transform( ) : offset( vec2_zero ), rotation( 0.0f ), scale( vec2_one ), texCoord( -1 ), index( 0 ), resolved( false ) { } idVec2 offset; float rotation; idVec2 scale; int texCoord; idStr extensions; -gltfExtra extras; + gltfExtra extras; //for shader uint index; @@ -631,53 +729,85 @@ const inline idList & ##name##List() { return target; } // EACH URI will have an unique chunk // JSON chunk MUST be the first one to be allocated/added -class gltfData { +class gltfData +{ public: gltfData( ) : fileNameHash( 0 ), json( nullptr ), data( nullptr ), totalChunks( -1 ) { }; ~gltfData( ); - byte *AddData( int size, int *bufferID = nullptr ); - byte *GetJsonData( int &size ) { size = jsonDataLength; return json; } - byte *GetData( int index ) { return data[index]; } - void FileName( const idStr &file ) { fileName = file; fileNameHash = fileDataHash.GenerateKey( file.c_str( ) ); } - int FileNameHash( ) { return fileNameHash; } - idStr &FileName( ) { return fileName; } + byte* AddData( int size, int* bufferID = nullptr ); + byte* GetJsonData( int& size ) + { + size = jsonDataLength; + return json; + } + byte* GetData( int index ) + { + return data[index]; + } + void FileName( const idStr& file ) + { + fileName = file; + fileNameHash = fileDataHash.GenerateKey( file.c_str( ) ); + } + int FileNameHash( ) + { + return fileNameHash; + } + idStr& FileName( ) + { + return fileName; + } static idHashIndex fileDataHash; - static idList dataList; + static idList dataList; //add data from filename - static gltfData *Data( idStr &fileName ) { + static gltfData* Data( idStr& fileName ) + { dataList.AssureSizeAlloc( dataList.Num( ) + 1, idListNewElement ); dataList[dataList.Num( ) - 1]->FileName( fileName ); fileDataHash.Add( fileDataHash.GenerateKey( fileName ), dataList.Num( ) - 1 ); return dataList[dataList.Num( ) - 1]; } //find data; - static gltfData *Data( const char *filename ) { return dataList[fileDataHash.First( fileDataHash.GenerateKey( filename ) )]; } - static const idList &DataList( ) { return dataList; } - static void ClearData( ) { idLib::Warning( "TODO! DATA NOT FREED" ); } + static gltfData* Data( const char* filename ) + { + return dataList[fileDataHash.First( fileDataHash.GenerateKey( filename ) )]; + } + static const idList& DataList( ) + { + return dataList; + } + static void ClearData( ) + { + idLib::Warning( "TODO! DATA NOT FREED" ); + } //return the GLTF nodes that control the given camera //return TRUE if the camera uses 2 nodes (like when blender exports gltfs with +Y..) - //This is determined by checking for an "_Orientation" suffix to the camera name of the node that has the target camera assigned. + //This is determined by checking for an "_Orientation" suffix to the camera name of the node that has the target camera assigned. // if so, translate node will be set to the parent node of the orientation node. //Note: does not take overides into account! - gltfNode* GetCameraNodes( gltfCamera *camera ) + gltfNode* GetCameraNodes( gltfCamera* camera ) { gltfCameraNodePtrs result; assert( camera ); int camId = -1; - for ( auto *cam : cameras ) + for( auto* cam : cameras ) { camId++; - if ( cam == camera ) + if( cam == camera ) + { break; + } } - for ( int i = 0; i < nodes.Num( ); i++ ) + for( int i = 0; i < nodes.Num( ); i++ ) { - if ( nodes[i]->camera != -1 && nodes[i]->camera == camId ) + if( nodes[i]->camera != -1 && nodes[i]->camera == camId ) + { return nodes[i]; + } } return nullptr; @@ -693,15 +823,16 @@ public: idMat4 result = mat4_identity; - idList hierachy(2); + idList hierachy( 2 ); gltfNode* parent = nullptr; - for ( int i = 0; i < nodes.Num( ); i++ ) + for( int i = 0; i < nodes.Num( ); i++ ) { - if ( nodes[i]->camera != -1 && nodes[i]->camera == camId ) + if( nodes[i]->camera != -1 && nodes[i]->camera == camId ) { parent = nodes[i]; - while ( parent ) { + while( parent ) + { hierachy.Append( parent ); parent = parent->parent; } @@ -709,27 +840,30 @@ public: } } - for ( int i = hierachy.Num( ) - 1; i >= 0; i-- ) + for( int i = hierachy.Num( ) - 1; i >= 0; i-- ) { - ResolveNodeMatrix(hierachy[i]); + ResolveNodeMatrix( hierachy[i] ); result *= hierachy[i]->matrix; } return result; } //Please note : assumes all nodes are _not_ dirty! - idMat4 GetLightMatrix( int lightId ) const + idMat4 GetLightMatrix( int lightId ) const { idMat4 result = mat4_identity; - idList hierachy; - gltfNode *parent = nullptr; + idList hierachy; + gltfNode* parent = nullptr; hierachy.SetGranularity( 2 ); - for ( int i = 0; i < nodes.Num( ); i++ ) { - if ( nodes[i]->extensions.KHR_lights_punctual && nodes[i]->extensions.KHR_lights_punctual->light == lightId ) { + for( int i = 0; i < nodes.Num( ); i++ ) + { + if( nodes[i]->extensions.KHR_lights_punctual && nodes[i]->extensions.KHR_lights_punctual->light == lightId ) + { parent = nodes[i]; - while ( parent ) { + while( parent ) + { hierachy.Append( parent ); parent = parent->parent; } @@ -737,59 +871,70 @@ public: } } - for ( int i = hierachy.Num( ) - 1; i >= 0; i-- ) + for( int i = hierachy.Num( ) - 1; i >= 0; i-- ) + { result *= hierachy[i]->matrix; + } return result; } - + // v * T * R * S. ->row major // v' = S * R * T * v -> column major; //bgfx = column-major //idmath = row major, except mat3 //gltf matrices : column-major. //if mat* is valid , it will be multplied by this node's matrix that is resolved in its full hiararchy and stops at root. - static void ResolveNodeMatrix( gltfNode *node, idMat4 *mat = nullptr ,gltfNode *root = nullptr ) + static void ResolveNodeMatrix( gltfNode* node, idMat4* mat = nullptr , gltfNode* root = nullptr ) { - if ( node->dirty ) + if( node->dirty ) { idMat4 scaleMat = idMat4( - node->scale.x, 0, 0, 0, - 0, node->scale.y, 0, 0, - 0, 0, node->scale.z, 0, - 0, 0, 0, 1 - ); - + node->scale.x, 0, 0, 0, + 0, node->scale.y, 0, 0, + 0, 0, node->scale.z, 0, + 0, 0, 0, 1 + ); + node->matrix = idMat4( mat3_identity, node->translation ) * node->rotation.ToMat4( ).Transpose( ) * scaleMat; node->dirty = false; } //resolve full hierarchy - if ( mat != nullptr ) { - idList hierachy(2); - gltfNode *parent = node; - while ( parent ) { - ResolveNodeMatrix(parent); + if( mat != nullptr ) + { + idList hierachy( 2 ); + gltfNode* parent = node; + while( parent ) + { + ResolveNodeMatrix( parent ); hierachy.Append( parent ); - if ( parent == root ) + if( parent == root ) + { break; + } parent = parent->parent; } - for ( int i = hierachy.Num( ) - 1; i >= 0; i-- ) + for( int i = hierachy.Num( ) - 1; i >= 0; i-- ) + { *mat *= hierachy[i]->matrix; + } } } - void Advance( gltfAnimation *anim = nullptr ); + void Advance( gltfAnimation* anim = nullptr ); //this copies the data and view cached on the accessor template - idList &GetAccessorView( gltfAccessor *accessor ); - idList &GetAccessorView( gltfAccessor *accessor ); - idList &GetAccessorViewMat( gltfAccessor *accessor ); + idList& GetAccessorView( gltfAccessor* accessor ); + idList& GetAccessorView( gltfAccessor* accessor ); + idList& GetAccessorViewMat( gltfAccessor* accessor ); - int &DefaultScene( ) { return scene; } + int& DefaultScene( ) + { + return scene; + } GLTFCACHEITEM( Buffer, buffers ) GLTFCACHEITEM( Sampler, samplers ) GLTFCACHEITEM( BufferView, bufferViews ) @@ -805,34 +950,34 @@ public: GLTFCACHEITEM( Extensions, extensions ) GLTFCACHEITEM( Animation, animations ) GLTFCACHEITEM( Skin, skins ) - + //gltfCameraManager * cameraManager; private: idStr fileName; int fileNameHash; - byte *json; - byte **data; + byte* json; + byte** data; int jsonDataLength; int totalChunks; - idList buffers; - idList images; - idList assetData; - idList samplers; - idList bufferViews; - idList textures; - idList accessors; - idList extensionsUsed; - idList meshes; + idList buffers; + idList images; + idList assetData; + idList samplers; + idList bufferViews; + idList textures; + idList accessors; + idList extensionsUsed; + idList meshes; int scene; - idList scenes; - idList nodes; - idList cameras; - idList materials; - idList extensions; - idList animations; - idList skins; + idList scenes; + idList nodes; + idList cameras; + idList materials; + idList extensions; + idList animations; + idList skins; }; #undef GLTFCACHEITEM \ No newline at end of file diff --git a/neo/renderer/ModelManager.cpp b/neo/renderer/ModelManager.cpp index 9f2ffdcf..ac22c360 100644 --- a/neo/renderer/ModelManager.cpp +++ b/neo/renderer/ModelManager.cpp @@ -357,14 +357,15 @@ idRenderModel* idRenderModelManagerLocal::GetModel( const char* _modelName, bool idRenderModel* model = NULL; // HvG: GLTF 2 support - if ( (extension.Icmp( GLTF_GLB_EXT ) == 0 ) ||( extension.Icmp( GLTF_EXT ) == 0 )) + if( ( extension.Icmp( GLTF_GLB_EXT ) == 0 ) || ( extension.Icmp( GLTF_EXT ) == 0 ) ) { model = new( TAG_MODEL ) idRenderModelGLTF; - - // RB: Collada DAE and Wavefront OBJ - }else if ( ( extension.Icmp( "dae" ) == 0 ) || ( extension.Icmp( "obj" ) == 0 ) // RB: Collada DAE and Wavefront OBJ - || ( extension.Icmp( "ase" ) == 0 ) || ( extension.Icmp( "lwo" ) == 0 ) - || ( extension.Icmp( "flt" ) == 0 ) || ( extension.Icmp( "ma" ) == 0 ) ) + + // RB: Collada DAE and Wavefront OBJ + } + else if( ( extension.Icmp( "dae" ) == 0 ) || ( extension.Icmp( "obj" ) == 0 ) // RB: Collada DAE and Wavefront OBJ + || ( extension.Icmp( "ase" ) == 0 ) || ( extension.Icmp( "lwo" ) == 0 ) + || ( extension.Icmp( "flt" ) == 0 ) || ( extension.Icmp( "ma" ) == 0 ) ) { model = new( TAG_MODEL ) idRenderModelStatic; } diff --git a/neo/renderer/Model_gltf.cpp b/neo/renderer/Model_gltf.cpp index 3ea0faed..1f8554d0 100644 --- a/neo/renderer/Model_gltf.cpp +++ b/neo/renderer/Model_gltf.cpp @@ -8,7 +8,8 @@ -bool idRenderModelStatic::ConvertGltfMeshToModelsurfaces( const gltfMesh *mesh ) { +bool idRenderModelStatic::ConvertGltfMeshToModelsurfaces( const gltfMesh* mesh ) +{ //for ( auto mesh : currentAsset->MeshList( ) ) { // for ( auto prim : mesh->primitives ) { @@ -16,30 +17,37 @@ bool idRenderModelStatic::ConvertGltfMeshToModelsurfaces( const gltfMesh *mesh ) return false; } -void MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh *_mesh, gltfData *data ) { - for ( auto* gltfMesh : data->MeshList( ) ) { - for ( auto prim : gltfMesh->primitives ) { - common->Printf("primitive for %s\n",gltfMesh->name.c_str() ); +void MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh* _mesh, gltfData* data ) +{ + for( auto* gltfMesh : data->MeshList( ) ) + { + for( auto prim : gltfMesh->primitives ) + { + common->Printf( "primitive for %s\n", gltfMesh->name.c_str() ); - gltfAccessor *accessor = data->AccessorList( )[prim->indices]; - gltfBufferView *bv = data->BufferViewList( )[accessor->bufferView]; - gltfData *data = bv->parent; + gltfAccessor* accessor = data->AccessorList( )[prim->indices]; + gltfBufferView* bv = data->BufferViewList( )[accessor->bufferView]; + gltfData* data = bv->parent; - gltfBuffer *buff = data->BufferList( )[bv->buffer]; + gltfBuffer* buff = data->BufferList( )[bv->buffer]; uint idxDataSize = sizeof( uint ) * accessor->count; - uint *indices = ( uint * ) Mem_ClearedAlloc( idxDataSize , TAG_IDLIB_GLTF); + uint* indices = ( uint* ) Mem_ClearedAlloc( idxDataSize , TAG_IDLIB_GLTF ); idFile_Memory idxBin = idFile_Memory( "gltfChunkIndices", - ( const char * ) ( ( data->GetData( bv->buffer ) + bv->byteOffset + accessor->byteOffset ) ), bv->byteLength ); + ( const char* )( ( data->GetData( bv->buffer ) + bv->byteOffset + accessor->byteOffset ) ), bv->byteLength ); - for ( int i = 0; i < accessor->count; i++ ) { - idxBin.Read( ( void * ) ( &indices[i] ), accessor->typeSize ); - if ( bv->byteStride ) + for( int i = 0; i < accessor->count; i++ ) + { + idxBin.Read( ( void* )( &indices[i] ), accessor->typeSize ); + if( bv->byteStride ) + { idxBin.Seek( bv->byteStride - accessor->typeSize, FS_SEEK_CUR ); + } } - - for ( int i = 0; i < accessor->count; i+=3 ) { - MapPolygon &polygon = polygons.Alloc( ); + + for( int i = 0; i < accessor->count; i += 3 ) + { + MapPolygon& polygon = polygons.Alloc( ); polygon.SetMaterial( "textures/base_wall/lfwall27d" ); polygon.AddIndex( indices[i + 1] ); polygon.AddIndex( indices[i + 2] ); @@ -49,417 +57,514 @@ void MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh *_mesh, gltfData *data Mem_Free( indices ); bool sizeSet = false; - for ( auto &attrib : prim->attributes ) { - gltfAccessor *attrAcc = data->AccessorList( )[attrib->accessorIndex]; - gltfBufferView *attrBv = data->BufferViewList( )[attrAcc->bufferView]; - gltfData *attrData = attrBv->parent; - gltfBuffer *attrbuff = attrData->BufferList( )[attrBv->buffer]; + for( auto& attrib : prim->attributes ) + { + gltfAccessor* attrAcc = data->AccessorList( )[attrib->accessorIndex]; + gltfBufferView* attrBv = data->BufferViewList( )[attrAcc->bufferView]; + gltfData* attrData = attrBv->parent; + gltfBuffer* attrbuff = attrData->BufferList( )[attrBv->buffer]; idFile_Memory bin = idFile_Memory( "gltfChunkVertices", - ( const char * ) ( ( attrData->GetData( attrBv->buffer ) + attrBv->byteOffset + attrAcc->byteOffset ) ), attrBv->byteLength ); + ( const char* )( ( attrData->GetData( attrBv->buffer ) + attrBv->byteOffset + attrAcc->byteOffset ) ), attrBv->byteLength ); - if ( !sizeSet ) + if( !sizeSet ) { verts.AssureSize( attrAcc->count ); sizeSet = true; } - switch ( attrib->type ) { - case gltfMesh_Primitive_Attribute::Type::Position: + switch( attrib->type ) { - for ( int i = attrAcc->count-1; i >= 0; i-- ) { - bin.Read( ( void * ) ( &verts[i].xyz.x ), attrAcc->typeSize ); - bin.Read( ( void * ) ( &verts[i].xyz.y ), attrAcc->typeSize ); - bin.Read( ( void * ) ( &verts[i].xyz.z ), attrAcc->typeSize ); - if ( attrBv->byteStride ) - bin.Seek( attrBv->byteStride - ( 3 * attrAcc->typeSize ), FS_SEEK_CUR ); + case gltfMesh_Primitive_Attribute::Type::Position: + { + for( int i = attrAcc->count - 1; i >= 0; i-- ) + { + idVec3 pos; - idRandom rnd( i ); - int r = rnd.RandomInt( 255 ), g = rnd.RandomInt( 255 ), b = rnd.RandomInt( 255 ); + bin.Read( ( void* )( &pos.x ), attrAcc->typeSize ); + bin.Read( ( void* )( &pos.y ), attrAcc->typeSize ); + bin.Read( ( void* )( &pos.z ), attrAcc->typeSize ); - //vtxData[i].abgr = 0xff000000 + ( b << 16 ) + ( g << 8 ) + r; + verts[i].xyz = pos; + + if( attrBv->byteStride ) + { + bin.Seek( attrBv->byteStride - ( 3 * attrAcc->typeSize ), FS_SEEK_CUR ); + } + + idRandom rnd( i ); + int r = rnd.RandomInt( 255 ), g = rnd.RandomInt( 255 ), b = rnd.RandomInt( 255 ); + + //vtxData[i].abgr = 0xff000000 + ( b << 16 ) + ( g << 8 ) + r; + } + + break; } - - break; - } - case gltfMesh_Primitive_Attribute::Type::Normal: - { - idVec3 vec; - for ( int i = 0; i < attrAcc->count; i++ ) { + case gltfMesh_Primitive_Attribute::Type::Normal: + { idVec3 vec; - bin.Read( ( void * ) ( &vec.x ), attrAcc->typeSize ); - bin.Read( ( void * ) ( &vec.y ), attrAcc->typeSize ); - bin.Read( ( void * ) ( &vec.z ), attrAcc->typeSize ); - if ( attrBv->byteStride ) - bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR ); - verts[i].SetNormal(vec); - } + for( int i = 0; i < attrAcc->count; i++ ) + { + idVec3 vec; + bin.Read( ( void* )( &vec.x ), attrAcc->typeSize ); + bin.Read( ( void* )( &vec.y ), attrAcc->typeSize ); + bin.Read( ( void* )( &vec.z ), attrAcc->typeSize ); + if( attrBv->byteStride ) + { + bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR ); + } + verts[i].SetNormal( vec ); + } - break; - } - case gltfMesh_Primitive_Attribute::Type::TexCoord0: - { - idVec2 vec; - for ( int i = 0; i < attrAcc->count; i++ ) { - bin.Read( ( void * ) ( &vec.x ), attrAcc->typeSize ); - bin.Read( ( void * ) ( &vec.y ), attrAcc->typeSize ); - if ( attrBv->byteStride ) - bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR ); - verts[i].SetTexCoord(vec); + break; } + case gltfMesh_Primitive_Attribute::Type::TexCoord0: + { + idVec2 vec; + for( int i = 0; i < attrAcc->count; i++ ) + { + bin.Read( ( void* )( &vec.x ), attrAcc->typeSize ); + bin.Read( ( void* )( &vec.y ), attrAcc->typeSize ); + if( attrBv->byteStride ) + { + bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR ); + } + verts[i].SetTexCoord( vec ); + } - break; - } - case gltfMesh_Primitive_Attribute::Type::Tangent: - { - idVec4 vec; - for ( int i = 0; i < attrAcc->count; i++ ) { - bin.Read( ( void * ) ( &vec.x ), attrAcc->typeSize ); - bin.Read( ( void * ) ( &vec.y ), attrAcc->typeSize ); - bin.Read( ( void * ) ( &vec.z ), attrAcc->typeSize ); - bin.Read( ( void * ) ( &vec.w ), attrAcc->typeSize ); - if ( attrBv->byteStride ) - bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR ); - verts[i].SetTangent(vec.ToVec3()); - verts[i].SetBiTangentSign(vec.w); + break; } - break; + case gltfMesh_Primitive_Attribute::Type::Tangent: + { + idVec4 vec; + for( int i = 0; i < attrAcc->count; i++ ) + { + bin.Read( ( void* )( &vec.x ), attrAcc->typeSize ); + bin.Read( ( void* )( &vec.y ), attrAcc->typeSize ); + bin.Read( ( void* )( &vec.z ), attrAcc->typeSize ); + bin.Read( ( void* )( &vec.w ), attrAcc->typeSize ); + if( attrBv->byteStride ) + { + bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR ); + } + verts[i].SetTangent( vec.ToVec3() ); + verts[i].SetBiTangentSign( vec.w ); + } + break; + } + //case gltfMesh_Primitive_Attribute::Type::Weight: + //{ + // for ( int i = 0; i < attrAcc->count; i++ ) { + // bin.Read( ( void * ) ( &vtxData[i].weight.x ), attrAcc->typeSize ); + // bin.Read( ( void * ) ( &vtxData[i].weight.y ), attrAcc->typeSize ); + // bin.Read( ( void * ) ( &vtxData[i].weight.z ), attrAcc->typeSize ); + // bin.Read( ( void * ) ( &vtxData[i].weight.w ), attrAcc->typeSize ); + // if ( attrBv->byteStride ) + // bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR ); + // } + // break; + //} + //case gltfMesh_Primitive_Attribute::Type::Indices: + //{ + // for ( int i = 0; i < attrAcc->count; i++ ) { + // bin.Read( ( void * ) ( &vtxData[i].boneIndex.x ), attrAcc->typeSize ); + // bin.Read( ( void * ) ( &vtxData[i].boneIndex.y ), attrAcc->typeSize ); + // bin.Read( ( void * ) ( &vtxData[i].boneIndex.z ), attrAcc->typeSize ); + // bin.Read( ( void * ) ( &vtxData[i].boneIndex.w ), attrAcc->typeSize ); + // if ( attrBv->byteStride ) + // bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR ); + // } + // break; + //} } - //case gltfMesh_Primitive_Attribute::Type::Weight: - //{ - // for ( int i = 0; i < attrAcc->count; i++ ) { - // bin.Read( ( void * ) ( &vtxData[i].weight.x ), attrAcc->typeSize ); - // bin.Read( ( void * ) ( &vtxData[i].weight.y ), attrAcc->typeSize ); - // bin.Read( ( void * ) ( &vtxData[i].weight.z ), attrAcc->typeSize ); - // bin.Read( ( void * ) ( &vtxData[i].weight.w ), attrAcc->typeSize ); - // if ( attrBv->byteStride ) - // bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR ); - // } - // break; - //} - //case gltfMesh_Primitive_Attribute::Type::Indices: - //{ - // for ( int i = 0; i < attrAcc->count; i++ ) { - // bin.Read( ( void * ) ( &vtxData[i].boneIndex.x ), attrAcc->typeSize ); - // bin.Read( ( void * ) ( &vtxData[i].boneIndex.y ), attrAcc->typeSize ); - // bin.Read( ( void * ) ( &vtxData[i].boneIndex.z ), attrAcc->typeSize ); - // bin.Read( ( void * ) ( &vtxData[i].boneIndex.w ), attrAcc->typeSize ); - // if ( attrBv->byteStride ) - // bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR ); - // } - // break; - //} - } - + } } } SetContents(); } -int idMapEntity::GetEntities( gltfData * data, EntityListRef entities, int sceneID ) { +int idMapEntity::GetEntities( gltfData* data, EntityListRef entities, int sceneID ) +{ + idMapEntity* worldspawn = new idMapEntity(); + entities.Append( worldspawn ); + int entityCount = 0; - for ( auto & nodeID : data->SceneList()[sceneID]->nodes ) + for( auto& nodeID : data->SceneList()[sceneID]->nodes ) { - auto * node = data->NodeList()[nodeID]; - auto * newEntity = new idMapEntity( ); + auto* node = data->NodeList()[nodeID]; - bool isWorldSpawn = false; + idMapEntity* newEntity = NULL; - //set name and retrieve epairs from node extras - if ( node->name.Length() ) - newEntity->epairs.Set( "name", node->name); - newEntity->epairs.Copy(node->extras.strPairs); - - isWorldSpawn = idStr::Icmp(newEntity->epairs.GetString( "classname" ), "worldspawn" ) == 0; - - if ( isWorldSpawn ) - newEntity->primitives.Resize( 1024, 256 ); - - //check for primitive type - idStr primType = newEntity->epairs.GetString( "PrimitiveType" ); - if ( primType.Length() ) + bool isWorldSpawn = idStr::Icmp( node->extras.strPairs.GetString( "classname" ), "worldspawn" ) == 0; + if( isWorldSpawn ) { - if ( primType.Icmp( "BrushDef3" ) == 0 ) // change to MapMesh/Primitive + worldspawn->primitives.Resize( 1024, 256 ); + worldspawn->epairs.Copy( node->extras.strPairs ); + } + else + { + // account all meshes starting with worldspawn. or BSP in the name + if( idStr::Icmpn( node->name, "BSP", 3 ) == 0 || idStr::Icmpn( node->name, "worldspawn.", 11 ) == 0 ) { - MapPolygonMesh *meshPrim = new MapPolygonMesh( ); - meshPrim->epairs.Copy( newEntity->epairs ); + MapPolygonMesh* meshPrim = new MapPolygonMesh(); + //meshPrim->epairs.Copy( newEntity->epairs ); - meshPrim->ConvertFromMeshGltf(data->MeshList()[node->mesh],data); - newEntity->AddPrimitive(meshPrim); + meshPrim->ConvertFromMeshGltf( data->MeshList()[node->mesh], data ); + worldspawn->AddPrimitive( meshPrim ); + } + else + { + newEntity = new idMapEntity(); + + // set name and retrieve epairs from node extras + if( node->name.Length() ) + { + newEntity->epairs.Set( "name", node->name ); + } + newEntity->epairs.Copy( node->extras.strPairs ); + + for( int i = 0; i < newEntity->epairs.GetNumKeyVals(); i++ ) + { + const idKeyValue* kv = newEntity->epairs.GetKeyVal( i ); + + idLib::Printf( "entity[ %s ] key = '%s' value = '%s'\n", node->name.c_str(), kv->GetKey().c_str(), kv->GetValue().c_str() ); + } + + data->ResolveNodeMatrix( node ); + newEntity->epairs.Set( "origin", node->translation.ToString() ); + + common->Printf( " %s \n ", node->name.c_str( ) ); + entities.Append( newEntity ); + + entityCount++; } } - data->ResolveNodeMatrix(node); - newEntity->epairs.Set( "origin", node->translation.ToString()); - common->Printf(" %s \n ", node->name.c_str( ) ); - entities.Append(newEntity); - - entityCount++; } - if ( entities.Num( ) > 0 && ( idStr::Icmp( entities[0]->epairs.GetString( "name" ), "worldspawn" ) != 0 ) ) { + /* + if( entities.Num( ) > 0 && ( idStr::Icmp( entities[0]->epairs.GetString( "name" ), "worldspawn" ) != 0 ) ) + { // move world spawn to first place - for ( int i = 1; i < entities.Num( ); i++ ) { - if ( idStr::Icmp( entities[i]->epairs.GetString( "name" ), "worldspawn" ) == 0 ) { - idMapEntity *tmp = entities[0]; + for( int i = 1; i < entities.Num( ); i++ ) + { + if( idStr::Icmp( entities[i]->epairs.GetString( "name" ), "worldspawn" ) == 0 ) + { + idMapEntity* tmp = entities[0]; entities[0] = entities[i]; entities[i] = tmp; break; } } } + */ return entityCount; } // [filename].[%i|%s].[gltf/glb] -bool gltfManager::ExtractMeshIdentifier( idStr &filename, int &meshId, idStr &meshName ) { +bool gltfManager::ExtractMeshIdentifier( idStr& filename, int& meshId, idStr& meshName ) +{ idStr extension; - filename.ExtractFileExtension(extension); + filename.ExtractFileExtension( extension ); - idStr idPart = filename.Left(filename.Length()-extension.Length()-1); + idStr idPart = filename.Left( filename.Length() - extension.Length() - 1 ); idStr id; - idPart.ExtractFileExtension(id); - - if ( !id.Length() ) + idPart.ExtractFileExtension( id ); + + if( !id.Length() ) { - idLib::Warning( "no gltf mesh identifier"); + idLib::Warning( "no gltf mesh identifier" ); return false; } - filename = idPart.Left(idPart.Length()-id.Length()) + extension; + filename = idPart.Left( idPart.Length() - id.Length() ) + extension; idLexer lexer( LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS ); lexer.LoadMemory( id.c_str( ), id.Size( ), "GltfmeshID", 0 ); idToken token; - if (lexer.ExpectAnyToken(&token)) + if( lexer.ExpectAnyToken( &token ) ) { - if (lexer.EndOfFile() && (token.type == TT_NUMBER) && (token.subtype & TT_INTEGER) ) + if( lexer.EndOfFile() && ( token.type == TT_NUMBER ) && ( token.subtype & TT_INTEGER ) ) + { meshId = token.GetIntValue(); - else if (token.type == TT_NUMBER || token.type == TT_STRING ) + } + else if( token.type == TT_NUMBER || token.type == TT_STRING ) + { meshName = id; - else { - lexer.Warning("malformed gltf mesh identifier" ); + } + else + { + lexer.Warning( "malformed gltf mesh identifier" ); return false; } return true; - }else - lexer.Warning("malformed gltf mesh identifier" ); + } + else + { + lexer.Warning( "malformed gltf mesh identifier" ); + } return false; } -void idRenderModelGLTF::InitFromFile( const char *fileName ) { +void idRenderModelGLTF::InitFromFile( const char* fileName ) +{ common->Warning( "The method or operation is not implemented." ); } -bool idRenderModelGLTF::LoadBinaryModel( idFile *file, const ID_TIME_T sourceTimeStamp ) { +bool idRenderModelGLTF::LoadBinaryModel( idFile* file, const ID_TIME_T sourceTimeStamp ) +{ common->Warning( "The method or operation is not implemented." ); return false; } -void idRenderModelGLTF::WriteBinaryModel( idFile *file, ID_TIME_T *_timeStamp /*= NULL */ ) const { +void idRenderModelGLTF::WriteBinaryModel( idFile* file, ID_TIME_T* _timeStamp /*= NULL */ ) const +{ common->Warning( "The method or operation is not implemented." ); } -bool idRenderModelGLTF::SupportsBinaryModel( ) { +bool idRenderModelGLTF::SupportsBinaryModel( ) +{ common->Warning( "The method or operation is not implemented." ); return false; } -void idRenderModelGLTF::ExportOBJ( idFile *objFile, idFile *mtlFile, ID_TIME_T *_timeStamp /*= NULL */ ) { +void idRenderModelGLTF::ExportOBJ( idFile* objFile, idFile* mtlFile, ID_TIME_T* _timeStamp /*= NULL */ ) +{ common->Warning( "The method or operation is not implemented." ); } -void idRenderModelGLTF::PartialInitFromFile( const char *fileName ) { +void idRenderModelGLTF::PartialInitFromFile( const char* fileName ) +{ common->Warning( "The method or operation is not implemented." ); } -void idRenderModelGLTF::PurgeModel( ) { +void idRenderModelGLTF::PurgeModel( ) +{ common->Warning( "The method or operation is not implemented." ); } -void idRenderModelGLTF::Reset( ) { +void idRenderModelGLTF::Reset( ) +{ common->Warning( "The method or operation is not implemented." ); } -void idRenderModelGLTF::LoadModel( ) { +void idRenderModelGLTF::LoadModel( ) +{ common->Warning( "The method or operation is not implemented." ); } -bool idRenderModelGLTF::IsLoaded( ) { +bool idRenderModelGLTF::IsLoaded( ) +{ common->Warning( "The method or operation is not implemented." ); return false; } -void idRenderModelGLTF::SetLevelLoadReferenced( bool referenced ) { +void idRenderModelGLTF::SetLevelLoadReferenced( bool referenced ) +{ common->Warning( "The method or operation is not implemented." ); } -bool idRenderModelGLTF::IsLevelLoadReferenced( ) { +bool idRenderModelGLTF::IsLevelLoadReferenced( ) +{ common->Warning( "The method or operation is not implemented." ); return false; } -void idRenderModelGLTF::TouchData( ) { +void idRenderModelGLTF::TouchData( ) +{ common->Warning( "The method or operation is not implemented." ); } -void idRenderModelGLTF::CreateBuffers( nvrhi::ICommandList *commandList ) { +void idRenderModelGLTF::CreateBuffers( nvrhi::ICommandList* commandList ) +{ common->Warning( "The method or operation is not implemented." ); } -void idRenderModelGLTF::InitEmpty( const char *name ) { +void idRenderModelGLTF::InitEmpty( const char* name ) +{ common->Warning( "The method or operation is not implemented." ); } -void idRenderModelGLTF::AddSurface( modelSurface_t surface ) { +void idRenderModelGLTF::AddSurface( modelSurface_t surface ) +{ common->Warning( "The method or operation is not implemented." ); } -void idRenderModelGLTF::FinishSurfaces( bool useMikktspace ) { +void idRenderModelGLTF::FinishSurfaces( bool useMikktspace ) +{ common->Warning( "The method or operation is not implemented." ); } -void idRenderModelGLTF::FreeVertexCache( ) { +void idRenderModelGLTF::FreeVertexCache( ) +{ common->Warning( "The method or operation is not implemented." ); } -const char *idRenderModelGLTF::Name( ) const { +const char* idRenderModelGLTF::Name( ) const +{ common->Warning( "The method or operation is not implemented." ); return ""; } -void idRenderModelGLTF::Print( ) const { +void idRenderModelGLTF::Print( ) const +{ common->Warning( "The method or operation is not implemented." ); } -void idRenderModelGLTF::List( ) const { +void idRenderModelGLTF::List( ) const +{ common->Warning( "The method or operation is not implemented." ); } -int idRenderModelGLTF::Memory( ) const { +int idRenderModelGLTF::Memory( ) const +{ common->Warning( "The method or operation is not implemented." ); return -1; } -ID_TIME_T idRenderModelGLTF::Timestamp( ) const { +ID_TIME_T idRenderModelGLTF::Timestamp( ) const +{ common->Warning( "The method or operation is not implemented." ); return FILE_NOT_FOUND_TIMESTAMP; } -int idRenderModelGLTF::NumSurfaces( ) const { +int idRenderModelGLTF::NumSurfaces( ) const +{ common->Warning( "The method or operation is not implemented." ); return -1; } -int idRenderModelGLTF::NumBaseSurfaces( ) const { +int idRenderModelGLTF::NumBaseSurfaces( ) const +{ common->Warning( "The method or operation is not implemented." ); return -1; } -const modelSurface_t *idRenderModelGLTF::Surface( int surfaceNum ) const { +const modelSurface_t* idRenderModelGLTF::Surface( int surfaceNum ) const +{ common->Warning( "The method or operation is not implemented." ); return nullptr; } -srfTriangles_t *idRenderModelGLTF::AllocSurfaceTriangles( int numVerts, int numIndexes ) const { +srfTriangles_t* idRenderModelGLTF::AllocSurfaceTriangles( int numVerts, int numIndexes ) const +{ common->Warning( "The method or operation is not implemented." ); return nullptr; } -void idRenderModelGLTF::FreeSurfaceTriangles( srfTriangles_t *tris ) const { +void idRenderModelGLTF::FreeSurfaceTriangles( srfTriangles_t* tris ) const +{ common->Warning( "The method or operation is not implemented." ); } -bool idRenderModelGLTF::IsStaticWorldModel( ) const { +bool idRenderModelGLTF::IsStaticWorldModel( ) const +{ common->Warning( "The method or operation is not implemented." ); return false; } -dynamicModel_t idRenderModelGLTF::IsDynamicModel( ) const { +dynamicModel_t idRenderModelGLTF::IsDynamicModel( ) const +{ common->Warning( "The method or operation is not implemented." ); return dynamicModel_t(); } -bool idRenderModelGLTF::IsDefaultModel( ) const { +bool idRenderModelGLTF::IsDefaultModel( ) const +{ common->Warning( "The method or operation is not implemented." ); return false; } -bool idRenderModelGLTF::IsReloadable( ) const { +bool idRenderModelGLTF::IsReloadable( ) const +{ common->Warning( "The method or operation is not implemented." ); return false; } -idRenderModel *idRenderModelGLTF::InstantiateDynamicModel( const struct renderEntity_s *ent, const viewDef_t *view, idRenderModel *cachedModel ) { +idRenderModel* idRenderModelGLTF::InstantiateDynamicModel( const struct renderEntity_s* ent, const viewDef_t* view, idRenderModel* cachedModel ) +{ common->Warning( "The method or operation is not implemented." ); return nullptr; } -int idRenderModelGLTF::NumJoints( ) const { +int idRenderModelGLTF::NumJoints( ) const +{ common->Warning( "The method or operation is not implemented." ); return 0; } -const idMD5Joint *idRenderModelGLTF::GetJoints( ) const { +const idMD5Joint* idRenderModelGLTF::GetJoints( ) const +{ common->Warning( "The method or operation is not implemented." ); return nullptr; } -jointHandle_t idRenderModelGLTF::GetJointHandle( const char *name ) const { +jointHandle_t idRenderModelGLTF::GetJointHandle( const char* name ) const +{ common->Warning( "The method or operation is not implemented." ); return jointHandle_t(); } -const char *idRenderModelGLTF::GetJointName( jointHandle_t handle ) const { +const char* idRenderModelGLTF::GetJointName( jointHandle_t handle ) const +{ common->Warning( "The method or operation is not implemented." ); return ""; } -const idJointQuat *idRenderModelGLTF::GetDefaultPose( ) const { +const idJointQuat* idRenderModelGLTF::GetDefaultPose( ) const +{ common->Warning( "The method or operation is not implemented." ); return nullptr; } -int idRenderModelGLTF::NearestJoint( int surfaceNum, int a, int b, int c ) const { +int idRenderModelGLTF::NearestJoint( int surfaceNum, int a, int b, int c ) const +{ common->Warning( "The method or operation is not implemented." ); return -1; } -idBounds idRenderModelGLTF::Bounds( const struct renderEntity_s *ent ) const { +idBounds idRenderModelGLTF::Bounds( const struct renderEntity_s* ent ) const +{ common->Warning( "The method or operation is not implemented." ); return idBounds(); } -void idRenderModelGLTF::ReadFromDemoFile( class idDemoFile *f ) { +void idRenderModelGLTF::ReadFromDemoFile( class idDemoFile* f ) +{ common->Warning( "The method or operation is not implemented." ); } -void idRenderModelGLTF::WriteToDemoFile( class idDemoFile *f ) { +void idRenderModelGLTF::WriteToDemoFile( class idDemoFile* f ) +{ common->Warning( "The method or operation is not implemented." ); } -float idRenderModelGLTF::DepthHack( ) const { +float idRenderModelGLTF::DepthHack( ) const +{ common->Warning( "The method or operation is not implemented." ); return -1.0f; } -bool idRenderModelGLTF::ModelHasDrawingSurfaces( ) const { +bool idRenderModelGLTF::ModelHasDrawingSurfaces( ) const +{ common->Warning( "The method or operation is not implemented." ); return false; } -bool idRenderModelGLTF::ModelHasInteractingSurfaces( ) const { +bool idRenderModelGLTF::ModelHasInteractingSurfaces( ) const +{ common->Warning( "The method or operation is not implemented." ); return false; } -bool idRenderModelGLTF::ModelHasShadowCastingSurfaces( ) const { +bool idRenderModelGLTF::ModelHasShadowCastingSurfaces( ) const +{ common->Warning( "The method or operation is not implemented." ); return false; } diff --git a/neo/renderer/Model_gltf.h b/neo/renderer/Model_gltf.h index 25fdda89..353c0d51 100644 --- a/neo/renderer/Model_gltf.h +++ b/neo/renderer/Model_gltf.h @@ -1,30 +1,31 @@ #pragma once #include "Model_local.h" -class gltfManager { -public: - static bool ExtractMeshIdentifier(idStr& filename , int & meshId, idStr & meshName ); -}; - -class idGltfMesh +class gltfManager { public: - idGltfMesh(gltfMesh * _mesh, gltfData * _data) : mesh(_mesh),data(_data){}; + static bool ExtractMeshIdentifier( idStr& filename , int& meshId, idStr& meshName ); +}; + +class idGltfMesh +{ +public: + idGltfMesh( gltfMesh* _mesh, gltfData* _data ) : mesh( _mesh ), data( _data ) {}; private: - gltfMesh * mesh; - gltfData * data; + gltfMesh* mesh; + gltfData* data; }; class idRenderModelGLTF : public idRenderModelStatic { public: - void InitFromFile( const char *fileName ) override; - bool LoadBinaryModel( idFile *file, const ID_TIME_T sourceTimeStamp ) override; - void WriteBinaryModel( idFile *file, ID_TIME_T *_timeStamp = NULL ) const override; + void InitFromFile( const char* fileName ) override; + bool LoadBinaryModel( idFile* file, const ID_TIME_T sourceTimeStamp ) override; + void WriteBinaryModel( idFile* file, ID_TIME_T* _timeStamp = NULL ) const override; bool SupportsBinaryModel( ) override; - void ExportOBJ( idFile *objFile, idFile *mtlFile, ID_TIME_T *_timeStamp = NULL ) override; - void PartialInitFromFile( const char *fileName ) override; + void ExportOBJ( idFile* objFile, idFile* mtlFile, ID_TIME_T* _timeStamp = NULL ) override; + void PartialInitFromFile( const char* fileName ) override; void PurgeModel( ) override; void Reset( ) override; void LoadModel( ) override; @@ -32,35 +33,35 @@ public: void SetLevelLoadReferenced( bool referenced ) override; bool IsLevelLoadReferenced( ) override; void TouchData( ) override; - void CreateBuffers( nvrhi::ICommandList *commandList ) override; - void InitEmpty( const char *name ) override; + void CreateBuffers( nvrhi::ICommandList* commandList ) override; + void InitEmpty( const char* name ) override; void AddSurface( modelSurface_t surface ) override; void FinishSurfaces( bool useMikktspace ) override; void FreeVertexCache( ) override; - const char *Name( ) const override; + const char* Name( ) const override; void Print( ) const override; void List( ) const override; int Memory( ) const override; ID_TIME_T Timestamp( ) const override; int NumSurfaces( ) const override; int NumBaseSurfaces( ) const override; - const modelSurface_t *Surface( int surfaceNum ) const override; - srfTriangles_t *AllocSurfaceTriangles( int numVerts, int numIndexes ) const override; - void FreeSurfaceTriangles( srfTriangles_t *tris ) const override; + const modelSurface_t* Surface( int surfaceNum ) const override; + srfTriangles_t* AllocSurfaceTriangles( int numVerts, int numIndexes ) const override; + void FreeSurfaceTriangles( srfTriangles_t* tris ) const override; bool IsStaticWorldModel( ) const override; dynamicModel_t IsDynamicModel( ) const override; bool IsDefaultModel( ) const override; bool IsReloadable( ) const override; - idRenderModel *InstantiateDynamicModel( const struct renderEntity_s *ent, const viewDef_t *view, idRenderModel *cachedModel ) override; + idRenderModel* InstantiateDynamicModel( const struct renderEntity_s* ent, const viewDef_t* view, idRenderModel* cachedModel ) override; int NumJoints( ) const override; - const idMD5Joint *GetJoints( ) const override; - jointHandle_t GetJointHandle( const char *name ) const override; - const char *GetJointName( jointHandle_t handle ) const override; - const idJointQuat *GetDefaultPose( ) const override; + const idMD5Joint* GetJoints( ) const override; + jointHandle_t GetJointHandle( const char* name ) const override; + const char* GetJointName( jointHandle_t handle ) const override; + const idJointQuat* GetDefaultPose( ) const override; int NearestJoint( int surfaceNum, int a, int b, int c ) const override; - idBounds Bounds( const struct renderEntity_s *ent ) const override; - void ReadFromDemoFile( class idDemoFile *f ) override; - void WriteToDemoFile( class idDemoFile *f ) override; + idBounds Bounds( const struct renderEntity_s* ent ) const override; + void ReadFromDemoFile( class idDemoFile* f ) override; + void WriteToDemoFile( class idDemoFile* f ) override; float DepthHack( ) const override; bool ModelHasDrawingSurfaces( ) const override; bool ModelHasInteractingSurfaces( ) const override; diff --git a/neo/renderer/Model_local.h b/neo/renderer/Model_local.h index adfed068..b61aeb1f 100644 --- a/neo/renderer/Model_local.h +++ b/neo/renderer/Model_local.h @@ -130,8 +130,8 @@ public: bool ConvertASEToModelSurfaces( const struct aseModel_s* ase ); bool ConvertLWOToModelSurfaces( const struct st_lwObject* lwo ); bool ConvertMAToModelSurfaces( const struct maModel_s* ma ); - bool ConvertGltfMeshToModelsurfaces( const gltfMesh * mesh); - + bool ConvertGltfMeshToModelsurfaces( const gltfMesh* mesh ); + struct aseModel_s* ConvertLWOToASE( const struct st_lwObject* obj, const char* fileName ); bool DeleteSurfaceWithId( int id );