From 98ed96adf4ba0bedd188e767242e30b8f3046626 Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Tue, 25 Oct 2022 19:02:34 +0200 Subject: [PATCH 1/7] LoadOgg fix --- neo/sound/XAudio2/XA2_SoundSample.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/neo/sound/XAudio2/XA2_SoundSample.cpp b/neo/sound/XAudio2/XA2_SoundSample.cpp index 184201d4..8610f8e0 100644 --- a/neo/sound/XAudio2/XA2_SoundSample.cpp +++ b/neo/sound/XAudio2/XA2_SoundSample.cpp @@ -299,7 +299,9 @@ bool idSoundSample_XAudio2::LoadOgg( const idStr& filename ) buffers[0].numSamples = playLength; buffers[0].buffer = AllocBuffer( totalBufferSize, GetName() ); - decoder.Read( buffers[0].buffer, buffers[0].bufferSize ); + int val = decoder.Read( buffers[0].buffer, buffers[0].bufferSize ); + + return ( val != -1 ); } /* From 9589ea300d360b8ad111d47583da86fed633aaeb Mon Sep 17 00:00:00 2001 From: HarrievG Date: Sun, 23 Oct 2022 13:02:43 +0200 Subject: [PATCH 2/7] [+] Inline support for gltf maps; add "inline" 0 property to an idStaticEntity or func_static to not inlude it in the map bsp. Defaults to 1 --- neo/idlib/MapFile_gltf.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/neo/idlib/MapFile_gltf.cpp b/neo/idlib/MapFile_gltf.cpp index cb4787a7..598a8758 100644 --- a/neo/idlib/MapFile_gltf.cpp +++ b/neo/idlib/MapFile_gltf.cpp @@ -370,10 +370,11 @@ int idMapEntity::GetEntities( gltfData* data, EntityListRef entities, int sceneI } else { - idStr classname = node->extras.strPairs.GetString( "classname" ); + idStr classnameStr = node->extras.strPairs.GetString( "classname" ); + bool skipInline = !node->extras.strPairs.GetBool("inline",true); // skip everything that is not an entity - if( !classname.IsEmpty() ) + if( !classnameStr.IsEmpty()) { idMapEntity* newEntity = new( TAG_IDLIB_GLTF ) idMapEntity(); entities.Append( newEntity ); @@ -418,7 +419,10 @@ int idMapEntity::GetEntities( gltfData* data, EntityListRef entities, int sceneI #endif // add meshes from all subnodes - ProcessSceneNode_r( newEntity, node, mat4_identity, worldToEntityTransform, data ); + if (!skipInline) + { + ProcessSceneNode_r(newEntity, node, mat4_identity, worldToEntityTransform, data); + } entityCount++; } From 2cf8d5c8f99bc624fe2e031f95ecceb22663bf65 Mon Sep 17 00:00:00 2001 From: HarrievG Date: Thu, 27 Oct 2022 00:52:01 +0200 Subject: [PATCH 3/7] [+] Recursive entity/collection support for gltf maps [+] KHR_lights_punctual spotlight support --- neo/idlib/MapFile_gltf.cpp | 187 ++++++++++++++++++++++++++++--------- neo/idlib/gltfProperties.h | 18 +++- 2 files changed, 157 insertions(+), 48 deletions(-) diff --git a/neo/idlib/MapFile_gltf.cpp b/neo/idlib/MapFile_gltf.cpp index 598a8758..cf494908 100644 --- a/neo/idlib/MapFile_gltf.cpp +++ b/neo/idlib/MapFile_gltf.cpp @@ -340,6 +340,137 @@ static void AddMeshesToWorldspawn_r( idMapEntity* entity, gltfNode* node, const } }; +void ResolveLight( gltfData* data, idMapEntity* newEntity, gltfNode* node ) +{ + assert( node && node->extensions.KHR_lights_punctual ); + + int lightID = node->extensions.KHR_lights_punctual->light; + gltfExt_KHR_lights_punctual* light = nullptr; + auto& ext = data->ExtensionsList(); + for( auto& it : ext ) + { + if( it->KHR_lights_punctual.Num() ) + { + assert( lightID + 1 <= it->KHR_lights_punctual.Num() ); + light = it->KHR_lights_punctual[lightID]; + } + } + + assert( light ); + + switch( gltfExt_KHR_lights_punctual::resolveType( light->type ) ) + { + default: + break; + case gltfExt_KHR_lights_punctual::Directional: + { + + break; + } + case gltfExt_KHR_lights_punctual::Point: + { + + break; + } + case gltfExt_KHR_lights_punctual::Spot: + { + idMat4 entityToWorldTransform = mat4_identity; + gltfData::ResolveNodeMatrix( node, &entityToWorldTransform ); + idMat4 worldToEntityTransform = entityToWorldTransform.Inverse(); + + float fov = tan( light->spot.outerConeAngle ) / idMath::HALF_PI ; + idMat3 axis = idAngles( 0.0f, 90.0f, 90.0f ).ToMat3() * entityToWorldTransform.ToMat3(); + + + newEntity->epairs.SetMatrix( "rotation", mat3_default ); + newEntity->epairs.SetVector( "_color", light->color ); + newEntity->epairs.SetVector( "light_target", axis[0] ); + newEntity->epairs.SetVector( "light_right", axis[1] * -fov ); + newEntity->epairs.SetVector( "light_up", axis[2] * fov ); + newEntity->epairs.SetVector( "light_start", axis[0] * 16 ); + newEntity->epairs.SetVector( "light_end", axis[0] * ( light->range - 16 ) ); + newEntity->epairs.Set( "texture", "lights/spot01" ); + break; + } + case gltfExt_KHR_lights_punctual::count: + break; + } + +} + +void ResolveEntity( gltfData* data, idMapEntity* newEntity, gltfNode* node ) +{ + const char* classname = node->extras.strPairs.GetString( "classname" ); + + if( node->name.Length() ) + { + newEntity->epairs.Set( "name", node->name ); + } + + // copy custom properties filled in Blender + idDict newPairs = node->extras.strPairs; + newPairs.SetDefaults( &newEntity->epairs ); + newEntity->epairs = newPairs; + + // gather entity transform and bring it into id Tech 4 space + gltfData::ResolveNodeMatrix( node ); + + + // set entity transform in a way the game and physics code understand it + idVec3 origin = blenderToDoomTransform * node->translation; + newEntity->epairs.SetVector( "origin", origin ); + + if( node->extensions.KHR_lights_punctual != nullptr ) + { + ResolveLight( data, newEntity, node ); + } + + // TODO set rotation key to store rotation and scaling + //if (idStr::Icmp(classname, "info_player_start") == 0) + // if( !node->matrix.IsIdentity() ) + //{ + // newEntity->epairs.SetMatrix("rotation", axis ); + //} + +#if 0 + for( int i = 0; i < newEntity->epairs.GetNumKeyVals(); i++ ) + { + const idKeyValue* kv = newEntity->epairs.GetKeyVal( i ); + + idLib::Printf( "entity[ %s ] key = '%s' value = '%s'\n", node->name.c_str(), kv->GetKey().c_str(), kv->GetValue().c_str() ); + } +#endif +} + +int FindEntities( gltfData* data, idMapEntity::EntityListRef entities, gltfNode* node ) +{ + int entityCount = 0; + + const char* classname = node->extras.strPairs.GetString( "classname" ); + + // skip all nodes with "worldspawn." or "BSP" in the name + if( idStr::Icmpn( node->name, "BSP", 3 ) != 0 && idStr::Icmpn( node->name, "worldspawn.", 11 ) != 0 ) + { + idStr classnameStr = node->extras.strPairs.GetString( "classname" ); + + // skip everything that is not an entity + if( !classnameStr.IsEmpty() ) + { + idMapEntity* newEntity = new( TAG_IDLIB_GLTF ) idMapEntity(); + entities.Append( newEntity ); + ResolveEntity( data, newEntity, node ); + entityCount++; + } + } + + for( auto& child : node->children ) + { + entityCount += FindEntities( data, entities, data->NodeList()[child] ); + } + + return entityCount; +} + int idMapEntity::GetEntities( gltfData* data, EntityListRef entities, int sceneID ) { idMapEntity* worldspawn = new( TAG_IDLIB_GLTF ) idMapEntity(); @@ -371,61 +502,31 @@ int idMapEntity::GetEntities( gltfData* data, EntityListRef entities, int sceneI else { idStr classnameStr = node->extras.strPairs.GetString( "classname" ); - bool skipInline = !node->extras.strPairs.GetBool("inline",true); + bool skipInline = !node->extras.strPairs.GetBool( "inline", true ); // skip everything that is not an entity - if( !classnameStr.IsEmpty()) + if( !classnameStr.IsEmpty() ) { idMapEntity* newEntity = new( TAG_IDLIB_GLTF ) idMapEntity(); entities.Append( newEntity ); - - if( node->name.Length() ) - { - newEntity->epairs.Set( "name", node->name ); - } - - // copy custom properties filled in Blender - idDict newPairs = node->extras.strPairs; - newPairs.SetDefaults( &newEntity->epairs ); - newEntity->epairs = newPairs; - - // gather entity transform and bring it into id Tech 4 space - gltfData::ResolveNodeMatrix( node ); - - idMat4 entityToWorldTransform = node->matrix; - idMat4 worldToEntityTransform = entityToWorldTransform.Inverse(); - - // set entity transform in a way the game and physics code understand it - idVec3 origin = blenderToDoomTransform * node->translation; - newEntity->epairs.SetVector( "origin", origin ); - - // TODO set rotation key to store rotation and scaling -#if 0 - if( idStr::Icmp( classname, "info_player_start" ) != 0 ) - //if( !node->matrix.IsIdentity() ) - { - idMat3 rotation = entityToWorldTransform.ToMat3(); - newEntity->epairs.SetMatrix( "rotation", rotation ); - } -#endif - -#if 0 - for( int i = 0; i < newEntity->epairs.GetNumKeyVals(); i++ ) - { - const idKeyValue* kv = newEntity->epairs.GetKeyVal( i ); - - idLib::Printf( "entity[ %s ] key = '%s' value = '%s'\n", node->name.c_str(), kv->GetKey().c_str(), kv->GetValue().c_str() ); - } -#endif + ResolveEntity( data, newEntity, node ); // add meshes from all subnodes - if (!skipInline) + if( !skipInline ) { - ProcessSceneNode_r(newEntity, node, mat4_identity, worldToEntityTransform, data); + gltfData::ResolveNodeMatrix( node ); + idMat4 entityToWorldTransform = node->matrix; + idMat4 worldToEntityTransform = entityToWorldTransform.Inverse(); + ProcessSceneNode_r( newEntity, node, mat4_identity, worldToEntityTransform, data ); } entityCount++; } + // add entities from all subnodes + for( auto& child : node->children ) + { + entityCount += FindEntities( data, entities, data->NodeList()[child] ); + } } } } diff --git a/neo/idlib/gltfProperties.h b/neo/idlib/gltfProperties.h index f298afa1..f53b08f6 100644 --- a/neo/idlib/gltfProperties.h +++ b/neo/idlib/gltfProperties.h @@ -701,6 +701,13 @@ public: class gltfExt_KHR_lights_punctual { public: + enum Type + { + Directional, + Point, + Spot, + count + }; gltfExt_KHR_lights_punctual() : color( vec3_one ), intensity( 1.0f ), range( -1.0f ), intType( -1 ) { } idVec3 color; float intensity; @@ -713,21 +720,22 @@ public: int intType; - static int resolveType( idStr type ) + + static Type resolveType( idStr type ) { if( type == "directional" ) { - return 0; + return Type::Directional; } else if( type == "point" ) { - return 1; + return Type::Point; } else if( type == "spot" ) { - return 2; + return Type::Spot; } - return -1; + return Type::count; } }; From 889f613610833e00f845f0827ab829cf376a7381 Mon Sep 17 00:00:00 2001 From: HarrievG Date: Fri, 28 Oct 2022 21:14:58 +0200 Subject: [PATCH 4/7] [+] Ext_KHR_lights_punctual::Point support [!] Fix for multple collections, entity names will be written out according to the full hierarchy. --- neo/idlib/MapFile_gltf.cpp | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/neo/idlib/MapFile_gltf.cpp b/neo/idlib/MapFile_gltf.cpp index cf494908..2538b0fb 100644 --- a/neo/idlib/MapFile_gltf.cpp +++ b/neo/idlib/MapFile_gltf.cpp @@ -134,11 +134,6 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* p { 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; @@ -232,7 +227,7 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* p { bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR ); } - + mesh->verts[i].SetColor2( PackColor( vec ) ); } @@ -358,18 +353,23 @@ void ResolveLight( gltfData* data, idMapEntity* newEntity, gltfNode* node ) assert( light ); + newEntity->epairs.SetMatrix("rotation", mat3_default); + newEntity->epairs.SetVector("_color", light->color); + switch( gltfExt_KHR_lights_punctual::resolveType( light->type ) ) { default: + common->Warning("Unsupported Light Type"); break; case gltfExt_KHR_lights_punctual::Directional: { - + common->Warning("KHR_lights_punctual::Directional not implemented"); break; } case gltfExt_KHR_lights_punctual::Point: { - + newEntity->epairs.SetVector("light_radius", idVec3(light->range) ); + newEntity->epairs.Set("texture", "lights/defaultpointlight"); break; } case gltfExt_KHR_lights_punctual::Spot: @@ -378,12 +378,9 @@ void ResolveLight( gltfData* data, idMapEntity* newEntity, gltfNode* node ) gltfData::ResolveNodeMatrix( node, &entityToWorldTransform ); idMat4 worldToEntityTransform = entityToWorldTransform.Inverse(); - float fov = tan( light->spot.outerConeAngle ) / idMath::HALF_PI ; + float fov = tan( light->spot.outerConeAngle ) / 2 ; idMat3 axis = idAngles( 0.0f, 90.0f, 90.0f ).ToMat3() * entityToWorldTransform.ToMat3(); - - newEntity->epairs.SetMatrix( "rotation", mat3_default ); - newEntity->epairs.SetVector( "_color", light->color ); newEntity->epairs.SetVector( "light_target", axis[0] ); newEntity->epairs.SetVector( "light_right", axis[1] * -fov ); newEntity->epairs.SetVector( "light_up", axis[2] * fov ); @@ -402,9 +399,22 @@ void ResolveEntity( gltfData* data, idMapEntity* newEntity, gltfNode* node ) { const char* classname = node->extras.strPairs.GetString( "classname" ); - if( node->name.Length() ) + if (node->name.Length()) { - newEntity->epairs.Set( "name", node->name ); + idStr name; + idStrList names; + gltfNode* parent = node->parent; + while (parent) + { + names.Alloc() = parent->name; + parent = parent->parent; + } + + for (int i = names.Num () ; i >= 1 ; i--) + { + name += names[i-1] + "."; + } + newEntity->epairs.Set( "name", name+node->name ); } // copy custom properties filled in Blender From 7166b50501e298122b54f7ccda31c4da017857b9 Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Sat, 29 Oct 2022 17:42:09 +0200 Subject: [PATCH 5/7] Astyle --- neo/idlib/MapFile_gltf.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/neo/idlib/MapFile_gltf.cpp b/neo/idlib/MapFile_gltf.cpp index 2538b0fb..a5a08b6d 100644 --- a/neo/idlib/MapFile_gltf.cpp +++ b/neo/idlib/MapFile_gltf.cpp @@ -227,7 +227,7 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* p { bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR ); } - + mesh->verts[i].SetColor2( PackColor( vec ) ); } @@ -353,23 +353,23 @@ void ResolveLight( gltfData* data, idMapEntity* newEntity, gltfNode* node ) assert( light ); - newEntity->epairs.SetMatrix("rotation", mat3_default); - newEntity->epairs.SetVector("_color", light->color); + newEntity->epairs.SetMatrix( "rotation", mat3_default ); + newEntity->epairs.SetVector( "_color", light->color ); switch( gltfExt_KHR_lights_punctual::resolveType( light->type ) ) { default: - common->Warning("Unsupported Light Type"); + common->Warning( "Unsupported Light Type" ); break; case gltfExt_KHR_lights_punctual::Directional: { - common->Warning("KHR_lights_punctual::Directional not implemented"); + common->Warning( "KHR_lights_punctual::Directional not implemented" ); break; } case gltfExt_KHR_lights_punctual::Point: { - newEntity->epairs.SetVector("light_radius", idVec3(light->range) ); - newEntity->epairs.Set("texture", "lights/defaultpointlight"); + newEntity->epairs.SetVector( "light_radius", idVec3( light->range ) ); + newEntity->epairs.Set( "texture", "lights/defaultpointlight" ); break; } case gltfExt_KHR_lights_punctual::Spot: @@ -399,22 +399,22 @@ void ResolveEntity( gltfData* data, idMapEntity* newEntity, gltfNode* node ) { const char* classname = node->extras.strPairs.GetString( "classname" ); - if (node->name.Length()) + if( node->name.Length() ) { idStr name; idStrList names; gltfNode* parent = node->parent; - while (parent) + while( parent ) { names.Alloc() = parent->name; parent = parent->parent; } - for (int i = names.Num () ; i >= 1 ; i--) + for( int i = names.Num() ; i >= 1 ; i-- ) { - name += names[i-1] + "."; + name += names[i - 1] + "."; } - newEntity->epairs.Set( "name", name+node->name ); + newEntity->epairs.Set( "name", name + node->name ); } // copy custom properties filled in Blender From b53271fc68b09461a0c99e4fd1a1c5f02357511b Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Sat, 29 Oct 2022 18:25:56 +0200 Subject: [PATCH 6/7] No need to set the rotation for the Blender lights --- neo/idlib/MapFile_gltf.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/neo/idlib/MapFile_gltf.cpp b/neo/idlib/MapFile_gltf.cpp index a5a08b6d..e448ca9f 100644 --- a/neo/idlib/MapFile_gltf.cpp +++ b/neo/idlib/MapFile_gltf.cpp @@ -353,7 +353,7 @@ void ResolveLight( gltfData* data, idMapEntity* newEntity, gltfNode* node ) assert( light ); - newEntity->epairs.SetMatrix( "rotation", mat3_default ); + //newEntity->epairs.SetMatrix( "rotation", mat3_default ); newEntity->epairs.SetVector( "_color", light->color ); switch( gltfExt_KHR_lights_punctual::resolveType( light->type ) ) @@ -361,17 +361,20 @@ void ResolveLight( gltfData* data, idMapEntity* newEntity, gltfNode* node ) default: common->Warning( "Unsupported Light Type" ); break; + case gltfExt_KHR_lights_punctual::Directional: { common->Warning( "KHR_lights_punctual::Directional not implemented" ); break; } + case gltfExt_KHR_lights_punctual::Point: { newEntity->epairs.SetVector( "light_radius", idVec3( light->range ) ); newEntity->epairs.Set( "texture", "lights/defaultpointlight" ); break; } + case gltfExt_KHR_lights_punctual::Spot: { idMat4 entityToWorldTransform = mat4_identity; @@ -389,6 +392,7 @@ void ResolveLight( gltfData* data, idMapEntity* newEntity, gltfNode* node ) newEntity->epairs.Set( "texture", "lights/spot01" ); break; } + case gltfExt_KHR_lights_punctual::count: break; } @@ -425,7 +429,6 @@ void ResolveEntity( gltfData* data, idMapEntity* newEntity, gltfNode* node ) // gather entity transform and bring it into id Tech 4 space gltfData::ResolveNodeMatrix( node ); - // set entity transform in a way the game and physics code understand it idVec3 origin = blenderToDoomTransform * node->translation; newEntity->epairs.SetVector( "origin", origin ); From 3a877568e4cf9166d4efae4ae3523a7b82c88068 Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Sat, 29 Oct 2022 19:08:12 +0200 Subject: [PATCH 7/7] Support glTF2 vertex colors for static models --- neo/idlib/MapFile_gltf.cpp | 84 +++++++++++++++++++++++++++++++++++++- neo/idlib/gltfParser.cpp | 2 +- neo/idlib/gltfProperties.h | 2 +- 3 files changed, 84 insertions(+), 4 deletions(-) diff --git a/neo/idlib/MapFile_gltf.cpp b/neo/idlib/MapFile_gltf.cpp index e448ca9f..182d3f00 100644 --- a/neo/idlib/MapFile_gltf.cpp +++ b/neo/idlib/MapFile_gltf.cpp @@ -138,6 +138,7 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* p break; } + case gltfMesh_Primitive_Attribute::Type::Normal: { idVec3 vec; @@ -168,6 +169,7 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* p break; } + case gltfMesh_Primitive_Attribute::Type::TexCoord0: { idVec2 vec; @@ -186,6 +188,7 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* p break; } + case gltfMesh_Primitive_Attribute::Type::Tangent: { idVec4 vec; @@ -214,6 +217,7 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* p } break; } + case gltfMesh_Primitive_Attribute::Type::Weight: { idVec4 vec; @@ -233,7 +237,84 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* p } break; } - case gltfMesh_Primitive_Attribute::Type::Indices: + + case gltfMesh_Primitive_Attribute::Type::Color0: + //case gltfMesh_Primitive_Attribute::Type::Color1: + //case gltfMesh_Primitive_Attribute::Type::Color2: + //case gltfMesh_Primitive_Attribute::Type::Color3: + { + if( attrAcc->typeSize == 4 ) + { + idVec4 vec; + + assert( sizeof( vec ) == ( attrAcc->typeSize * 4 ) ); + + for( int i = 0; i < attrAcc->count; i++ ) + { + bin.Read( ( void* )( &vec[0] ), attrAcc->typeSize ); + bin.Read( ( void* )( &vec[1] ), attrAcc->typeSize ); + bin.Read( ( void* )( &vec[2] ), attrAcc->typeSize ); + bin.Read( ( void* )( &vec[3] ), attrAcc->typeSize ); + if( attrBv->byteStride ) + { + bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR ); + } + + mesh->verts[i].color[0] = idMath::Ftob( vec.x * 255.0f ); + mesh->verts[i].color[1] = idMath::Ftob( vec.y * 255.0f ); + mesh->verts[i].color[2] = idMath::Ftob( vec.z * 255.0f ); + mesh->verts[i].color[3] = 255; + } + } + else if( attrAcc->typeSize == 2 ) + { + uint16_t vec[4]; + + assert( sizeof( vec ) == ( attrAcc->typeSize * 4 ) ); + + for( int i = 0; i < attrAcc->count; i++ ) + { + bin.Read( ( void* )( &vec[0] ), attrAcc->typeSize ); + bin.Read( ( void* )( &vec[1] ), attrAcc->typeSize ); + bin.Read( ( void* )( &vec[2] ), attrAcc->typeSize ); + bin.Read( ( void* )( &vec[3] ), attrAcc->typeSize ); + if( attrBv->byteStride ) + { + bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR ); + } + + mesh->verts[i].color[0] = idMath::Ftob( ( vec[0] * 1.0f / 65335 ) * 255.0f ); + mesh->verts[i].color[1] = idMath::Ftob( ( vec[1] * 1.0f / 65335 ) * 255.0f ); + mesh->verts[i].color[2] = idMath::Ftob( ( vec[2] * 1.0f / 65335 ) * 255.0f ); + mesh->verts[i].color[3] = 255; + } + } + else + { + uint8_t vec[4]; + for( int i = 0; i < attrAcc->count; i++ ) + { + assert( sizeof( vec ) == ( attrAcc->typeSize * 4 ) ); + + bin.Read( ( void* )( &vec[0] ), attrAcc->typeSize ); + bin.Read( ( void* )( &vec[1] ), attrAcc->typeSize ); + bin.Read( ( void* )( &vec[2] ), attrAcc->typeSize ); + bin.Read( ( void* )( &vec[3] ), attrAcc->typeSize ); + if( attrBv->byteStride ) + { + bin.Seek( attrBv->byteStride - ( attrib->elementSize * attrAcc->typeSize ), FS_SEEK_CUR ); + } + + mesh->verts[i].color[0] = vec[0]; + mesh->verts[i].color[1] = vec[1]; + mesh->verts[i].color[2] = vec[2]; + mesh->verts[i].color[3] = vec[3]; + } + } + break; + } + + case gltfMesh_Primitive_Attribute::Type::Joints: { if( attrAcc->typeSize == 2 ) { @@ -281,7 +362,6 @@ MapPolygonMesh* MapPolygonMesh::ConvertFromMeshGltf( const gltfMesh_Primitive* p } } break; - } } diff --git a/neo/idlib/gltfParser.cpp b/neo/idlib/gltfParser.cpp index b6d55316..a0198180 100644 --- a/neo/idlib/gltfParser.cpp +++ b/neo/idlib/gltfParser.cpp @@ -97,7 +97,7 @@ gltf_mesh_attribute_map s_meshAttributeMap[] = "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, + "JOINTS_0", gltfMesh_Primitive_Attribute::Type::Joints, 4, "", gltfMesh_Primitive_Attribute::Type::Count }; diff --git a/neo/idlib/gltfProperties.h b/neo/idlib/gltfProperties.h index f53b08f6..2e9aee96 100644 --- a/neo/idlib/gltfProperties.h +++ b/neo/idlib/gltfProperties.h @@ -194,7 +194,7 @@ public: Color2, Color3, Weight, - Indices, + Joints, // joint indices Count };