Browse Source

Added option to ColladaLoader to recenter all Geometry so that they are centered around the local origin of their containing Mesh.

Erik Kitson 13 years ago
parent
commit
fe8e1b881f
2 changed files with 14 additions and 0 deletions
  1. 2 0
      src/extras/GeometryUtils.js
  2. 12 0
      src/extras/loaders/ColladaLoader.js

+ 2 - 0
src/extras/GeometryUtils.js

@@ -488,6 +488,8 @@ THREE.GeometryUtils = {
 
 
 		geometry.computeBoundingBox();
 		geometry.computeBoundingBox();
 
 
+		return new THREE.Vector3( dx, dy, dz );
+
 	}
 	}
 
 
 
 

+ 12 - 0
src/extras/loaders/ColladaLoader.js

@@ -28,6 +28,10 @@ THREE.ColladaLoader = function () {
 	var preferredShading = THREE.SmoothShading;
 	var preferredShading = THREE.SmoothShading;
 
 
 	var options = {
 	var options = {
+		// Force Geometry to always be centered at the local origin of the
+		// containing Mesh.
+		centerGeometry: false,
+
 		// Axis conversion is done for geometries, animations, and controllers.
 		// Axis conversion is done for geometries, animations, and controllers.
 		// If we ever pull cameras or lights out of the COLLADA file, they'll
 		// If we ever pull cameras or lights out of the COLLADA file, they'll
 		// need extra work.
 		// need extra work.
@@ -795,6 +799,14 @@ THREE.ColladaLoader = function () {
 		obj.useQuaternion = true;
 		obj.useQuaternion = true;
 		obj.scale = props[ 2 ];
 		obj.scale = props[ 2 ];
 
 
+		if ( options.centerGeometry && obj.geometry ) {
+
+			var delta = THREE.GeometryUtils.center( obj.geometry );
+			obj.quaternion.multiplyVector3( delta.multiplySelf( obj.scale ) );
+			obj.position.subSelf( delta );
+
+		}
+
 		for ( i = 0; i < node.nodes.length; i ++ ) {
 		for ( i = 0; i < node.nodes.length; i ++ ) {
 
 
 			obj.add( createSceneGraph( node.nodes[i], node ) );
 			obj.add( createSceneGraph( node.nodes[i], node ) );