mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 08:04:40 +00:00
dont autoconfig up axis set it explicitly for the formats
This commit is contained in:
parent
28fcb8d68b
commit
5beef47b23
3 changed files with 30 additions and 56 deletions
|
|
@ -96,7 +96,9 @@ MatrixF AssimpAppNode::getTransform(F32 time)
|
||||||
{
|
{
|
||||||
// Check if we can use the last computed transform
|
// Check if we can use the last computed transform
|
||||||
if (time == mLastTransformTime)
|
if (time == mLastTransformTime)
|
||||||
|
{
|
||||||
return mLastTransform;
|
return mLastTransform;
|
||||||
|
}
|
||||||
|
|
||||||
if (appParent) {
|
if (appParent) {
|
||||||
// Get parent node's transform
|
// Get parent node's transform
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,16 @@ void AssimpShapeLoader::releaseImport()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void applyTransformation(aiNode* node, const aiMatrix4x4& transform) {
|
||||||
|
node->mTransformation = transform * node->mTransformation; // Apply transformation to the node
|
||||||
|
}
|
||||||
|
|
||||||
|
void scaleScene(const aiScene* scene, float scaleFactor) {
|
||||||
|
aiMatrix4x4 scaleMatrix;
|
||||||
|
scaleMatrix = aiMatrix4x4::Scaling(aiVector3D(scaleFactor, scaleFactor, scaleFactor), scaleMatrix);
|
||||||
|
applyTransformation(scene->mRootNode, scaleMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
void debugSceneMetaData(const aiScene* scene) {
|
void debugSceneMetaData(const aiScene* scene) {
|
||||||
if (!scene->mMetaData) {
|
if (!scene->mMetaData) {
|
||||||
Con::printf("[ASSIMP] No metadata available.");
|
Con::printf("[ASSIMP] No metadata available.");
|
||||||
|
|
@ -166,49 +176,15 @@ void debugSceneMetaData(const aiScene* scene) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void applyTransformation(aiNode* node, const aiMatrix4x4& transform) {
|
|
||||||
node->mTransformation = transform * node->mTransformation; // Apply transformation to the node
|
|
||||||
}
|
|
||||||
|
|
||||||
void reorientGLTFScene(const aiScene* scene) {
|
|
||||||
aiMatrix4x4 rotationMatrix;
|
|
||||||
rotationMatrix = aiMatrix4x4::RotationX(AI_MATH_PI / 2, rotationMatrix); // Rotate -90 degrees around X-axis
|
|
||||||
|
|
||||||
applyTransformation(scene->mRootNode, rotationMatrix);
|
|
||||||
|
|
||||||
rotationMatrix = aiMatrix4x4::RotationZ(AI_MATH_PI, rotationMatrix); // Rotate -90 degrees around X-axis
|
|
||||||
applyTransformation(scene->mRootNode, rotationMatrix);
|
|
||||||
}
|
|
||||||
|
|
||||||
float getUnitScaleFactor(const aiScene* scene) {
|
|
||||||
float scale = 1.0f;
|
|
||||||
|
|
||||||
if (scene->mMetaData) {
|
|
||||||
double unitScaleFactor;
|
|
||||||
if (scene->mMetaData->Get("UnitScaleFactor", unitScaleFactor)) {
|
|
||||||
scale = static_cast<float>(unitScaleFactor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
void scaleScene(const aiScene* scene, float scaleFactor) {
|
|
||||||
aiMatrix4x4 scaleMatrix;
|
|
||||||
scaleMatrix = aiMatrix4x4::Scaling(aiVector3D(scaleFactor, scaleFactor, scaleFactor), scaleMatrix);
|
|
||||||
applyTransformation(scene->mRootNode, scaleMatrix);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AssimpShapeLoader::enumerateScene()
|
void AssimpShapeLoader::enumerateScene()
|
||||||
{
|
{
|
||||||
TSShapeLoader::updateProgress(TSShapeLoader::Load_ReadFile, "Reading File");
|
TSShapeLoader::updateProgress(TSShapeLoader::Load_ReadFile, "Reading File");
|
||||||
Con::printf("[ASSIMP] Attempting to load file: %s", shapePath.getFullPath().c_str());
|
Con::printf("[ASSIMP] Attempting to load file: %s", shapePath.getFullPath().c_str());
|
||||||
|
|
||||||
// Define post-processing steps
|
// Define post-processing steps
|
||||||
unsigned int ppsteps = aiProcess_Triangulate | aiProcess_ValidateDataStructure | aiProcess_MakeLeftHanded | aiProcess_FlipUVs;
|
unsigned int ppsteps = aiProcess_Triangulate | aiProcess_ConvertToLeftHanded & ~aiProcess_FlipWindingOrder;
|
||||||
|
|
||||||
const auto& options = ColladaUtils::getOptions();
|
const auto& options = ColladaUtils::getOptions();
|
||||||
if (options.convertLeftHanded) ppsteps |= aiProcess_MakeLeftHanded;
|
|
||||||
if (options.reverseWindingOrder) ppsteps |= aiProcess_FlipWindingOrder;
|
if (options.reverseWindingOrder) ppsteps |= aiProcess_FlipWindingOrder;
|
||||||
if (options.calcTangentSpace) ppsteps |= aiProcess_CalcTangentSpace;
|
if (options.calcTangentSpace) ppsteps |= aiProcess_CalcTangentSpace;
|
||||||
if (options.joinIdenticalVerts) ppsteps |= aiProcess_JoinIdenticalVertices;
|
if (options.joinIdenticalVerts) ppsteps |= aiProcess_JoinIdenticalVertices;
|
||||||
|
|
@ -245,22 +221,28 @@ void AssimpShapeLoader::enumerateScene()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//debugSceneMetaData(mScene);
|
|
||||||
|
|
||||||
Con::printf("[ASSIMP] Mesh Count: %d", mScene->mNumMeshes);
|
Con::printf("[ASSIMP] Mesh Count: %d", mScene->mNumMeshes);
|
||||||
Con::printf("[ASSIMP] Material Count: %d", mScene->mNumMaterials);
|
Con::printf("[ASSIMP] Material Count: %d", mScene->mNumMaterials);
|
||||||
|
|
||||||
|
#ifdef TORQUE_DEBUG
|
||||||
|
debugSceneMetaData(mScene);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ColladaUtils::getOptions().upAxis = UPAXISTYPE_Y_UP; // default to Y up for assimp.
|
||||||
|
// Handle scaling
|
||||||
|
configureImportUnits();
|
||||||
|
|
||||||
// Format-specific adjustments
|
// Format-specific adjustments
|
||||||
String fileExt = String::ToLower(shapePath.getExtension());
|
String fileExt = String::ToLower(shapePath.getExtension());
|
||||||
const aiImporterDesc* importerDescription = aiGetImporterDesc(fileExt.c_str());
|
const aiImporterDesc* importerDescription = aiGetImporterDesc(fileExt.c_str());
|
||||||
if (fileExt == String::ToString("gltf") || fileExt == String::ToString("glb")) {
|
if (fileExt == String::ToString("gltf") || fileExt == String::ToString("glb")) {
|
||||||
Con::printf("[ASSIMP] Detected GLTF format, applying reorientation...");
|
Con::printf("[ASSIMP] Detected GLTF format, applying reorientation...");
|
||||||
reorientGLTFScene(mScene); // Reorient GLTF
|
ColladaUtils::getOptions().upAxis = UPAXISTYPE_X_UP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (importerDescription && dStrcmp(importerDescription->mName, "Autodesk FBX Importer") == 0) {
|
if (importerDescription && dStrcmp(importerDescription->mName, "Autodesk FBX Importer") == 0) {
|
||||||
Con::printf("[ASSIMP] Detected FBX format, checking unit scale...");
|
Con::printf("[ASSIMP] Detected FBX format, checking unit scale...");
|
||||||
F32 scaleFactor = getUnitScaleFactor(mScene);
|
F32 scaleFactor = ColladaUtils::getOptions().unit;
|
||||||
if (scaleFactor != 1.0f) {
|
if (scaleFactor != 1.0f) {
|
||||||
Con::printf("[ASSIMP] Applying FBX scale factor: %f", scaleFactor);
|
Con::printf("[ASSIMP] Applying FBX scale factor: %f", scaleFactor);
|
||||||
scaleScene(mScene, scaleFactor);
|
scaleScene(mScene, scaleFactor);
|
||||||
|
|
@ -269,10 +251,9 @@ void AssimpShapeLoader::enumerateScene()
|
||||||
{
|
{
|
||||||
scaleScene(mScene, 0.01f);
|
scaleScene(mScene, 0.01f);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Handle scaling and up-axis conversions if necessary
|
ColladaUtils::getOptions().upAxis = UPAXISTYPE_Y_UP;
|
||||||
configureImportUnitsAndAxis();
|
}
|
||||||
|
|
||||||
// Extract embedded textures
|
// Extract embedded textures
|
||||||
for (unsigned int i = 0; i < mScene->mNumTextures; ++i) {
|
for (unsigned int i = 0; i < mScene->mNumTextures; ++i) {
|
||||||
|
|
@ -296,11 +277,10 @@ void AssimpShapeLoader::enumerateScene()
|
||||||
|
|
||||||
// Add a bounds node if none exists
|
// Add a bounds node if none exists
|
||||||
if (!boundsNode) {
|
if (!boundsNode) {
|
||||||
aiNode* req[1];
|
auto* reqNode = new aiNode("bounds");
|
||||||
req[0] = new aiNode("bounds");
|
mScene->mRootNode->addChildren(1, &reqNode);
|
||||||
mScene->mRootNode->addChildren(1, req);
|
|
||||||
|
|
||||||
auto* appBoundsNode = new AssimpAppNode(mScene, req[0]);
|
auto* appBoundsNode = new AssimpAppNode(mScene, reqNode);
|
||||||
if (!processNode(appBoundsNode)) {
|
if (!processNode(appBoundsNode)) {
|
||||||
delete appBoundsNode;
|
delete appBoundsNode;
|
||||||
}
|
}
|
||||||
|
|
@ -313,7 +293,7 @@ void AssimpShapeLoader::enumerateScene()
|
||||||
aiDetachLogStream(&shapeLog);
|
aiDetachLogStream(&shapeLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssimpShapeLoader::configureImportUnitsAndAxis() {
|
void AssimpShapeLoader::configureImportUnits() {
|
||||||
auto& options = ColladaUtils::getOptions();
|
auto& options = ColladaUtils::getOptions();
|
||||||
|
|
||||||
// Configure unit scaling
|
// Configure unit scaling
|
||||||
|
|
@ -331,14 +311,6 @@ void AssimpShapeLoader::configureImportUnitsAndAxis() {
|
||||||
}
|
}
|
||||||
options.unit = static_cast<float>(unitScaleFactor);
|
options.unit = static_cast<float>(unitScaleFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure up-axis
|
|
||||||
if (options.upAxis == UPAXISTYPE_COUNT) {
|
|
||||||
int upAxis = UPAXISTYPE_Z_UP;
|
|
||||||
if (getMetaInt("UpAxis", upAxis)) {
|
|
||||||
options.upAxis = static_cast<domUpAxisType>(upAxis);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssimpShapeLoader::processAnimations()
|
void AssimpShapeLoader::processAnimations()
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ public:
|
||||||
|
|
||||||
void releaseImport();
|
void releaseImport();
|
||||||
void enumerateScene() override;
|
void enumerateScene() override;
|
||||||
void configureImportUnitsAndAxis();
|
void configureImportUnits();
|
||||||
void updateMaterialsScript(const Torque::Path &path);
|
void updateMaterialsScript(const Torque::Path &path);
|
||||||
void processAnimations();
|
void processAnimations();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue