From c104a1200c1bb7db6468cc6f51f764f4c0b50540 Mon Sep 17 00:00:00 2001
From: Sandro Weber <webers@in.tum.de>
Date: Tue, 10 Nov 2020 18:25:36 +0000
Subject: [PATCH] Merged in NUIT-221-some-models-dont-show-up (pull request
 #43)

[NUIT-221] mirrored frontend changes

* [NUIT-221] mirrored frontend changes

Approved-by: Manos Angelidis
Approved-by: Antoine Detailleur
---
 gz3d/build/gz3d.js  | 22 ++++++++++++++--------
 gz3d/src/gziface.js |  7 ++++++-
 gz3d/src/gzscene.js | 15 ++++++++-------
 3 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/gz3d/build/gz3d.js b/gz3d/build/gz3d.js
index 89e3571..ac836ba 100644
--- a/gz3d/build/gz3d.js
+++ b/gz3d/build/gz3d.js
@@ -5925,6 +5925,11 @@ GZ3D.GZIface.prototype.createGeom = function(
           parent.scale.y = geom.mesh.scale.y;
           parent.scale.z = geom.mesh.scale.z;
         }
+        
+        // After updating ColladaLoader to support v1.4.1 specs, most models turned to their sides (rotation incorrect).
+        // This is a quick fix. Would need further investigation to see if something is being missed on load,
+        // e.g. the new loader supplies additional info for collada scenes that we fail to apply here
+        parent.quaternion.premultiply(new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(1,0,0), Math.PI / 2));
 
         var modelUri = uriPath + '/' + modelName;
         var modelCacheKey = modelUri;
@@ -5960,7 +5965,7 @@ GZ3D.GZIface.prototype.createGeom = function(
 
           // HBP Change (Luc): we assume that all requested collada files are
           // are web-compliant
-          if (modelUri.indexOf('.dae') !== -1) {
+          if (modelUri.indexOf('.dae') !== -1 || modelUri.indexOf('.DAE') !== -1) {
             var materialName = parent.name + '::' + element.url;
 
             that.scene.loadMesh(
@@ -11156,7 +11161,7 @@ GZ3D.Scene.prototype.loadMesh = function(
   var uriPath = uri.substring(0, uri.lastIndexOf('/'));
   var uriFile = uri.substring(uri.lastIndexOf('/') + 1);
 
-  // load urdf model
+  // load collada model
   if (uriFile.substr(-4).toLowerCase() === '.dae') {
     return this.loadCollada(
       uri,
@@ -11165,7 +11170,9 @@ GZ3D.Scene.prototype.loadMesh = function(
       callback,
       progressCallback
     );
-  } else if (uriFile.substr(-5).toLowerCase() === '.urdf') {
+  }
+  // load urdf model
+  else if (uriFile.substr(-5).toLowerCase() === '.urdf') {
     /*var urdfModel = new ROSLIB.UrdfModel({
       string : uri
     });
@@ -11241,11 +11248,10 @@ GZ3D.Scene.prototype.loadCollada = function(
     uri,
     function(collada) {
       // check for a scale factor
-      /*if(collada.dae.asset.unit)
-    {
-      var scale = collada.dae.asset.unit;
-      collada.scene.scale = new THREE.Vector3(scale, scale, scale);
-    }*/
+      /*if(collada.dae.asset.unit) {
+        var scale = collada.dae.asset.unit;
+        collada.scene.scale = new THREE.Vector3(scale, scale, scale);
+      }*/
 
       dae = collada.scene;
       dae.updateMatrix();
diff --git a/gz3d/src/gziface.js b/gz3d/src/gziface.js
index 9b4ddc8..b428761 100644
--- a/gz3d/src/gziface.js
+++ b/gz3d/src/gziface.js
@@ -1411,6 +1411,11 @@ GZ3D.GZIface.prototype.createGeom = function(
           parent.scale.y = geom.mesh.scale.y;
           parent.scale.z = geom.mesh.scale.z;
         }
+        
+        // After updating ColladaLoader to support v1.4.1 specs, most models turned to their sides (rotation incorrect).
+        // This is a quick fix. Would need further investigation to see if something is being missed on load,
+        // e.g. the new loader supplies additional info for collada scenes that we fail to apply here
+        parent.quaternion.premultiply(new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(1,0,0), Math.PI / 2));
 
         var modelUri = uriPath + '/' + modelName;
         var modelCacheKey = modelUri;
@@ -1446,7 +1451,7 @@ GZ3D.GZIface.prototype.createGeom = function(
 
           // HBP Change (Luc): we assume that all requested collada files are
           // are web-compliant
-          if (modelUri.indexOf('.dae') !== -1) {
+          if (modelUri.indexOf('.dae') !== -1 || modelUri.indexOf('.DAE') !== -1) {
             var materialName = parent.name + '::' + element.url;
 
             that.scene.loadMesh(
diff --git a/gz3d/src/gzscene.js b/gz3d/src/gzscene.js
index fe4b18f..dff1dc7 100644
--- a/gz3d/src/gzscene.js
+++ b/gz3d/src/gzscene.js
@@ -1667,7 +1667,7 @@ GZ3D.Scene.prototype.loadMesh = function(
   var uriPath = uri.substring(0, uri.lastIndexOf('/'));
   var uriFile = uri.substring(uri.lastIndexOf('/') + 1);
 
-  // load urdf model
+  // load collada model
   if (uriFile.substr(-4).toLowerCase() === '.dae') {
     return this.loadCollada(
       uri,
@@ -1676,7 +1676,9 @@ GZ3D.Scene.prototype.loadMesh = function(
       callback,
       progressCallback
     );
-  } else if (uriFile.substr(-5).toLowerCase() === '.urdf') {
+  }
+  // load urdf model
+  else if (uriFile.substr(-5).toLowerCase() === '.urdf') {
     /*var urdfModel = new ROSLIB.UrdfModel({
       string : uri
     });
@@ -1752,11 +1754,10 @@ GZ3D.Scene.prototype.loadCollada = function(
     uri,
     function(collada) {
       // check for a scale factor
-      /*if(collada.dae.asset.unit)
-    {
-      var scale = collada.dae.asset.unit;
-      collada.scene.scale = new THREE.Vector3(scale, scale, scale);
-    }*/
+      /*if(collada.dae.asset.unit) {
+        var scale = collada.dae.asset.unit;
+        collada.scene.scale = new THREE.Vector3(scale, scale, scale);
+      }*/
 
       dae = collada.scene;
       dae.updateMatrix();
-- 
GitLab