Skip to content

Commit 96e9af2

Browse files
authored
Merge pull request #80 from dknezevic/master
Ensure GLB data is padded to 8-byte alignment so that validation checks pass
2 parents 9c9b2f9 + c52e341 commit 96e9af2

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

Obj2Gltf/BufferState.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public int MakeNormalAccessors(string name)
173173
Name = "Normals",
174174
Buffer = _model.AddBuffer(NormalsBuffer),
175175
ByteStride = 12,
176-
//Target = BufferViewTarget.ARRAY_BUFFER
176+
Target = BufferViewTarget.ARRAY_BUFFER
177177
};
178178
NormalsBufferViewIndex = _model.AddBufferView(NormalsBufferView);
179179
}
@@ -203,7 +203,7 @@ internal int MakeUvAccessor(string name)
203203
Name = "Uvs",
204204
Buffer = _model.AddBuffer(UvsBuffer),
205205
ByteStride = 8,
206-
//Target = BufferViewTarget.ARRAY_BUFFER
206+
Target = BufferViewTarget.ARRAY_BUFFER
207207
};
208208
UvsBufferViewIndex = _model.AddBufferView(UvsBufferView);
209209
}

Obj2Tiles/Stages/TilingStage.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static void Tile(string sourcePath, string destPath, int lods, double bas
1616
{
1717

1818
Console.WriteLine(" ?> Working on objs conversion");
19-
19+
2020
ConvertAllB3dm(sourcePath, destPath, lods);
2121

2222
Console.WriteLine(" -> Generating tileset.json");
@@ -26,7 +26,7 @@ public static void Tile(string sourcePath, string destPath, int lods, double bas
2626
Console.WriteLine(" ?> Using default coordinates");
2727
coords = DefaultGpsCoords;
2828
}
29-
29+
3030
// Don't ask me why 100, I have no idea but it works
3131
// https://github.com/CesiumGS/3d-tiles/issues/162
3232
//const int baseError = 100;
@@ -40,9 +40,7 @@ public static void Tile(string sourcePath, string destPath, int lods, double bas
4040
{
4141
GeometricError = baseError,
4242
Refine = "ADD",
43-
4443
Transform = coords.ToEcefTransform(),
45-
Children = new List<TileElement>()
4644
}
4745
};
4846

@@ -54,11 +52,11 @@ public static void Tile(string sourcePath, string destPath, int lods, double bas
5452
var minZ = double.MaxValue;
5553

5654
var masterDescriptors = boundsMapper[0].Keys;
57-
55+
5856
foreach (var descriptor in masterDescriptors)
5957
{
6058
var currentTileElement = tileset.Root;
61-
59+
6260
var refBox = boundsMapper[0][descriptor];
6361

6462
for (var lod = lods - 1; lod >= 0; lod--)
@@ -87,14 +85,15 @@ public static void Tile(string sourcePath, string destPath, int lods, double bas
8785
{
8886
GeometricError = lod == 0 ? 0 : CalculateGeometricError(refBox, box3, lod),
8987
Refine = "REPLACE",
90-
Children = new List<TileElement>(),
9188
Content = new Content
9289
{
9390
Uri = $"LOD-{lod}/{Path.GetFileNameWithoutExtension(descriptor)}.b3dm"
9491
},
9592
BoundingVolume = box3.ToBoundingVolume()
9693
};
9794

95+
if (currentTileElement.Children == null)
96+
currentTileElement.Children = new List<TileElement>();
9897
currentTileElement.Children.Add(tile);
9998
currentTileElement = tile;
10099
}
@@ -116,7 +115,7 @@ private static double CalculateGeometricError(Box3 refBox, Box3 box, int lod)
116115
var dW = Math.Abs(refBox.Width - box.Width) / box.Width + 1;
117116
var dH = Math.Abs(refBox.Height - box.Height) / box.Height + 1;
118117
var dD = Math.Abs(refBox.Depth - box.Depth) / box.Depth + 1;
119-
118+
120119
return Math.Pow(dW + dH + dD, lod);
121120

122121
}

Obj2Tiles/Tiles/B3dm.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ public byte[] ToBytes()
3030
{
3131
const int headerLength = 28;
3232

33-
var featureTableJson = BufferPadding.AddPadding(FeatureTableJson);
33+
var featureTableJson = BufferPadding.AddPadding(FeatureTableJson, headerLength);
3434
var batchTableJson = BufferPadding.AddPadding(BatchTableJson);
3535
var featureTableBinary = BufferPadding.AddPadding(FeatureTableBinary);
3636
var batchTableBinary = BufferPadding.AddPadding(BatchTableBinary);
3737

38+
// Ensure GLB data is padded to 8-byte alignment
39+
GlbData = BufferPadding.AddPadding(GlbData);
40+
3841
B3dmHeader.ByteLength = GlbData.Length + headerLength + featureTableJson.Length + Encoding.UTF8.GetByteCount(batchTableJson) + batchTableBinary.Length + FeatureTableBinary.Length;
3942

4043
B3dmHeader.FeatureTableJsonByteLength = featureTableJson.Length;

0 commit comments

Comments
 (0)