Skip to content

Commit

Permalink
remove skin related data in mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
T-rvw committed Jan 5, 2024
1 parent 458f5c5 commit 324ce29
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 164 deletions.
25 changes: 11 additions & 14 deletions examples/Prototype/HalfEdgeMesh/FbxToHEMToFbx/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
#include "Scene/SceneDatabase.h"
#include "Utilities/PerformanceProfiler.h"

namespace
{

int main(int argc, char** argv)
{
// argv[0] : exe name
Expand Down Expand Up @@ -37,17 +34,17 @@ int main(int argc, char** argv)
}

// 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);
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
2 changes: 1 addition & 1 deletion private/Framework/ProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void ProcessorImpl::FlattenSceneDatabase()
for (uint32_t meshIndex = 0U; meshIndex < m_pCurrentSceneDatabase->GetMeshCount(); ++meshIndex)
{
cd::Mesh& mesh = meshes[meshIndex];
if (0U != mesh.GetVertexInfluenceCount())
if (mesh.GetSkinIDCount() > 0U)
{
// Don't need to support flatten SkinMesh currently.
continue;
Expand Down
62 changes: 58 additions & 4 deletions private/Producers/FbxProducer/FbxProducerImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#include "FbxProducerImpl.h"

#include "Hashers/StringHash.hpp"
#include "Scene/MaterialTextureType.h"
#include "Scene/Mesh.h"
#include "Scene/SceneDatabase.h"
#include "Scene/VertexFormat.h"

#include <fbxsdk.h>

Expand Down Expand Up @@ -316,11 +313,27 @@ void FbxProducerImpl::TraverseNodeRecursively(fbxsdk::FbxNode* pSDKNode, cd::Nod
mesh.SetBlendShapeIDCount(blendShapeCount);
for (int32_t blendShapeIndex = 0; blendShapeIndex < blendShapeCount; ++blendShapeIndex)
{
const fbxsdk::FbxBlendShape* pBlendShape = static_cast<fbxsdk::FbxBlendShape*>(pFbxMesh->GetDeformer(blendShapeIndex, fbxsdk::FbxDeformer::eBlendShape));
const auto* pBlendShape = static_cast<fbxsdk::FbxBlendShape*>(pFbxMesh->GetDeformer(blendShapeIndex, fbxsdk::FbxDeformer::eBlendShape));
mesh.SetBlendShapeID(blendShapeIndex, ParseBlendShape(pBlendShape, mesh, pSceneDatabase));
}
}

// SkinMesh
if (IsOptionEnabled(FbxProducerOptions::ImportSkinMesh))
{
auto& vertexFormat = mesh.GetVertexFormat();
vertexFormat.AddAttributeLayout(cd::VertexAttributeType::BoneIndex, cd::AttributeValueType::Int16, cd::MaxBoneInfluenceCount);
vertexFormat.AddAttributeLayout(cd::VertexAttributeType::BoneWeight, cd::AttributeValueType::Float, cd::MaxBoneInfluenceCount);

int32_t skinDeformerCount = pFbxMesh->GetDeformerCount(fbxsdk::FbxDeformer::eSkin);
mesh.SetSkinIDCount(skinDeformerCount);
for (int32_t skinIndex = 0; skinIndex < skinDeformerCount; ++skinIndex)
{
const auto* pSkin = static_cast<fbxsdk::FbxSkin*>(pFbxMesh->GetDeformer(skinIndex, fbxsdk::FbxDeformer::eSkin));
mesh.SetSkinID(skinIndex, ParseSkin(pSkin, mesh, pSceneDatabase));
}
}

pSceneDatabase->AddMesh(cd::MoveTemp(mesh));
}
}
Expand Down Expand Up @@ -707,6 +720,47 @@ cd::BlendShapeID FbxProducerImpl::ParseBlendShape(const fbxsdk::FbxBlendShape* p
return blendShapeID;
}

cd::SkinID FbxProducerImpl::ParseSkin(const fbxsdk::FbxSkin* pSkin, const cd::Mesh& sourceMesh, cd::SceneDatabase* pSceneDatabase)
{
assert(pSkin);

cd::SkinID skinID = m_skinIDGenerator.AllocateID();
uint32_t influenceBoneCount = pSkin->GetClusterCount();

cd::Skin skin;
skin.SetID(skinID);
skin.SetMeshID(sourceMesh.GetID());
skin.SetName(pSkin->GetName());
skin.SetVertexInfluenceBoneIDCount(influenceBoneCount);
skin.SetVertexBoneIndexCount(sourceMesh.GetVertexPositionCount());
skin.SetVertexBoneWeightCount(sourceMesh.GetVertexPositionCount());
for (int32_t skinClusterIndex = 0; skinClusterIndex < pSkin->GetClusterCount(); ++skinClusterIndex)
{
const fbxsdk::FbxCluster* pSkinCluster = pSkin->GetCluster(skinClusterIndex);
assert(pSkinCluster);

const fbxsdk::FbxNode* pLinkBone = pSkinCluster->GetLink();
assert(pLinkBone);

const char* pBoneName = pLinkBone->GetName();

const int32_t controlPointIndicesCount = pSkinCluster->GetControlPointIndicesCount();
int* pControlPointIndices = pSkinCluster->GetControlPointIndices();
double* pBoneWeights = pSkinCluster->GetControlPointWeights();
for (int32_t controlPointIndex = 0; controlPointIndex < controlPointIndicesCount; ++controlPointIndex)
{
uint32_t vertexIndex = pControlPointIndices[controlPointIndex];
float boneWeight = static_cast<float>(pBoneWeights[controlPointIndex]);


}
}

pSceneDatabase->AddSkin(cd::MoveTemp(skin));

return skinID;
}

std::pair<cd::MaterialID, bool> FbxProducerImpl::AllocateMaterialID(const fbxsdk::FbxSurfaceMaterial* pSDKMaterial)
{
uint32_t materialHash = cd::StringHash<cd::MaterialID::ValueType>(pSDKMaterial->GetName());
Expand Down
4 changes: 3 additions & 1 deletion private/Producers/FbxProducer/FbxProducerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class FbxMesh;
class FbxNode;
class FbxProperty;
class FbxScene;
class FbxSkin;
class FbxSurfaceMaterial;

}
Expand Down Expand Up @@ -70,9 +71,10 @@ class FbxProducerImpl final

void ParseMesh(cd::Mesh& mesh, fbxsdk::FbxNode* pSDKNode, fbxsdk::FbxMesh* pFbxMesh);

void ParseSkin();
cd::BlendShapeID ParseBlendShape(const fbxsdk::FbxBlendShape* pBlendShape, const cd::Mesh& sourceMesh, cd::SceneDatabase* pSceneDatabase);

cd::SkinID ParseSkin(const fbxsdk::FbxSkin* pSkin, const cd::Mesh& sourceMesh, cd::SceneDatabase* pSceneDatabase);

cd::BoneID ParseBone(const fbxsdk::FbxNode* pSDKNode, cd::BoneID parentBoneID, cd::SceneDatabase* pSceneDatabase);
void ParseAnimation(fbxsdk::FbxScene* scene, cd::SceneDatabase* pSceneDatabase);

Expand Down
9 changes: 0 additions & 9 deletions private/ProgressiveMesh/ProgressiveMeshImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,15 +478,6 @@ cd::Mesh ProgressiveMeshImpl::GenerateLodMesh(uint32_t targetFaceCount, const cd
mesh.SetVertexColor(setIndex, newVertexIndex, pSourceMesh->GetVertexColor(setIndex, vertexIndex));
}
}

