From 458f5c51f73faa249bef1dbc05c640dba0249c2f Mon Sep 17 00:00:00 2001 From: T-rvw <429601557@qq.com> Date: Fri, 5 Jan 2024 15:54:10 +0800 Subject: [PATCH] fix bugs --- private/Math/MeshGenerator.cpp | 10 ++- .../Producers/FbxProducer/FbxProducerImpl.cpp | 9 +-- .../GenericProducer/GenericProducerImpl.cpp | 7 +- .../ProgressiveMesh/ProgressiveMeshImpl.cpp | 3 +- private/Scene/Mesh.cpp | 43 +++++------ private/Scene/MeshImpl.cpp | 74 ++++++++++++++++--- private/Scene/MeshImpl.h | 37 +++++++--- private/Scene/SceneDatabaseImpl.cpp | 41 +++++++--- private/Scene/TextureImpl.h | 1 + public/Scene/APITypeTraits.inl | 5 +- public/Scene/Mesh.h | 11 +-- 11 files changed, 164 insertions(+), 77 deletions(-) diff --git a/private/Math/MeshGenerator.cpp b/private/Math/MeshGenerator.cpp index d63ad23..218f652 100644 --- a/private/Math/MeshGenerator.cpp +++ b/private/Math/MeshGenerator.cpp @@ -87,9 +87,11 @@ std::optional MeshGenerator::Generate(const Box& box, const VertexFormat& } } - cd::Mesh mesh(static_cast(positions.size())); + cd::Mesh mesh; + uint32_t vertexCount = static_cast(positions.size()); + mesh.Init(vertexCount); - for (uint32_t i = 0U; i < positions.size(); ++i) + for (uint32_t i = 0U; i < vertexCount; ++i) { mesh.SetVertexPosition(i, positions[i]); } @@ -173,7 +175,9 @@ std::optional MeshGenerator::Generate(const Sphere& sphere, uint32_t numSt uint32_t vertexCount = (numStacks + 1) * (numSlices + 1); - cd::Mesh mesh(vertexCount); + cd::Mesh mesh; + mesh.Init(vertexCount); + cd::VertexFormat meshVertexFormat; meshVertexFormat.AddAttributeLayout(cd::VertexAttributeType::Position, cd::GetAttributeValueType(), cd::Point::Size); diff --git a/private/Producers/FbxProducer/FbxProducerImpl.cpp b/private/Producers/FbxProducer/FbxProducerImpl.cpp index 66d4a2e..45f6f73 100644 --- a/private/Producers/FbxProducer/FbxProducerImpl.cpp +++ b/private/Producers/FbxProducer/FbxProducerImpl.cpp @@ -313,11 +313,11 @@ void FbxProducerImpl::TraverseNodeRecursively(fbxsdk::FbxNode* pSDKNode, cd::Nod if (IsOptionEnabled(FbxProducerOptions::ImportBlendShape)) { int32_t blendShapeCount = pFbxMesh->GetDeformerCount(fbxsdk::FbxDeformer::eBlendShape); - assert(blendShapeCount <= 1 && "Why use two blendshape in a mesh?"); + mesh.SetBlendShapeIDCount(blendShapeCount); for (int32_t blendShapeIndex = 0; blendShapeIndex < blendShapeCount; ++blendShapeIndex) { const fbxsdk::FbxBlendShape* pBlendShape = static_cast(pFbxMesh->GetDeformer(blendShapeIndex, fbxsdk::FbxDeformer::eBlendShape)); - mesh.SetBlendShapeID(ParseBlendShape(pBlendShape, mesh, pSceneDatabase)); + mesh.SetBlendShapeID(blendShapeIndex, ParseBlendShape(pBlendShape, mesh, pSceneDatabase)); } } @@ -435,8 +435,8 @@ void FbxProducerImpl::ParseMesh(cd::Mesh& mesh, fbxsdk::FbxNode* pSDKNode, fbxsd // Init vertex position. uint32_t controlPointCount = pFbxMesh->GetControlPointsCount(); - mesh.SetVertexPositionCount(controlPointCount); - mesh.SetVertexInstanceIDCount(controlPointCount); // Map control point index to vertex instance id. + uint32_t vertexInstanceCount = pFbxMesh->GetPolygonVertexCount(); + mesh.Init(controlPointCount, vertexInstanceCount); for (uint32_t controlPointIndex = 0U; controlPointIndex < controlPointCount; ++controlPointIndex) { fbxsdk::FbxVector4 position = pFbxMesh->GetControlPointAt(controlPointIndex); @@ -444,7 +444,6 @@ void FbxProducerImpl::ParseMesh(cd::Mesh& mesh, fbxsdk::FbxNode* pSDKNode, fbxsd } // Init vertex format. - uint32_t vertexInstanceCount = pFbxMesh->GetPolygonVertexCount(); cd::VertexFormat meshVertexFormat; if (controlPointCount > 0U) { diff --git a/private/Producers/GenericProducer/GenericProducerImpl.cpp b/private/Producers/GenericProducer/GenericProducerImpl.cpp index f28cc63..4628d5d 100644 --- a/private/Producers/GenericProducer/GenericProducerImpl.cpp +++ b/private/Producers/GenericProducer/GenericProducerImpl.cpp @@ -180,13 +180,14 @@ cd::MeshID GenericProducerImpl::AddMesh(cd::SceneDatabase* pSceneDatabase, const assert(pSourceMesh->mVertices && numVertices > 0 && "No vertex data."); std::stringstream meshHashString; - // TODO : this hash is good to reuse mesh instance, but break the rule id same to index. Wait to have a explicit mesh instance support. - // meshHashString << pSourceMesh->mName.C_Str() << "_" << pSourceMesh->mVertices << "_" << pSourceMesh->mFaces; meshHashString << pSourceMesh->mName.C_Str() << "_" << pSceneDatabase->GetMeshCount(); cd::MeshID::ValueType meshHash = cd::StringHash(meshHashString.str()); cd::MeshID meshID = m_meshIDGenerator.AllocateID(meshHash); - cd::Mesh mesh(meshID, pSourceMesh->mName.C_Str(), numVertices); + cd::Mesh mesh; + mesh.SetID(meshID); + mesh.SetName(pSourceMesh->mName.C_Str()); + mesh.Init(numVertices); // By default, aabb will be empty. if (IsOptionEnabled(GenericProducerOptions::GenerateBoundingBox)) diff --git a/private/ProgressiveMesh/ProgressiveMeshImpl.cpp b/private/ProgressiveMesh/ProgressiveMeshImpl.cpp index 9a44128..9724719 100644 --- a/private/ProgressiveMesh/ProgressiveMeshImpl.cpp +++ b/private/ProgressiveMesh/ProgressiveMeshImpl.cpp @@ -414,7 +414,8 @@ cd::Mesh ProgressiveMeshImpl::GenerateLodMesh(uint32_t targetFaceCount, const cd std::vector map = collapseInfoPair.second; uint32_t targetVertexCount = targetFaceCount * 3U; - cd::Mesh mesh(targetVertexCount); + cd::Mesh mesh; + mesh.Init(targetVertexCount); if (pSourceMesh) { diff --git a/private/Scene/Mesh.cpp b/private/Scene/Mesh.cpp index 6036abb..5962f0c 100644 --- a/private/Scene/Mesh.cpp +++ b/private/Scene/Mesh.cpp @@ -8,6 +8,21 @@ namespace cd PIMPL_SCENE_CLASS(Mesh); +PIMPL_SIMPLE_TYPE_APIS(Mesh, ID); +PIMPL_SIMPLE_TYPE_APIS(Mesh, VertexAttributeCount); +PIMPL_STRING_TYPE_APIS(Mesh, Name); +PIMPL_COMPLEX_TYPE_APIS(Mesh, AABB); +PIMPL_COMPLEX_TYPE_APIS(Mesh, VertexFormat); +PIMPL_VECTOR_TYPE_APIS(Mesh, MaterialID); +PIMPL_VECTOR_TYPE_APIS(Mesh, BlendShapeID); +PIMPL_VECTOR_TYPE_APIS(Mesh, SkinID); +PIMPL_VECTOR_TYPE_APIS(Mesh, VertexInstanceID); +PIMPL_VECTOR_TYPE_APIS(Mesh, VertexPosition); +PIMPL_VECTOR_TYPE_APIS(Mesh, VertexNormal); +PIMPL_VECTOR_TYPE_APIS(Mesh, VertexTangent); +PIMPL_VECTOR_TYPE_APIS(Mesh, VertexBiTangent); +PIMPL_VECTOR_TYPE_APIS(Mesh, PolygonGroup); + Mesh Mesh::FromHalfEdgeMesh(const HalfEdgeMesh& halfEdgeMesh, ConvertStrategy strategy) { Mesh mesh; @@ -16,38 +31,16 @@ Mesh Mesh::FromHalfEdgeMesh(const HalfEdgeMesh& halfEdgeMesh, ConvertStrategy st return mesh; } -Mesh::Mesh(uint32_t vertexCount) +void Mesh::Init(uint32_t vertexCount) { - m_pMeshImpl = new MeshImpl(); m_pMeshImpl->Init(vertexCount); } -Mesh::Mesh(MeshID id, const char* pName, uint32_t vertexCount) : - Mesh(vertexCount) -{ - m_pMeshImpl->SetID(id); - m_pMeshImpl->SetName(pName); -} - -void Mesh::Init(uint32_t vertexCount) +void Mesh::Init(uint32_t vertexPositionCount, uint32_t vertexAttributeCount) { - m_pMeshImpl->Init(vertexCount); + m_pMeshImpl->Init(vertexPositionCount, vertexAttributeCount); } -PIMPL_SIMPLE_TYPE_APIS(Mesh, ID); -PIMPL_SIMPLE_TYPE_APIS(Mesh, BlendShapeID); -PIMPL_STRING_TYPE_APIS(Mesh, Name); -PIMPL_COMPLEX_TYPE_APIS(Mesh, AABB); -PIMPL_COMPLEX_TYPE_APIS(Mesh, VertexFormat); -PIMPL_VECTOR_TYPE_APIS(Mesh, SkinID); -PIMPL_VECTOR_TYPE_APIS(Mesh, VertexInstanceID); -PIMPL_VECTOR_TYPE_APIS(Mesh, VertexPosition); -PIMPL_VECTOR_TYPE_APIS(Mesh, VertexNormal); -PIMPL_VECTOR_TYPE_APIS(Mesh, VertexTangent); -PIMPL_VECTOR_TYPE_APIS(Mesh, VertexBiTangent); -PIMPL_VECTOR_TYPE_APIS(Mesh, PolygonGroup); -PIMPL_VECTOR_TYPE_APIS(Mesh, MaterialID); - uint32_t Mesh::GetVertexCount() const { return m_pMeshImpl->GetVertexCount(); diff --git a/private/Scene/MeshImpl.cpp b/private/Scene/MeshImpl.cpp index ead4421..2f9e67e 100644 --- a/private/Scene/MeshImpl.cpp +++ b/private/Scene/MeshImpl.cpp @@ -149,22 +149,68 @@ void MeshImpl::FromHalfEdgeMesh(const HalfEdgeMesh& halfEdgeMesh, ConvertStrateg assert("Unsupported convert strategy."); } + GetPolygonGroups().emplace_back(cd::MoveTemp(polygonGroup)); + // Make capcity same with actual size. - vertexPositions.shrink_to_fit(); - vertexNormals.shrink_to_fit(); - m_vertexUVSets[0].shrink_to_fit(); - polygonGroup.shrink_to_fit(); - GetPolygonGroups().emplace_back(cd::MoveTemp(polygonGroup)).shrink_to_fit(); + ShrinkToFit(); } void MeshImpl::Init(uint32_t vertexCount) { - assert(vertexCount > 0 && "No need to create an empty mesh."); - SetVertexPositionCount(vertexCount); - SetVertexNormalCount(vertexCount); - SetVertexTangentCount(vertexCount); - SetVertexBiTangentCount(vertexCount); + SetVertexInstanceIDCount(0U); + + InitVertexAttributes(vertexCount); +} + +void MeshImpl::Init(uint32_t vertexPositionCount, uint32_t vertexAttributeCount) +{ + SetVertexPositionCount(vertexPositionCount); + SetVertexInstanceIDCount(vertexPositionCount); + + InitVertexAttributes(vertexAttributeCount); +} + +void MeshImpl::InitVertexAttributes(uint32_t vertexAttributeCount) +{ + SetVertexAttributeCount(vertexAttributeCount); + SetVertexNormalCount(GetVertexAttributeCount()); + SetVertexTangentCount(GetVertexAttributeCount()); + SetVertexBiTangentCount(GetVertexAttributeCount()); + + for (uint32_t setIndex = 0U; setIndex < GetVertexUVSetCount(); ++setIndex) + { + m_vertexUVSets[setIndex].resize(GetVertexAttributeCount()); + } + + for (uint32_t setIndex = 0U; setIndex < m_vertexColorSetCount; ++setIndex) + { + m_vertexColorSets[setIndex].resize(GetVertexAttributeCount()); + } +} + +void MeshImpl::ShrinkToFit() +{ + GetVertexPositions().shrink_to_fit(); + GetVertexInstanceIDs().shrink_to_fit(); + + GetVertexNormals().shrink_to_fit(); + GetVertexTangents().shrink_to_fit(); + GetVertexBiTangents().shrink_to_fit(); + for (uint32_t setIndex = 0U; setIndex < GetVertexUVSetCount(); ++setIndex) + { + m_vertexUVSets[setIndex].shrink_to_fit(); + } + for (uint32_t setIndex = 0U; setIndex < GetVertexColorSetCount(); ++setIndex) + { + m_vertexColorSets[setIndex].shrink_to_fit(); + } + + GetPolygonGroups().shrink_to_fit(); + for (uint32_t polygonGroupIndex = 0U; polygonGroupIndex < GetPolygonGroupCount(); ++polygonGroupIndex) + { + GetPolygonGroup(polygonGroupIndex).shrink_to_fit(); + } } uint32_t MeshImpl::GetPolygonCount() const @@ -209,6 +255,8 @@ void MeshImpl::ComputeVertexNormals() return; } + SetVertexNormalCount(vertexCount); + // Create a vector of normals with the same size as the vertex positions vector, // initialized to the zero vector. std::vector vertexNormals(vertexCount, Direction(0, 0, 0)); @@ -248,6 +296,8 @@ void MeshImpl::ComputeVertexNormals() void MeshImpl::ComputeVertexTangents() { + SetVertexTangentCount(GetVertexCount()); + // Compute the tangents for (const auto& polygonGroup : GetPolygonGroups()) { @@ -298,7 +348,7 @@ void MeshImpl::SetVertexUVSetCount(uint32_t setCount) m_vertexUVSetCount = setCount; for(uint32_t setIndex = 0U; setIndex < m_vertexUVSetCount; ++setIndex) { - m_vertexUVSets[setIndex].resize(GetVertexCount()); + m_vertexUVSets[setIndex].resize(GetVertexAttributeCount()); } } @@ -312,7 +362,7 @@ void MeshImpl::SetVertexColorSetCount(uint32_t setCount) m_vertexColorSetCount = setCount; for (uint32_t setIndex = 0U; setIndex < m_vertexColorSetCount; ++setIndex) { - m_vertexColorSets[setIndex].resize(GetVertexCount()); + m_vertexColorSets[setIndex].resize(GetVertexAttributeCount()); } } diff --git a/private/Scene/MeshImpl.h b/private/Scene/MeshImpl.h index 4edbbcd..4354419 100644 --- a/private/Scene/MeshImpl.h +++ b/private/Scene/MeshImpl.h @@ -26,13 +26,13 @@ class MeshImpl final public: DECLARE_SCENE_IMPL_CLASS(Mesh); - void Init(uint32_t vertexCount); - IMPLEMENT_SIMPLE_TYPE_APIS(Mesh, ID); - IMPLEMENT_SIMPLE_TYPE_APIS(Mesh, BlendShapeID); + IMPLEMENT_SIMPLE_TYPE_APIS(Mesh, VertexAttributeCount); IMPLEMENT_STRING_TYPE_APIS(Mesh, Name); IMPLEMENT_COMPLEX_TYPE_APIS(Mesh, AABB); IMPLEMENT_COMPLEX_TYPE_APIS(Mesh, VertexFormat); + IMPLEMENT_VECTOR_TYPE_APIS(Mesh, MaterialID); + IMPLEMENT_VECTOR_TYPE_APIS(Mesh, BlendShapeID); IMPLEMENT_VECTOR_TYPE_APIS(Mesh, SkinID); IMPLEMENT_VECTOR_TYPE_APIS(Mesh, VertexInstanceID); IMPLEMENT_VECTOR_TYPE_APIS(Mesh, VertexPosition); @@ -40,7 +40,11 @@ class MeshImpl final IMPLEMENT_VECTOR_TYPE_APIS(Mesh, VertexTangent); IMPLEMENT_VECTOR_TYPE_APIS(Mesh, VertexBiTangent); IMPLEMENT_VECTOR_TYPE_APIS(Mesh, PolygonGroup); - IMPLEMENT_VECTOR_TYPE_APIS(Mesh, MaterialID); + + void Init(uint32_t vertexCount); + void Init(uint32_t vertexPositionCount, uint32_t vertexAttributeCount); + void InitVertexAttributes(uint32_t vertexAttributeCount); + void ShrinkToFit(); uint32_t GetVertexCount() const { return GetVertexPositionCount(); } uint32_t GetPolygonCount() const; @@ -79,27 +83,35 @@ class MeshImpl final template MeshImpl& operator<<(TInputArchive& inputArchive) { - uint32_t skinCount; uint32_t materialCount; + uint32_t blendShapeCount; + uint32_t skinCount; uint32_t vertexCount; uint32_t vertexUVSetCount; uint32_t vertexColorSetCount; uint32_t vertexInfluenceCount; uint32_t polygonGroupCount; - inputArchive >> GetName() >> GetID().Data() >> GetBlendShapeID().Data() >> GetAABB() >> materialCount >> skinCount - >> vertexCount >> vertexUVSetCount >> vertexColorSetCount >> vertexInfluenceCount >> polygonGroupCount; + inputArchive >> GetName() >> GetID().Data() >> GetAABB() + >> materialCount >> blendShapeCount >> skinCount + >> vertexCount >> GetVertexAttributeCount() + >> vertexUVSetCount >> vertexColorSetCount >> vertexInfluenceCount + >> polygonGroupCount; GetVertexFormat() << inputArchive; SetMaterialIDCount(materialCount); inputArchive.ImportBuffer(GetMaterialIDs().data()); + SetBlendShapeIDCount(blendShapeCount); + inputArchive.ImportBuffer(GetBlendShapeIDs().data()); + SetSkinIDCount(skinCount); inputArchive.ImportBuffer(GetSkinIDs().data()); - Init(vertexCount); + Init(vertexCount, GetVertexAttributeCount()); inputArchive.ImportBuffer(GetVertexPositions().data()); + inputArchive.ImportBuffer(GetVertexInstanceIDs().data()); inputArchive.ImportBuffer(GetVertexNormals().data()); inputArchive.ImportBuffer(GetVertexTangents().data()); inputArchive.ImportBuffer(GetVertexBiTangents().data()); @@ -146,13 +158,18 @@ class MeshImpl final template const MeshImpl& operator>>(TOutputArchive& outputArchive) const { - outputArchive << GetName() << GetID().Data() << GetBlendShapeID().Data() << GetAABB() << GetMaterialIDCount() << GetSkinIDCount() - << GetVertexCount() << GetVertexUVSetCount() << GetVertexColorSetCount() << GetVertexInfluenceCount() << GetPolygonGroupCount(); + outputArchive << GetName() << GetID().Data() << GetAABB() + << GetMaterialIDCount() << GetBlendShapeIDCount() << GetSkinIDCount() + << GetVertexPositionCount() << GetVertexAttributeCount() + << GetVertexUVSetCount() << GetVertexColorSetCount() << GetVertexInfluenceCount() + << GetPolygonGroupCount(); GetVertexFormat() >> outputArchive; outputArchive.ExportBuffer(GetMaterialIDs().data(), GetMaterialIDs().size()); + outputArchive.ExportBuffer(GetBlendShapeIDs().data(), GetBlendShapeIDs().size()); outputArchive.ExportBuffer(GetSkinIDs().data(), GetSkinIDs().size()); outputArchive.ExportBuffer(GetVertexPositions().data(), GetVertexPositions().size()); + outputArchive.ExportBuffer(GetVertexInstanceIDs().data(), GetVertexInstanceIDs().size()); outputArchive.ExportBuffer(GetVertexNormals().data(), GetVertexNormals().size()); outputArchive.ExportBuffer(GetVertexTangents().data(), GetVertexTangents().size()); outputArchive.ExportBuffer(GetVertexBiTangents().data(), GetVertexBiTangents().size()); diff --git a/private/Scene/SceneDatabaseImpl.cpp b/private/Scene/SceneDatabaseImpl.cpp index ef2ea92..3b6addc 100644 --- a/private/Scene/SceneDatabaseImpl.cpp +++ b/private/Scene/SceneDatabaseImpl.cpp @@ -202,12 +202,22 @@ void SceneDatabaseImpl::Dump() const { auto& polygonGroup = polygonGroups[polygonGroupIndex]; auto materialID = mesh.GetMaterialID(polygonGroupIndex); - printf("\t[PolygonGroup %u] PolygonCount = %u, MaterialID = %u\n", polygonGroupIndex, static_cast(polygonGroup.size()), materialID.Data()); + printf("\t[PolygonGroup %u] PolygonCount = %u\n", polygonGroupIndex, static_cast(polygonGroup.size())); + printf("\t\t[Associated Material %u] Name = %s\n", materialID.Data(), GetMaterial(materialID.Data()).GetName()); if (materialID.IsValid()) { materialDrawMeshPolygonGroupIDs[materialID][mesh.GetID()].push_back(polygonGroupIndex); } - printf("\t[Associated BlendShape %u]", mesh.GetBlendShapeID().Data()); + } + + for (auto blendShapeID : mesh.GetBlendShapeIDs()) + { + printf("\t[Associated BlendShape %u] Name = %s\n", blendShapeID.Data(), GetBlendShape(blendShapeID.Data()).GetName()); + } + + for (auto skinID : mesh.GetSkinIDs()) + { + printf("\t[Associated Skin %u] Name = %s\n", skinID.Data(), GetSkin(skinID.Data()).GetName()); } } } @@ -231,8 +241,7 @@ void SceneDatabaseImpl::Dump() const printf("\n"); for (const auto& morph : GetMorphs()) { - printf("[Morph %u] Name = %s\n", morph.GetID().Data(), morph.GetName()); - printf("\tVertexCount = %u\n", morph.GetVertexCount()); + printf("[Morph %u] Name = %s, VertexCount = %u\n", morph.GetID().Data(), morph.GetName(), morph.GetVertexCount()); printf("\tWeight = %f\n", morph.GetWeight()); if (morph.GetBlendShapeID().IsValid()) { @@ -321,7 +330,7 @@ void SceneDatabaseImpl::Dump() const printf("\n"); for (const auto& texture : GetTextures()) { - printf("\tName = %s\n", texture.GetName()); + printf("[Texture %u] Name = %s\n", texture.GetID().Data(), texture.GetName()); printf("\tPath = %s\n", texture.GetPath()); printf("\tUVMapMode = (%s, %s)\n", nameof::nameof_enum(texture.GetUMapMode()).data(), nameof::nameof_enum(texture.GetVMapMode()).data()); } @@ -531,14 +540,16 @@ void SceneDatabaseImpl::Validate() const void SceneDatabaseImpl::Merge(cd::SceneDatabaseImpl&& sceneDatabaseImpl) { + uint32_t originAnimationCount = GetAnimationCount(); + uint32_t originBlendShapeCount = GetBlendShapeCount(); + uint32_t originBoneCount = GetBoneCount(); uint32_t originNodeCount = GetNodeCount(); uint32_t originMeshCount = GetMeshCount(); - uint32_t originBlendShapeCount = GetBlendShapeCount(); - uint32_t originMorphCount = GetMorphCount(); uint32_t originMaterialCount = GetMaterialCount(); - uint32_t originTextureCount = GetTextureCount(); + uint32_t originMorphCount = GetMorphCount(); uint32_t originSkeletonCount = GetSkeletonCount(); - uint32_t originBoneCount = GetBoneCount(); + uint32_t originSkinCount = GetSkinCount(); + uint32_t originTextureCount = GetTextureCount(); uint32_t originTrackCount = GetTrackCount(); for (auto& node : sceneDatabaseImpl.GetNodes()) @@ -559,11 +570,19 @@ void SceneDatabaseImpl::Merge(cd::SceneDatabaseImpl&& sceneDatabaseImpl) for (auto& mesh : sceneDatabaseImpl.GetMeshes()) { mesh.SetID(GetMeshCount()); - mesh.SetBlendShapeID(mesh.GetBlendShapeID().Data() + originBlendShapeCount); for (auto& materialID : mesh.GetMaterialIDs()) { materialID.Set(materialID.Data() + originMaterialCount); } + for (auto& blendShapeID : mesh.GetBlendShapeIDs()) + { + blendShapeID.Set(blendShapeID.Data() + originBlendShapeCount); + } + for (auto& skinID : mesh.GetSkinIDs()) + { + skinID.Set(skinID.Data() + originSkinCount); + } + AddMesh(cd::MoveTemp(mesh)); } @@ -658,7 +677,7 @@ void SceneDatabaseImpl::Merge(cd::SceneDatabaseImpl&& sceneDatabaseImpl) for (auto& light : sceneDatabaseImpl.GetLights()) { - light.SetID(GetCameraCount()); + light.SetID(GetLightCount()); AddLight(cd::MoveTemp(light)); } diff --git a/private/Scene/TextureImpl.h b/private/Scene/TextureImpl.h index 99d7fa3..12958dc 100644 --- a/private/Scene/TextureImpl.h +++ b/private/Scene/TextureImpl.h @@ -72,6 +72,7 @@ class TextureImpl final static_cast(GetFormat()) << GetUseMipMap(); outputArchive << GetPath() << GetWidth() << GetHeight() << GetDepth(); + outputArchive << GetRawData().size(); outputArchive.ExportBuffer(GetRawData().data(), GetRawData().size()); return *this; diff --git a/public/Scene/APITypeTraits.inl b/public/Scene/APITypeTraits.inl index 7cf4bc3..4daac73 100644 --- a/public/Scene/APITypeTraits.inl +++ b/public/Scene/APITypeTraits.inl @@ -146,7 +146,7 @@ struct MeshTypeTraits { // Simple using ID = cd::MeshID; - using BlendShapeID = cd::BlendShapeID; + using VertexAttributeCount = uint32_t; // String using Name = std::string; @@ -156,6 +156,8 @@ struct MeshTypeTraits using VertexFormat = cd::VertexFormat; // Vector + using MaterialID = cd::MaterialID; + using BlendShapeID = cd::BlendShapeID; using SkinID = cd::SkinID; using VertexPosition = cd::Point; using VertexInstanceID = cd::VertexID; @@ -163,7 +165,6 @@ struct MeshTypeTraits using VertexTangent = cd::Direction; using VertexBiTangent = cd::Direction; using PolygonGroup = cd::PolygonGroup; - using MaterialID = cd::MaterialID; }; struct MorphTypeTraits diff --git a/public/Scene/Mesh.h b/public/Scene/Mesh.h index 1ce2a3a..7190f70 100644 --- a/public/Scene/Mesh.h +++ b/public/Scene/Mesh.h @@ -23,15 +23,14 @@ class CORE_API Mesh final public: DECLARE_SCENE_CLASS(Mesh); - explicit Mesh(uint32_t vertexCount); - explicit Mesh(MeshID id, const char* pName, uint32_t vertexCount); - void Init(uint32_t vertexCount); EXPORT_SIMPLE_TYPE_APIS(Mesh, ID); - EXPORT_SIMPLE_TYPE_APIS(Mesh, BlendShapeID); + EXPORT_SIMPLE_TYPE_APIS(Mesh, VertexAttributeCount); EXPORT_STRING_TYPE_APIS(Mesh, Name); EXPORT_COMPLEX_TYPE_APIS(Mesh, AABB); EXPORT_COMPLEX_TYPE_APIS(Mesh, VertexFormat); + EXPORT_VECTOR_TYPE_APIS(Mesh, MaterialID); + EXPORT_VECTOR_TYPE_APIS(Mesh, BlendShapeID); EXPORT_VECTOR_TYPE_APIS(Mesh, SkinID); EXPORT_VECTOR_TYPE_APIS(Mesh, VertexInstanceID); EXPORT_VECTOR_TYPE_APIS(Mesh, VertexPosition); @@ -39,8 +38,10 @@ class CORE_API Mesh final EXPORT_VECTOR_TYPE_APIS(Mesh, VertexTangent); EXPORT_VECTOR_TYPE_APIS(Mesh, VertexBiTangent); EXPORT_VECTOR_TYPE_APIS(Mesh, PolygonGroup); - EXPORT_VECTOR_TYPE_APIS(Mesh, MaterialID); + void Init(uint32_t vertexCount); + void Init(uint32_t vertexPositionCount, uint32_t vertexAttributeCount); + uint32_t GetVertexCount() const; uint32_t GetPolygonCount() const;