Переглянути джерело

Added boundingSphere to BufferGeometryLoader/BufferGeometryExporter.

Mr.doob 12 роки тому
батько
коміт
7a17974cc6

+ 18 - 5
examples/js/exporters/BufferGeometryExporter.js

@@ -16,12 +16,17 @@ THREE.BufferGeometryExporter.prototype = {
 				type: 'BufferGeometry',
 				generator: 'BufferGeometryExporter'
 			},
-			attributes: {}
+			attributes: {
+			}
 		};
 
-		for ( var key in geometry.attributes ) {
+		var attributes = geometry.attributes;
+		var offsets = geometry.offsets;
+		var boundingSphere = geometry.boundingSphere;
+
+		for ( var key in attributes ) {
 
-			var attribute = geometry.attributes[ key ];
+			var attribute = attributes[ key ];
 
 			output.attributes[ key ] = {
 				itemSize: attribute.itemSize,
@@ -31,9 +36,17 @@ THREE.BufferGeometryExporter.prototype = {
 
 		}
 
-		if ( geometry.offsets.length > 0 ) {
+		if ( offsets.length > 0 ) {
 
-			output.offsets = JSON.parse( JSON.stringify( geometry.offsets ) );
+			output.offsets = JSON.parse( JSON.stringify( offsets ) );
+
+		}
+
+		if ( boundingSphere !== null ) {
+
+			output.boundingSphere = {
+				radius: boundingSphere.radius
+			}
 
 		}
 

+ 15 - 4
src/loaders/BufferGeometryLoader.js

@@ -36,9 +36,14 @@ THREE.BufferGeometryLoader.prototype = {
 
 		var geometry = new THREE.BufferGeometry();
 
-		for ( var key in json.attributes ) {
+		var attributes = json.attributes;
+		var offsets = json.offsets;
+		var boundingSphere = json.boundingSphere;
+
+		for ( var key in attributes ) {
+
+			var attribute = attributes[ key ];
 
-			var attribute = json.attributes[ key ];
 			geometry.attributes[ key ] = {
 				itemSize: attribute.itemSize,
 				array: new self[ attribute.type ]( attribute.array )
@@ -46,9 +51,15 @@ THREE.BufferGeometryLoader.prototype = {
 
 		}
 
-		if ( json.offsets !== undefined ) {
+		if ( offsets !== undefined ) {
+
+			geometry.offsets = JSON.parse( JSON.stringify( offsets ) );
+
+		}
+
+		if ( boundingSphere !== undefined ) {
 
-			geometry.offsets = JSON.parse( JSON.stringify( json.offsets ) );
+			geometry.boundingSphere = new THREE.Sphere( undefined, boundingSphere.radius );
 
 		}