if (vertexFormat.Contains(cd::VertexAttributeType::BoneIndex) && vertexFormat.Contains(cd::VertexAttributeType::BoneWeight))
{
mesh.SetVertexInfluenceCount(pSourceMesh->GetVertexInfluenceCount());
for (uint32_t boneIndex = 0U; boneIndex < mesh.GetVertexInfluenceCount(); ++boneIndex)
{
mesh.SetVertexBoneWeight(boneIndex, newVertexIndex, pSourceMesh->GetVertexBoneID(boneIndex, vertexIndex), pSourceMesh->GetVertexWeight(boneIndex, vertexIndex));
}
}
}
}
}
Expand Down
53 changes: 0 additions & 53 deletions private/Scene/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,57 +142,4 @@ const Color& Mesh::GetVertexColor(uint32_t setIndex, uint32_t vertexIndex) const
return m_pMeshImpl->GetVertexColor(setIndex, vertexIndex);
}

//////////////////////////////////////////////////////////////////////////
// Vertex animation data
//////////////////////////////////////////////////////////////////////////
void Mesh::SetVertexInfluenceCount(uint32_t influenceCount)
{
m_pMeshImpl->SetVertexInfluenceCount(influenceCount);
}

uint32_t Mesh::GetVertexInfluenceCount() const
{
return m_pMeshImpl->GetVertexInfluenceCount();
}

void Mesh::SetVertexBoneWeight(uint32_t boneIndex, uint32_t vertexIndex, BoneID boneID, VertexWeight weight)
{
m_pMeshImpl->SetVertexBoneWeight(boneIndex, vertexIndex, boneID, weight);
}

std::vector<BoneID>& Mesh::GetVertexBoneIDs(uint32_t boneIndex)
{
return m_pMeshImpl->GetVertexBoneIDs(boneIndex);
}

