Skip to content

Commit 9700f01

Browse files
Fixed issue in the .babylon serializer (#16524)
When serializing to .babylon file we are setting the _isExpanded property directly in the array object to flag if matrices indices are in compact or expanded form. However, JSON.stringify will remove those properties since it does not support properties in array objects. I'm moving those flags to the serializationObject itself to allows it to be properly exported. I'm also keeping the deserializer for it just in case someone has a file that somehow has that property in the array. Releated to Exporters PR: BabylonJS/Exporters#1137 --------- Co-authored-by: Raanan Weber <raananw+github@gmail.com>
1 parent 8404e41 commit 9700f01

File tree

2 files changed

+44
-30
lines changed

2 files changed

+44
-30
lines changed

packages/dev/core/src/Meshes/geometry.ts

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,85 +1135,85 @@ export class Geometry implements IGetSetVerticesData {
11351135
if (this.isVerticesDataPresent(VertexBuffer.PositionKind)) {
11361136
serializationObject.positions = this._toNumberArray(this.getVerticesData(VertexBuffer.PositionKind));
11371137
if (this.isVertexBufferUpdatable(VertexBuffer.PositionKind)) {
1138-
serializationObject.positions._updatable = true;
1138+
serializationObject.positionsUpdatable = true;
11391139
}
11401140
}
11411141

11421142
if (this.isVerticesDataPresent(VertexBuffer.NormalKind)) {
11431143
serializationObject.normals = this._toNumberArray(this.getVerticesData(VertexBuffer.NormalKind));
11441144
if (this.isVertexBufferUpdatable(VertexBuffer.NormalKind)) {
1145-
serializationObject.normals._updatable = true;
1145+
serializationObject.normalsUpdatable = true;
11461146
}
11471147
}
11481148

11491149
if (this.isVerticesDataPresent(VertexBuffer.TangentKind)) {
11501150
serializationObject.tangents = this._toNumberArray(this.getVerticesData(VertexBuffer.TangentKind));
11511151
if (this.isVertexBufferUpdatable(VertexBuffer.TangentKind)) {
1152-
serializationObject.tangents._updatable = true;
1152+
serializationObject.tangentsUpdatable = true;
11531153
}
11541154
}
11551155

11561156
if (this.isVerticesDataPresent(VertexBuffer.UVKind)) {
11571157
serializationObject.uvs = this._toNumberArray(this.getVerticesData(VertexBuffer.UVKind));
11581158
if (this.isVertexBufferUpdatable(VertexBuffer.UVKind)) {
1159-
serializationObject.uvs._updatable = true;
1159+
serializationObject.uvsUpdatable = true;
11601160
}
11611161
}
11621162

11631163
if (this.isVerticesDataPresent(VertexBuffer.UV2Kind)) {
11641164
serializationObject.uvs2 = this._toNumberArray(this.getVerticesData(VertexBuffer.UV2Kind));
11651165
if (this.isVertexBufferUpdatable(VertexBuffer.UV2Kind)) {
1166-
serializationObject.uvs2._updatable = true;
1166+
serializationObject.uvs2Updatable = true;
11671167
}
11681168
}
11691169

11701170
if (this.isVerticesDataPresent(VertexBuffer.UV3Kind)) {
11711171
serializationObject.uvs3 = this._toNumberArray(this.getVerticesData(VertexBuffer.UV3Kind));
11721172
if (this.isVertexBufferUpdatable(VertexBuffer.UV3Kind)) {
1173-
serializationObject.uvs3._updatable = true;
1173+
serializationObject.uvs3Updatable = true;
11741174
}
11751175
}
11761176

11771177
if (this.isVerticesDataPresent(VertexBuffer.UV4Kind)) {
11781178
serializationObject.uvs4 = this._toNumberArray(this.getVerticesData(VertexBuffer.UV4Kind));
11791179
if (this.isVertexBufferUpdatable(VertexBuffer.UV4Kind)) {
1180-
serializationObject.uvs4._updatable = true;
1180+
serializationObject.uvs4Updatable = true;
11811181
}
11821182
}
11831183

11841184
if (this.isVerticesDataPresent(VertexBuffer.UV5Kind)) {
11851185
serializationObject.uvs5 = this._toNumberArray(this.getVerticesData(VertexBuffer.UV5Kind));
11861186
if (this.isVertexBufferUpdatable(VertexBuffer.UV5Kind)) {
1187-
serializationObject.uvs5._updatable = true;
1187+
serializationObject.uvs5Updatable = true;
11881188
}
11891189
}
11901190

11911191
if (this.isVerticesDataPresent(VertexBuffer.UV6Kind)) {
11921192
serializationObject.uvs6 = this._toNumberArray(this.getVerticesData(VertexBuffer.UV6Kind));
11931193
if (this.isVertexBufferUpdatable(VertexBuffer.UV6Kind)) {
1194-
serializationObject.uvs6._updatable = true;
1194+
serializationObject.uvs6Updatable = true;
11951195
}
11961196
}
11971197

11981198
if (this.isVerticesDataPresent(VertexBuffer.ColorKind)) {
11991199
serializationObject.colors = this._toNumberArray(this.getVerticesData(VertexBuffer.ColorKind));
12001200
if (this.isVertexBufferUpdatable(VertexBuffer.ColorKind)) {
1201-
serializationObject.colors._updatable = true;
1201+
serializationObject.colorsUpdatable = true;
12021202
}
12031203
}
12041204

12051205
if (this.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind)) {
12061206
serializationObject.matricesIndices = this._toNumberArray(this.getVerticesData(VertexBuffer.MatricesIndicesKind));
1207-
serializationObject.matricesIndices._isExpanded = true;
1207+
serializationObject.matricesIndicesExpanded = true;
12081208
if (this.isVertexBufferUpdatable(VertexBuffer.MatricesIndicesKind)) {
1209-
serializationObject.matricesIndices._updatable = true;
1209+
serializationObject.matricesIndicesUpdatable = true;
12101210
}
12111211
}
12121212

12131213
if (this.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind)) {
12141214
serializationObject.matricesWeights = this._toNumberArray(this.getVerticesData(VertexBuffer.MatricesWeightsKind));
12151215
if (this.isVertexBufferUpdatable(VertexBuffer.MatricesWeightsKind)) {
1216-
serializationObject.matricesWeights._updatable = true;
1216+
serializationObject.matricesWeightsUpdatable = true;
12171217
}
12181218
}
12191219

