Reputation: 653
I'm working on upgrading threejs to the latest version in an existing project where an older 0.120.0 version threejs is being used. But, ColladaLoader.js and OrbitControls.js files are being locally maintained (most probably even older version, don't know which). The ThreeJS was upgraded but nobody upgraded the ColladaLoader and OrbitControls.
As part of the upgrade, I upgraded threejs to 0.155.0 and stopped using the local copies in favor of three/examples/jsm/loaders/ColladaLoader.js
and three/examples/jsm/controls/OrbitControls.js
Some models are showing up wrongly oriented after the upgrade. There's no longer colladaLoader.options.convertUpAxis = true
supported. ColladaLoader says Up axis is converted automatically.
but there's issue with few models after upgrade.
Here are the before and after screenshots of the model
Before upgrade (expected view)
Not all models have this issue. So, whatever fix is needed for this shouldn't mess with other models. How do I re-orient it to show as expected?
Here is how it looks in blender(dae import). I do not have the original model file. These models have been existing long before I joined.
I've tried setting camera's up axis but it doesn't quite work. Even if it works for this model, it will cause issue with other models.
UPDATE 1:
On further investigation, I've observed that we need the model to be facing in a certain position and to achieve this, there's some rotation (config.rotation
) that is being given to the collada scene (collada.scene.rotation.y = config.rotation;
). This is messing with the up axis fix ColladaLoader is doing.
if ( asset.upAxis === 'Z_UP' ) {
scene.quaternion.setFromEuler( new Euler( - Math.PI / 2, 0, 0 ));
}
If the collada model has Z_UP, I want to apply the config.rotation
by using new Euler(-Math.PI/2, 0, config.rotation);
, otherwise new Euler(0, config.rotation, 0);
.
But how do I know if the collada xml has 'Z_UP' or 'Y_UP'? ColladaLoader parse method doesn't return this information. I don't want to override or maintain a updated local copy of the ColladaLoader.js
Upvotes: 1
Views: 75
Reputation: 653
If the quaternion has x value set, then it means that Z_UP has been converted to Y_UP.
Based on this, I set
if(scene.quaternion && scene.quaternion.x !== 0) {
scene.rotation.z = config.rotation;
} else {
scene.rotation.y = config.rotation;
}
This resolved the issue. Any other suggestions or better solutions are welcome though!
Upvotes: 0