From 842fbb1bdd79e615528155cd4bdc3a9f11cab310 Mon Sep 17 00:00:00 2001 From: Bert Temme Date: Tue, 11 Jun 2024 10:28:32 +0200 Subject: [PATCH] improve tags error handling --- src/TileHandler.cs | 48 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/TileHandler.cs b/src/TileHandler.cs index 7143bc0..f47dd9f 100644 --- a/src/TileHandler.cs +++ b/src/TileHandler.cs @@ -161,40 +161,40 @@ private static byte[] GetGpuGlb(object model, List positions, bool Use var settings = SceneBuilderSchema2Settings.WithGpuInstancing; settings.GpuMeshInstancingMinCount = 0; var gltf = sceneBuilder.ToGltf2(settings); + PropertyTable propertyTable = null; - var rootMetadata = gltf.UseStructuralMetadata(); - var schema = rootMetadata.UseEmbeddedSchema("schema"); - var schemaClass = schema.UseClassMetadata("propertyTable"); - - if(tags.Count > 0) + if (tags.Count > 0 && tags[0] != null) { - var propertyTable = schemaClass.AddPropertyTable(positions.Count); + var rootMetadata = gltf.UseStructuralMetadata(); + var schema = rootMetadata.UseEmbeddedSchema("schema"); + var schemaClass = schema.UseClassMetadata("propertyTable"); + + propertyTable = schemaClass.AddPropertyTable(positions.Count); - if (tags[0] != null) + var properties = TinyJson.GetProperties(tags[0]); + foreach (var property in properties) { - var properties = TinyJson.GetProperties(tags[0]); - foreach(var property in properties) - { - var values = TinyJson.GetValues(tags, property); + var values = TinyJson.GetValues(tags, property); - var nameProperty = schemaClass - .UseProperty(property) - .WithStringType(); + var nameProperty = schemaClass + .UseProperty(property) + .WithStringType(); - // todo: use other types than string - var strings = values.Select(s => s.ToString()).ToArray(); + // todo: use other types than string + var strings = values.Select(s => s.ToString()).ToArray(); - propertyTable - .UseProperty(nameProperty) - .SetValues(strings); - } + propertyTable + .UseProperty(nameProperty) + .SetValues(strings); } + } + var featureId0 = propertyTable!= null? + new FeatureIDBuilder(positions.Count, 0, propertyTable): + new FeatureIDBuilder(positions.Count, 0); + + gltf.LogicalNodes[0].AddInstanceFeatureIds(featureId0); - var featureId0 = new FeatureIDBuilder(positions.Count, 0, propertyTable); - gltf.LogicalNodes[0].AddInstanceFeatureIds(featureId0); - } - // todo: use exisiting transformation... gltf.LogicalNodes[0].LocalTransform = Matrix4x4.CreateTranslation(translation);