Skip to content

Commit 6f201db

Browse files
gkjohnsonRuthySheffi
authored andcommitted
BatchedMesh: Fix toJSON, ObjectLoader integration (mrdoob#30965)
* BatchedMesh: fix copy function * BatchedMesh: Update toJSON function * BatchedMesh.toJSON: small cleanup * ObjectLoader: Fix BatchedMesh support * BatchedMesh.copy: Remove redundant field * Object3D, ObjectLoader: adjust serialized definitions * ObjectLoader: Copy over necessary info
1 parent d348691 commit 6f201db

File tree

3 files changed

+91
-33
lines changed

3 files changed

+91
-33
lines changed

src/core/Object3D.js

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,43 +1294,56 @@ class Object3D extends EventDispatcher {
12941294
object.drawRanges = this._drawRanges;
12951295
object.reservedRanges = this._reservedRanges;
12961296

1297-
object.visibility = this._visibility;
1298-
object.active = this._active;
1299-
object.bounds = this._bounds.map( bound => ( {
1300-
boxInitialized: bound.boxInitialized,
1301-
boxMin: bound.box.min.toArray(),
1302-
boxMax: bound.box.max.toArray(),
1303-
1304-
sphereInitialized: bound.sphereInitialized,
1305-
sphereRadius: bound.sphere.radius,
1306-
sphereCenter: bound.sphere.center.toArray()
1297+
object.geometryInfo = this._geometryInfo.map( info => ( {
1298+
...info,
1299+
boundingBox: info.boundingBox ? {
1300+
min: info.boundingBox.min.toArray(),
1301+
max: info.boundingBox.max.toArray()
1302+
} : undefined,
1303+
boundingSphere: info.boundingSphere ? {
1304+
radius: info.boundingSphere.radius,
1305+
center: info.boundingSphere.center.toArray()
1306+
} : undefined
13071307
} ) );
1308+
object.instanceInfo = this._instanceInfo.map( info => ( { ...info } ) );
1309+
1310+
object.availableInstanceIds = this._availableInstanceIds.slice();
1311+
object.availableGeometryIds = this._availableGeometryIds.slice();
1312+
1313+
object.nextIndexStart = this._nextIndexStart;
1314+
object.nextVertexStart = this._nextVertexStart;
1315+
object.geometryCount = this._geometryCount;
13081316

13091317
object.maxInstanceCount = this._maxInstanceCount;
13101318
object.maxVertexCount = this._maxVertexCount;
13111319
object.maxIndexCount = this._maxIndexCount;
13121320

13131321
object.geometryInitialized = this._geometryInitialized;
1314-
object.geometryCount = this._geometryCount;
13151322

13161323
object.matricesTexture = this._matricesTexture.toJSON( meta );
13171324

1318-
if ( this._colorsTexture !== null ) object.colorsTexture = this._colorsTexture.toJSON( meta );
1325+
object.indirectTexture = this._indirectTexture.toJSON( meta );
1326+
1327+
if ( this._colorsTexture !== null ) {
1328+
1329+
object.colorsTexture = this._colorsTexture.toJSON( meta );
1330+
1331+
}
13191332

13201333
if ( this.boundingSphere !== null ) {
13211334

13221335
object.boundingSphere = {
1323-
center: object.boundingSphere.center.toArray(),
1324-
radius: object.boundingSphere.radius
1336+
center: this.boundingSphere.center.toArray(),
1337+
radius: this.boundingSphere.radius
13251338
};
13261339

13271340
}
13281341

13291342
if ( this.boundingBox !== null ) {
13301343

13311344
object.boundingBox = {
1332-
min: object.boundingBox.min.toArray(),
1333-
max: object.boundingBox.max.toArray()
1345+
min: this.boundingBox.min.toArray(),
1346+
max: this.boundingBox.max.toArray()
13341347
};
13351348

13361349
}

src/loaders/ObjectLoader.js

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -973,37 +973,73 @@ class ObjectLoader extends Loader {
973973
object._drawRanges = data.drawRanges;
974974
object._reservedRanges = data.reservedRanges;
975975

976-
object._visibility = data.visibility;
977-
object._active = data.active;
978-
object._bounds = data.bounds.map( bound => {
976+
object._geometryInfo = data.geometryInfo.map( info => {
979977

980-
const box = new Box3();
981-
box.min.fromArray( bound.boxMin );
982-
box.max.fromArray( bound.boxMax );
978+
let box = null;
979+
let sphere = null;
980+
if ( info.boundingBox !== undefined ) {
983981

984-
const sphere = new Sphere();
985-
sphere.radius = bound.sphereRadius;
986-
sphere.center.fromArray( bound.sphereCenter );
982+
box = new Box3();
983+
box.min.fromArray( info.boundingBox.min );
984+
box.max.fromArray( info.boundingBox.max );
987985

988-
return {
989-
boxInitialized: bound.boxInitialized,
990-
box: box,
986+
}
987+
988+
if ( info.boundingSphere !== undefined ) {
989+
990+
sphere = new Sphere();
991+
sphere.radius = info.boundingSphere.radius;
992+
sphere.center.fromArray( info.boundingSphere.center );
993+
994+
}
991995

992-
sphereInitialized: bound.sphereInitialized,
993-
sphere: sphere
996+
return {
997+
...info,
998+
boundingBox: box,
999+
boundingSphere: sphere
9941000
};
9951001

9961002
} );
1003+
object._instanceInfo = data.instanceInfo;
1004+
1005+
object._availableInstanceIds = data._availableInstanceIds;
1006+
object._availableGeometryIds = data._availableGeometryIds;
1007+
1008+
object._nextIndexStart = data.nextIndexStart;
1009+
object._nextVertexStart = data.nextVertexStart;
1010+
object._geometryCount = data.geometryCount;
9971011

9981012
object._maxInstanceCount = data.maxInstanceCount;
9991013
object._maxVertexCount = data.maxVertexCount;
10001014
object._maxIndexCount = data.maxIndexCount;
10011015

10021016
object._geometryInitialized = data.geometryInitialized;
1003-
object._geometryCount = data.geometryCount;
10041017

10051018
object._matricesTexture = getTexture( data.matricesTexture.uuid );
1006-
if ( data.colorsTexture !== undefined ) object._colorsTexture = getTexture( data.colorsTexture.uuid );
1019+
1020+
object._indirectTexture = getTexture( data.indirectTexture.uuid );
1021+
1022+
if ( data.colorsTexture !== undefined ) {
1023+
1024+
object._colorsTexture = getTexture( data.colorsTexture.uuid );
1025+
1026+
}
1027+
1028+
if ( data.boundingSphere !== undefined ) {
1029+
1030+
object.boundingSphere = new Sphere();
1031+
object.boundingSphere.center.fromArray( data.boundingSphere.center );
1032+
object.boundingSphere.radius = data.boundingSphere.radius;
1033+
1034+
}
1035+
1036+
if ( data.boundingBox !== undefined ) {
1037+
1038+
object.boundingBox = new Box3();
1039+
object.boundingBox.min.fromArray( data.boundingBox.min );
1040+
object.boundingBox.max.fromArray( data.boundingBox.max );
1041+
1042+
}
10071043

10081044
break;
10091045

src/objects/BatchedMesh.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,15 +1443,24 @@ class BatchedMesh extends Mesh {
14431443
} ) );
14441444
this._instanceInfo = source._instanceInfo.map( info => ( { ...info } ) );
14451445

1446+
this._availableInstanceIds = source._availableInstanceIds.slice();
1447+
this._availableGeometryIds = source._availableGeometryIds.slice();
1448+
1449+
this._nextIndexStart = source._nextIndexStart;
1450+
this._nextVertexStart = source._nextVertexStart;
1451+
this._geometryCount = source._geometryCount;
1452+
14461453
this._maxInstanceCount = source._maxInstanceCount;
14471454
this._maxVertexCount = source._maxVertexCount;
14481455
this._maxIndexCount = source._maxIndexCount;
14491456

14501457
this._geometryInitialized = source._geometryInitialized;
1451-
this._geometryCount = source._geometryCount;
14521458
this._multiDrawCounts = source._multiDrawCounts.slice();
14531459
this._multiDrawStarts = source._multiDrawStarts.slice();
14541460

1461+
this._indirectTexture = source._indirectTexture.clone();
1462+
this._indirectTexture.image.data = this._indirectTexture.image.data.slice();
1463+
14551464
this._matricesTexture = source._matricesTexture.clone();
14561465
this._matricesTexture.image.data = this._matricesTexture.image.data.slice();
14571466

0 commit comments

Comments
 (0)