const std::vector<BoneID>& Mesh::GetVertexBoneIDs(uint32_t boneIndex) const
{
return m_pMeshImpl->GetVertexBoneIDs(boneIndex);
}

BoneID Mesh::GetVertexBoneID(uint32_t boneIndex, uint32_t vertexIndex) const
{
return m_pMeshImpl->GetVertexBoneID(boneIndex, vertexIndex);
}

std::vector<VertexWeight>& Mesh::GetVertexWeights(uint32_t boneIndex)
{
return m_pMeshImpl->GetVertexWeights(boneIndex);
}

const std::vector<VertexWeight>& Mesh::GetVertexWeights(uint32_t boneIndex) const
{
return m_pMeshImpl->GetVertexWeights(boneIndex);
}

VertexWeight& Mesh::GetVertexWeight(uint32_t boneIndex, uint32_t vertexIndex)
{
return m_pMeshImpl->GetVertexWeight(boneIndex, vertexIndex);
}

const VertexWeight& Mesh::GetVertexWeight(uint32_t boneIndex, uint32_t vertexIndex) const
{
return m_pMeshImpl->GetVertexWeight(boneIndex, vertexIndex);
}

}
34 changes: 0 additions & 34 deletions private/Scene/MeshImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,38 +371,4 @@ void MeshImpl::SetVertexColor(uint32_t setIndex, uint32_t vertexIndex, const Col
m_vertexColorSets[setIndex][vertexIndex] = color;
}

////////////////////////////////////////////////////////////////////////////////////
// Vertex skin data
////////////////////////////////////////////////////////////////////////////////////
void MeshImpl::SetVertexInfluenceCount(uint32_t influenceCount)
{
assert(GetVertexCount() != 0U);

m_vertexInfluenceCount = influenceCount;
for (uint32_t influenceIndex = 0U; influenceIndex < influenceCount; ++influenceIndex)
{
m_vertexBoneIDs[influenceIndex].resize(GetVertexCount());
m_vertexWeights[influenceIndex].resize(GetVertexCount());
}
}

void MeshImpl::SetVertexBoneWeight(uint32_t boneIndex, uint32_t vertexIndex, BoneID boneID, VertexWeight weight)
{
assert(vertexIndex < GetVertexCount());

if(m_vertexBoneIDs[boneIndex].empty() &&
m_vertexWeights[boneIndex].empty())
{
m_vertexBoneIDs[boneIndex].resize(GetVertexCount());
m_vertexWeights[boneIndex].resize(GetVertexCount());

++m_vertexInfluenceCount;

assert(m_vertexInfluenceCount <= cd::MaxBoneInfluenceCount);
}

m_vertexBoneIDs[boneIndex][vertexIndex] = boneID;
m_vertexWeights[boneIndex][vertexIndex] = weight;
}

}
36 changes: 2 additions & 34 deletions private/Scene/MeshImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,6 @@ class MeshImpl final
std::vector<Color>& GetVertexColors(uint32_t colorSetIndex) { return m_vertexColorSets[colorSetIndex]; }
const std::vector<Color>& GetVertexColors(uint32_t colorSetIndex) const { return m_vertexColorSets[colorSetIndex]; }

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) const { return m_vertexBoneIDs[boneIndex][vertexIndex]; }
std::vector<BoneID>& GetVertexBoneIDs(uint32_t boneIndex) { return m_vertexBoneIDs[boneIndex]; }
const std::vector<BoneID>& GetVertexBoneIDs(uint32_t boneIndex) const { return m_vertexBoneIDs[boneIndex]; }
VertexWeight& GetVertexWeight(uint32_t boneIndex, uint32_t vertexIndex) { return m_vertexWeights[boneIndex][vertexIndex]; }
const VertexWeight& GetVertexWeight(uint32_t boneIndex, uint32_t vertexIndex) const { return m_vertexWeights[boneIndex][vertexIndex]; }
std::vector<VertexWeight>& GetVertexWeights(uint32_t boneIndex) { return m_vertexWeights[boneIndex]; }
const std::vector<VertexWeight>& GetVertexWeights(uint32_t boneIndex) const { return m_vertexWeights[boneIndex]; }

template<bool SwapBytesOrder>
MeshImpl& operator<<(TInputArchive<SwapBytesOrder>& inputArchive)
{
Expand All @@ -89,13 +78,11 @@ class MeshImpl final
uint32_t vertexCount;
uint32_t vertexUVSetCount;
uint32_t vertexColorSetCount;
uint32_t vertexInfluenceCount;
uint32_t polygonGroupCount;

inputArchive >> GetName() >> GetID().Data() >> GetAABB()
>> materialCount >> blendShapeCount >> skinCount
>> vertexCount >> GetVertexAttributeCount()
>> vertexUVSetCount >> vertexColorSetCount >> vertexInfluenceCount
>> vertexCount >> GetVertexAttributeCount() >> vertexUVSetCount >> vertexColorSetCount
>> polygonGroupCount;

GetVertexFormat() << inputArchive;
Expand Down Expand Up @@ -128,13 +115,6 @@ class MeshImpl final
inputArchive.ImportBuffer(GetVertexColors(colorSetIndex).data());
}

