aboutsummaryrefslogtreecommitdiff
path: root/sdk/extensions/exporter/source
diff options
context:
space:
mode:
authorBryan Galdrikian <[email protected]>2019-05-03 00:25:46 -0700
committerBryan Galdrikian <[email protected]>2019-05-03 00:25:46 -0700
commit74b64a27f8e07b1b0b47b809b1a060518fa11a97 (patch)
tree34cca01711be56892c149706f02ba7358d87ec54 /sdk/extensions/exporter/source
parentFixing chunk reorder bug in BlastTool, when importing a prefractured mesh (diff)
downloadblast-1.1.5_pre1.tar.xz
blast-1.1.5_pre1.zip
Blast SDK 1.1.5 prerelease #1v1.1.5_pre1
Diffstat (limited to 'sdk/extensions/exporter/source')
-rwxr-xr-xsdk/extensions/exporter/source/NvBlastExtExporterFbxReader.cpp53
-rwxr-xr-xsdk/extensions/exporter/source/NvBlastExtExporterFbxReader.h25
-rwxr-xr-xsdk/extensions/exporter/source/NvBlastExtExporterFbxUtils.cpp16
-rwxr-xr-xsdk/extensions/exporter/source/NvBlastExtExporterFbxUtils.h7
-rwxr-xr-xsdk/extensions/exporter/source/NvBlastExtExporterFbxWriter.cpp565
-rwxr-xr-xsdk/extensions/exporter/source/NvBlastExtExporterFbxWriter.h2
-rwxr-xr-xsdk/extensions/exporter/source/NvBlastExtExporterJsonCollision.cpp8
-rwxr-xr-xsdk/extensions/exporter/source/NvBlastExtExporterObjReader.cpp12
-rwxr-xr-xsdk/extensions/exporter/source/NvBlastExtExporterObjReader.h12
-rwxr-xr-xsdk/extensions/exporter/source/NvBlastExtExporterObjWriter.cpp8
10 files changed, 351 insertions, 357 deletions
diff --git a/sdk/extensions/exporter/source/NvBlastExtExporterFbxReader.cpp b/sdk/extensions/exporter/source/NvBlastExtExporterFbxReader.cpp
index 99600fd..22503d3 100755
--- a/sdk/extensions/exporter/source/NvBlastExtExporterFbxReader.cpp
+++ b/sdk/extensions/exporter/source/NvBlastExtExporterFbxReader.cpp
@@ -35,12 +35,9 @@
#include <sstream>
#include <unordered_map>
-#include "PxVec3.h"
-#include "PxVec2.h"
-#include "PxPlane.h"
#include "NvBlastExtAuthoringMesh.h"
#include "NvBlastExtAuthoringBondGenerator.h"
-#include "NvBlastExtAuthoringCollisionBuilder.h"
+#include "NvBlastPxSharedHelpers.h"
using physx::PxVec3;
using physx::PxVec2;
@@ -201,15 +198,15 @@ void FbxFileReader::loadFromFile(const char* filename)
bool bAllTriangles = mesh->IsTriangleMesh();
if (!bAllTriangles)
{
+ //It creates corrupted mesh and return true. Disable it to prevent crash.
//try letting the FBX SDK triangulate it
- geoConverter.Triangulate(mesh, true);
- bAllTriangles = mesh->IsTriangleMesh();
+ //bAllTriangles = geoConverter.Triangulate(mesh, true) && mesh->IsTriangleMesh();
}
int polyCount = mesh->GetPolygonCount();
if (!bAllTriangles)
{
- std::cerr << "Mesh 0 has " << polyCount << " but not all polygons are triangles. Mesh must be triangulated." << std::endl;
+ std::cerr << "Mesh 0 has " << polyCount << " polygons but not all of them are triangles. Mesh must be triangulated." << std::endl;
return;
}
@@ -219,9 +216,9 @@ void FbxFileReader::loadFromFile(const char* filename)
const char * uvSetName = uvSetNames.GetStringAt(0);
- std::vector<PxVec3> positions;
- std::vector<PxVec3> normals;
- std::vector<PxVec2> uv;
+ std::vector<NvcVec3> positions;
+ std::vector<NvcVec3> normals;
+ std::vector<NvcVec2> uv;
std::vector<uint32_t> indices;
int* polyVertices = mesh->GetPolygonVertices();
@@ -259,9 +256,9 @@ void FbxFileReader::loadFromFile(const char* filename)
vert = trans.MultT(vert);
normVec = normalTransf.MultT(normVec);
- positions.push_back(PxVec3((float) vert[0], (float)vert[1], (float)vert[2]));
- normals.push_back(PxVec3((float)normVec[0], (float)normVec[1], (float)normVec[2]));
- uv.push_back(PxVec2((float)uvVec[0], (float)uvVec[1]));
+ positions.push_back({(float) vert[0], (float)vert[1], (float)vert[2]});
+ normals.push_back({(float)normVec[0], (float)normVec[1], (float)normVec[2]});
+ uv.push_back({(float)uvVec[0], (float)uvVec[1]});
indices.push_back(vertIndex++);
}
if (matLayer != nullptr)
@@ -431,7 +428,7 @@ bool FbxFileReader::getCollisionInternal()
vpos++;
}
- chull.points = new PxVec3[uniqueCPValues.size()];
+ chull.points = new NvcVec3[uniqueCPValues.size()];
chull.pointsCount = uint32_t(uniqueCPValues.size());
physx::PxVec3 hullCentroid(0.0f);
@@ -442,7 +439,7 @@ bool FbxFileReader::getCollisionInternal()
chull.points[i].x = (float)worldVPos[0];
chull.points[i].y = (float)worldVPos[1];
chull.points[i].z = (float)worldVPos[2];
- hullCentroid += chull.points[i];
+ hullCentroid += toPxShared(chull.points[i]);
}
if (chull.pointsCount)
@@ -451,7 +448,7 @@ bool FbxFileReader::getCollisionInternal()
}
uint32_t polyCount = meshNode->GetPolygonCount();
- chull.polygonData = new Nv::Blast::CollisionHull::HullPolygon[polyCount];
+ chull.polygonData = new Nv::Blast::HullPolygon[polyCount];
chull.polygonDataCount = polyCount;
chull.indicesCount = meshNode->GetPolygonVertexCount();
@@ -462,8 +459,8 @@ bool FbxFileReader::getCollisionInternal()
{
int32_t vInPolyCount = meshNode->GetPolygonSize(poly);
auto& pd = chull.polygonData[poly];
- pd.mIndexBase = (uint16_t)curIndexCount;
- pd.mNbVerts = (uint16_t)vInPolyCount;
+ pd.indexBase = (uint16_t)curIndexCount;
+ pd.vertexCount = (uint16_t)vInPolyCount;
int32_t* ind = &meshNode->GetPolygonVertices()[meshNode->GetPolygonVertexIndex(poly)];
uint32_t* destInd = chull.indices + curIndexCount;
for (int32_t v = 0; v < vInPolyCount; v++)
@@ -474,9 +471,9 @@ bool FbxFileReader::getCollisionInternal()
//Don't depend on the normals to create the plane normal, they could be wrong
PxVec3 lastThreeVerts[3] = {
- chull.points[chull.indices[curIndexCount - 1]],
- chull.points[chull.indices[curIndexCount - 2]],
- chull.points[chull.indices[curIndexCount - 3]]
+ toPxShared(chull.points[chull.indices[curIndexCount - 1]]),
+ toPxShared(chull.points[chull.indices[curIndexCount - 2]]),
+ toPxShared(chull.points[chull.indices[curIndexCount - 3]])
};
physx::PxPlane plane(lastThreeVerts[0], lastThreeVerts[1], lastThreeVerts[2]);
@@ -484,10 +481,10 @@ bool FbxFileReader::getCollisionInternal()
const float s = plane.n.dot(lastThreeVerts[0] - hullCentroid) >= 0.0f ? 1.0f : -1.0f;
- pd.mPlane[0] = s*plane.n.x;
- pd.mPlane[1] = s*plane.n.y;
- pd.mPlane[2] = s*plane.n.z;
- pd.mPlane[3] = s*plane.d;
+ pd.plane[0] = s*plane.n.x;
+ pd.plane[1] = s*plane.n.y;
+ pd.plane[2] = s*plane.n.z;
+ pd.plane[3] = s*plane.d;
}
}
@@ -582,17 +579,17 @@ bool FbxFileReader::getBoneInfluencesInternal(FbxMesh* meshNode)
return true;
};
-physx::PxVec3* FbxFileReader::getPositionArray()
+NvcVec3* FbxFileReader::getPositionArray()
{
return mVertexPositions.data();
};
-physx::PxVec3* FbxFileReader::getNormalsArray()
+NvcVec3* FbxFileReader::getNormalsArray()
{
return mVertexNormals.data();
};
-physx::PxVec2* FbxFileReader::getUvArray()
+NvcVec2* FbxFileReader::getUvArray()
{
return mVertexUv.data();
};
diff --git a/sdk/extensions/exporter/source/NvBlastExtExporterFbxReader.h b/sdk/extensions/exporter/source/NvBlastExtExporterFbxReader.h
index 0509700..061e603 100755
--- a/sdk/extensions/exporter/source/NvBlastExtExporterFbxReader.h
+++ b/sdk/extensions/exporter/source/NvBlastExtExporterFbxReader.h
@@ -46,11 +46,6 @@ class FbxFileReader : public IFbxFileReader
{
struct CollisionHullImpl : public Nv::Blast::CollisionHull
{
- void release() override
- {
- delete this;
- }
-
//copy from existing
CollisionHullImpl(const CollisionHullImpl& other) : CollisionHullImpl()
{
@@ -76,7 +71,9 @@ class FbxFileReader : public IFbxFileReader
{
if (&other != this)
{
- release();
+ delete[] points;
+ delete[] indices;
+ delete[] polygonData;
copyFrom(other);
}
return *this;
@@ -116,9 +113,9 @@ class FbxFileReader : public IFbxFileReader
pointsCount = other.pointsCount;
indicesCount = other.indicesCount;
polygonDataCount = other.polygonDataCount;
- points = new physx::PxVec3[pointsCount];
+ points = new NvcVec3[pointsCount];
indices = new uint32_t[indicesCount];
- polygonData = new Nv::Blast::CollisionHull::HullPolygon[polygonDataCount];
+ polygonData = new Nv::Blast::HullPolygon[polygonDataCount];
memcpy(points, other.points, sizeof(points[0]) * pointsCount);
memcpy(indices, other.indices, sizeof(indices[0]) * indicesCount);
memcpy(polygonData, other.polygonData, sizeof(polygonData[0]) * polygonDataCount);
@@ -163,15 +160,15 @@ public:
/**
Get loaded vertex positions
*/
- virtual physx::PxVec3* getPositionArray() override;
+ virtual NvcVec3* getPositionArray() override;
/**
Get loaded vertex normals
*/
- virtual physx::PxVec3* getNormalsArray() override;
+ virtual NvcVec3* getNormalsArray() override;
/**
Get loaded vertex uv-coordinates
*/
- virtual physx::PxVec2* getUvArray() override;
+ virtual NvcVec2* getUvArray() override;
/**
Get loaded triangle indices
*/
@@ -203,9 +200,9 @@ private:
std::vector<CollisionHullImpl> mHulls;
std::vector<uint32_t> mVertexToContainingChunkMap;
std::multimap<uint32_t, FbxNode*> mCollisionNodes;
- std::vector<physx::PxVec3> mVertexPositions;
- std::vector<physx::PxVec3> mVertexNormals;
- std::vector<physx::PxVec2> mVertexUv;
+ std::vector<NvcVec3> mVertexPositions;
+ std::vector<NvcVec3> mVertexNormals;
+ std::vector<NvcVec2> mVertexUv;
std::vector<uint32_t> mIndices;
std::vector<int32_t> mSmoothingGroups;
std::vector<int32_t> mMaterialIds;
diff --git a/sdk/extensions/exporter/source/NvBlastExtExporterFbxUtils.cpp b/sdk/extensions/exporter/source/NvBlastExtExporterFbxUtils.cpp
index f135436..4bd996b 100755
--- a/sdk/extensions/exporter/source/NvBlastExtExporterFbxUtils.cpp
+++ b/sdk/extensions/exporter/source/NvBlastExtExporterFbxUtils.cpp
@@ -28,24 +28,18 @@
#include "fbxsdk.h"
#include "NvBlastExtExporterFbxUtils.h"
-#include "PxVec3.h"
-#include "PxVec2.h"
#include "NvBlastExtAuthoringTypes.h"
#include <sstream>
#include <cctype>
-using physx::PxVec3;
-using physx::PxVec2;
-
-
void FbxUtils::VertexToFbx(const Nv::Blast::Vertex& vert, FbxVector4& outVertex, FbxVector4& outNormal, FbxVector2& outUV)
{
- PxVec3ToFbx(vert.p, outVertex);
- PxVec3ToFbx(vert.n, outNormal);
- PxVec2ToFbx(vert.uv[0], outUV);
+ NvcVec3ToFbx(vert.p, outVertex);
+ NvcVec3ToFbx(vert.n, outNormal);
+ NvcVec2ToFbx(vert.uv[0], outUV);
}
-void FbxUtils::PxVec3ToFbx(const physx::PxVec3& inVector, FbxVector4& outVector)
+void FbxUtils::NvcVec3ToFbx(const NvcVec3& inVector, FbxVector4& outVector)
{
outVector[0] = inVector.x;
outVector[1] = inVector.y;
@@ -53,7 +47,7 @@ void FbxUtils::PxVec3ToFbx(const physx::PxVec3& inVector, FbxVector4& outVector)
outVector[3] = 0;
}
-void FbxUtils::PxVec2ToFbx(const physx::PxVec2& inVector, FbxVector2& outVector)
+void FbxUtils::NvcVec2ToFbx(const NvcVec2& inVector, FbxVector2& outVector)
{
outVector[0] = inVector.x;
outVector[1] = inVector.y;
diff --git a/sdk/extensions/exporter/source/NvBlastExtExporterFbxUtils.h b/sdk/extensions/exporter/source/NvBlastExtExporterFbxUtils.h
index 431d63a..ca5b3a2 100755
--- a/sdk/extensions/exporter/source/NvBlastExtExporterFbxUtils.h
+++ b/sdk/extensions/exporter/source/NvBlastExtExporterFbxUtils.h
@@ -30,8 +30,7 @@
#define NVBLASTEXTEXPORTERFBXUTILS_H
#include "fbxsdk.h"
-#include "PxVec3.h"
-#include "PxVec2.h"
+#include <NvCTypes.h>
#include <string>
namespace Nv
@@ -47,8 +46,8 @@ class FbxUtils
public:
static void VertexToFbx(const Nv::Blast::Vertex& vert, FbxVector4& outVertex, FbxVector4& outNormal, FbxVector2& outUV);
- static void PxVec3ToFbx(const physx::PxVec3& inVector, FbxVector4& outVector);
- static void PxVec2ToFbx(const physx::PxVec2& inVector, FbxVector2& outVector);
+ static void NvcVec3ToFbx(const NvcVec3& inVector, FbxVector4& outVector);
+ static void NvcVec2ToFbx(const NvcVec2& inVector, FbxVector2& outVector);
static FbxAxisSystem getBlastFBXAxisSystem();
static FbxSystemUnit getBlastFBXUnit();
diff --git a/sdk/extensions/exporter/source/NvBlastExtExporterFbxWriter.cpp b/sdk/extensions/exporter/source/NvBlastExtExporterFbxWriter.cpp
index a0de9d5..540e9de 100755
--- a/sdk/extensions/exporter/source/NvBlastExtExporterFbxWriter.cpp
+++ b/sdk/extensions/exporter/source/NvBlastExtExporterFbxWriter.cpp
@@ -43,20 +43,16 @@
#include <functional>
#include "NvBlastExtExporterFbxWriter.h"
#include "NvBlastExtExporterFbxUtils.h"
-#include "NvBlastExtAuthoringCollisionBuilder.h"
#include "NvBlastExtAuthoring.h"
#include "NvBlastExtAuthoringMesh.h"
using namespace Nv::Blast;
-FbxFileWriter::FbxFileWriter():
- bOutputFBXAscii(false)
+FbxFileWriter::FbxFileWriter() : bOutputFBXAscii(false)
{
- // Wrap in a shared ptr so that when it deallocates we get an auto destroy and all of the other assets created don't leak.
- sdkManager = std::shared_ptr<FbxManager>(FbxManager::Create(), [=](FbxManager* manager)
- {
- manager->Destroy();
- });
+ // Wrap in a shared ptr so that when it deallocates we get an auto destroy and all of the other assets created don't
+ // leak.
+ sdkManager = std::shared_ptr<FbxManager>(FbxManager::Create(), [=](FbxManager* manager) { manager->Destroy(); });
mScene = FbxScene::Create(sdkManager.get(), "Export Scene");
@@ -65,7 +61,8 @@ FbxFileWriter::FbxFileWriter():
mScene->GetGlobalSettings().SetOriginalUpAxis(FbxUtils::getBlastFBXAxisSystem());
mScene->GetGlobalSettings().SetOriginalSystemUnit(FbxUtils::getBlastFBXUnit());
- //We don't actually check for membership in this layer, but it's useful to show and hide the geo to look at the collision geo
+ // We don't actually check for membership in this layer, but it's useful to show and hide the geo to look at the
+ // collision geo
mRenderLayer = FbxDisplayLayer::Create(mScene, FbxUtils::getRenderGeometryLayerName().c_str());
mRenderLayer->Show.Set(true);
mRenderLayer->Color.Set(FbxDouble3(0.0f, 1.0f, 0.0f));
@@ -75,7 +72,7 @@ FbxFileWriter::FbxFileWriter():
void FbxFileWriter::release()
{
- //sdkManager->Destroy();
+ // sdkManager->Destroy();
delete this;
}
@@ -88,11 +85,11 @@ FbxScene* FbxFileWriter::getScene()
void FbxFileWriter::createMaterials(const ExporterMeshData& aResult)
{
mMaterials.clear();
-
+
for (uint32_t i = 0; i < aResult.submeshCount; ++i)
{
FbxSurfacePhong* material = FbxSurfacePhong::Create(sdkManager.get(), aResult.submeshMats[i].name);
- material->Diffuse.Set(FbxDouble3(float(rand()) / RAND_MAX , float(rand()) / RAND_MAX, float(rand()) / RAND_MAX));
+ material->Diffuse.Set(FbxDouble3(float(rand()) / RAND_MAX, float(rand()) / RAND_MAX, float(rand()) / RAND_MAX));
material->DiffuseFactor.Set(1.0);
mMaterials.push_back(material);
}
@@ -121,7 +118,7 @@ void FbxFileWriter::createMaterials(const AuthoringResult& aResult)
material->DiffuseFactor.Set(1.0);
mMaterials.push_back(material);
}
- if (mInteriorIndex == -1) // No material setted. Create new one.
+ if (mInteriorIndex == -1) // No material setted. Create new one.
{
FbxSurfacePhong* interiorMat = FbxSurfacePhong::Create(sdkManager.get(), "Interior_Material");
interiorMat->Diffuse.Set(FbxDouble3(1.0, 0.0, 0.5));
@@ -130,10 +127,11 @@ void FbxFileWriter::createMaterials(const AuthoringResult& aResult)
}
else
{
- if (mInteriorIndex < 0) mInteriorIndex = 0;
- if (static_cast<size_t>(mInteriorIndex) >= mMaterials.size()) mInteriorIndex = 0;
+ if (mInteriorIndex < 0)
+ mInteriorIndex = 0;
+ if (static_cast<size_t>(mInteriorIndex) >= mMaterials.size())
+ mInteriorIndex = 0;
}
-
}
@@ -145,7 +143,8 @@ bool FbxFileWriter::appendMesh(const AuthoringResult& aResult, const char* asset
{
return appendNonSkinnedMesh(aResult, assetName);
}
- std::string meshName(assetName); meshName.append("_rendermesh");
+ std::string meshName(assetName);
+ meshName.append("_rendermesh");
FbxMesh* mesh = FbxMesh::Create(sdkManager.get(), meshName.c_str());
@@ -158,20 +157,20 @@ bool FbxFileWriter::appendMesh(const AuthoringResult& aResult, const char* asset
geUV->SetReferenceMode(FbxGeometryElement::eDirect);
FbxGeometryElementSmoothing* smElement = nullptr;
- size_t triangleCount = aResult.geometryOffset[aResult.chunkCount];
+ size_t triangleCount = aResult.geometryOffset[aResult.chunkCount];
for (size_t triangle = 0; triangle < triangleCount; triangle++)
{
if (aResult.geometry[triangle].smoothingGroup >= 0)
{
- //Found a valid smoothing group
+ // Found a valid smoothing group
smElement = mesh->CreateElementSmoothing();
smElement->SetMappingMode(FbxGeometryElement::eByPolygon);
smElement->SetReferenceMode(FbxGeometryElement::eDirect);
break;
}
}
-
+
mesh->InitControlPoints((int)triangleCount * 3);
@@ -188,13 +187,14 @@ bool FbxFileWriter::appendMesh(const AuthoringResult& aResult, const char* asset
FbxNode* lRootNode = mScene->GetRootNode();
- //In order for Maya to correctly convert the axis of a skinned model there must be a common root node between the skeleton and the model
+ // In order for Maya to correctly convert the axis of a skinned model there must be a common root node between the
+ // skeleton and the model
FbxNode* sceneRootNode = FbxNode::Create(sdkManager.get(), "sceneRoot");
lRootNode->AddChild(sceneRootNode);
sceneRootNode->AddChild(meshNode);
- //UE4 cannot hide the root bone, so add a dummy chunk so chunk0 is not the root
- FbxNode* skelRootNode = FbxNode::Create(sdkManager.get(), "root");
+ // UE4 cannot hide the root bone, so add a dummy chunk so chunk0 is not the root
+ FbxNode* skelRootNode = FbxNode::Create(sdkManager.get(), "root");
FbxSkeleton* skelAttrib = FbxSkeleton::Create(sdkManager.get(), "SkelRootAttrib");
skelAttrib->SetSkeletonType(FbxSkeleton::eRoot);
skelRootNode->SetNodeAttribute(skelAttrib);
@@ -204,7 +204,7 @@ bool FbxFileWriter::appendMesh(const AuthoringResult& aResult, const char* asset
FbxSkin* skin = FbxSkin::Create(sdkManager.get(), "Skin of the thing");
skin->SetGeometry(mesh);
mesh->AddDeformer(skin);
-
+
// Add a material otherwise UE4 freaks out on import
FbxGeometryElementMaterial* matElement = mesh->CreateElementMaterial();
@@ -214,7 +214,7 @@ bool FbxFileWriter::appendMesh(const AuthoringResult& aResult, const char* asset
// Now walk the tree and create a skeleton with geometry at the same time
// Find a "root" chunk and walk the tree from there.
uint32_t chunkCount = NvBlastAssetGetChunkCount(aResult.asset, Nv::Blast::logLL);
- auto chunks = NvBlastAssetGetChunks(aResult.asset, Nv::Blast::logLL);
+ auto chunks = NvBlastAssetGetChunks(aResult.asset, Nv::Blast::logLL);
uint32_t cpIdx = 0;
for (uint32_t i = 0; i < chunkCount; i++)
@@ -230,7 +230,7 @@ bool FbxFileWriter::appendMesh(const AuthoringResult& aResult, const char* asset
if (!smElement)
{
- //If no smoothing groups, generate them
+ // If no smoothing groups, generate them
generateSmoothingGroups(mesh, skin);
}
@@ -249,9 +249,9 @@ bool FbxFileWriter::appendNonSkinnedMesh(const AuthoringResult& aResult, const c
{
FbxNode* lRootNode = mScene->GetRootNode();
- //UE4 cannot hide the root bone, so add a dummy chunk so chunk0 is not the root
+ // UE4 cannot hide the root bone, so add a dummy chunk so chunk0 is not the root
FbxNode* skelRootNode = FbxNode::Create(sdkManager.get(), "root");
- //UE4 needs this to be a skeleton node, null node, or mesh node to get used
+ // UE4 needs this to be a skeleton node, null node, or mesh node to get used
FbxNull* nullAttr = FbxNull::Create(sdkManager.get(), "SkelRootAttrib");
skelRootNode->SetNodeAttribute(nullAttr);
lRootNode->AddChild(skelRootNode);
@@ -259,7 +259,7 @@ bool FbxFileWriter::appendNonSkinnedMesh(const AuthoringResult& aResult, const c
// Now walk the tree and create a skeleton with geometry at the same time
// Find a "root" chunk and walk the tree from there.
uint32_t chunkCount = NvBlastAssetGetChunkCount(aResult.asset, Nv::Blast::logLL);
- auto chunks = NvBlastAssetGetChunks(aResult.asset, Nv::Blast::logLL);
+ auto chunks = NvBlastAssetGetChunks(aResult.asset, Nv::Blast::logLL);
for (uint32_t i = 0; i < chunkCount; i++)
{
@@ -284,9 +284,9 @@ bool FbxFileWriter::appendNonSkinnedMesh(const ExporterMeshData& meshData, const
{
FbxNode* lRootNode = mScene->GetRootNode();
- //UE4 cannot hide the root bone, so add a dummy chunk so chunk0 is not the root
+ // UE4 cannot hide the root bone, so add a dummy chunk so chunk0 is not the root
FbxNode* skelRootNode = FbxNode::Create(sdkManager.get(), "root");
- //UE4 needs this to be a skeleton node, null node, or mesh node to get used
+ // UE4 needs this to be a skeleton node, null node, or mesh node to get used
FbxNull* nullAttr = FbxNull::Create(sdkManager.get(), "SkelRootAttrib");
skelRootNode->SetNodeAttribute(nullAttr);
lRootNode->AddChild(skelRootNode);
@@ -313,10 +313,11 @@ bool FbxFileWriter::appendNonSkinnedMesh(const ExporterMeshData& meshData, const
return true;
}
-bool FbxFileWriter::appendCollisionMesh(uint32_t meshCount, uint32_t* offsets, CollisionHull** hulls, const char* assetName)
+bool FbxFileWriter::appendCollisionMesh(uint32_t meshCount, uint32_t* offsets, CollisionHull** hulls,
+ const char* assetName)
{
FbxDisplayLayer* displayLayer = FbxDisplayLayer::Create(mScene, FbxUtils::getCollisionGeometryLayerName().c_str());
- //Hide by default
+ // Hide by default
displayLayer->Show.Set(false);
displayLayer->Color.Set(FbxDouble3(0.0f, 0.0f, 1.0f));
@@ -331,26 +332,27 @@ bool FbxFileWriter::appendCollisionMesh(uint32_t meshCount, uint32_t* offsets, C
std::cerr << "Warning: No chunk node for chunk " << i << ". Ignoring collision geo" << std::endl;
continue;
}
- addCollisionHulls(i, displayLayer, findIt->second, offsets[i+1] - offsets[i], hulls + offsets[i]);
+ addCollisionHulls(i, displayLayer, findIt->second, offsets[i + 1] - offsets[i], hulls + offsets[i]);
}
return true;
}
/*
- Recursive method that creates this chunk and all it's children.
+ Recursive method that creates this chunk and all it's children.
- This creates a FbxNode with an FbxCluster, and all of the geometry for this chunk.
+ This creates a FbxNode with an FbxCluster, and all of the geometry for this chunk.
- Returns the number of added control points
+ Returns the number of added control points
*/
-uint32_t FbxFileWriter::createChunkRecursive(uint32_t currentCpIdx, uint32_t chunkIndex, FbxNode *meshNode, FbxNode* parentNode, FbxSkin* skin, const AuthoringResult& aResult)
+uint32_t FbxFileWriter::createChunkRecursive(uint32_t currentCpIdx, uint32_t chunkIndex, FbxNode* meshNode,
+ FbxNode* parentNode, FbxSkin* skin, const AuthoringResult& aResult)
{
- auto chunks = NvBlastAssetGetChunks(aResult.asset, Nv::Blast::logLL);
+ auto chunks = NvBlastAssetGetChunks(aResult.asset, Nv::Blast::logLL);
const NvBlastChunk* chunk = &chunks[chunkIndex];
- physx::PxVec3 centroid = physx::PxVec3(chunk->centroid[0], chunk->centroid[1], chunk->centroid[2]);
+ NvcVec3 centroid = { chunk->centroid[0], chunk->centroid[1], chunk->centroid[2] };
- //mesh->InitTextureUV(triangles.size() * 3);
+ // mesh->InitTextureUV(triangles.size() * 3);
std::string boneName = FbxUtils::getChunkNodeName(chunkIndex);
@@ -360,7 +362,7 @@ uint32_t FbxFileWriter::createChunkRecursive(uint32_t currentCpIdx, uint32_t chu
skelAttrib->SetSkeletonType(FbxSkeleton::eRoot);
// Change the centroid to origin
- centroid = physx::PxVec3(0.0f);
+ centroid = { 0, 0, 0 };
}
else
{
@@ -368,7 +370,7 @@ uint32_t FbxFileWriter::createChunkRecursive(uint32_t currentCpIdx, uint32_t chu
worldChunkPivots[chunkIndex] = centroid;
}
- skelAttrib->Size.Set(1.0); // What's this for?
+ skelAttrib->Size.Set(1.0); // What's this for?
FbxNode* boneNode = FbxNode::Create(sdkManager.get(), boneName.c_str());
@@ -382,7 +384,7 @@ uint32_t FbxFileWriter::createChunkRecursive(uint32_t currentCpIdx, uint32_t chu
FbxVector4 c2 = mat.MultT(vec);
boneNode->LclTranslation.Set(c2);
-
+
parentNode->AddChild(boneNode);
std::ostringstream namestream;
@@ -398,14 +400,13 @@ uint32_t FbxFileWriter::createChunkRecursive(uint32_t currentCpIdx, uint32_t chu
FbxMesh* mesh = static_cast<FbxMesh*>(meshNode->GetNodeAttribute());
- FbxVector4* controlPoints = mesh->GetControlPoints();
- auto geNormal = mesh->GetElementNormal();
- auto geUV = mesh->GetElementUV("diffuseElement");
+ FbxVector4* controlPoints = mesh->GetControlPoints();
+ auto geNormal = mesh->GetElementNormal();
+ auto geUV = mesh->GetElementUV("diffuseElement");
FbxGeometryElementMaterial* matElement = mesh->GetElementMaterial();
FbxGeometryElementSmoothing* smElement = mesh->GetElementSmoothing();
- auto addVert = [&](Nv::Blast::Vertex vert, int controlPointIdx)
- {
+ auto addVert = [&](Nv::Blast::Vertex vert, int controlPointIdx) {
FbxVector4 vertex;
FbxVector4 normal;
FbxVector2 uv;
@@ -419,7 +420,7 @@ uint32_t FbxFileWriter::createChunkRecursive(uint32_t currentCpIdx, uint32_t chu
cluster->AddControlPointIndex(controlPointIdx, 1.0);
};
- uint32_t cpIdx = 0;
+ uint32_t cpIdx = 0;
uint32_t polyCount = mesh->GetPolygonCount();
for (uint32_t i = aResult.geometryOffset[chunkIndex]; i < aResult.geometryOffset[chunkIndex + 1]; i++)
{
@@ -433,7 +434,9 @@ uint32_t FbxFileWriter::createChunkRecursive(uint32_t currentCpIdx, uint32_t chu
mesh->AddPolygon(currentCpIdx + cpIdx + 1);
mesh->AddPolygon(currentCpIdx + cpIdx + 2);
mesh->EndPolygon();
- int32_t material = (tri.materialId != MATERIAL_INTERIOR) ? ((tri.materialId < int32_t(mMaterials.size())) ? tri.materialId : 0) : ((mInteriorIndex == -1) ? int32_t(mMaterials.size() - 1): mInteriorIndex);
+ int32_t material = (tri.materialId != kMaterialInteriorId) ?
+ ((tri.materialId < int32_t(mMaterials.size())) ? tri.materialId : 0) :
+ ((mInteriorIndex == -1) ? int32_t(mMaterials.size() - 1) : mInteriorIndex);
matElement->GetIndexArray().SetAt(polyCount, material);
if (smElement)
{
@@ -443,21 +446,22 @@ uint32_t FbxFileWriter::createChunkRecursive(uint32_t currentCpIdx, uint32_t chu
}
else
{
- smElement->GetDirectArray().Add(SMOOTHING_GROUP_INTERIOR);
+ smElement->GetDirectArray().Add(kSmoothingGroupInteriorId);
}
}
-
+
polyCount++;
cpIdx += 3;
}
-
+
mat = meshNode->EvaluateGlobalTransform();
cluster->SetTransformMatrix(mat);
mat = boneNode->EvaluateGlobalTransform();
cluster->SetTransformLinkMatrix(mat);
- uint32_t addedCps = static_cast<uint32_t>((aResult.geometryOffset[chunkIndex + 1] - aResult.geometryOffset[chunkIndex]) * 3);
+ uint32_t addedCps =
+ static_cast<uint32_t>((aResult.geometryOffset[chunkIndex + 1] - aResult.geometryOffset[chunkIndex]) * 3);
for (uint32_t i = chunk->firstChildIndex; i < chunk->childIndexStop; i++)
{
@@ -469,11 +473,12 @@ uint32_t FbxFileWriter::createChunkRecursive(uint32_t currentCpIdx, uint32_t chu
void FbxFileWriter::createChunkRecursiveNonSkinned(const std::string& meshName, uint32_t chunkIndex, FbxNode* parentNode,
- const std::vector<FbxSurfaceMaterial*>& materials, const ExporterMeshData& meshData)
+ const std::vector<FbxSurfaceMaterial*>& materials,
+ const ExporterMeshData& meshData)
{
- auto chunks = NvBlastAssetGetChunks(meshData.asset, Nv::Blast::logLL);
+ auto chunks = NvBlastAssetGetChunks(meshData.asset, Nv::Blast::logLL);
const NvBlastChunk* chunk = &chunks[chunkIndex];
- physx::PxVec3 centroid = physx::PxVec3(chunk->centroid[0], chunk->centroid[1], chunk->centroid[2]);
+ NvcVec3 centroid = { chunk->centroid[0], chunk->centroid[1], chunk->centroid[2] };
std::string chunkName = FbxUtils::getChunkNodeName(chunkIndex);
@@ -491,27 +496,27 @@ void FbxFileWriter::createChunkRecursiveNonSkinned(const std::string& meshName,
FbxVector4 c2 = mat.MultT(FbxVector4(centroid.x, centroid.y, centroid.z, 1.0f));
if (chunk->parentChunkIndex != UINT32_MAX)
{
- //Don't mess with the root chunk pivot
+ // Don't mess with the root chunk pivot
meshNode->LclTranslation.Set(c2);
worldChunkPivots[chunkIndex] = centroid;
}
-
+
parentNode->AddChild(meshNode);
FbxAMatrix finalXForm = meshNode->EvaluateGlobalTransform();
- //Set the geo transform to inverse so we can use the world mesh coordinates
+ // Set the geo transform to inverse so we can use the world mesh coordinates
FbxAMatrix invFinalXForm = finalXForm.Inverse();
meshNode->SetGeometricTranslation(FbxNode::eSourcePivot, invFinalXForm.GetT());
meshNode->SetGeometricRotation(FbxNode::eSourcePivot, invFinalXForm.GetR());
meshNode->SetGeometricScaling(FbxNode::eSourcePivot, invFinalXForm.GetS());
auto geNormal = mesh->CreateElementNormal();
- auto geUV = mesh->CreateElementUV("diffuseElement");
- auto matr = mesh->CreateElementMaterial();
+ auto geUV = mesh->CreateElementUV("diffuseElement");
+ auto matr = mesh->CreateElementMaterial();
uint32_t* firstIdx = meshData.submeshOffsets + chunkIndex * meshData.submeshCount;
uint32_t* lastIdx = meshData.submeshOffsets + (chunkIndex + 1) * meshData.submeshCount;
- uint32_t cpCount = *lastIdx - *firstIdx;
+ uint32_t cpCount = *lastIdx - *firstIdx;
mesh->InitControlPoints(cpCount);
geNormal->SetMappingMode(FbxGeometryElement::eByPolygonVertex);
@@ -528,9 +533,9 @@ void FbxFileWriter::createChunkRecursiveNonSkinned(const std::string& meshName,
meshNode->AddMaterial(m);
}
- uint32_t cPolygCount = 0;
+ uint32_t cPolygCount = 0;
int32_t addedVertices = 0;
-
+
for (uint32_t subMesh = 0; subMesh < meshData.submeshCount; ++subMesh)
{
for (uint32_t tr = *(firstIdx + subMesh); tr < *(firstIdx + subMesh + 1); tr += 3)
@@ -541,14 +546,14 @@ void FbxFileWriter::createChunkRecursiveNonSkinned(const std::string& meshName,
mesh->AddPolygon(tr - *firstIdx + k);
FbxVector4 temp;
- FbxUtils::PxVec3ToFbx(meshData.positions[meshData.posIndex[tr + k]], temp);
+ FbxUtils::NvcVec3ToFbx(meshData.positions[meshData.posIndex[tr + k]], temp);
mesh->SetControlPointAt(temp, tr - *firstIdx + k);
- FbxUtils::PxVec3ToFbx(meshData.normals[meshData.normIndex[tr + k]], temp);
+ FbxUtils::NvcVec3ToFbx(meshData.normals[meshData.normIndex[tr + k]], temp);
geNormal->GetDirectArray().Add(temp);
-
+
FbxVector2 temp2;
- FbxUtils::PxVec2ToFbx(meshData.uvs[meshData.texIndex[tr + k]], temp2);
+ FbxUtils::NvcVec2ToFbx(meshData.uvs[meshData.texIndex[tr + k]], temp2);
geUV->GetDirectArray().Add(temp2);
}
mesh->EndPolygon();
@@ -559,7 +564,7 @@ void FbxFileWriter::createChunkRecursiveNonSkinned(const std::string& meshName,
if (!mesh->GetElementSmoothing())
{
- //If no smoothing groups, generate them
+ // If no smoothing groups, generate them
generateSmoothingGroups(mesh, nullptr);
}
@@ -572,11 +577,13 @@ void FbxFileWriter::createChunkRecursiveNonSkinned(const std::string& meshName,
}
-void FbxFileWriter::createChunkRecursiveNonSkinned(const std::string& meshName, uint32_t chunkIndex, FbxNode* parentNode, const std::vector<FbxSurfaceMaterial*>& materials, const AuthoringResult& aResult)
+void FbxFileWriter::createChunkRecursiveNonSkinned(const std::string& meshName, uint32_t chunkIndex, FbxNode* parentNode,
+ const std::vector<FbxSurfaceMaterial*>& materials,
+ const AuthoringResult& aResult)
{
- auto chunks = NvBlastAssetGetChunks(aResult.asset, Nv::Blast::logLL);
+ auto chunks = NvBlastAssetGetChunks(aResult.asset, Nv::Blast::logLL);
const NvBlastChunk* chunk = &chunks[chunkIndex];
- physx::PxVec3 centroid = physx::PxVec3(chunk->centroid[0], chunk->centroid[1], chunk->centroid[2]);
+ NvcVec3 centroid = { chunk->centroid[0], chunk->centroid[1], chunk->centroid[2] };
std::string chunkName = FbxUtils::getChunkNodeName(chunkIndex).c_str();
@@ -595,7 +602,7 @@ void FbxFileWriter::createChunkRecursiveNonSkinned(const std::string& meshName,
if (chunk->parentChunkIndex != UINT32_MAX)
{
- //Don't mess with the root chunk pivot
+ // Don't mess with the root chunk pivot
meshNode->LclTranslation.Set(c2);
worldChunkPivots[chunkIndex] = centroid;
}
@@ -603,7 +610,7 @@ void FbxFileWriter::createChunkRecursiveNonSkinned(const std::string& meshName,
parentNode->AddChild(meshNode);
FbxAMatrix finalXForm = meshNode->EvaluateGlobalTransform();
- //Set the geo transform to inverse so we can use the world mesh coordinates
+ // Set the geo transform to inverse so we can use the world mesh coordinates
FbxAMatrix invFinalXForm = finalXForm.Inverse();
meshNode->SetGeometricTranslation(FbxNode::eSourcePivot, invFinalXForm.GetT());
meshNode->SetGeometricRotation(FbxNode::eSourcePivot, invFinalXForm.GetR());
@@ -611,8 +618,8 @@ void FbxFileWriter::createChunkRecursiveNonSkinned(const std::string& meshName,
auto geNormal = mesh->CreateElementNormal();
- auto geUV = mesh->CreateElementUV("diffuseElement");
- auto matr = mesh->CreateElementMaterial();
+ auto geUV = mesh->CreateElementUV("diffuseElement");
+ auto matr = mesh->CreateElementMaterial();
uint32_t firstIdx = aResult.geometryOffset[chunkIndex];
uint32_t lastIdx = aResult.geometryOffset[chunkIndex + 1];
@@ -622,7 +629,7 @@ void FbxFileWriter::createChunkRecursiveNonSkinned(const std::string& meshName,
{
if (aResult.geometry[triangle].smoothingGroup >= 0)
{
- //Found a valid smoothing group
+ // Found a valid smoothing group
smElement = mesh->CreateElementSmoothing();
smElement->SetMappingMode(FbxGeometryElement::eByPolygon);
smElement->SetReferenceMode(FbxGeometryElement::eDirect);
@@ -647,10 +654,10 @@ void FbxFileWriter::createChunkRecursiveNonSkinned(const std::string& meshName,
}
FbxGeometryElementMaterial* matElement = mesh->GetElementMaterial();
- int32_t polyCount = 0;
+ int32_t polyCount = 0;
for (uint32_t tr = firstIdx; tr < lastIdx; tr++)
{
- auto& geo = aResult.geometry[tr];
+ auto& geo = aResult.geometry[tr];
const Nv::Blast::Vertex triVerts[3] = { geo.a, geo.b, geo.c };
mesh->BeginPolygon();
for (uint32_t k = 0; k < 3; ++k)
@@ -665,7 +672,9 @@ void FbxFileWriter::createChunkRecursiveNonSkinned(const std::string& meshName,
geUV->GetDirectArray().Add(uv);
}
mesh->EndPolygon();
- int32_t material = (geo.materialId != MATERIAL_INTERIOR) ? ((geo.materialId < int32_t(mMaterials.size()))? geo.materialId : 0) : ((mInteriorIndex == -1)? int32_t(mMaterials.size() - 1) : mInteriorIndex);
+ int32_t material = (geo.materialId != kMaterialInteriorId) ?
+ ((geo.materialId < int32_t(mMaterials.size())) ? geo.materialId : 0) :
+ ((mInteriorIndex == -1) ? int32_t(mMaterials.size() - 1) : mInteriorIndex);
matElement->GetIndexArray().SetAt(polyCount, material);
if (smElement)
@@ -676,19 +685,17 @@ void FbxFileWriter::createChunkRecursiveNonSkinned(const std::string& meshName,
}
else
{
- smElement->GetDirectArray().Add(SMOOTHING_GROUP_INTERIOR);
+ smElement->GetDirectArray().Add(kSmoothingGroupInteriorId);
}
}
- polyCount++;
-
+ polyCount++;
}
if (!smElement)
{
- //If no smoothing groups, generate them
+ // If no smoothing groups, generate them
generateSmoothingGroups(mesh, nullptr);
-
}
removeDuplicateControlPoints(mesh, nullptr);
@@ -699,19 +706,20 @@ void FbxFileWriter::createChunkRecursiveNonSkinned(const std::string& meshName,
}
}
-uint32_t FbxFileWriter::addCollisionHulls(uint32_t chunkIndex, FbxDisplayLayer* displayLayer, FbxNode* parentNode, uint32_t hullsCount, CollisionHull** hulls)
+uint32_t FbxFileWriter::addCollisionHulls(uint32_t chunkIndex, FbxDisplayLayer* displayLayer, FbxNode* parentNode,
+ uint32_t hullsCount, CollisionHull** hulls)
{
for (uint32_t hullId = 0; hullId < hullsCount; ++hullId)
{
std::stringstream namestream;
namestream.clear();
- namestream << "collisionHull_" << chunkIndex << "_" << hullId;
+ namestream << "collisionHull_" << chunkIndex << "_" << hullId;
FbxNode* collisionNode = FbxNode::Create(sdkManager.get(), namestream.str().c_str());
displayLayer->AddMember(collisionNode);
- //TODO: Remove this when tools are converted over
+ // TODO: Remove this when tools are converted over
FbxProperty::Create(collisionNode, FbxIntDT, "ParentalChunkIndex");
collisionNode->FindProperty("ParentalChunkIndex").Set(chunkIndex);
//
@@ -721,20 +729,20 @@ uint32_t FbxFileWriter::addCollisionHulls(uint32_t chunkIndex, FbxDisplayLayer*
FbxMesh* meshAttr = FbxMesh::Create(sdkManager.get(), namestream.str().c_str());
collisionNode->SetNodeAttribute(meshAttr);
parentNode->AddChild(collisionNode);
-
- auto mat = parentNode->EvaluateGlobalTransform().Inverse();
+
+ auto mat = parentNode->EvaluateGlobalTransform().Inverse();
auto centroid = worldChunkPivots.find(chunkIndex);
-
+
if (centroid != worldChunkPivots.end())
{
FbxVector4 c2 = mat.MultT(FbxVector4(centroid->second.x, centroid->second.y, centroid->second.z, 1.0f));
- //Don't mess with the root chunk pivot
+ // Don't mess with the root chunk pivot
collisionNode->LclTranslation.Set(c2);
}
parentNode->AddChild(collisionNode);
FbxAMatrix finalXForm = collisionNode->EvaluateGlobalTransform();
- //Set the geo transform to inverse so we can use the world mesh coordinates
+ // Set the geo transform to inverse so we can use the world mesh coordinates
FbxAMatrix invFinalXForm = finalXForm.Inverse();
collisionNode->SetGeometricTranslation(FbxNode::eSourcePivot, invFinalXForm.GetT());
collisionNode->SetGeometricRotation(FbxNode::eSourcePivot, invFinalXForm.GetR());
@@ -744,7 +752,7 @@ uint32_t FbxFileWriter::addCollisionHulls(uint32_t chunkIndex, FbxDisplayLayer*
meshAttr->InitControlPoints(hulls[hullId]->pointsCount);
meshAttr->CreateElementNormal();
FbxVector4* controlPoints = meshAttr->GetControlPoints();
- auto geNormal = meshAttr->GetElementNormal();
+ auto geNormal = meshAttr->GetElementNormal();
geNormal->SetMappingMode(FbxGeometryElement::eByPolygon);
geNormal->SetReferenceMode(FbxGeometryElement::eDirect);
for (uint32_t i = 0; i < hulls[hullId]->pointsCount; ++i)
@@ -758,128 +766,128 @@ uint32_t FbxFileWriter::addCollisionHulls(uint32_t chunkIndex, FbxDisplayLayer*
{
auto& poly = hulls[hullId]->polygonData[i];
meshAttr->BeginPolygon();
- for (uint32_t j = 0; j < poly.mNbVerts; ++j)
- {
- meshAttr->AddPolygon(hulls[hullId]->indices[poly.mIndexBase + j]);
+ for (uint32_t j = 0; j < poly.vertexCount; ++j)
+ {
+ meshAttr->AddPolygon(hulls[hullId]->indices[poly.indexBase + j]);
}
meshAttr->EndPolygon();
- FbxVector4 plane(poly.mPlane[0], poly.mPlane[1], poly.mPlane[2], 0);
+ FbxVector4 plane(poly.plane[0], poly.plane[1], poly.plane[2], 0);
geNormal->GetDirectArray().Add(plane);
- }
- }
+ }
+ }
return 1;
}
-uint32_t FbxFileWriter::createChunkRecursive(uint32_t currentCpIdx, uint32_t chunkIndex, FbxNode *meshNode, FbxNode* parentNode, FbxSkin* skin, const ExporterMeshData& meshData)
+uint32_t FbxFileWriter::createChunkRecursive(uint32_t currentCpIdx, uint32_t chunkIndex, FbxNode* meshNode,
+ FbxNode* parentNode, FbxSkin* skin, const ExporterMeshData& meshData)
{
- auto chunks = NvBlastAssetGetChunks(meshData.asset, Nv::Blast::logLL);
- const NvBlastChunk* chunk = &chunks[chunkIndex];
- physx::PxVec3 centroid = physx::PxVec3(chunk->centroid[0], chunk->centroid[1], chunk->centroid[2]);
+ auto chunks = NvBlastAssetGetChunks(meshData.asset, Nv::Blast::logLL);
+ const NvBlastChunk* chunk = &chunks[chunkIndex];
+ NvcVec3 centroid = { chunk->centroid[0], chunk->centroid[1], chunk->centroid[2] };
- std::string boneName = FbxUtils::getChunkNodeName(chunkIndex).c_str();
+ std::string boneName = FbxUtils::getChunkNodeName(chunkIndex).c_str();
- FbxSkeleton* skelAttrib = FbxSkeleton::Create(sdkManager.get(), boneName.c_str());
- if (chunk->parentChunkIndex == UINT32_MAX)
- {
- skelAttrib->SetSkeletonType(FbxSkeleton::eRoot);
+ FbxSkeleton* skelAttrib = FbxSkeleton::Create(sdkManager.get(), boneName.c_str());
+ if (chunk->parentChunkIndex == UINT32_MAX)
+ {
+ skelAttrib->SetSkeletonType(FbxSkeleton::eRoot);
- // Change the centroid to origin
- centroid = physx::PxVec3(0.0f);
- }
- else
- {
- skelAttrib->SetSkeletonType(FbxSkeleton::eLimbNode);
- worldChunkPivots[chunkIndex] = centroid;
- }
+ // Change the centroid to origin
+ centroid = { 0, 0, 0 };
+ }
+ else
+ {
+ skelAttrib->SetSkeletonType(FbxSkeleton::eLimbNode);
+ worldChunkPivots[chunkIndex] = centroid;
+ }
+
+ FbxNode* boneNode = FbxNode::Create(sdkManager.get(), boneName.c_str());
+ boneNode->SetNodeAttribute(skelAttrib);
- FbxNode* boneNode = FbxNode::Create(sdkManager.get(), boneName.c_str());
- boneNode->SetNodeAttribute(skelAttrib);
+ chunkNodes[chunkIndex] = boneNode;
- chunkNodes[chunkIndex] = boneNode;
-
- auto mat = parentNode->EvaluateGlobalTransform().Inverse();
+ auto mat = parentNode->EvaluateGlobalTransform().Inverse();
- FbxVector4 vec(0, 0, 0, 0);
- FbxVector4 c2 = mat.MultT(vec);
+ FbxVector4 vec(0, 0, 0, 0);
+ FbxVector4 c2 = mat.MultT(vec);
- boneNode->LclTranslation.Set(c2);
+ boneNode->LclTranslation.Set(c2);
- parentNode->AddChild(boneNode);
+ parentNode->AddChild(boneNode);
- std::ostringstream namestream;
- namestream << "cluster_" << std::setw(5) << std::setfill('0') << chunkIndex;
- std::string clusterName = namestream.str();
+ std::ostringstream namestream;
+ namestream << "cluster_" << std::setw(5) << std::setfill('0') << chunkIndex;
+ std::string clusterName = namestream.str();
- FbxCluster* cluster = FbxCluster::Create(sdkManager.get(), clusterName.c_str());
- cluster->SetTransformMatrix(FbxAMatrix());
- cluster->SetLink(boneNode);
- cluster->SetLinkMode(FbxCluster::eTotalOne);
+ FbxCluster* cluster = FbxCluster::Create(sdkManager.get(), clusterName.c_str());
+ cluster->SetTransformMatrix(FbxAMatrix());
+ cluster->SetLink(boneNode);
+ cluster->SetLinkMode(FbxCluster::eTotalOne);
- skin->AddCluster(cluster);
+ skin->AddCluster(cluster);
- FbxMesh* mesh = static_cast<FbxMesh*>(meshNode->GetNodeAttribute());
+ FbxMesh* mesh = static_cast<FbxMesh*>(meshNode->GetNodeAttribute());
- auto geNormal = mesh->GetElementNormal();
- auto geUV = mesh->GetElementUV("diffuseElement");
- auto matr = mesh->GetElementMaterial();
+ auto geNormal = mesh->GetElementNormal();
+ auto geUV = mesh->GetElementUV("diffuseElement");
+ auto matr = mesh->GetElementMaterial();
- std::vector<bool> addedVerticesFlag(mesh->GetControlPointsCount(), false);
+ std::vector<bool> addedVerticesFlag(mesh->GetControlPointsCount(), false);
- uint32_t* firstIdx = meshData.submeshOffsets + chunkIndex * meshData.submeshCount;
- uint32_t cPolygCount = mesh->GetPolygonCount();
- int32_t addedVertices = 0;
- for (uint32_t subMesh = 0; subMesh < meshData.submeshCount; ++subMesh)
- {
- for (uint32_t tr = *(firstIdx + subMesh); tr < *(firstIdx + subMesh + 1); tr += 3)
+ uint32_t* firstIdx = meshData.submeshOffsets + chunkIndex * meshData.submeshCount;
+ uint32_t cPolygCount = mesh->GetPolygonCount();
+ int32_t addedVertices = 0;
+ for (uint32_t subMesh = 0; subMesh < meshData.submeshCount; ++subMesh)
+ {
+ for (uint32_t tr = *(firstIdx + subMesh); tr < *(firstIdx + subMesh + 1); tr += 3)
+ {
+ mesh->BeginPolygon(subMesh);
+ mesh->AddPolygon(meshData.posIndex[tr + 0]);
+ mesh->AddPolygon(meshData.posIndex[tr + 1]);
+ mesh->AddPolygon(meshData.posIndex[tr + 2]);
+ mesh->EndPolygon();
+ for (uint32_t k = 0; k < 3; ++k)
{
- mesh->BeginPolygon(subMesh);
- mesh->AddPolygon(meshData.posIndex[tr + 0]);
- mesh->AddPolygon(meshData.posIndex[tr + 1]);
- mesh->AddPolygon(meshData.posIndex[tr + 2]);
- mesh->EndPolygon();
- for (uint32_t k = 0; k < 3; ++k)
- {
- geNormal->GetIndexArray().SetAt(currentCpIdx + addedVertices + k, meshData.normIndex[tr + k]);
- geUV->GetIndexArray().SetAt(currentCpIdx + addedVertices + k, meshData.texIndex[tr + k]);
- }
- if (subMesh == 0)
- {
- matr->GetIndexArray().SetAt(cPolygCount, 0);
- }
- else
- {
- matr->GetIndexArray().SetAt(cPolygCount, 1);
- }
- cPolygCount++;
- addedVertices += 3;
- for (uint32_t k = 0; k < 3; ++k)
+ geNormal->GetIndexArray().SetAt(currentCpIdx + addedVertices + k, meshData.normIndex[tr + k]);
+ geUV->GetIndexArray().SetAt(currentCpIdx + addedVertices + k, meshData.texIndex[tr + k]);
+ }
+ if (subMesh == 0)
+ {
+ matr->GetIndexArray().SetAt(cPolygCount, 0);
+ }
+ else
+ {
+ matr->GetIndexArray().SetAt(cPolygCount, 1);
+ }
+ cPolygCount++;
+ addedVertices += 3;
+ for (uint32_t k = 0; k < 3; ++k)
+ {
+ if (!addedVerticesFlag[meshData.posIndex[tr + k]])
{
- if (!addedVerticesFlag[meshData.posIndex[tr + k]])
- {
- cluster->AddControlPointIndex(meshData.posIndex[tr + k], 1.0);
- addedVerticesFlag[meshData.posIndex[tr + k]] = true;
- }
+ cluster->AddControlPointIndex(meshData.posIndex[tr + k], 1.0);
+ addedVerticesFlag[meshData.posIndex[tr + k]] = true;
}
}
}
- mat = meshNode->EvaluateGlobalTransform();
- cluster->SetTransformMatrix(mat);
+ }
+ mat = meshNode->EvaluateGlobalTransform();
+ cluster->SetTransformMatrix(mat);
- mat = boneNode->EvaluateGlobalTransform();
- cluster->SetTransformLinkMatrix(mat);
+ mat = boneNode->EvaluateGlobalTransform();
+ cluster->SetTransformLinkMatrix(mat);
- for (uint32_t i = chunk->firstChildIndex; i < chunk->childIndexStop; i++)
- {
- addedVertices += createChunkRecursive(currentCpIdx + addedVertices, i, meshNode, boneNode, skin, meshData);
- }
+ for (uint32_t i = chunk->firstChildIndex; i < chunk->childIndexStop; i++)
+ {
+ addedVertices += createChunkRecursive(currentCpIdx + addedVertices, i, meshNode, boneNode, skin, meshData);
+ }
- return addedVertices;
-
+ return addedVertices;
}
void FbxFileWriter::addControlPoints(FbxMesh* mesh, const ExporterMeshData& meshData)
-{
+{
std::vector<uint32_t> vertices;
std::cout << "Adding control points" << std::endl;
std::vector<int32_t> mapping(meshData.positionsCount, -1);
@@ -889,7 +897,7 @@ void FbxFileWriter::addControlPoints(FbxMesh* mesh, const ExporterMeshData& mesh
for (uint32_t sb = 0; sb < meshData.submeshCount; ++sb)
{
uint32_t* first = meshData.submeshOffsets + ch * meshData.submeshCount + sb;
- for (uint32_t pi = *first; pi < *(first+1); ++pi)
+ for (uint32_t pi = *first; pi < *(first + 1); ++pi)
{
uint32_t p = meshData.posIndex[pi];
if (mapping[p] == -1)
@@ -902,14 +910,14 @@ void FbxFileWriter::addControlPoints(FbxMesh* mesh, const ExporterMeshData& mesh
{
meshData.posIndex[pi] = mapping[p];
}
- }
+ }
}
}
mesh->InitControlPoints((int)vertices.size());
FbxVector4* controlPoints = mesh->GetControlPoints();
for (auto v : vertices)
{
- auto& p = meshData.positions[v];
+ auto& p = meshData.positions[v];
*controlPoints = FbxVector4(p.x, p.y, p.z, 0);
++controlPoints;
}
@@ -919,14 +927,14 @@ void FbxFileWriter::addControlPoints(FbxMesh* mesh, const ExporterMeshData& mesh
void FbxFileWriter::addBindPose()
{
// Store the bind pose
- //Just add all the nodes, it doesn't seem to do any harm and it stops Maya complaining about incomplete bind poses
+ // Just add all the nodes, it doesn't seem to do any harm and it stops Maya complaining about incomplete bind poses
FbxPose* pose = FbxPose::Create(sdkManager.get(), "BindPose");
pose->SetIsBindPose(true);
int nodeCount = mScene->GetNodeCount();
for (int i = 0; i < nodeCount; i++)
{
- FbxNode* node = mScene->GetNode(i);
+ FbxNode* node = mScene->GetNode(i);
FbxMatrix bindMat = node->EvaluateGlobalTransform();
pose->Add(node, bindMat);
@@ -942,11 +950,11 @@ bool FbxFileWriter::saveToFile(const char* assetName, const char* outputPath)
FbxIOSettings* ios = FbxIOSettings::Create(sdkManager.get(), IOSROOT);
// Set some properties on the io settings
-
+
sdkManager->SetIOSettings(ios);
-
+
sdkManager->GetIOSettings()->SetBoolProp(EXP_ASCIIFBX, bOutputFBXAscii);
-
+
FbxExporter* exporter = FbxExporter::Create(sdkManager.get(), "Scene Exporter");
exporter->SetFileExportVersion(FBX_2012_00_COMPATIBLE);
@@ -962,7 +970,7 @@ bool FbxFileWriter::saveToFile(const char* assetName, const char* outputPath)
lFormat = sdkManager->GetIOPluginRegistry()->FindWriterIDByDescription("FBX binary (*.fbx)");
}
- auto path = std::string(outputPath) + "\\" + assetName + ".fbx";
+ auto path = std::string(outputPath) + "\\" + assetName + ".fbx";
bool exportStatus = exporter->Initialize(path.c_str(), lFormat, sdkManager->GetIOSettings());
if (!exportStatus)
@@ -986,7 +994,6 @@ bool FbxFileWriter::saveToFile(const char* assetName, const char* outputPath)
}
-
bool FbxFileWriter::appendMesh(const ExporterMeshData& meshData, const char* assetName, bool nonSkinned)
{
createMaterials(meshData);
@@ -997,7 +1004,7 @@ bool FbxFileWriter::appendMesh(const ExporterMeshData& meshData, const char* ass
}
/**
- Get polygon count
+ Get polygon count
*/
uint32_t polygCount = meshData.submeshOffsets[meshData.meshCount * meshData.submeshCount] / 3;
@@ -1031,7 +1038,7 @@ bool FbxFileWriter::appendMesh(const ExporterMeshData& meshData, const char* ass
mesh->AddDeformer(skin);
/**
- Create control points, copy data to buffers
+ Create control points, copy data to buffers
*/
addControlPoints(mesh, meshData);
@@ -1047,7 +1054,7 @@ bool FbxFileWriter::appendMesh(const ExporterMeshData& meshData, const char* ass
auto& uvs = meshData.uvs[i];
uvsElem->GetDirectArray().Add(FbxVector2(uvs.x, uvs.y));
}
-
+
FbxGeometryElementMaterial* matElement = mesh->CreateElementMaterial();
matElement->SetMappingMode(FbxGeometryElement::eByPolygon);
matElement->SetReferenceMode(FbxGeometryElement::eIndexToDirect);
@@ -1060,13 +1067,14 @@ bool FbxFileWriter::appendMesh(const ExporterMeshData& meshData, const char* ass
std::cout << "Create chunks recursive" << std::endl;
- //In order for Maya to correctly convert the axis of a skinned model there must be a common root node between the skeleton and the model
+ // In order for Maya to correctly convert the axis of a skinned model there must be a common root node between the
+ // skeleton and the model
FbxNode* sceneRootNode = FbxNode::Create(sdkManager.get(), "sceneRoot");
lRootNode->AddChild(sceneRootNode);
sceneRootNode->AddChild(meshNode);
- //UE4 cannot hide the root bone, so add a dummy chunk so chunk0 is not the root
- FbxNode* skelRootNode = FbxNode::Create(sdkManager.get(), "root");
+ // UE4 cannot hide the root bone, so add a dummy chunk so chunk0 is not the root
+ FbxNode* skelRootNode = FbxNode::Create(sdkManager.get(), "root");
FbxSkeleton* skelAttrib = FbxSkeleton::Create(sdkManager.get(), "SkelRootAttrib");
skelAttrib->SetSkeletonType(FbxSkeleton::eRoot);
skelRootNode->SetNodeAttribute(skelAttrib);
@@ -1076,8 +1084,8 @@ bool FbxFileWriter::appendMesh(const ExporterMeshData& meshData, const char* ass
// Now walk the tree and create a skeleton with geometry at the same time
// Find a "root" chunk and walk the tree from there.
uint32_t chunkCount = NvBlastAssetGetChunkCount(meshData.asset, Nv::Blast::logLL);
- auto chunks = NvBlastAssetGetChunks(meshData.asset, Nv::Blast::logLL);
- uint32_t cpIdx = 0;
+ auto chunks = NvBlastAssetGetChunks(meshData.asset, Nv::Blast::logLL);
+ uint32_t cpIdx = 0;
for (uint32_t i = 0; i < chunkCount; i++)
{
const NvBlastChunk* chunk = &chunks[i];
@@ -1091,7 +1099,7 @@ bool FbxFileWriter::appendMesh(const ExporterMeshData& meshData, const char* ass
if (!mesh->GetElementSmoothing())
{
- //If no smoothing groups, generate them
+ // If no smoothing groups, generate them
generateSmoothingGroups(mesh, skin);
}
@@ -1108,27 +1116,28 @@ void FbxFileWriter::generateSmoothingGroups(fbxsdk::FbxMesh* mesh, FbxSkin* skin
{
if (mesh->GetElementSmoothing(0) || !mesh->IsTriangleMesh())
{
- //they already exist or we can't make it
+ // they already exist or we can't make it
return;
}
const FbxGeometryElementNormal* geNormal = mesh->GetElementNormal();
- if (!geNormal || geNormal->GetMappingMode() != FbxGeometryElement::eByPolygonVertex || geNormal->GetReferenceMode() != FbxGeometryElement::eDirect)
+ if (!geNormal || geNormal->GetMappingMode() != FbxGeometryElement::eByPolygonVertex ||
+ geNormal->GetReferenceMode() != FbxGeometryElement::eDirect)
{
- //We just set this up, but just incase
+ // We just set this up, but just incase
return;
}
int clusterCount = 0;
- std::vector<std::vector<int>> cpsPerCluster;
+ std::vector<std::vector<int> > cpsPerCluster;
if (skin)
{
clusterCount = skin->GetClusterCount();
cpsPerCluster.resize(clusterCount);
for (int c = 0; c < clusterCount; c++)
{
- FbxCluster* cluster = skin->GetCluster(c);
- int* clusterCPList = cluster->GetControlPointIndices();
+ FbxCluster* cluster = skin->GetCluster(c);
+ int* clusterCPList = cluster->GetControlPointIndices();
const int clusterCPListLength = cluster->GetControlPointIndicesCount();
cpsPerCluster[c].resize(clusterCPListLength);
@@ -1142,17 +1151,17 @@ void FbxFileWriter::generateSmoothingGroups(fbxsdk::FbxMesh* mesh, FbxSkin* skin
smElement->SetReferenceMode(FbxGeometryElement::eDirect);
FbxVector4* cpList = mesh->GetControlPoints();
- const int cpCount = mesh->GetControlPointsCount();
+ const int cpCount = mesh->GetControlPointsCount();
const int triangleCount = mesh->GetPolygonCount();
- const int cornerCount = triangleCount * 3;
+ const int cornerCount = triangleCount * 3;
- int* polygonCPList = mesh->GetPolygonVertices();
+ int* polygonCPList = mesh->GetPolygonVertices();
const auto& normalByCornerList = geNormal->GetDirectArray();
std::multimap<int, int> overlappingCorners;
- //sort them by z for faster overlap checking
- std::vector<std::pair<double, int>> cornerIndexesByZ(cornerCount);
+ // sort them by z for faster overlap checking
+ std::vector<std::pair<double, int> > cornerIndexesByZ(cornerCount);
for (int c = 0; c < cornerCount; c++)
{
cornerIndexesByZ[c] = std::pair<double, int>(cpList[polygonCPList[c]][2], c);
@@ -1162,9 +1171,9 @@ void FbxFileWriter::generateSmoothingGroups(fbxsdk::FbxMesh* mesh, FbxSkin* skin
for (int i = 0; i < cornerCount; i++)
{
const int cornerA = cornerIndexesByZ[i].second;
- const int cpiA = polygonCPList[cornerA];
- FbxVector4 cpA = cpList[cpiA];
- cpA[3] = 0;
+ const int cpiA = polygonCPList[cornerA];
+ FbxVector4 cpA = cpList[cpiA];
+ cpA[3] = 0;
int clusterIndexA = -1;
for (int c = 0; c < clusterCount; c++)
@@ -1180,15 +1189,15 @@ void FbxFileWriter::generateSmoothingGroups(fbxsdk::FbxMesh* mesh, FbxSkin* skin
{
if (std::abs(cornerIndexesByZ[j].first - cornerIndexesByZ[i].first) > FBXSDK_TOLERANCE)
{
- break; // if the z's don't match other values don't matter
+ break; // if the z's don't match other values don't matter
}
const int cornerB = cornerIndexesByZ[j].second;
- const int cpiB = polygonCPList[cornerB];
- FbxVector4 cpB = cpList[cpiB];
+ const int cpiB = polygonCPList[cornerB];
+ FbxVector4 cpB = cpList[cpiB];
cpB[3] = 0;
- //uses FBXSDK_TOLERANCE
+ // uses FBXSDK_TOLERANCE
if (cpA == cpB)
{
int clusterIndexB = -1;
@@ -1215,7 +1224,7 @@ void FbxFileWriter::generateSmoothingGroups(fbxsdk::FbxMesh* mesh, FbxSkin* skin
{
smoothingGroupByTri.Add(0);
}
- //first one
+ // first one
smoothingGroupByTri.SetAt(0, 1);
for (int i = 1; i < triangleCount; i++)
@@ -1223,16 +1232,16 @@ void FbxFileWriter::generateSmoothingGroups(fbxsdk::FbxMesh* mesh, FbxSkin* skin
int sharedMask = 0, unsharedMask = 0;
for (int c = 0; c < 3; c++)
{
- int myCorner = i * 3 + c;
+ int myCorner = i * 3 + c;
FbxVector4 myNormal = normalByCornerList.GetAt(myCorner);
myNormal.Normalize();
myNormal[3] = 0;
auto otherCornersRangeBegin = overlappingCorners.lower_bound(myCorner);
- auto otherCornersRangeEnd = overlappingCorners.upper_bound(myCorner);
+ auto otherCornersRangeEnd = overlappingCorners.upper_bound(myCorner);
for (auto it = otherCornersRangeBegin; it != otherCornersRangeEnd; it++)
{
- int otherCorner = it->second;
+ int otherCorner = it->second;
FbxVector4 otherNormal = normalByCornerList.GetAt(otherCorner);
otherNormal.Normalize();
otherNormal[3] = 0;
@@ -1247,7 +1256,7 @@ void FbxFileWriter::generateSmoothingGroups(fbxsdk::FbxMesh* mesh, FbxSkin* skin
}
}
- //Easy case, no overlap
+ // Easy case, no overlap
if ((sharedMask & unsharedMask) == 0 && sharedMask != 0)
{
smoothingGroupByTri.SetAt(i, sharedMask);
@@ -1265,63 +1274,62 @@ void FbxFileWriter::generateSmoothingGroups(fbxsdk::FbxMesh* mesh, FbxSkin* skin
}
}
}
-
}
namespace
{
- //These methods have different names for some reason
- inline double* getControlPointBlendWeights(FbxSkin* skin)
- {
- return skin->GetControlPointBlendWeights();
- }
+// These methods have different names for some reason
+inline double* getControlPointBlendWeights(FbxSkin* skin)
+{
+ return skin->GetControlPointBlendWeights();
+}
- inline double* getControlPointBlendWeights(FbxCluster* cluster)
- {
- return cluster->GetControlPointWeights();
- }
+inline double* getControlPointBlendWeights(FbxCluster* cluster)
+{
+ return cluster->GetControlPointWeights();
+}
- template <typename T>
- void remapCPsAndRemoveDuplicates(const int newCPCount, const std::vector<int>& oldToNewCPMapping, T* skinOrCluster)
- {
- //Need to avoid duplicate entires since UE doesn't seem to normalize this correctly
- std::vector<bool> addedCP(newCPCount, false);
- std::vector<std::pair<int, double>> newCPsAndWeights;
- newCPsAndWeights.reserve(newCPCount);
+template <typename T>
+void remapCPsAndRemoveDuplicates(const int newCPCount, const std::vector<int>& oldToNewCPMapping, T* skinOrCluster)
+{
+ // Need to avoid duplicate entires since UE doesn't seem to normalize this correctly
+ std::vector<bool> addedCP(newCPCount, false);
+ std::vector<std::pair<int, double> > newCPsAndWeights;
+ newCPsAndWeights.reserve(newCPCount);
- int* skinCPList = skinOrCluster->GetControlPointIndices();
- double* skinCPWeights = getControlPointBlendWeights(skinOrCluster);
- const int skinCPListLength = skinOrCluster->GetControlPointIndicesCount();
+ int* skinCPList = skinOrCluster->GetControlPointIndices();
+ double* skinCPWeights = getControlPointBlendWeights(skinOrCluster);
+ const int skinCPListLength = skinOrCluster->GetControlPointIndicesCount();
- for (int bw = 0; bw < skinCPListLength; bw++)
- {
- int newCPIdx = oldToNewCPMapping[skinCPList[bw]];
- if (!addedCP[newCPIdx])
- {
- addedCP[newCPIdx] = true;
- newCPsAndWeights.emplace_back(newCPIdx, skinCPWeights[bw]);
- }
- }
- skinOrCluster->SetControlPointIWCount(newCPsAndWeights.size());
- skinCPList = skinOrCluster->GetControlPointIndices();
- skinCPWeights = getControlPointBlendWeights(skinOrCluster);
- for (size_t bw = 0; bw < newCPsAndWeights.size(); bw++)
+ for (int bw = 0; bw < skinCPListLength; bw++)
+ {
+ int newCPIdx = oldToNewCPMapping[skinCPList[bw]];
+ if (!addedCP[newCPIdx])
{
- skinCPList[bw] = newCPsAndWeights[bw].first;
- skinCPWeights[bw] = newCPsAndWeights[bw].second;
+ addedCP[newCPIdx] = true;
+ newCPsAndWeights.emplace_back(newCPIdx, skinCPWeights[bw]);
}
}
+ skinOrCluster->SetControlPointIWCount(newCPsAndWeights.size());
+ skinCPList = skinOrCluster->GetControlPointIndices();
+ skinCPWeights = getControlPointBlendWeights(skinOrCluster);
+ for (size_t bw = 0; bw < newCPsAndWeights.size(); bw++)
+ {
+ skinCPList[bw] = newCPsAndWeights[bw].first;
+ skinCPWeights[bw] = newCPsAndWeights[bw].second;
+ }
}
+} // namespace
-//Do this otherwise Maya shows the mesh as faceted due to not being welded
+// Do this otherwise Maya shows the mesh as faceted due to not being welded
void FbxFileWriter::removeDuplicateControlPoints(fbxsdk::FbxMesh* mesh, FbxSkin* skin)
{
FbxVector4* cpList = mesh->GetControlPoints();
- const int cpCount = mesh->GetControlPointsCount();
+ const int cpCount = mesh->GetControlPointsCount();
std::vector<int> oldToNewCPMapping(cpCount, -1);
- //sort them by z for faster overlap checking
- std::vector<std::pair<double, int>> cpIndexesByZ(cpCount);
+ // sort them by z for faster overlap checking
+ std::vector<std::pair<double, int> > cpIndexesByZ(cpCount);
for (int cp = 0; cp < cpCount; cp++)
{
cpIndexesByZ[cp] = std::pair<double, int>(cpList[cp][2], cp);
@@ -1329,15 +1337,15 @@ void FbxFileWriter::removeDuplicateControlPoints(fbxsdk::FbxMesh* mesh, FbxSkin*
std::sort(cpIndexesByZ.begin(), cpIndexesByZ.end());
int clusterCount = 0;
- std::vector<std::vector<int>> cpsPerCluster;
+ std::vector<std::vector<int> > cpsPerCluster;
if (skin)
{
clusterCount = skin->GetClusterCount();
cpsPerCluster.resize(clusterCount);
for (int c = 0; c < clusterCount; c++)
{
- FbxCluster* cluster = skin->GetCluster(c);
- int* clusterCPList = cluster->GetControlPointIndices();
+ FbxCluster* cluster = skin->GetCluster(c);
+ int* clusterCPList = cluster->GetControlPointIndices();
const int clusterCPListLength = cluster->GetControlPointIndicesCount();
cpsPerCluster[c].resize(clusterCPListLength);
@@ -1355,10 +1363,10 @@ void FbxFileWriter::removeDuplicateControlPoints(fbxsdk::FbxMesh* mesh, FbxSkin*
FbxVector4 cpA = cpList[cpiA];
if (!(oldToNewCPMapping[cpiA] < 0))
{
- //already culled this one
+ // already culled this one
continue;
}
- const int newIdx = int(uniqueCPs.size());
+ const int newIdx = int(uniqueCPs.size());
oldToNewCPMapping[cpiA] = newIdx;
uniqueCPs.push_back(cpA);
@@ -1371,18 +1379,18 @@ void FbxFileWriter::removeDuplicateControlPoints(fbxsdk::FbxMesh* mesh, FbxSkin*
break;
}
}
-
+
for (int j = i + 1; j < cpCount; j++)
{
if (std::abs(cpIndexesByZ[j].first - cpIndexesByZ[i].first) > FBXSDK_TOLERANCE)
{
- break; // if the z's don't match other values don't matter
+ break; // if the z's don't match other values don't matter
}
-
+
const int cpiB = cpIndexesByZ[j].second;
FbxVector4 cpB = cpList[cpiB];
- //uses FBXSDK_TOLERANCE
+ // uses FBXSDK_TOLERANCE
if (cpA == cpB)
{
int clusterIndexB = -1;
@@ -1395,7 +1403,7 @@ void FbxFileWriter::removeDuplicateControlPoints(fbxsdk::FbxMesh* mesh, FbxSkin*
}
}
- //don't merge unless they share the same clusters
+ // don't merge unless they share the same clusters
if (clusterIndexA == clusterIndexB)
{
oldToNewCPMapping[cpiB] = newIdx;
@@ -1405,11 +1413,11 @@ void FbxFileWriter::removeDuplicateControlPoints(fbxsdk::FbxMesh* mesh, FbxSkin*
}
const int originalCPCount = cpCount;
- const int newCPCount = int(uniqueCPs.size());
+ const int newCPCount = int(uniqueCPs.size());
if (newCPCount == cpCount)
{
- //don't bother, it will just scramble it for no reason
+ // don't bother, it will just scramble it for no reason
return;
}
@@ -1421,7 +1429,7 @@ void FbxFileWriter::removeDuplicateControlPoints(fbxsdk::FbxMesh* mesh, FbxSkin*
cpList[cp] = uniqueCPs[cp];
}
- int* polygonCPList = mesh->GetPolygonVertices();
+ int* polygonCPList = mesh->GetPolygonVertices();
const int polygonCPListLength = mesh->GetPolygonVertexCount();
for (int pv = 0; pv < polygonCPListLength; pv++)
{
@@ -1436,6 +1444,5 @@ void FbxFileWriter::removeDuplicateControlPoints(fbxsdk::FbxMesh* mesh, FbxSkin*
FbxCluster* cluster = skin->GetCluster(c);
remapCPsAndRemoveDuplicates(newCPCount, oldToNewCPMapping, cluster);
}
-
}
} \ No newline at end of file
diff --git a/sdk/extensions/exporter/source/NvBlastExtExporterFbxWriter.h b/sdk/extensions/exporter/source/NvBlastExtExporterFbxWriter.h
index 75b4843..ad61fd5 100755
--- a/sdk/extensions/exporter/source/NvBlastExtExporterFbxWriter.h
+++ b/sdk/extensions/exporter/source/NvBlastExtExporterFbxWriter.h
@@ -106,7 +106,7 @@ private:
//TODO we should track for every memory allocation and deallocate it not only for sdkManager
std::shared_ptr<fbxsdk::FbxManager> sdkManager;
std::map<uint32_t, fbxsdk::FbxNode*> chunkNodes;
- std::map<uint32_t, physx::PxVec3> worldChunkPivots;
+ std::map<uint32_t, NvcVec3> worldChunkPivots;
bool appendNonSkinnedMesh(const AuthoringResult& aResult, const char* assetName);
bool appendNonSkinnedMesh(const ExporterMeshData& meshData, const char* assetName);
diff --git a/sdk/extensions/exporter/source/NvBlastExtExporterJsonCollision.cpp b/sdk/extensions/exporter/source/NvBlastExtExporterJsonCollision.cpp
index 7b63461..a9da985 100755
--- a/sdk/extensions/exporter/source/NvBlastExtExporterJsonCollision.cpp
+++ b/sdk/extensions/exporter/source/NvBlastExtExporterJsonCollision.cpp
@@ -39,14 +39,14 @@
using namespace Nv::Blast;
-void serializaHullPolygon(std::ofstream& stream, const CollisionHull::HullPolygon& p, uint32_t indent)
+void serializaHullPolygon(std::ofstream& stream, const HullPolygon& p, uint32_t indent)
{
std::string sindent(indent, '\t');
std::string bindent(indent + 1, '\t');
stream << sindent << "{\n" <<
- bindent << JS_NAME("mIndexBase") << p.mIndexBase << ",\n" <<
- bindent << JS_NAME("mPlane") << "[" << p.mPlane[0] << ", " << p.mPlane[1] << ", " << p.mPlane[2] << ", " << p.mPlane[3] << "],\n" <<
- bindent << JS_NAME("mNbVerts") << p.mNbVerts << "\n" <<
+ bindent << JS_NAME("mIndexBase") << p.indexBase << ",\n" <<
+ bindent << JS_NAME("mPlane") << "[" << p.plane[0] << ", " << p.plane[1] << ", " << p.plane[2] << ", " << p.plane[3] << "],\n" <<
+ bindent << JS_NAME("mNbVerts") << p.vertexCount << "\n" <<
sindent << "}";
}
void serializeCollisionHull(std::ofstream& stream, const CollisionHull& hl, uint32_t indent)
diff --git a/sdk/extensions/exporter/source/NvBlastExtExporterObjReader.cpp b/sdk/extensions/exporter/source/NvBlastExtExporterObjReader.cpp
index d43c1ae..9d44947 100755
--- a/sdk/extensions/exporter/source/NvBlastExtExporterObjReader.cpp
+++ b/sdk/extensions/exporter/source/NvBlastExtExporterObjReader.cpp
@@ -106,17 +106,17 @@ void ObjFileReader::loadFromFile(const char* filename)
auto& psVec = shapes[0].mesh.positions;
for (uint32_t i = 0; i < psVec.size() / 3; ++i)
{
- mVertexPositions.push_back(PxVec3(psVec[i * 3], psVec[i * 3 + 1], psVec[i * 3 + 2]));
+ mVertexPositions.push_back({psVec[i * 3], psVec[i * 3 + 1], psVec[i * 3 + 2]});
}
auto& nmVec = shapes[0].mesh.normals;
for (uint32_t i = 0; i < nmVec.size() / 3; ++i)
{
- mVertexNormals.push_back(PxVec3(nmVec[i * 3], nmVec[i * 3 + 1], nmVec[i * 3 + 2]));
+ mVertexNormals.push_back({nmVec[i * 3], nmVec[i * 3 + 1], nmVec[i * 3 + 2]});
}
auto& txVec = shapes[0].mesh.texcoords;
for (uint32_t i = 0; i < txVec.size() / 2; ++i)
{
- mVertexUv.push_back(PxVec2(txVec[i * 2], txVec[i * 2 + 1]));
+ mVertexUv.push_back({txVec[i * 2], txVec[i * 2 + 1]});
}
mIndices = shapes[0].mesh.indices;
@@ -145,17 +145,17 @@ uint32_t ObjFileReader::getCollision(uint32_t*& hullsOffset, Nv::Blast::Collisio
return 0;
};
-physx::PxVec3* ObjFileReader::getPositionArray()
+NvcVec3* ObjFileReader::getPositionArray()
{
return mVertexPositions.data();
};
-physx::PxVec3* ObjFileReader::getNormalsArray()
+NvcVec3* ObjFileReader::getNormalsArray()
{
return mVertexNormals.data();
};
-physx::PxVec2* ObjFileReader::getUvArray()
+NvcVec2* ObjFileReader::getUvArray()
{
return mVertexUv.data();
};
diff --git a/sdk/extensions/exporter/source/NvBlastExtExporterObjReader.h b/sdk/extensions/exporter/source/NvBlastExtExporterObjReader.h
index 7657be3..0f3e843 100755
--- a/sdk/extensions/exporter/source/NvBlastExtExporterObjReader.h
+++ b/sdk/extensions/exporter/source/NvBlastExtExporterObjReader.h
@@ -75,15 +75,15 @@ public:
/**
Get loaded vertex positions
*/
- virtual physx::PxVec3* getPositionArray() override;
+ virtual NvcVec3* getPositionArray() override;
/**
Get loaded vertex normals
*/
- virtual physx::PxVec3* getNormalsArray() override;
+ virtual NvcVec3* getNormalsArray() override;
/**
Get loaded vertex uv-coordinates
*/
- virtual physx::PxVec2* getUvArray() override;
+ virtual NvcVec2* getUvArray() override;
/**
Get loaded triangle indices
*/
@@ -110,9 +110,9 @@ public:
int32_t getMaterialCount() { return mMaterialNames.size(); };
private:
- std::vector<physx::PxVec3> mVertexPositions;
- std::vector<physx::PxVec3> mVertexNormals;
- std::vector<physx::PxVec2> mVertexUv;
+ std::vector<NvcVec3> mVertexPositions;
+ std::vector<NvcVec3> mVertexNormals;
+ std::vector<NvcVec2> mVertexUv;
std::vector<uint32_t> mIndices;
std::vector<std::string> mMaterialNames;
diff --git a/sdk/extensions/exporter/source/NvBlastExtExporterObjWriter.cpp b/sdk/extensions/exporter/source/NvBlastExtExporterObjWriter.cpp
index e6ec276..3cd8c62 100755
--- a/sdk/extensions/exporter/source/NvBlastExtExporterObjWriter.cpp
+++ b/sdk/extensions/exporter/source/NvBlastExtExporterObjWriter.cpp
@@ -103,9 +103,9 @@ bool ObjFileWriter::appendMesh(const AuthoringResult& aResult, const char* /*ass
md.positionsCount = triCount * 3;
md.normalsCount = md.positionsCount;
md.uvsCount = md.positionsCount;
- md.positions = new PxVec3[md.positionsCount];
- md.normals = new PxVec3[md.normalsCount];
- md.uvs = new PxVec2[md.uvsCount];
+ md.positions = new NvcVec3[md.positionsCount];
+ md.normals = new NvcVec3[md.normalsCount];
+ md.uvs = new NvcVec2[md.uvsCount];
md.posIndex = new uint32_t[triCount * 3];
md.normIndex = md.posIndex;
@@ -132,7 +132,7 @@ bool ObjFileWriter::appendMesh(const AuthoringResult& aResult, const char* /*ass
{
sorted.push_back(aResult.geometry[t]);
int32_t cmat = sorted.back().materialId;
- if (cmat == MATERIAL_INTERIOR)
+ if (cmat == kMaterialInteriorId)
{
cmat = mIntSurfaceMatIndex;
}