Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/core/BufferGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -1299,10 +1299,7 @@ class BufferGeometry extends EventDispatcher {

if ( boundingSphere !== null ) {

data.data.boundingSphere = {
center: boundingSphere.center.toArray(),
radius: boundingSphere.radius
};
data.data.boundingSphere = boundingSphere.toJSON();

}

Expand Down
10 changes: 2 additions & 8 deletions src/core/Object3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -1297,10 +1297,7 @@ class Object3D extends EventDispatcher {
object.geometryInfo = this._geometryInfo.map( info => ( {
...info,
boundingBox: info.boundingBox ? info.boundingBox.toJSON() : undefined,
boundingSphere: info.boundingSphere ? {
radius: info.boundingSphere.radius,
center: info.boundingSphere.center.toArray()
} : undefined
boundingSphere: info.boundingSphere ? info.boundingSphere.toJSON() : undefined
} ) );
object.instanceInfo = this._instanceInfo.map( info => ( { ...info } ) );

Expand Down Expand Up @@ -1329,10 +1326,7 @@ class Object3D extends EventDispatcher {

if ( this.boundingSphere !== null ) {

object.boundingSphere = {
center: this.boundingSphere.center.toArray(),
radius: this.boundingSphere.radius
};
object.boundingSphere = this.boundingSphere.toJSON();

}

Expand Down
11 changes: 1 addition & 10 deletions src/loaders/BufferGeometryLoader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Sphere } from '../math/Sphere.js';
import { Vector3 } from '../math/Vector3.js';
import { BufferAttribute } from '../core/BufferAttribute.js';
import { BufferGeometry } from '../core/BufferGeometry.js';
import { FileLoader } from './FileLoader.js';
Expand Down Expand Up @@ -227,15 +226,7 @@ class BufferGeometryLoader extends Loader {

if ( boundingSphere !== undefined ) {

const center = new Vector3();

if ( boundingSphere.center !== undefined ) {

center.fromArray( boundingSphere.center );

}

geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
geometry.boundingSphere = new Sphere().fromJSON( boundingSphere );

}

Expand Down
8 changes: 2 additions & 6 deletions src/loaders/ObjectLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -985,9 +985,7 @@ class ObjectLoader extends Loader {

if ( info.boundingSphere !== undefined ) {

sphere = new Sphere();
sphere.radius = info.boundingSphere.radius;
sphere.center.fromArray( info.boundingSphere.center );
sphere = new Sphere().fromJSON( info.boundingSphere );

}

Expand Down Expand Up @@ -1025,9 +1023,7 @@ class ObjectLoader extends Loader {

if ( data.boundingSphere !== undefined ) {

object.boundingSphere = new Sphere();
object.boundingSphere.center.fromArray( data.boundingSphere.center );
object.boundingSphere.radius = data.boundingSphere.radius;
object.boundingSphere = new Sphere().fromJSON( data.boundingSphere );

}

Expand Down
28 changes: 28 additions & 0 deletions src/math/Sphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,34 @@ class Sphere {

}

/**
* Returns a serialized structure of the bounding sphere.
*
* @return {Object} Serialized structure with fields representing the object state.
*/
toJSON() {

return {
radius: this.radius,
center: this.center.toArray()
};

}

/**
* Returns a serialized structure of the bounding sphere.
*
* @param {Object} json - The serialized json to set the sphere from.
* @return {Box3} A reference to this bounding sphere.
*/
fromJSON( json ) {

this.radius = json.radius;
this.center.fromArray( json.center );
return this;

}

}

export { Sphere };