Skip to content

Commit

Permalink
refact scene types (#273)
Browse files Browse the repository at this point in the history
* use options enum for procesor and fbxproducer

* add blendshape/skeleton/skin

* refact skeletal mesh workflow
  • Loading branch information
T-rvw authored Jan 11, 2024
1 parent 7f628b4 commit a672f50
Show file tree
Hide file tree
Showing 98 changed files with 2,490 additions and 2,281 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@

# Learning Resources

[assimp](https://github.com/assimp/assimp)

[OpenGEX](https://opengex.org/)

[Scotty3D](https://github.com/CMU-Graphics/Scotty3D)

[UHEM](https://github.com/Ubpa/UHEMesh)
4 changes: 3 additions & 1 deletion auto/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ print("ChoosePlatform = "..ChoosePlatform)
local USE_CLANG_TOOLSET = os.getenv("USE_CLANG_TOOLSET") or "0"
BUILD_ASSIMP = not os.istarget("linux") and USE_CLANG_TOOLSET == "0"
BUILD_FBX = not os.istarget("linux") and USE_CLANG_TOOLSET == "0"
BUILD_TERRAIN = not os.istarget("linux") and USE_CLANG_TOOLSET == "0"
local BUILD_EXAMPLES = not os.istarget("linux") and USE_CLANG_TOOLSET == "0"

-- Deprecated
BUILD_TERRAIN = false -- not os.istarget("linux") and USE_CLANG_TOOLSET == "0"

find_fbxsdk = require("premake-findfbx")
find_fbxsdk.dump_information = true
local sdkLocation = find_fbxsdk.get_sdk_location()
Expand Down
10 changes: 8 additions & 2 deletions examples/ConvertToCD/FbxToCD/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ int main(int argc, char** argv)
const char* pInputFilePath = argv[1];
const char* pOutputFilePath = argv[2];
FbxProducer producer(pInputFilePath);
producer.EnableOption(FbxProducerOptions::ImportAnimation);
producer.EnableOption(FbxProducerOptions::ImportBlendShape);
producer.EnableOption(FbxProducerOptions::ImportMaterial);
producer.EnableOption(FbxProducerOptions::ImportTexture);
producer.EnableOption(FbxProducerOptions::ImportSkeleton);
producer.EnableOption(FbxProducerOptions::ImportSkeletalMesh);
producer.EnableOption(FbxProducerOptions::ImportLight);
producer.EnableOption(FbxProducerOptions::Triangulate);
CDConsumer consumer(pOutputFilePath);
Processor processor(&producer, &consumer);
processor.SetDumpSceneDatabaseEnable(true);
processor.SetValidateSceneDatabaseEnable(true);
processor.Run();

return 0;
Expand Down
9 changes: 0 additions & 9 deletions examples/ConvertToCD/GenericToCD/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,8 @@ int main(int argc, char** argv)
const char* pInputFilePath = argv[1];
const char* pOutputFilePath = argv[2];
GenericProducer producer(pInputFilePath);
producer.EnableOption(GenericProducerOptions::GenerateBoundingBox);
producer.EnableOption(GenericProducerOptions::TriangulateModel);
producer.EnableOption(GenericProducerOptions::GenerateTangentSpace);
producer.EnableOption(GenericProducerOptions::CleanUnusedObjects);
producer.EnableOption(GenericProducerOptions::OnlyTransformAnimationKey);

CDConsumer consumer(pOutputFilePath);
Processor processor(&producer, &consumer);
//processor.SetFlattenSceneDatabaseEnable(true);
processor.SetDumpSceneDatabaseEnable(true);
processor.SetValidateSceneDatabaseEnable(true);
processor.Run();

return 0;
Expand Down
5 changes: 1 addition & 4 deletions examples/ProjectTools/ArtDemo_CDToCD/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ int main(int argc, char** argv)
auto pSceneDatabase = std::make_unique<cd::SceneDatabase>();
{
Processor processor(&producer, nullptr, pSceneDatabase.get());
processor.SetDumpSceneDatabaseEnable(false);
processor.SetValidateSceneDatabaseEnable(true);
processor.DisableOption(ProcessorOptions::Dump);
processor.Run();
}

Expand Down Expand Up @@ -63,8 +62,6 @@ int main(int argc, char** argv)

{
Processor processor(nullptr, &consumer, pSceneDatabase.get());
processor.SetDumpSceneDatabaseEnable(true);
processor.SetValidateSceneDatabaseEnable(true);
processor.Run();
}

Expand Down
6 changes: 1 addition & 5 deletions examples/ProjectTools/FF7_GenericToCD/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ int main(int argc, char** argv)
std::string ormTextureSuffixAndExtension = "ORM.png";
{
GenericProducer producer(pInputFilePath);
producer.EnableOption(GenericProducerOptions::GenerateBoundingBox);
producer.EnableOption(GenericProducerOptions::TriangulateModel);
producer.EnableOption(GenericProducerOptions::GenerateTangentSpace);
producer.EnableOption(GenericProducerOptions::CleanUnusedObjects);
producer.EnableOption(GenericProducerOptions::FlattenTransformHierarchy);

MergeTextureConsumer consumer(outputTextureFolderPath.string().c_str());
Expand All @@ -58,7 +54,7 @@ int main(int argc, char** argv)
consumer.SetTextureTypeAndDefaultValue(cd::MaterialTextureType::Metallic, 25);

Processor processor(&producer, &consumer, pSceneDatabase.get());
processor.SetDumpSceneDatabaseEnable(false);
processor.DisableOption(ProcessorOptions::Dump);
processor.Run();
}

Expand Down
3 changes: 1 addition & 2 deletions examples/ProjectTools/ORM_FbxToCD/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main(int argc, char** argv)
consumer.SetTextureTypeAndDefaultValue(cd::MaterialTextureType::Metallic, 128);

Processor processor(&producer, &consumer, pSceneDatabase.get());
processor.SetDumpSceneDatabaseEnable(false);
processor.DisableOption(ProcessorOptions::Dump);
processor.Run();
}

Expand Down Expand Up @@ -121,7 +121,6 @@ int main(int argc, char** argv)
{
CDConsumer consumer(pOutputFilePath);
Processor processor(nullptr, &consumer, pSceneDatabase.get());
processor.SetFlattenSceneDatabaseEnable(true);
processor.Run();
}

Expand Down
6 changes: 1 addition & 5 deletions examples/ProjectTools/ORM_GenericToCD/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ int main(int argc, char** argv)
std::string ormTextureSuffixAndExtension = "orm.png";
{
GenericProducer producer(pInputFilePath);
producer.EnableOption(GenericProducerOptions::GenerateBoundingBox);
producer.EnableOption(GenericProducerOptions::TriangulateModel);
producer.EnableOption(GenericProducerOptions::GenerateTangentSpace);
producer.EnableOption(GenericProducerOptions::CleanUnusedObjects);
producer.EnableOption(GenericProducerOptions::FlattenTransformHierarchy);

MergeTextureConsumer consumer;
Expand All @@ -52,7 +48,7 @@ int main(int argc, char** argv)
consumer.SetTextureTypeAndDefaultValue(cd::MaterialTextureType::Metallic, 128);

Processor processor(&producer, &consumer, pSceneDatabase.get());
processor.SetDumpSceneDatabaseEnable(false);
processor.DisableOption(ProcessorOptions::Dump);
processor.Run();
}

Expand Down
78 changes: 12 additions & 66 deletions examples/Prototype/HalfEdgeMesh/FbxToHEMToFbx/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,6 @@
#include "Scene/SceneDatabase.h"
#include "Utilities/PerformanceProfiler.h"

namespace
{

cd::Mesh GenerateBoundaryMesh(const cd::Mesh& mesh)
{
uint32_t newVertexIndex = 0U;
std::map<uint32_t, uint32_t> mapPosToVertexIndex;
std::map<uint32_t, uint32_t> mapOldIndexToNewIndex;
for (uint32_t vertexIndex = 0U; vertexIndex < mesh.GetVertexCount(); ++vertexIndex)
{
const auto& position = mesh.GetVertexPosition(vertexIndex);
uint32_t positionHash = cd::HashCombine(cd::Math::CastFloatToU32(position.x()),
cd::HashCombine(cd::Math::CastFloatToU32(position.y()), cd::Math::CastFloatToU32(position.z())));

auto itVertexIndex = mapPosToVertexIndex.find(positionHash);
if (itVertexIndex != mapPosToVertexIndex.end())
{
uint32_t uniqueVertexIndex = itVertexIndex->second;
mapOldIndexToNewIndex[vertexIndex] = mapOldIndexToNewIndex[uniqueVertexIndex];
}
else
{
mapPosToVertexIndex[positionHash] = vertexIndex;
mapOldIndexToNewIndex[vertexIndex] = newVertexIndex++;
}
}

uint32_t newVertexCount = static_cast<uint32_t>(mapPosToVertexIndex.size());
uint32_t newPolygonCount = mesh.GetPolygonCount();
cd::Mesh newMesh(newVertexCount, newPolygonCount);
newMesh.SetName(mesh.GetName());
newMesh.SetMaterialID(mesh.GetMaterialID());

for (const auto& [oldIndex, newIndex] : mapOldIndexToNewIndex)
{
newMesh.SetVertexPosition(newIndex, mesh.GetVertexPosition(oldIndex));
}

for (uint32_t polygonIndex = 0U; polygonIndex < newPolygonCount; ++polygonIndex)
{
const auto& oldPolygon = mesh.GetPolygon(polygonIndex);
auto& newPolygon = newMesh.GetPolygon(polygonIndex);
for (uint32_t polygonVertexIndex = 0U; polygonVertexIndex < oldPolygon.size(); ++polygonVertexIndex)
{
uint32_t oldIndex = oldPolygon[polygonVertexIndex].Data();
newPolygon.push_back(mapOldIndexToNewIndex[oldIndex]);
}
}

return newMesh;
}

}

int main(int argc, char** argv)
{
// argv[0] : exe name
Expand All @@ -82,23 +28,23 @@ int main(int argc, char** argv)
// Import
{
FbxProducer producer(pInputFilePath);
producer.SetWantTriangulate(false);
producer.DisableOption(FbxProducerOptions::Triangulate);
Processor processor(&producer, nullptr, pSceneDatabase.get());
processor.Run();
}

// Processing
for (const auto& mesh : pSceneDatabase->GetMeshes())
{
cd::Mesh boundaryMesh = GenerateBoundaryMesh(mesh);
auto halfEdgeMesh = cd::HalfEdgeMesh::FromIndexedMesh(boundaryMesh);
assert(halfEdgeMesh.IsValid());

auto newMesh = cd::Mesh::FromHalfEdgeMesh(halfEdgeMesh, cd::ConvertStrategy::BoundaryOnly);
newMesh.SetName(mesh.GetName());
newMesh.SetID(pNewSceneDatabase->GetMeshCount());
pNewSceneDatabase->AddMesh(cd::MoveTemp(newMesh));
}
//for (const auto& mesh : pSceneDatabase->GetMeshes())
//{
// cd::Mesh boundaryMesh = GenerateBoundaryMesh(mesh);
// auto halfEdgeMesh = cd::HalfEdgeMesh::FromIndexedMesh(boundaryMesh);
// assert(halfEdgeMesh.IsValid());
//
// auto newMesh = cd::Mesh::FromHalfEdgeMesh(halfEdgeMesh);
// newMesh.SetName(mesh.GetName());
// newMesh.SetID(pNewSceneDatabase->GetMeshCount());
// pNewSceneDatabase->AddMesh(cd::MoveTemp(newMesh));
//}

// Export
{
Expand Down
1 change: 0 additions & 1 deletion examples/Prototype/HalfEdgeMesh/HEMToFbx/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ int main(int argc, char** argv)
{
FbxConsumer consumer(pOutputFilePath);
Processor processor(nullptr, &consumer, pSceneDatabase.get());
processor.SetDumpSceneDatabaseEnable(true);
processor.Run();
}

Expand Down
17 changes: 8 additions & 9 deletions examples/Prototype/ProgressiveMesh/GenericToPM/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ int main(int argc, char** argv)
// Import
{
GenericProducer producer(pInputFilePath);
producer.EnableOption(GenericProducerOptions::GenerateBoundingBox);
producer.EnableOption(GenericProducerOptions::TriangulateModel);
producer.EnableOption(GenericProducerOptions::FlattenTransformHierarchy);

Processor processor(&producer, nullptr, pSceneDatabase.get());
processor.SetDumpSceneDatabaseEnable(false);
processor.DisableOption(ProcessorOptions::Dump);
processor.Run();
}

Expand All @@ -43,14 +41,15 @@ int main(int argc, char** argv)
uint32_t polygonCount = mesh.GetPolygonCount();

std::vector<uint32_t> indexBuffer;
for (uint32_t polygonIndex = 0U; polygonIndex < polygonCount; ++polygonIndex)
for (const auto& polygonGroup : mesh.GetPolygonGroups())
{
const auto& polygon = mesh.GetPolygon(polygonIndex);
assert(polygon.size() == 3U && "Need to triangulate.");

for (uint32_t polygonVertexIndex = 0U; polygonVertexIndex < polygon.size(); ++polygonVertexIndex)
for (const auto& polygon : polygonGroup)
{
indexBuffer.push_back(polygon[polygonVertexIndex].Data());
assert(polygon.size() == 3U && "Need to triangulate.");
for (uint32_t polygonVertexIndex = 0U; polygonVertexIndex < polygon.size(); ++polygonVertexIndex)
{
indexBuffer.push_back(polygon[polygonVertexIndex].Data());
}
}
}

Expand Down
20 changes: 8 additions & 12 deletions examples/Prototype/ProgressiveMesh/GenericToPMToFbx/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ int main(int argc, char** argv)
// Import
{
GenericProducer producer(pInputFilePath);
producer.EnableOption(GenericProducerOptions::GenerateBoundingBox);
producer.EnableOption(GenericProducerOptions::TriangulateModel);
producer.EnableOption(GenericProducerOptions::GenerateTangentSpace);
producer.EnableOption(GenericProducerOptions::FlattenTransformHierarchy);
Processor processor(&producer, nullptr, pSceneDatabase.get());
processor.SetDumpSceneDatabaseEnable(true);
processor.Run();
}

Expand All @@ -42,18 +38,18 @@ int main(int argc, char** argv)
{
const auto& mesh = pSceneDatabase->GetMesh(meshIndex);
uint32_t vertexCount = mesh.GetVertexCount();
uint32_t polygonCount = mesh.GetPolygonCount();

std::vector<uint32_t> indexBuffer;
indexBuffer.reserve(polygonCount);
for (uint32_t polygonIndex = 0U; polygonIndex < polygonCount; ++polygonIndex)
for (const auto& polygonGroup : mesh.GetPolygonGroups())
{
const auto& polygon = mesh.GetPolygon(polygonIndex);
assert(polygon.size() == 3U && "Need to triangulate.");

for (uint32_t polygonVertexIndex = 0U; polygonVertexIndex < polygon.size(); ++polygonVertexIndex)
for (const auto& polygon : polygonGroup)
{
indexBuffer.push_back(polygon[polygonVertexIndex].Data());
assert(polygon.size() == 3U && "Need to triangulate.");

for (uint32_t polygonVertexIndex = 0U; polygonVertexIndex < polygon.size(); ++polygonVertexIndex)
{
indexBuffer.push_back(polygon[polygonVertexIndex].Data());
}
}
}

Expand Down
58 changes: 0 additions & 58 deletions examples/Prototype/Terrain/TerrainToCD/Main.cpp

This file was deleted.

Loading

0 comments on commit a672f50

Please sign in to comment.