final commit get this merged

This commit is contained in:
marauder2k7 2024-12-12 14:32:20 +00:00
parent 13a6df35cc
commit 4a1d664b6a
7 changed files with 122 additions and 31 deletions

View file

@ -23,7 +23,6 @@
#include "platform/platform.h"
#include "ts/collada/colladaExtensions.h"
#include "ts/assimp/assimpAppMesh.h"
#include "ts/assimp/assimpAppNode.h"
// assimp include files.
#include <assimp/cimport.h>
@ -36,10 +35,107 @@ S32 AssimpAppMesh::fixedSize = 2;
//------------------------------------------------------------------------------
void AssimpAppMesh::computeBounds(Box3F& bounds)
{
bounds = Box3F::Invalid;
if (isSkin())
{
// Compute bounds for skinned mesh
Vector<MatrixF> boneTransforms;
boneTransforms.setSize(nodeIndex.size());
// Calculate bone transformations
for (S32 iBone = 0; iBone < boneTransforms.size(); iBone++) {
MatrixF nodeMat = bones[iBone]->getNodeTransform(TSShapeLoader::DefaultTime);
TSShapeLoader::zapScale(nodeMat); // Remove scaling to ensure uniform transformation
boneTransforms[iBone].mul(nodeMat, initialTransforms[iBone]);
}
// Transform vertices using weighted bone transformations
Vector<Point3F> transformedVerts;
transformedVerts.setSize(initialVerts.size());
transformedVerts.fill(Point3F::Zero);
for (S32 iWeight = 0; iWeight < vertexIndex.size(); iWeight++) {
const S32 vertIndex = vertexIndex[iWeight];
const MatrixF& deltaTransform = boneTransforms[boneIndex[iWeight]];
Point3F weightedVert;
deltaTransform.mulP(initialVerts[vertIndex], &weightedVert);
weightedVert *= weight[iWeight];
transformedVerts[vertIndex] += weightedVert;
}
// Extend bounds using the transformed vertices
for (const auto& vert : transformedVerts) {
bounds.extend(vert);
}
}
else
{
MatrixF transform = getMeshTransform(TSShapeLoader::DefaultTime);
TSShapeLoader::zapScale(transform);
for (S32 iVert = 0; iVert < points.size(); iVert++)
{
Point3F p;
transform.mulP(points[iVert], &p);
bounds.extend(p);
}
}
}
TSMesh* AssimpAppMesh::constructTSMesh()
{
TSMesh* tsmesh;
if (isSkin())
{
TSSkinMesh* tsskin = new TSSkinMesh();
tsmesh = tsskin;
// Copy skin elements
tsskin->weight = weight;
tsskin->boneIndex = boneIndex;
tsskin->vertexIndex = vertexIndex;
tsskin->batchData.nodeIndex = nodeIndex;
tsskin->batchData.initialTransforms = initialTransforms;
tsskin->batchData.initialVerts = initialVerts;
tsskin->batchData.initialNorms = initialNorms;
}
else
{
tsmesh = new TSMesh();
}
// Copy mesh elements
tsmesh->mVerts = points;
tsmesh->mNorms = normals;
tsmesh->mTverts = uvs;
tsmesh->mPrimitives = primitives;
tsmesh->mIndices = indices;
tsmesh->mColors = colors;
tsmesh->mTverts2 = uv2s;
// Finish initializing the shape
computeBounds(tsmesh->mBounds);
tsmesh->setFlags(flags);
tsmesh->updateMeshFlags();
//tsmesh->computeBounds();
tsmesh->numFrames = numFrames;
tsmesh->numMatFrames = numMatFrames;
tsmesh->vertsPerFrame = vertsPerFrame;
tsmesh->createTangents(tsmesh->mVerts, tsmesh->mNorms);
tsmesh->mEncodedNorms.set(NULL, 0);
return tsmesh;
}
AssimpAppMesh::AssimpAppMesh(const struct aiMesh* mesh, AssimpAppNode* node)
: mMeshData(mesh), appNode(node)
{
Con::printf("[ASSIMP] Mesh Created: %s", getName());
Con::printf("[ASSIMP] Mesh Created: %s for Node: %s", getName(), node->getName());
// See if it's a skinned mesh
mIsSkinMesh = false;