SetVertexInfluenceCount(vertexInfluenceCount);
for (uint32_t boneIndex = 0U; boneIndex < GetVertexInfluenceCount(); ++boneIndex)
{
inputArchive.ImportBuffer(GetVertexBoneIDs(boneIndex).data());
inputArchive.ImportBuffer(GetVertexWeights(boneIndex).data());
}

SetPolygonGroupCount(polygonGroupCount);
for (uint32_t polygonGroupIndex = 0U; polygonGroupIndex < GetPolygonGroupCount(); ++polygonGroupIndex)
{
Expand All @@ -160,8 +140,7 @@ class MeshImpl final
{
outputArchive << GetName() << GetID().Data() << GetAABB()
<< GetMaterialIDCount() << GetBlendShapeIDCount() << GetSkinIDCount()
<< GetVertexPositionCount() << GetVertexAttributeCount()
<< GetVertexUVSetCount() << GetVertexColorSetCount() << GetVertexInfluenceCount()
<< GetVertexPositionCount() << GetVertexAttributeCount() << GetVertexUVSetCount() << GetVertexColorSetCount()
<< GetPolygonGroupCount();

GetVertexFormat() >> outputArchive;
Expand All @@ -184,12 +163,6 @@ class MeshImpl final
outputArchive.ExportBuffer(GetVertexColors(colorSetIndex).data(), GetVertexColors(colorSetIndex).size());
}

for (uint32_t boneIndex = 0U; boneIndex < GetVertexInfluenceCount(); ++boneIndex)
{
outputArchive.ExportBuffer(GetVertexBoneIDs(boneIndex).data(), GetVertexBoneIDs(boneIndex).size());
outputArchive.ExportBuffer(GetVertexWeights(boneIndex).data(), GetVertexWeights(boneIndex).size());
}

for (uint32_t polygonGroupIndex = 0U; polygonGroupIndex < GetPolygonGroupCount(); ++polygonGroupIndex)
{
const auto& polygonGroup = GetPolygonGroup(polygonGroupIndex);
Expand All @@ -208,15 +181,10 @@ class MeshImpl final
private:
uint32_t m_vertexUVSetCount = 0U;
uint32_t m_vertexColorSetCount = 0U;
uint32_t m_vertexInfluenceCount = 0U;

// vertex texture data
std::vector<UV> m_vertexUVSets[MaxUVSetCount];
std::vector<Color> m_vertexColorSets[MaxColorSetCount];

// vertex skin data
std::vector<BoneID> m_vertexBoneIDs[MaxBoneInfluenceCount];
std::vector<VertexWeight> m_vertexWeights[MaxBoneInfluenceCount];
};

}
2 changes: 1 addition & 1 deletion private/Scene/SceneDatabaseImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include "Scene/Mesh.h"
#include "Scene/Morph.h"
#include "Scene/Node.h"
#include "Scene/Skin.h"
#include "Scene/Skeleton.h"
#include "Scene/Skin.h"
#include "Scene/Texture.h"
#include "Scene/Track.h"
#include "Scene/ParticleEmitter.h"
Expand Down
1 change: 1 addition & 0 deletions private/Scene/Skin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace cd

PIMPL_SCENE_CLASS(Skin);
PIMPL_SIMPLE_TYPE_APIS(Skin, ID);
PIMPL_SIMPLE_TYPE_APIS(Skin, MeshID);
PIMPL_SIMPLE_TYPE_APIS(Skin, SkeletonID);
PIMPL_STRING_TYPE_APIS(Skin, Name);
PIMPL_VECTOR_TYPE_APIS(Skin, VertexInfluenceBoneID);
Expand Down
1 change: 1 addition & 0 deletions private/Scene/SkinImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SkinImpl final
DECLARE_SCENE_IMPL_CLASS(Skin);

IMPLEMENT_SIMPLE_TYPE_APIS(Skin, ID);
IMPLEMENT_SIMPLE_TYPE_APIS(Skin, MeshID);
IMPLEMENT_SIMPLE_TYPE_APIS(Skin, SkeletonID);
IMPLEMENT_STRING_TYPE_APIS(Skin, Name);
IMPLEMENT_VECTOR_TYPE_APIS(Skin, VertexInfluenceBoneID);
Expand Down
Loading

0 comments on commit 324ce29

Please sign in to comment.