mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-03-14 22:50:45 +00:00
Fixed Linux compile issues caused by glTF2 code
This commit is contained in:
parent
fd6eee32e3
commit
3c1bcc2153
8 changed files with 269 additions and 48 deletions
|
@ -95,8 +95,11 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* p
|
|||
Mem_Free( indices );
|
||||
bool sizeSet = false;
|
||||
|
||||
for( auto& attrib : prim->attributes )
|
||||
//for( const auto& attrib : prim->attributes )
|
||||
for( int a = 0; a < prim->attributes.Num(); a++ )
|
||||
{
|
||||
gltfMesh_Primitive_Attribute* attrib = prim->attributes[a];
|
||||
|
||||
gltfAccessor* attrAcc = data->AccessorList()[attrib->accessorIndex];
|
||||
gltfBufferView* attrBv = data->BufferViewList()[attrAcc->bufferView];
|
||||
gltfData* attrData = attrBv->parent;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
Doom 3 BFG Edition GPL Source Code
|
||||
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
||||
Copyright (C) 2022 Stephen Pridham
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
||||
|
@ -30,6 +31,7 @@ If you have questions concerning this license or the applicable additional terms
|
|||
#define __LIST_H__
|
||||
|
||||
#include <new>
|
||||
#include <initializer_list>
|
||||
|
||||
/*
|
||||
===============================================================================
|
||||
|
@ -124,6 +126,7 @@ public:
|
|||
|
||||
idList( int newgranularity = 16 );
|
||||
idList( const idList& other );
|
||||
idList( std::initializer_list<_type_> initializerList );
|
||||
~idList();
|
||||
|
||||
void Clear(); // clear the list
|
||||
|
@ -200,6 +203,7 @@ public:
|
|||
memTag = ( byte )tag_;
|
||||
};
|
||||
|
||||
/*
|
||||
struct Iterator
|
||||
{
|
||||
_type_* p;
|
||||
|
@ -225,6 +229,54 @@ public:
|
|||
{
|
||||
return Iterator{list + Num()};
|
||||
};
|
||||
*/
|
||||
|
||||
// Begin/End methods for range-based for loops.
|
||||
_type_* begin()
|
||||
{
|
||||
if( num > 0 )
|
||||
{
|
||||
return &list[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
_type_* end()
|
||||
{
|
||||
if( num > 0 )
|
||||
{
|
||||
return &list[num - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
const _type_* begin() const
|
||||
{
|
||||
if( num > 0 )
|
||||
{
|
||||
return &list[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
const _type_* end() const
|
||||
{
|
||||
if( num > 0 )
|
||||
{
|
||||
return &list[num - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int num;
|
||||
|
@ -262,6 +314,14 @@ ID_INLINE idList<_type_, _tag_>::idList( const idList& other )
|
|||
*this = other;
|
||||
}
|
||||
|
||||
template< typename _type_, memTag_t _tag_ >
|
||||
ID_INLINE idList<_type_, _tag_>::idList( std::initializer_list<_type_> initializerList )
|
||||
: idList( 16 )
|
||||
{
|
||||
SetNum( initializerList.size() );
|
||||
std::copy( initializerList.begin(), initializerList.end(), list );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
idList<_type_,_tag_>::~idList< _type_, _tag_ >
|
||||
|
@ -312,7 +372,10 @@ ID_INLINE void idList<_type_, _tag_>::DeleteContents( bool clear )
|
|||
|
||||
for( i = 0; i < num; i++ )
|
||||
{
|
||||
delete list[ i ];
|
||||
if( list[i] )
|
||||
{
|
||||
delete list[i];
|
||||
}
|
||||
list[ i ] = NULL;
|
||||
}
|
||||
|
||||
|
@ -548,7 +611,6 @@ ID_INLINE void idList<_type_, _tag_>::AssureSize( int newSize )
|
|||
|
||||
if( newSize > size )
|
||||
{
|
||||
|
||||
if( granularity == 0 ) // this is a hack to fix our memset classes
|
||||
{
|
||||
granularity = 16;
|
||||
|
@ -557,9 +619,9 @@ ID_INLINE void idList<_type_, _tag_>::AssureSize( int newSize )
|
|||
newSize += granularity - 1;
|
||||
newSize -= newSize % granularity;
|
||||
Resize( newSize );
|
||||
}
|
||||
|
||||
num = newNum;
|
||||
num = newNum;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
|
||||
idStaticList();
|
||||
idStaticList( const idStaticList<type, size>& other );
|
||||
idStaticList( std::initializer_list<type> initializerList );
|
||||
~idStaticList<type, size>();
|
||||
|
||||
void Clear(); // marks the list as empty. does not deallocate or intialize data.
|
||||
|
@ -114,6 +115,13 @@ ID_INLINE idStaticList<type, size>::idStaticList( const idStaticList<type, size>
|
|||
*this = other;
|
||||
}
|
||||
|
||||
template<class type, int size>
|
||||
ID_INLINE idStaticList<type, size>::idStaticList( std::initializer_list<type> initializerList )
|
||||
{
|
||||
SetNum( initializerList.size() );
|
||||
std::copy( initializerList.begin(), initializerList.end(), list );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
idStaticList<type,size>::~idStaticList<type,size>
|
||||
|
|
|
@ -290,6 +290,11 @@ gltfPropertyArray::Iterator gltfPropertyArray::end()
|
|||
return Iterator{ this , endPtr};
|
||||
}
|
||||
|
||||
gltfItemArray::~gltfItemArray()
|
||||
{
|
||||
items.DeleteContents( true );
|
||||
}
|
||||
|
||||
int gltfItemArray::Fill( idLexer* lexer, idDict* strPairs )
|
||||
{
|
||||
idToken token;
|
||||
|
@ -1975,7 +1980,7 @@ bool GLTF_Parser::loadGLB( idStr filename )
|
|||
int read = file->Read( ( void* )data, chunk_length );
|
||||
if( read != chunk_length )
|
||||
{
|
||||
common->FatalError( "Could not read full chunk (%i bytes) in file %s", chunk_length, filename );
|
||||
common->FatalError( "Could not read full chunk (%i bytes) in file %s", chunk_length, filename.c_str() );
|
||||
}
|
||||
length -= read;
|
||||
if( chunk_type == gltfChunk_Type_JSON )
|
||||
|
@ -2075,7 +2080,7 @@ bool GLTF_Parser::Parse()
|
|||
}
|
||||
else
|
||||
{
|
||||
common->FatalError( "%s not fully loaded.", currentFile );
|
||||
common->FatalError( "%s not fully loaded.", currentFile.c_str() );
|
||||
}
|
||||
|
||||
buffersDone = false;
|
||||
|
|
|
@ -37,6 +37,8 @@ If you have questions concerning this license or the applicable additional terms
|
|||
struct parsable
|
||||
{
|
||||
public:
|
||||
virtual ~parsable() {}
|
||||
|
||||
virtual void parse( idToken& token ) = 0;
|
||||
virtual void parse( idToken& token , idLexer* parser ) {};
|
||||
virtual idStr& Name() = 0;
|
||||
|
@ -229,10 +231,7 @@ gltfItemClass( boolean, bool, if( token.Icmp( "true" ) == 0 ) *item = true; else
|
|||
class gltfItemArray
|
||||
{
|
||||
public:
|
||||
~gltfItemArray()
|
||||
{
|
||||
items.DeleteContents( true );
|
||||
}
|
||||
~gltfItemArray();
|
||||
gltfItemArray() { };
|
||||
int Num()
|
||||
{
|
||||
|
|
|
@ -752,9 +752,9 @@ public:
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//// For these to function you need to add an private idList<gltf{name}*> {target}
|
||||
#define GLTFCACHEITEM(name,target) \
|
||||
gltf##name * name () { target.AssureSizeAlloc( target.Num()+1,idListNewElement<gltf##name>); return target[target.Num()-1];} \
|
||||
const inline idList<gltf##name*> & ##name##List() { return target; }
|
||||
//#define GLTFCACHEITEM(name,target) \
|
||||
//gltf##name * name () { target.AssureSizeAlloc( target.Num()+1,idListNewElement<gltf##name>); return target[target.Num()-1];} \
|
||||
//const inline idList<gltf##name*> & ##name##List() { return target; }
|
||||
|
||||
|
||||
// URI's are resolved during parsing so that
|
||||
|
@ -1254,6 +1254,162 @@ public:
|
|||
{
|
||||
return scene;
|
||||
}
|
||||
|
||||
//#define GLTFCACHEITEM(name,target) \
|
||||
//gltf##name * name () { target.AssureSizeAlloc( target.Num()+1,idListNewElement<gltf##name>); return target[target.Num()-1];} \
|
||||
//const inline idList<gltf##name*> & ##name##List() { return target; }
|
||||
|
||||
gltfBuffer* Buffer()
|
||||
{
|
||||
buffers.AssureSizeAlloc( buffers.Num() + 1 , idListNewElement<gltfBuffer> );
|
||||
return buffers[buffers.Num() - 1];
|
||||
}
|
||||
const inline idList<gltfBuffer*>& BufferList()
|
||||
{
|
||||
return buffers;
|
||||
}
|
||||
|
||||
gltfSampler* Sampler()
|
||||
{
|
||||
samplers.AssureSizeAlloc( samplers.Num() + 1 , idListNewElement<gltfSampler> );
|
||||
return samplers[samplers.Num() - 1];
|
||||
}
|
||||
const inline idList<gltfSampler*>& SamplerList()
|
||||
{
|
||||
return samplers;
|
||||
}
|
||||
|
||||
gltfBufferView* BufferView()
|
||||
{
|
||||
bufferViews.AssureSizeAlloc( bufferViews.Num() + 1 , idListNewElement<gltfBufferView> );
|
||||
return bufferViews[bufferViews.Num() - 1];
|
||||
}
|
||||
const inline idList<gltfBufferView*>& BufferViewList()
|
||||
{
|
||||
return bufferViews;
|
||||
}
|
||||
|
||||
gltfImage* Image()
|
||||
{
|
||||
images.AssureSizeAlloc( images.Num() + 1 , idListNewElement<gltfImage> );
|
||||
return images[images.Num() - 1];
|
||||
}
|
||||
const inline idList<gltfImage*>& ImageList()
|
||||
{
|
||||
return images;
|
||||
}
|
||||
|
||||
gltfTexture* Texture()
|
||||
{
|
||||
textures.AssureSizeAlloc( textures.Num() + 1 , idListNewElement<gltfTexture> );
|
||||
return textures[textures.Num() - 1];
|
||||
}
|
||||
const inline idList<gltfTexture*>& TextureList()
|
||||
{
|
||||
return textures;
|
||||
}
|
||||
|
||||
gltfAccessor* Accessor()
|
||||
{
|
||||
accessors.AssureSizeAlloc( accessors.Num() + 1 , idListNewElement<gltfAccessor> );
|
||||
return accessors[accessors.Num() - 1];
|
||||
}
|
||||
const inline idList<gltfAccessor*>& AccessorList()
|
||||
{
|
||||
return accessors;
|
||||
}
|
||||
|
||||
gltfExtensionsUsed* ExtensionsUsed()
|
||||
{
|
||||
extensionsUsed.AssureSizeAlloc( accessors.Num() + 1 , idListNewElement<gltfExtensionsUsed> );
|
||||
return extensionsUsed[extensionsUsed.Num() - 1];
|
||||
}
|
||||
const inline idList<gltfExtensionsUsed*>& ExtensionsUsedList()
|
||||
{
|
||||
return extensionsUsed;
|
||||
}
|
||||
|
||||
gltfMesh* Mesh()
|
||||
{
|
||||
meshes.AssureSizeAlloc( meshes.Num() + 1 , idListNewElement<gltfMesh> );
|
||||
return meshes[meshes.Num() - 1];
|
||||
}
|
||||
const inline idList<gltfMesh*>& MeshList()
|
||||
{
|
||||
return meshes;
|
||||
}
|
||||
|
||||
gltfScene* Scene()
|
||||
{
|
||||
scenes.AssureSizeAlloc( scenes.Num() + 1 , idListNewElement<gltfScene> );
|
||||
return scenes[scenes.Num() - 1];
|
||||
}
|
||||
const inline idList<gltfScene*>& SceneList()
|
||||
{
|
||||
return scenes;
|
||||
}
|
||||
|
||||
gltfNode* Node()
|
||||
{
|
||||
nodes.AssureSizeAlloc( nodes.Num() + 1 , idListNewElement<gltfNode> );
|
||||
return nodes[nodes.Num() - 1];
|
||||
}
|
||||
const inline idList<gltfNode*>& NodeList()
|
||||
{
|
||||
return nodes;
|
||||
}
|
||||
|
||||
gltfCamera* Camera()
|
||||
{
|
||||
cameras.AssureSizeAlloc( cameras.Num() + 1 , idListNewElement<gltfCamera> );
|
||||
return cameras[cameras.Num() - 1];
|
||||
}
|
||||
const inline idList<gltfCamera*>& CameraList()
|
||||
{
|
||||
return cameras;
|
||||
}
|
||||
|
||||
gltfMaterial* Material()
|
||||
{
|
||||
materials.AssureSizeAlloc( materials.Num() + 1 , idListNewElement<gltfMaterial> );
|
||||
return materials[materials.Num() - 1];
|
||||
}
|
||||
const inline idList<gltfMaterial*>& MaterialList()
|
||||
{
|
||||
return materials;
|
||||
}
|
||||
|
||||
gltfExtensions* Extensions()
|
||||
{
|
||||
extensions.AssureSizeAlloc( extensions.Num() + 1 , idListNewElement<gltfExtensions> );
|
||||
return extensions[extensions.Num() - 1];
|
||||
}
|
||||
const inline idList<gltfExtensions*>& ExtensionsList()
|
||||
{
|
||||
return extensions;
|
||||
}
|
||||
|
||||
gltfAnimation* Animation()
|
||||
{
|
||||
animations.AssureSizeAlloc( animations.Num() + 1 , idListNewElement<gltfAnimation> );
|
||||
return animations[animations.Num() - 1];
|
||||
}
|
||||
const inline idList<gltfAnimation*>& AnimationList()
|
||||
{
|
||||
return animations;
|
||||
}
|
||||
|
||||
gltfSkin* Skin()
|
||||
{
|
||||
skins.AssureSizeAlloc( skins.Num() + 1 , idListNewElement<gltfSkin> );
|
||||
return skins[skins.Num() - 1];
|
||||
}
|
||||
const inline idList<gltfSkin*>& SkinList()
|
||||
{
|
||||
return skins;
|
||||
}
|
||||
|
||||
/*
|
||||
GLTFCACHEITEM( Buffer, buffers )
|
||||
GLTFCACHEITEM( Sampler, samplers )
|
||||
GLTFCACHEITEM( BufferView, bufferViews )
|
||||
|
@ -1269,6 +1425,7 @@ public:
|
|||
GLTFCACHEITEM( Extensions, extensions )
|
||||
GLTFCACHEITEM( Animation, animations )
|
||||
GLTFCACHEITEM( Skin, skins )
|
||||
*/
|
||||
|
||||
//gltfCameraManager * cameraManager;
|
||||
private:
|
||||
|
|
|
@ -357,6 +357,20 @@ bool idRenderModelGLTF::LoadBinaryModel( idFile* file, const ID_TIME_T sourceTim
|
|||
return true;
|
||||
}
|
||||
|
||||
const idMD5Joint* idRenderModelGLTF::FindMD5Joint( const idStr& name ) const
|
||||
{
|
||||
for( auto& joint : md5joints )
|
||||
{
|
||||
if( joint.name == name )
|
||||
{
|
||||
return &joint;
|
||||
}
|
||||
}
|
||||
assert( 0 );
|
||||
static idMD5Joint staticJoint;
|
||||
return &staticJoint;
|
||||
}
|
||||
|
||||
void idRenderModelGLTF::UpdateMd5Joints()
|
||||
{
|
||||
md5joints.Clear();
|
||||
|
@ -386,20 +400,6 @@ void idRenderModelGLTF::UpdateMd5Joints()
|
|||
}
|
||||
}
|
||||
|
||||
auto findMd5Joint = [&]( idStr & name ) -> auto
|
||||
{
|
||||
for( auto& joint : md5joints )
|
||||
{
|
||||
if( joint.name == name )
|
||||
{
|
||||
return &joint;
|
||||
}
|
||||
}
|
||||
assert( 0 );
|
||||
static idMD5Joint staticJoint;
|
||||
return &staticJoint;
|
||||
};
|
||||
|
||||
for( int i = 0 ; i < bones.Num(); i++ )
|
||||
{
|
||||
gltfNode* node = nodeList[bones[i]];
|
||||
|
@ -407,11 +407,11 @@ void idRenderModelGLTF::UpdateMd5Joints()
|
|||
{
|
||||
if( node->parent->name == ovrBoneName )
|
||||
{
|
||||
md5joints[i].parent = findMd5Joint( idStr( "origin" ) );
|
||||
md5joints[i].parent = FindMD5Joint( idStr( "origin" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
md5joints[i].parent = findMd5Joint( node->parent->name );
|
||||
md5joints[i].parent = FindMD5Joint( node->parent->name );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -715,7 +715,7 @@ idFile_Memory* idRenderModelGLTF::GetAnimBin( idStr animName , const ID_TIME_T
|
|||
// max_timestamp_value / totalFrames
|
||||
// but keeping it fixed for now.
|
||||
frameRate = gltf_AnimSampleRate.GetInteger();
|
||||
INT animLength = ( ( numFrames - 1 ) * 1000 + frameRate - 1 ) / frameRate;
|
||||
int animLength = ( ( numFrames - 1 ) * 1000 + frameRate - 1 ) / frameRate;
|
||||
|
||||
for( int i = 0; i < jointInfo.Num(); i++ )
|
||||
{
|
||||
|
@ -1152,28 +1152,13 @@ void idRenderModelGLTF::LoadModel()
|
|||
}
|
||||
}
|
||||
|
||||
auto findMd5Joint = [&]( idStr & name ) -> auto
|
||||
{
|
||||
for( auto& joint : md5joints )
|
||||
{
|
||||
if( joint.name == name )
|
||||
{
|
||||
return &joint;
|
||||
}
|
||||
}
|
||||
assert( 0 );
|
||||
static idMD5Joint staticJoint;
|
||||
return &staticJoint;
|
||||
};
|
||||
|
||||
|
||||
for( int i = 0; i < bones.Num(); i++ )
|
||||
{
|
||||
auto* node = nodes[bones[i]];
|
||||
|
||||
if( i && node->parent && node->parent != root )
|
||||
{
|
||||
md5joints[i].parent = findMd5Joint( node->parent->name );
|
||||
md5joints[i].parent = FindMD5Joint( node->parent->name );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1658,7 +1643,7 @@ const idJointQuat* idRenderModelGLTF::GetDefaultPose() const
|
|||
|
||||
int idRenderModelGLTF::NearestJoint( int surfaceNum, int a, int b, int c ) const
|
||||
{
|
||||
for( modelSurface_t& surf : surfaces )
|
||||
for( const modelSurface_t& surf : surfaces )
|
||||
{
|
||||
idDrawVert* verts = surf.geometry->verts;
|
||||
int numVerts = surf.geometry->numVerts;
|
||||
|
|
|
@ -60,6 +60,8 @@ private:
|
|||
void ProcessNode( gltfNode* modelNode, idMat4 trans, gltfData* data );
|
||||
void UpdateSurface( const struct renderEntity_s* ent, const idJointMat* entJoints, const idJointMat* entJointsInverted, modelSurface_t* surf, const modelSurface_t& sourceSurf );
|
||||
void UpdateMd5Joints();
|
||||
|
||||
const idMD5Joint* FindMD5Joint( const idStr& name ) const;
|
||||
gltfData* data;
|
||||
gltfNode* root;
|
||||
bool fileExclusive;
|
||||
|
|
Loading…
Reference in a new issue