mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 08:34:40 +00:00
final commit get this merged
This commit is contained in:
parent
13a6df35cc
commit
4a1d664b6a
7 changed files with 122 additions and 31 deletions
|
|
@ -23,7 +23,6 @@
|
||||||
#include "platform/platform.h"
|
#include "platform/platform.h"
|
||||||
#include "ts/collada/colladaExtensions.h"
|
#include "ts/collada/colladaExtensions.h"
|
||||||
#include "ts/assimp/assimpAppMesh.h"
|
#include "ts/assimp/assimpAppMesh.h"
|
||||||
#include "ts/assimp/assimpAppNode.h"
|
|
||||||
|
|
||||||
// assimp include files.
|
// assimp include files.
|
||||||
#include <assimp/cimport.h>
|
#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)
|
AssimpAppMesh::AssimpAppMesh(const struct aiMesh* mesh, AssimpAppNode* node)
|
||||||
: mMeshData(mesh), appNode(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
|
// See if it's a skinned mesh
|
||||||
mIsSkinMesh = false;
|
mIsSkinMesh = false;
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,8 @@ protected:
|
||||||
static S32 fixedSize; ///< The fixed detail size value for all geometry
|
static S32 fixedSize; ///< The fixed detail size value for all geometry
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void computeBounds(Box3F& bounds) override;
|
||||||
|
TSMesh* constructTSMesh() override;
|
||||||
|
|
||||||
AssimpAppMesh(const struct aiMesh* mesh, AssimpAppNode* node);
|
AssimpAppMesh(const struct aiMesh* mesh, AssimpAppNode* node);
|
||||||
~AssimpAppMesh()
|
~AssimpAppMesh()
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
#include "platform/platform.h"
|
#include "platform/platform.h"
|
||||||
#include "ts/loader/appSequence.h"
|
#include "ts/loader/appSequence.h"
|
||||||
#include "ts/assimp/assimpAppNode.h"
|
#include "ts/assimp/assimpAppNode.h"
|
||||||
|
#include "ts/assimp/assimpAppMesh.h"
|
||||||
|
|
||||||
// assimp include files.
|
// assimp include files.
|
||||||
#include <assimp/cimport.h>
|
#include <assimp/cimport.h>
|
||||||
|
|
|
||||||
|
|
@ -32,14 +32,14 @@
|
||||||
#ifndef _COLLADA_EXTENSIONS_H_
|
#ifndef _COLLADA_EXTENSIONS_H_
|
||||||
#include "ts/collada/colladaExtensions.h"
|
#include "ts/collada/colladaExtensions.h"
|
||||||
#endif
|
#endif
|
||||||
#ifndef _ASSIMP_APPMESH_H_
|
|
||||||
#include "ts/assimp/assimpAppMesh.h"
|
|
||||||
#endif
|
|
||||||
#ifndef AI_TYPES_H_INC
|
#ifndef AI_TYPES_H_INC
|
||||||
#include <assimp/types.h>
|
#include <assimp/types.h>
|
||||||
#endif
|
#endif
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
|
|
||||||
|
class AssimpAppMesh;
|
||||||
|
|
||||||
class AssimpAppNode : public AppNode
|
class AssimpAppNode : public AppNode
|
||||||
{
|
{
|
||||||
typedef AppNode Parent;
|
typedef AppNode Parent;
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,15 @@ void applyTransformation(aiNode* node, const aiMatrix4x4& transform) {
|
||||||
node->mTransformation = transform * node->mTransformation; // Apply transformation to the node
|
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) {
|
void scaleScene(const aiScene* scene, F32 scaleFactor) {
|
||||||
aiMatrix4x4 scaleMatrix;
|
aiMatrix4x4 scaleMatrix;
|
||||||
scaleMatrix = aiMatrix4x4::Scaling(aiVector3D(scaleFactor, scaleFactor, scaleFactor), scaleMatrix);
|
scaleMatrix = aiMatrix4x4::Scaling(aiVector3D(scaleFactor, scaleFactor, scaleFactor), scaleMatrix);
|
||||||
|
|
@ -270,26 +279,10 @@ void AssimpShapeLoader::enumerateScene()
|
||||||
// Setup LOD checks
|
// Setup LOD checks
|
||||||
detectDetails();
|
detectDetails();
|
||||||
|
|
||||||
|
aiMatrix4x4 sceneRoot = aiMatrix4x4(1, 0, 0, 0,
|
||||||
aiMatrix4x4 sceneRoot;
|
0, 0, -1, 0,
|
||||||
|
0, 1, 0, 0,
|
||||||
if (ColladaUtils::getOptions().upAxis == UPAXISTYPE_X_UP) {
|
0, 0, 0, 1);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
applyTransformation(mScene->mRootNode, sceneRoot);
|
applyTransformation(mScene->mRootNode, sceneRoot);
|
||||||
|
|
||||||
|
|
@ -305,7 +298,7 @@ void AssimpShapeLoader::enumerateScene()
|
||||||
if (!boundsNode) {
|
if (!boundsNode) {
|
||||||
aiNode* reqNode = new aiNode("bounds");
|
aiNode* reqNode = new aiNode("bounds");
|
||||||
mScene->mRootNode->addChildren(1, &reqNode);
|
mScene->mRootNode->addChildren(1, &reqNode);
|
||||||
//reqNode->mTransformation = mScene->mRootNode->mTransformation;
|
reqNode->mTransformation = aiMatrix4x4();// *sceneRoot;
|
||||||
AssimpAppNode* appBoundsNode = new AssimpAppNode(mScene, reqNode);
|
AssimpAppNode* appBoundsNode = new AssimpAppNode(mScene, reqNode);
|
||||||
if (!processNode(appBoundsNode)) {
|
if (!processNode(appBoundsNode)) {
|
||||||
delete appBoundsNode;
|
delete appBoundsNode;
|
||||||
|
|
|
||||||
|
|
@ -74,11 +74,11 @@ public:
|
||||||
AppMesh();
|
AppMesh();
|
||||||
virtual ~AppMesh();
|
virtual ~AppMesh();
|
||||||
|
|
||||||
void computeBounds(Box3F& bounds);
|
virtual void computeBounds(Box3F& bounds);
|
||||||
void computeNormals();
|
void computeNormals();
|
||||||
|
|
||||||
// Create a TSMesh object
|
// Create a TSMesh object
|
||||||
TSMesh* constructTSMesh();
|
virtual TSMesh* constructTSMesh();
|
||||||
|
|
||||||
virtual const char * getName(bool allowFixed=true) = 0;
|
virtual const char * getName(bool allowFixed=true) = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -252,7 +252,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
U32 mMeshType;
|
U32 mMeshType;
|
||||||
Box3F mBounds;
|
|
||||||
Point3F mCenter;
|
Point3F mCenter;
|
||||||
F32 mRadius;
|
F32 mRadius;
|
||||||
F32 mVisibility;
|
F32 mVisibility;
|
||||||
|
|
@ -272,7 +272,7 @@ public:
|
||||||
S32 numFrames;
|
S32 numFrames;
|
||||||
S32 numMatFrames;
|
S32 numMatFrames;
|
||||||
S32 vertsPerFrame;
|
S32 vertsPerFrame;
|
||||||
|
Box3F mBounds;
|
||||||
U32 mVertOffset;
|
U32 mVertOffset;
|
||||||
U32 mVertSize;
|
U32 mVertSize;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue