2022-06-05 22:39:04 +00:00
|
|
|
#include "precompiled.h"
|
|
|
|
#pragma hdrstop
|
|
|
|
|
|
|
|
/// <TODO>
|
|
|
|
/// Clean up registerd gltfItem_Extra's
|
|
|
|
/// Clean up loaded gltfData;
|
|
|
|
/// </TODO>
|
|
|
|
|
|
|
|
static const unsigned int gltfChunk_Type_JSON = 0x4E4F534A; //1313821514
|
|
|
|
static const unsigned int gltfChunk_Type_BIN = 0x004E4942; //5130562
|
|
|
|
|
2022-06-17 23:18:28 +00:00
|
|
|
idCVar gltf_parseVerbose( "gltf_parseVerbose", "0", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_BOOL, "print gltf json data while parsing" );
|
2022-06-05 22:39:04 +00:00
|
|
|
idCVar gltfParser_PrefixNodeWithID( "gltfParser_PrefixNodeWithID", "0", CVAR_SYSTEM | CVAR_BOOL, "The node's id is prefixed to the node's name during load" );
|
|
|
|
//
|
|
|
|
//gltf_sampler_wrap_type_map s_samplerWrapTypeMap[] = {
|
|
|
|
// //33071 CLAMP_TO_EDGE
|
|
|
|
// 33071, BGFX_SAMPLER_U_CLAMP, BGFX_SAMPLER_V_CLAMP,
|
|
|
|
// //33648 MIRRORED_REPEAT
|
|
|
|
// 33648, BGFX_SAMPLER_U_MIRROR, BGFX_SAMPLER_V_MIRROR,
|
|
|
|
// //10497 REPEAT
|
|
|
|
// 10497, BGFX_SAMPLER_NONE , BGFX_SAMPLER_NONE ,
|
|
|
|
// 0,0,0
|
|
|
|
//};
|
|
|
|
////todo
|
|
|
|
//gltf_sampler_mag_type_map s_samplerMagTypeMap[] = {
|
|
|
|
// //9728 NEAREST //mag/min
|
|
|
|
// 9728 , BGFX_SAMPLER_MIN_ANISOTROPIC
|
2022-06-06 14:13:32 +00:00
|
|
|
// //9729 LINEAR // mag/min
|
2022-06-05 22:39:04 +00:00
|
|
|
// //
|
|
|
|
// //9984 NEAREST_MIPMAP_NEAREST //min
|
|
|
|
// //
|
|
|
|
// //9985 LINEAR_MIPMAP_NEAREST //min
|
|
|
|
// //
|
|
|
|
// //9986 NEAREST_MIPMAP_LINEAR //min
|
|
|
|
// //
|
|
|
|
// //9987 LINEAR_MIPMAP_LINEAR //min
|
|
|
|
//};
|
|
|
|
|
|
|
|
//uint64_t GetSamplerFlags( gltfSampler * sampler) {
|
|
|
|
// // Ignore the sampling options for filter -- always use mag: LINEAR and min: LINEAR_MIPMAP_LINEAR
|
|
|
|
// uint64_t flags ;//= BGFX_TEXTURE_NONE | BGFX_SAMPLER_MIN_ANISOTROPIC ;
|
|
|
|
// int i = -1;
|
|
|
|
// while ( s_samplerWrapTypeMap[++i].id != 0 )
|
|
|
|
// {
|
|
|
|
// if ( s_samplerWrapTypeMap[i].id == sampler->wrapS)
|
|
|
|
// flags |= s_samplerWrapTypeMap[i].bgfxFlagU;
|
|
|
|
// if ( s_samplerWrapTypeMap[i].id == sampler->wrapT )
|
|
|
|
// flags |= s_samplerWrapTypeMap[i].bgfxFlagV;
|
|
|
|
// }
|
|
|
|
// return flags;
|
|
|
|
//}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
|
|
|
|
gltf_mesh_attribute_map s_meshAttributeMap[] =
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
"POSITION", gltfMesh_Primitive_Attribute::Type::Position, 3,
|
|
|
|
"NORMAL", gltfMesh_Primitive_Attribute::Type::Normal, 3,
|
|
|
|
"TANGENT", gltfMesh_Primitive_Attribute::Type::Tangent, 3,
|
|
|
|
"TEXCOORD_0", gltfMesh_Primitive_Attribute::Type::TexCoord0, 2,
|
|
|
|
"TEXCOORD_1", gltfMesh_Primitive_Attribute::Type::TexCoord1, 2,
|
|
|
|
"TEXCOORD_2", gltfMesh_Primitive_Attribute::Type::TexCoord2, 2,
|
|
|
|
"TEXCOORD_3", gltfMesh_Primitive_Attribute::Type::TexCoord3, 2,
|
|
|
|
"TEXCOORD_4", gltfMesh_Primitive_Attribute::Type::TexCoord4, 2,
|
|
|
|
"TEXCOORD_5", gltfMesh_Primitive_Attribute::Type::TexCoord5, 2,
|
|
|
|
"TEXCOORD_6", gltfMesh_Primitive_Attribute::Type::TexCoord6, 2,
|
|
|
|
"TEXCOORD_7", gltfMesh_Primitive_Attribute::Type::TexCoord7, 2,
|
2022-06-06 14:13:32 +00:00
|
|
|
"COLOR_0", gltfMesh_Primitive_Attribute::Type::Color0, 4,
|
2022-06-05 22:39:04 +00:00
|
|
|
"COLOR_1", gltfMesh_Primitive_Attribute::Type::Color1, 4,
|
|
|
|
"COLOR_2", gltfMesh_Primitive_Attribute::Type::Color2, 4,
|
|
|
|
"COLOR_3", gltfMesh_Primitive_Attribute::Type::Color3, 4,
|
|
|
|
"WEIGHTS_0", gltfMesh_Primitive_Attribute::Type::Weight, 4,
|
|
|
|
"JOINTS_0", gltfMesh_Primitive_Attribute::Type::Indices, 4,
|
|
|
|
"", gltfMesh_Primitive_Attribute::Type::Count
|
|
|
|
};
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfMesh_Primitive_Attribute::Type GetAttributeEnum( const char* str , uint* elementSize = nullptr )
|
|
|
|
{
|
|
|
|
int i = -1;
|
|
|
|
while( s_meshAttributeMap[++i].attib != gltfMesh_Primitive_Attribute::Type::Count )
|
|
|
|
if( !idStr::Icmp( s_meshAttributeMap[i].stringID, str ) )
|
|
|
|
{
|
|
|
|
if( elementSize != nullptr )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-06 14:13:32 +00:00
|
|
|
*elementSize = s_meshAttributeMap[i].elementSize;
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
return s_meshAttributeMap[i].attib;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gltfMesh_Primitive_Attribute::Type::Count;
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//https://github.com/KhronosGroup/glTF/issues/832
|
|
|
|
//gltf_accessor_component_type_map<bgfx::AttribType::Enum> s_bgfxComponentTypeMap[] = {
|
|
|
|
// "signed byte", 5120, bgfx::AttribType::Count, 1 ,
|
|
|
|
// "unsigned byte", 5121, bgfx::AttribType::Uint8, 1 ,
|
|
|
|
// "signed short", 5122, bgfx::AttribType::Int16, 2 ,
|
|
|
|
// "unsigned short", 5123, bgfx::AttribType::Count, 2 ,
|
2022-06-06 14:13:32 +00:00
|
|
|
// "unsigned int", 5125, bgfx::AttribType::Count, 4 ,
|
2022-06-05 22:39:04 +00:00
|
|
|
// "float", 5126, bgfx::AttribType::Float, 4 ,
|
|
|
|
// "double", 5130, bgfx::AttribType::Float, 8 ,
|
|
|
|
// "", 0, bgfx::AttribType::Count, 0
|
|
|
|
//};
|
|
|
|
//
|
2022-06-06 14:13:32 +00:00
|
|
|
gltf_accessor_component_type_map<gltf_accessor_component::Type> s_nativeComponentTypeMap[] =
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
"signed byte", 5120, gltf_accessor_component::Type::_byte, 1 ,
|
|
|
|
"unsigned byte", 5121, gltf_accessor_component::Type::_uByte, 1 ,
|
|
|
|
"signed short", 5122, gltf_accessor_component::Type::_short, 2 ,
|
|
|
|
"unsigned short", 5123, gltf_accessor_component::Type::_uShort, 2 ,
|
|
|
|
"unsigned int", 5125, gltf_accessor_component::Type::_uInt, 4 ,
|
|
|
|
"float", 5126, gltf_accessor_component::Type::_float, 4 ,
|
|
|
|
"double", 5130, gltf_accessor_component::Type::_double, 8 ,
|
|
|
|
"", 0, gltf_accessor_component::Type::Count, 0
|
|
|
|
};
|
|
|
|
//
|
2022-06-06 14:13:32 +00:00
|
|
|
gltf_accessor_component::Type GetComponentTypeEnum( int id , uint* sizeInBytes = nullptr )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
int i = -1;
|
2022-06-06 14:13:32 +00:00
|
|
|
while( s_nativeComponentTypeMap[++i].id != 0 )
|
|
|
|
if( s_nativeComponentTypeMap[i].id == id )
|
|
|
|
{
|
|
|
|
if( sizeInBytes != nullptr )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
*sizeInBytes = s_nativeComponentTypeMap[i].sizeInBytes;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
return s_nativeComponentTypeMap[i].type;
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
|
2022-06-05 22:39:04 +00:00
|
|
|
return gltf_accessor_component::Type::Count;
|
|
|
|
}
|
|
|
|
|
|
|
|
//some arbitrary amount for now.
|
|
|
|
#define GLTF_MAX_CHUNKS 32
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
idList<gltfData*> gltfData::dataList;
|
2022-06-05 22:39:04 +00:00
|
|
|
idHashIndex gltfData::fileDataHash;
|
|
|
|
gltfItemArray* gltfItem_Extra::items = new gltfItemArray();
|
|
|
|
|
|
|
|
//Helper macros for gltf data deserialize
|
|
|
|
//NOTE: gltfItems that deviate from the default SET(T*) function cannot be handled with itemref macro.
|
|
|
|
// target must be an gltfArrayItem.
|
|
|
|
// type with name will be added to the array.
|
|
|
|
#define GLTFARRAYITEM(target,name,type) auto * name = new type (#name); target.AddItemDef((parsable*)name)
|
|
|
|
// name must point to an existing valid entry
|
|
|
|
// name->Set (&target->name);
|
|
|
|
#define GLTFARRAYITEMREF(target,name) name->Set(&target->name)
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfPropertyArray::Iterator::operator ++( )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
//check if by modification, we are iterating again.
|
|
|
|
//custom not AOS things can do this since it is not nicely guarded by braces
|
2022-06-06 14:13:32 +00:00
|
|
|
if( array->dirty && ( !array->iterating && !array->isArrayOfStructs ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
array->iterating = array->parser->PeekTokenString( "," );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( array->iterating )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
array->properties.AssureSizeAlloc( array->properties.Num( ) + 1, idListNewElement<gltfPropertyItem> );
|
|
|
|
array->parser->ExpectTokenString( "," );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( array->iterating )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
p = array->properties[array->properties.Num( ) - 1];
|
|
|
|
p->array = array;
|
2022-06-06 14:13:32 +00:00
|
|
|
if( array->isArrayOfStructs )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
array->parser->ParseBracedSection( p->item );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
idToken token;
|
|
|
|
array->parser->ExpectAnyToken( &token );
|
|
|
|
p->item = token;
|
|
|
|
}
|
|
|
|
array->iterating = array->parser->PeekTokenString( "," );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( array->iterating )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
array->properties.AssureSizeAlloc( array->properties.Num( ) + 1, idListNewElement<gltfPropertyItem> );
|
|
|
|
array->parser->ExpectTokenString( "," );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-06 14:13:32 +00:00
|
|
|
if( array->dirty )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
p = array->endPtr;
|
|
|
|
array->dirty = false;
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
else if( array->index + 1 < array->properties.Num() )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
p = array->properties[++array->index];
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
else
|
2022-06-06 14:13:32 +00:00
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
p = array->endPtr;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
gltfPropertyArray::~gltfPropertyArray()
|
|
|
|
{
|
|
|
|
delete endPtr;
|
2022-06-06 14:13:32 +00:00
|
|
|
properties.DeleteContents( true );
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfPropertyArray::gltfPropertyArray( idLexer* Parser, bool AoS/* = true */ )
|
|
|
|
: parser( Parser ), iterating( true ), dirty( true ), index( 0 ), isArrayOfStructs( AoS )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-06 14:13:32 +00:00
|
|
|
properties.AssureSizeAlloc( 32, idListNewElement<gltfPropertyItem> );
|
|
|
|
properties.SetNum( 0 );
|
2022-06-05 22:39:04 +00:00
|
|
|
endPtr = new gltfPropertyItem();
|
|
|
|
endPtr->array = this;
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfPropertyArray::Iterator gltfPropertyArray::begin( )
|
|
|
|
{
|
|
|
|
if( iterating )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-06 14:13:32 +00:00
|
|
|
if( isArrayOfStructs && !parser->PeekTokenString( "{" ) )
|
|
|
|
{
|
|
|
|
if( !parser->ExpectTokenString( "[" ) && parser->PeekTokenString( "{" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->FatalError( "Malformed gltf array" );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !isArrayOfStructs && !parser->ExpectTokenString( "[" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->FatalError( "Malformed gltf array" );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
properties.AssureSizeAlloc( properties.Num() + 1, idListNewElement<gltfPropertyItem> );
|
|
|
|
gltfPropertyItem* start = properties[0];
|
|
|
|
start->array = this;
|
|
|
|
if( isArrayOfStructs )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser->ParseBracedSection( start->item );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
idToken token;
|
2022-06-06 14:13:32 +00:00
|
|
|
parser->ExpectAnyToken( &token );
|
2022-06-05 22:39:04 +00:00
|
|
|
start->item = token;
|
|
|
|
}
|
|
|
|
iterating = parser->PeekTokenString( "," );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( iterating )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-06 14:13:32 +00:00
|
|
|
properties.AssureSizeAlloc( properties.Num() + 1, idListNewElement<gltfPropertyItem> );
|
2022-06-05 22:39:04 +00:00
|
|
|
parser->ExpectTokenString( "," );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
return Iterator{ this , start };
|
|
|
|
}
|
|
|
|
index = 0;
|
2022-06-06 14:13:32 +00:00
|
|
|
return Iterator{ this , properties[index]};
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfPropertyArray::Iterator gltfPropertyArray::end( )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return Iterator{ this , endPtr};
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
int gltfItemArray::Fill( idLexer* lexer, idDict* strPairs )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
idToken token;
|
|
|
|
bool parsing = true;
|
|
|
|
int parseCount = 0;
|
|
|
|
lexer->ExpectTokenString( "{" );
|
2022-06-06 14:13:32 +00:00
|
|
|
while( parsing && !lexer->PeekTokenString( "}" ) && lexer->ExpectAnyToken( &token ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer->ExpectTokenString( ":" );
|
|
|
|
idStr key = token;
|
|
|
|
idStr value;
|
|
|
|
key.StripTrailingWhitespace( );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( lexer->PeekTokenString( "{" ) )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-06 14:13:32 +00:00
|
|
|
lexer->ParseBracedSectionExact( value );
|
2022-06-05 22:39:04 +00:00
|
|
|
value.StripTrailingWhitespace( );
|
|
|
|
strPairs->Set( key, value );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
lexer->ExpectAnyToken( &token );
|
|
|
|
value = token;
|
|
|
|
value.StripTrailingWhitespace( );
|
|
|
|
key.StripTrailingWhitespace( );
|
|
|
|
strPairs->Set( key, token );
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
|
2022-06-05 22:39:04 +00:00
|
|
|
parseCount++;
|
|
|
|
parsing = lexer->PeekTokenString( "," );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( parsing )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer->ExpectTokenString( "," );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
lexer->ExpectTokenString( "}" );
|
|
|
|
return parseCount;
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
int gltfItemArray::Parse( idLexer* lexer, bool forwardLexer/* = false*/ )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
idToken token;
|
|
|
|
bool parsing = true;
|
|
|
|
int parseCount = 0;
|
|
|
|
lexer->ExpectTokenString( "{" );
|
2022-06-06 14:13:32 +00:00
|
|
|
while( parsing && !lexer->PeekTokenString( "}" ) && lexer->ExpectAnyToken( &token ) )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
lexer->ExpectTokenString( ":" );
|
|
|
|
bool parsed = false;
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto item : items )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-06 14:13:32 +00:00
|
|
|
if( item->Name( ) == token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
lexer->ExpectAnyToken( &token );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( forwardLexer )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
item->parse( token , lexer );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
else
|
2022-06-06 14:13:32 +00:00
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
item->parse( token );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
parsed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
if( !parsed )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer->SkipBracedSection();
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
else
|
2022-06-06 14:13:32 +00:00
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parseCount++;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
parsing = lexer->PeekTokenString( "," );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( parsing )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer->ExpectTokenString( "," );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
lexer->ExpectTokenString( "}" );
|
|
|
|
return parseCount;
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
byte* gltfData::AddData( int size, int* bufferID/*=nullptr*/ )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-06 14:13:32 +00:00
|
|
|
if( totalChunks == -1 )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-06 14:13:32 +00:00
|
|
|
json = ( byte* ) Mem_ClearedAlloc( size, TAG_IDLIB_GLTF );
|
2022-06-05 22:39:04 +00:00
|
|
|
totalChunks++;
|
|
|
|
jsonDataLength = size;
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
|
|
|
|
int id = totalChunks;
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( data == nullptr )
|
|
|
|
{
|
|
|
|
data = ( byte** ) Mem_ClearedAlloc( GLTF_MAX_CHUNKS * sizeof( byte* ), TAG_IDLIB_GLTF );
|
|
|
|
}
|
|
|
|
data[totalChunks++] = ( byte* ) Mem_ClearedAlloc( size, TAG_IDLIB_GLTF );
|
|
|
|
|
|
|
|
if( bufferID )
|
|
|
|
{
|
|
|
|
*bufferID = id;
|
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
return data[id];
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
bool gltfItem_uri::Convert( )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
//HVG_TODO
|
|
|
|
// uri cache.
|
|
|
|
//read data
|
|
|
|
int length = fileSystem->ReadFile( item->c_str( ), NULL );
|
2022-06-06 14:13:32 +00:00
|
|
|
idFile* file = fileSystem->OpenFileRead( item->c_str() );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
//create buffer
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfBuffer* buffer = data->Buffer( );
|
2022-06-05 22:39:04 +00:00
|
|
|
buffer->parent = data;
|
|
|
|
buffer->name = item->c_str( );
|
|
|
|
buffer->byteLength = length;
|
|
|
|
int bufferID = -1;
|
2022-06-06 14:13:32 +00:00
|
|
|
byte* dest = data->AddData( length, &bufferID );
|
|
|
|
|
|
|
|
if( file->Read( dest, length ) != length )
|
|
|
|
{
|
|
|
|
common->FatalError( "Could not read %s", item->c_str() );
|
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool() )
|
|
|
|
{
|
|
|
|
common->Warning( "gltf Uri %s loaded into buffer[ %i ]", buffer->name.c_str(), bufferID );
|
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
//create bufferview
|
|
|
|
//if bufferview is not set, this is an buffer.uri.
|
|
|
|
//A bufferview should aready be defined if the buffer is used.
|
2022-06-06 14:13:32 +00:00
|
|
|
if( bufferView != nullptr )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
*bufferView = data->BufferViewList().Num();
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfBufferView* newBufferView = data->BufferView( );
|
2022-06-05 22:39:04 +00:00
|
|
|
newBufferView->buffer = bufferID;
|
|
|
|
newBufferView->byteLength = length;
|
|
|
|
newBufferView->parent = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
fileSystem->CloseFile( file );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_Extra::parse( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser->UnreadToken( &token );
|
2022-06-06 14:13:32 +00:00
|
|
|
parser->ParseBracedSectionExact( item->json );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-17 23:18:28 +00:00
|
|
|
idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer.LoadMemory( item->json, item->json.Size( ), "gltfItem_Extra", 0 );
|
2022-06-06 14:13:32 +00:00
|
|
|
items->Fill( &lexer, &item->strPairs );
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer.Reset();
|
|
|
|
items->Parse( &lexer , true );
|
2022-06-06 14:13:32 +00:00
|
|
|
|
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", item->json.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_Extra::Register( parsable* extra )
|
|
|
|
{
|
|
|
|
common->DPrintf( "...Registering gltf Extra \"%s\" total(%i)\n", extra->Name().c_str(), items->Num() );
|
2022-06-05 22:39:04 +00:00
|
|
|
items->AddItemDef( extra );
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_animation_sampler::parse( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
gltfItemArray animSampler;
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( animSampler, input, gltfItem_integer );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( animSampler, interpolation, gltfItem );
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( animSampler, output, gltfItem_integer );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( animSampler, extensions, gltfItem );
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( animSampler, extras, gltfItem_Extra );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
gltfPropertyArray array = gltfPropertyArray( parser );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& prop : array )
|
|
|
|
{
|
2022-06-17 23:18:28 +00:00
|
|
|
idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfAnimation_Sampler", 0 );
|
|
|
|
|
|
|
|
item->AssureSizeAlloc( item->Num( ) + 1, idListNewElement<gltfAnimation_Sampler> );
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfAnimation_Sampler* gltfAnimSampler = ( *item )[item->Num( ) - 1];
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
GLTFARRAYITEMREF( gltfAnimSampler, input );
|
|
|
|
GLTFARRAYITEMREF( gltfAnimSampler, interpolation );
|
|
|
|
GLTFARRAYITEMREF( gltfAnimSampler, output );
|
|
|
|
GLTFARRAYITEMREF( gltfAnimSampler, extensions );
|
2022-06-06 14:13:32 +00:00
|
|
|
extras->Set( &gltfAnimSampler->extras, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
animSampler.Parse( &lexer );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", prop.item.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfAnimSampler->intType = gltfAnimation_Sampler::resolveType( gltfAnimSampler->interpolation );
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
parser->ExpectTokenString( "]" );
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_animation_channel_target::parse( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser->UnreadToken( &token );
|
|
|
|
gltfItemArray animChannelTarget;
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( animChannelTarget, node, gltfItem_integer );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( animChannelTarget, path, gltfItem );
|
|
|
|
GLTFARRAYITEM( animChannelTarget, extensions, gltfItem );
|
|
|
|
GLTFARRAYITEM( animChannelTarget, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
GLTFARRAYITEMREF( item, node );
|
|
|
|
GLTFARRAYITEMREF( item, path );
|
|
|
|
GLTFARRAYITEMREF( item, extensions );
|
2022-06-06 14:13:32 +00:00
|
|
|
extras->Set( &item->extras, parser );
|
2022-06-05 22:39:04 +00:00
|
|
|
animChannelTarget.Parse( parser );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", token.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
item->TRS = gltfAnimation_Channel_Target::resolveType( item->path );
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_animation_channel::parse( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
//parser->UnreadToken( &token );
|
|
|
|
gltfItemArray anim;
|
|
|
|
GLTFARRAYITEM( anim, sampler, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( anim, target, gltfItem_animation_channel_target );
|
|
|
|
GLTFARRAYITEM( anim, extensions, gltfItem );
|
|
|
|
GLTFARRAYITEM( anim, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
gltfPropertyArray array = gltfPropertyArray( parser );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& prop : array )
|
|
|
|
{
|
2022-06-17 23:18:28 +00:00
|
|
|
idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfAnimation_Channel", 0 );
|
|
|
|
|
|
|
|
|
|
|
|
item->AssureSizeAlloc( item->Num( ) + 1, idListNewElement<gltfAnimation_Channel> );
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfAnimation_Channel* gltfAnimationChannel = ( *item )[item->Num( ) - 1];
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
GLTFARRAYITEMREF( gltfAnimationChannel, sampler );
|
2022-06-06 14:13:32 +00:00
|
|
|
target->Set( &gltfAnimationChannel->target, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEMREF( gltfAnimationChannel, extensions );
|
2022-06-06 14:13:32 +00:00
|
|
|
extras->Set( &gltfAnimationChannel->extras, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
anim.Parse( &lexer );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", token.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
parser->ExpectTokenString( "]" );
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_mesh_primitive::parse( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
gltfItemArray prim;
|
|
|
|
GLTFARRAYITEM( prim, attributes, gltfItem_mesh_primitive_attribute );
|
|
|
|
GLTFARRAYITEM( prim, indices, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( prim, material, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( prim, mode, gltfItem_integer );
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( prim, target, gltfItem );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( prim, extensions, gltfItem );
|
|
|
|
GLTFARRAYITEM( prim, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
gltfPropertyArray array = gltfPropertyArray( parser );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& prop : array )
|
|
|
|
{
|
2022-06-17 23:18:28 +00:00
|
|
|
idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfItem_mesh_primitiveB", 0 );
|
|
|
|
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
item->AssureSizeAlloc( item->Num() + 1, idListNewElement<gltfMesh_Primitive> );
|
|
|
|
gltfMesh_Primitive* gltfMeshPrim = ( *item )[item->Num() - 1];
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
attributes->Set( &gltfMeshPrim->attributes, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEMREF( gltfMeshPrim, indices );
|
|
|
|
GLTFARRAYITEMREF( gltfMeshPrim, material );
|
|
|
|
GLTFARRAYITEMREF( gltfMeshPrim, mode );
|
|
|
|
GLTFARRAYITEMREF( gltfMeshPrim, target );
|
|
|
|
GLTFARRAYITEMREF( gltfMeshPrim, extensions );
|
2022-06-06 14:13:32 +00:00
|
|
|
extras->Set( &gltfMeshPrim->extras, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
prim.Parse( &lexer );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", prop.item.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
parser->ExpectTokenString( "]" );
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_mesh_primitive_attribute::parse( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
bool parsing = true;
|
2022-06-06 14:13:32 +00:00
|
|
|
while( parsing && parser->ExpectAnyToken( &token ) )
|
|
|
|
{
|
|
|
|
|
2022-06-05 22:39:04 +00:00
|
|
|
item->AssureSizeAlloc( item->Num( ) + 1, idListNewElement<gltfMesh_Primitive_Attribute> );
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfMesh_Primitive_Attribute* attr = ( *item )[item->Num( ) - 1];
|
2022-06-05 22:39:04 +00:00
|
|
|
parser->ExpectTokenString( ":" );
|
|
|
|
attr->attributeSemantic = token;
|
|
|
|
attr->type = GetAttributeEnum( attr->attributeSemantic.c_str(), &attr->elementSize );
|
|
|
|
parser->ExpectAnyToken( &token );
|
|
|
|
attr->accessorIndex = token.GetIntValue();
|
|
|
|
parsing = parser->PeekTokenString( "," );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( parsing )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser->ExpectTokenString( "," );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
parser->ExpectTokenString( "}" );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", token.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_integer_array::parse( idToken& token )
|
|
|
|
{
|
|
|
|
|
2022-06-05 22:39:04 +00:00
|
|
|
parser->UnreadToken( &token );
|
|
|
|
gltfPropertyArray array = gltfPropertyArray( parser, false );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& prop : array )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
idStr neg;
|
2022-06-06 14:13:32 +00:00
|
|
|
int& value = item->Alloc( );
|
2022-06-05 22:39:04 +00:00
|
|
|
value = prop.item.GetIntValue();
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( prop.item.type == TT_PUNCTUATION && prop.item == "-" )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser->ExpectTokenType( TT_NUMBER, 0, &prop.item );
|
|
|
|
value = -( prop.item.GetIntValue( ) );
|
|
|
|
neg = "-";
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else if( prop.item.type == TT_NUMBER )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
value = prop.item.GetIntValue( );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->FatalError( "parse error" );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s%s", neg.c_str( ), prop.item.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
parser->ExpectTokenString( "]" );
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_number_array::parse( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
parser->UnreadToken( &token );
|
2022-06-05 22:39:04 +00:00
|
|
|
gltfPropertyArray array = gltfPropertyArray( parser, false );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& prop : array )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
idStr neg;
|
|
|
|
double& value = item->Alloc( );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( prop.item.type == TT_PUNCTUATION && prop.item == "-" )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser->ExpectTokenType( TT_NUMBER, 0, &prop.item );
|
2022-06-06 14:13:32 +00:00
|
|
|
value = -( prop.item.GetDoubleValue() );
|
2022-06-05 22:39:04 +00:00
|
|
|
neg = "-";
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else if( prop.item.type == TT_NUMBER )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
value = prop.item.GetDoubleValue( );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
common->FatalError( "parse error" );
|
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
|
|
|
common->Printf( "%s%s", neg.c_str(), prop.item.c_str( ) );
|
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
parser->ExpectTokenString( "]" );
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_vec4::parse( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
auto* numbers = new gltfItem_number_array( "" );
|
2022-06-05 22:39:04 +00:00
|
|
|
idList<double> numberarray;
|
|
|
|
numbers->Set( &numberarray, parser );
|
|
|
|
numbers->parse( token );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( numbers->item->Num( ) != 4 )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->FatalError( "gltfItem_vec4 : missing arguments, expected 4, got %i", numbers->item->Num( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
double* val = numbers->item->Ptr( );
|
2022-06-05 22:39:04 +00:00
|
|
|
*item = idVec4( val[0], val[1], val[2], val[3] );
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_vec3::parse( idToken& token )
|
|
|
|
{
|
|
|
|
auto* numbers = new gltfItem_number_array( "" );
|
2022-06-05 22:39:04 +00:00
|
|
|
idList<double> numberarray;
|
|
|
|
numbers->Set( &numberarray, parser );
|
|
|
|
numbers->parse( token );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( numbers->item->Num( ) != 3 )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->FatalError( "gltfItem_vec3 : missing arguments, expected 3, got %i", numbers->item->Num( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
double* val = numbers->item->Ptr( );
|
2022-06-05 22:39:04 +00:00
|
|
|
*item = idVec3( val[0], val[1], val[2] );
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_vec2::parse( idToken& token )
|
|
|
|
{
|
|
|
|
auto* numbers = new gltfItem_number_array( "" );
|
2022-06-05 22:39:04 +00:00
|
|
|
idList<double> numberarray;
|
|
|
|
numbers->Set( &numberarray, parser );
|
|
|
|
numbers->parse( token );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( numbers->item->Num( ) != 2 )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->FatalError( "gltfItem_vec3 : missing arguments, expected 2, got %i", numbers->item->Num( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
double* val = numbers->item->Ptr( );
|
2022-06-05 22:39:04 +00:00
|
|
|
*item = idVec2( val[0], val[1] );
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_quat::parse( idToken& token )
|
|
|
|
{
|
|
|
|
auto* numbers = new gltfItem_number_array( "" );
|
2022-06-05 22:39:04 +00:00
|
|
|
idList<double> numberarray;
|
|
|
|
numbers->Set( &numberarray, parser );
|
|
|
|
numbers->parse( token );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( numbers->item->Num() != 4 )
|
|
|
|
{
|
|
|
|
common->FatalError( "gltfItem_quat : missing arguments, expectd 4, got %i", numbers->item->Num( ) );
|
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
double* val = numbers->item->Ptr();
|
2022-06-05 22:39:04 +00:00
|
|
|
*item = idQuat( val[0] , val[1] , val[2] , val[3] );
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_mat4::parse( idToken& token )
|
|
|
|
{
|
|
|
|
auto* numbers = new gltfItem_number_array( "" );
|
2022-06-05 22:39:04 +00:00
|
|
|
idList<double> numberarray;
|
|
|
|
numbers->Set( &numberarray, parser );
|
|
|
|
numbers->parse( token );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( numbers->item->Num( ) != 16 )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->FatalError( "gltfItem_mat4 : missing arguments, expectd 16, got %i", numbers->item->Num( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
double* val = numbers->item->Ptr( );
|
|
|
|
*item = idMat4(
|
|
|
|
val[0], val[1], val[2], val[3],
|
|
|
|
val[4], val[5], val[6], val[7],
|
|
|
|
val[8], val[9], val[10], val[11],
|
|
|
|
val[12], val[13], val[14], val[15]
|
|
|
|
);
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_accessor_sparse::parse( idToken& token )
|
|
|
|
{
|
|
|
|
parser->Warning( "%s is untested!", "gltfItem_accessor_sparse" );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
gltfItemArray sparse;
|
|
|
|
GLTFARRAYITEM( sparse, count, gltfItem_integer );
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( sparse, indices, gltfItem_accessor_sparse_indices );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( sparse, values, gltfItem_accessor_sparse_values );
|
|
|
|
GLTFARRAYITEM( sparse, extensions, gltfItem );
|
|
|
|
GLTFARRAYITEM( sparse, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
GLTFARRAYITEMREF( item, count );
|
2022-06-06 14:13:32 +00:00
|
|
|
indices->Set( &item->indices, parser );
|
|
|
|
values->Set( &item->values, parser );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEMREF( item, extensions );
|
2022-06-06 14:13:32 +00:00
|
|
|
extras->Set( &item->extras, parser );
|
2022-06-05 22:39:04 +00:00
|
|
|
sparse.Parse( parser );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", token.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_accessor_sparse_values::parse( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser->Warning( "%s is untested!", "gltfItem_accessor_sparse_values" );
|
|
|
|
|
|
|
|
gltfItemArray values;
|
|
|
|
GLTFARRAYITEM( values, bufferView, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( values, byteOffset, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( values, extensions, gltfItem );
|
|
|
|
GLTFARRAYITEM( values, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
GLTFARRAYITEMREF( item, bufferView );
|
|
|
|
GLTFARRAYITEMREF( item, byteOffset );
|
|
|
|
GLTFARRAYITEMREF( item, extensions );
|
2022-06-06 14:13:32 +00:00
|
|
|
extras->Set( &item->extras, parser );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", token.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_accessor_sparse_indices::parse( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser->Warning( "%s is untested!", "gltfItem_accessor_sparse_indices" );
|
|
|
|
|
|
|
|
gltfItemArray indices;
|
|
|
|
GLTFARRAYITEM( indices, bufferView, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( indices, byteOffset, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( indices, componentType, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( indices, extensions, gltfItem );
|
|
|
|
GLTFARRAYITEM( indices, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
GLTFARRAYITEMREF( item, bufferView );
|
|
|
|
GLTFARRAYITEMREF( item, byteOffset );
|
|
|
|
GLTFARRAYITEMREF( item, componentType );
|
|
|
|
GLTFARRAYITEMREF( item, extensions );
|
2022-06-06 14:13:32 +00:00
|
|
|
extras->Set( &item->extras, parser );
|
2022-06-05 22:39:04 +00:00
|
|
|
indices.Parse( parser );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", token.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_camera_orthographic::parse( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
gltfPropertyArray array = gltfPropertyArray( parser );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& prop : array )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", prop.item.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
parser->ExpectTokenString( "]" );
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_camera_perspective::parse( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
parser->UnreadToken( &token );
|
|
|
|
gltfItemArray cameraPerspective;
|
|
|
|
GLTFARRAYITEM( cameraPerspective, aspectRatio, gltfItem_number );
|
|
|
|
GLTFARRAYITEM( cameraPerspective, yfov, gltfItem_number );
|
|
|
|
GLTFARRAYITEM( cameraPerspective, zfar, gltfItem_number );
|
|
|
|
GLTFARRAYITEM( cameraPerspective, znear, gltfItem_number );
|
|
|
|
GLTFARRAYITEM( cameraPerspective, extensions, gltfItem );
|
|
|
|
GLTFARRAYITEM( cameraPerspective, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
GLTFARRAYITEMREF( item, aspectRatio );
|
|
|
|
GLTFARRAYITEMREF( item, yfov );
|
|
|
|
GLTFARRAYITEMREF( item, zfar );
|
|
|
|
GLTFARRAYITEMREF( item, znear );
|
|
|
|
GLTFARRAYITEMREF( item, extensions );
|
2022-06-06 14:13:32 +00:00
|
|
|
extras->Set( &item->extras, parser );
|
2022-06-05 22:39:04 +00:00
|
|
|
cameraPerspective.Parse( parser );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", token.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_occlusion_texture::parse( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser->UnreadToken( &token );
|
|
|
|
gltfItemArray textureInfo;
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( textureInfo, index, gltfItem_integer );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( textureInfo, texCoord, gltfItem_integer );
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( textureInfo, strength, gltfItem_number );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( textureInfo, extensions, gltfItem_texture_info_extensions );
|
|
|
|
GLTFARRAYITEM( textureInfo, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
GLTFARRAYITEMREF( item, index );
|
|
|
|
GLTFARRAYITEMREF( item, texCoord );
|
|
|
|
GLTFARRAYITEMREF( item, strength );
|
2022-06-06 14:13:32 +00:00
|
|
|
extensions->Set( &item->extensions, parser );
|
|
|
|
extras->Set( &item->extras, parser );
|
2022-06-05 22:39:04 +00:00
|
|
|
textureInfo.Parse( parser );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", token.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_normal_texture::parse( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser->UnreadToken( &token );
|
|
|
|
gltfItemArray textureInfo;
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( textureInfo, index, gltfItem_integer );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( textureInfo, texCoord, gltfItem_integer );
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( textureInfo, scale, gltfItem_number );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( textureInfo, extensions, gltfItem_texture_info_extensions );
|
|
|
|
GLTFARRAYITEM( textureInfo, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
GLTFARRAYITEMREF( item, index );
|
|
|
|
GLTFARRAYITEMREF( item, texCoord );
|
|
|
|
GLTFARRAYITEMREF( item, scale );
|
2022-06-06 14:13:32 +00:00
|
|
|
extensions->Set( &item->extensions, parser );
|
|
|
|
extras->Set( &item->extras, parser );
|
2022-06-05 22:39:04 +00:00
|
|
|
textureInfo.Parse( parser );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", token.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_texture_info::parse( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser->UnreadToken( &token );
|
|
|
|
gltfItemArray textureInfo;
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( textureInfo, index, gltfItem_integer );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( textureInfo, texCoord, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( textureInfo, extensions, gltfItem_texture_info_extensions );
|
|
|
|
GLTFARRAYITEM( textureInfo, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
GLTFARRAYITEMREF( item, index );
|
|
|
|
GLTFARRAYITEMREF( item, texCoord );
|
2022-06-06 14:13:32 +00:00
|
|
|
extensions->Set( &item->extensions, parser );
|
|
|
|
extras->Set( &item->extras, parser );
|
2022-06-05 22:39:04 +00:00
|
|
|
textureInfo.Parse( parser );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", token.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_pbrMetallicRoughness::parse( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
parser->UnreadToken( &token );
|
|
|
|
gltfItemArray pbrMetallicRoughness;
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( pbrMetallicRoughness, baseColorFactor, gltfItem_vec4 );
|
|
|
|
GLTFARRAYITEM( pbrMetallicRoughness, baseColorTexture, gltfItem_texture_info );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( pbrMetallicRoughness, metallicFactor, gltfItem_number );
|
|
|
|
GLTFARRAYITEM( pbrMetallicRoughness, roughnessFactor, gltfItem_number );
|
|
|
|
GLTFARRAYITEM( pbrMetallicRoughness, metallicRoughnessTexture, gltfItem_texture_info );
|
|
|
|
GLTFARRAYITEM( pbrMetallicRoughness, extensions, gltfItem );
|
|
|
|
GLTFARRAYITEM( pbrMetallicRoughness, extras, gltfItem_Extra );
|
2022-06-06 14:13:32 +00:00
|
|
|
|
|
|
|
baseColorFactor->Set( &item->baseColorFactor, parser );
|
|
|
|
baseColorTexture->Set( &item->baseColorTexture, parser );
|
|
|
|
GLTFARRAYITEMREF( item, metallicFactor );
|
|
|
|
GLTFARRAYITEMREF( item, roughnessFactor );
|
2022-06-05 22:39:04 +00:00
|
|
|
metallicRoughnessTexture->Set( &item->metallicRoughnessTexture, parser );
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEMREF( item, extensions );
|
|
|
|
extras->Set( &item->extras, parser );
|
2022-06-05 22:39:04 +00:00
|
|
|
pbrMetallicRoughness.Parse( parser );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", token.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_TextureInfo_KHR_texture_transform::parse( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser->UnreadToken( &token );
|
|
|
|
gltfItemArray texureTransform;
|
|
|
|
GLTFARRAYITEM( texureTransform, offset, gltfItem_vec2 );
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( texureTransform, rotation, gltfItem_number );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( texureTransform, scale, gltfItem_vec2 );
|
|
|
|
GLTFARRAYITEM( texureTransform, texCoord, gltfItem_integer );
|
|
|
|
|
|
|
|
item->KHR_texture_transform = new gltfExt_KHR_texture_transform( );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
offset->Set( &item->KHR_texture_transform->offset, parser );
|
|
|
|
GLTFARRAYITEMREF( item->KHR_texture_transform, rotation );
|
|
|
|
scale->Set( &item->KHR_texture_transform->scale, parser );
|
|
|
|
GLTFARRAYITEMREF( item->KHR_texture_transform, texCoord );
|
2022-06-05 22:39:04 +00:00
|
|
|
texureTransform.Parse( parser );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", token.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_Material_KHR_materials_pbrSpecularGlossiness::parse( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
parser->UnreadToken( &token );
|
|
|
|
gltfItemArray khrPbr;
|
|
|
|
GLTFARRAYITEM( khrPbr, diffuseFactor, gltfItem_vec4 );
|
|
|
|
GLTFARRAYITEM( khrPbr, diffuseTexture, gltfItem_texture_info );
|
|
|
|
GLTFARRAYITEM( khrPbr, specularFactor, gltfItem_vec3 );
|
|
|
|
GLTFARRAYITEM( khrPbr, glossinessFactor, gltfItem_number );
|
|
|
|
GLTFARRAYITEM( khrPbr, specularGlossinessTexture, gltfItem_texture_info );
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( khrPbr, extensions, gltfItem );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( khrPbr, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
item->KHR_materials_pbrSpecularGlossiness = new gltfExt_KHR_materials_pbrSpecularGlossiness( );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
diffuseFactor->Set( &item->KHR_materials_pbrSpecularGlossiness->diffuseFactor, parser );
|
|
|
|
diffuseTexture->Set( &item->KHR_materials_pbrSpecularGlossiness->diffuseTexture, parser );
|
|
|
|
specularFactor->Set( &item->KHR_materials_pbrSpecularGlossiness->specularFactor, parser );
|
|
|
|
GLTFARRAYITEMREF( item->KHR_materials_pbrSpecularGlossiness, glossinessFactor );
|
|
|
|
specularGlossinessTexture->Set( &item->KHR_materials_pbrSpecularGlossiness->specularGlossinessTexture, parser );
|
|
|
|
GLTFARRAYITEMREF( item->KHR_materials_pbrSpecularGlossiness, extensions );
|
|
|
|
extras->Set( &item->KHR_materials_pbrSpecularGlossiness->extras, parser );
|
2022-06-05 22:39:04 +00:00
|
|
|
khrPbr.Parse( parser );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", token.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_Node_KHR_lights_punctual::parse( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
parser->UnreadToken( &token );
|
|
|
|
gltfItemArray xlight;
|
|
|
|
GLTFARRAYITEM( xlight, light, gltfItem_integer );
|
|
|
|
item->KHR_lights_punctual = new gltfNode_KHR_lights_punctual( );
|
|
|
|
light->Set( &item->KHR_lights_punctual->light );
|
|
|
|
xlight.Parse( parser );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", token.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_KHR_lights_punctual::parse( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
idToken localToken;
|
|
|
|
parser->ExpectTokenString( "lights" );
|
|
|
|
parser->ExpectTokenString( ":" );
|
|
|
|
|
|
|
|
gltfItemArray light;
|
|
|
|
GLTFARRAYITEM( light, color, gltfItem_vec3 );
|
|
|
|
GLTFARRAYITEM( light, intensity, gltfItem_number );
|
|
|
|
//GLTFARRAYITEM( light, spot, gltfItem );
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( light, type, gltfItem );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( light, range, gltfItem_number );
|
|
|
|
GLTFARRAYITEM( light, name, gltfItem );
|
|
|
|
GLTFARRAYITEM( light, extensions, gltfItem );
|
|
|
|
GLTFARRAYITEM( light, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
gltfPropertyArray array = gltfPropertyArray( parser );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& prop : array )
|
|
|
|
{
|
2022-06-17 23:18:28 +00:00
|
|
|
idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfNode_light", 0 );
|
|
|
|
|
|
|
|
item->KHR_lights_punctual.AssureSizeAlloc(
|
|
|
|
item->KHR_lights_punctual.Num( ) + 1,
|
|
|
|
idListNewElement<gltfExt_KHR_lights_punctual> );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfExt_KHR_lights_punctual* gltfLight =
|
2022-06-05 22:39:04 +00:00
|
|
|
item->KHR_lights_punctual[item->KHR_lights_punctual.Num( ) - 1];
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
color->Set( &gltfLight->color, &lexer );
|
|
|
|
GLTFARRAYITEMREF( gltfLight, intensity );
|
2022-06-05 22:39:04 +00:00
|
|
|
//GLTFARRAYITEMREF (gltfLight, spot );
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEMREF( gltfLight, type );
|
|
|
|
GLTFARRAYITEMREF( gltfLight, range );
|
|
|
|
GLTFARRAYITEMREF( gltfLight, name );
|
|
|
|
GLTFARRAYITEMREF( gltfLight, extensions );
|
|
|
|
extras->Set( &gltfLight->extras, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
light.Parse( &lexer );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfLight->intType = gltfExt_KHR_lights_punctual::resolveType( gltfLight->type );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", prop.item.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
parser->ExpectTokenString( "]" );
|
|
|
|
parser->ExpectTokenString( "}" );
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_node_extensions::parse( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
parser->UnreadToken( &token );
|
|
|
|
gltfItemArray extensions;
|
|
|
|
GLTFARRAYITEM( extensions, KHR_lights_punctual, gltfItem_Node_KHR_lights_punctual );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
KHR_lights_punctual->Set( item, parser );
|
2022-06-05 22:39:04 +00:00
|
|
|
extensions.Parse( parser );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", token.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_material_extensions::parse( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser->UnreadToken( &token );
|
|
|
|
|
|
|
|
gltfItemArray extensions;
|
|
|
|
GLTFARRAYITEM( extensions, KHR_materials_pbrSpecularGlossiness, gltfItem_Material_KHR_materials_pbrSpecularGlossiness );
|
|
|
|
|
|
|
|
KHR_materials_pbrSpecularGlossiness->Set( item, parser );
|
|
|
|
extensions.Parse( parser );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", token.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void gltfItem_texture_info_extensions::parse( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser->UnreadToken( &token );
|
|
|
|
|
|
|
|
gltfItemArray extensions;
|
|
|
|
GLTFARRAYITEM( extensions, KHR_texture_transform, gltfItem_TextureInfo_KHR_texture_transform );
|
|
|
|
|
|
|
|
KHR_texture_transform->Set( item, parser );
|
|
|
|
extensions.Parse( parser );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", token.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::Shutdown( )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser.FreeSource();
|
|
|
|
currentFile.FreeData();
|
|
|
|
}
|
|
|
|
GLTF_Parser::GLTF_Parser()
|
2022-06-06 14:13:32 +00:00
|
|
|
: parser( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES ) , buffersDone( false ), bufferViewsDone( false ) { }
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::Parse_ASSET( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
idStr section;
|
|
|
|
parser.ParseBracedSection( section );
|
2022-06-06 14:13:32 +00:00
|
|
|
common->Printf( "%s\n", section.c_str( ) );
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::Parse_SCENE( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
currentAsset->DefaultScene( ) = parser.ParseInt( );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
|
|
|
common->Printf( " ^1 %s scene ^6 : ^8 %i", token.c_str( ), currentAsset->DefaultScene( ) );
|
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::Parse_SCENES( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
gltfItemArray scene;
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( scene, nodes, gltfItem_integer_array );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( scene, name, gltfItem );
|
|
|
|
GLTFARRAYITEM( scene, extensions, gltfItem );
|
|
|
|
GLTFARRAYITEM( scene, extras, gltfItem_Extra );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfPropertyArray array = gltfPropertyArray( &parser );
|
|
|
|
for( auto& prop : array )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-17 23:18:28 +00:00
|
|
|
idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfScene", 0 );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfScene* gltfscene = currentAsset->Scene();
|
|
|
|
nodes->Set( &gltfscene->nodes, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEMREF( gltfscene, name );
|
|
|
|
GLTFARRAYITEMREF( gltfscene, extensions );
|
2022-06-06 14:13:32 +00:00
|
|
|
extras->Set( &gltfscene->extras, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
scene.Parse( &lexer );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
|
|
|
common->Printf( "%s", prop.item.c_str() );
|
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
parser.ExpectTokenString( "]" );
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::Parse_CAMERAS( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
gltfItemArray camera;
|
|
|
|
GLTFARRAYITEM( camera, orthographic, gltfItem_camera_orthographic );
|
|
|
|
GLTFARRAYITEM( camera, perspective, gltfItem_camera_perspective );
|
|
|
|
GLTFARRAYITEM( camera, type, gltfItem );
|
|
|
|
GLTFARRAYITEM( camera, name, gltfItem );
|
|
|
|
GLTFARRAYITEM( camera, extensions, gltfItem );
|
|
|
|
GLTFARRAYITEM( camera, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
gltfPropertyArray array = gltfPropertyArray( &parser );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& prop : array )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-17 23:18:28 +00:00
|
|
|
idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfCamera", 0 );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfCamera* item = currentAsset->Camera( );
|
2022-06-05 22:39:04 +00:00
|
|
|
orthographic->Set( &item->orthographic, &lexer );
|
2022-06-06 14:13:32 +00:00
|
|
|
perspective->Set( &item->perspective, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
GLTFARRAYITEMREF( item, type );
|
|
|
|
GLTFARRAYITEMREF( item, name );
|
|
|
|
GLTFARRAYITEMREF( item, extensions );
|
2022-06-06 14:13:32 +00:00
|
|
|
extras->Set( &item->extras, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
camera.Parse( &lexer );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", prop.item.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
parser.ExpectTokenString( "]" );
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::Parse_NODES( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-06 14:13:32 +00:00
|
|
|
|
2022-06-05 22:39:04 +00:00
|
|
|
gltfItemArray node;
|
|
|
|
GLTFARRAYITEM( node, camera, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( node, children, gltfItem_integer_array );
|
|
|
|
GLTFARRAYITEM( node, skin, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( node, matrix, gltfItem_mat4 );
|
|
|
|
GLTFARRAYITEM( node, mesh, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( node, rotation, gltfItem_quat );
|
|
|
|
GLTFARRAYITEM( node, scale, gltfItem_vec3 );
|
|
|
|
GLTFARRAYITEM( node, translation, gltfItem_vec3 );
|
|
|
|
GLTFARRAYITEM( node, weights, gltfItem_number_array );
|
|
|
|
GLTFARRAYITEM( node, name, gltfItem );
|
|
|
|
GLTFARRAYITEM( node, extensions, gltfItem_node_extensions );
|
|
|
|
GLTFARRAYITEM( node, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
gltfPropertyArray array = gltfPropertyArray( &parser );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& prop : array )
|
|
|
|
{
|
2022-06-17 23:18:28 +00:00
|
|
|
idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfNode", 0 );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfNode* gltfnode = currentAsset->Node( );
|
|
|
|
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEMREF( gltfnode, camera );
|
2022-06-06 14:13:32 +00:00
|
|
|
matrix->Set( &gltfnode->matrix, &lexer );
|
|
|
|
children->Set( &gltfnode->children, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEMREF( gltfnode, skin );
|
2022-06-06 14:13:32 +00:00
|
|
|
matrix->Set( &gltfnode->matrix, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEMREF( gltfnode, mesh );
|
2022-06-06 14:13:32 +00:00
|
|
|
rotation->Set( &gltfnode->rotation, &lexer );
|
|
|
|
scale->Set( &gltfnode->scale, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
translation->Set( &gltfnode->translation, &lexer );
|
2022-06-06 14:13:32 +00:00
|
|
|
weights->Set( &gltfnode->weights, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEMREF( gltfnode, name );
|
2022-06-06 14:13:32 +00:00
|
|
|
extensions->Set( &gltfnode->extensions, &lexer );
|
|
|
|
extras->Set( &gltfnode->extras, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
node.Parse( &lexer );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", prop.item.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
parser.ExpectTokenString( "]" );
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::Parse_MATERIALS( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
gltfItemArray material;
|
|
|
|
GLTFARRAYITEM( material, pbrMetallicRoughness, gltfItem_pbrMetallicRoughness );
|
|
|
|
GLTFARRAYITEM( material, normalTexture, gltfItem_normal_texture );
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( material, occlusionTexture, gltfItem_occlusion_texture );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( material, emissiveTexture, gltfItem_texture_info );
|
|
|
|
GLTFARRAYITEM( material, emissiveFactor, gltfItem_vec3 );
|
|
|
|
GLTFARRAYITEM( material, alphaMode, gltfItem );
|
|
|
|
GLTFARRAYITEM( material, alphaCutoff, gltfItem_number );
|
|
|
|
GLTFARRAYITEM( material, doubleSided, gltfItem_boolean );
|
|
|
|
GLTFARRAYITEM( material, name, gltfItem );
|
|
|
|
GLTFARRAYITEM( material, extensions, gltfItem_material_extensions );
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( material, extras, gltfItem_Extra );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
gltfPropertyArray array = gltfPropertyArray( &parser );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& prop : array )
|
|
|
|
{
|
2022-06-17 23:18:28 +00:00
|
|
|
idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfMaterial", 0 );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfMaterial* gltfmaterial = currentAsset->Material( );
|
|
|
|
|
|
|
|
pbrMetallicRoughness->Set( &gltfmaterial->pbrMetallicRoughness, &lexer );
|
|
|
|
normalTexture->Set( &gltfmaterial->normalTexture, &lexer );
|
|
|
|
occlusionTexture->Set( &gltfmaterial->occlusionTexture, &lexer );
|
|
|
|
emissiveTexture->Set( &gltfmaterial->emissiveTexture, &lexer );
|
|
|
|
emissiveFactor->Set( &gltfmaterial->emissiveFactor, &lexer );
|
|
|
|
GLTFARRAYITEMREF( gltfmaterial, alphaMode );
|
|
|
|
GLTFARRAYITEMREF( gltfmaterial, alphaCutoff );
|
|
|
|
GLTFARRAYITEMREF( gltfmaterial, doubleSided );
|
|
|
|
GLTFARRAYITEMREF( gltfmaterial, name );
|
|
|
|
extensions->Set( &gltfmaterial->extensions, &lexer );
|
|
|
|
extras->Set( &gltfmaterial->extras, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
material.Parse( &lexer );
|
|
|
|
|
|
|
|
gltfmaterial->intType = gltfMaterial::resolveAlphaMode( gltfmaterial->alphaMode );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", prop.item.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
parser.ExpectTokenString( "]" );
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::Parse_MESHES( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
gltfItemArray mesh;
|
|
|
|
GLTFARRAYITEM( mesh, primitives, gltfItem_mesh_primitive ); // object
|
|
|
|
GLTFARRAYITEM( mesh, weights, gltfItem_number_array ); //number[1 - *]
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( mesh, name, gltfItem );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( mesh, extensions, gltfItem );
|
|
|
|
GLTFARRAYITEM( mesh, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
gltfPropertyArray array = gltfPropertyArray( &parser );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& prop : array )
|
|
|
|
{
|
2022-06-17 23:18:28 +00:00
|
|
|
idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfMesh", 0 );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfMesh* gltfmesh = currentAsset->Mesh( );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
primitives->Set( &gltfmesh->primitives, &lexer );
|
|
|
|
weights->Set( &gltfmesh->weights, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEMREF( gltfmesh, name );
|
|
|
|
GLTFARRAYITEMREF( gltfmesh, extensions );
|
2022-06-06 14:13:32 +00:00
|
|
|
extras->Set( &gltfmesh->extras, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
mesh.Parse( &lexer );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", prop.item.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
parser.ExpectTokenString( "]" );
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::Parse_TEXTURES( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
gltfItemArray texture;
|
|
|
|
GLTFARRAYITEM( texture, sampler, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( texture, source, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( texture, name, gltfItem );
|
|
|
|
GLTFARRAYITEM( texture, extensions, gltfItem_texture_info_extensions );
|
|
|
|
GLTFARRAYITEM( texture, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
gltfPropertyArray array = gltfPropertyArray( &parser );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& prop : array )
|
|
|
|
{
|
2022-06-17 23:18:28 +00:00
|
|
|
idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfTexture", 0 );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfTexture* gltftexture = currentAsset->Texture( );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
GLTFARRAYITEMREF( gltftexture, sampler );
|
|
|
|
GLTFARRAYITEMREF( gltftexture, source );
|
|
|
|
GLTFARRAYITEMREF( gltftexture, name );
|
2022-06-06 14:13:32 +00:00
|
|
|
extensions->Set( &gltftexture->extensions, &lexer );
|
|
|
|
extras->Set( &gltftexture->extras, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
texture.Parse( &lexer );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", prop.item.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
parser.ExpectTokenString( "]" );
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::Parse_IMAGES( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
//reference impl
|
|
|
|
gltfPropertyArray array = gltfPropertyArray( &parser );
|
|
|
|
|
|
|
|
gltfItemArray propItems;
|
2022-06-06 14:13:32 +00:00
|
|
|
auto uri = new gltfItem_uri( "uri" );
|
|
|
|
propItems.AddItemDef( ( parsable* )uri );
|
|
|
|
auto mimeType = new gltfItem( "mimeType" );
|
|
|
|
propItems.AddItemDef( ( parsable* )mimeType );
|
|
|
|
auto bufferView = new gltfItem_integer( "bufferView" );
|
|
|
|
propItems.AddItemDef( ( parsable* )bufferView );
|
|
|
|
auto name = new gltfItem( "name" );
|
|
|
|
propItems.AddItemDef( ( parsable* )name );
|
|
|
|
auto extensions = new gltfItem( "extensions" );
|
|
|
|
propItems.AddItemDef( ( parsable* )extensions );
|
|
|
|
auto extras = new gltfItem_Extra( "extras" );
|
|
|
|
propItems.AddItemDef( ( parsable* ) extras );
|
|
|
|
|
|
|
|
for( auto& prop : array )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-17 23:18:28 +00:00
|
|
|
idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
2022-06-06 14:13:32 +00:00
|
|
|
lexer.LoadMemory( prop.item.c_str(), prop.item.Size(), "gltfImage", 0 );
|
|
|
|
|
|
|
|
gltfImage* image = currentAsset->Image();
|
|
|
|
uri->Set( &image->uri, &image->bufferView, currentAsset );
|
|
|
|
mimeType->Set( &image->mimeType );
|
|
|
|
bufferView->Set( &image->bufferView );
|
|
|
|
name->Set( &image->name );
|
|
|
|
extensions->Set( &image->extensions );
|
|
|
|
extras->Set( &image->extras, &lexer );
|
|
|
|
propItems.Parse( &lexer );
|
|
|
|
|
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", prop.item.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
//automate..
|
|
|
|
//image->bgfxTexture.handle.idx = UINT16_MAX;
|
|
|
|
}
|
|
|
|
parser.ExpectTokenString( "]" );
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::Parse_ACCESSORS( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
gltfItemArray accessor;
|
|
|
|
GLTFARRAYITEM( accessor, bufferView, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( accessor, byteOffset, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( accessor, componentType, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( accessor, normalized, gltfItem_boolean );
|
|
|
|
GLTFARRAYITEM( accessor, count, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( accessor, type, gltfItem );
|
|
|
|
GLTFARRAYITEM( accessor, max, gltfItem_number_array );
|
|
|
|
GLTFARRAYITEM( accessor, min, gltfItem_number_array );
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( accessor, sparse, gltfItem_accessor_sparse );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( accessor, name, gltfItem );
|
|
|
|
GLTFARRAYITEM( accessor, extensions, gltfItem );
|
|
|
|
GLTFARRAYITEM( accessor, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
gltfPropertyArray array = gltfPropertyArray( &parser );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& prop : array )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-17 23:18:28 +00:00
|
|
|
idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfAccessor", 0 );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfAccessor* item = currentAsset->Accessor();
|
|
|
|
GLTFARRAYITEMREF( item, bufferView );
|
|
|
|
GLTFARRAYITEMREF( item, byteOffset );
|
|
|
|
GLTFARRAYITEMREF( item, componentType );
|
|
|
|
GLTFARRAYITEMREF( item, normalized );
|
|
|
|
GLTFARRAYITEMREF( item, count );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEMREF( item, type );
|
2022-06-06 14:13:32 +00:00
|
|
|
max->Set( &item->max, &lexer );
|
|
|
|
min->Set( &item->min, &lexer );
|
|
|
|
sparse->Set( &item->sparse, &lexer );
|
|
|
|
GLTFARRAYITEMREF( item, name );
|
|
|
|
GLTFARRAYITEMREF( item, extensions );
|
|
|
|
extras->Set( &item->extras, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
accessor.Parse( &lexer );
|
|
|
|
|
|
|
|
GetComponentTypeEnum( item->componentType, &item->typeSize );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", prop.item.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
parser.ExpectTokenString( "]" );
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::Parse_BUFFERVIEWS( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
gltfItemArray bv;
|
|
|
|
GLTFARRAYITEM( bv, buffer, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( bv, byteLength, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( bv, byteStride, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( bv, byteOffset, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( bv, target, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( bv, name, gltfItem );
|
|
|
|
GLTFARRAYITEM( bv, extensions, gltfItem );
|
|
|
|
GLTFARRAYITEM( bv, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
gltfPropertyArray array = gltfPropertyArray( &parser );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& prop : array )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-17 23:18:28 +00:00
|
|
|
idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfBufferView", 0 );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfBufferView* gltfBV = currentAsset->BufferView();
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEMREF( gltfBV, buffer );
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEMREF( gltfBV, byteLength );
|
|
|
|
GLTFARRAYITEMREF( gltfBV, byteStride );
|
|
|
|
GLTFARRAYITEMREF( gltfBV, byteOffset );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEMREF( gltfBV, target );
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEMREF( gltfBV, name );
|
|
|
|
GLTFARRAYITEMREF( gltfBV, extensions );
|
|
|
|
extras->Set( &gltfBV->extras, &lexer );
|
|
|
|
bv.Parse( &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
gltfBV->parent = currentAsset;
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool() )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", prop.item.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
parser.ExpectTokenString( "]" );
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::Parse_SAMPLERS( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
gltfItemArray sampl;
|
|
|
|
GLTFARRAYITEM( sampl, magFilter, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( sampl, minFilter, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( sampl, wrapS, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( sampl, wrapT, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( sampl, name, gltfItem );
|
|
|
|
GLTFARRAYITEM( sampl, extensions, gltfItem );
|
|
|
|
GLTFARRAYITEM( sampl, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
gltfPropertyArray array = gltfPropertyArray( &parser );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& prop : array )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-17 23:18:28 +00:00
|
|
|
idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfSampler", 0 );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfSampler* gltfSampl = currentAsset->Sampler();
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEMREF( gltfSampl, magFilter );
|
|
|
|
GLTFARRAYITEMREF( gltfSampl, minFilter );
|
|
|
|
GLTFARRAYITEMREF( gltfSampl, wrapS );
|
|
|
|
GLTFARRAYITEMREF( gltfSampl, wrapT );
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEMREF( gltfSampl, name );
|
|
|
|
GLTFARRAYITEMREF( gltfSampl, extensions );
|
|
|
|
extras->Set( &gltfSampl->extras, &lexer );
|
|
|
|
sampl.Parse( &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool() )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", prop.item.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
parser.ExpectTokenString( "]" );
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::Parse_BUFFERS( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
gltfItemArray buf;
|
|
|
|
GLTFARRAYITEM( buf, uri, gltfItem_uri );
|
|
|
|
GLTFARRAYITEM( buf, byteLength, gltfItem_integer );
|
|
|
|
GLTFARRAYITEM( buf, name, gltfItem );
|
|
|
|
GLTFARRAYITEM( buf, extensions, gltfItem );
|
|
|
|
GLTFARRAYITEM( buf, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
gltfPropertyArray array = gltfPropertyArray( &parser );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& prop : array )
|
|
|
|
{
|
2022-06-17 23:18:28 +00:00
|
|
|
idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfBuffer", 0 );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfBuffer* gltfBuf = currentAsset->Buffer( );
|
2022-06-05 22:39:04 +00:00
|
|
|
gltfBuf->parent = currentAsset;
|
|
|
|
|
|
|
|
uri->Set( &gltfBuf->uri, nullptr , currentAsset );
|
|
|
|
GLTFARRAYITEMREF( gltfBuf, byteLength );
|
|
|
|
GLTFARRAYITEMREF( gltfBuf, name );
|
|
|
|
GLTFARRAYITEMREF( gltfBuf, extensions );
|
2022-06-06 14:13:32 +00:00
|
|
|
extras->Set( &gltfBuf->extras, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
buf.Parse( &lexer );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", prop.item.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
parser.ExpectTokenString( "]" );
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::Parse_ANIMATIONS( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
gltfItemArray anim;
|
|
|
|
GLTFARRAYITEM( anim, channels, gltfItem_animation_channel ); //channel[1 - *]
|
|
|
|
GLTFARRAYITEM( anim, samplers, gltfItem_animation_sampler ); //sampler[1 - *]
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( anim, name, gltfItem );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( anim, extensions, gltfItem );
|
|
|
|
GLTFARRAYITEM( anim, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
gltfPropertyArray array = gltfPropertyArray( &parser );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& prop : array )
|
|
|
|
{
|
2022-06-17 23:18:28 +00:00
|
|
|
idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfAnimation", 0 );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfAnimation* gltfanim = currentAsset->Animation( );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
channels->Set( &gltfanim->channels, &lexer );
|
|
|
|
samplers->Set( &gltfanim->samplers, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEMREF( gltfanim, name );
|
|
|
|
GLTFARRAYITEMREF( gltfanim, extensions );
|
2022-06-06 14:13:32 +00:00
|
|
|
extras->Set( &gltfanim->extras, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
anim.Parse( &lexer );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", prop.item.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
parser.ExpectTokenString( "]" );
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::Parse_SKINS( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
gltfItemArray skin;
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( skin, inverseBindMatrices, gltfItem_integer );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( skin, skeleton, gltfItem_integer );
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTFARRAYITEM( skin, joints, gltfItem_integer_array );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEM( skin, name, gltfItem );
|
|
|
|
GLTFARRAYITEM( skin, extensions, gltfItem );
|
|
|
|
GLTFARRAYITEM( skin, extras, gltfItem_Extra );
|
|
|
|
|
|
|
|
gltfPropertyArray array = gltfPropertyArray( &parser );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& prop : array )
|
|
|
|
{
|
2022-06-17 23:18:28 +00:00
|
|
|
idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer.LoadMemory( prop.item.c_str( ), prop.item.Size( ), "gltfSkin", 0 );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfSkin* gltfSkin = currentAsset->Skin( );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
GLTFARRAYITEMREF( gltfSkin, inverseBindMatrices );
|
|
|
|
GLTFARRAYITEMREF( gltfSkin, skeleton );
|
2022-06-06 14:13:32 +00:00
|
|
|
joints->Set( &gltfSkin->joints, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
GLTFARRAYITEMREF( gltfSkin, name );
|
|
|
|
GLTFARRAYITEMREF( gltfSkin, extensions );
|
2022-06-06 14:13:32 +00:00
|
|
|
extras->Set( &gltfSkin->extras, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
skin.Parse( &lexer );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", prop.item.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
parser.ExpectTokenString( "]" );
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::Parse_EXTENSIONS( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
idStr json;
|
|
|
|
parser.ParseBracedSection( json );
|
|
|
|
|
|
|
|
gltfItemArray extensions;
|
|
|
|
//GLTFARRAYITEM( extensions, KHR_materials_pbrSpecularGlossiness, gltfItem_KHR_materials_pbrSpecularGlossiness );
|
|
|
|
GLTFARRAYITEM( extensions, KHR_lights_punctual, gltfItem_KHR_lights_punctual );
|
|
|
|
|
2022-06-17 23:18:28 +00:00
|
|
|
idLexer lexer( LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGESCAPECHARS );
|
2022-06-05 22:39:04 +00:00
|
|
|
lexer.LoadMemory( json.c_str( ), json.Size( ), "Extensions", 0 );
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfExtensions* gltfextension = currentAsset->Extensions();
|
2022-06-05 22:39:04 +00:00
|
|
|
//KHR_materials_pbrSpecularGlossiness->Set( &gltfextensions, &lexer );
|
2022-06-06 14:13:32 +00:00
|
|
|
KHR_lights_punctual->Set( gltfextension, &lexer );
|
2022-06-05 22:39:04 +00:00
|
|
|
extensions.Parse( &lexer );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", json.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::Parse_EXTENSIONS_USED( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfPropertyArray array = gltfPropertyArray( &parser, false );
|
|
|
|
for( auto& prop : array )
|
|
|
|
{
|
|
|
|
gltfExtensionsUsed* ext = currentAsset->ExtensionsUsed( );
|
2022-06-05 22:39:04 +00:00
|
|
|
ext->extension = prop.item;
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", prop.item.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
parser.ExpectTokenString( "]" );
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::Parse_EXTENSIONS_REQUIRED( idToken& token )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser.ExpectTokenString( "[" );
|
|
|
|
idStrList exts;
|
|
|
|
idToken item;
|
|
|
|
bool parsing = true;
|
2022-06-06 14:13:32 +00:00
|
|
|
while( parsing && parser.ExpectAnyToken( &item ) )
|
|
|
|
{
|
|
|
|
if( item.type != TT_STRING )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->FatalError( "malformed extensions_used array" );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
idStr& extension = exts.Alloc( );
|
2022-06-05 22:39:04 +00:00
|
|
|
extension = item.c_str( );
|
|
|
|
parsing = parser.PeekTokenString( "," );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( parsing )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser.ExpectTokenString( "," );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
parser.ExpectTokenString( "]" );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& out : exts )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s", out.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfProperty GLTF_Parser::ParseProp( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
parser.ExpectTokenString( ":" );
|
|
|
|
gltfProperty prop = ResolveProp( token );
|
|
|
|
|
|
|
|
bool skipping = false;
|
2022-06-06 14:13:32 +00:00
|
|
|
if( !buffersDone || !bufferViewsDone )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-06 14:13:32 +00:00
|
|
|
if( prop == BUFFERS && !buffersDone )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
Parse_BUFFERS( token );
|
|
|
|
return prop;
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
if( prop == BUFFERVIEWS && !bufferViewsDone )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
Parse_BUFFERVIEWS( token );
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
skipping = true;
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
|
|
|
common->DPrintf( "Searching for buffer tag. Skipping %s.", token.c_str() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-06 14:13:32 +00:00
|
|
|
if( ( prop == BUFFERS && buffersDone ) || ( prop == BUFFERVIEWS && bufferViewsDone ) )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
skipping = true;
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->DPrintf( "Skipping %s , already done.", token.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( skipping )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
//1. search for {} scope.
|
|
|
|
//2. search for [] scope.
|
|
|
|
//3. single token.
|
|
|
|
|
|
|
|
idToken skipTok;
|
|
|
|
int sectionsSkipped = 0;
|
2022-06-06 14:13:32 +00:00
|
|
|
if( parser.PeekTokenString( "{" ) )
|
|
|
|
{
|
|
|
|
parser.SkipBracedSection( true, BRSKIP_BRACES, §ionsSkipped );
|
|
|
|
}
|
|
|
|
if( !sectionsSkipped && parser.PeekTokenString( "[" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser.SkipBracedSection( true, BRSKIP_BRACKET, §ionsSkipped );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
if( !sectionsSkipped )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser.ExpectAnyToken( &skipTok );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
return gltfProperty::INVALID;
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
|
|
|
|
switch( prop )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
case ASSET:
|
|
|
|
Parse_ASSET( token );
|
|
|
|
break;
|
|
|
|
case CAMERAS:
|
|
|
|
Parse_CAMERAS( token );
|
|
|
|
break;
|
|
|
|
case SCENE:
|
|
|
|
Parse_SCENE( token );
|
|
|
|
break;
|
|
|
|
case SCENES:
|
|
|
|
Parse_SCENES( token );
|
|
|
|
break;
|
|
|
|
case NODES:
|
|
|
|
Parse_NODES( token );
|
|
|
|
break;
|
|
|
|
case MATERIALS:
|
|
|
|
Parse_MATERIALS( token );
|
|
|
|
break;
|
|
|
|
case MESHES:
|
|
|
|
Parse_MESHES( token );
|
|
|
|
break;
|
|
|
|
case TEXTURES:
|
|
|
|
Parse_TEXTURES( token );
|
|
|
|
break;
|
|
|
|
case IMAGES:
|
|
|
|
Parse_IMAGES( token );
|
|
|
|
break;
|
|
|
|
case ACCESSORS:
|
|
|
|
Parse_ACCESSORS( token );
|
|
|
|
break;
|
|
|
|
case BUFFERVIEWS:
|
|
|
|
//Parse_BUFFERVIEWS( token );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( !bufferViewsDone )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->FatalError( "Bufferviews should already be parsed!" );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
break;
|
|
|
|
case SAMPLERS:
|
|
|
|
Parse_SAMPLERS( token );
|
|
|
|
break;
|
|
|
|
case BUFFERS:
|
2022-06-06 14:13:32 +00:00
|
|
|
if( !buffersDone )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->FatalError( "Buffers should already be parsed!" );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
break;
|
|
|
|
case ANIMATIONS:
|
|
|
|
Parse_ANIMATIONS( token );
|
|
|
|
break;
|
|
|
|
case SKINS:
|
|
|
|
Parse_SKINS( token );
|
|
|
|
break;
|
|
|
|
case EXTENSIONS:
|
|
|
|
Parse_EXTENSIONS( token );
|
|
|
|
break;
|
|
|
|
case EXTENSIONS_USED:
|
|
|
|
Parse_EXTENSIONS_USED( token );
|
|
|
|
break;
|
|
|
|
case EXTENSIONS_REQUIRED:
|
|
|
|
Parse_EXTENSIONS_REQUIRED( token );
|
|
|
|
break;
|
|
|
|
default:
|
2022-06-06 14:13:32 +00:00
|
|
|
common->FatalError( "UnImplemented GLTF property : %s", token.c_str() );
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
return prop;
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfProperty GLTF_Parser::ResolveProp( idToken& token )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-06 14:13:32 +00:00
|
|
|
if( !idStr::Icmp( token.c_str( ), "asset" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return gltfProperty::ASSET;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else if( !idStr::Icmp( token.c_str( ), "cameras" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return gltfProperty::CAMERAS;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else if( !idStr::Icmp( token.c_str( ), "scene" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return gltfProperty::SCENE;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else if( !idStr::Icmp( token.c_str( ), "scenes" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return gltfProperty::SCENES;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else if( !idStr::Icmp( token.c_str( ), "nodes" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return gltfProperty::NODES;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else if( !idStr::Icmp( token.c_str( ), "materials" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return gltfProperty::MATERIALS;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else if( !idStr::Icmp( token.c_str( ), "meshes" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return gltfProperty::MESHES;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else if( !idStr::Icmp( token.c_str( ), "textures" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return gltfProperty::TEXTURES;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else if( !idStr::Icmp( token.c_str( ), "images" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return gltfProperty::IMAGES;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else if( !idStr::Icmp( token.c_str( ), "accessors" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return gltfProperty::ACCESSORS;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else if( !idStr::Icmp( token.c_str( ), "bufferViews" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return gltfProperty::BUFFERVIEWS;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else if( !idStr::Icmp( token.c_str( ), "samplers" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return gltfProperty::SAMPLERS;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else if( !idStr::Icmp( token.c_str( ), "buffers" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return gltfProperty::BUFFERS;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else if( !idStr::Icmp( token.c_str( ), "animations" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return gltfProperty::ANIMATIONS;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else if( !idStr::Icmp( token.c_str( ), "skins" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return gltfProperty::SKINS;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else if( !idStr::Icmp( token.c_str( ), "extensions" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return gltfProperty::EXTENSIONS;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else if( !idStr::Icmp( token.c_str( ), "extensionsused" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return gltfProperty::EXTENSIONS_USED;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else if( !idStr::Icmp( token.c_str( ), "extensionsrequired" ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return gltfProperty::EXTENSIONS_REQUIRED;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
return gltfProperty::INVALID;
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
bool GLTF_Parser::loadGLB( idStr filename )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-06 14:13:32 +00:00
|
|
|
idFile* file = fileSystem->OpenFileRead( filename );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( file->Length() < 20 )
|
|
|
|
{
|
|
|
|
common->FatalError( "Too short data size for glTF Binary." );
|
2022-06-05 22:39:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
idStr gltfMagic( "glTF" );
|
2022-06-05 22:39:04 +00:00
|
|
|
unsigned char fileMagic[5];
|
2022-06-06 14:13:32 +00:00
|
|
|
|
|
|
|
file->Read( ( void* )&fileMagic, 4 );
|
|
|
|
fileMagic[4] = 0;
|
|
|
|
if( gltfMagic.Icmp( ( const char* )&fileMagic ) == 0 )
|
|
|
|
{
|
|
|
|
common->Printf( "reading %s...\n", filename.c_str() );
|
|
|
|
}
|
|
|
|
else
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
common->Error( "invalid magic" );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int version = 0; // 4 bytes
|
|
|
|
unsigned int length = 0; // 4 bytes
|
|
|
|
|
|
|
|
//HVG_TODO
|
|
|
|
//handle 0 bin chunk -> size is chunk[0].size + 20;
|
|
|
|
file->ReadUnsignedInt( version );
|
|
|
|
file->ReadUnsignedInt( length );
|
|
|
|
length -= 12; // header size
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
unsigned int chunk_type = 0; // 4 bytes
|
|
|
|
unsigned int chunk_length = 0; // 4 bytes
|
|
|
|
byte* data = nullptr;
|
|
|
|
gltfData* dataCache = gltfData::Data( filename );
|
2022-06-05 22:39:04 +00:00
|
|
|
currentAsset = dataCache;
|
|
|
|
|
|
|
|
int chunkCount = 0;
|
2022-06-06 14:13:32 +00:00
|
|
|
while( length )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
unsigned int prev_length = chunk_length;
|
|
|
|
length -= file->ReadUnsignedInt( chunk_length );
|
|
|
|
length -= file->ReadUnsignedInt( chunk_type );
|
2022-06-06 14:13:32 +00:00
|
|
|
|
2022-06-05 22:39:04 +00:00
|
|
|
data = dataCache->AddData( chunk_length );
|
2022-06-06 14:13:32 +00:00
|
|
|
dataCache->FileName( filename );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
int read = file->Read( ( void* )data, chunk_length );
|
|
|
|
if( read != chunk_length )
|
|
|
|
{
|
|
|
|
common->FatalError( "Could not read full chunk (%i bytes) in file %s", chunk_length, filename );
|
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
length -= read;
|
2022-06-06 14:13:32 +00:00
|
|
|
if( chunk_type == gltfChunk_Type_JSON )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-17 23:18:28 +00:00
|
|
|
currentFile = filename ;
|
2022-06-06 14:13:32 +00:00
|
|
|
parser.LoadMemory( ( const char* )data, chunk_length, "gltfJson", 0 );
|
|
|
|
}
|
|
|
|
else if( !chunkCount )
|
|
|
|
{
|
|
|
|
common->FatalError( "first chunk was not a json chunk" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
common->Printf( "BINCHUNK %i %i bytes\n", chunkCount, chunk_length );
|
|
|
|
}
|
|
|
|
if( chunkCount++ && length )
|
|
|
|
{
|
|
|
|
common->FatalError( "corrupt glb file." );
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Parse();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
bool GLTF_Parser::Parse( )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
bool parsing = true;
|
|
|
|
parser.ExpectTokenString( "{" );
|
2022-06-06 14:13:32 +00:00
|
|
|
while( parsing && parser.ExpectAnyToken( &token ) )
|
|
|
|
{
|
|
|
|
if( token.type != TT_STRING )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->FatalError( "Expected an \"string\" " );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( token.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
gltfProperty prop = ParseProp( token );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( ( prop == BUFFERS && !buffersDone ) )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
parser.Reset();
|
|
|
|
parser.ExpectTokenString( "{" );
|
|
|
|
buffersDone = true;
|
|
|
|
continue;
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
if( ( prop == BUFFERVIEWS && !bufferViewsDone ) )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
parser.Reset( );
|
|
|
|
parser.ExpectTokenString( "{" );
|
|
|
|
bufferViewsDone = true;
|
|
|
|
continue;
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
if( gltf_parseVerbose.GetBool( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "\n" );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
parsing = parser.PeekTokenString( "," );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( parsing )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
parser.ExpectTokenString( "," );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
//we are at the end, and no bufferview or buffer has been found.
|
2022-06-06 14:13:32 +00:00
|
|
|
if( !buffersDone || !bufferViewsDone )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-06 14:13:32 +00:00
|
|
|
if( !buffersDone )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
buffersDone = true;
|
|
|
|
common->Printf( "no %s found", "buffers" );
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
if( !bufferViewsDone )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "no %s found", "bufferviews" );
|
|
|
|
bufferViewsDone = true;
|
|
|
|
}
|
|
|
|
parser.Reset( );
|
|
|
|
parser.ExpectTokenString( "{" );
|
|
|
|
parsing = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
parser.ExpectTokenString( "}" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//parser should be at end.
|
|
|
|
parser.ReadToken( &token );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( parser.EndOfFile( ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->Printf( "%s ^2loaded\n", currentFile.c_str( ) );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
else
|
2022-06-06 14:13:32 +00:00
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
common->FatalError( "%s not fully loaded.", currentFile );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
2022-06-05 22:39:04 +00:00
|
|
|
buffersDone = false;
|
|
|
|
bufferViewsDone = false;
|
|
|
|
return true;
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
|
|
|
|
bool GLTF_Parser::Load( idStr filename )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
//seriously fix this; proper gltf data cache.
|
|
|
|
//.. and destroy it properly too!!
|
|
|
|
static idStr lastFile = "";
|
|
|
|
|
|
|
|
//next line still has to be fixed.
|
|
|
|
//gfx is not updated on command
|
|
|
|
common->SetRefreshOnPrint( true );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( lastFile == filename )
|
|
|
|
{
|
|
|
|
common->Warning( "Did not parse %s again", filename.c_str() );
|
2022-06-05 22:39:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
lastFile = filename;
|
|
|
|
currentFile = filename;
|
2022-06-06 14:13:32 +00:00
|
|
|
if( filename.CheckExtension( ".glb" ) )
|
|
|
|
{
|
|
|
|
if( !loadGLB( filename ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return false;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
else if( filename.CheckExtension( ".gltf" ) )
|
|
|
|
{
|
|
|
|
int length = fileSystem->ReadFile( filename, NULL );
|
|
|
|
if( !length )
|
|
|
|
{
|
|
|
|
common->FatalError( "Failed to read file" );
|
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfData* data = gltfData::Data( filename );
|
|
|
|
data->FileName( filename );
|
|
|
|
byte* dataBuff = data->AddData( length );
|
2022-06-05 22:39:04 +00:00
|
|
|
currentAsset = data;
|
2022-06-06 14:13:32 +00:00
|
|
|
|
2022-06-05 22:39:04 +00:00
|
|
|
idFile* file = fileSystem->OpenFileRead( filename );
|
2022-06-06 14:13:32 +00:00
|
|
|
if( file->Read( dataBuff, length ) != length )
|
|
|
|
{
|
|
|
|
common->FatalError( "Cannot read file, %s", filename.c_str() );
|
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
fileSystem->CloseFile( file );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( !parser.LoadMemory( ( const char* )dataBuff, length, "GLTF_ASCII_JSON", 0 ) )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return false;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
2022-06-05 22:39:04 +00:00
|
|
|
Parse();
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
return false;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
parser.Reset();
|
|
|
|
parser.FreeSource();
|
|
|
|
common->SetRefreshOnPrint( false );
|
2022-06-06 14:13:32 +00:00
|
|
|
|
2022-06-05 22:39:04 +00:00
|
|
|
//fix up node hierarchy
|
2022-06-06 14:13:32 +00:00
|
|
|
auto& nodeList = currentAsset->NodeList( );
|
|
|
|
for( auto& scene : currentAsset->SceneList( ) )
|
|
|
|
for( auto& node : scene->nodes )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
SetNodeParent( nodeList[node] );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//prefix with id
|
|
|
|
if( gltfParser_PrefixNodeWithID.GetBool() )
|
|
|
|
for( int i = 0; i < nodeList.Num(); i++ )
|
|
|
|
{
|
|
|
|
nodeList[i]->name = "[" + idStr( i ) + "]" + nodeList[i]->name;
|
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
//CreateBgfxData();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
void GLTF_Parser::SetNodeParent( gltfNode* node, gltfNode* parent )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
node->parent = parent;
|
2022-06-06 14:13:32 +00:00
|
|
|
for( auto& child : node->children )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
SetNodeParent( currentAsset->NodeList()[child], node );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
void GLTF_Parser::CreateBgfxData( )
|
|
|
|
{
|
|
|
|
//buffers
|
2022-06-06 14:13:32 +00:00
|
|
|
for ( auto mesh : currentAsset->MeshList( ) )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-06 14:13:32 +00:00
|
|
|
for ( auto prim : mesh->primitives )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
//gltfAccessor -> idList<acessorType*>;
|
|
|
|
//vertex indices accessor
|
|
|
|
gltfAccessor * accessor = currentAsset->AccessorList( )[prim->indices];
|
|
|
|
gltfBufferView *bv = currentAsset->BufferViewList( )[accessor->bufferView];
|
|
|
|
gltfData *data = bv->parent;
|
|
|
|
|
|
|
|
gltfBuffer *buff = data->BufferList( )[bv->buffer];
|
|
|
|
uint idxDataSize = sizeof( uint ) * accessor->count;
|
|
|
|
uint * indices = ( uint *)Mem_ClearedAlloc( idxDataSize );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
idFile_Memory idxBin = idFile_Memory( "gltfChunkIndices",
|
2022-06-05 22:39:04 +00:00
|
|
|
( const char * ) ((data->GetData( bv->buffer ) + bv->byteOffset + accessor->byteOffset )), bv->byteLength );
|
|
|
|
|
|
|
|
for ( int i = 0; i < accessor->count; i++ ) {
|
|
|
|
idxBin.Read( ( void * ) ( &indices[i] ), accessor->typeSize );
|
|
|
|
if ( bv->byteStride )
|
|
|
|
idxBin.Seek( bv->byteStride - accessor->typeSize, FS_SEEK_CUR );
|
|
|
|
}
|
|
|
|
prim->indexBufferHandle = bgfx::createIndexBuffer(bgfx::copy( indices,idxDataSize ),BGFX_BUFFER_INDEX32);
|
|
|
|
|
|
|
|
Mem_Free( indices );
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
//vertex attribs
|
2022-06-05 22:39:04 +00:00
|
|
|
pbrVertex * vtxData = NULL;
|
|
|
|
uint vtxDataSize = 0;
|
|
|
|
bgfx::VertexLayout vtxLayout;
|
|
|
|
|
|
|
|
for ( auto & attrib : prim->attributes )
|
|
|
|
{
|
|
|
|
gltfAccessor * attrAcc = currentAsset->AccessorList( )[attrib->accessorIndex];
|
|
|
|
gltfBufferView *attrBv = currentAsset->BufferViewList( )[attrAcc->bufferView];
|
|
|
|
gltfData *attrData = attrBv->parent;
|
|
|
|
gltfBuffer *attrbuff = attrData->BufferList( )[attrBv->buffer];
|
|
|
|
|
|
|
|
idFile_Memory bin = idFile_Memory( "gltfChunkVertices",
|
|
|
|
( const char * )(( attrData->GetData( attrBv->buffer ) + attrBv->byteOffset + attrAcc->byteOffset )) , attrBv->byteLength );
|
|
|
|
|
|
|
|
if ( vtxData == nullptr ) {
|
|
|
|
vtxDataSize = sizeof( pbrVertex ) * attrAcc->count;
|
|
|
|
vtxData = ( pbrVertex * ) Mem_ClearedAlloc( vtxDataSize );
|
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
|
2022-06-05 22:39:04 +00:00
|
|
|
switch (attrib->bgfxType)
|
|
|
|
{
|
|
|
|
case bgfx::Attrib::Enum::Position : {
|
|
|
|
for ( int i = 0; i < attrAcc->count; i++ ) {
|
|
|
|
bin.Read( ( void * ) ( &vtxData[i].pos.x ), attrAcc->typeSize );
|
|
|
|
bin.Read( ( void * ) ( &vtxData[i].pos.y ), attrAcc->typeSize );
|
|
|
|
bin.Read( ( void * ) ( &vtxData[i].pos.z ), attrAcc->typeSize );
|
|
|
|
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 bgfx::Attrib::Enum::Normal : {
|
|
|
|
for ( int i = 0; i < attrAcc->count; i++ ) {
|
|
|
|
bin.Read( ( void * ) ( &vtxData[i].normal.x ), attrAcc->typeSize );
|
|
|
|
bin.Read( ( void * ) ( &vtxData[i].normal.y ), attrAcc->typeSize );
|
|
|
|
bin.Read( ( void * ) ( &vtxData[i].normal.z ), attrAcc->typeSize );
|
|
|
|
if ( attrBv->byteStride )
|
|
|
|
bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case bgfx::Attrib::Enum::TexCoord0:{
|
|
|
|
for ( int i = 0; i < attrAcc->count; i++ ) {
|
|
|
|
bin.Read( ( void * ) ( &vtxData[i].uv.x ), attrAcc->typeSize );
|
|
|
|
bin.Read( ( void * ) ( &vtxData[i].uv.y ), attrAcc->typeSize );
|
|
|
|
if ( attrBv->byteStride )
|
|
|
|
bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case bgfx::Attrib::Enum::Tangent:
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < attrAcc->count; i++ ) {
|
|
|
|
bin.Read( ( void * ) ( &vtxData[i].tangent.x ), attrAcc->typeSize );
|
|
|
|
bin.Read( ( void * ) ( &vtxData[i].tangent.y ), attrAcc->typeSize );
|
|
|
|
bin.Read( ( void * ) ( &vtxData[i].tangent.z ), attrAcc->typeSize );
|
|
|
|
bin.Read( ( void * ) ( &vtxData[i].tangent.w ), attrAcc->typeSize );
|
|
|
|
if ( attrBv->byteStride )
|
|
|
|
bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case bgfx::Attrib::Enum::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 bgfx::Attrib::Enum::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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vtxLayout.begin( )
|
|
|
|
.add( bgfx::Attrib::Position, 3, bgfx::AttribType::Float )
|
|
|
|
.add( bgfx::Attrib::Normal, 3, bgfx::AttribType::Float )
|
|
|
|
.add( bgfx::Attrib::Tangent, 4, bgfx::AttribType::Float )
|
|
|
|
.add( bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float )
|
|
|
|
.add( bgfx::Attrib::Weight, 4, bgfx::AttribType::Float,true )
|
|
|
|
.add( bgfx::Attrib::Indices, 4, bgfx::AttribType::Uint8,false,true )
|
|
|
|
//.add( bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true )
|
|
|
|
.end( );
|
|
|
|
vtxLayout.end();
|
|
|
|
if ( vtxData != NULL ) {
|
|
|
|
prim->vertexBufferHandle = bgfx::createVertexBuffer(
|
|
|
|
bgfx::copy( vtxData, vtxDataSize ), vtxLayout );
|
|
|
|
|
|
|
|
Mem_Free( vtxData );
|
|
|
|
}else
|
|
|
|
common->FatalError("Failed to read vertex info" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto & samplerList = currentAsset->SamplerList( );
|
2022-06-06 14:13:32 +00:00
|
|
|
//Samplers -> this should move to read/parse sampler call
|
2022-06-05 22:39:04 +00:00
|
|
|
for ( auto &sampler : samplerList )
|
|
|
|
sampler->bgfxSamplerFlags = GetSamplerFlags(sampler);
|
2022-06-06 14:13:32 +00:00
|
|
|
|
2022-06-05 22:39:04 +00:00
|
|
|
auto & imgList = currentAsset->ImageList( );
|
|
|
|
//textures
|
2022-06-06 14:13:32 +00:00
|
|
|
for ( auto &texture : currentAsset->TextureList( ) )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
|
|
|
auto * image = imgList[texture->source];
|
|
|
|
if ( image->bgfxTexture.handle.idx == UINT16_MAX ) {
|
|
|
|
gltfBufferView *bv = currentAsset->BufferViewList( )[image->bufferView];
|
|
|
|
gltfData *data = bv->parent;
|
|
|
|
gltfBuffer *buff = data->BufferList( )[bv->buffer];
|
|
|
|
|
|
|
|
//image->bgfxTexture = bgfxImageLoad(data->GetData(bv->buffer) + bv->byteOffset,bv->byteLength );
|
|
|
|
bgfxImageLoadAsync( data->GetData( bv->buffer ) + bv->byteOffset, bv->byteLength, &image->bgfxTexture, samplerList[texture->sampler]->bgfxSamplerFlags );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
idList<gltfArticulatedFigure*> afs;
|
|
|
|
//AF
|
|
|
|
for (auto * skin : currentAsset->SkinList() ){
|
|
|
|
afs.Alloc() = new gltfArticulatedFigure(skin,currentAsset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
idList<float>& gltfData::GetAccessorView( gltfAccessor* accessor )
|
|
|
|
{
|
|
|
|
idList<float>*& floatView = accessor->floatView;;
|
|
|
|
|
|
|
|
if( floatView == nullptr )
|
2022-06-05 22:39:04 +00:00
|
|
|
{
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfBufferView* attrBv = bufferViews[accessor->bufferView];
|
|
|
|
gltfData* attrData = attrBv->parent;
|
|
|
|
gltfBuffer* attrbuff = attrData->BufferList( )[attrBv->buffer];
|
|
|
|
assert( sizeof( float ) == accessor->typeSize );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
idFile_Memory bin = idFile_Memory( "GetAccessorView(float)",
|
2022-06-06 14:13:32 +00:00
|
|
|
( const char* )( ( attrData->GetData( attrBv->buffer ) + attrBv->byteOffset + accessor->byteOffset ) ), attrBv->byteLength );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
floatView = new idList<float>( 16 );
|
|
|
|
floatView->AssureSize( accessor->count );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( int i = 0; i < accessor->count; i++ )
|
|
|
|
{
|
|
|
|
bin.Read( ( void* ) & ( *floatView )[i] , accessor->typeSize );
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
if( attrBv->byteStride )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
bin.Seek( attrBv->byteStride - ( accessor->typeSize ), FS_SEEK_CUR );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
return *floatView;
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
idList<idMat4>& gltfData::GetAccessorViewMat( gltfAccessor* accessor )
|
|
|
|
{
|
|
|
|
idList<idMat4>*& matView = accessor->matView;
|
|
|
|
if( matView == nullptr )
|
|
|
|
{
|
|
|
|
gltfBufferView* attrBv = bufferViews[accessor->bufferView];
|
|
|
|
gltfData* attrData = attrBv->parent;
|
|
|
|
gltfBuffer* attrbuff = attrData->BufferList( )[attrBv->buffer];
|
2022-06-05 22:39:04 +00:00
|
|
|
assert( sizeof( float ) == accessor->typeSize );
|
|
|
|
|
|
|
|
idFile_Memory bin = idFile_Memory( "GetAccessorView(idMat4*)",
|
2022-06-06 14:13:32 +00:00
|
|
|
( const char* )( ( attrData->GetData( attrBv->buffer ) + attrBv->byteOffset + accessor->byteOffset ) ), attrBv->byteLength );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
size_t elementSize = accessor->typeSize * 16;
|
|
|
|
matView = new idList<idMat4>( 16 );
|
|
|
|
matView->AssureSize( accessor->count );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( int i = 0; i < accessor->count; i++ )
|
|
|
|
{
|
|
|
|
bin.Read( ( void* ) & ( *matView )[i] , elementSize );
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
if( attrBv->byteStride )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
bin.Seek( attrBv->byteStride - elementSize, FS_SEEK_CUR );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
return *matView;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
2022-06-06 14:13:32 +00:00
|
|
|
idList<idVec3*>& gltfData::GetAccessorView( gltfAccessor* accessor )
|
|
|
|
{
|
|
|
|
idList<idVec3*>*& vecView = accessor->vecView;
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( vecView == nullptr )
|
|
|
|
{
|
|
|
|
gltfBufferView* attrBv = bufferViews[accessor->bufferView];
|
|
|
|
gltfData* attrData = attrBv->parent;
|
|
|
|
gltfBuffer* attrbuff = attrData->BufferList( )[attrBv->buffer];
|
|
|
|
assert( sizeof( float ) == accessor->typeSize );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
idFile_Memory bin = idFile_Memory( "GetAccessorView(idVec3*)",
|
2022-06-06 14:13:32 +00:00
|
|
|
( const char* )( ( attrData->GetData( attrBv->buffer ) + attrBv->byteOffset + accessor->byteOffset ) ), attrBv->byteLength );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
vecView = new idList<idVec3*>( 16 );
|
2022-06-05 22:39:04 +00:00
|
|
|
vecView->AssureSizeAlloc( accessor->count, idListNewElement<idVec3> );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( int i = 0; i < accessor->count; i++ )
|
|
|
|
{
|
|
|
|
idVec3& vec = *( *vecView )[i];
|
|
|
|
bin.Read( ( void* ) &vec.x , accessor->typeSize );
|
|
|
|
bin.Read( ( void* ) &vec.y , accessor->typeSize );
|
|
|
|
bin.Read( ( void* ) &vec.z , accessor->typeSize );
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
2022-06-06 14:13:32 +00:00
|
|
|
if( attrBv->byteStride )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
bin.Seek( attrBv->byteStride - ( 3 * accessor->typeSize ), FS_SEEK_CUR );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
return *vecView;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2022-06-06 14:13:32 +00:00
|
|
|
idList<idQuat*>& gltfData::GetAccessorView( gltfAccessor* accessor )
|
|
|
|
{
|
|
|
|
idList<idQuat*>*& quatView = accessor->quatView;
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( quatView == nullptr )
|
|
|
|
{
|
|
|
|
gltfBufferView* attrBv = bufferViews[accessor->bufferView];
|
|
|
|
gltfData* attrData = attrBv->parent;
|
|
|
|
gltfBuffer* attrbuff = attrData->BufferList( )[attrBv->buffer];
|
2022-06-05 22:39:04 +00:00
|
|
|
assert( sizeof( float ) == accessor->typeSize );
|
|
|
|
|
|
|
|
idFile_Memory bin = idFile_Memory( "GetAccessorView(idQuat*)",
|
2022-06-06 14:13:32 +00:00
|
|
|
( const char* )( ( attrData->GetData( attrBv->buffer ) + attrBv->byteOffset + accessor->byteOffset ) ), attrBv->byteLength );
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
quatView = new idList<idQuat*>( 16 );
|
2022-06-05 22:39:04 +00:00
|
|
|
quatView->AssureSizeAlloc( accessor->count, idListNewElement<idQuat> );
|
2022-06-06 14:13:32 +00:00
|
|
|
for( int i = 0; i < accessor->count; i++ )
|
|
|
|
{
|
|
|
|
idQuat& vec = *( *quatView )[i];
|
|
|
|
bin.Read( ( void* ) &vec.x, accessor->typeSize );
|
|
|
|
bin.Read( ( void* ) &vec.y, accessor->typeSize );
|
|
|
|
bin.Read( ( void* ) &vec.z, accessor->typeSize );
|
|
|
|
bin.Read( ( void* ) &vec.w, accessor->typeSize );
|
|
|
|
}
|
|
|
|
if( attrBv->byteStride )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
bin.Seek( attrBv->byteStride - ( 4 * accessor->typeSize ), FS_SEEK_CUR );
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
return *quatView;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
gltfData::~gltfData()
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
//hvg_todo
|
|
|
|
//delete data, not only pointer
|
2022-06-06 14:13:32 +00:00
|
|
|
common->Warning( "GLTF DATA NOT FREED" );
|
|
|
|
if( data )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
delete[] data;
|
2022-06-06 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
2022-06-05 22:39:04 +00:00
|
|
|
//delete cameraManager;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
GLTF_Parser localGltfParser;
|
2022-06-06 14:13:32 +00:00
|
|
|
GLTF_Parser* gltfParser = &localGltfParser;
|
2022-06-05 22:39:04 +00:00
|
|
|
|
|
|
|
#undef GLTFARRAYITEM
|
|
|
|
#undef GLTFARRAYITEMREF
|
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
CONSOLE_COMMAND_COMPILE( LoadGLTF, "Loads an .gltf or .glb file", idCmdSystem::ArgCompletion_MapName )
|
|
|
|
{
|
2022-06-05 22:39:04 +00:00
|
|
|
|
2022-06-06 14:13:32 +00:00
|
|
|
if( args.Argc( ) > 1 )
|
|
|
|
{
|
|
|
|
gltfParser->Load( args.Argv( 1 ) );
|
2022-06-05 22:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
//+set r_fullscreen 0 +set com_allowConsole 1 +set developer 1 +set fs_debug 0 +set win_outputDebugString 1 +set fs_basepath "E:\SteamLibrary\steamapps\common\DOOM 3 BFG Edition\"
|