From b5e96616bee94b414129b19a1e7caa4bd9f46eb7 Mon Sep 17 00:00:00 2001 From: Bert Temme Date: Mon, 10 Jun 2024 13:28:56 +0200 Subject: [PATCH] fix jittering by storing relative positions instead of abslute ones. The center position (first poisition) is stored in the node transformation --- src/Program.cs | 1 - src/TileHandler.cs | 21 ++++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Program.cs b/src/Program.cs index de9f8ac..2530b02 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -10,7 +10,6 @@ using System.Diagnostics; using System.IO; using System.Linq; -using System.Numerics; using System.Reflection; namespace i3dm.export; diff --git a/src/TileHandler.cs b/src/TileHandler.cs index dfeaacb..706d7c5 100644 --- a/src/TileHandler.cs +++ b/src/TileHandler.cs @@ -106,6 +106,9 @@ private static byte[] GetGpuGlb(object model, List positions, bool Use var pointId = 0; + Vector3 translation = Vector3.One; + bool first = true; + foreach (var p in positions) { var point = (Point)p.Position; @@ -134,16 +137,23 @@ private static byte[] GetGpuGlb(object model, List positions, bool Use m4.M33 = forward.Z; var res = Quaternion.CreateFromRotationMatrix(m4); - var translation = new Vector3((float)p1.X, (float)p1.Y, (float)p1.Z); + var position = new Vector3((float)p1.X, (float)p1.Y, (float)p1.Z); + + if (first) + { + translation = position; + first = false; + } + + var position2 = position - translation; - // todo: make translation relative? // todo: use quaternion for yaw/pitch/roll // var quaternion = Quaternion.CreateFromYawPitchRoll((float)p.Yaw, (float)p.Pitch, (float)p.Roll); var transformation = new AffineTransform( scale, new Quaternion(-res.X, -res.Z, res.Y, res.W), - translation); + position2); var json = "{\"_FEATURE_ID_0\":" + pointId + "}"; sceneBuilder.AddRigidMesh(meshBuilder, transformation).WithExtras(JsonNode.Parse(json)); pointId++; @@ -184,9 +194,10 @@ private static byte[] GetGpuGlb(object model, List positions, bool Use var featureId0 = new FeatureIDBuilder(positions.Count, 0, propertyTable); gltf.LogicalNodes[0].AddInstanceFeatureIds(featureId0); - } - + + // todo: use exisiting transformation... + gltf.LogicalNodes[0].LocalTransform = Matrix4x4.CreateTranslation(translation); var bytes = gltf.WriteGLB().Array; return bytes;