Browse Source

Merge remote-tracking branch 'AddictArts/dev_collada' into dev

Mr.doob 13 years ago
parent
commit
a640e74c70
2 changed files with 31 additions and 1 deletions
  1. 2 0
      src/extras/GeometryUtils.js
  2. 29 1
      src/extras/loaders/ColladaLoader.js

+ 2 - 0
src/extras/GeometryUtils.js

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

+ 29 - 1
src/extras/loaders/ColladaLoader.js

@@ -28,6 +28,10 @@ THREE.ColladaLoader = function () {
 	var preferredShading = THREE.SmoothShading;
 
 	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.
 		// If we ever pull cameras or lights out of the COLLADA file, they'll
 		// need extra work.
@@ -45,7 +49,9 @@ THREE.ColladaLoader = function () {
 
 	var TO_RADIANS = Math.PI / 180;
 
-	function load ( url, readyCallback ) {
+	function load ( url, readyCallback, progressCallback ) {
+
+		var length = 0;
 
 		if ( document.implementation && document.implementation.createDocument ) {
 
@@ -79,6 +85,20 @@ THREE.ColladaLoader = function () {
 
 					}
 
+				} else if ( req.readyState == 3 ) {
+
+					if ( progressCallback ) {
+
+						if ( length == 0 ) {
+
+							length = req.getResponseHeader( "Content-Length" );
+
+						}
+
+						progressCallback( { total: length, loaded: req.responseText.length } );
+
+					}
+
 				}
 
 			}
@@ -795,6 +815,14 @@ THREE.ColladaLoader = function () {
 		obj.useQuaternion = true;
 		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 ++ ) {
 
 			obj.add( createSceneGraph( node.nodes[i], node ) );