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;

View file

@ -46,6 +46,8 @@ protected:
static S32 fixedSize; ///< The fixed detail size value for all geometry
public:
void computeBounds(Box3F& bounds) override;
TSMesh* constructTSMesh() override;
AssimpAppMesh(const struct aiMesh* mesh, AssimpAppNode* node);
~AssimpAppMesh()

View file

@ -23,7 +23,7 @@
#include "platform/platform.h"
#include "ts/loader/appSequence.h"
#include "ts/assimp/assimpAppNode.h"
#include "ts/assimp/assimpAppMesh.h"
// assimp include files.
#include <assimp/cimport.h>

View file

@ -32,14 +32,14 @@
#ifndef _COLLADA_EXTENSIONS_H_
#include "ts/collada/colladaExtensions.h"
#endif
#ifndef _ASSIMP_APPMESH_H_
#include "ts/assimp/assimpAppMesh.h"
#endif
#ifndef AI_TYPES_H_INC
#include <assimp/types.h>
#endif
#include <assimp/scene.h>
class AssimpAppMesh;
class AssimpAppNode : public AppNode
{
typedef AppNode Parent;

View file

@ -128,6 +128,15 @@ void applyTransformation(aiNode* node, const aiMatrix4x4& transform) {
node->mTransformation = transform * node->mTransformation; // Apply transformation to the node
}
void applyRootTransformation(aiNode* node, const aiMatrix4x4& transform) {
node->mTransformation = transform * node->mTransformation; // Apply transformation to the node
// Recursively apply to all child nodes
for (unsigned int i = 0; i < node->mNumChildren; ++i) {
applyRootTransformation(node->mChildren[i], transform);
}
}
void scaleScene(const aiScene* scene, F32 scaleFactor) {
aiMatrix4x4 scaleMatrix;
scaleMatrix = aiMatrix4x4::Scaling(aiVector3D(scaleFactor, scaleFactor, scaleFactor), scaleMatrix);
@ -270,26 +279,10 @@ void AssimpShapeLoader::enumerateScene()
// Setup LOD checks
detectDetails();
aiMatrix4x4 sceneRoot;
if (ColladaUtils::getOptions().upAxis == UPAXISTYPE_X_UP) {
sceneRoot = aiMatrix4x4(1, 0, 0, 0,
0, 0, 1, 0,
0, 1, 0, 0,
0, 0, 0, 1);
}
if (ColladaUtils::getOptions().upAxis == UPAXISTYPE_Z_UP) {
sceneRoot = aiMatrix4x4(1, 0, 0, 0,
0, 0, -1, 0,
0, 1, 0, 0,
0, 0, 0, 1);
}
if (ColladaUtils::getOptions().upAxis == UPAXISTYPE_Y_UP) {
sceneRoot = aiMatrix4x4::RotationX(AI_MATH_PI / 2, sceneRoot);
}
aiMatrix4x4 sceneRoot = aiMatrix4x4(1, 0, 0, 0,
0, 0, -1, 0,
0, 1, 0, 0,
0, 0, 0, 1);
applyTransformation(mScene->mRootNode, sceneRoot);
@ -305,7 +298,7 @@ void AssimpShapeLoader::enumerateScene()
if (!boundsNode) {
aiNode* reqNode = new aiNode("bounds");
mScene->mRootNode->addChildren(1, &reqNode);
//reqNode->mTransformation = mScene->mRootNode->mTransformation;
reqNode->mTransformation = aiMatrix4x4();// *sceneRoot;
AssimpAppNode* appBoundsNode = new AssimpAppNode(mScene, reqNode);
if (!processNode(appBoundsNode)) {
delete appBoundsNode;

View file

@ -74,11 +74,11 @@ public:
AppMesh();
virtual ~AppMesh();
void computeBounds(Box3F& bounds);
virtual void computeBounds(Box3F& bounds);
void computeNormals();
// Create a TSMesh object
TSMesh* constructTSMesh();
virtual TSMesh* constructTSMesh();
virtual const char * getName(bool allowFixed=true) = 0;

View file

@ -252,7 +252,7 @@ public:
protected:
U32 mMeshType;
Box3F mBounds;
Point3F mCenter;
F32 mRadius;
F32 mVisibility;
@ -272,7 +272,7 @@ public:
S32 numFrames;
S32 numMatFrames;
S32 vertsPerFrame;
Box3F mBounds;
U32 mVertOffset;
U32 mVertSize;