@@ -1672,7 +1672,7 @@ void MeshSystem::createTorus(MeshComponent& mesh, float radius, float ringRadius
16721672 mesh.needReload = true ;
16731673}
16741674
1675- bool MeshSystem::loadGLTF (Entity entity, const std::string filename, bool asyncLoad, bool skipEntities){
1675+ bool MeshSystem::loadGLTF (Entity entity, const std::string filename, bool asyncLoad, bool skipEntities, bool changeRootTransform ){
16761676 MeshComponent& mesh = scene->getComponent <MeshComponent>(entity);
16771677 ModelComponent& model = scene->getComponent <ModelComponent>(entity);
16781678 Transform& transform = scene->getComponent <Transform>(entity);
@@ -1764,13 +1764,27 @@ bool MeshSystem::loadGLTF(Entity entity, const std::string filename, bool asyncL
17641764 }
17651765 }
17661766
1767- // Only apply the GLTF root transform when the entity still has the default transform.
17681767 Matrix4 matrix = getGLTFMeshGlobalMatrix (meshNode, model, nodesParent);
1769- bool hasDefaultTransform = (transform.position == Vector3::ZERO)
1770- && (transform.rotation == Quaternion::IDENTITY)
1771- && (transform.scale == Vector3::UNIT_SCALE);
1772- if (hasDefaultTransform) {
1773- matrix.decompose (transform.position , transform.scale , transform.rotation );
1768+
1769+ if (changeRootTransform) {
1770+ bool hasDefaultPosition = (transform.position == Vector3::ZERO);
1771+ bool hasDefaultRotation = (transform.rotation == Quaternion::IDENTITY);
1772+ bool hasDefaultScale = (transform.scale == Vector3::UNIT_SCALE);
1773+
1774+ Vector3 newPosition;
1775+ Vector3 newScale;
1776+ Quaternion newRotation;
1777+ matrix.decompose (newPosition, newScale, newRotation);
1778+
1779+ if (hasDefaultPosition) {
1780+ transform.position = newPosition;
1781+ }
1782+ if (hasDefaultRotation) {
1783+ transform.rotation = newRotation;
1784+ }
1785+ if (hasDefaultScale) {
1786+ transform.scale = newScale;
1787+ }
17741788 transform.needUpdate = true ;
17751789 }
17761790
@@ -2786,7 +2800,7 @@ bool MeshSystem::createOrUpdateModel(Entity entity, ModelComponent& model, MeshC
27862800 if (ext == " obj" ){
27872801 ret = loadOBJ (entity, model.filename , false );
27882802 }else {
2789- ret = loadGLTF (entity, model.filename , false , skipEntities);
2803+ ret = loadGLTF (entity, model.filename , false , skipEntities, false );
27902804 }
27912805
27922806 if (ret){
0 commit comments