public void DeserializeFeatureTableToJsonTest() { // arrange var positions = new List <Vector3>(); positions.Add(new Vector3(0, 0, 0)); positions.Add(new Vector3(1, 1, 1)); var treeGlb = File.ReadAllBytes(@"testfixtures/barrel.glb"); var i3dm = new I3dm.Tile.I3dm(positions, treeGlb); i3dm.Positions = positions; // act var featureTableJson = i3dm.GetFeatureTableJson(); var serializeOptions = new JsonSerializerOptions() { IgnoreNullValues = true }; serializeOptions.Converters.Add(new Vector3Converter()); var featureTable = JsonSerializer.Deserialize <FeatureTable>(featureTableJson, serializeOptions); // assert Assert.IsTrue(featureTable.InstancesLength == 2); Assert.IsTrue(featureTable.IsEastNorthUp == true); Assert.IsTrue(featureTable.PositionOffset.offset == 0); }
public static string Write(string path, I3dm i3dm) { i3dm.FeatureTableJson = i3dm.GetFeatureTableJson(); var featureTableBinary = new List <byte>(); featureTableBinary.AddRange(i3dm.Positions.ToBytes()); if (i3dm.NormalUps != null) { featureTableBinary.AddRange(i3dm.NormalUps.ToBytes()); } if (i3dm.NormalRights != null) { featureTableBinary.AddRange(i3dm.NormalRights.ToBytes()); } if (i3dm.ScaleNonUniforms != null) { featureTableBinary.AddRange(i3dm.ScaleNonUniforms.ToBytes()); } if (i3dm.BatchIdsBytes != null) { featureTableBinary.AddRange(i3dm.BatchIdsBytes.ToArray()); } i3dm.FeatureTableBinary = featureTableBinary.ToArray(); var header_length = 28; i3dm.I3dmHeader.ByteLength = i3dm.GlbData.Length + header_length + i3dm.FeatureTableJson.Length + i3dm.BatchTableJson.Length + i3dm.BatchTableBinary.Length + i3dm.FeatureTableBinary.Length; i3dm.I3dmHeader.FeatureTableJsonByteLength = i3dm.FeatureTableJson.Length; i3dm.I3dmHeader.BatchTableJsonByteLength = i3dm.BatchTableJson.Length; i3dm.I3dmHeader.FeatureTableBinaryByteLength = i3dm.FeatureTableBinary.Length; i3dm.I3dmHeader.BatchTableBinaryByteLength = i3dm.BatchTableBinary.Length; var fileStream = File.Open(path, FileMode.Create); var binaryWriter = new BinaryWriter(fileStream); binaryWriter.Write(i3dm.I3dmHeader.AsBinary()); binaryWriter.Write(Encoding.UTF8.GetBytes(i3dm.FeatureTableJson)); if (i3dm.FeatureTableBinary != null) { binaryWriter.Write(i3dm.FeatureTableBinary); } binaryWriter.Write(Encoding.UTF8.GetBytes(i3dm.BatchTableJson)); if (i3dm.BatchTableBinary != null) { binaryWriter.Write(i3dm.BatchTableBinary); } binaryWriter.Write(i3dm.GlbData); binaryWriter.Flush(); binaryWriter.Close(); return(fileStream.Name); }
public void DeserializeFeatureTableToJsonTest() { // arrange var i3dm = new I3dm.Tile.I3dm(); var positions = new List <Vector3>(); positions.Add(new Vector3(0, 0, 0)); positions.Add(new Vector3(1, 1, 1)); i3dm.Positions = positions; // act var featureTableJson = i3dm.GetFeatureTableJson(); var featureTable = JsonSerializer.Deserialize <FeatureTable>(featureTableJson); // assert Assert.IsTrue(featureTable.InstancesLength == 2); Assert.IsTrue(featureTable.IsEastNorthUp == false); Assert.IsTrue(featureTable.PositionOffset.byteOffset == 0); }
private static void UpdateProperties(I3dm i3dm, string batchIdSerializeType) { var batchIdBytes = new byte[0]; if (i3dm.BatchIds != null) { batchIdBytes = GetBatchIdsBytes(i3dm.BatchIds, batchIdSerializeType); } i3dm.FeatureTableJson = BufferPadding.AddPadding(i3dm.GetFeatureTableJson(batchIdSerializeType, batchIdBytes.Length)); var featureTableBinary = new List <byte>(); featureTableBinary.AddRange(i3dm.Positions.ToBytes()); if (i3dm.NormalUps != null) { featureTableBinary.AddRange(i3dm.NormalUps.ToBytes()); } if (i3dm.NormalRights != null) { featureTableBinary.AddRange(i3dm.NormalRights.ToBytes()); } if (i3dm.ScaleNonUniforms != null) { featureTableBinary.AddRange(i3dm.ScaleNonUniforms.ToBytes()); } if (i3dm.Scales != null) { featureTableBinary.AddRange(i3dm.Scales.ToBytes()); } if (i3dm.BatchIds != null) { featureTableBinary.AddRange(batchIdBytes); } if (i3dm.RtcCenter != null) { featureTableBinary.AddRange(((Vector3)i3dm.RtcCenter).ToBytes()); } if (i3dm.BatchTableJson != string.Empty) { i3dm.BatchTableJson = BufferPadding.AddPadding(i3dm.BatchTableJson); } if (i3dm.BatchTableBinary != null) { i3dm.BatchTableBinary = BufferPadding.AddPadding(i3dm.BatchTableBinary); } i3dm.FeatureTableBinary = BufferPadding.AddPadding(featureTableBinary.ToArray()); var header_length = 28; var glbLength = i3dm.I3dmHeader.GltfFormat == 0 ? i3dm.GlbUrl.Length : i3dm.GlbData.Length; i3dm.I3dmHeader.ByteLength = glbLength + header_length + i3dm.FeatureTableJson.Length + i3dm.BatchTableJson.Length + i3dm.BatchTableBinary.Length + i3dm.FeatureTableBinary.Length + BitConverter.GetBytes(i3dm.I3dmHeader.GltfFormat).Length; i3dm.I3dmHeader.FeatureTableJsonByteLength = i3dm.FeatureTableJson.Length; i3dm.I3dmHeader.BatchTableJsonByteLength = i3dm.BatchTableJson.Length; i3dm.I3dmHeader.FeatureTableBinaryByteLength = i3dm.FeatureTableBinary.Length; i3dm.I3dmHeader.BatchTableBinaryByteLength = i3dm.BatchTableBinary.Length; }
public static string Write(string path, I3dm i3dm, string batchIdSerializeType = "UNSIGNED_SHORT") { var batchIdBytes = new byte[0]; if (i3dm.BatchIds != null) { batchIdBytes = GetBatchIdsBytes(i3dm.BatchIds, batchIdSerializeType); } i3dm.FeatureTableJson = BufferPadding.AddPadding(i3dm.GetFeatureTableJson(batchIdSerializeType, batchIdBytes.Length)); var featureTableBinary = new List <byte>(); featureTableBinary.AddRange(i3dm.Positions.ToBytes()); if (i3dm.NormalUps != null) { featureTableBinary.AddRange(i3dm.NormalUps.ToBytes()); } if (i3dm.NormalRights != null) { featureTableBinary.AddRange(i3dm.NormalRights.ToBytes()); } if (i3dm.ScaleNonUniforms != null) { featureTableBinary.AddRange(i3dm.ScaleNonUniforms.ToBytes()); } if (i3dm.Scales != null) { featureTableBinary.AddRange(i3dm.Scales.ToBytes()); } if (i3dm.BatchIds != null) { featureTableBinary.AddRange(batchIdBytes); } if (!i3dm.RtcCenter.Equals(Vector3.Zero)) { featureTableBinary.AddRange(i3dm.RtcCenter.ToBytes()); } if (i3dm.BatchTableJson != string.Empty) { i3dm.BatchTableJson = BufferPadding.AddPadding(i3dm.BatchTableJson); } if (i3dm.BatchTableBinary != null) { i3dm.BatchTableBinary = BufferPadding.AddPadding(i3dm.BatchTableBinary); } i3dm.FeatureTableBinary = BufferPadding.AddPadding(featureTableBinary.ToArray()); var header_length = 28; i3dm.I3dmHeader.ByteLength = i3dm.GlbData.Length + header_length + i3dm.FeatureTableJson.Length + i3dm.BatchTableJson.Length + i3dm.BatchTableBinary.Length + i3dm.FeatureTableBinary.Length + BitConverter.GetBytes(i3dm.I3dmHeader.GltfFormat).Length; i3dm.I3dmHeader.FeatureTableJsonByteLength = i3dm.FeatureTableJson.Length; i3dm.I3dmHeader.BatchTableJsonByteLength = i3dm.BatchTableJson.Length; i3dm.I3dmHeader.FeatureTableBinaryByteLength = i3dm.FeatureTableBinary.Length; i3dm.I3dmHeader.BatchTableBinaryByteLength = i3dm.BatchTableBinary.Length; var fileStream = File.Open(path, FileMode.Create); var binaryWriter = new BinaryWriter(fileStream); binaryWriter.Write(i3dm.I3dmHeader.AsBinary()); binaryWriter.Write(Encoding.UTF8.GetBytes(i3dm.FeatureTableJson)); if (i3dm.FeatureTableBinary != null) { binaryWriter.Write(i3dm.FeatureTableBinary); } binaryWriter.Write(Encoding.UTF8.GetBytes(i3dm.BatchTableJson)); if (i3dm.BatchTableBinary != null) { binaryWriter.Write(i3dm.BatchTableBinary); } binaryWriter.Write(i3dm.GlbData); binaryWriter.Flush(); binaryWriter.Close(); return(fileStream.Name); }