File tree 5 files changed +34
-28
lines changed
5 files changed +34
-28
lines changed Original file line number Diff line number Diff line change @@ -1299,10 +1299,7 @@ class BufferGeometry extends EventDispatcher {
1299
1299
1300
1300
if ( boundingSphere !== null ) {
1301
1301
1302
- data . data . boundingSphere = {
1303
- center : boundingSphere . center . toArray ( ) ,
1304
- radius : boundingSphere . radius
1305
- } ;
1302
+ data . data . boundingSphere = boundingSphere . toJSON ( ) ;
1306
1303
1307
1304
}
1308
1305
Original file line number Diff line number Diff line change @@ -1297,10 +1297,7 @@ class Object3D extends EventDispatcher {
1297
1297
object . geometryInfo = this . _geometryInfo . map ( info => ( {
1298
1298
...info ,
1299
1299
boundingBox : info . boundingBox ? info . boundingBox . toJSON ( ) : undefined ,
1300
- boundingSphere : info . boundingSphere ? {
1301
- radius : info . boundingSphere . radius ,
1302
- center : info . boundingSphere . center . toArray ( )
1303
- } : undefined
1300
+ boundingSphere : info . boundingSphere ? info . boundingSphere . toJSON ( ) : undefined
1304
1301
} ) ) ;
1305
1302
object . instanceInfo = this . _instanceInfo . map ( info => ( { ...info } ) ) ;
1306
1303
@@ -1329,10 +1326,7 @@ class Object3D extends EventDispatcher {
1329
1326
1330
1327
if ( this . boundingSphere !== null ) {
1331
1328
1332
- object . boundingSphere = {
1333
- center : this . boundingSphere . center . toArray ( ) ,
1334
- radius : this . boundingSphere . radius
1335
- } ;
1329
+ object . boundingSphere = this . boundingSphere . toJSON ( ) ;
1336
1330
1337
1331
}
1338
1332
Original file line number Diff line number Diff line change 1
1
import { Sphere } from '../math/Sphere.js' ;
2
- import { Vector3 } from '../math/Vector3.js' ;
3
2
import { BufferAttribute } from '../core/BufferAttribute.js' ;
4
3
import { BufferGeometry } from '../core/BufferGeometry.js' ;
5
4
import { FileLoader } from './FileLoader.js' ;
@@ -227,15 +226,7 @@ class BufferGeometryLoader extends Loader {
227
226
228
227
if ( boundingSphere !== undefined ) {
229
228
230
- const center = new Vector3 ( ) ;
231
-
232
- if ( boundingSphere . center !== undefined ) {
233
-
234
- center . fromArray ( boundingSphere . center ) ;
235
-
236
- }
237
-
238
- geometry . boundingSphere = new Sphere ( center , boundingSphere . radius ) ;
229
+ geometry . boundingSphere = new Sphere ( ) . fromJSON ( boundingSphere ) ;
239
230
240
231
}
241
232
Original file line number Diff line number Diff line change @@ -985,9 +985,7 @@ class ObjectLoader extends Loader {
985
985
986
986
if ( info . boundingSphere !== undefined ) {
987
987
988
- sphere = new Sphere ( ) ;
989
- sphere . radius = info . boundingSphere . radius ;
990
- sphere . center . fromArray ( info . boundingSphere . center ) ;
988
+ sphere = new Sphere ( ) . fromJSON ( info . boundingSphere ) ;
991
989
992
990
}
993
991
@@ -1025,9 +1023,7 @@ class ObjectLoader extends Loader {
1025
1023
1026
1024
if ( data . boundingSphere !== undefined ) {
1027
1025
1028
- object . boundingSphere = new Sphere ( ) ;
1029
- object . boundingSphere . center . fromArray ( data . boundingSphere . center ) ;
1030
- object . boundingSphere . radius = data . boundingSphere . radius ;
1026
+ object . boundingSphere = new Sphere ( ) . fromJSON ( data . boundingSphere ) ;
1031
1027
1032
1028
}
1033
1029
Original file line number Diff line number Diff line change @@ -387,6 +387,34 @@ class Sphere {
387
387
388
388
}
389
389
390
+ /**
391
+ * Returns a serialized structure of the bounding sphere.
392
+ *
393
+ * @return {Object } Serialized structure with fields representing the object state.
394
+ */
395
+ toJSON ( ) {
396
+
397
+ return {
398
+ radius : this . radius ,
399
+ center : this . center . toArray ( )
400
+ } ;
401
+
402
+ }
403
+
404
+ /**
405
+ * Returns a serialized structure of the bounding sphere.
406
+ *
407
+ * @param {Object } json - The serialized json to set the sphere from.
408
+ * @return {Box3 } A reference to this bounding sphere.
409
+ */
410
+ fromJSON ( json ) {
411
+
412
+ this . radius = json . radius ;
413
+ this . center . fromArray ( json . center ) ;
414
+ return this ;
415
+
416
+ }
417
+
390
418
}
391
419
392
420
export { Sphere } ;
You can’t perform that action at this time.
0 commit comments