Skip to content

Commit

Permalink
Merge pull request #58 from Geodan/fix_jittering
Browse files Browse the repository at this point in the history
fix jittering
  • Loading branch information
bertt authored Jun 10, 2024
2 parents 3bd860e + b5e9661 commit 6ec7fd2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection;

namespace i3dm.export;
Expand Down
21 changes: 16 additions & 5 deletions src/TileHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ private static byte[] GetGpuGlb(object model, List<Instance> positions, bool Use

var pointId = 0;

Vector3 translation = Vector3.One;
bool first = true;

foreach (var p in positions)
{
var point = (Point)p.Position;
Expand Down Expand Up @@ -134,16 +137,23 @@ private static byte[] GetGpuGlb(object model, List<Instance> 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++;
Expand Down Expand Up @@ -184,9 +194,10 @@ private static byte[] GetGpuGlb(object model, List<Instance> 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;
Expand Down

0 comments on commit 6ec7fd2

Please sign in to comment.