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
|
@ -1507,31 +1507,43 @@ Skips until a matching close brace is found.
|
|||
Internal brace depths are properly skipped.
|
||||
=================
|
||||
*/
|
||||
int idLexer::SkipBracedSection( bool parseFirstBrace, braceSkipMode_t skipMode/* = BRSKIP_BRACE */, int * skipped /*= nullptr*/) {
|
||||
int idLexer::SkipBracedSection( bool parseFirstBrace, braceSkipMode_t skipMode/* = BRSKIP_BRACE */, int* skipped /*= nullptr*/ )
|
||||
{
|
||||
idToken token;
|
||||
int depth;
|
||||
idStr openTokens[2] = { "{" , "[" };
|
||||
idStr closeTokens[2] = { "}" , "]" };
|
||||
|
||||
if( skipped != nullptr )
|
||||
{
|
||||
*skipped = 0;
|
||||
}
|
||||
|
||||
int scopeCount = 0;
|
||||
depth = parseFirstBrace ? 0 : 1;
|
||||
do {
|
||||
if ( !ReadToken( &token ) ) {
|
||||
do
|
||||
{
|
||||
if( !ReadToken( &token ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( token.type == TT_PUNCTUATION ) {
|
||||
if ( token == openTokens[skipMode] ) {
|
||||
if( token.type == TT_PUNCTUATION )
|
||||
{
|
||||
if( token == openTokens[skipMode] )
|
||||
{
|
||||
depth++;
|
||||
if( skipped != nullptr )
|
||||
{
|
||||
( *skipped )++;
|
||||
} else if ( token == closeTokens[skipMode] ) {
|
||||
}
|
||||
}
|
||||
else if( token == closeTokens[skipMode] )
|
||||
{
|
||||
depth--;
|
||||
}
|
||||
}
|
||||
} while( depth );
|
||||
}
|
||||
while( depth );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,8 @@ typedef enum
|
|||
LEXFL_ONLYSTRINGS = BIT( 13 ) // parse as whitespace deliminated strings (quoted strings keep quotes)
|
||||
} lexerFlags_t;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
BRSKIP_BRACES,
|
||||
BRSKIP_BRACKET
|
||||
} braceSkipMode_t;
|
||||
|
|
|
@ -1574,7 +1574,8 @@ bool idMapFile::Parse( const char* filename, bool ignoreRegion, bool osPath )
|
|||
}
|
||||
|
||||
bool isGTLF = false;
|
||||
if ( !src.IsLoaded( ) ) {
|
||||
if( !src.IsLoaded( ) )
|
||||
{
|
||||
// HVG: try loading a .gltf/glb second
|
||||
fullName.SetFileExtension( "glb" );
|
||||
isGTLF = src.LoadFile( fullName, osPath );
|
||||
|
@ -1672,7 +1673,8 @@ bool idMapFile::Parse( const char* filename, bool ignoreRegion, bool osPath )
|
|||
{
|
||||
gltfParser->Load( fullName );
|
||||
idMapEntity::GetEntities( gltfParser->currentAsset, entities, 0 );
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
if( token == "Version" )
|
||||
{
|
||||
|
|
|
@ -368,7 +368,8 @@ public:
|
|||
return verts.Append( v );
|
||||
}
|
||||
|
||||
int AddVertices( const idList<idDrawVert> &v ) {
|
||||
int AddVertices( const idList<idDrawVert>& v )
|
||||
{
|
||||
return verts.Append( v );
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
|
||||
extern idCVar gltf_parseVerbose;
|
||||
|
||||
void gltfExtra_Scatter::parse( idToken &token, idLexer * parser ) {
|
||||
void gltfExtra_Scatter::parse( idToken& token, idLexer* parser )
|
||||
{
|
||||
|
||||
parser->UnreadToken( &token );
|
||||
|
||||
|
@ -13,7 +14,8 @@ void gltfExtra_Scatter::parse( idToken &token, idLexer * parser ) {
|
|||
scatterInfo.Parse( parser, true );
|
||||
}
|
||||
|
||||
void gltfExtra_cvar::parse( idToken &token, idLexer *parser ) {
|
||||
void gltfExtra_cvar::parse( idToken& token, idLexer* parser )
|
||||
{
|
||||
|
||||
parser->UnreadToken( &token );
|
||||
gltfItemArray cvarInfo;
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
#ifndef GLTF_EXTRAS_H
|
||||
#define GLTF_EXTRAS_H
|
||||
|
||||
class test {
|
||||
class test
|
||||
{
|
||||
public:
|
||||
test() { }
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -6,7 +6,8 @@
|
|||
#pragma region GLTF Types parsing
|
||||
|
||||
#pragma region Parser interfaces
|
||||
struct parsable {
|
||||
struct parsable
|
||||
{
|
||||
public:
|
||||
virtual void parse( idToken& token ) = 0;
|
||||
virtual void parse( idToken& token , idLexer* parser ) {};
|
||||
|
@ -14,44 +15,77 @@ public:
|
|||
};
|
||||
|
||||
template<class T>
|
||||
class parseType {
|
||||
class parseType
|
||||
{
|
||||
public:
|
||||
void Set(T * type ) { item = type; }
|
||||
virtual ~parseType() { delete item; }
|
||||
void Set( T* type )
|
||||
{
|
||||
item = type;
|
||||
}
|
||||
virtual ~parseType()
|
||||
{
|
||||
delete item;
|
||||
}
|
||||
T* item;
|
||||
};
|
||||
|
||||
class gltfItem : public parsable, public parseType<idStr>
|
||||
{
|
||||
public:
|
||||
gltfItem( idStr Name) : name( Name ) { item = nullptr; }
|
||||
virtual void parse( idToken &token ) { *item = token; };
|
||||
virtual idStr &Name( ) {return name;}
|
||||
gltfItem( idStr Name ) : name( Name )
|
||||
{
|
||||
item = nullptr;
|
||||
}
|
||||
virtual void parse( idToken& token )
|
||||
{
|
||||
*item = token;
|
||||
};
|
||||
virtual idStr& Name( )
|
||||
{
|
||||
return name;
|
||||
}
|
||||
~gltfItem() {}
|
||||
private:
|
||||
idStr name;
|
||||
};
|
||||
|
||||
class gltfObject : public parsable, public parseType<idStr> {
|
||||
class gltfObject : public parsable, public parseType<idStr>
|
||||
{
|
||||
public:
|
||||
gltfObject( idStr Name ) : name( Name ), object( "null" ) {}
|
||||
virtual void parse( idToken& token ) {}
|
||||
virtual void parse(idToken & token , idLexer * parser){
|
||||
parser->UnreadToken( &token );parser->ParseBracedSection( object );
|
||||
virtual void parse( idToken& token , idLexer* parser )
|
||||
{
|
||||
parser->UnreadToken( &token );
|
||||
parser->ParseBracedSection( object );
|
||||
}
|
||||
virtual idStr& Name( )
|
||||
{
|
||||
return name;
|
||||
}
|
||||
virtual idStr &Name( ) { return name; }
|
||||
private:
|
||||
idStr name;
|
||||
idStr object;
|
||||
};
|
||||
|
||||
class gltfItemArray;
|
||||
class gltfItem_Extra : public parsable, public parseType<gltfExtra> {
|
||||
class gltfItem_Extra : public parsable, public parseType<gltfExtra>
|
||||
{
|
||||
public:
|
||||
gltfItem_Extra( idStr Name ) : name( Name ), data(nullptr),parser(nullptr) { item = nullptr; }
|
||||
gltfItem_Extra( idStr Name ) : name( Name ), data( nullptr ), parser( nullptr )
|
||||
{
|
||||
item = nullptr;
|
||||
}
|
||||
virtual void parse( idToken& token ) ;
|
||||
virtual idStr &Name( ) { return name; }
|
||||
void Set( gltfExtra *type, idLexer *lexer ) { parseType::Set( type ); parser = lexer; }
|
||||
virtual idStr& Name( )
|
||||
{
|
||||
return name;
|
||||
}
|
||||
void Set( gltfExtra* type, idLexer* lexer )
|
||||
{
|
||||
parseType::Set( type );
|
||||
parser = lexer;
|
||||
}
|
||||
static void Register( parsable* extra );
|
||||
private:
|
||||
idStr name;
|
||||
|
@ -60,12 +94,28 @@ private:
|
|||
static gltfItemArray* items;
|
||||
};
|
||||
|
||||
class gltfItem_uri : public parsable, public parseType<idStr> {
|
||||
class gltfItem_uri : public parsable, public parseType<idStr>
|
||||
{
|
||||
public:
|
||||
gltfItem_uri( idStr Name ) : name( Name ) { item = nullptr; }
|
||||
virtual void parse( idToken &token ) { *item = token; Convert(); };
|
||||
virtual idStr &Name( ) { return name; }
|
||||
void Set( idStr *type,int * targetBufferview,gltfData* dataDestination ) { parseType::Set(type); bufferView = targetBufferview; data = dataDestination; }
|
||||
gltfItem_uri( idStr Name ) : name( Name )
|
||||
{
|
||||
item = nullptr;
|
||||
}
|
||||
virtual void parse( idToken& token )
|
||||
{
|
||||
*item = token;
|
||||
Convert();
|
||||
};
|
||||
virtual idStr& Name( )
|
||||
{
|
||||
return name;
|
||||
}
|
||||
void Set( idStr* type, int* targetBufferview, gltfData* dataDestination )
|
||||
{
|
||||
parseType::Set( type );
|
||||
bufferView = targetBufferview;
|
||||
data = dataDestination;
|
||||
}
|
||||
// read data from uri file, and push it at end of current data buffer for this GLTF File
|
||||
// bufferView will be set accordingly to the generated buffer.
|
||||
bool Convert( );
|
||||
|
@ -135,20 +185,46 @@ private: \
|
|||
|
||||
gltfItemClass( integer, int, *item = token.GetIntValue( ); );
|
||||
gltfItemClass( number, float, *item = token.GetFloatValue( ); );
|
||||
gltfItemClass(boolean, bool, if (token.Icmp("true") == 0 ) *item=true; else{ if(token.Icmp("false") == 0)*item=false; else idLib::FatalError("parse error");});
|
||||
gltfItemClass( boolean, bool, if( token.Icmp( "true" ) == 0 ) *item = true; else
|
||||
{
|
||||
if( token.Icmp( "false" ) == 0 )
|
||||
{
|
||||
*item = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
idLib::FatalError( "parse error" );
|
||||
}
|
||||
} );
|
||||
#undef gltfItemClass
|
||||
|
||||
class gltfItemArray
|
||||
{
|
||||
public:
|
||||
~gltfItemArray( ) { items.DeleteContents(true); }
|
||||
~gltfItemArray( )
|
||||
{
|
||||
items.DeleteContents( true );
|
||||
}
|
||||
gltfItemArray( ) { };
|
||||
int Num() { return items.Num(); }
|
||||
void AddItemDef( parsable *item ) { items.Alloc( ) = item;}
|
||||
int Num()
|
||||
{
|
||||
return items.Num();
|
||||
}
|
||||
void AddItemDef( parsable* item )
|
||||
{
|
||||
items.Alloc( ) = item;
|
||||
}
|
||||
int Fill( idLexer* lexer , idDict* strPairs );
|
||||
int Parse( idLexer* lexer , bool forwardLexer = false );
|
||||
template<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:
|
||||
idList<parsable*> items;
|
||||
};
|
||||
|
@ -169,11 +245,16 @@ class gltfPropertyArray
|
|||
public:
|
||||
gltfPropertyArray( idLexer* Parser, bool AoS = true );
|
||||
~gltfPropertyArray( );
|
||||
struct Iterator {
|
||||
struct Iterator
|
||||
{
|
||||
gltfPropertyArray* array;
|
||||
gltfPropertyItem* p;
|
||||
gltfPropertyItem &operator*( ) {return *p;}
|
||||
bool operator != ( Iterator &rhs ) {
|
||||
gltfPropertyItem& operator*( )
|
||||
{
|
||||
return *p;
|
||||
}
|
||||
bool operator != ( Iterator& rhs )
|
||||
{
|
||||
return p != rhs.p;
|
||||
}
|
||||
void operator ++( );
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
#include "Lib.h"
|
||||
#include "containers/List.h"
|
||||
|
||||
enum gltfProperty {
|
||||
enum gltfProperty
|
||||
{
|
||||
INVALID,
|
||||
ASSET,
|
||||
ACCESSOR,
|
||||
|
@ -33,7 +34,8 @@ class gltfData;
|
|||
|
||||
struct gltf_accessor_component
|
||||
{
|
||||
enum Type {
|
||||
enum Type
|
||||
{
|
||||
_byte,
|
||||
_uByte,
|
||||
_short,
|
||||
|
@ -46,7 +48,8 @@ struct gltf_accessor_component
|
|||
};
|
||||
|
||||
template< class T >
|
||||
struct gltf_accessor_component_type_map {
|
||||
struct gltf_accessor_component_type_map
|
||||
{
|
||||
idStr stringID;
|
||||
int id;
|
||||
T type;
|
||||
|
@ -66,18 +69,21 @@ public:
|
|||
};
|
||||
|
||||
class gltfExt_KHR_lights_punctual;
|
||||
class gltfExtensions {
|
||||
class gltfExtensions
|
||||
{
|
||||
public:
|
||||
gltfExtensions( ) { }
|
||||
idList<gltfExt_KHR_lights_punctual*> KHR_lights_punctual;
|
||||
};
|
||||
|
||||
class gltfNode_KHR_lights_punctual {
|
||||
class gltfNode_KHR_lights_punctual
|
||||
{
|
||||
public:
|
||||
int light;
|
||||
};
|
||||
|
||||
class gltfNode_Extensions {
|
||||
class gltfNode_Extensions
|
||||
{
|
||||
public:
|
||||
gltfNode_Extensions( ) :
|
||||
KHR_lights_punctual( nullptr ) { }
|
||||
|
@ -85,7 +91,8 @@ public:
|
|||
};
|
||||
|
||||
class gltfExt_KHR_materials_pbrSpecularGlossiness;
|
||||
class gltfMaterial_Extensions {
|
||||
class gltfMaterial_Extensions
|
||||
{
|
||||
public:
|
||||
gltfMaterial_Extensions( ) :
|
||||
KHR_materials_pbrSpecularGlossiness( nullptr ) { }
|
||||
|
@ -93,7 +100,8 @@ public:
|
|||
};
|
||||
|
||||
|
||||
class gltfNode {
|
||||
class gltfNode
|
||||
{
|
||||
public:
|
||||
gltfNode( ) : camera( -1 ), skin( -1 ), matrix( mat4_zero ),
|
||||
mesh( -1 ), rotation( 0.f, 0.f, 0.f, 1.f ), scale( 1.f, 1.f, 1.f ),
|
||||
|
@ -116,12 +124,14 @@ public:
|
|||
bool dirty;
|
||||
};
|
||||
|
||||
struct gltfCameraNodePtrs {
|
||||
struct gltfCameraNodePtrs
|
||||
{
|
||||
gltfNode* translationNode = nullptr;
|
||||
gltfNode* orientationNode = nullptr;
|
||||
};
|
||||
|
||||
class gltfScene {
|
||||
class gltfScene
|
||||
{
|
||||
public:
|
||||
gltfScene( ) { }
|
||||
idList<int> nodes;
|
||||
|
@ -130,9 +140,11 @@ public:
|
|||
gltfExtra extras;
|
||||
};
|
||||
|
||||
class gltfMesh_Primitive_Attribute {
|
||||
class gltfMesh_Primitive_Attribute
|
||||
{
|
||||
public:
|
||||
enum Type {
|
||||
enum Type
|
||||
{
|
||||
Position,
|
||||
Normal,
|
||||
Tangent,
|
||||
|
@ -161,13 +173,15 @@ public:
|
|||
Type type;
|
||||
};
|
||||
|
||||
struct gltf_mesh_attribute_map {
|
||||
struct gltf_mesh_attribute_map
|
||||
{
|
||||
idStr stringID;
|
||||
gltfMesh_Primitive_Attribute::Type attib;
|
||||
uint elementSize;
|
||||
};
|
||||
|
||||
class gltfMesh_Primitive {
|
||||
class gltfMesh_Primitive
|
||||
{
|
||||
public:
|
||||
gltfMesh_Primitive( ) : indices( -1 ), material( -1 ), mode( -1 ) { }
|
||||
idList<gltfMesh_Primitive_Attribute*> attributes;
|
||||
|
@ -179,7 +193,8 @@ public:
|
|||
gltfExtra extras;
|
||||
};
|
||||
|
||||
class gltfMesh {
|
||||
class gltfMesh
|
||||
{
|
||||
public:
|
||||
gltfMesh( ) { };
|
||||
|
||||
|
@ -190,7 +205,8 @@ public:
|
|||
gltfExtra extras;
|
||||
};
|
||||
|
||||
class gltfCamera_Orthographic {
|
||||
class gltfCamera_Orthographic
|
||||
{
|
||||
public:
|
||||
gltfCamera_Orthographic( ) : xmag( 0.0f ), ymag( 0.0f ), zfar( 0.0f ), znear( 0.0f ) { };
|
||||
float xmag;
|
||||
|
@ -201,7 +217,8 @@ public:
|
|||
gltfExtra extras;
|
||||
};
|
||||
|
||||
class gltfCamera_Perspective {
|
||||
class gltfCamera_Perspective
|
||||
{
|
||||
public:
|
||||
gltfCamera_Perspective( ) : aspectRatio( 0.0f ), yfov( 0.0f ), zfar( 0.0f ), znear( 0.0f ) { };
|
||||
float aspectRatio;
|
||||
|
@ -212,7 +229,8 @@ public:
|
|||
gltfExtra extras;
|
||||
};
|
||||
|
||||
class gltfCamera {
|
||||
class gltfCamera
|
||||
{
|
||||
public:
|
||||
gltfCamera( ) { };
|
||||
gltfCamera_Orthographic orthographic;
|
||||
|
@ -223,7 +241,8 @@ public:
|
|||
gltfExtra extras;
|
||||
};
|
||||
|
||||
class gltfAnimation_Channel_Target {
|
||||
class gltfAnimation_Channel_Target
|
||||
{
|
||||
public:
|
||||
gltfAnimation_Channel_Target( ) : node( -1 ), TRS( gltfTRS::count ) { };
|
||||
int node;
|
||||
|
@ -231,7 +250,8 @@ public:
|
|||
idStr extensions;
|
||||
gltfExtra extras;
|
||||
|
||||
enum gltfTRS {
|
||||
enum gltfTRS
|
||||
{
|
||||
none,
|
||||
rotation,
|
||||
translation,
|
||||
|
@ -242,20 +262,30 @@ public:
|
|||
|
||||
gltfTRS TRS;
|
||||
|
||||
static gltfTRS resolveType( idStr type ) {
|
||||
static gltfTRS resolveType( idStr type )
|
||||
{
|
||||
if( type == "translation" )
|
||||
{
|
||||
return gltfTRS::translation;
|
||||
}
|
||||
else if( type == "rotation" )
|
||||
{
|
||||
return gltfTRS::rotation;
|
||||
}
|
||||
else if( type == "scale" )
|
||||
{
|
||||
return gltfTRS::scale;
|
||||
}
|
||||
else if( type == "weights" )
|
||||
{
|
||||
return gltfTRS::weights;
|
||||
}
|
||||
return gltfTRS::count;
|
||||
}
|
||||
};
|
||||
|
||||
class gltfAnimation_Channel {
|
||||
class gltfAnimation_Channel
|
||||
{
|
||||
public:
|
||||
gltfAnimation_Channel( ) : sampler( -1 ) { };
|
||||
int sampler;
|
||||
|
@ -264,7 +294,8 @@ public:
|
|||
gltfExtra extras;
|
||||
};
|
||||
|
||||
class gltfAnimation_Sampler {
|
||||
class gltfAnimation_Sampler
|
||||
{
|
||||
public:
|
||||
gltfAnimation_Sampler( ) : input( -1 ), interpolation( "LINEAR" ), output( -1 ), intType( gltfInterpType::count ) { };
|
||||
int input;
|
||||
|
@ -273,7 +304,8 @@ public:
|
|||
idStr extensions;
|
||||
gltfExtra extras;
|
||||
|
||||
enum gltfInterpType {
|
||||
enum gltfInterpType
|
||||
{
|
||||
linear,
|
||||
step,
|
||||
cubicSpline,
|
||||
|
@ -282,19 +314,27 @@ public:
|
|||
|
||||
gltfInterpType intType;
|
||||
|
||||
static gltfInterpType resolveType( idStr type ) {
|
||||
static gltfInterpType resolveType( idStr type )
|
||||
{
|
||||
if( type == "LINEAR" )
|
||||
{
|
||||
return gltfInterpType::linear;
|
||||
}
|
||||
else if( type == "STEP" )
|
||||
{
|
||||
return gltfInterpType::step;
|
||||
}
|
||||
else if( type == "CUBICSPLINE" )
|
||||
{
|
||||
return gltfInterpType::cubicSpline;
|
||||
}
|
||||
return gltfInterpType::count;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class gltfAnimation {
|
||||
class gltfAnimation
|
||||
{
|
||||
public:
|
||||
gltfAnimation( ) : maxTime( 0.0f ), numFrames( 0 ) { };
|
||||
idList<gltfAnimation_Channel*> channels;
|
||||
|
@ -308,16 +348,39 @@ public:
|
|||
//id specific
|
||||
mutable int ref_count;
|
||||
int numFrames;
|
||||
void DecreaseRefs() const {ref_count--;};
|
||||
void IncreaseRefs() const {ref_count++;};
|
||||
bool GetBounds( idBounds &bnds, int time, int cyclecount ) const { return false;}
|
||||
bool GetOriginRotation( idQuat &rotation, int time, int cyclecount ) const { return false;}
|
||||
bool GetOrigin( idVec3 &offset, int time, int cyclecount ) const { return false;}
|
||||
const idVec3 &TotalMovementDelta( void ) const {static idVec3 temp; return temp; }
|
||||
int NumFrames() const {return numFrames;}
|
||||
void DecreaseRefs() const
|
||||
{
|
||||
ref_count--;
|
||||
};
|
||||
void IncreaseRefs() const
|
||||
{
|
||||
ref_count++;
|
||||
};
|
||||
bool GetBounds( idBounds& bnds, int time, int cyclecount ) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool GetOriginRotation( idQuat& rotation, int time, int cyclecount ) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool GetOrigin( idVec3& offset, int time, int cyclecount ) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
const idVec3& TotalMovementDelta( void ) const
|
||||
{
|
||||
static idVec3 temp;
|
||||
return temp;
|
||||
}
|
||||
int NumFrames() const
|
||||
{
|
||||
return numFrames;
|
||||
}
|
||||
};
|
||||
|
||||
class gltfAccessor_Sparse_Values {
|
||||
class gltfAccessor_Sparse_Values
|
||||
{
|
||||
public:
|
||||
gltfAccessor_Sparse_Values( ) : bufferView( -1 ), byteOffset( -1 ) { };
|
||||
int bufferView;
|
||||
|
@ -326,7 +389,8 @@ public:
|
|||
gltfExtra extras;
|
||||
};
|
||||
|
||||
class gltfAccessor_Sparse_Indices {
|
||||
class gltfAccessor_Sparse_Indices
|
||||
{
|
||||
public:
|
||||
gltfAccessor_Sparse_Indices( ) : bufferView( -1 ), byteOffset( -1 ), componentType( -1 ) { };
|
||||
int bufferView;
|
||||
|
@ -336,7 +400,8 @@ public:
|
|||
gltfExtra extras;
|
||||
};
|
||||
|
||||
class gltfAccessor_Sparse {
|
||||
class gltfAccessor_Sparse
|
||||
{
|
||||
public:
|
||||
gltfAccessor_Sparse( ) : count( -1 ) { };
|
||||
int count;
|
||||
|
@ -346,7 +411,8 @@ public:
|
|||
gltfExtra extras;
|
||||
};
|
||||
|
||||
class gltfAccessor {
|
||||
class gltfAccessor
|
||||
{
|
||||
public:
|
||||
gltfAccessor( ) : bufferView( -1 ), byteOffset( 0 ), componentType( -1 ), normalized( false ), count( -1 ) ,
|
||||
floatView( nullptr ), vecView( nullptr ), quatView( nullptr ), matView( nullptr ) { }
|
||||
|
@ -371,7 +437,8 @@ public:
|
|||
idList<idMat4>* matView;
|
||||
};
|
||||
|
||||
class gltfBufferView {
|
||||
class gltfBufferView
|
||||
{
|
||||
public:
|
||||
gltfBufferView( ) : buffer( -1 ), byteLength( -1 ), byteStride( 0 ), byteOffset( 0 ), target( -1 ) { };
|
||||
int buffer;
|
||||
|
@ -386,7 +453,8 @@ public:
|
|||
gltfData* parent;
|
||||
};
|
||||
|
||||
class gltfBuffer {
|
||||
class gltfBuffer
|
||||
{
|
||||
public:
|
||||
gltfBuffer( ) : byteLength( -1 ), parent( nullptr ) { };
|
||||
idStr uri;
|
||||
|
@ -398,7 +466,8 @@ public:
|
|||
gltfData* parent;
|
||||
};
|
||||
|
||||
class gltfSampler {
|
||||
class gltfSampler
|
||||
{
|
||||
public:
|
||||
gltfSampler( ) : magFilter( 0 ), minFilter( 0 ), wrapS( 10497 ), wrapT( 10497 ) { };
|
||||
int magFilter;
|
||||
|
@ -412,7 +481,8 @@ public:
|
|||
uint bgfxSamplerFlags;
|
||||
};
|
||||
|
||||
class gltfImage {
|
||||
class gltfImage
|
||||
{
|
||||
public:
|
||||
gltfImage( ) : bufferView( -1 ) { }
|
||||
idStr uri;
|
||||
|
@ -423,7 +493,8 @@ public:
|
|||
gltfExtra extras;
|
||||
};
|
||||
|
||||
class gltfSkin {
|
||||
class gltfSkin
|
||||
{
|
||||
public:
|
||||
gltfSkin( ) : inverseBindMatrices( -1 ), skeleton( -1 ), name( "unnamedSkin" ) { };
|
||||
int inverseBindMatrices;
|
||||
|
@ -435,14 +506,16 @@ public:
|
|||
};
|
||||
|
||||
class gltfExt_KHR_texture_transform;
|
||||
class gltfTexture_Info_Extensions {
|
||||
class gltfTexture_Info_Extensions
|
||||
{
|
||||
public:
|
||||
gltfTexture_Info_Extensions( ) :
|
||||
KHR_texture_transform( nullptr ) { }
|
||||
gltfExt_KHR_texture_transform* KHR_texture_transform;
|
||||
};
|
||||
|
||||
class gltfOcclusionTexture_Info {
|
||||
class gltfOcclusionTexture_Info
|
||||
{
|
||||
public:
|
||||
gltfOcclusionTexture_Info( ) : index( -1 ), texCoord( 0 ), strength( 1.0f ) { }
|
||||
int index;
|
||||
|
@ -452,7 +525,8 @@ public:
|
|||
gltfExtra extras;
|
||||
};
|
||||
|
||||
class gltfNormalTexture_Info {
|
||||
class gltfNormalTexture_Info
|
||||
{
|
||||
public:
|
||||
gltfNormalTexture_Info( ) : index( -1 ), texCoord( 0 ), scale( 1.0f ) { }
|
||||
int index;
|
||||
|
@ -462,7 +536,8 @@ public:
|
|||
gltfExtra extras;
|
||||
};
|
||||
|
||||
class gltfTexture_Info {
|
||||
class gltfTexture_Info
|
||||
{
|
||||
public:
|
||||
gltfTexture_Info( ) : index( -1 ), texCoord( 0 ) { }
|
||||
int index;
|
||||
|
@ -472,7 +547,8 @@ public:
|
|||
};
|
||||
|
||||
|
||||
class gltfTexture {
|
||||
class gltfTexture
|
||||
{
|
||||
public:
|
||||
gltfTexture( ) : sampler( -1 ), source( -1 ) { }
|
||||
int sampler;
|
||||
|
@ -482,7 +558,8 @@ public:
|
|||
gltfExtra extras;
|
||||
};
|
||||
|
||||
class gltfMaterial_pbrMetallicRoughness {
|
||||
class gltfMaterial_pbrMetallicRoughness
|
||||
{
|
||||
public:
|
||||
gltfMaterial_pbrMetallicRoughness( ) : baseColorFactor( vec4_one ), metallicFactor( 1.0f ), roughnessFactor( 1.0f ) { }
|
||||
idVec4 baseColorFactor;
|
||||
|
@ -494,9 +571,11 @@ public:
|
|||
gltfExtra extras;
|
||||
};
|
||||
|
||||
class gltfMaterial {
|
||||
class gltfMaterial
|
||||
{
|
||||
public:
|
||||
enum gltfAlphaMode {
|
||||
enum gltfAlphaMode
|
||||
{
|
||||
gltfOPAQUE,
|
||||
gltfMASK,
|
||||
gltfBLEND,
|
||||
|
@ -518,18 +597,26 @@ public:
|
|||
|
||||
gltfAlphaMode intType;
|
||||
|
||||
static gltfAlphaMode resolveAlphaMode( idStr type ) {
|
||||
static gltfAlphaMode resolveAlphaMode( idStr type )
|
||||
{
|
||||
if( type == "OPAQUE" )
|
||||
{
|
||||
return gltfAlphaMode::gltfOPAQUE;
|
||||
}
|
||||
else if( type == "MASK" )
|
||||
{
|
||||
return gltfAlphaMode::gltfMASK;
|
||||
}
|
||||
else if( type == "BLEND" )
|
||||
{
|
||||
return gltfAlphaMode::gltfBLEND;
|
||||
}
|
||||
return gltfAlphaMode::count;
|
||||
}
|
||||
};
|
||||
|
||||
class gltfAsset {
|
||||
class gltfAsset
|
||||
{
|
||||
public:
|
||||
gltfAsset( ) { }
|
||||
idStr copyright;
|
||||
|
@ -542,7 +629,8 @@ public:
|
|||
|
||||
//this is not used.
|
||||
//if an extension is found, it _will_ be used. (if implemented)
|
||||
class gltfExtensionsUsed {
|
||||
class gltfExtensionsUsed
|
||||
{
|
||||
public:
|
||||
gltfExtensionsUsed( ) { }
|
||||
idStr extension;
|
||||
|
@ -565,7 +653,8 @@ public:
|
|||
|
||||
//KHR_lights_punctual_spot
|
||||
//https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_lights_punctual/schema/light.spot.schema.json
|
||||
class gltfExt_KHR_lights_punctual_spot {
|
||||
class gltfExt_KHR_lights_punctual_spot
|
||||
{
|
||||
public:
|
||||
gltfExt_KHR_lights_punctual_spot( ) : innerConeAngle( 0.0f ), outerConeAngle( idMath::ONEFOURTH_PI ) { }
|
||||
float innerConeAngle;
|
||||
|
@ -577,7 +666,8 @@ typedef gltfExt_KHR_lights_punctual_spot spot;
|
|||
|
||||
//KHR_lights_punctual
|
||||
//https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_lights_punctual/schema/light.schema.json
|
||||
class gltfExt_KHR_lights_punctual {
|
||||
class gltfExt_KHR_lights_punctual
|
||||
{
|
||||
public:
|
||||
gltfExt_KHR_lights_punctual( ) : color( vec3_one ), intensity( 1.0f ), range( -1.0f ), intType( -1 ) { }
|
||||
idVec3 color;
|
||||
|
@ -591,20 +681,28 @@ public:
|
|||
|
||||
int intType;
|
||||
|
||||
static int resolveType( idStr type ) {
|
||||
static int resolveType( idStr type )
|
||||
{
|
||||
if( type == "directional" )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if( type == "point" )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if( type == "spot" )
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
//KHR_texture_transform
|
||||
//https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_transform/schema/KHR_texture_transform.textureInfo.schema.json
|
||||
class gltfExt_KHR_texture_transform {
|
||||
class gltfExt_KHR_texture_transform
|
||||
{
|
||||
public:
|
||||
gltfExt_KHR_texture_transform( ) : offset( vec2_zero ), rotation( 0.0f ), scale( vec2_one ), texCoord( -1 ), index( 0 ), resolved( false ) { }
|
||||
idVec2 offset;
|
||||
|
@ -631,30 +729,58 @@ const inline idList<gltf##name*> & ##name##List() { return target; }
|
|||
// EACH URI will have an unique chunk
|
||||
// JSON chunk MUST be the first one to be allocated/added
|
||||
|
||||
class gltfData {
|
||||
class gltfData
|
||||
{
|
||||
public:
|
||||
gltfData( ) : fileNameHash( 0 ), json( nullptr ), data( nullptr ), totalChunks( -1 ) { };
|
||||
~gltfData( );
|
||||
byte* AddData( int size, int* bufferID = nullptr );
|
||||
byte *GetJsonData( int &size ) { size = jsonDataLength; return json; }
|
||||
byte *GetData( int index ) { return data[index]; }
|
||||
void FileName( const idStr &file ) { fileName = file; fileNameHash = fileDataHash.GenerateKey( file.c_str( ) ); }
|
||||
int FileNameHash( ) { return fileNameHash; }
|
||||
idStr &FileName( ) { return fileName; }
|
||||
byte* GetJsonData( int& size )
|
||||
{
|
||||
size = jsonDataLength;
|
||||
return json;
|
||||
}
|
||||
byte* GetData( int index )
|
||||
{
|
||||
return data[index];
|
||||
}
|
||||
void FileName( const idStr& file )
|
||||
{
|
||||
fileName = file;
|
||||
fileNameHash = fileDataHash.GenerateKey( file.c_str( ) );
|
||||
}
|
||||
int FileNameHash( )
|
||||
{
|
||||
return fileNameHash;
|
||||
}
|
||||
idStr& FileName( )
|
||||
{
|
||||
return fileName;
|
||||
}
|
||||
|
||||
static idHashIndex fileDataHash;
|
||||
static idList<gltfData*> dataList;
|
||||
//add data from filename
|
||||
static gltfData *Data( idStr &fileName ) {
|
||||
static gltfData* Data( idStr& fileName )
|
||||
{
|
||||
dataList.AssureSizeAlloc( dataList.Num( ) + 1, idListNewElement<gltfData> );
|
||||
dataList[dataList.Num( ) - 1]->FileName( fileName );
|
||||
fileDataHash.Add( fileDataHash.GenerateKey( fileName ), dataList.Num( ) - 1 );
|
||||
return dataList[dataList.Num( ) - 1];
|
||||
}
|
||||
//find data;
|
||||
static gltfData *Data( const char *filename ) { return dataList[fileDataHash.First( fileDataHash.GenerateKey( filename ) )]; }
|
||||
static const idList<gltfData *> &DataList( ) { return dataList; }
|
||||
static void ClearData( ) { idLib::Warning( "TODO! DATA NOT FREED" ); }
|
||||
static gltfData* Data( const char* filename )
|
||||
{
|
||||
return dataList[fileDataHash.First( fileDataHash.GenerateKey( filename ) )];
|
||||
}
|
||||
static const idList<gltfData*>& DataList( )
|
||||
{
|
||||
return dataList;
|
||||
}
|
||||
static void ClearData( )
|
||||
{
|
||||
idLib::Warning( "TODO! DATA NOT FREED" );
|
||||
}
|
||||
|
||||
//return the GLTF nodes that control the given camera
|
||||
//return TRUE if the camera uses 2 nodes (like when blender exports gltfs with +Y..)
|
||||
|
@ -671,14 +797,18 @@ public:
|
|||
{
|
||||
camId++;
|
||||
if( cam == camera )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for( int i = 0; i < nodes.Num( ); i++ )
|
||||
{
|
||||
if( nodes[i]->camera != -1 && nodes[i]->camera == camId )
|
||||
{
|
||||
return nodes[i];
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -701,7 +831,8 @@ public:
|
|||
if( nodes[i]->camera != -1 && nodes[i]->camera == camId )
|
||||
{
|
||||
parent = nodes[i];
|
||||
while ( parent ) {
|
||||
while( parent )
|
||||
{
|
||||
hierachy.Append( parent );
|
||||
parent = parent->parent;
|
||||
}
|
||||
|
@ -726,10 +857,13 @@ public:
|
|||
gltfNode* parent = nullptr;
|
||||
hierachy.SetGranularity( 2 );
|
||||
|
||||
for ( int i = 0; i < nodes.Num( ); i++ ) {
|
||||
if ( nodes[i]->extensions.KHR_lights_punctual && nodes[i]->extensions.KHR_lights_punctual->light == lightId ) {
|
||||
for( int i = 0; i < nodes.Num( ); i++ )
|
||||
{
|
||||
if( nodes[i]->extensions.KHR_lights_punctual && nodes[i]->extensions.KHR_lights_punctual->light == lightId )
|
||||
{
|
||||
parent = nodes[i];
|
||||
while ( parent ) {
|
||||
while( parent )
|
||||
{
|
||||
hierachy.Append( parent );
|
||||
parent = parent->parent;
|
||||
}
|
||||
|
@ -738,7 +872,9 @@ public:
|
|||
}
|
||||
|
||||
for( int i = hierachy.Num( ) - 1; i >= 0; i-- )
|
||||
{
|
||||
result *= hierachy[i]->matrix;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -766,20 +902,26 @@ public:
|
|||
}
|
||||
|
||||
//resolve full hierarchy
|
||||
if ( mat != nullptr ) {
|
||||
if( mat != nullptr )
|
||||
{
|
||||
idList<gltfNode*> hierachy( 2 );
|
||||
gltfNode* parent = node;
|
||||
while ( parent ) {
|
||||
while( parent )
|
||||
{
|
||||
ResolveNodeMatrix( parent );
|
||||
hierachy.Append( parent );
|
||||
if( parent == root )
|
||||
{
|
||||
break;
|
||||
}
|
||||
parent = parent->parent;
|
||||
}
|
||||
for( int i = hierachy.Num( ) - 1; i >= 0; i-- )
|
||||
{
|
||||
*mat *= hierachy[i]->matrix;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Advance( gltfAnimation* anim = nullptr );
|
||||
|
||||
|
@ -789,7 +931,10 @@ public:
|
|||
idList<float>& GetAccessorView( gltfAccessor* accessor );
|
||||
idList<idMat4>& GetAccessorViewMat( gltfAccessor* accessor );
|
||||
|
||||
int &DefaultScene( ) { return scene; }
|
||||
int& DefaultScene( )
|
||||
{
|
||||
return scene;
|
||||
}
|
||||
GLTFCACHEITEM( Buffer, buffers )
|
||||
GLTFCACHEITEM( Sampler, samplers )
|
||||
GLTFCACHEITEM( BufferView, bufferViews )
|
||||
|
|
|
@ -347,7 +347,8 @@ idRenderModel* idRenderModelManagerLocal::GetModel( const char* _modelName, bool
|
|||
model = new( TAG_MODEL ) idRenderModelGLTF;
|
||||
|
||||
// RB: Collada DAE and Wavefront OBJ
|
||||
}else if ( ( extension.Icmp( "dae" ) == 0 ) || ( extension.Icmp( "obj" ) == 0 ) // RB: Collada DAE and Wavefront OBJ
|
||||
}
|
||||
else if( ( extension.Icmp( "dae" ) == 0 ) || ( extension.Icmp( "obj" ) == 0 ) // RB: Collada DAE and Wavefront OBJ
|
||||
|| ( extension.Icmp( "ase" ) == 0 ) || ( extension.Icmp( "lwo" ) == 0 )
|
||||
|| ( extension.Icmp( "flt" ) == 0 ) || ( extension.Icmp( "ma" ) == 0 ) )
|
||||
{
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
|
||||
|
||||
|
||||
bool idRenderModelStatic::ConvertGltfMeshToModelsurfaces( const gltfMesh *mesh ) {
|
||||
bool idRenderModelStatic::ConvertGltfMeshToModelsurfaces( const gltfMesh* mesh )
|
||||
{
|
||||
|
||||
//for ( auto mesh : currentAsset->MeshList( ) ) {
|
||||
// for ( auto prim : mesh->primitives ) {
|
||||
|
@ -16,9 +17,12 @@ bool idRenderModelStatic::ConvertGltfMeshToModelsurfaces( const gltfMesh *mesh )
|
|||
return false;
|
||||
}
|
||||
|
||||
void MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh *_mesh, gltfData *data ) {
|
||||
for ( auto* gltfMesh : data->MeshList( ) ) {
|
||||
for ( auto prim : gltfMesh->primitives ) {
|
||||
void MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh* _mesh, gltfData* data )
|
||||
{
|
||||
for( auto* gltfMesh : data->MeshList( ) )
|
||||
{
|
||||
for( auto prim : gltfMesh->primitives )
|
||||
{
|
||||
common->Printf( "primitive for %s\n", gltfMesh->name.c_str() );
|
||||
|
||||
gltfAccessor* accessor = data->AccessorList( )[prim->indices];
|
||||
|
@ -32,13 +36,17 @@ void MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh *_mesh, gltfData *data
|
|||
idFile_Memory idxBin = idFile_Memory( "gltfChunkIndices",
|
||||
( const char* )( ( data->GetData( bv->buffer ) + bv->byteOffset + accessor->byteOffset ) ), bv->byteLength );
|
||||
|
||||
for ( int i = 0; i < accessor->count; i++ ) {
|
||||
for( int i = 0; i < accessor->count; i++ )
|
||||
{
|
||||
idxBin.Read( ( void* )( &indices[i] ), accessor->typeSize );
|
||||
if( bv->byteStride )
|
||||
{
|
||||
idxBin.Seek( bv->byteStride - accessor->typeSize, FS_SEEK_CUR );
|
||||
}
|
||||
}
|
||||
|
||||
for ( int i = 0; i < accessor->count; i+=3 ) {
|
||||
for( int i = 0; i < accessor->count; i += 3 )
|
||||
{
|
||||
MapPolygon& polygon = polygons.Alloc( );
|
||||
polygon.SetMaterial( "textures/base_wall/lfwall27d" );
|
||||
polygon.AddIndex( indices[i + 1] );
|
||||
|
@ -49,7 +57,8 @@ void MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh *_mesh, gltfData *data
|
|||
Mem_Free( indices );
|
||||
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];
|
||||
gltfData* attrData = attrBv->parent;
|
||||
|
@ -64,15 +73,24 @@ void MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh *_mesh, gltfData *data
|
|||
sizeSet = true;
|
||||
}
|
||||
|
||||
switch ( attrib->type ) {
|
||||
switch( attrib->type )
|
||||
{
|
||||
case gltfMesh_Primitive_Attribute::Type::Position:
|
||||
{
|
||||
for ( int i = attrAcc->count-1; i >= 0; i-- ) {
|
||||
bin.Read( ( void * ) ( &verts[i].xyz.x ), attrAcc->typeSize );
|
||||
bin.Read( ( void * ) ( &verts[i].xyz.y ), attrAcc->typeSize );
|
||||
bin.Read( ( void * ) ( &verts[i].xyz.z ), attrAcc->typeSize );
|
||||
for( int i = attrAcc->count - 1; i >= 0; i-- )
|
||||
{
|
||||
idVec3 pos;
|
||||
|
||||
bin.Read( ( void* )( &pos.x ), attrAcc->typeSize );
|
||||
bin.Read( ( void* )( &pos.y ), attrAcc->typeSize );
|
||||
bin.Read( ( void* )( &pos.z ), attrAcc->typeSize );
|
||||
|
||||
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 );
|
||||
|
@ -85,13 +103,16 @@ void MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh *_mesh, gltfData *data
|
|||
case gltfMesh_Primitive_Attribute::Type::Normal:
|
||||
{
|
||||
idVec3 vec;
|
||||
for ( int i = 0; i < attrAcc->count; i++ ) {
|
||||
for( int i = 0; i < attrAcc->count; i++ )
|
||||
{
|
||||
idVec3 vec;
|
||||
bin.Read( ( void* )( &vec.x ), attrAcc->typeSize );
|
||||
bin.Read( ( void* )( &vec.y ), attrAcc->typeSize );
|
||||
bin.Read( ( void* )( &vec.z ), attrAcc->typeSize );
|
||||
if( attrBv->byteStride )
|
||||
{
|
||||
bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR );
|
||||
}
|
||||
verts[i].SetNormal( vec );
|
||||
}
|
||||
|
||||
|
@ -100,11 +121,14 @@ void MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh *_mesh, gltfData *data
|
|||
case gltfMesh_Primitive_Attribute::Type::TexCoord0:
|
||||
{
|
||||
idVec2 vec;
|
||||
for ( int i = 0; i < attrAcc->count; i++ ) {
|
||||
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 );
|
||||
}
|
||||
|
||||
|
@ -113,13 +137,16 @@ void MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh *_mesh, gltfData *data
|
|||
case gltfMesh_Primitive_Attribute::Type::Tangent:
|
||||
{
|
||||
idVec4 vec;
|
||||
for ( int i = 0; i < attrAcc->count; i++ ) {
|
||||
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 );
|
||||
}
|
||||
|
@ -157,50 +184,72 @@ void MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh *_mesh, gltfData *data
|
|||
SetContents();
|
||||
}
|
||||
|
||||
int idMapEntity::GetEntities( gltfData * data, EntityListRef entities, int sceneID ) {
|
||||
int idMapEntity::GetEntities( gltfData* data, EntityListRef entities, int sceneID )
|
||||
{
|
||||
idMapEntity* worldspawn = new idMapEntity();
|
||||
entities.Append( worldspawn );
|
||||
|
||||
int entityCount = 0;
|
||||
for( auto& nodeID : data->SceneList()[sceneID]->nodes )
|
||||
{
|
||||
auto* node = data->NodeList()[nodeID];
|
||||
auto * newEntity = new idMapEntity( );
|
||||
|
||||
bool isWorldSpawn = false;
|
||||
idMapEntity* newEntity = NULL;
|
||||
|
||||
bool isWorldSpawn = idStr::Icmp( node->extras.strPairs.GetString( "classname" ), "worldspawn" ) == 0;
|
||||
if( isWorldSpawn )
|
||||
{
|
||||
worldspawn->primitives.Resize( 1024, 256 );
|
||||
worldspawn->epairs.Copy( node->extras.strPairs );
|
||||
}
|
||||
else
|
||||
{
|
||||
// account all meshes starting with worldspawn. or BSP in the name
|
||||
if( idStr::Icmpn( node->name, "BSP", 3 ) == 0 || idStr::Icmpn( node->name, "worldspawn.", 11 ) == 0 )
|
||||
{
|
||||
MapPolygonMesh* meshPrim = new MapPolygonMesh();
|
||||
//meshPrim->epairs.Copy( newEntity->epairs );
|
||||
|
||||
meshPrim->ConvertFromMeshGltf( data->MeshList()[node->mesh], data );
|
||||
worldspawn->AddPrimitive( meshPrim );
|
||||
}
|
||||
else
|
||||
{
|
||||
newEntity = new idMapEntity();
|
||||
|
||||
// set name and retrieve epairs from node extras
|
||||
if( node->name.Length() )
|
||||
{
|
||||
newEntity->epairs.Set( "name", node->name );
|
||||
}
|
||||
newEntity->epairs.Copy( node->extras.strPairs );
|
||||
|
||||
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() )
|
||||
for( int i = 0; i < newEntity->epairs.GetNumKeyVals(); i++ )
|
||||
{
|
||||
if ( primType.Icmp( "BrushDef3" ) == 0 ) // change to MapMesh/Primitive
|
||||
{
|
||||
MapPolygonMesh *meshPrim = new MapPolygonMesh( );
|
||||
meshPrim->epairs.Copy( newEntity->epairs );
|
||||
const idKeyValue* kv = newEntity->epairs.GetKeyVal( i );
|
||||
|
||||
meshPrim->ConvertFromMeshGltf(data->MeshList()[node->mesh],data);
|
||||
newEntity->AddPrimitive(meshPrim);
|
||||
}
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( entities.Num( ) > 0 && ( idStr::Icmp( entities[0]->epairs.GetString( "name" ), "worldspawn" ) != 0 ) ) {
|
||||
/*
|
||||
if( entities.Num( ) > 0 && ( idStr::Icmp( entities[0]->epairs.GetString( "name" ), "worldspawn" ) != 0 ) )
|
||||
{
|
||||
// move world spawn to first place
|
||||
for ( int i = 1; i < entities.Num( ); i++ ) {
|
||||
if ( idStr::Icmp( entities[i]->epairs.GetString( "name" ), "worldspawn" ) == 0 ) {
|
||||
for( int i = 1; i < entities.Num( ); i++ )
|
||||
{
|
||||
if( idStr::Icmp( entities[i]->epairs.GetString( "name" ), "worldspawn" ) == 0 )
|
||||
{
|
||||
idMapEntity* tmp = entities[0];
|
||||
entities[0] = entities[i];
|
||||
entities[i] = tmp;
|
||||
|
@ -208,13 +257,15 @@ int idMapEntity::GetEntities( gltfData * data, EntityListRef entities, int scene
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return entityCount;
|
||||
}
|
||||
|
||||
|
||||
// [filename].[%i|%s].[gltf/glb]
|
||||
bool gltfManager::ExtractMeshIdentifier( idStr &filename, int &meshId, idStr &meshName ) {
|
||||
bool gltfManager::ExtractMeshIdentifier( idStr& filename, int& meshId, idStr& meshName )
|
||||
{
|
||||
|
||||
idStr extension;
|
||||
filename.ExtractFileExtension( extension );
|
||||
|
@ -238,228 +289,282 @@ bool gltfManager::ExtractMeshIdentifier( idStr &filename, int &meshId, idStr &me
|
|||
if( lexer.ExpectAnyToken( &token ) )
|
||||
{
|
||||
if( lexer.EndOfFile() && ( token.type == TT_NUMBER ) && ( token.subtype & TT_INTEGER ) )
|
||||
{
|
||||
meshId = token.GetIntValue();
|
||||
}
|
||||
else if( token.type == TT_NUMBER || token.type == TT_STRING )
|
||||
{
|
||||
meshName = id;
|
||||
else {
|
||||
}
|
||||
else
|
||||
{
|
||||
lexer.Warning( "malformed gltf mesh identifier" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
lexer.Warning( "malformed gltf mesh identifier" );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::InitFromFile( const char *fileName ) {
|
||||
void idRenderModelGLTF::InitFromFile( const char* fileName )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
|
||||
}
|
||||
|
||||
bool idRenderModelGLTF::LoadBinaryModel( idFile *file, const ID_TIME_T sourceTimeStamp ) {
|
||||
bool idRenderModelGLTF::LoadBinaryModel( idFile* file, const ID_TIME_T sourceTimeStamp )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return false;
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::WriteBinaryModel( idFile *file, ID_TIME_T *_timeStamp /*= NULL */ ) const {
|
||||
void idRenderModelGLTF::WriteBinaryModel( idFile* file, ID_TIME_T* _timeStamp /*= NULL */ ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
bool idRenderModelGLTF::SupportsBinaryModel( ) {
|
||||
bool idRenderModelGLTF::SupportsBinaryModel( )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return false;
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::ExportOBJ( idFile *objFile, idFile *mtlFile, ID_TIME_T *_timeStamp /*= NULL */ ) {
|
||||
void idRenderModelGLTF::ExportOBJ( idFile* objFile, idFile* mtlFile, ID_TIME_T* _timeStamp /*= NULL */ )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::PartialInitFromFile( const char *fileName ) {
|
||||
void idRenderModelGLTF::PartialInitFromFile( const char* fileName )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::PurgeModel( ) {
|
||||
void idRenderModelGLTF::PurgeModel( )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::Reset( ) {
|
||||
void idRenderModelGLTF::Reset( )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::LoadModel( ) {
|
||||
void idRenderModelGLTF::LoadModel( )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
bool idRenderModelGLTF::IsLoaded( ) {
|
||||
bool idRenderModelGLTF::IsLoaded( )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return false;
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::SetLevelLoadReferenced( bool referenced ) {
|
||||
void idRenderModelGLTF::SetLevelLoadReferenced( bool referenced )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
bool idRenderModelGLTF::IsLevelLoadReferenced( ) {
|
||||
bool idRenderModelGLTF::IsLevelLoadReferenced( )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return false;
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::TouchData( ) {
|
||||
void idRenderModelGLTF::TouchData( )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::CreateBuffers( nvrhi::ICommandList *commandList ) {
|
||||
void idRenderModelGLTF::CreateBuffers( nvrhi::ICommandList* commandList )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::InitEmpty( const char *name ) {
|
||||
void idRenderModelGLTF::InitEmpty( const char* name )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::AddSurface( modelSurface_t surface ) {
|
||||
void idRenderModelGLTF::AddSurface( modelSurface_t surface )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::FinishSurfaces( bool useMikktspace ) {
|
||||
void idRenderModelGLTF::FinishSurfaces( bool useMikktspace )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::FreeVertexCache( ) {
|
||||
void idRenderModelGLTF::FreeVertexCache( )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
const char *idRenderModelGLTF::Name( ) const {
|
||||
const char* idRenderModelGLTF::Name( ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return "";
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::Print( ) const {
|
||||
void idRenderModelGLTF::Print( ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::List( ) const {
|
||||
void idRenderModelGLTF::List( ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
int idRenderModelGLTF::Memory( ) const {
|
||||
int idRenderModelGLTF::Memory( ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return -1;
|
||||
}
|
||||
|
||||
ID_TIME_T idRenderModelGLTF::Timestamp( ) const {
|
||||
ID_TIME_T idRenderModelGLTF::Timestamp( ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return FILE_NOT_FOUND_TIMESTAMP;
|
||||
}
|
||||
|
||||
int idRenderModelGLTF::NumSurfaces( ) const {
|
||||
int idRenderModelGLTF::NumSurfaces( ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return -1;
|
||||
}
|
||||
|
||||
int idRenderModelGLTF::NumBaseSurfaces( ) const {
|
||||
int idRenderModelGLTF::NumBaseSurfaces( ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return -1;
|
||||
}
|
||||
|
||||
const modelSurface_t *idRenderModelGLTF::Surface( int surfaceNum ) const {
|
||||
const modelSurface_t* idRenderModelGLTF::Surface( int surfaceNum ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
srfTriangles_t *idRenderModelGLTF::AllocSurfaceTriangles( int numVerts, int numIndexes ) const {
|
||||
srfTriangles_t* idRenderModelGLTF::AllocSurfaceTriangles( int numVerts, int numIndexes ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::FreeSurfaceTriangles( srfTriangles_t *tris ) const {
|
||||
void idRenderModelGLTF::FreeSurfaceTriangles( srfTriangles_t* tris ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
bool idRenderModelGLTF::IsStaticWorldModel( ) const {
|
||||
bool idRenderModelGLTF::IsStaticWorldModel( ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return false;
|
||||
}
|
||||
|
||||
dynamicModel_t idRenderModelGLTF::IsDynamicModel( ) const {
|
||||
dynamicModel_t idRenderModelGLTF::IsDynamicModel( ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return dynamicModel_t();
|
||||
}
|
||||
|
||||
bool idRenderModelGLTF::IsDefaultModel( ) const {
|
||||
bool idRenderModelGLTF::IsDefaultModel( ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return false;
|
||||
}
|
||||
|
||||
bool idRenderModelGLTF::IsReloadable( ) const {
|
||||
bool idRenderModelGLTF::IsReloadable( ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return false;
|
||||
}
|
||||
|
||||
idRenderModel *idRenderModelGLTF::InstantiateDynamicModel( const struct renderEntity_s *ent, const viewDef_t *view, idRenderModel *cachedModel ) {
|
||||
idRenderModel* idRenderModelGLTF::InstantiateDynamicModel( const struct renderEntity_s* ent, const viewDef_t* view, idRenderModel* cachedModel )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int idRenderModelGLTF::NumJoints( ) const {
|
||||
int idRenderModelGLTF::NumJoints( ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return 0;
|
||||
}
|
||||
|
||||
const idMD5Joint *idRenderModelGLTF::GetJoints( ) const {
|
||||
const idMD5Joint* idRenderModelGLTF::GetJoints( ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jointHandle_t idRenderModelGLTF::GetJointHandle( const char *name ) const {
|
||||
jointHandle_t idRenderModelGLTF::GetJointHandle( const char* name ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return jointHandle_t();
|
||||
}
|
||||
|
||||
const char *idRenderModelGLTF::GetJointName( jointHandle_t handle ) const {
|
||||
const char* idRenderModelGLTF::GetJointName( jointHandle_t handle ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return "";
|
||||
}
|
||||
|
||||
const idJointQuat *idRenderModelGLTF::GetDefaultPose( ) const {
|
||||
const idJointQuat* idRenderModelGLTF::GetDefaultPose( ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int idRenderModelGLTF::NearestJoint( int surfaceNum, int a, int b, int c ) const {
|
||||
int idRenderModelGLTF::NearestJoint( int surfaceNum, int a, int b, int c ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return -1;
|
||||
}
|
||||
|
||||
idBounds idRenderModelGLTF::Bounds( const struct renderEntity_s *ent ) const {
|
||||
idBounds idRenderModelGLTF::Bounds( const struct renderEntity_s* ent ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return idBounds();
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::ReadFromDemoFile( class idDemoFile *f ) {
|
||||
void idRenderModelGLTF::ReadFromDemoFile( class idDemoFile* f )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::WriteToDemoFile( class idDemoFile *f ) {
|
||||
void idRenderModelGLTF::WriteToDemoFile( class idDemoFile* f )
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
}
|
||||
|
||||
float idRenderModelGLTF::DepthHack( ) const {
|
||||
float idRenderModelGLTF::DepthHack( ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return -1.0f;
|
||||
}
|
||||
|
||||
bool idRenderModelGLTF::ModelHasDrawingSurfaces( ) const {
|
||||
bool idRenderModelGLTF::ModelHasDrawingSurfaces( ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return false;
|
||||
}
|
||||
|
||||
bool idRenderModelGLTF::ModelHasInteractingSurfaces( ) const {
|
||||
bool idRenderModelGLTF::ModelHasInteractingSurfaces( ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return false;
|
||||
}
|
||||
|
||||
bool idRenderModelGLTF::ModelHasShadowCastingSurfaces( ) const {
|
||||
bool idRenderModelGLTF::ModelHasShadowCastingSurfaces( ) const
|
||||
{
|
||||
common->Warning( "The method or operation is not implemented." );
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#pragma once
|
||||
#include "Model_local.h"
|
||||
|
||||
class gltfManager {
|
||||
class gltfManager
|
||||
{
|
||||
public:
|
||||
static bool ExtractMeshIdentifier( idStr& filename , int& meshId, idStr& meshName );
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue