diff --git a/neo/idlib/MapFile.cpp b/neo/idlib/MapFile.cpp index 5baa75fb..e6cdcac7 100644 --- a/neo/idlib/MapFile.cpp +++ b/neo/idlib/MapFile.cpp @@ -1452,7 +1452,7 @@ unsigned int idMapEntity::GetGeometryCRC() const idMapPrimitive* mapPrim; crc = 0; - for(int i = 0; i < GetNumPrimitives(); i++ ) + for( int i = 0; i < GetNumPrimitives(); i++ ) { mapPrim = GetPrimitive( i ); @@ -2776,13 +2776,13 @@ unsigned int MapPolygonMesh::GetGeometryCRC() const unsigned int crc = 0; for( i = 0; i < verts.Num(); i++ ) { - crc ^= StringCRC((verts[i].xyz * (i+1)).ToString()); + crc ^= StringCRC( ( verts[i].xyz * ( i + 1 ) ).ToString() ); } for( i = 0; i < polygons.Num(); i++ ) { const MapPolygon& poly = polygons[i]; - crc ^= StringCRC( poly.GetMaterial() + idStr(i) ); + crc ^= StringCRC( poly.GetMaterial() + idStr( i ) ); } return crc; diff --git a/neo/idlib/MapFile.h b/neo/idlib/MapFile.h index b1798551..f3aa31b9 100644 --- a/neo/idlib/MapFile.h +++ b/neo/idlib/MapFile.h @@ -349,7 +349,7 @@ public: void ConvertFromBrush( const idMapBrush* brush, int entityNum, int primitiveNum ); void ConvertFromPatch( const idMapPatch* patch, int entityNum, int primitiveNum ); - static MapPolygonMesh* ConvertFromMeshGltf( const gltfMesh_Primitive * prim, gltfData* _data ); + static MapPolygonMesh* ConvertFromMeshGltf( const gltfMesh_Primitive* prim, gltfData* _data ); static MapPolygonMesh* Parse( idLexer& src, const idVec3& origin, float version = CURRENT_MAP_VERSION ); bool Write( idFile* fp, int primitiveNum, const idVec3& origin ) const; diff --git a/neo/renderer/Model_gltf.cpp b/neo/renderer/Model_gltf.cpp index 4e50c175..2bd4c95f 100644 --- a/neo/renderer/Model_gltf.cpp +++ b/neo/renderer/Model_gltf.cpp @@ -13,20 +13,25 @@ bool idRenderModelStatic::ConvertGltfMeshToModelsurfaces( const gltfMesh* mesh ) return false; } -MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive * prim, gltfData* _data ) +MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* prim, gltfData* _data ) { MapPolygonMesh* mesh = new MapPolygonMesh(); gltfAccessor* accessor = _data->AccessorList( )[prim->indices]; gltfBufferView* bv = _data->BufferViewList( )[accessor->bufferView]; gltfData* data = bv->parent; - gltfMaterial* mat = _data->MaterialList()[prim->material]; + + gltfMaterial* mat = NULL; + if( prim->material != -1 ) + { + mat = _data->MaterialList()[prim->material]; + } gltfBuffer* buff = data->BufferList( )[bv->buffer]; uint idxDataSize = sizeof( uint ) * accessor->count; uint* indices = ( uint* ) Mem_ClearedAlloc( idxDataSize , TAG_IDLIB_GLTF ); idFile_Memory idxBin = idFile_Memory( "gltfChunkIndices", - ( const char* )( ( data->GetData( bv->buffer ) + bv->byteOffset + accessor->byteOffset ) ), bv->byteLength ); + ( const char* )( ( data->GetData( bv->buffer ) + bv->byteOffset + accessor->byteOffset ) ), bv->byteLength ); for( int i = 0; i < accessor->count; i++ ) { @@ -40,7 +45,16 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive * for( int i = 0; i < accessor->count; i += 3 ) { MapPolygon& polygon = mesh->polygons.Alloc(); - polygon.SetMaterial( mat->name ); + + if( mat != NULL ) + { + polygon.SetMaterial( mat->name ); + } + else + { + polygon.SetMaterial( "textures/base_wall/snpanel2rust" ); + } + polygon.AddIndex( indices[i + 2] ); polygon.AddIndex( indices[i + 1] ); polygon.AddIndex( indices[i + 0] ); @@ -57,7 +71,7 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive * gltfBuffer* attrbuff = attrData->BufferList( )[attrBv->buffer]; idFile_Memory bin = idFile_Memory( "gltfChunkVertices", - ( const char* )( ( attrData->GetData( attrBv->buffer ) + attrBv->byteOffset + attrAcc->byteOffset ) ), attrBv->byteLength ); + ( const char* )( ( attrData->GetData( attrBv->buffer ) + attrBv->byteOffset + attrAcc->byteOffset ) ), attrBv->byteLength ); if( !sizeSet ) { @@ -214,9 +228,9 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive * int idMapEntity::GetEntities( gltfData* data, EntityListRef entities, int sceneID ) { - entities.AssureSizeAlloc( entities.Num( ) + 1, idListNewElement ); + idMapEntity* worldspawn = new( TAG_IDLIB_GLTF ) idMapEntity(); + entities.Append( worldspawn ); - idMapEntity* worldspawn = entities[0]; bool wpSet = false; int entityCount = 0; @@ -224,8 +238,6 @@ int idMapEntity::GetEntities( gltfData* data, EntityListRef entities, int sceneI { auto* node = data->NodeList()[nodeID]; - idMapEntity* newEntity = NULL; - bool isWorldSpawn = idStr::Icmp( node->extras.strPairs.GetString( "classname" ), "worldspawn" ) == 0; if( isWorldSpawn ) { @@ -238,15 +250,16 @@ int idMapEntity::GetEntities( gltfData* data, EntityListRef entities, int sceneI // account all meshes starting with worldspawn. or BSP in the name if( idStr::Icmpn( node->name, "BSP", 3 ) == 0 || idStr::Icmpn( node->name, "worldspawn.", 11 ) == 0 ) { - for ( auto prim : data->MeshList()[node->mesh]->primitives ) { - worldspawn->AddPrimitive( MapPolygonMesh::ConvertFromMeshGltf( prim, data )); + for( auto prim : data->MeshList()[node->mesh]->primitives ) + { + worldspawn->AddPrimitive( MapPolygonMesh::ConvertFromMeshGltf( prim, data ) ); } } else { - entities.AssureSizeAlloc(entities.Num()+1,idListNewElement); - newEntity = entities[entities.Num()-1]; + idMapEntity* newEntity = new( TAG_IDLIB_GLTF ) idMapEntity(); + entities.Append( newEntity ); // set name and retrieve epairs from node extras if( node->name.Length() )