diff --git a/examples/ProgressiveMeshToFbx/Main.cpp b/examples/ProgressiveMeshToFbx/Main.cpp index 64b48ffc..175b4024 100644 --- a/examples/ProgressiveMeshToFbx/Main.cpp +++ b/examples/ProgressiveMeshToFbx/Main.cpp @@ -15,46 +15,46 @@ int main(int argc, char** argv) return 1; } - const char* pInputFilePath = argv[1]; - const char* pOutputFilePath = argv[2]; - - using namespace cdtools; - PerformanceProfiler profiler("ProgressiveMesh"); - - auto pSceneDatabase = std::make_unique(); - - // Generate a source mesh. - { - cd::VertexFormat vertexFormat; - vertexFormat.AddAttributeLayout(cd::VertexAttributeType::Position, cd::GetAttributeValueType(), 3); - vertexFormat.AddAttributeLayout(cd::VertexAttributeType::Normal, cd::GetAttributeValueType(), 3); - vertexFormat.AddAttributeLayout(cd::VertexAttributeType::UV, cd::GetAttributeValueType(), 3); - vertexFormat.AddAttributeLayout(cd::VertexAttributeType::Tangent, cd::GetAttributeValueType(), 3); - vertexFormat.AddAttributeLayout(cd::VertexAttributeType::Bitangent, cd::GetAttributeValueType(), 3); - - //cd::Sphere shape(cd::Point(0.0f, 0.0f, 0.0f), 2.0f); - //std::optional optMesh = cd::MeshGenerator::Generate(shape, 20, 20, vertexFormat); - cd::Box shape(cd::Vec3f(-1.0f, -1.0f, -1.0f), cd::Vec3f(1.0f, 1.0f, 1.0f)); - std::optional optMesh = cd::MeshGenerator::Generate(shape, vertexFormat); - assert(optMesh.has_value()); - cd::Mesh& mesh = optMesh.value(); - mesh.SetID(cd::MeshID(0U)); - pSceneDatabase->SetMeshCount(1U); - pSceneDatabase->AddMesh(MoveTemp(mesh)); - - Processor processor(nullptr, nullptr, pSceneDatabase.get()); - processor.SetDumpSceneDatabaseEnable(false); - processor.SetCalculateConnetivityDataEnable(true); - processor.Run(); - } - - // Generate a progressive target mesh. - { - ProgressiveMeshProducer producer(""); - FbxConsumer consumer(pOutputFilePath); - Processor processor(&producer, &consumer, pSceneDatabase.get()); - processor.Run(); - } + //const char* pInputFilePath = argv[1]; + //const char* pOutputFilePath = argv[2]; + // + //using namespace cdtools; + //PerformanceProfiler profiler("ProgressiveMesh"); + // + //auto pSceneDatabase = std::make_unique(); + // + //// Generate a source mesh. + //{ + // cd::VertexFormat vertexFormat; + // vertexFormat.AddAttributeLayout(cd::VertexAttributeType::Position, cd::GetAttributeValueType(), 3); + // vertexFormat.AddAttributeLayout(cd::VertexAttributeType::Normal, cd::GetAttributeValueType(), 3); + // vertexFormat.AddAttributeLayout(cd::VertexAttributeType::UV, cd::GetAttributeValueType(), 3); + // vertexFormat.AddAttributeLayout(cd::VertexAttributeType::Tangent, cd::GetAttributeValueType(), 3); + // vertexFormat.AddAttributeLayout(cd::VertexAttributeType::Bitangent, cd::GetAttributeValueType(), 3); + // + // //cd::Sphere shape(cd::Point(0.0f, 0.0f, 0.0f), 2.0f); + // //std::optional optMesh = cd::MeshGenerator::Generate(shape, 20, 20, vertexFormat); + // cd::Box shape(cd::Vec3f(-1.0f, -1.0f, -1.0f), cd::Vec3f(1.0f, 1.0f, 1.0f)); + // std::optional optMesh = cd::MeshGenerator::Generate(shape, vertexFormat); + // assert(optMesh.has_value()); + // cd::Mesh& mesh = optMesh.value(); + // mesh.SetID(cd::MeshID(0U)); + // pSceneDatabase->SetMeshCount(1U); + // pSceneDatabase->AddMesh(MoveTemp(mesh)); + // + // Processor processor(nullptr, nullptr, pSceneDatabase.get()); + // processor.SetDumpSceneDatabaseEnable(false); + // processor.SetCalculateConnetivityDataEnable(true); + // processor.Run(); + //} + // + //// Generate a progressive target mesh. + //{ + // ProgressiveMeshProducer producer(""); + // FbxConsumer consumer(pOutputFilePath); + // Processor processor(&producer, &consumer, pSceneDatabase.get()); + // processor.Run(); + //} return 0; } \ No newline at end of file diff --git a/misc/ProgressiveMeshProducer.hpp b/misc/ProgressiveMeshProducer.hpp index ae6a4b14..da7db21f 100644 --- a/misc/ProgressiveMeshProducer.hpp +++ b/misc/ProgressiveMeshProducer.hpp @@ -14,217 +14,217 @@ namespace cdtools { -class ProgressiveMeshProducer final : public IProducer -{ -public: - ProgressiveMeshProducer() = delete; - explicit ProgressiveMeshProducer(const char* pFilePath) : m_filePath(pFilePath) {} - ProgressiveMeshProducer(const ProgressiveMeshProducer&) = delete; - ProgressiveMeshProducer& operator=(const ProgressiveMeshProducer&) = delete; - ProgressiveMeshProducer(ProgressiveMeshProducer&&) = delete; - ProgressiveMeshProducer& operator=(ProgressiveMeshProducer&&) = delete; - virtual ~ProgressiveMeshProducer() {} - - virtual void Execute(cd::SceneDatabase* pSceneDatabase) override - { - pSceneDatabase->SetName("ProgressiveMesh"); - - for (cd::Mesh& mesh : pSceneDatabase->GetMeshes()) - { - ProcessMesh(mesh); - } - } - -private: - void ProcessMesh(cd::Mesh& mesh) - { - // Query mesh basic information. - uint32_t originVertexCount = mesh.GetVertexCount(); - uint32_t originPolygonCount = mesh.GetPolygonCount(); - - // Prepare for vertex data. - std::vector vertexEdgeCollapseCosts; - std::vector vertexEdgeCollapseTargets; - { - vertexEdgeCollapseCosts.resize(originVertexCount); - std::fill(vertexEdgeCollapseCosts.begin(), vertexEdgeCollapseCosts.end(), FLT_MAX); - - vertexEdgeCollapseTargets.resize(originVertexCount); - std::fill(vertexEdgeCollapseTargets.begin(), vertexEdgeCollapseTargets.end(), cd::VertexID::InvalidID); - } - - // Prepare for polygon data. - std::vector polygonNormals; - { - polygonNormals.resize(originPolygonCount); - for (uint32_t polygonIndex = 0U; polygonIndex < originPolygonCount; ++polygonIndex) - { - const cd::Polygon& polygon = mesh.GetPolygon(polygonIndex); - cd::Point v0 = mesh.GetVertexPosition(polygon[0].Data()); - cd::Point v1v0 = mesh.GetVertexPosition(polygon[1].Data()) - v0; - cd::Point v2v0 = mesh.GetVertexPosition(polygon[2].Data()) - v0; - polygonNormals[polygonIndex] = v1v0.Cross(v2v0).Normalize(); - } - } - - // Calculate edge collapse data. - for (uint32_t vertexIndex = 0U; vertexIndex < mesh.GetVertexCount(); ++vertexIndex) - { - if (0U == mesh.GetVertexAdjacentVertexCount(vertexIndex)) - { - // Orphan vertex, nothing to collapse. - continue; - } - - // Loop every edge to calculate the min collapse cost. - for (cd::VertexID adjVertexID : mesh.GetVertexAdjacentVertexArray(vertexIndex)) - { - float collapseCost = CalculateEdgeCollapseCost(mesh, vertexIndex, adjVertexID.Data(), polygonNormals); - if (collapseCost < vertexEdgeCollapseCosts[vertexIndex]) - { - vertexEdgeCollapseCosts[vertexIndex] = collapseCost; - vertexEdgeCollapseTargets[vertexIndex] = adjVertexID; - } - } - } - - // Start to collapse edge. - auto GetMinCollapseCostVertexIndex = [&vertexEdgeCollapseCosts, &mesh]() - { - float minCost = FLT_MAX; - uint32_t minCostVertexIndex = cd::VertexID::InvalidID; - for (uint32_t vertexIndex = 0U, vertexCount = mesh.GetVertexCount(); vertexIndex < vertexCount; ++vertexIndex) - { - if (vertexEdgeCollapseCosts[vertexIndex] < minCost) - { - minCost = vertexEdgeCollapseCosts[vertexIndex]; - minCostVertexIndex = vertexIndex; - } - } - - return minCostVertexIndex; - }; - - for (int collapseIndex = originVertexCount - 1; collapseIndex >= 0; --collapseIndex) - { - uint32_t v0 = GetMinCollapseCostVertexIndex(); - uint32_t v1 = vertexEdgeCollapseTargets[v0].Data(); - - printf("Collapse Edge (%u, %u)\n", v0, v1); - CollapseEdge(mesh, v0, v1); - break; - } - } - - void CollapseEdge(cd::Mesh& mesh, uint32_t v0, uint32_t v1) - { - assert(v0 != cd::VertexID::InvalidID); - assert(v1 != cd::VertexID::InvalidID); - - // Delete polygons - { - uint32_t adjPolygonCount = mesh.GetVertexAdjacentPolygonCount(v0); - const cd::PolygonIDArray& adjPolygons = mesh.GetVertexAdjacentPolygonArray(v0); - for (uint32_t polygonIndex = 0U; polygonIndex < adjPolygonCount; ++polygonIndex) - { - cd::PolygonID adjacentPolygonID = adjPolygons[polygonIndex]; - const cd::Polygon& adjacentPolygon = mesh.GetPolygon(adjacentPolygonID.Data()); - if (adjacentPolygon.Contains(cd::VertexID(v1))) - { - // Delete Edge (v0, v1) adjacent polygons - mesh.RemovePolygonData(adjacentPolygonID); - - // 1. Loop through polygon's every vertex which maintains adjacent polygon id. - { - const auto& polygons = mesh.GetPolygons(); - for (size_t vertexIndex = 0U; vertexIndex < adjacentPolygon.Size; ++vertexIndex) - { - auto polygonVertexID = adjacentPolygon[vertexIndex]; - auto& adjPolygons = mesh.GetVertexAdjacentPolygonArray(polygonVertexID.Data()); - adjPolygons.erase(std::remove(adjPolygons.begin(), adjPolygons.end(), polygonVertexID.Data()), adjPolygons.end()); - } - } - } - } - } - - // Replace v1 with v0. - { - // 1. Loop through v1's adjacent polygons and maintain polygon's adjacent vertex ids. - for (auto v1AdjPolygonID : mesh.GetVertexAdjacentPolygonArray(v1)) - { - auto& v1AdjPolygon = mesh.GetPolygon(v1); - for (size_t vertexIndex = 0U; vertexIndex < v1AdjPolygon.Size; ++vertexIndex) - { - auto polygonVertexID = v1AdjPolygon[vertexIndex]; - if (polygonVertexID.Data() == v1) - { - v1AdjPolygon[vertexIndex] = cd::VertexID(v0); - } - } - } - - // 2. Loop through v1's adjacent vertices and maintain vertex adjacent vertex ids. - for (auto v1AdjVertexID : mesh.GetVertexAdjacentVertexArray(v1)) - { - auto& v1AdjVertexAdjVertexIDs = mesh.GetVertexAdjacentVertexArray(v1AdjVertexID.Data()); - for (size_t vertexIndex = 0U; vertexIndex < v1AdjVertexAdjVertexIDs.size(); ++vertexIndex) - { - auto v1AdjVertexAdjVertexID = v1AdjVertexAdjVertexIDs[vertexIndex]; - if (v1AdjVertexAdjVertexID.Data() == v1) - { - v1AdjVertexAdjVertexIDs[vertexIndex] = cd::VertexID(v0); - } - } - } - - // Replace v1 with v0. - mesh.SwapVertexData(cd::VertexID(v0), cd::VertexID(v1)); - mesh.RemoveVertexData(cd::VertexID(v1)); - } - } - - float CalculateEdgeCollapseCost(const cd::Mesh& mesh, uint32_t v0, uint32_t v1, const std::vector& polygonNormals) - { - cd::VertexID v1ID(v1); - cd::PolygonIDArray sharedPolygons; - for (cd::PolygonID polygonID : mesh.GetVertexAdjacentPolygonArray(v0)) - { - const cd::Polygon& polygon = mesh.GetPolygon(polygonID.Data()); - if (polygon.Contains(v1ID)) - { - sharedPolygons.push_back(polygonID); - } - } - - float curvature = 0.0f; - for (cd::PolygonID polygonID : mesh.GetVertexAdjacentPolygonArray(v0)) - { - float minCurvature = 1.0f; - const cd::Direction& v0FaceNormal = polygonNormals[polygonID.Data()]; - for (cd::PolygonID sharedPolygonID : sharedPolygons) - { - const cd::Direction& sharedFaceNormal = polygonNormals[sharedPolygonID.Data()]; - float faceNormalDot = v0FaceNormal.Dot(sharedFaceNormal); - float t = (1 - faceNormalDot) * 0.5f; - if (t < minCurvature) - { - minCurvature = t; - } - } - - if (minCurvature > curvature) - { - curvature = minCurvature; - } - } - - float edgeLength = (mesh.GetVertexPosition(v0) - mesh.GetVertexPosition(v1)).Length(); - return edgeLength * curvature; - } - -private: - std::string m_filePath; -}; +//class ProgressiveMeshProducer final : public IProducer +//{ +//public: +// ProgressiveMeshProducer() = delete; +// explicit ProgressiveMeshProducer(const char* pFilePath) : m_filePath(pFilePath) {} +// ProgressiveMeshProducer(const ProgressiveMeshProducer&) = delete; +// ProgressiveMeshProducer& operator=(const ProgressiveMeshProducer&) = delete; +// ProgressiveMeshProducer(ProgressiveMeshProducer&&) = delete; +// ProgressiveMeshProducer& operator=(ProgressiveMeshProducer&&) = delete; +// virtual ~ProgressiveMeshProducer() {} +// +// virtual void Execute(cd::SceneDatabase* pSceneDatabase) override +// { +// pSceneDatabase->SetName("ProgressiveMesh"); +// +// for (cd::Mesh& mesh : pSceneDatabase->GetMeshes()) +// { +// ProcessMesh(mesh); +// } +// } +// +//private: +// void ProcessMesh(cd::Mesh& mesh) +// { +// // Query mesh basic information. +// uint32_t originVertexCount = mesh.GetVertexCount(); +// uint32_t originPolygonCount = mesh.GetPolygonCount(); +// +// // Prepare for vertex data. +// std::vector vertexEdgeCollapseCosts; +// std::vector vertexEdgeCollapseTargets; +// { +// vertexEdgeCollapseCosts.resize(originVertexCount); +// std::fill(vertexEdgeCollapseCosts.begin(), vertexEdgeCollapseCosts.end(), FLT_MAX); +// +// vertexEdgeCollapseTargets.resize(originVertexCount); +// std::fill(vertexEdgeCollapseTargets.begin(), vertexEdgeCollapseTargets.end(), cd::VertexID::InvalidID); +// } +// +// // Prepare for polygon data. +// std::vector polygonNormals; +// { +// polygonNormals.resize(originPolygonCount); +// for (uint32_t polygonIndex = 0U; polygonIndex < originPolygonCount; ++polygonIndex) +// { +// const cd::Polygon& polygon = mesh.GetPolygon(polygonIndex); +// cd::Point v0 = mesh.GetVertexPosition(polygon[0].Data()); +// cd::Point v1v0 = mesh.GetVertexPosition(polygon[1].Data()) - v0; +// cd::Point v2v0 = mesh.GetVertexPosition(polygon[2].Data()) - v0; +// polygonNormals[polygonIndex] = v1v0.Cross(v2v0).Normalize(); +// } +// } +// +// // Calculate edge collapse data. +// for (uint32_t vertexIndex = 0U; vertexIndex < mesh.GetVertexCount(); ++vertexIndex) +// { +// if (0U == mesh.GetVertexAdjacentVertexCount(vertexIndex)) +// { +// // Orphan vertex, nothing to collapse. +// continue; +// } +// +// // Loop every edge to calculate the min collapse cost. +// for (cd::VertexID adjVertexID : mesh.GetVertexAdjacentVertexArray(vertexIndex)) +// { +// float collapseCost = CalculateEdgeCollapseCost(mesh, vertexIndex, adjVertexID.Data(), polygonNormals); +// if (collapseCost < vertexEdgeCollapseCosts[vertexIndex]) +// { +// vertexEdgeCollapseCosts[vertexIndex] = collapseCost; +// vertexEdgeCollapseTargets[vertexIndex] = adjVertexID; +// } +// } +// } +// +// // Start to collapse edge. +// auto GetMinCollapseCostVertexIndex = [&vertexEdgeCollapseCosts, &mesh]() +// { +// float minCost = FLT_MAX; +// uint32_t minCostVertexIndex = cd::VertexID::InvalidID; +// for (uint32_t vertexIndex = 0U, vertexCount = mesh.GetVertexCount(); vertexIndex < vertexCount; ++vertexIndex) +// { +// if (vertexEdgeCollapseCosts[vertexIndex] < minCost) +// { +// minCost = vertexEdgeCollapseCosts[vertexIndex]; +// minCostVertexIndex = vertexIndex; +// } +// } +// +// return minCostVertexIndex; +// }; +// +// for (int collapseIndex = originVertexCount - 1; collapseIndex >= 0; --collapseIndex) +// { +// uint32_t v0 = GetMinCollapseCostVertexIndex(); +// uint32_t v1 = vertexEdgeCollapseTargets[v0].Data(); +// +// printf("Collapse Edge (%u, %u)\n", v0, v1); +// CollapseEdge(mesh, v0, v1); +// break; +// } +// } +// +// void CollapseEdge(cd::Mesh& mesh, uint32_t v0, uint32_t v1) +// { +// assert(v0 != cd::VertexID::InvalidID); +// assert(v1 != cd::VertexID::InvalidID); +// +// // Delete polygons +// { +// uint32_t adjPolygonCount = mesh.GetVertexAdjacentPolygonCount(v0); +// const cd::PolygonIDArray& adjPolygons = mesh.GetVertexAdjacentPolygonArray(v0); +// for (uint32_t polygonIndex = 0U; polygonIndex < adjPolygonCount; ++polygonIndex) +// { +// cd::PolygonID adjacentPolygonID = adjPolygons[polygonIndex]; +// const cd::Polygon& adjacentPolygon = mesh.GetPolygon(adjacentPolygonID.Data()); +// if (adjacentPolygon.Contains(cd::VertexID(v1))) +// { +// // Delete Edge (v0, v1) adjacent polygons +// mesh.RemovePolygonData(adjacentPolygonID); +// +// // 1. Loop through polygon's every vertex which maintains adjacent polygon id. +// { +// const auto& polygons = mesh.GetPolygons(); +// for (size_t vertexIndex = 0U; vertexIndex < adjacentPolygon.Size; ++vertexIndex) +// { +// auto polygonVertexID = adjacentPolygon[vertexIndex]; +// auto& adjPolygons = mesh.GetVertexAdjacentPolygonArray(polygonVertexID.Data()); +// adjPolygons.erase(std::remove(adjPolygons.begin(), adjPolygons.end(), polygonVertexID.Data()), adjPolygons.end()); +// } +// } +// } +// } +// } +// +// // Replace v1 with v0. +// { +// // 1. Loop through v1's adjacent polygons and maintain polygon's adjacent vertex ids. +// for (auto v1AdjPolygonID : mesh.GetVertexAdjacentPolygonArray(v1)) +// { +// auto& v1AdjPolygon = mesh.GetPolygon(v1); +// for (size_t vertexIndex = 0U; vertexIndex < v1AdjPolygon.Size; ++vertexIndex) +// { +// auto polygonVertexID = v1AdjPolygon[vertexIndex]; +// if (polygonVertexID.Data() == v1) +// { +// v1AdjPolygon[vertexIndex] = cd::VertexID(v0); +// } +// } +// } +// +// // 2. Loop through v1's adjacent vertices and maintain vertex adjacent vertex ids. +// for (auto v1AdjVertexID : mesh.GetVertexAdjacentVertexArray(v1)) +// { +// auto& v1AdjVertexAdjVertexIDs = mesh.GetVertexAdjacentVertexArray(v1AdjVertexID.Data()); +// for (size_t vertexIndex = 0U; vertexIndex < v1AdjVertexAdjVertexIDs.size(); ++vertexIndex) +// { +// auto v1AdjVertexAdjVertexID = v1AdjVertexAdjVertexIDs[vertexIndex]; +// if (v1AdjVertexAdjVertexID.Data() == v1) +// { +// v1AdjVertexAdjVertexIDs[vertexIndex] = cd::VertexID(v0); +// } +// } +// } +// +// // Replace v1 with v0. +// mesh.SwapVertexData(cd::VertexID(v0), cd::VertexID(v1)); +// mesh.RemoveVertexData(cd::VertexID(v1)); +// } +// } +// +// float CalculateEdgeCollapseCost(const cd::Mesh& mesh, uint32_t v0, uint32_t v1, const std::vector& polygonNormals) +// { +// cd::VertexID v1ID(v1); +// cd::PolygonIDArray sharedPolygons; +// for (cd::PolygonID polygonID : mesh.GetVertexAdjacentPolygonArray(v0)) +// { +// const cd::Polygon& polygon = mesh.GetPolygon(polygonID.Data()); +// if (polygon.Contains(v1ID)) +// { +// sharedPolygons.push_back(polygonID); +// } +// } +// +// float curvature = 0.0f; +// for (cd::PolygonID polygonID : mesh.GetVertexAdjacentPolygonArray(v0)) +// { +// float minCurvature = 1.0f; +// const cd::Direction& v0FaceNormal = polygonNormals[polygonID.Data()]; +// for (cd::PolygonID sharedPolygonID : sharedPolygons) +// { +// const cd::Direction& sharedFaceNormal = polygonNormals[sharedPolygonID.Data()]; +// float faceNormalDot = v0FaceNormal.Dot(sharedFaceNormal); +// float t = (1 - faceNormalDot) * 0.5f; +// if (t < minCurvature) +// { +// minCurvature = t; +// } +// } +// +// if (minCurvature > curvature) +// { +// curvature = minCurvature; +// } +// } +// +// float edgeLength = (mesh.GetVertexPosition(v0) - mesh.GetVertexPosition(v1)).Length(); +// return edgeLength * curvature; +// } +// +//private: +// std::string m_filePath; +//}; } \ No newline at end of file diff --git a/private/Framework/Processor.cpp b/private/Framework/Processor.cpp index 5d8ad351..c091016a 100644 --- a/private/Framework/Processor.cpp +++ b/private/Framework/Processor.cpp @@ -68,16 +68,6 @@ bool Processor::IsFlattenSceneDatabaseEnabled() const return m_pProcessorImpl->IsFlattenSceneDatabaseEnabled(); } -void Processor::SetCalculateConnetivityDataEnable(bool enable) -{ - m_pProcessorImpl->SetCalculateConnetivityDataEnable(enable); -} - -bool Processor::IsCalculateConnetivityDataEnabled() const -{ - return m_pProcessorImpl->IsCalculateConnetivityDataEnabled(); -} - void Processor::AddExtraTextureSearchFolder(const char* pFolderPath) { m_pProcessorImpl->AddExtraTextureSearchFolder(pFolderPath); diff --git a/private/Framework/ProcessorImpl.cpp b/private/Framework/ProcessorImpl.cpp index 4fbca843..7aa3d5a2 100644 --- a/private/Framework/ProcessorImpl.cpp +++ b/private/Framework/ProcessorImpl.cpp @@ -158,11 +158,6 @@ void ProcessorImpl::Run() CalculateAABBForSceneDatabase(); } - if (IsCalculateConnetivityDataEnabled()) - { - CalculateConnetivityData(); - } - if (IsSearchMissingTexturesEnabled()) { SearchMissingTextures(); @@ -498,42 +493,6 @@ void ProcessorImpl::ValidateSceneDatabase() } } -void ProcessorImpl::CalculateConnetivityData() -{ - for (auto& mesh : m_pCurrentSceneDatabase->GetMeshes()) - { - uint32_t vertexCount = mesh.GetVertexCount(); - mesh.GetVertexAdjacentVertexArrays().resize(vertexCount); - mesh.GetVertexAdjacentPolygonArrays().resize(vertexCount); - - uint32_t polygonCount = mesh.GetPolygonCount(); - for (uint32_t polygonIndex = 0U; polygonIndex < polygonCount; ++polygonIndex) - { - const auto& polygon = mesh.GetPolygon(polygonIndex); - - mesh.AddVertexAdjacentVertexID(polygon[0].Data(), polygon[1]); - mesh.AddVertexAdjacentVertexID(polygon[0].Data(), polygon[2]); - mesh.AddVertexAdjacentVertexID(polygon[1].Data(), polygon[0]); - mesh.AddVertexAdjacentVertexID(polygon[1].Data(), polygon[2]); - mesh.AddVertexAdjacentVertexID(polygon[2].Data(), polygon[0]); - mesh.AddVertexAdjacentVertexID(polygon[2].Data(), polygon[1]); - - mesh.AddVertexAdjacentPolygonID(polygon[0].Data(), cd::PolygonID(polygonIndex)); - mesh.AddVertexAdjacentPolygonID(polygon[1].Data(), cd::PolygonID(polygonIndex)); - mesh.AddVertexAdjacentPolygonID(polygon[2].Data(), cd::PolygonID(polygonIndex)); - } - - for (uint32_t vertexIndex = 0U; vertexIndex < vertexCount; ++vertexIndex) - { - cd::VertexIDArray& adjVertexIDs = mesh.GetVertexAdjacentVertexArray(vertexIndex); - std::sort(adjVertexIDs.begin(), adjVertexIDs.end(), [](cd::VertexID lhs, cd::VertexID rhs) { return lhs < rhs; }); - - cd::PolygonIDArray& adjPolygonIDs = mesh.GetVertexAdjacentPolygonArray(vertexIndex); - std::sort(adjPolygonIDs.begin(), adjPolygonIDs.end(), [](cd::PolygonID lhs, cd::PolygonID rhs) { return lhs < rhs; }); - } - } -} - void ProcessorImpl::CalculateAABBForSceneDatabase() { // Update mesh AABB by its current vertex positions. diff --git a/private/Framework/ProcessorImpl.h b/private/Framework/ProcessorImpl.h index e1281320..6f99c920 100644 --- a/private/Framework/ProcessorImpl.h +++ b/private/Framework/ProcessorImpl.h @@ -43,9 +43,6 @@ class ProcessorImpl final void SetFlattenSceneDatabaseEnable(bool enable) { m_enableFlattenSceneDatabase = enable; } bool IsFlattenSceneDatabaseEnabled() const { return m_enableFlattenSceneDatabase; } - void SetCalculateConnetivityDataEnable(bool enable) { m_enableCalculateConnetivityData = enable; } - bool IsCalculateConnetivityDataEnabled() const { return m_enableCalculateConnetivityData; } - void AddExtraTextureSearchFolder(const char* pFolderPath) { m_textureSearchFolders.push_back(pFolderPath); } bool IsSearchMissingTexturesEnabled() const { return !m_textureSearchFolders.empty(); } @@ -56,7 +53,6 @@ class ProcessorImpl final void ValidateSceneDatabase(); void CalculateAABBForSceneDatabase(); void FlattenSceneDatabase(); - void CalculateConnetivityData(); void SearchMissingTextures(); void EmbedTextureFiles(); @@ -72,7 +68,6 @@ class ProcessorImpl final bool m_enableValidateSceneDatabase = true; bool m_enableCalculateAABBForSceneDatabase = true; bool m_enableFlattenSceneDatabase = false; - bool m_enableCalculateConnetivityData = false; bool m_enableEmbedTextureFiles = false; }; diff --git a/private/Producers/GenericProducer/GenericProducerImpl.cpp b/private/Producers/GenericProducer/GenericProducerImpl.cpp index aa82bd71..9c27c5ff 100644 --- a/private/Producers/GenericProducer/GenericProducerImpl.cpp +++ b/private/Producers/GenericProducer/GenericProducerImpl.cpp @@ -304,7 +304,7 @@ cd::MeshID GenericProducerImpl::AddMesh(cd::SceneDatabase* pSceneDatabase, const cd::MeshID::ValueType meshHash = cd::StringHash(meshHashString.str()); cd::MeshID meshID = m_meshIDGenerator.AllocateID(meshHash); cd::Mesh mesh(meshID, pSourceMesh->mName.C_Str(), numVertices, pSourceMesh->mNumFaces); - mesh.SetMaterialID(m_materialIDGenerator.GetCurrentID() + pSourceMesh->mMaterialIndex); + mesh.SetMaterialID(cd::MaterialID(m_materialIDGenerator.GetCurrentID() + pSourceMesh->mMaterialIndex)); // By default, aabb will be empty. if (IsBoundingBoxServiceActive()) @@ -527,7 +527,7 @@ void GenericProducerImpl::AddNodeRecursively(cd::SceneDatabase* pSceneDatabase, // Parent node ID should be queried because we are doing Depth-First search. const auto itParentNodeID = m_aiNodeToNodeIDLookup.find(pSourceNode->mParent); assert(itParentNodeID != m_aiNodeToNodeIDLookup.end() && "Failed to query parent node ID in scene database."); - sceneNode.SetParentID(itParentNodeID->second); + sceneNode.SetParentID(cd::NodeID(itParentNodeID->second)); } // Add meshes from node. @@ -535,14 +535,14 @@ void GenericProducerImpl::AddNodeRecursively(cd::SceneDatabase* pSceneDatabase, { uint32_t sceneMeshIndex = pSourceNode->mMeshes[meshIndex]; cd::MeshID meshID = AddMesh(pSceneDatabase, pSourceScene->mMeshes[sceneMeshIndex]); - sceneNode.AddMeshID(meshID.Data()); + sceneNode.AddMeshID(meshID); } std::vector childNodeIDs; for (uint32_t childIndex = 0U; childIndex < pSourceNode->mNumChildren; ++childIndex) { cd::NodeID childNodeID = m_nodeIDGenerator.AllocateID(); - sceneNode.AddChildID(childNodeID.Data()); + sceneNode.AddChildID(cd::NodeID(childNodeID.Data())); childNodeIDs.push_back(childNodeID.Data()); } @@ -819,8 +819,8 @@ void GenericProducerImpl::RemoveBoneReferenceNodes(cd::SceneDatabase* pSceneData } if (cd::Bone* pParentBone = const_cast(pSceneDatabase->GetBoneByName(parentBoneShortName.c_str()))) { - bone.SetParentID(pParentBone->GetID().Data()); - pParentBone->AddChildID(bone.GetID().Data()); + bone.SetParentID(pParentBone->GetID()); + pParentBone->AddChildID(bone.GetID()); } } } @@ -875,7 +875,7 @@ void GenericProducerImpl::KeepNodeIDAndIndexSame(cd::SceneDatabase* pSceneDataba auto itModifiedIDNode = oldToNewNodeID.find(parentID); if (itModifiedIDNode != oldToNewNodeID.end()) { - sceneNode.SetParentID(itModifiedIDNode->second); + sceneNode.SetParentID(cd::NodeID(itModifiedIDNode->second)); } auto& childIDs = sceneNode.GetChildIDs(); diff --git a/private/Producers/TerrainProducer/TerrainProducerImpl.cpp b/private/Producers/TerrainProducer/TerrainProducerImpl.cpp index 132d9107..c4b42d93 100644 --- a/private/Producers/TerrainProducer/TerrainProducerImpl.cpp +++ b/private/Producers/TerrainProducer/TerrainProducerImpl.cpp @@ -351,7 +351,7 @@ void TerrainProducerImpl::GenerateAllSectors(cd::SceneDatabase* pSceneDatabase) std::vector elevationMap = GenerateElevationMap(sector_col, sector_row, elevationMinMax); Mesh generatedTerrain = GenerateSectorAt(sector_col, sector_row, elevationMinMax); MaterialID meshMaterialID = GenerateMaterialAndTextures(pSceneDatabase, sector_col, sector_row, cd::MoveTemp(elevationMap)); - generatedTerrain.SetMaterialID(meshMaterialID.Data()); + generatedTerrain.SetMaterialID(meshMaterialID); pSceneDatabase->AddMesh(std::move(generatedTerrain)); } } diff --git a/private/Scene/Animation.cpp b/private/Scene/Animation.cpp index 74725d75..ad779da3 100644 --- a/private/Scene/Animation.cpp +++ b/private/Scene/Animation.cpp @@ -44,7 +44,12 @@ void Animation::Init(AnimationID id, std::string name) m_pAnimationImpl->Init(id, cd::MoveTemp(name)); } -const AnimationID& Animation::GetID() const +void Animation::SetID(AnimationID id) +{ + return m_pAnimationImpl->SetID(id); +} + +AnimationID Animation::GetID() const { return m_pAnimationImpl->GetID(); } diff --git a/private/Scene/AnimationImpl.h b/private/Scene/AnimationImpl.h index 8438841d..09f81dc4 100644 --- a/private/Scene/AnimationImpl.h +++ b/private/Scene/AnimationImpl.h @@ -31,7 +31,8 @@ class AnimationImpl final void Init(AnimationID id, std::string name); - const AnimationID& GetID() const { return m_id; } + void SetID(AnimationID id) { m_id = id; } + AnimationID GetID() const { return m_id; } void SetName(std::string name) { m_name = cd::MoveTemp(name); } const std::string& GetName() const { return m_name; } diff --git a/private/Scene/Bone.cpp b/private/Scene/Bone.cpp index 07071cec..6c628e33 100644 --- a/private/Scene/Bone.cpp +++ b/private/Scene/Bone.cpp @@ -44,7 +44,7 @@ void Bone::Init(BoneID id, std::string name) m_pBoneImpl->Init(id, MoveTemp(name)); } -const BoneID& Bone::GetID() const +BoneID Bone::GetID() const { return m_pBoneImpl->GetID(); } @@ -59,17 +59,17 @@ const char* Bone::GetName() const return m_pBoneImpl->GetName().c_str(); } -void Bone::SetParentID(uint32_t parentID) +void Bone::SetParentID(BoneID parentID) { m_pBoneImpl->SetParentID(parentID); } -const BoneID& Bone::GetParentID() const +BoneID Bone::GetParentID() const { return m_pBoneImpl->GetParentID(); } -void Bone::AddChildID(uint32_t childID) +void Bone::AddChildID(BoneID childID) { m_pBoneImpl->AddChildID(childID); } diff --git a/private/Scene/BoneImpl.h b/private/Scene/BoneImpl.h index af0dc36a..2557412b 100644 --- a/private/Scene/BoneImpl.h +++ b/private/Scene/BoneImpl.h @@ -29,18 +29,17 @@ class BoneImpl final void Init(BoneID id, std::string name); - void SetID(uint32_t id) { m_id = BoneID(id); } - const BoneID& GetID() const { return m_id; } + void SetID(BoneID id) { m_id = BoneID(id); } + BoneID GetID() const { return m_id; } void SetName(std::string name) { m_name = MoveTemp(name); } std::string& GetName() { return m_name; } const std::string& GetName() const { return m_name; } - void SetParentID(uint32_t parentID) { m_parentID.Set(parentID); } - BoneID& GetParentID() { return m_parentID; } - const BoneID& GetParentID() const { return m_parentID; } + void SetParentID(BoneID parentID) { m_parentID = parentID; } + BoneID GetParentID() const { return m_parentID; } - void AddChildID(uint32_t childID) { m_childIDs.push_back(BoneID(childID)); } + void AddChildID(BoneID childID) { m_childIDs.push_back(childID); } uint32_t GetChildCount() const { return static_cast(m_childIDs.size()); } std::vector& GetChildIDs() { return m_childIDs; } const std::vector& GetChildIDs() const { return m_childIDs; } @@ -65,7 +64,7 @@ class BoneImpl final >> boneParentID >> boneChildIDCount; Init(BoneID(boneID), cd::MoveTemp(boneName)); - SetParentID(boneParentID); + SetParentID(BoneID(boneParentID)); m_childIDs.resize(boneChildIDCount); inputArchive.ImportBuffer(GetChildIDs().data()); diff --git a/private/Scene/Camera.cpp b/private/Scene/Camera.cpp index 1eb08388..e21b54ce 100644 --- a/private/Scene/Camera.cpp +++ b/private/Scene/Camera.cpp @@ -39,7 +39,12 @@ Camera::~Camera() } } -const CameraID& Camera::GetID() const +void Camera::SetID(CameraID id) +{ + m_pCameraImpl->SetID(id); +} + +CameraID Camera::GetID() const { return m_pCameraImpl->GetID(); } diff --git a/private/Scene/CameraImpl.h b/private/Scene/CameraImpl.h index 6cb03ebe..9eeefc4b 100644 --- a/private/Scene/CameraImpl.h +++ b/private/Scene/CameraImpl.h @@ -29,8 +29,8 @@ class CameraImpl final void Init(CameraID id, std::string name); - void SetID(uint32_t id) { m_id = CameraID(id); } - const CameraID& GetID() const { return m_id; } + void SetID(CameraID id) { m_id = id; } + CameraID GetID() const { return m_id; } void SetName(std::string name) { m_name = cd::MoveTemp(name); } std::string& GetName() { return m_name; } diff --git a/private/Scene/MaterialImpl.h b/private/Scene/MaterialImpl.h index dcdede61..1748e70e 100644 --- a/private/Scene/MaterialImpl.h +++ b/private/Scene/MaterialImpl.h @@ -83,7 +83,7 @@ class MaterialImpl final } template - const MaterialImpl &operator>>(TOutputArchive& outputArchive) const + const MaterialImpl& operator>>(TOutputArchive& outputArchive) const { outputArchive << GetID().Data() << GetName() << static_cast(GetType()); GetPropertyGroups() >> outputArchive; diff --git a/private/Scene/Mesh.cpp b/private/Scene/Mesh.cpp index d33f35d4..7e0bfcc0 100644 --- a/private/Scene/Mesh.cpp +++ b/private/Scene/Mesh.cpp @@ -116,9 +116,9 @@ const AABB& Mesh::GetAABB() const return m_pMeshImpl->GetAABB(); } -void Mesh::SetMaterialID(uint32_t materialIndex) +void Mesh::SetMaterialID(MaterialID materialID) { - return m_pMeshImpl->SetMaterialID(materialIndex); + return m_pMeshImpl->SetMaterialID(materialID); } MaterialID Mesh::GetMaterialID() const @@ -365,12 +365,7 @@ const std::vector& Mesh::GetVertexBoneIDs(uint32_t boneIndex) const return m_pMeshImpl->GetVertexBoneIDs(boneIndex); } -BoneID& Mesh::GetVertexBoneID(uint32_t boneIndex, uint32_t vertexIndex) -{ - return m_pMeshImpl->GetVertexBoneID(boneIndex, vertexIndex); -} - -const BoneID& Mesh::GetVertexBoneID(uint32_t boneIndex, uint32_t vertexIndex) const +BoneID Mesh::GetVertexBoneID(uint32_t boneIndex, uint32_t vertexIndex) const { return m_pMeshImpl->GetVertexBoneID(boneIndex, vertexIndex); } @@ -395,69 +390,6 @@ const VertexWeight& Mesh::GetVertexWeight(uint32_t boneIndex, uint32_t vertexInd return m_pMeshImpl->GetVertexWeight(boneIndex, vertexIndex); } -////////////////////////////////////////////////////////////////////////// -// Vertex connectivity data -////////////////////////////////////////////////////////////////////////// -uint32_t Mesh::GetVertexAdjacentVertexCount(uint32_t vertexIndex) const -{ - return m_pMeshImpl->GetVertexAdjacentVertexCount(vertexIndex); -} - -void Mesh::AddVertexAdjacentVertexID(uint32_t vertexIndex, VertexID vertexID) -{ - return m_pMeshImpl->AddVertexAdjacentVertexID(vertexIndex, vertexID); -} - -VertexIDArray& Mesh::GetVertexAdjacentVertexArray(uint32_t vertexIndex) -{ - return m_pMeshImpl->GetVertexAdjacentVertexArray(vertexIndex); -} - -const VertexIDArray& Mesh::GetVertexAdjacentVertexArray(uint32_t vertexIndex) const -{ - return m_pMeshImpl->GetVertexAdjacentVertexArray(vertexIndex); -} - -std::vector& Mesh::GetVertexAdjacentVertexArrays() -{ - return m_pMeshImpl->GetVertexAdjacentVertexArrays(); -} - -const std::vector& Mesh::GetVertexAdjacentVertexArrays() const -{ - return m_pMeshImpl->GetVertexAdjacentVertexArrays(); -} - -uint32_t Mesh::GetVertexAdjacentPolygonCount(uint32_t vertexIndex) const -{ - return m_pMeshImpl->GetVertexAdjacentPolygonCount(vertexIndex); -} - -void Mesh::AddVertexAdjacentPolygonID(uint32_t vertexIndex, PolygonID polygonID) -{ - return m_pMeshImpl->AddVertexAdjacentPolygonID(vertexIndex, polygonID); -} - -PolygonIDArray& Mesh::GetVertexAdjacentPolygonArray(uint32_t vertexIndex) -{ - return m_pMeshImpl->GetVertexAdjacentPolygonArray(vertexIndex); -} - -const PolygonIDArray& Mesh::GetVertexAdjacentPolygonArray(uint32_t vertexIndex) const -{ - return m_pMeshImpl->GetVertexAdjacentPolygonArray(vertexIndex); -} - -std::vector& Mesh::GetVertexAdjacentPolygonArrays() -{ - return m_pMeshImpl->GetVertexAdjacentPolygonArrays(); -} - -const std::vector& Mesh::GetVertexAdjacentPolygonArrays() const -{ - return m_pMeshImpl->GetVertexAdjacentPolygonArrays(); -} - ////////////////////////////////////////////////////////////////////////// // Polygon index data ////////////////////////////////////////////////////////////////////////// @@ -492,43 +424,8 @@ cd::VertexID Mesh::GetPolygonVertexID(uint32_t polygonIndex, uint32_t vertexInde } ////////////////////////////////////////////////////////////////////////// -// Editing +// Serialization ////////////////////////////////////////////////////////////////////////// -void Mesh::MarkVertexInvalid(VertexID v) -{ - m_pMeshImpl->MarkVertexInvalid(v); -} - -bool Mesh::IsVertexValid(VertexID v) const -{ - return m_pMeshImpl->IsVertexValid(v); -} - -void Mesh::RemoveVertexData(VertexID v) -{ - m_pMeshImpl->RemoveVertexData(v); -} - -void Mesh::SwapVertexData(VertexID v0, VertexID v1) -{ - m_pMeshImpl->SwapVertexData(v0, v1); -} - -void Mesh::MarkPolygonInvalid(PolygonID p) -{ - m_pMeshImpl->MarkPolygonInvalid(p); -} - -bool Mesh::IsPolygonValid(PolygonID p) const -{ - return m_pMeshImpl->IsPolygonValid(p); -} - -void Mesh::RemovePolygonData(PolygonID p) -{ - m_pMeshImpl->RemovePolygonData(p); -} - Mesh& Mesh::operator<<(InputArchive& inputArchive) { *m_pMeshImpl << inputArchive; diff --git a/private/Scene/MeshImpl.cpp b/private/Scene/MeshImpl.cpp index 7316ad8f..86e31467 100644 --- a/private/Scene/MeshImpl.cpp +++ b/private/Scene/MeshImpl.cpp @@ -2,27 +2,6 @@ #include -namespace -{ - -template -void SwapArrayElement(std::vector& data, uint32_t v0, uint32_t v1) -{ - T temp = cd::MoveTemp(data[v0]); - data[v0] = cd::MoveTemp(data[v1]); - data[v1] = cd::MoveTemp(temp); -}; - -template -void RemoveArrayElement(std::vector& data, uint32_t v0) -{ - T temp = cd::MoveTemp(data.back()); - data[v0] = cd::MoveTemp(temp); - data.pop_back(); -}; - -} - namespace cd { @@ -239,37 +218,6 @@ void MeshImpl::SetVertexBoneWeight(uint32_t boneIndex, uint32_t vertexIndex, Bon m_vertexWeights[boneIndex][vertexIndex] = weight; } -//////////////////////////////////////////////////////////////////////////////////// -// Vertex connectivity data -//////////////////////////////////////////////////////////////////////////////////// -void MeshImpl::AddVertexAdjacentVertexID(uint32_t vertexIndex, VertexID vertexID) -{ - VertexIDArray& adjVertexArray = m_vertexAdjacentVertexArrays[vertexIndex]; - for (VertexID adjVertexID : adjVertexArray) - { - if (vertexID == adjVertexID) - { - return; - } - } - - adjVertexArray.push_back(vertexID); -} - -void MeshImpl::AddVertexAdjacentPolygonID(uint32_t vertexIndex, PolygonID polygonID) -{ - PolygonIDArray& adjPolygonArray = m_vertexAdjacentPolygonArrays[vertexIndex]; - for (PolygonID adjPolygonID : adjPolygonArray) - { - if (polygonID == adjPolygonID) - { - return; - } - } - - m_vertexAdjacentPolygonArrays[vertexIndex].push_back(polygonID); -} - //////////////////////////////////////////////////////////////////////////////////// // Polygon index data //////////////////////////////////////////////////////////////////////////////////// @@ -283,120 +231,4 @@ cd::VertexID MeshImpl::GetPolygonVertexID(uint32_t polygonIndex, uint32_t vertex return m_polygons[polygonIndex][vertexIndex]; } - -//////////////////////////////////////////////////////////////////////////////////// -// Editing -//////////////////////////////////////////////////////////////////////////////////// -void MeshImpl::MarkVertexInvalid(VertexID v) -{ - m_mapChaosVertexIDToIndex[v] = cd::VertexID::InvalidID; -} - -bool MeshImpl::IsVertexValid(VertexID v) const -{ - auto itVertex = m_mapChaosVertexIDToIndex.find(v); - return itVertex != m_mapChaosVertexIDToIndex.end() && itVertex->second == cd::VertexID::InvalidID; -} - -//void MeshImpl::SwapVertex(VertexID v0, VertexID v1) -//{ -// m_mapChaosVertexIDToIndex[v0] = v1.Data(); -// m_mapChaosVertexIDToIndex[v1] = v0.Data(); -//} - -void MeshImpl::SwapVertexData(VertexID v0, VertexID v1) -{ - SwapArrayElement(m_vertexPositions, v0.Data(), v1.Data()); - SwapArrayElement(m_vertexNormals, v0.Data(), v1.Data()); - SwapArrayElement(m_vertexTangents, v0.Data(), v1.Data()); - SwapArrayElement(m_vertexBiTangents, v0.Data(), v1.Data()); - - for (uint32_t m_colorSetIndex = 0; m_colorSetIndex < m_vertexColorSetCount; ++m_colorSetIndex) - { - SwapArrayElement(m_vertexColorSets[m_colorSetIndex], v0.Data(), v1.Data()); - } - - for (uint32_t m_uvSetIndex = 0; m_uvSetIndex < m_vertexUVSetCount; ++m_uvSetIndex) - { - SwapArrayElement(m_vertexUVSets[m_uvSetIndex], v0.Data(), v1.Data()); - } - - for (uint32_t m_influenceIndex = 0; m_influenceIndex < m_vertexInfluenceCount; ++m_influenceIndex) - { - SwapArrayElement(m_vertexBoneIDs[m_influenceIndex], v0.Data(), v1.Data()); - SwapArrayElement(m_vertexWeights[m_influenceIndex], v0.Data(), v1.Data()); - } - - SwapArrayElement(m_vertexAdjacentVertexArrays, v0.Data(), v1.Data()); - SwapArrayElement(m_vertexAdjacentPolygonArrays, v0.Data(), v1.Data()); -} - -void MeshImpl::RemoveVertexData(VertexID v0) -{ - RemoveArrayElement(m_vertexPositions, v0.Data()); - RemoveArrayElement(m_vertexNormals, v0.Data()); - RemoveArrayElement(m_vertexTangents, v0.Data()); - RemoveArrayElement(m_vertexBiTangents, v0.Data()); - - for (uint32_t m_colorSetIndex = 0; m_colorSetIndex < m_vertexColorSetCount; ++m_colorSetIndex) - { - RemoveArrayElement(m_vertexColorSets[m_colorSetIndex], v0.Data()); - } - - for (uint32_t m_uvSetIndex = 0; m_uvSetIndex < m_vertexUVSetCount; ++m_uvSetIndex) - { - RemoveArrayElement(m_vertexUVSets[m_uvSetIndex], v0.Data()); - } - - for (uint32_t m_influenceIndex = 0; m_influenceIndex < m_vertexInfluenceCount; ++m_influenceIndex) - { - RemoveArrayElement(m_vertexBoneIDs[m_influenceIndex], v0.Data()); - RemoveArrayElement(m_vertexWeights[m_influenceIndex], v0.Data()); - } - - RemoveArrayElement(m_vertexAdjacentVertexArrays, v0.Data()); - RemoveArrayElement(m_vertexAdjacentPolygonArrays, v0.Data()); - - --m_vertexCount; -} - -void MeshImpl::MarkPolygonInvalid(PolygonID p) -{ - m_mapChaosPolygonIDToIndex[p] = cd::VertexID::InvalidID; -} - -bool MeshImpl::IsPolygonValid(PolygonID p) const -{ - auto itPolygon = m_mapChaosPolygonIDToIndex.find(p); - return itPolygon != m_mapChaosPolygonIDToIndex.end() && itPolygon->second == cd::PolygonID::InvalidID; -} - -void MeshImpl::RemovePolygonData(PolygonID p) -{ - RemoveArrayElement(m_polygons, p.Data()); - - --m_polygonCount; -} - -void MeshImpl::Unify() -{ - for (const auto& [vertexID, vertexIndex] : m_mapChaosVertexIDToIndex) - { - if (cd::VertexID::InvalidID == vertexIndex) - { - RemoveVertexData(vertexID); - m_mapChaosVertexIDToIndex.erase(vertexID); - } - } - - for (const auto& [polygonID, polygonIndex] : m_mapChaosPolygonIDToIndex) - { - if (cd::VertexID::InvalidID == polygonIndex) - { - RemovePolygonData(polygonID); - m_mapChaosPolygonIDToIndex.erase(polygonID); - } - } -} - } \ No newline at end of file diff --git a/private/Scene/MeshImpl.h b/private/Scene/MeshImpl.h index 5ab79827..ef7bbc24 100644 --- a/private/Scene/MeshImpl.h +++ b/private/Scene/MeshImpl.h @@ -55,7 +55,7 @@ class MeshImpl final AABB& GetAABB() { return m_aabb; } const AABB& GetAABB() const { return m_aabb; } - void SetMaterialID(uint32_t materialIndex) { m_materialID = materialIndex; } + void SetMaterialID(MaterialID materialID) { m_materialID = materialID; } MaterialID GetMaterialID() const { return m_materialID; } uint32_t GetMorphCount() const { return static_cast(m_morphTargets.size()); } @@ -108,8 +108,7 @@ class MeshImpl final void SetVertexInfluenceCount(uint32_t influenceCount); uint32_t GetVertexInfluenceCount() const { return m_vertexInfluenceCount; } void SetVertexBoneWeight(uint32_t boneIndex, uint32_t vertexIndex, BoneID boneID, VertexWeight weight); - BoneID& GetVertexBoneID(uint32_t boneIndex, uint32_t vertexIndex) { return m_vertexBoneIDs[boneIndex][vertexIndex]; } - const BoneID& GetVertexBoneID(uint32_t boneIndex, uint32_t vertexIndex) const { return m_vertexBoneIDs[boneIndex][vertexIndex]; } + BoneID GetVertexBoneID(uint32_t boneIndex, uint32_t vertexIndex) const { return m_vertexBoneIDs[boneIndex][vertexIndex]; } std::vector& GetVertexBoneIDs(uint32_t boneIndex) { return m_vertexBoneIDs[boneIndex]; } const std::vector& GetVertexBoneIDs(uint32_t boneIndex) const { return m_vertexBoneIDs[boneIndex]; } VertexWeight& GetVertexWeight(uint32_t boneIndex, uint32_t vertexIndex) { return m_vertexWeights[boneIndex][vertexIndex]; } @@ -117,20 +116,6 @@ class MeshImpl final std::vector& GetVertexWeights(uint32_t boneIndex) { return m_vertexWeights[boneIndex]; } const std::vector& GetVertexWeights(uint32_t boneIndex) const { return m_vertexWeights[boneIndex]; } - uint32_t GetVertexAdjacentVertexCount(uint32_t vertexIndex) const { return static_cast(m_vertexAdjacentVertexArrays[vertexIndex].size()); } - void AddVertexAdjacentVertexID(uint32_t vertexIndex, VertexID vertexID); - VertexIDArray& GetVertexAdjacentVertexArray(uint32_t vertexIndex) { return m_vertexAdjacentVertexArrays[vertexIndex]; } - const VertexIDArray& GetVertexAdjacentVertexArray(uint32_t vertexIndex) const { return m_vertexAdjacentVertexArrays[vertexIndex]; } - std::vector& GetVertexAdjacentVertexArrays() { return m_vertexAdjacentVertexArrays; } - const std::vector& GetVertexAdjacentVertexArrays() const { return m_vertexAdjacentVertexArrays; } - - uint32_t GetVertexAdjacentPolygonCount(uint32_t vertexIndex) const { return static_cast(m_vertexAdjacentPolygonArrays[vertexIndex].size()); } - void AddVertexAdjacentPolygonID(uint32_t vertexIndex, PolygonID polygonID); - PolygonIDArray& GetVertexAdjacentPolygonArray(uint32_t vertexIndex) { return m_vertexAdjacentPolygonArrays[vertexIndex]; } - const PolygonIDArray& GetVertexAdjacentPolygonArray(uint32_t vertexIndex) const { return m_vertexAdjacentPolygonArrays[vertexIndex]; } - std::vector& GetVertexAdjacentPolygonArrays() { return m_vertexAdjacentPolygonArrays; } - const std::vector& GetVertexAdjacentPolygonArrays() const { return m_vertexAdjacentPolygonArrays; } - void SetPolygon(uint32_t polygonIndex, cd::Polygon polygon); std::vector& GetPolygons() { return m_polygons; } const std::vector& GetPolygons() const { return m_polygons; } @@ -138,18 +123,6 @@ class MeshImpl final const Polygon& GetPolygon(uint32_t polygonIndex) const { return m_polygons[polygonIndex]; } cd::VertexID GetPolygonVertexID(uint32_t polygonIndex, uint32_t vertexIndex) const; - void MarkVertexInvalid(VertexID v); - bool IsVertexValid(VertexID v) const; - void SwapVertexData(VertexID v0, VertexID v1); - void RemoveVertexData(VertexID v); - - void MarkPolygonInvalid(PolygonID p); - bool IsPolygonValid(PolygonID p) const; - void RemovePolygonData(PolygonID p); - - // After unify, all IDs cached by users should clean up. - void Unify(); - template MeshImpl& operator<<(TInputArchive& inputArchive) { @@ -169,7 +142,7 @@ class MeshImpl final >> polygonCount; Init(MeshID(meshID), MoveTemp(meshName), vertexCount, polygonCount); - SetMaterialID(meshMaterialID); + SetMaterialID(MaterialID(meshMaterialID)); SetVertexUVSetCount(vertexUVSetCount); SetVertexColorSetCount(vertexColorSetCount); SetVertexInfluenceCount(vertexInfluenceCount); @@ -259,9 +232,9 @@ class MeshImpl final // We can generate VertexFormat immediately based on current vertex data types. VertexFormat m_vertexFormat; std::vector m_vertexPositions; - std::vector m_vertexNormals; // Maybe we wants to use face normals? Or we can help to calculate it. - std::vector m_vertexTangents; // Ditto. - std::vector m_vertexBiTangents; // If not stored in model file, we can help to calculate it. + std::vector m_vertexNormals; + std::vector m_vertexTangents; + std::vector m_vertexBiTangents; // vertex texture data std::vector m_vertexUVSets[MaxUVSetCount]; @@ -271,17 +244,6 @@ class MeshImpl final std::vector m_vertexBoneIDs[MaxBoneInfluenceCount]; std::vector m_vertexWeights[MaxBoneInfluenceCount]; - // vertex connectivity data - // For geometry processing algorithms, it is common to query connectivity data. - std::vector m_vertexAdjacentVertexArrays; - std::vector m_vertexAdjacentPolygonArrays; - - // editing data - // During the process of removing vertices/polygons, it is difficult to maintain the relationship - // which means id is same to index. - std::map m_mapChaosVertexIDToIndex; - std::map m_mapChaosPolygonIDToIndex; - // polygon data std::vector m_polygons; }; diff --git a/private/Scene/Node.cpp b/private/Scene/Node.cpp index 8f0a91c0..a7049dd4 100644 --- a/private/Scene/Node.cpp +++ b/private/Scene/Node.cpp @@ -49,7 +49,7 @@ void Node::SetID(NodeID nodeID) m_pNodeImpl->SetID(nodeID); } -const NodeID& Node::GetID() const +NodeID Node::GetID() const { return m_pNodeImpl->GetID(); } @@ -64,17 +64,17 @@ const char* Node::GetName() const return m_pNodeImpl->GetName().c_str(); } -void Node::SetParentID(uint32_t parentID) +void Node::SetParentID(NodeID parentID) { m_pNodeImpl->SetParentID(parentID); } -const NodeID& Node::GetParentID() const +NodeID Node::GetParentID() const { return m_pNodeImpl->GetParentID(); } -void Node::AddChildID(uint32_t childID) +void Node::AddChildID(NodeID childID) { m_pNodeImpl->AddChildID(childID); } @@ -94,7 +94,7 @@ const std::vector& Node::GetChildIDs() const return m_pNodeImpl->GetChildIDs(); } -void Node::AddMeshID(uint32_t meshID) +void Node::AddMeshID(MeshID meshID) { m_pNodeImpl->AddMeshID(meshID); } diff --git a/private/Scene/NodeImpl.h b/private/Scene/NodeImpl.h index d5c43817..7a10ac58 100644 --- a/private/Scene/NodeImpl.h +++ b/private/Scene/NodeImpl.h @@ -31,21 +31,21 @@ class NodeImpl final void Init(NodeID nodeID, std::string name); void SetID(NodeID nodeID) { m_id = nodeID; } - const NodeID& GetID() const { return m_id; } + NodeID GetID() const { return m_id; } void SetName(std::string name) { m_name = cd::MoveTemp(name); } std::string& GetName() { return m_name; } const std::string& GetName() const { return m_name; } - void SetParentID(uint32_t parentID) { m_parentID.Set(parentID); } - const NodeID& GetParentID() const { return m_parentID; } + void SetParentID(NodeID parentID) { m_parentID = parentID; } + NodeID GetParentID() const { return m_parentID; } - void AddChildID(uint32_t childID) { m_childIDs.push_back(NodeID(childID)); } + void AddChildID(NodeID childID) { m_childIDs.push_back(childID); } uint32_t GetChildCount() const { return static_cast(m_childIDs.size()); } std::vector& GetChildIDs() { return m_childIDs; } const std::vector& GetChildIDs() const { return m_childIDs; } - void AddMeshID(uint32_t meshID) { m_meshIDs.push_back(MeshID(meshID)); } + void AddMeshID(MeshID meshID) { m_meshIDs.push_back(meshID); } uint32_t GetMeshCount() const { return static_cast(m_meshIDs.size()); } std::vector& GetMeshIDs() { return m_meshIDs; } const std::vector& GetMeshIDs() const { return m_meshIDs; } @@ -69,7 +69,7 @@ class NodeImpl final inputArchive >> childCount >> meshCount; Init(NodeID(nodeID), cd::MoveTemp(nodeName)); - SetParentID(parentID); + SetParentID(NodeID(parentID)); SetTransform(cd::MoveTemp(transform)); m_childIDs.resize(childCount); diff --git a/private/Scene/Track.cpp b/private/Scene/Track.cpp index d989405e..c3fdd303 100644 --- a/private/Scene/Track.cpp +++ b/private/Scene/Track.cpp @@ -44,7 +44,12 @@ void Track::Init(TrackID id, std::string name) m_pTrackImpl->Init(id, cd::MoveTemp(name)); } -const TrackID& Track::GetID() const +void Track::SetID(TrackID id) +{ + m_pTrackImpl->SetID(id); +} + +TrackID Track::GetID() const { return m_pTrackImpl->GetID(); } diff --git a/private/Scene/TrackImpl.h b/private/Scene/TrackImpl.h index 6af62b9e..1ab3a1a8 100644 --- a/private/Scene/TrackImpl.h +++ b/private/Scene/TrackImpl.h @@ -30,7 +30,8 @@ class TrackImpl final void Init(TrackID id, std::string name); - const TrackID& GetID() const { return m_id; } + void SetID(TrackID id) { m_id = id; } + TrackID GetID() const { return m_id; } void SetName(std::string name) { m_name = cd::MoveTemp(name); } const std::string& GetName() const { return m_name; } diff --git a/public/Base/Platform.h b/public/Base/Platform.h index 3b8b75cb..7ebadd7b 100644 --- a/public/Base/Platform.h +++ b/public/Base/Platform.h @@ -21,4 +21,12 @@ #else # define CD_FORCEINLINE inline __attribute__((always_inline)) # define CD_NOINLINE __attribute__((noinline)) +#endif + +// novtable can avoid generating initialization codes for virtual tables in class. +// Note that it will not save memory for objects. The virtual pointer still exists. +#ifdef _MSC_VER +# define CD_NO_VTABLE __declspec(novtable) +#else +# define CD_NO_VTABLE #endif \ No newline at end of file diff --git a/public/Framework/Processor.h b/public/Framework/Processor.h index 01e8afd0..f88caff5 100644 --- a/public/Framework/Processor.h +++ b/public/Framework/Processor.h @@ -43,9 +43,6 @@ class CORE_API Processor final void SetFlattenSceneDatabaseEnable(bool enable); bool IsFlattenSceneDatabaseEnabled() const; - void SetCalculateConnetivityDataEnable(bool enable); - bool IsCalculateConnetivityDataEnabled() const; - void AddExtraTextureSearchFolder(const char* pFolderPath); bool IsSearchMissingTexturesEnabled() const; diff --git a/public/Scene/Animation.h b/public/Scene/Animation.h index b2f306cc..f5d9affd 100644 --- a/public/Scene/Animation.h +++ b/public/Scene/Animation.h @@ -32,7 +32,8 @@ class CORE_API Animation final void Init(AnimationID id, std::string name); - const AnimationID& GetID() const; + void SetID(AnimationID id); + AnimationID GetID() const; void SetName(std::string name); const char* GetName() const; diff --git a/public/Scene/Bone.h b/public/Scene/Bone.h index 72ce7952..32c77cb6 100644 --- a/public/Scene/Bone.h +++ b/public/Scene/Bone.h @@ -31,15 +31,15 @@ class CORE_API Bone final void Init(BoneID id, std::string name); - const BoneID& GetID() const; + BoneID GetID() const; void SetName(std::string name); const char* GetName() const; - void SetParentID(uint32_t parentID); - const BoneID& GetParentID() const; + void SetParentID(BoneID parentID); + BoneID GetParentID() const; - void AddChildID(uint32_t childID); + void AddChildID(BoneID childID); uint32_t GetChildCount() const; std::vector& GetChildIDs(); const std::vector& GetChildIDs() const; diff --git a/public/Scene/Camera.h b/public/Scene/Camera.h index 52b31bae..9f9dae3a 100644 --- a/public/Scene/Camera.h +++ b/public/Scene/Camera.h @@ -28,7 +28,8 @@ class CORE_API Camera final Camera& operator=(Camera&&); ~Camera(); - const CameraID& GetID() const; + void SetID(CameraID id); + CameraID GetID() const; void SetName(const char* pName); const char* GetName() const; diff --git a/public/Scene/Mesh.h b/public/Scene/Mesh.h index 4f4f2ba5..8f6e5128 100644 --- a/public/Scene/Mesh.h +++ b/public/Scene/Mesh.h @@ -51,7 +51,7 @@ class CORE_API Mesh final AABB& GetAABB(); const AABB& GetAABB() const; - void SetMaterialID(uint32_t materialIndex); + void SetMaterialID(MaterialID materialID); MaterialID GetMaterialID() const; uint32_t GetMorphCount() const; @@ -106,27 +106,12 @@ class CORE_API Mesh final void SetVertexBoneWeight(uint32_t boneIndex, uint32_t vertexIndex, BoneID boneID, VertexWeight weight); std::vector& GetVertexBoneIDs(uint32_t boneIndex); const std::vector& GetVertexBoneIDs(uint32_t boneIndex) const; - BoneID& GetVertexBoneID(uint32_t boneIndex, uint32_t vertexIndex); - const BoneID& GetVertexBoneID(uint32_t boneIndex, uint32_t vertexIndex) const; + BoneID GetVertexBoneID(uint32_t boneIndex, uint32_t vertexIndex) const; std::vector& GetVertexWeights(uint32_t boneIndex); const std::vector& GetVertexWeights(uint32_t boneIndex) const; VertexWeight& GetVertexWeight(uint32_t boneIndex, uint32_t vertexIndex); const VertexWeight& GetVertexWeight(uint32_t boneIndex, uint32_t vertexIndex) const; - uint32_t GetVertexAdjacentVertexCount(uint32_t vertexIndex) const; - void AddVertexAdjacentVertexID(uint32_t vertexIndex, VertexID vertexID); - VertexIDArray& GetVertexAdjacentVertexArray(uint32_t vertexIndex); - const VertexIDArray& GetVertexAdjacentVertexArray(uint32_t vertexIndex) const; - std::vector& GetVertexAdjacentVertexArrays(); - const std::vector& GetVertexAdjacentVertexArrays() const; - - uint32_t GetVertexAdjacentPolygonCount(uint32_t vertexIndex) const; - void AddVertexAdjacentPolygonID(uint32_t vertexIndex, PolygonID polygonID); - PolygonIDArray& GetVertexAdjacentPolygonArray(uint32_t vertexIndex); - const PolygonIDArray& GetVertexAdjacentPolygonArray(uint32_t vertexIndex) const; - std::vector& GetVertexAdjacentPolygonArrays(); - const std::vector& GetVertexAdjacentPolygonArrays() const; - void SetPolygon(uint32_t polygonIndex, Polygon polygon); std::vector& GetPolygons(); const std::vector& GetPolygons() const; @@ -134,15 +119,6 @@ class CORE_API Mesh final const Polygon& GetPolygon(uint32_t polygonIndex) const; cd::VertexID GetPolygonVertexID(uint32_t polygonIndex, uint32_t vertexIndex) const; - void MarkVertexInvalid(VertexID v); - bool IsVertexValid(VertexID v) const; - void SwapVertexData(VertexID v0, VertexID v1); - void RemoveVertexData(VertexID v); - - void MarkPolygonInvalid(PolygonID p); - bool IsPolygonValid(PolygonID p) const; - void RemovePolygonData(PolygonID p); - Mesh& operator<<(InputArchive& inputArchive); Mesh& operator<<(InputArchiveSwapBytes& inputArchive); const Mesh& operator>>(OutputArchive& outputArchive) const; diff --git a/public/Scene/Node.h b/public/Scene/Node.h index 74fb53fd..c821bddd 100644 --- a/public/Scene/Node.h +++ b/public/Scene/Node.h @@ -33,20 +33,20 @@ class CORE_API Node final void Init(NodeID nodeID, std::string name); void SetID(NodeID nodeID); - const NodeID& GetID() const; + NodeID GetID() const; void SetName(std::string name); const char* GetName() const; - void SetParentID(uint32_t parentID); - const NodeID& GetParentID() const; + void SetParentID(NodeID parentID); + NodeID GetParentID() const; - void AddChildID(uint32_t childID); + void AddChildID(NodeID childID); uint32_t GetChildCount() const; std::vector& GetChildIDs(); const std::vector& GetChildIDs() const; - void AddMeshID(uint32_t meshID); + void AddMeshID(MeshID meshID); uint32_t GetMeshCount() const; std::vector& GetMeshIDs(); const std::vector& GetMeshIDs() const; diff --git a/public/Scene/ObjectID.h b/public/Scene/ObjectID.h index 0dd70eee..eb63e39b 100644 --- a/public/Scene/ObjectID.h +++ b/public/Scene/ObjectID.h @@ -27,7 +27,7 @@ class ObjectID final ObjectID(ObjectID&&) = default; ObjectID& operator=(ObjectID&&) = default; ~ObjectID() = default; - const T& Data() const { return m_id; } + T Data() const { return m_id; } void Set(T id) { m_id = id; } ObjectID& operator=(T id) { m_id = id; return *this; } diff --git a/public/Scene/Track.h b/public/Scene/Track.h index 2d7b0095..2ae1b11f 100644 --- a/public/Scene/Track.h +++ b/public/Scene/Track.h @@ -32,7 +32,8 @@ class CORE_API Track final void Init(TrackID id, std::string name); - const TrackID& GetID() const; + void SetID(TrackID id); + TrackID GetID() const; void SetName(std::string name); const char* GetName() const;