mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-06-02 01:31:45 +00:00
gltf2 -> idMapFile fixes. dmap and map commands work
# Conflicts: # neo/idlib/containers/List.h
This commit is contained in:
parent
50bb904e22
commit
24845c7edf
14 changed files with 1823 additions and 1134 deletions
|
@ -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 ) )
|
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 ) )
|
ID_INLINE void idCmdSystem::ArgCompletion_MapNameNoJson( const idCmdArgs& args, void( *callback )( const char* s ) )
|
||||||
|
|
|
@ -1507,31 +1507,43 @@ Skips until a matching close brace is found.
|
||||||
Internal brace depths are properly skipped.
|
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;
|
idToken token;
|
||||||
int depth;
|
int depth;
|
||||||
idStr openTokens[2] = { "{" , "[" };
|
idStr openTokens[2] = { "{" , "[" };
|
||||||
idStr closeTokens[2] = { "}" , "]" };
|
idStr closeTokens[2] = { "}" , "]" };
|
||||||
|
|
||||||
if ( skipped != nullptr )
|
if( skipped != nullptr )
|
||||||
|
{
|
||||||
*skipped = 0;
|
*skipped = 0;
|
||||||
|
}
|
||||||
|
|
||||||
int scopeCount = 0;
|
int scopeCount = 0;
|
||||||
depth = parseFirstBrace ? 0 : 1;
|
depth = parseFirstBrace ? 0 : 1;
|
||||||
do {
|
do
|
||||||
if ( !ReadToken( &token ) ) {
|
{
|
||||||
|
if( !ReadToken( &token ) )
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ( token.type == TT_PUNCTUATION ) {
|
if( token.type == TT_PUNCTUATION )
|
||||||
if ( token == openTokens[skipMode] ) {
|
{
|
||||||
|
if( token == openTokens[skipMode] )
|
||||||
|
{
|
||||||
depth++;
|
depth++;
|
||||||
if ( skipped != nullptr )
|
if( skipped != nullptr )
|
||||||
(*skipped)++;
|
{
|
||||||
} else if ( token == closeTokens[skipMode] ) {
|
( *skipped )++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if( token == closeTokens[skipMode] )
|
||||||
|
{
|
||||||
depth--;
|
depth--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while( depth );
|
}
|
||||||
|
while( depth );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,8 @@ typedef enum
|
||||||
LEXFL_ONLYSTRINGS = BIT( 13 ) // parse as whitespace deliminated strings (quoted strings keep quotes)
|
LEXFL_ONLYSTRINGS = BIT( 13 ) // parse as whitespace deliminated strings (quoted strings keep quotes)
|
||||||
} lexerFlags_t;
|
} lexerFlags_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
BRSKIP_BRACES,
|
BRSKIP_BRACES,
|
||||||
BRSKIP_BRACKET
|
BRSKIP_BRACKET
|
||||||
} braceSkipMode_t;
|
} braceSkipMode_t;
|
||||||
|
@ -188,7 +189,7 @@ public:
|
||||||
// skip the rest of the current line
|
// skip the rest of the current line
|
||||||
int SkipRestOfLine();
|
int SkipRestOfLine();
|
||||||
// skip the braced section
|
// 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.
|
// skips spaces, tabs, C-like comments etc. Returns false if there is no token left to read.
|
||||||
bool SkipWhiteSpace( bool currentLine );
|
bool SkipWhiteSpace( bool currentLine );
|
||||||
// unread the given token
|
// unread the given token
|
||||||
|
|
|
@ -1574,11 +1574,12 @@ bool idMapFile::Parse( const char* filename, bool ignoreRegion, bool osPath )
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isGTLF = false;
|
bool isGTLF = false;
|
||||||
if ( !src.IsLoaded( ) ) {
|
if( !src.IsLoaded( ) )
|
||||||
|
{
|
||||||
// HVG: try loading a .gltf/glb second
|
// HVG: try loading a .gltf/glb second
|
||||||
fullName.SetFileExtension( "glb" );
|
fullName.SetFileExtension( "glb" );
|
||||||
isGTLF = src.LoadFile( fullName, osPath );
|
isGTLF = src.LoadFile( fullName, osPath );
|
||||||
if ( !isGTLF )
|
if( !isGTLF )
|
||||||
{
|
{
|
||||||
fullName.SetFileExtension( "gltf" );
|
fullName.SetFileExtension( "gltf" );
|
||||||
isGTLF = src.LoadFile( fullName, osPath );
|
isGTLF = src.LoadFile( fullName, osPath );
|
||||||
|
@ -1601,7 +1602,7 @@ bool idMapFile::Parse( const char* filename, bool ignoreRegion, bool osPath )
|
||||||
fileTime = src.GetFileTime();
|
fileTime = src.GetFileTime();
|
||||||
entities.DeleteContents( true );
|
entities.DeleteContents( true );
|
||||||
|
|
||||||
if(!isGTLF && !src.ReadToken( &token ) )
|
if( !isGTLF && !src.ReadToken( &token ) )
|
||||||
{
|
{
|
||||||
return false;
|
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 );
|
gltfParser->Load( fullName );
|
||||||
idMapEntity::GetEntities(gltfParser->currentAsset,entities,0);
|
idMapEntity::GetEntities( gltfParser->currentAsset, entities, 0 );
|
||||||
}else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if( token == "Version" )
|
if( token == "Version" )
|
||||||
{
|
{
|
||||||
|
|
|
@ -349,7 +349,7 @@ public:
|
||||||
|
|
||||||
void ConvertFromBrush( const idMapBrush* brush, int entityNum, int primitiveNum );
|
void ConvertFromBrush( const idMapBrush* brush, int entityNum, int primitiveNum );
|
||||||
void ConvertFromPatch( const idMapPatch* patch, 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 );
|
static MapPolygonMesh* Parse( idLexer& src, const idVec3& origin, float version = CURRENT_MAP_VERSION );
|
||||||
bool Write( idFile* fp, int primitiveNum, const idVec3& origin ) const;
|
bool Write( idFile* fp, int primitiveNum, const idVec3& origin ) const;
|
||||||
|
|
||||||
|
@ -368,7 +368,8 @@ public:
|
||||||
return verts.Append( v );
|
return verts.Append( v );
|
||||||
}
|
}
|
||||||
|
|
||||||
int AddVertices( const idList<idDrawVert> &v ) {
|
int AddVertices( const idList<idDrawVert>& v )
|
||||||
|
{
|
||||||
return verts.Append( v );
|
return verts.Append( v );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,9 +427,9 @@ protected:
|
||||||
|
|
||||||
class idMapEntity
|
class idMapEntity
|
||||||
{
|
{
|
||||||
typedef idList<idMapEntity *, TAG_IDLIB_LIST_MAP> EntityList;
|
typedef idList<idMapEntity*, TAG_IDLIB_LIST_MAP> EntityList;
|
||||||
typedef idList<idMapEntity *, TAG_IDLIB_LIST_MAP> &EntityListRef;
|
typedef idList<idMapEntity*, TAG_IDLIB_LIST_MAP>& EntityListRef;
|
||||||
typedef idList<idMapEntity *, TAG_IDLIB_LIST_MAP> *EntityListPtr;
|
typedef idList<idMapEntity*, TAG_IDLIB_LIST_MAP>* EntityListPtr;
|
||||||
|
|
||||||
friend class idMapFile;
|
friend class idMapFile;
|
||||||
|
|
||||||
|
@ -446,10 +447,10 @@ public:
|
||||||
primitives.DeleteContents( true );
|
primitives.DeleteContents( true );
|
||||||
}
|
}
|
||||||
// HVG check gltf scene for entities
|
// 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 );
|
static idMapEntity* Parse( idLexer& src, bool worldSpawn = false, float version = CURRENT_MAP_VERSION );
|
||||||
bool Write( idFile* fp, int entityNum, bool valve220 ) const;
|
bool Write( idFile* fp, int entityNum, bool valve220 ) const;
|
||||||
|
|
||||||
// HVG NOTE: this is not compatible with gltf (extra) json!
|
// HVG NOTE: this is not compatible with gltf (extra) json!
|
||||||
// RB begin
|
// RB begin
|
||||||
static idMapEntity* ParseJSON( idLexer& src );
|
static idMapEntity* ParseJSON( idLexer& src );
|
||||||
|
|
|
@ -4,32 +4,34 @@
|
||||||
|
|
||||||
extern idCVar gltf_parseVerbose;
|
extern idCVar gltf_parseVerbose;
|
||||||
|
|
||||||
void gltfExtra_Scatter::parse( idToken &token, idLexer * parser ) {
|
void gltfExtra_Scatter::parse( idToken& token, idLexer* parser )
|
||||||
|
{
|
||||||
|
|
||||||
parser->UnreadToken( &token );
|
parser->UnreadToken( &token );
|
||||||
|
|
||||||
gltfItemArray scatterInfo;
|
gltfItemArray scatterInfo;
|
||||||
GLTFARRAYITEM( scatterInfo, emitter, gltfObject );
|
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 );
|
parser->UnreadToken( &token );
|
||||||
gltfItemArray cvarInfo;
|
gltfItemArray cvarInfo;
|
||||||
idStr n,t,v,d;
|
idStr n, t, v, d;
|
||||||
GLTFARRAYITEMREF( cvarInfo, name, gltfItem , n);
|
GLTFARRAYITEMREF( cvarInfo, name, gltfItem , n );
|
||||||
GLTFARRAYITEMREF( cvarInfo, type, gltfItem , t);
|
GLTFARRAYITEMREF( cvarInfo, type, gltfItem , t );
|
||||||
GLTFARRAYITEMREF( cvarInfo, value, gltfItem, v );
|
GLTFARRAYITEMREF( cvarInfo, value, gltfItem, v );
|
||||||
GLTFARRAYITEMREF( cvarInfo, desc, gltfItem , d);
|
GLTFARRAYITEMREF( cvarInfo, desc, gltfItem , d );
|
||||||
int total = cvarInfo.Parse( parser );
|
int total = cvarInfo.Parse( parser );
|
||||||
assert( total == 3 );
|
assert( total == 3 );
|
||||||
idCVar * gltExtra_cvar = new idCVar(
|
idCVar* gltExtra_cvar = new idCVar(
|
||||||
n.c_str(),
|
n.c_str(),
|
||||||
v.c_str(),
|
v.c_str(),
|
||||||
CVAR_SYSTEM | CVAR_BOOL,
|
CVAR_SYSTEM | CVAR_BOOL,
|
||||||
d.c_str()
|
d.c_str()
|
||||||
);
|
);
|
||||||
|
|
||||||
cvarSystem->Register(gltExtra_cvar);
|
cvarSystem->Register( gltExtra_cvar );
|
||||||
}
|
}
|
|
@ -10,7 +10,7 @@
|
||||||
virtual idStr &Name( ) { return name; } \
|
virtual idStr &Name( ) { return name; } \
|
||||||
private: \
|
private: \
|
||||||
idStr name;}
|
idStr name;}
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Helper macros for gltf data deserialize
|
//Helper macros for gltf data deserialize
|
||||||
|
@ -19,9 +19,10 @@
|
||||||
#ifndef GLTF_EXTRAS_H
|
#ifndef GLTF_EXTRAS_H
|
||||||
#define GLTF_EXTRAS_H
|
#define GLTF_EXTRAS_H
|
||||||
|
|
||||||
class test {
|
class test
|
||||||
public:
|
{
|
||||||
test(){ }
|
public:
|
||||||
|
test() { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,5 +32,5 @@ gltfExtraParser( cvar, idCVar );
|
||||||
#endif // GLTF_EXTRAS_H
|
#endif // GLTF_EXTRAS_H
|
||||||
|
|
||||||
#ifndef gltfExternalParser
|
#ifndef gltfExternalParser
|
||||||
#undef gltfExtraParser
|
#undef gltfExtraParser
|
||||||
#endif
|
#endif
|
File diff suppressed because it is too large
Load diff
|
@ -6,75 +6,125 @@
|
||||||
#pragma region GLTF Types parsing
|
#pragma region GLTF Types parsing
|
||||||
|
|
||||||
#pragma region Parser interfaces
|
#pragma region Parser interfaces
|
||||||
struct parsable {
|
struct parsable
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
virtual void parse(idToken & token )=0;
|
virtual void parse( idToken& token ) = 0;
|
||||||
virtual void parse(idToken & token , idLexer * parser){};
|
virtual void parse( idToken& token , idLexer* parser ) {};
|
||||||
virtual idStr &Name( ) = 0;
|
virtual idStr& Name( ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
class parseType {
|
class parseType
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
void Set(T * type ) { item = type; }
|
void Set( T* type )
|
||||||
virtual ~parseType() { delete item; }
|
{
|
||||||
|
item = type;
|
||||||
|
}
|
||||||
|
virtual ~parseType()
|
||||||
|
{
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
T* item;
|
T* item;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfItem : public parsable, public parseType<idStr>
|
class gltfItem : public parsable, public parseType<idStr>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
gltfItem( idStr Name) : name( Name ) { item = nullptr; }
|
gltfItem( idStr Name ) : name( Name )
|
||||||
virtual void parse( idToken &token ) { *item = token; };
|
{
|
||||||
virtual idStr &Name( ) {return name;}
|
item = nullptr;
|
||||||
~gltfItem(){}
|
}
|
||||||
|
virtual void parse( idToken& token )
|
||||||
|
{
|
||||||
|
*item = token;
|
||||||
|
};
|
||||||
|
virtual idStr& Name( )
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
~gltfItem() {}
|
||||||
private:
|
private:
|
||||||
idStr name;
|
idStr name;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfObject : public parsable, public parseType<idStr> {
|
class gltfObject : public parsable, public parseType<idStr>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfObject( idStr Name ) : name( Name ), object("null"){}
|
gltfObject( idStr Name ) : name( Name ), object( "null" ) {}
|
||||||
virtual void parse( idToken &token ) {}
|
virtual void parse( idToken& token ) {}
|
||||||
virtual void parse(idToken & token , idLexer * parser){
|
virtual void parse( idToken& token , idLexer* parser )
|
||||||
parser->UnreadToken( &token );parser->ParseBracedSection( object );
|
{
|
||||||
|
parser->UnreadToken( &token );
|
||||||
|
parser->ParseBracedSection( object );
|
||||||
|
}
|
||||||
|
virtual idStr& Name( )
|
||||||
|
{
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
virtual idStr &Name( ) { return name; }
|
|
||||||
private:
|
private:
|
||||||
idStr name;
|
idStr name;
|
||||||
idStr object;
|
idStr object;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfItemArray;
|
class gltfItemArray;
|
||||||
class gltfItem_Extra : public parsable, public parseType<gltfExtra> {
|
class gltfItem_Extra : public parsable, public parseType<gltfExtra>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfItem_Extra( idStr Name ) : name( Name ), data(nullptr),parser(nullptr) { item = nullptr; }
|
gltfItem_Extra( idStr Name ) : name( Name ), data( nullptr ), parser( nullptr )
|
||||||
virtual void parse( idToken &token ) ;
|
{
|
||||||
virtual idStr &Name( ) { return name; }
|
item = nullptr;
|
||||||
void Set( gltfExtra *type, idLexer *lexer ) { parseType::Set( type ); parser = lexer; }
|
}
|
||||||
static void Register(parsable * extra);
|
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:
|
private:
|
||||||
idStr name;
|
idStr name;
|
||||||
gltfData *data;
|
gltfData* data;
|
||||||
idLexer* parser;
|
idLexer* parser;
|
||||||
static gltfItemArray*items;
|
static gltfItemArray* items;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfItem_uri : public parsable, public parseType<idStr> {
|
class gltfItem_uri : public parsable, public parseType<idStr>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfItem_uri( idStr Name ) : name( Name ) { item = nullptr; }
|
gltfItem_uri( idStr Name ) : name( Name )
|
||||||
virtual void parse( idToken &token ) { *item = token; Convert(); };
|
{
|
||||||
virtual idStr &Name( ) { return name; }
|
item = nullptr;
|
||||||
void Set( idStr *type,int * targetBufferview,gltfData* dataDestination ) { parseType::Set(type); bufferView = targetBufferview; data = dataDestination; }
|
}
|
||||||
|
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
|
// 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.
|
// bufferView will be set accordingly to the generated buffer.
|
||||||
bool Convert( );
|
bool Convert( );
|
||||||
private:
|
private:
|
||||||
idStr name;
|
idStr name;
|
||||||
int * bufferView;
|
int* bufferView;
|
||||||
gltfData * data;
|
gltfData* data;
|
||||||
};
|
};
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
#pragma region helper macro to define gltf data types with extra parsing context forced to be implemented externally
|
#pragma region helper macro to define gltf data types with extra parsing context forced to be implemented externally
|
||||||
#define gltfItemClassParser(className,ptype) \
|
#define gltfItemClassParser(className,ptype) \
|
||||||
|
@ -87,15 +137,15 @@ class gltfItem_##className : public parsable, public parseType<ptype> \
|
||||||
private: \
|
private: \
|
||||||
idStr name; \
|
idStr name; \
|
||||||
idLexer *parser;}
|
idLexer *parser;}
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
gltfItemClassParser( animation_sampler, idList<gltfAnimation_Sampler*> );
|
gltfItemClassParser( animation_sampler, idList<gltfAnimation_Sampler*> );
|
||||||
gltfItemClassParser( animation_channel_target, gltfAnimation_Channel_Target );
|
gltfItemClassParser( animation_channel_target, gltfAnimation_Channel_Target );
|
||||||
gltfItemClassParser( animation_channel, idList<gltfAnimation_Channel*>);
|
gltfItemClassParser( animation_channel, idList<gltfAnimation_Channel*> );
|
||||||
gltfItemClassParser( mesh_primitive, idList<gltfMesh_Primitive *>);
|
gltfItemClassParser( mesh_primitive, idList<gltfMesh_Primitive*> );
|
||||||
gltfItemClassParser( mesh_primitive_attribute, idList<gltfMesh_Primitive_Attribute *> );
|
gltfItemClassParser( mesh_primitive_attribute, idList<gltfMesh_Primitive_Attribute*> );
|
||||||
gltfItemClassParser( integer_array, idList<int>);
|
gltfItemClassParser( integer_array, idList<int> );
|
||||||
gltfItemClassParser( number_array, idList<double>);//does float suffice?
|
gltfItemClassParser( number_array, idList<double> ); //does float suffice?
|
||||||
gltfItemClassParser( mat4, idMat4 );
|
gltfItemClassParser( mat4, idMat4 );
|
||||||
gltfItemClassParser( vec4, idVec4 );
|
gltfItemClassParser( vec4, idVec4 );
|
||||||
gltfItemClassParser( vec3, idVec3 );
|
gltfItemClassParser( vec3, idVec3 );
|
||||||
|
@ -107,8 +157,8 @@ gltfItemClassParser( accessor_sparse_values, gltfAccessor_Sparse_Values );
|
||||||
gltfItemClassParser( camera_perspective, gltfCamera_Perspective );
|
gltfItemClassParser( camera_perspective, gltfCamera_Perspective );
|
||||||
gltfItemClassParser( camera_orthographic, gltfCamera_Orthographic );
|
gltfItemClassParser( camera_orthographic, gltfCamera_Orthographic );
|
||||||
gltfItemClassParser( pbrMetallicRoughness, gltfMaterial_pbrMetallicRoughness );
|
gltfItemClassParser( pbrMetallicRoughness, gltfMaterial_pbrMetallicRoughness );
|
||||||
gltfItemClassParser( texture_info, gltfTexture_Info);
|
gltfItemClassParser( texture_info, gltfTexture_Info );
|
||||||
gltfItemClassParser( normal_texture, gltfNormalTexture_Info);
|
gltfItemClassParser( normal_texture, gltfNormalTexture_Info );
|
||||||
gltfItemClassParser( occlusion_texture, gltfOcclusionTexture_Info );
|
gltfItemClassParser( occlusion_texture, gltfOcclusionTexture_Info );
|
||||||
gltfItemClassParser( node_extensions, gltfNode_Extensions );
|
gltfItemClassParser( node_extensions, gltfNode_Extensions );
|
||||||
gltfItemClassParser( material_extensions, gltfMaterial_Extensions );
|
gltfItemClassParser( material_extensions, gltfMaterial_Extensions );
|
||||||
|
@ -131,104 +181,135 @@ class gltfItem_##className : public parsable, public parseType<type> \
|
||||||
virtual idStr &Name( ) { return name; } \
|
virtual idStr &Name( ) { return name; } \
|
||||||
private: \
|
private: \
|
||||||
idStr name;}
|
idStr name;}
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
gltfItemClass(integer, int, *item = token.GetIntValue( ); );
|
gltfItemClass( integer, int, *item = token.GetIntValue( ); );
|
||||||
gltfItemClass(number, float, *item = token.GetFloatValue( ); );
|
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( boolean, bool, if( token.Icmp( "true" ) == 0 ) *item = true; else
|
||||||
|
{
|
||||||
|
if( token.Icmp( "false" ) == 0 )
|
||||||
|
{
|
||||||
|
*item = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
idLib::FatalError( "parse error" );
|
||||||
|
}
|
||||||
|
} );
|
||||||
#undef gltfItemClass
|
#undef gltfItemClass
|
||||||
|
|
||||||
class gltfItemArray
|
class gltfItemArray
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
~gltfItemArray( ) { items.DeleteContents(true); }
|
~gltfItemArray( )
|
||||||
|
{
|
||||||
|
items.DeleteContents( true );
|
||||||
|
}
|
||||||
gltfItemArray( ) { };
|
gltfItemArray( ) { };
|
||||||
int Num() { return items.Num(); }
|
int Num()
|
||||||
void AddItemDef( parsable *item ) { items.Alloc( ) = item;}
|
{
|
||||||
int Fill(idLexer * lexer , idDict * strPairs );
|
return items.Num();
|
||||||
int Parse(idLexer * lexer , bool forwardLexer = false );
|
}
|
||||||
|
void AddItemDef( parsable* item )
|
||||||
|
{
|
||||||
|
items.Alloc( ) = item;
|
||||||
|
}
|
||||||
|
int Fill( idLexer* lexer , idDict* strPairs );
|
||||||
|
int Parse( idLexer* lexer , bool forwardLexer = false );
|
||||||
template<class T>
|
template<class T>
|
||||||
T* Get(idStr name ){ for ( auto * item : items) if (item->Name() == name) return static_cast<T*>(item); return nullptr; }
|
T* Get( idStr name )
|
||||||
|
{
|
||||||
|
for( auto* item : items ) if( item->Name() == name )
|
||||||
|
{
|
||||||
|
return static_cast<T*>( item );
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
idList<parsable*> items;
|
idList<parsable*> items;
|
||||||
};
|
};
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
#pragma region GLTF Object parsing
|
#pragma region GLTF Object parsing
|
||||||
class gltfPropertyArray;
|
class gltfPropertyArray;
|
||||||
class gltfPropertyItem
|
class gltfPropertyItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
gltfPropertyItem( ) : array(nullptr){ }
|
gltfPropertyItem( ) : array( nullptr ) { }
|
||||||
gltfPropertyArray * array;
|
gltfPropertyArray* array;
|
||||||
idToken item;
|
idToken item;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfPropertyArray
|
class gltfPropertyArray
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
gltfPropertyArray( idLexer *Parser,bool AoS = true );
|
gltfPropertyArray( idLexer* Parser, bool AoS = true );
|
||||||
~gltfPropertyArray( );
|
~gltfPropertyArray( );
|
||||||
struct Iterator {
|
struct Iterator
|
||||||
gltfPropertyArray * array;
|
{
|
||||||
gltfPropertyItem *p;
|
gltfPropertyArray* array;
|
||||||
gltfPropertyItem &operator*( ) {return *p;}
|
gltfPropertyItem* p;
|
||||||
bool operator != ( Iterator &rhs ) {
|
gltfPropertyItem& operator*( )
|
||||||
return p != rhs.p;
|
{
|
||||||
|
return *p;
|
||||||
|
}
|
||||||
|
bool operator != ( Iterator& rhs )
|
||||||
|
{
|
||||||
|
return p != rhs.p;
|
||||||
}
|
}
|
||||||
void operator ++( );
|
void operator ++( );
|
||||||
};
|
};
|
||||||
gltfPropertyArray::Iterator begin( );
|
gltfPropertyArray::Iterator begin( );
|
||||||
gltfPropertyArray::Iterator end( );
|
gltfPropertyArray::Iterator end( );
|
||||||
private:
|
private:
|
||||||
bool iterating;
|
bool iterating;
|
||||||
bool dirty;
|
bool dirty;
|
||||||
int index;
|
int index;
|
||||||
idLexer * parser;
|
idLexer* parser;
|
||||||
idList<gltfPropertyItem*> properties;
|
idList<gltfPropertyItem*> properties;
|
||||||
gltfPropertyItem * endPtr;
|
gltfPropertyItem* endPtr;
|
||||||
bool isArrayOfStructs;
|
bool isArrayOfStructs;
|
||||||
};
|
};
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
class GLTF_Parser
|
class GLTF_Parser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GLTF_Parser();
|
GLTF_Parser();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
bool Parse();
|
bool Parse();
|
||||||
bool Load(idStr filename );
|
bool Load( idStr filename );
|
||||||
bool loadGLB(idStr filename );
|
bool loadGLB( idStr filename );
|
||||||
|
|
||||||
//current/last loaded gltf asset and index offsets
|
//current/last loaded gltf asset and index offsets
|
||||||
gltfData *currentAsset;
|
gltfData* currentAsset;
|
||||||
private:
|
private:
|
||||||
void SetNodeParent( gltfNode *node, gltfNode *parent = nullptr );
|
void SetNodeParent( gltfNode* node, gltfNode* parent = nullptr );
|
||||||
//void CreateBgfxData( );
|
//void CreateBgfxData( );
|
||||||
|
|
||||||
void Parse_ASSET( idToken &token );
|
void Parse_ASSET( idToken& token );
|
||||||
void Parse_CAMERAS( idToken &token );
|
void Parse_CAMERAS( idToken& token );
|
||||||
void Parse_SCENE( idToken &token );
|
void Parse_SCENE( idToken& token );
|
||||||
void Parse_SCENES( idToken &token );
|
void Parse_SCENES( idToken& token );
|
||||||
void Parse_NODES( idToken &token );
|
void Parse_NODES( idToken& token );
|
||||||
void Parse_MATERIALS( idToken &token );
|
void Parse_MATERIALS( idToken& token );
|
||||||
void Parse_MESHES( idToken &token );
|
void Parse_MESHES( idToken& token );
|
||||||
void Parse_TEXTURES( idToken &token );
|
void Parse_TEXTURES( idToken& token );
|
||||||
void Parse_IMAGES( idToken &token );
|
void Parse_IMAGES( idToken& token );
|
||||||
void Parse_ACCESSORS( idToken &token );
|
void Parse_ACCESSORS( idToken& token );
|
||||||
void Parse_BUFFERVIEWS( idToken &token );
|
void Parse_BUFFERVIEWS( idToken& token );
|
||||||
void Parse_SAMPLERS( idToken &token );
|
void Parse_SAMPLERS( idToken& token );
|
||||||
void Parse_BUFFERS( idToken &token );
|
void Parse_BUFFERS( idToken& token );
|
||||||
void Parse_ANIMATIONS( idToken &token );
|
void Parse_ANIMATIONS( idToken& token );
|
||||||
void Parse_SKINS( idToken &token );
|
void Parse_SKINS( idToken& token );
|
||||||
void Parse_EXTENSIONS( idToken &token );
|
void Parse_EXTENSIONS( idToken& token );
|
||||||
void Parse_EXTENSIONS_USED( idToken &token );
|
void Parse_EXTENSIONS_USED( idToken& token );
|
||||||
void Parse_EXTENSIONS_REQUIRED( 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;
|
idLexer parser;
|
||||||
idToken token;
|
idToken token;
|
||||||
idStr currentFile;
|
idStr currentFile;
|
||||||
|
@ -237,4 +318,4 @@ private:
|
||||||
bool bufferViewsDone;
|
bool bufferViewsDone;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern GLTF_Parser * gltfParser;
|
extern GLTF_Parser* gltfParser;
|
|
@ -5,7 +5,8 @@
|
||||||
#include "Lib.h"
|
#include "Lib.h"
|
||||||
#include "containers/List.h"
|
#include "containers/List.h"
|
||||||
|
|
||||||
enum gltfProperty {
|
enum gltfProperty
|
||||||
|
{
|
||||||
INVALID,
|
INVALID,
|
||||||
ASSET,
|
ASSET,
|
||||||
ACCESSOR,
|
ACCESSOR,
|
||||||
|
@ -33,7 +34,8 @@ class gltfData;
|
||||||
|
|
||||||
struct gltf_accessor_component
|
struct gltf_accessor_component
|
||||||
{
|
{
|
||||||
enum Type {
|
enum Type
|
||||||
|
{
|
||||||
_byte,
|
_byte,
|
||||||
_uByte,
|
_uByte,
|
||||||
_short,
|
_short,
|
||||||
|
@ -46,7 +48,8 @@ struct gltf_accessor_component
|
||||||
};
|
};
|
||||||
|
|
||||||
template< class T >
|
template< class T >
|
||||||
struct gltf_accessor_component_type_map {
|
struct gltf_accessor_component_type_map
|
||||||
|
{
|
||||||
idStr stringID;
|
idStr stringID;
|
||||||
int id;
|
int id;
|
||||||
T type;
|
T type;
|
||||||
|
@ -62,38 +65,43 @@ public:
|
||||||
//str:str pairs of each item
|
//str:str pairs of each item
|
||||||
idDict strPairs;
|
idDict strPairs;
|
||||||
//specialized parsers
|
//specialized parsers
|
||||||
idList<gltfExtra *> extras;
|
idList<gltfExtra*> extras;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfExt_KHR_lights_punctual;
|
class gltfExt_KHR_lights_punctual;
|
||||||
class gltfExtensions {
|
class gltfExtensions
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfExtensions( ) { }
|
gltfExtensions( ) { }
|
||||||
idList<gltfExt_KHR_lights_punctual *> KHR_lights_punctual;
|
idList<gltfExt_KHR_lights_punctual*> KHR_lights_punctual;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfNode_KHR_lights_punctual {
|
class gltfNode_KHR_lights_punctual
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
int light;
|
int light;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfNode_Extensions {
|
class gltfNode_Extensions
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfNode_Extensions( ) :
|
gltfNode_Extensions( ) :
|
||||||
KHR_lights_punctual( nullptr) { }
|
KHR_lights_punctual( nullptr ) { }
|
||||||
gltfNode_KHR_lights_punctual* KHR_lights_punctual;
|
gltfNode_KHR_lights_punctual* KHR_lights_punctual;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfExt_KHR_materials_pbrSpecularGlossiness;
|
class gltfExt_KHR_materials_pbrSpecularGlossiness;
|
||||||
class gltfMaterial_Extensions {
|
class gltfMaterial_Extensions
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfMaterial_Extensions( ) :
|
gltfMaterial_Extensions( ) :
|
||||||
KHR_materials_pbrSpecularGlossiness( nullptr ) { }
|
KHR_materials_pbrSpecularGlossiness( nullptr ) { }
|
||||||
gltfExt_KHR_materials_pbrSpecularGlossiness *KHR_materials_pbrSpecularGlossiness;
|
gltfExt_KHR_materials_pbrSpecularGlossiness* KHR_materials_pbrSpecularGlossiness;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class gltfNode {
|
class gltfNode
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfNode( ) : camera( -1 ), skin( -1 ), matrix( mat4_zero ),
|
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 ),
|
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;
|
gltfExtra extras;
|
||||||
|
|
||||||
//
|
//
|
||||||
gltfNode * parent;
|
gltfNode* parent;
|
||||||
bool dirty;
|
bool dirty;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct gltfCameraNodePtrs {
|
struct gltfCameraNodePtrs
|
||||||
gltfNode *translationNode = nullptr;
|
{
|
||||||
gltfNode *orientationNode = nullptr;
|
gltfNode* translationNode = nullptr;
|
||||||
|
gltfNode* orientationNode = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfScene {
|
class gltfScene
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfScene( ) { }
|
gltfScene( ) { }
|
||||||
idList<int> nodes;
|
idList<int> nodes;
|
||||||
|
@ -130,9 +140,11 @@ public:
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfMesh_Primitive_Attribute {
|
class gltfMesh_Primitive_Attribute
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
enum Type {
|
enum Type
|
||||||
|
{
|
||||||
Position,
|
Position,
|
||||||
Normal,
|
Normal,
|
||||||
Tangent,
|
Tangent,
|
||||||
|
@ -153,7 +165,7 @@ public:
|
||||||
Count
|
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;
|
idStr attributeSemantic;
|
||||||
int accessorIndex;
|
int accessorIndex;
|
||||||
uint elementSize;
|
uint elementSize;
|
||||||
|
@ -161,16 +173,18 @@ public:
|
||||||
Type type;
|
Type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct gltf_mesh_attribute_map {
|
struct gltf_mesh_attribute_map
|
||||||
|
{
|
||||||
idStr stringID;
|
idStr stringID;
|
||||||
gltfMesh_Primitive_Attribute::Type attib;
|
gltfMesh_Primitive_Attribute::Type attib;
|
||||||
uint elementSize;
|
uint elementSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfMesh_Primitive {
|
class gltfMesh_Primitive
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfMesh_Primitive( ) : indices( -1 ), material( -1 ), mode( -1 ) { }
|
gltfMesh_Primitive( ) : indices( -1 ), material( -1 ), mode( -1 ) { }
|
||||||
idList<gltfMesh_Primitive_Attribute *> attributes;
|
idList<gltfMesh_Primitive_Attribute*> attributes;
|
||||||
int indices;
|
int indices;
|
||||||
int material;
|
int material;
|
||||||
int mode;
|
int mode;
|
||||||
|
@ -179,18 +193,20 @@ public:
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfMesh {
|
class gltfMesh
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfMesh( ) { };
|
gltfMesh( ) { };
|
||||||
|
|
||||||
idList<gltfMesh_Primitive *> primitives; // gltfMesh_Primitive[1,*]
|
idList<gltfMesh_Primitive*> primitives; // gltfMesh_Primitive[1,*]
|
||||||
idList<double> weights; // number[1,*]
|
idList<double> weights; // number[1,*]
|
||||||
idStr name;
|
idStr name;
|
||||||
idStr extensions;
|
idStr extensions;
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfCamera_Orthographic {
|
class gltfCamera_Orthographic
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfCamera_Orthographic( ) : xmag( 0.0f ), ymag( 0.0f ), zfar( 0.0f ), znear( 0.0f ) { };
|
gltfCamera_Orthographic( ) : xmag( 0.0f ), ymag( 0.0f ), zfar( 0.0f ), znear( 0.0f ) { };
|
||||||
float xmag;
|
float xmag;
|
||||||
|
@ -201,7 +217,8 @@ public:
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfCamera_Perspective {
|
class gltfCamera_Perspective
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfCamera_Perspective( ) : aspectRatio( 0.0f ), yfov( 0.0f ), zfar( 0.0f ), znear( 0.0f ) { };
|
gltfCamera_Perspective( ) : aspectRatio( 0.0f ), yfov( 0.0f ), zfar( 0.0f ), znear( 0.0f ) { };
|
||||||
float aspectRatio;
|
float aspectRatio;
|
||||||
|
@ -212,7 +229,8 @@ public:
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfCamera {
|
class gltfCamera
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfCamera( ) { };
|
gltfCamera( ) { };
|
||||||
gltfCamera_Orthographic orthographic;
|
gltfCamera_Orthographic orthographic;
|
||||||
|
@ -223,7 +241,8 @@ public:
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfAnimation_Channel_Target {
|
class gltfAnimation_Channel_Target
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfAnimation_Channel_Target( ) : node( -1 ), TRS( gltfTRS::count ) { };
|
gltfAnimation_Channel_Target( ) : node( -1 ), TRS( gltfTRS::count ) { };
|
||||||
int node;
|
int node;
|
||||||
|
@ -231,7 +250,8 @@ public:
|
||||||
idStr extensions;
|
idStr extensions;
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
|
|
||||||
enum gltfTRS {
|
enum gltfTRS
|
||||||
|
{
|
||||||
none,
|
none,
|
||||||
rotation,
|
rotation,
|
||||||
translation,
|
translation,
|
||||||
|
@ -242,20 +262,30 @@ public:
|
||||||
|
|
||||||
gltfTRS TRS;
|
gltfTRS TRS;
|
||||||
|
|
||||||
static gltfTRS resolveType( idStr type ) {
|
static gltfTRS resolveType( idStr type )
|
||||||
if ( type == "translation" )
|
{
|
||||||
|
if( type == "translation" )
|
||||||
|
{
|
||||||
return gltfTRS::translation;
|
return gltfTRS::translation;
|
||||||
else if ( type == "rotation" )
|
}
|
||||||
|
else if( type == "rotation" )
|
||||||
|
{
|
||||||
return gltfTRS::rotation;
|
return gltfTRS::rotation;
|
||||||
else if ( type == "scale" )
|
}
|
||||||
|
else if( type == "scale" )
|
||||||
|
{
|
||||||
return gltfTRS::scale;
|
return gltfTRS::scale;
|
||||||
else if ( type == "weights" )
|
}
|
||||||
|
else if( type == "weights" )
|
||||||
|
{
|
||||||
return gltfTRS::weights;
|
return gltfTRS::weights;
|
||||||
|
}
|
||||||
return gltfTRS::count;
|
return gltfTRS::count;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfAnimation_Channel {
|
class gltfAnimation_Channel
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfAnimation_Channel( ) : sampler( -1 ) { };
|
gltfAnimation_Channel( ) : sampler( -1 ) { };
|
||||||
int sampler;
|
int sampler;
|
||||||
|
@ -264,16 +294,18 @@ public:
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfAnimation_Sampler {
|
class gltfAnimation_Sampler
|
||||||
|
{
|
||||||
public:
|
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;
|
int input;
|
||||||
idStr interpolation;
|
idStr interpolation;
|
||||||
int output;
|
int output;
|
||||||
idStr extensions;
|
idStr extensions;
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
|
|
||||||
enum gltfInterpType {
|
enum gltfInterpType
|
||||||
|
{
|
||||||
linear,
|
linear,
|
||||||
step,
|
step,
|
||||||
cubicSpline,
|
cubicSpline,
|
||||||
|
@ -282,23 +314,31 @@ public:
|
||||||
|
|
||||||
gltfInterpType intType;
|
gltfInterpType intType;
|
||||||
|
|
||||||
static gltfInterpType resolveType( idStr type ) {
|
static gltfInterpType resolveType( idStr type )
|
||||||
if ( type == "LINEAR" )
|
{
|
||||||
|
if( type == "LINEAR" )
|
||||||
|
{
|
||||||
return gltfInterpType::linear;
|
return gltfInterpType::linear;
|
||||||
else if ( type == "STEP" )
|
}
|
||||||
|
else if( type == "STEP" )
|
||||||
|
{
|
||||||
return gltfInterpType::step;
|
return gltfInterpType::step;
|
||||||
else if ( type == "CUBICSPLINE" )
|
}
|
||||||
|
else if( type == "CUBICSPLINE" )
|
||||||
|
{
|
||||||
return gltfInterpType::cubicSpline;
|
return gltfInterpType::cubicSpline;
|
||||||
|
}
|
||||||
return gltfInterpType::count;
|
return gltfInterpType::count;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfAnimation {
|
class gltfAnimation
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfAnimation( ) : maxTime (0.0f),numFrames(0) { };
|
gltfAnimation( ) : maxTime( 0.0f ), numFrames( 0 ) { };
|
||||||
idList<gltfAnimation_Channel *> channels;
|
idList<gltfAnimation_Channel*> channels;
|
||||||
idList<gltfAnimation_Sampler *> samplers;
|
idList<gltfAnimation_Sampler*> samplers;
|
||||||
idStr name;
|
idStr name;
|
||||||
idStr extensions;
|
idStr extensions;
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
|
@ -308,16 +348,39 @@ public:
|
||||||
//id specific
|
//id specific
|
||||||
mutable int ref_count;
|
mutable int ref_count;
|
||||||
int numFrames;
|
int numFrames;
|
||||||
void DecreaseRefs() const {ref_count--;};
|
void DecreaseRefs() const
|
||||||
void IncreaseRefs() const {ref_count++;};
|
{
|
||||||
bool GetBounds( idBounds &bnds, int time, int cyclecount ) const { return false;}
|
ref_count--;
|
||||||
bool GetOriginRotation( idQuat &rotation, int time, int cyclecount ) const { return false;}
|
};
|
||||||
bool GetOrigin( idVec3 &offset, int time, int cyclecount ) const { return false;}
|
void IncreaseRefs() const
|
||||||
const idVec3 &TotalMovementDelta( void ) const {static idVec3 temp; return temp; }
|
{
|
||||||
int NumFrames() const {return numFrames;}
|
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:
|
public:
|
||||||
gltfAccessor_Sparse_Values( ) : bufferView( -1 ), byteOffset( -1 ) { };
|
gltfAccessor_Sparse_Values( ) : bufferView( -1 ), byteOffset( -1 ) { };
|
||||||
int bufferView;
|
int bufferView;
|
||||||
|
@ -326,7 +389,8 @@ public:
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfAccessor_Sparse_Indices {
|
class gltfAccessor_Sparse_Indices
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfAccessor_Sparse_Indices( ) : bufferView( -1 ), byteOffset( -1 ), componentType( -1 ) { };
|
gltfAccessor_Sparse_Indices( ) : bufferView( -1 ), byteOffset( -1 ), componentType( -1 ) { };
|
||||||
int bufferView;
|
int bufferView;
|
||||||
|
@ -336,7 +400,8 @@ public:
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfAccessor_Sparse {
|
class gltfAccessor_Sparse
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfAccessor_Sparse( ) : count( -1 ) { };
|
gltfAccessor_Sparse( ) : count( -1 ) { };
|
||||||
int count;
|
int count;
|
||||||
|
@ -346,10 +411,11 @@ public:
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfAccessor {
|
class gltfAccessor
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfAccessor( ) : bufferView( -1 ), byteOffset( 0 ), componentType( -1 ), normalized( false ), count( -1 ) ,
|
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 bufferView;
|
||||||
int byteOffset;
|
int byteOffset;
|
||||||
int componentType;
|
int componentType;
|
||||||
|
@ -365,13 +431,14 @@ public:
|
||||||
|
|
||||||
uint typeSize;
|
uint typeSize;
|
||||||
|
|
||||||
idList<float> * floatView;
|
idList<float>* floatView;
|
||||||
idList<idVec3*> * vecView;
|
idList<idVec3*>* vecView;
|
||||||
idList<idQuat*> * quatView;
|
idList<idQuat*>* quatView;
|
||||||
idList<idMat4> * matView;
|
idList<idMat4>* matView;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfBufferView {
|
class gltfBufferView
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfBufferView( ) : buffer( -1 ), byteLength( -1 ), byteStride( 0 ), byteOffset( 0 ), target( -1 ) { };
|
gltfBufferView( ) : buffer( -1 ), byteLength( -1 ), byteStride( 0 ), byteOffset( 0 ), target( -1 ) { };
|
||||||
int buffer;
|
int buffer;
|
||||||
|
@ -383,10 +450,11 @@ public:
|
||||||
idStr extensions;
|
idStr extensions;
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
//
|
//
|
||||||
gltfData *parent;
|
gltfData* parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfBuffer {
|
class gltfBuffer
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfBuffer( ) : byteLength( -1 ), parent( nullptr ) { };
|
gltfBuffer( ) : byteLength( -1 ), parent( nullptr ) { };
|
||||||
idStr uri;
|
idStr uri;
|
||||||
|
@ -395,10 +463,11 @@ public:
|
||||||
idStr extensions;
|
idStr extensions;
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
//
|
//
|
||||||
gltfData * parent;
|
gltfData* parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfSampler {
|
class gltfSampler
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfSampler( ) : magFilter( 0 ), minFilter( 0 ), wrapS( 10497 ), wrapT( 10497 ) { };
|
gltfSampler( ) : magFilter( 0 ), minFilter( 0 ), wrapS( 10497 ), wrapT( 10497 ) { };
|
||||||
int magFilter;
|
int magFilter;
|
||||||
|
@ -412,7 +481,8 @@ public:
|
||||||
uint bgfxSamplerFlags;
|
uint bgfxSamplerFlags;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfImage {
|
class gltfImage
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfImage( ) : bufferView( -1 ) { }
|
gltfImage( ) : bufferView( -1 ) { }
|
||||||
idStr uri;
|
idStr uri;
|
||||||
|
@ -423,9 +493,10 @@ public:
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfSkin {
|
class gltfSkin
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfSkin( ) : inverseBindMatrices(-1),skeleton(-1),name("unnamedSkin"){ };
|
gltfSkin( ) : inverseBindMatrices( -1 ), skeleton( -1 ), name( "unnamedSkin" ) { };
|
||||||
int inverseBindMatrices;
|
int inverseBindMatrices;
|
||||||
int skeleton;
|
int skeleton;
|
||||||
idList<int> joints; // integer[1,*]
|
idList<int> joints; // integer[1,*]
|
||||||
|
@ -435,14 +506,16 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfExt_KHR_texture_transform;
|
class gltfExt_KHR_texture_transform;
|
||||||
class gltfTexture_Info_Extensions {
|
class gltfTexture_Info_Extensions
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfTexture_Info_Extensions( ) :
|
gltfTexture_Info_Extensions( ) :
|
||||||
KHR_texture_transform( nullptr ) { }
|
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:
|
public:
|
||||||
gltfOcclusionTexture_Info( ) : index( -1 ), texCoord( 0 ), strength( 1.0f ) { }
|
gltfOcclusionTexture_Info( ) : index( -1 ), texCoord( 0 ), strength( 1.0f ) { }
|
||||||
int index;
|
int index;
|
||||||
|
@ -452,7 +525,8 @@ public:
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfNormalTexture_Info {
|
class gltfNormalTexture_Info
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfNormalTexture_Info( ) : index( -1 ), texCoord( 0 ), scale( 1.0f ) { }
|
gltfNormalTexture_Info( ) : index( -1 ), texCoord( 0 ), scale( 1.0f ) { }
|
||||||
int index;
|
int index;
|
||||||
|
@ -462,7 +536,8 @@ public:
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfTexture_Info {
|
class gltfTexture_Info
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfTexture_Info( ) : index( -1 ), texCoord( 0 ) { }
|
gltfTexture_Info( ) : index( -1 ), texCoord( 0 ) { }
|
||||||
int index;
|
int index;
|
||||||
|
@ -472,17 +547,19 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class gltfTexture {
|
class gltfTexture
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfTexture( ) : sampler( -1 ), source( -1 ) { }
|
gltfTexture( ) : sampler( -1 ), source( -1 ) { }
|
||||||
int sampler;
|
int sampler;
|
||||||
int source;
|
int source;
|
||||||
idStr name;
|
idStr name;
|
||||||
gltfTexture_Info_Extensions extensions;
|
gltfTexture_Info_Extensions extensions;
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfMaterial_pbrMetallicRoughness {
|
class gltfMaterial_pbrMetallicRoughness
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfMaterial_pbrMetallicRoughness( ) : baseColorFactor( vec4_one ), metallicFactor( 1.0f ), roughnessFactor( 1.0f ) { }
|
gltfMaterial_pbrMetallicRoughness( ) : baseColorFactor( vec4_one ), metallicFactor( 1.0f ), roughnessFactor( 1.0f ) { }
|
||||||
idVec4 baseColorFactor;
|
idVec4 baseColorFactor;
|
||||||
|
@ -494,9 +571,11 @@ public:
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfMaterial {
|
class gltfMaterial
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
enum gltfAlphaMode {
|
enum gltfAlphaMode
|
||||||
|
{
|
||||||
gltfOPAQUE,
|
gltfOPAQUE,
|
||||||
gltfMASK,
|
gltfMASK,
|
||||||
gltfBLEND,
|
gltfBLEND,
|
||||||
|
@ -518,18 +597,26 @@ public:
|
||||||
|
|
||||||
gltfAlphaMode intType;
|
gltfAlphaMode intType;
|
||||||
|
|
||||||
static gltfAlphaMode resolveAlphaMode( idStr type ) {
|
static gltfAlphaMode resolveAlphaMode( idStr type )
|
||||||
if ( type == "OPAQUE" )
|
{
|
||||||
|
if( type == "OPAQUE" )
|
||||||
|
{
|
||||||
return gltfAlphaMode::gltfOPAQUE;
|
return gltfAlphaMode::gltfOPAQUE;
|
||||||
else if ( type == "MASK" )
|
}
|
||||||
|
else if( type == "MASK" )
|
||||||
|
{
|
||||||
return gltfAlphaMode::gltfMASK;
|
return gltfAlphaMode::gltfMASK;
|
||||||
else if ( type == "BLEND" )
|
}
|
||||||
|
else if( type == "BLEND" )
|
||||||
|
{
|
||||||
return gltfAlphaMode::gltfBLEND;
|
return gltfAlphaMode::gltfBLEND;
|
||||||
|
}
|
||||||
return gltfAlphaMode::count;
|
return gltfAlphaMode::count;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class gltfAsset {
|
class gltfAsset
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfAsset( ) { }
|
gltfAsset( ) { }
|
||||||
idStr copyright;
|
idStr copyright;
|
||||||
|
@ -542,7 +629,8 @@ public:
|
||||||
|
|
||||||
//this is not used.
|
//this is not used.
|
||||||
//if an extension is found, it _will_ be used. (if implemented)
|
//if an extension is found, it _will_ be used. (if implemented)
|
||||||
class gltfExtensionsUsed {
|
class gltfExtensionsUsed
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfExtensionsUsed( ) { }
|
gltfExtensionsUsed( ) { }
|
||||||
idStr extension;
|
idStr extension;
|
||||||
|
@ -565,9 +653,10 @@ public:
|
||||||
|
|
||||||
//KHR_lights_punctual_spot
|
//KHR_lights_punctual_spot
|
||||||
//https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_lights_punctual/schema/light.spot.schema.json
|
//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:
|
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 innerConeAngle;
|
||||||
float outerConeAngle;
|
float outerConeAngle;
|
||||||
idStr extensions;
|
idStr extensions;
|
||||||
|
@ -577,9 +666,10 @@ typedef gltfExt_KHR_lights_punctual_spot spot;
|
||||||
|
|
||||||
//KHR_lights_punctual
|
//KHR_lights_punctual
|
||||||
//https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_lights_punctual/schema/light.schema.json
|
//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:
|
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;
|
idVec3 color;
|
||||||
float intensity;
|
float intensity;
|
||||||
spot spot;
|
spot spot;
|
||||||
|
@ -591,28 +681,36 @@ public:
|
||||||
|
|
||||||
int intType;
|
int intType;
|
||||||
|
|
||||||
static int resolveType( idStr type ) {
|
static int resolveType( idStr type )
|
||||||
if (type == "directional" )
|
{
|
||||||
|
if( type == "directional" )
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
else if (type == "point" )
|
}
|
||||||
|
else if( type == "point" )
|
||||||
|
{
|
||||||
return 1;
|
return 1;
|
||||||
else if (type == "spot" )
|
}
|
||||||
|
else if( type == "spot" )
|
||||||
|
{
|
||||||
return 2;
|
return 2;
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//KHR_texture_transform
|
//KHR_texture_transform
|
||||||
//https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_transform/schema/KHR_texture_transform.textureInfo.schema.json
|
//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:
|
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;
|
idVec2 offset;
|
||||||
float rotation;
|
float rotation;
|
||||||
idVec2 scale;
|
idVec2 scale;
|
||||||
int texCoord;
|
int texCoord;
|
||||||
idStr extensions;
|
idStr extensions;
|
||||||
gltfExtra extras;
|
gltfExtra extras;
|
||||||
|
|
||||||
//for shader
|
//for shader
|
||||||
uint index;
|
uint index;
|
||||||
|
@ -631,53 +729,85 @@ const inline idList<gltf##name*> & ##name##List() { return target; }
|
||||||
// EACH URI will have an unique chunk
|
// EACH URI will have an unique chunk
|
||||||
// JSON chunk MUST be the first one to be allocated/added
|
// JSON chunk MUST be the first one to be allocated/added
|
||||||
|
|
||||||
class gltfData {
|
class gltfData
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
gltfData( ) : fileNameHash( 0 ), json( nullptr ), data( nullptr ), totalChunks( -1 ) { };
|
gltfData( ) : fileNameHash( 0 ), json( nullptr ), data( nullptr ), totalChunks( -1 ) { };
|
||||||
~gltfData( );
|
~gltfData( );
|
||||||
byte *AddData( int size, int *bufferID = nullptr );
|
byte* AddData( int size, int* bufferID = nullptr );
|
||||||
byte *GetJsonData( int &size ) { size = jsonDataLength; return json; }
|
byte* GetJsonData( int& size )
|
||||||
byte *GetData( int index ) { return data[index]; }
|
{
|
||||||
void FileName( const idStr &file ) { fileName = file; fileNameHash = fileDataHash.GenerateKey( file.c_str( ) ); }
|
size = jsonDataLength;
|
||||||
int FileNameHash( ) { return fileNameHash; }
|
return json;
|
||||||
idStr &FileName( ) { return fileName; }
|
}
|
||||||
|
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 idHashIndex fileDataHash;
|
||||||
static idList<gltfData *> dataList;
|
static idList<gltfData*> dataList;
|
||||||
//add data from filename
|
//add data from filename
|
||||||
static gltfData *Data( idStr &fileName ) {
|
static gltfData* Data( idStr& fileName )
|
||||||
|
{
|
||||||
dataList.AssureSizeAlloc( dataList.Num( ) + 1, idListNewElement<gltfData> );
|
dataList.AssureSizeAlloc( dataList.Num( ) + 1, idListNewElement<gltfData> );
|
||||||
dataList[dataList.Num( ) - 1]->FileName( fileName );
|
dataList[dataList.Num( ) - 1]->FileName( fileName );
|
||||||
fileDataHash.Add( fileDataHash.GenerateKey( fileName ), dataList.Num( ) - 1 );
|
fileDataHash.Add( fileDataHash.GenerateKey( fileName ), dataList.Num( ) - 1 );
|
||||||
return dataList[dataList.Num( ) - 1];
|
return dataList[dataList.Num( ) - 1];
|
||||||
}
|
}
|
||||||
//find data;
|
//find data;
|
||||||
static gltfData *Data( const char *filename ) { return dataList[fileDataHash.First( fileDataHash.GenerateKey( filename ) )]; }
|
static gltfData* Data( const char* filename )
|
||||||
static const idList<gltfData *> &DataList( ) { return dataList; }
|
{
|
||||||
static void ClearData( ) { idLib::Warning( "TODO! DATA NOT FREED" ); }
|
return dataList[fileDataHash.First( fileDataHash.GenerateKey( filename ) )];
|
||||||
|
}
|
||||||
|
static const idList<gltfData*>& DataList( )
|
||||||
|
{
|
||||||
|
return dataList;
|
||||||
|
}
|
||||||
|
static void ClearData( )
|
||||||
|
{
|
||||||
|
idLib::Warning( "TODO! DATA NOT FREED" );
|
||||||
|
}
|
||||||
|
|
||||||
//return the GLTF nodes that control the given camera
|
//return the GLTF nodes that control the given camera
|
||||||
//return TRUE if the camera uses 2 nodes (like when blender exports gltfs with +Y..)
|
//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.
|
// if so, translate node will be set to the parent node of the orientation node.
|
||||||
//Note: does not take overides into account!
|
//Note: does not take overides into account!
|
||||||
gltfNode* GetCameraNodes( gltfCamera *camera )
|
gltfNode* GetCameraNodes( gltfCamera* camera )
|
||||||
{
|
{
|
||||||
gltfCameraNodePtrs result;
|
gltfCameraNodePtrs result;
|
||||||
|
|
||||||
assert( camera );
|
assert( camera );
|
||||||
int camId = -1;
|
int camId = -1;
|
||||||
for ( auto *cam : cameras )
|
for( auto* cam : cameras )
|
||||||
{
|
{
|
||||||
camId++;
|
camId++;
|
||||||
if ( cam == camera )
|
if( cam == camera )
|
||||||
|
{
|
||||||
break;
|
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 nodes[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -693,15 +823,16 @@ public:
|
||||||
|
|
||||||
idMat4 result = mat4_identity;
|
idMat4 result = mat4_identity;
|
||||||
|
|
||||||
idList<gltfNode*> hierachy(2);
|
idList<gltfNode*> hierachy( 2 );
|
||||||
gltfNode* parent = nullptr;
|
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];
|
parent = nodes[i];
|
||||||
while ( parent ) {
|
while( parent )
|
||||||
|
{
|
||||||
hierachy.Append( parent );
|
hierachy.Append( parent );
|
||||||
parent = parent->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;
|
result *= hierachy[i]->matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
//Please note : assumes all nodes are _not_ dirty!
|
//Please note : assumes all nodes are _not_ dirty!
|
||||||
idMat4 GetLightMatrix( int lightId ) const
|
idMat4 GetLightMatrix( int lightId ) const
|
||||||
{
|
{
|
||||||
idMat4 result = mat4_identity;
|
idMat4 result = mat4_identity;
|
||||||
|
|
||||||
idList<gltfNode *> hierachy;
|
idList<gltfNode*> hierachy;
|
||||||
gltfNode *parent = nullptr;
|
gltfNode* parent = nullptr;
|
||||||
hierachy.SetGranularity( 2 );
|
hierachy.SetGranularity( 2 );
|
||||||
|
|
||||||
for ( int i = 0; i < nodes.Num( ); i++ ) {
|
for( int i = 0; i < nodes.Num( ); i++ )
|
||||||
if ( nodes[i]->extensions.KHR_lights_punctual && nodes[i]->extensions.KHR_lights_punctual->light == lightId ) {
|
{
|
||||||
|
if( nodes[i]->extensions.KHR_lights_punctual && nodes[i]->extensions.KHR_lights_punctual->light == lightId )
|
||||||
|
{
|
||||||
parent = nodes[i];
|
parent = nodes[i];
|
||||||
while ( parent ) {
|
while( parent )
|
||||||
|
{
|
||||||
hierachy.Append( parent );
|
hierachy.Append( parent );
|
||||||
parent = parent->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;
|
result *= hierachy[i]->matrix;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// v * T * R * S. ->row major
|
// v * T * R * S. ->row major
|
||||||
// v' = S * R * T * v -> column major;
|
// v' = S * R * T * v -> column major;
|
||||||
//bgfx = column-major
|
//bgfx = column-major
|
||||||
//idmath = row major, except mat3
|
//idmath = row major, except mat3
|
||||||
//gltf matrices : column-major.
|
//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.
|
//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(
|
idMat4 scaleMat = idMat4(
|
||||||
node->scale.x, 0, 0, 0,
|
node->scale.x, 0, 0, 0,
|
||||||
0, node->scale.y, 0, 0,
|
0, node->scale.y, 0, 0,
|
||||||
0, 0, node->scale.z, 0,
|
0, 0, node->scale.z, 0,
|
||||||
0, 0, 0, 1
|
0, 0, 0, 1
|
||||||
);
|
);
|
||||||
|
|
||||||
node->matrix = idMat4( mat3_identity, node->translation ) * node->rotation.ToMat4( ).Transpose( ) * scaleMat;
|
node->matrix = idMat4( mat3_identity, node->translation ) * node->rotation.ToMat4( ).Transpose( ) * scaleMat;
|
||||||
|
|
||||||
node->dirty = false;
|
node->dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//resolve full hierarchy
|
//resolve full hierarchy
|
||||||
if ( mat != nullptr ) {
|
if( mat != nullptr )
|
||||||
idList<gltfNode *> hierachy(2);
|
{
|
||||||
gltfNode *parent = node;
|
idList<gltfNode*> hierachy( 2 );
|
||||||
while ( parent ) {
|
gltfNode* parent = node;
|
||||||
ResolveNodeMatrix(parent);
|
while( parent )
|
||||||
|
{
|
||||||
|
ResolveNodeMatrix( parent );
|
||||||
hierachy.Append( parent );
|
hierachy.Append( parent );
|
||||||
if ( parent == root )
|
if( parent == root )
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
parent = parent->parent;
|
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;
|
*mat *= hierachy[i]->matrix;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Advance( gltfAnimation *anim = nullptr );
|
void Advance( gltfAnimation* anim = nullptr );
|
||||||
|
|
||||||
//this copies the data and view cached on the accessor
|
//this copies the data and view cached on the accessor
|
||||||
template <class T>
|
template <class T>
|
||||||
idList<T*> &GetAccessorView( gltfAccessor *accessor );
|
idList<T*>& GetAccessorView( gltfAccessor* accessor );
|
||||||
idList<float> &GetAccessorView( gltfAccessor *accessor );
|
idList<float>& GetAccessorView( gltfAccessor* accessor );
|
||||||
idList<idMat4> &GetAccessorViewMat( gltfAccessor *accessor );
|
idList<idMat4>& GetAccessorViewMat( gltfAccessor* accessor );
|
||||||
|
|
||||||
int &DefaultScene( ) { return scene; }
|
int& DefaultScene( )
|
||||||
|
{
|
||||||
|
return scene;
|
||||||
|
}
|
||||||
GLTFCACHEITEM( Buffer, buffers )
|
GLTFCACHEITEM( Buffer, buffers )
|
||||||
GLTFCACHEITEM( Sampler, samplers )
|
GLTFCACHEITEM( Sampler, samplers )
|
||||||
GLTFCACHEITEM( BufferView, bufferViews )
|
GLTFCACHEITEM( BufferView, bufferViews )
|
||||||
|
@ -805,34 +950,34 @@ public:
|
||||||
GLTFCACHEITEM( Extensions, extensions )
|
GLTFCACHEITEM( Extensions, extensions )
|
||||||
GLTFCACHEITEM( Animation, animations )
|
GLTFCACHEITEM( Animation, animations )
|
||||||
GLTFCACHEITEM( Skin, skins )
|
GLTFCACHEITEM( Skin, skins )
|
||||||
|
|
||||||
//gltfCameraManager * cameraManager;
|
//gltfCameraManager * cameraManager;
|
||||||
private:
|
private:
|
||||||
idStr fileName;
|
idStr fileName;
|
||||||
int fileNameHash;
|
int fileNameHash;
|
||||||
|
|
||||||
byte *json;
|
byte* json;
|
||||||
byte **data;
|
byte** data;
|
||||||
int jsonDataLength;
|
int jsonDataLength;
|
||||||
int totalChunks;
|
int totalChunks;
|
||||||
|
|
||||||
idList<gltfBuffer *> buffers;
|
idList<gltfBuffer*> buffers;
|
||||||
idList<gltfImage *> images;
|
idList<gltfImage*> images;
|
||||||
idList<gltfData *> assetData;
|
idList<gltfData*> assetData;
|
||||||
idList<gltfSampler *> samplers;
|
idList<gltfSampler*> samplers;
|
||||||
idList<gltfBufferView *> bufferViews;
|
idList<gltfBufferView*> bufferViews;
|
||||||
idList<gltfTexture *> textures;
|
idList<gltfTexture*> textures;
|
||||||
idList<gltfAccessor *> accessors;
|
idList<gltfAccessor*> accessors;
|
||||||
idList<gltfExtensionsUsed *> extensionsUsed;
|
idList<gltfExtensionsUsed*> extensionsUsed;
|
||||||
idList<gltfMesh *> meshes;
|
idList<gltfMesh*> meshes;
|
||||||
int scene;
|
int scene;
|
||||||
idList<gltfScene *> scenes;
|
idList<gltfScene*> scenes;
|
||||||
idList<gltfNode *> nodes;
|
idList<gltfNode*> nodes;
|
||||||
idList<gltfCamera *> cameras;
|
idList<gltfCamera*> cameras;
|
||||||
idList<gltfMaterial *> materials;
|
idList<gltfMaterial*> materials;
|
||||||
idList<gltfExtensions *> extensions;
|
idList<gltfExtensions*> extensions;
|
||||||
idList<gltfAnimation *> animations;
|
idList<gltfAnimation*> animations;
|
||||||
idList<gltfSkin *> skins;
|
idList<gltfSkin*> skins;
|
||||||
};
|
};
|
||||||
|
|
||||||
#undef GLTFCACHEITEM
|
#undef GLTFCACHEITEM
|
|
@ -342,14 +342,15 @@ idRenderModel* idRenderModelManagerLocal::GetModel( const char* _modelName, bool
|
||||||
|
|
||||||
idRenderModel* model = NULL;
|
idRenderModel* model = NULL;
|
||||||
// HvG: GLTF 2 support
|
// 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;
|
model = new( TAG_MODEL ) idRenderModelGLTF;
|
||||||
|
|
||||||
// RB: Collada DAE and Wavefront OBJ
|
// 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 )
|
else if( ( extension.Icmp( "dae" ) == 0 ) || ( extension.Icmp( "obj" ) == 0 ) // RB: Collada DAE and Wavefront OBJ
|
||||||
|| ( extension.Icmp( "flt" ) == 0 ) || ( extension.Icmp( "ma" ) == 0 ) )
|
|| ( extension.Icmp( "ase" ) == 0 ) || ( extension.Icmp( "lwo" ) == 0 )
|
||||||
|
|| ( extension.Icmp( "flt" ) == 0 ) || ( extension.Icmp( "ma" ) == 0 ) )
|
||||||
{
|
{
|
||||||
model = new( TAG_MODEL ) idRenderModelStatic;
|
model = new( TAG_MODEL ) idRenderModelStatic;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool idRenderModelStatic::ConvertGltfMeshToModelsurfaces( const gltfMesh *mesh ) {
|
bool idRenderModelStatic::ConvertGltfMeshToModelsurfaces( const gltfMesh* mesh )
|
||||||
|
{
|
||||||
|
|
||||||
//for ( auto mesh : currentAsset->MeshList( ) ) {
|
//for ( auto mesh : currentAsset->MeshList( ) ) {
|
||||||
// for ( auto prim : mesh->primitives ) {
|
// for ( auto prim : mesh->primitives ) {
|
||||||
|
@ -16,30 +17,37 @@ bool idRenderModelStatic::ConvertGltfMeshToModelsurfaces( const gltfMesh *mesh )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh *_mesh, gltfData *data ) {
|
void MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh* _mesh, gltfData* data )
|
||||||
for ( auto* gltfMesh : data->MeshList( ) ) {
|
{
|
||||||
for ( auto prim : gltfMesh->primitives ) {
|
for( auto* gltfMesh : data->MeshList( ) )
|
||||||
common->Printf("primitive for %s\n",gltfMesh->name.c_str() );
|
{
|
||||||
|
for( auto prim : gltfMesh->primitives )
|
||||||
|
{
|
||||||
|
common->Printf( "primitive for %s\n", gltfMesh->name.c_str() );
|
||||||
|
|
||||||
gltfAccessor *accessor = data->AccessorList( )[prim->indices];
|
gltfAccessor* accessor = data->AccessorList( )[prim->indices];
|
||||||
gltfBufferView *bv = data->BufferViewList( )[accessor->bufferView];
|
gltfBufferView* bv = data->BufferViewList( )[accessor->bufferView];
|
||||||
gltfData *data = bv->parent;
|
gltfData* data = bv->parent;
|
||||||
|
|
||||||
gltfBuffer *buff = data->BufferList( )[bv->buffer];
|
gltfBuffer* buff = data->BufferList( )[bv->buffer];
|
||||||
uint idxDataSize = sizeof( uint ) * accessor->count;
|
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",
|
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++ ) {
|
for( int i = 0; i < accessor->count; i++ )
|
||||||
idxBin.Read( ( void * ) ( &indices[i] ), accessor->typeSize );
|
{
|
||||||
if ( bv->byteStride )
|
idxBin.Read( ( void* )( &indices[i] ), accessor->typeSize );
|
||||||
|
if( bv->byteStride )
|
||||||
|
{
|
||||||
idxBin.Seek( bv->byteStride - accessor->typeSize, FS_SEEK_CUR );
|
idxBin.Seek( bv->byteStride - accessor->typeSize, FS_SEEK_CUR );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( int i = 0; i < accessor->count; i+=3 ) {
|
for( int i = 0; i < accessor->count; i += 3 )
|
||||||
MapPolygon &polygon = polygons.Alloc( );
|
{
|
||||||
|
MapPolygon& polygon = polygons.Alloc( );
|
||||||
polygon.SetMaterial( "textures/base_wall/lfwall27d" );
|
polygon.SetMaterial( "textures/base_wall/lfwall27d" );
|
||||||
polygon.AddIndex( indices[i + 1] );
|
polygon.AddIndex( indices[i + 1] );
|
||||||
polygon.AddIndex( indices[i + 2] );
|
polygon.AddIndex( indices[i + 2] );
|
||||||
|
@ -49,417 +57,514 @@ void MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh *_mesh, gltfData *data
|
||||||
Mem_Free( indices );
|
Mem_Free( indices );
|
||||||
bool sizeSet = false;
|
bool sizeSet = false;
|
||||||
|
|
||||||
for ( auto &attrib : prim->attributes ) {
|
for( auto& attrib : prim->attributes )
|
||||||
gltfAccessor *attrAcc = data->AccessorList( )[attrib->accessorIndex];
|
{
|
||||||
gltfBufferView *attrBv = data->BufferViewList( )[attrAcc->bufferView];
|
gltfAccessor* attrAcc = data->AccessorList( )[attrib->accessorIndex];
|
||||||
gltfData *attrData = attrBv->parent;
|
gltfBufferView* attrBv = data->BufferViewList( )[attrAcc->bufferView];
|
||||||
gltfBuffer *attrbuff = attrData->BufferList( )[attrBv->buffer];
|
gltfData* attrData = attrBv->parent;
|
||||||
|
gltfBuffer* attrbuff = attrData->BufferList( )[attrBv->buffer];
|
||||||
|
|
||||||
idFile_Memory bin = idFile_Memory( "gltfChunkVertices",
|
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 );
|
verts.AssureSize( attrAcc->count );
|
||||||
sizeSet = true;
|
sizeSet = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ( attrib->type ) {
|
switch( attrib->type )
|
||||||
case gltfMesh_Primitive_Attribute::Type::Position:
|
|
||||||
{
|
{
|
||||||
for ( int i = attrAcc->count-1; i >= 0; i-- ) {
|
case gltfMesh_Primitive_Attribute::Type::Position:
|
||||||
bin.Read( ( void * ) ( &verts[i].xyz.x ), attrAcc->typeSize );
|
{
|
||||||
bin.Read( ( void * ) ( &verts[i].xyz.y ), attrAcc->typeSize );
|
for( int i = attrAcc->count - 1; i >= 0; i-- )
|
||||||
bin.Read( ( void * ) ( &verts[i].xyz.z ), attrAcc->typeSize );
|
{
|
||||||
if ( attrBv->byteStride )
|
idVec3 pos;
|
||||||
bin.Seek( attrBv->byteStride - ( 3 * attrAcc->typeSize ), FS_SEEK_CUR );
|
|
||||||
|
|
||||||
idRandom rnd( i );
|
bin.Read( ( void* )( &pos.x ), attrAcc->typeSize );
|
||||||
int r = rnd.RandomInt( 255 ), g = rnd.RandomInt( 255 ), b = rnd.RandomInt( 255 );
|
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;
|
||||||
}
|
}
|
||||||
|
case gltfMesh_Primitive_Attribute::Type::Normal:
|
||||||
break;
|
{
|
||||||
}
|
|
||||||
case gltfMesh_Primitive_Attribute::Type::Normal:
|
|
||||||
{
|
|
||||||
idVec3 vec;
|
|
||||||
for ( int i = 0; i < attrAcc->count; i++ ) {
|
|
||||||
idVec3 vec;
|
idVec3 vec;
|
||||||
bin.Read( ( void * ) ( &vec.x ), attrAcc->typeSize );
|
for( int i = 0; i < attrAcc->count; i++ )
|
||||||
bin.Read( ( void * ) ( &vec.y ), attrAcc->typeSize );
|
{
|
||||||
bin.Read( ( void * ) ( &vec.z ), attrAcc->typeSize );
|
idVec3 vec;
|
||||||
if ( attrBv->byteStride )
|
bin.Read( ( void* )( &vec.x ), attrAcc->typeSize );
|
||||||
bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR );
|
bin.Read( ( void* )( &vec.y ), attrAcc->typeSize );
|
||||||
verts[i].SetNormal(vec);
|
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;
|
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);
|
|
||||||
}
|
}
|
||||||
|
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;
|
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::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();
|
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;
|
int entityCount = 0;
|
||||||
for ( auto & nodeID : data->SceneList()[sceneID]->nodes )
|
for( auto& nodeID : data->SceneList()[sceneID]->nodes )
|
||||||
{
|
{
|
||||||
auto * node = data->NodeList()[nodeID];
|
auto* node = data->NodeList()[nodeID];
|
||||||
auto * newEntity = new idMapEntity( );
|
|
||||||
|
|
||||||
bool isWorldSpawn = false;
|
idMapEntity* newEntity = NULL;
|
||||||
|
|
||||||
//set name and retrieve epairs from node extras
|
bool isWorldSpawn = idStr::Icmp( node->extras.strPairs.GetString( "classname" ), "worldspawn" ) == 0;
|
||||||
if ( node->name.Length() )
|
if( isWorldSpawn )
|
||||||
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() )
|
|
||||||
{
|
{
|
||||||
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( );
|
MapPolygonMesh* meshPrim = new MapPolygonMesh();
|
||||||
meshPrim->epairs.Copy( newEntity->epairs );
|
//meshPrim->epairs.Copy( newEntity->epairs );
|
||||||
|
|
||||||
meshPrim->ConvertFromMeshGltf(data->MeshList()[node->mesh],data);
|
meshPrim->ConvertFromMeshGltf( data->MeshList()[node->mesh], data );
|
||||||
newEntity->AddPrimitive(meshPrim);
|
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
|
// move world spawn to first place
|
||||||
for ( int i = 1; i < entities.Num( ); i++ ) {
|
for( int i = 1; i < entities.Num( ); i++ )
|
||||||
if ( idStr::Icmp( entities[i]->epairs.GetString( "name" ), "worldspawn" ) == 0 ) {
|
{
|
||||||
idMapEntity *tmp = entities[0];
|
if( idStr::Icmp( entities[i]->epairs.GetString( "name" ), "worldspawn" ) == 0 )
|
||||||
|
{
|
||||||
|
idMapEntity* tmp = entities[0];
|
||||||
entities[0] = entities[i];
|
entities[0] = entities[i];
|
||||||
entities[i] = tmp;
|
entities[i] = tmp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return entityCount;
|
return entityCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// [filename].[%i|%s].[gltf/glb]
|
// [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;
|
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;
|
idStr id;
|
||||||
idPart.ExtractFileExtension(id);
|
idPart.ExtractFileExtension( id );
|
||||||
|
|
||||||
if ( !id.Length() )
|
if( !id.Length() )
|
||||||
{
|
{
|
||||||
idLib::Warning( "no gltf mesh identifier");
|
idLib::Warning( "no gltf mesh identifier" );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
filename = idPart.Left(idPart.Length()-id.Length()) + extension;
|
filename = idPart.Left( idPart.Length() - id.Length() ) + extension;
|
||||||
|
|
||||||
idLexer lexer( LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
idLexer lexer( LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
||||||
lexer.LoadMemory( id.c_str( ), id.Size( ), "GltfmeshID", 0 );
|
lexer.LoadMemory( id.c_str( ), id.Size( ), "GltfmeshID", 0 );
|
||||||
|
|
||||||
idToken token;
|
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();
|
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;
|
meshName = id;
|
||||||
else {
|
}
|
||||||
lexer.Warning("malformed gltf mesh identifier" );
|
else
|
||||||
|
{
|
||||||
|
lexer.Warning( "malformed gltf mesh identifier" );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}else
|
}
|
||||||
lexer.Warning("malformed gltf mesh identifier" );
|
else
|
||||||
|
{
|
||||||
|
lexer.Warning( "malformed gltf mesh identifier" );
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void idRenderModelGLTF::InitFromFile( const char *fileName ) {
|
void idRenderModelGLTF::InitFromFile( const char* fileName )
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
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." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return false;
|
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." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool idRenderModelGLTF::SupportsBinaryModel( ) {
|
bool idRenderModelGLTF::SupportsBinaryModel( )
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return false;
|
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." );
|
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." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
}
|
}
|
||||||
|
|
||||||
void idRenderModelGLTF::PurgeModel( ) {
|
void idRenderModelGLTF::PurgeModel( )
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
}
|
}
|
||||||
|
|
||||||
void idRenderModelGLTF::Reset( ) {
|
void idRenderModelGLTF::Reset( )
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
}
|
}
|
||||||
|
|
||||||
void idRenderModelGLTF::LoadModel( ) {
|
void idRenderModelGLTF::LoadModel( )
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool idRenderModelGLTF::IsLoaded( ) {
|
bool idRenderModelGLTF::IsLoaded( )
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void idRenderModelGLTF::SetLevelLoadReferenced( bool referenced ) {
|
void idRenderModelGLTF::SetLevelLoadReferenced( bool referenced )
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool idRenderModelGLTF::IsLevelLoadReferenced( ) {
|
bool idRenderModelGLTF::IsLevelLoadReferenced( )
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void idRenderModelGLTF::TouchData( ) {
|
void idRenderModelGLTF::TouchData( )
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
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." );
|
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." );
|
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." );
|
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." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
}
|
}
|
||||||
|
|
||||||
void idRenderModelGLTF::FreeVertexCache( ) {
|
void idRenderModelGLTF::FreeVertexCache( )
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
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." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void idRenderModelGLTF::Print( ) const {
|
void idRenderModelGLTF::Print( ) const
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
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." );
|
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." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ID_TIME_T idRenderModelGLTF::Timestamp( ) const {
|
ID_TIME_T idRenderModelGLTF::Timestamp( ) const
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return FILE_NOT_FOUND_TIMESTAMP;
|
return FILE_NOT_FOUND_TIMESTAMP;
|
||||||
}
|
}
|
||||||
|
|
||||||
int idRenderModelGLTF::NumSurfaces( ) const {
|
int idRenderModelGLTF::NumSurfaces( ) const
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int idRenderModelGLTF::NumBaseSurfaces( ) const {
|
int idRenderModelGLTF::NumBaseSurfaces( ) const
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return -1;
|
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." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return nullptr;
|
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." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return nullptr;
|
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." );
|
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." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
dynamicModel_t idRenderModelGLTF::IsDynamicModel( ) const {
|
dynamicModel_t idRenderModelGLTF::IsDynamicModel( ) const
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return dynamicModel_t();
|
return dynamicModel_t();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool idRenderModelGLTF::IsDefaultModel( ) const {
|
bool idRenderModelGLTF::IsDefaultModel( ) const
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool idRenderModelGLTF::IsReloadable( ) const {
|
bool idRenderModelGLTF::IsReloadable( ) const
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return false;
|
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." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int idRenderModelGLTF::NumJoints( ) const {
|
int idRenderModelGLTF::NumJoints( ) const
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const idMD5Joint *idRenderModelGLTF::GetJoints( ) const {
|
const idMD5Joint* idRenderModelGLTF::GetJoints( ) const
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return nullptr;
|
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." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return jointHandle_t();
|
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." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
const idJointQuat *idRenderModelGLTF::GetDefaultPose( ) const {
|
const idJointQuat* idRenderModelGLTF::GetDefaultPose( ) const
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return nullptr;
|
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." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return -1;
|
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." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return idBounds();
|
return idBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
void idRenderModelGLTF::ReadFromDemoFile( class idDemoFile *f ) {
|
void idRenderModelGLTF::ReadFromDemoFile( class idDemoFile* f )
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
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." );
|
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." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return -1.0f;
|
return -1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool idRenderModelGLTF::ModelHasDrawingSurfaces( ) const {
|
bool idRenderModelGLTF::ModelHasDrawingSurfaces( ) const
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool idRenderModelGLTF::ModelHasInteractingSurfaces( ) const {
|
bool idRenderModelGLTF::ModelHasInteractingSurfaces( ) const
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool idRenderModelGLTF::ModelHasShadowCastingSurfaces( ) const {
|
bool idRenderModelGLTF::ModelHasShadowCastingSurfaces( ) const
|
||||||
|
{
|
||||||
common->Warning( "The method or operation is not implemented." );
|
common->Warning( "The method or operation is not implemented." );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,31 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "Model_local.h"
|
#include "Model_local.h"
|
||||||
|
|
||||||
class gltfManager {
|
class gltfManager
|
||||||
public:
|
|
||||||
static bool ExtractMeshIdentifier(idStr& filename , int & meshId, idStr & meshName );
|
|
||||||
};
|
|
||||||
|
|
||||||
class idGltfMesh
|
|
||||||
{
|
{
|
||||||
public:
|
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:
|
private:
|
||||||
gltfMesh * mesh;
|
gltfMesh* mesh;
|
||||||
gltfData * data;
|
gltfData* data;
|
||||||
};
|
};
|
||||||
|
|
||||||
class idRenderModelGLTF : public idRenderModelStatic
|
class idRenderModelGLTF : public idRenderModelStatic
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void InitFromFile( const char *fileName ) override;
|
void InitFromFile( const char* fileName ) override;
|
||||||
bool LoadBinaryModel( idFile *file, const ID_TIME_T sourceTimeStamp ) override;
|
bool LoadBinaryModel( idFile* file, const ID_TIME_T sourceTimeStamp ) override;
|
||||||
void WriteBinaryModel( idFile *file, ID_TIME_T *_timeStamp = NULL ) const override;
|
void WriteBinaryModel( idFile* file, ID_TIME_T* _timeStamp = NULL ) const override;
|
||||||
bool SupportsBinaryModel( ) override;
|
bool SupportsBinaryModel( ) override;
|
||||||
void ExportOBJ( idFile *objFile, idFile *mtlFile, ID_TIME_T *_timeStamp = NULL ) override;
|
void ExportOBJ( idFile* objFile, idFile* mtlFile, ID_TIME_T* _timeStamp = NULL ) override;
|
||||||
void PartialInitFromFile( const char *fileName ) override;
|
void PartialInitFromFile( const char* fileName ) override;
|
||||||
void PurgeModel( ) override;
|
void PurgeModel( ) override;
|
||||||
void Reset( ) override;
|
void Reset( ) override;
|
||||||
void LoadModel( ) override;
|
void LoadModel( ) override;
|
||||||
|
@ -32,35 +33,35 @@ public:
|
||||||
void SetLevelLoadReferenced( bool referenced ) override;
|
void SetLevelLoadReferenced( bool referenced ) override;
|
||||||
bool IsLevelLoadReferenced( ) override;
|
bool IsLevelLoadReferenced( ) override;
|
||||||
void TouchData( ) override;
|
void TouchData( ) override;
|
||||||
void CreateBuffers( nvrhi::ICommandList *commandList ) override;
|
void CreateBuffers( nvrhi::ICommandList* commandList ) override;
|
||||||
void InitEmpty( const char *name ) override;
|
void InitEmpty( const char* name ) override;
|
||||||
void AddSurface( modelSurface_t surface ) override;
|
void AddSurface( modelSurface_t surface ) override;
|
||||||
void FinishSurfaces( bool useMikktspace ) override;
|
void FinishSurfaces( bool useMikktspace ) override;
|
||||||
void FreeVertexCache( ) override;
|
void FreeVertexCache( ) override;
|
||||||
const char *Name( ) const override;
|
const char* Name( ) const override;
|
||||||
void Print( ) const override;
|
void Print( ) const override;
|
||||||
void List( ) const override;
|
void List( ) const override;
|
||||||
int Memory( ) const override;
|
int Memory( ) const override;
|
||||||
ID_TIME_T Timestamp( ) const override;
|
ID_TIME_T Timestamp( ) const override;
|
||||||
int NumSurfaces( ) const override;
|
int NumSurfaces( ) const override;
|
||||||
int NumBaseSurfaces( ) const override;
|
int NumBaseSurfaces( ) const override;
|
||||||
const modelSurface_t *Surface( int surfaceNum ) const override;
|
const modelSurface_t* Surface( int surfaceNum ) const override;
|
||||||
srfTriangles_t *AllocSurfaceTriangles( int numVerts, int numIndexes ) const override;
|
srfTriangles_t* AllocSurfaceTriangles( int numVerts, int numIndexes ) const override;
|
||||||
void FreeSurfaceTriangles( srfTriangles_t *tris ) const override;
|
void FreeSurfaceTriangles( srfTriangles_t* tris ) const override;
|
||||||
bool IsStaticWorldModel( ) const override;
|
bool IsStaticWorldModel( ) const override;
|
||||||
dynamicModel_t IsDynamicModel( ) const override;
|
dynamicModel_t IsDynamicModel( ) const override;
|
||||||
bool IsDefaultModel( ) const override;
|
bool IsDefaultModel( ) const override;
|
||||||
bool IsReloadable( ) 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;
|
int NumJoints( ) const override;
|
||||||
const idMD5Joint *GetJoints( ) const override;
|
const idMD5Joint* GetJoints( ) const override;
|
||||||
jointHandle_t GetJointHandle( const char *name ) const override;
|
jointHandle_t GetJointHandle( const char* name ) const override;
|
||||||
const char *GetJointName( jointHandle_t handle ) const override;
|
const char* GetJointName( jointHandle_t handle ) const override;
|
||||||
const idJointQuat *GetDefaultPose( ) const override;
|
const idJointQuat* GetDefaultPose( ) const override;
|
||||||
int NearestJoint( int surfaceNum, int a, int b, int c ) const override;
|
int NearestJoint( int surfaceNum, int a, int b, int c ) const override;
|
||||||
idBounds Bounds( const struct renderEntity_s *ent ) const override;
|
idBounds Bounds( const struct renderEntity_s* ent ) const override;
|
||||||
void ReadFromDemoFile( class idDemoFile *f ) override;
|
void ReadFromDemoFile( class idDemoFile* f ) override;
|
||||||
void WriteToDemoFile( class idDemoFile *f ) override;
|
void WriteToDemoFile( class idDemoFile* f ) override;
|
||||||
float DepthHack( ) const override;
|
float DepthHack( ) const override;
|
||||||
bool ModelHasDrawingSurfaces( ) const override;
|
bool ModelHasDrawingSurfaces( ) const override;
|
||||||
bool ModelHasInteractingSurfaces( ) const override;
|
bool ModelHasInteractingSurfaces( ) const override;
|
||||||
|
|
|
@ -128,8 +128,8 @@ public:
|
||||||
bool ConvertASEToModelSurfaces( const struct aseModel_s* ase );
|
bool ConvertASEToModelSurfaces( const struct aseModel_s* ase );
|
||||||
bool ConvertLWOToModelSurfaces( const struct st_lwObject* lwo );
|
bool ConvertLWOToModelSurfaces( const struct st_lwObject* lwo );
|
||||||
bool ConvertMAToModelSurfaces( const struct maModel_s* ma );
|
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 );
|
struct aseModel_s* ConvertLWOToASE( const struct st_lwObject* obj, const char* fileName );
|
||||||
|
|
||||||
bool DeleteSurfaceWithId( int id );
|
bool DeleteSurfaceWithId( int id );
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue