Browse Source

Make BoxHelper workable with Object3D

gero3 10 years ago
parent
commit
0ce00ce80e
2 changed files with 27 additions and 12 deletions
  1. 4 0
      examples/webgl_helpers.html
  2. 23 12
      src/extras/helpers/BoxHelper.js

+ 4 - 0
examples/webgl_helpers.html

@@ -84,6 +84,10 @@
 					line.material.transparent = true;
 					line.position.x = -4;
 					group.add( line );
+					
+					scene.add( new THREE.BoxHelper( group ) );
+					scene.add( new THREE.BoxHelper( scene ) );
+					
 
 				} );
 

+ 23 - 12
src/extras/helpers/BoxHelper.js

@@ -22,17 +22,31 @@ THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
 
 THREE.BoxHelper.prototype.update = function ( object ) {
 
-	var geometry = object.geometry;
-
-	if ( geometry.boundingBox === null ) {
-
-		geometry.computeBoundingBox();
-
+	var min, max;
+	 if ( object.type == 'Mesh') {
+		
+		var geometry = object.geometry;
+		
+		if ( geometry.boundingBox === null ) {
+			
+			geometry.computeBoundingBox();
+			
+		}
+		
+		min = geometry.boundingBox.min;
+		max = geometry.boundingBox.max;
+		
+		this.matrix = object.matrixWorld;
+		this.matrixAutoUpdate = false;
+		
+	} else {
+		
+		var box = new THREE.Box3().setFromObject(object);
+		min = box.min;
+		max = box.max;
+		
 	}
 
-	var min = geometry.boundingBox.min;
-	var max = geometry.boundingBox.max;
-
 	/*
 	  5____4
 	1/___0/|
@@ -95,7 +109,4 @@ THREE.BoxHelper.prototype.update = function ( object ) {
 
 	this.geometry.computeBoundingSphere();
 
-	this.matrix = object.matrixWorld;
-	this.matrixAutoUpdate = false;
-
 };