Matthias Mullie has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/390274 )

Change subject: Improve camera rotation & initial position
......................................................................

Improve camera rotation & initial position

Bug: T179887
Change-Id: Iff721b17c407785635cf4fbb02dbbdef340a34e8
---
M modules/mmv.3d.js
1 file changed, 15 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/3D 
refs/changes/74/390274/1

diff --git a/modules/mmv.3d.js b/modules/mmv.3d.js
index 4d2e0ec..9b73ab9 100644
--- a/modules/mmv.3d.js
+++ b/modules/mmv.3d.js
@@ -65,23 +65,27 @@
        };
 
        TD.center = function ( object ) {
-               var bbox, bboxWidth, bboxHeight, bboxDepth,
-                       camerax, cameray, cameraz;
+               var radius;
+
                if ( object.type === 'Group' ) {
                        this.center( object.children[ 0 ] );
                } else if ( object.type === 'Mesh' ) {
                        object.geometry.center();
-                       object.geometry.computeBoundingBox();
+                       object.geometry.computeBoundingSphere();
 
-                       bbox = object.geometry.boundingBox;
-                       bboxWidth = bbox.max.x - bbox.min.x;
-                       bboxHeight = bbox.max.z - bbox.min.z;
-                       bboxDepth = bbox.max.y - bbox.min.y;
-                       camerax = -bboxWidth;
-                       cameray = -bboxDepth;
-                       cameraz = bboxHeight;
+                       radius = object.geometry.boundingSphere.radius;
 
-                       this.camera.position.set( camerax, cameray, cameraz );
+                       // `radius` is the edge of the object's sphere
+                       // We want to position our camera outside of that 
sphere.
+                       // We'll move `radius` (or more) in all directions (x, 
y, z), so that we're
+                       // looking at the object somewhat diagonally, which 
should always show something
+                       // useful (instead of possibly an uninteresting side or 
top...)
+                       // The exact position of the camera was arbitrarily 
decided by what looked
+                       // alright-ish for a few files I was testing with.
+                       // sketchfab.com has this at ( 0, -distance, 0 )
+                       // viewstl.com has this at ( 0, 0 distance )
+                       // openjscad.org has this at ( 0, -distance, distance )
+                       this.camera.position.set( radius * 1.5, -radius * 1.5, 
radius );
                }
        };
 

-- 
To view, visit https://gerrit.wikimedia.org/r/390274
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iff721b17c407785635cf4fbb02dbbdef340a34e8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/3D
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to