@@ -1409,44 +1409,44 @@ export class Geometry implements IGetSetVerticesData {
14091409
}
14101410
}
14111411
} else if (parsedGeometry.positions && parsedGeometry.normals && parsedGeometry.indices) {
1412-
mesh.setVerticesData(VertexBuffer.PositionKind, parsedGeometry.positions, parsedGeometry.positions._updatable);
1412+
mesh.setVerticesData(VertexBuffer.PositionKind, parsedGeometry.positions, parsedGeometry.positions._updatable || parsedGeometry.positionsUpdatable);
14131413

1414-
mesh.setVerticesData(VertexBuffer.NormalKind, parsedGeometry.normals, parsedGeometry.normals._updatable);
1414+
mesh.setVerticesData(VertexBuffer.NormalKind, parsedGeometry.normals, parsedGeometry.normals._updatable || parsedGeometry.normalsUpdatable);
14151415

14161416
if (parsedGeometry.tangents) {
1417-
mesh.setVerticesData(VertexBuffer.TangentKind, parsedGeometry.tangents, parsedGeometry.tangents._updatable);
1417+
mesh.setVerticesData(VertexBuffer.TangentKind, parsedGeometry.tangents, parsedGeometry.tangents._updatable || parsedGeometry.tangentsUpdatable);
14181418
}
14191419

14201420
if (parsedGeometry.uvs) {
1421-
mesh.setVerticesData(VertexBuffer.UVKind, parsedGeometry.uvs, parsedGeometry.uvs._updatable);
1421+
mesh.setVerticesData(VertexBuffer.UVKind, parsedGeometry.uvs, parsedGeometry.uvs._updatable || parsedGeometry.uvsUpdatable);
14221422
}
14231423

14241424
if (parsedGeometry.uvs2) {
1425-
mesh.setVerticesData(VertexBuffer.UV2Kind, parsedGeometry.uvs2, parsedGeometry.uvs2._updatable);
1425+
mesh.setVerticesData(VertexBuffer.UV2Kind, parsedGeometry.uvs2, parsedGeometry.uvs2._updatable || parsedGeometry.uvs2Updatable);
14261426
}
14271427

14281428
if (parsedGeometry.uvs3) {
1429-
mesh.setVerticesData(VertexBuffer.UV3Kind, parsedGeometry.uvs3, parsedGeometry.uvs3._updatable);
1429+
mesh.setVerticesData(VertexBuffer.UV3Kind, parsedGeometry.uvs3, parsedGeometry.uvs3._updatable || parsedGeometry.uvs3Updatable);
14301430
}
14311431

14321432
if (parsedGeometry.uvs4) {
1433-
mesh.setVerticesData(VertexBuffer.UV4Kind, parsedGeometry.uvs4, parsedGeometry.uvs4._updatable);
1433+
mesh.setVerticesData(VertexBuffer.UV4Kind, parsedGeometry.uvs4, parsedGeometry.uvs4._updatable || parsedGeometry.uvs4Updatable);
14341434
}
14351435

14361436
if (parsedGeometry.uvs5) {
1437-
mesh.setVerticesData(VertexBuffer.UV5Kind, parsedGeometry.uvs5, parsedGeometry.uvs5._updatable);
1437+
mesh.setVerticesData(VertexBuffer.UV5Kind, parsedGeometry.uvs5, parsedGeometry.uvs5._updatable || parsedGeometry.uvs5Updatable);
14381438
}
14391439

14401440
if (parsedGeometry.uvs6) {
1441-
mesh.setVerticesData(VertexBuffer.UV6Kind, parsedGeometry.uvs6, parsedGeometry.uvs6._updatable);
1441+
mesh.setVerticesData(VertexBuffer.UV6Kind, parsedGeometry.uvs6, parsedGeometry.uvs6._updatable || parsedGeometry.uvs6Updatable);
14421442
}
14431443

14441444
if (parsedGeometry.colors) {
14451445
mesh.setVerticesData(VertexBuffer.ColorKind, Color4.CheckColors4(parsedGeometry.colors, parsedGeometry.positions.length / 3), parsedGeometry.colors._updatable);
14461446
}
14471447

14481448
if (parsedGeometry.matricesIndices) {
1449-
if (!parsedGeometry.matricesIndices._isExpanded) {
1449+
if (!parsedGeometry.matricesIndices._isExpanded && !parsedGeometry.matricesIndicesExpanded) {
14501450
const floatIndices = [];
14511451

14521452
for (let i = 0; i < parsedGeometry.matricesIndices.length; i++) {
@@ -1458,15 +1458,20 @@ export class Geometry implements IGetSetVerticesData {
14581458
floatIndices.push((matricesIndex >> 24) & 0xff); // & 0xFF to convert to v + 256 if v < 0
14591459
}
14601460

1461-
mesh.setVerticesData(VertexBuffer.MatricesIndicesKind, floatIndices, parsedGeometry.matricesIndices._updatable);
1461+
mesh.setVerticesData(VertexBuffer.MatricesIndicesKind, floatIndices, parsedGeometry.matricesIndices._updatable || parsedGeometry.matricesIndicesUpdatable);
14621462
} else {
14631463
delete parsedGeometry.matricesIndices._isExpanded;
1464-
mesh.setVerticesData(VertexBuffer.MatricesIndicesKind, parsedGeometry.matricesIndices, parsedGeometry.matricesIndices._updatable);
1464+
delete parsedGeometry.matricesIndicesExpanded;
1465+
mesh.setVerticesData(
1466+
VertexBuffer.MatricesIndicesKind,
1467+
parsedGeometry.matricesIndices,
1468+
parsedGeometry.matricesIndices._updatable || parsedGeometry.matricesIndicesUpdatable
1469+
);
14651470
}
14661471
}
14671472

14681473
if (parsedGeometry.matricesIndicesExtra) {
1469-
if (!parsedGeometry.matricesIndicesExtra._isExpanded) {
1474+
if (!(parsedGeometry.matricesIndicesExtraExpanded || parsedGeometry.matricesIndicesExtra._isExpanded)) {
14701475
const floatIndices = [];
14711476

14721477
for (let i = 0; i < parsedGeometry.matricesIndicesExtra.length; i++) {
@@ -1478,10 +1483,19 @@ export class Geometry implements IGetSetVerticesData {
14781483
floatIndices.push((matricesIndex >> 24) & 0xff); // & 0xFF to convert to v + 256 if v < 0
14791484
}
14801485

1481-
mesh.setVerticesData(VertexBuffer.MatricesIndicesExtraKind, floatIndices, parsedGeometry.matricesIndicesExtra._updatable);
1486+
mesh.setVerticesData(
1487+
VertexBuffer.MatricesIndicesExtraKind,
1488+
floatIndices,
1489+
parsedGeometry.matricesIndicesExtra._updatable || parsedGeometry.matricesIndicesExtraUpdatable
1490+
);
14821491
} else {
14831492
delete parsedGeometry.matricesIndices._isExpanded;
1484-
mesh.setVerticesData(VertexBuffer.MatricesIndicesExtraKind, parsedGeometry.matricesIndicesExtra, parsedGeometry.matricesIndicesExtra._updatable);
1493+
delete parsedGeometry.matricesIndicesExtraExpanded;
1494+
mesh.setVerticesData(
1495+
VertexBuffer.MatricesIndicesExtraKind,
1496+
parsedGeometry.matricesIndicesExtra,
1497+
parsedGeometry.matricesIndicesExtra._updatable || parsedGeometry.matricesIndicesExtraUpdatable
1498+
);
14851499
}
14861500
}
14871501

packages/dev/core/src/Meshes/mesh.vertexData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ export class VertexData implements IVertexDataLike {
13991399

14001400
if (this.matricesIndices) {
14011401
serializationObject.matricesIndices = Array.from(this.matricesIndices);
1402-
serializationObject.matricesIndices._isExpanded = true;
1402+
serializationObject.matricesIndicesExpanded = true;
14031403
}
14041404

14051405
if (this.matricesWeights) {
@@ -1408,7 +1408,7 @@ export class VertexData implements IVertexDataLike {
14081408

14091409
if (this.matricesIndicesExtra) {
14101410
serializationObject.matricesIndicesExtra = Array.from(this.matricesIndicesExtra);
1411-
serializationObject.matricesIndicesExtra._isExpanded = true;
1411+
serializationObject.matricesIndicesExtraExpanded = true;
14121412
}
14131413

14141414
if (this.matricesWeightsExtra) {

0 commit comments

Comments
 (0)