Skip to content

Commit

Permalink
use rtc_Center for i3dm's
Browse files Browse the repository at this point in the history
  • Loading branch information
bertt committed Aug 1, 2024
1 parent 2ff8c3f commit 5e47f8e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 as build
WORKDIR /src
COPY . .
WORKDIR src
RUN dotnet build "i3dm.export.csproj" -c Release
RUN dotnet publish "i3dm.export.csproj" -c Release -o /app

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ Press F5 to start debugging.

## History

2024-08-01: release 2.8.2: fix for I3dm using rtc_center for high precision positions

2024-07-22: release 2.8.1: fix release

2024-07-22: release 2.8.0: to .NET 8.0
Expand Down
21 changes: 15 additions & 6 deletions src/TileHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,25 @@ public static byte[] GetI3dmTile(List<Instance> instances, bool UseExternalModel
var modelInstances = instances.Where(s => s.Model.Equals(model)).ToList();

var tags = new List<JArray>();
var firstPosition = (Point)modelInstances[0].Position;

CalculateArrays(modelInstances, UseScaleNonUniform, positions, scales, scalesNonUniform, normalUps, normalRights, tags);
var i3dm = GetI3dm(model, positions, scales, scalesNonUniform, normalUps, normalRights, tags, UseExternalModel, UseScaleNonUniform);

var i3dm = GetI3dm(model, positions, firstPosition, scales, scalesNonUniform, normalUps, normalRights, tags, UseExternalModel, UseScaleNonUniform);
var bytesI3dm = I3dmWriter.Write(i3dm);
return bytesI3dm;
}

internal static void CalculateArrays(List<Instance> instances, bool UseScaleNonUniform, List<Vector3> positions, List<float> scales, List<Vector3> scalesNonUniform, List<Vector3> normalUps, List<Vector3> normalRights, List<JArray> tags)
{
var firstPosition = (Point)instances[0].Position;

foreach (var instance in instances)
{
var pos = (Point)instance.Position;
var positionVector3 = new Vector3((float)pos.X, (float)pos.Y, (float)pos.Z.GetValueOrDefault());

var vec = GetPosition((Point)instance.Position);
var vec = GetRelativePosition((Point)instance.Position, firstPosition);
positions.Add(vec);

if (!UseScaleNonUniform)
Expand All @@ -68,7 +73,7 @@ internal static void CalculateArrays(List<Instance> instances, bool UseScaleNonU
}
}

internal static I3dm.Tile.I3dm GetI3dm(object model, List<Vector3> positions, List<float> scales, List<Vector3> scalesNonUniform, List<Vector3> normalUps, List<Vector3> normalRights, List<JArray> tags, bool UseExternalModel = false, bool UseScaleNonUniform = false)
internal static I3dm.Tile.I3dm GetI3dm(object model, List<Vector3> positions, Point rtcCenter, List<float> scales, List<Vector3> scalesNonUniform, List<Vector3> normalUps, List<Vector3> normalRights, List<JArray> tags, bool UseExternalModel = false, bool UseScaleNonUniform = false)
{
I3dm.Tile.I3dm i3dm = null;

Expand Down Expand Up @@ -100,7 +105,7 @@ internal static I3dm.Tile.I3dm GetI3dm(object model, List<Vector3> positions, Li

i3dm.NormalUps = normalUps;
i3dm.NormalRights = normalRights;

i3dm.RtcCenter = new Vector3((float)rtcCenter.X, (float)rtcCenter.Y, (float)rtcCenter.Z.GetValueOrDefault());
if (tags[0] != null)
{
var properties = TinyJson.GetProperties(tags[0]);
Expand All @@ -110,9 +115,13 @@ internal static I3dm.Tile.I3dm GetI3dm(object model, List<Vector3> positions, Li
return i3dm;
}

private static Vector3 GetPosition(Point p)
private static Vector3 GetRelativePosition(Point p, Point p_0)
{
var vec = new Vector3((float)(p.X), (float)(p.Y), (float)(p.Z.GetValueOrDefault()));
var dx = p.X - p_0.X;
var dy = p.Y - p_0.Y;
var dz = p.Z.GetValueOrDefault() - p_0.Z.GetValueOrDefault();

var vec = new Vector3((float)dx, (float)dy, (float)dz);
return vec;
}
}
6 changes: 3 additions & 3 deletions src/i3dm.export.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<TargetFramework>net8.0</TargetFramework>
<ToolCommandName>i3dm.export</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
<Version>2.8.1</Version>
<AssemblyVersion>2.8.1</AssemblyVersion>
<FileVersion>2.8.1</FileVersion>
<Version>2.8.2</Version>
<AssemblyVersion>2.8.2</AssemblyVersion>
<FileVersion>2.8.2</FileVersion>
<PackageProjectUrl>https://github.com/geodan/i3dm.export</PackageProjectUrl>
<RepositoryUrl>https://github.com/geodan/i3dm.export</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down
12 changes: 6 additions & 6 deletions tests/TileHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void GetTileTest()
// assert
Assert.That(tile.Length > 0);
Assert.That(i3dm.Positions.Count == 1);
Assert.That(i3dm.Positions[0] == new Vector3(1, 2, 0));
Assert.That(i3dm.Positions[0] == new Vector3(0, 0, 0));
}

[Test]
Expand Down Expand Up @@ -104,13 +104,13 @@ public void GetCompositeTileTest()
var i3dm0 = I3dmReader.Read(new MemoryStream(cmpt.Tiles.First()));
Assert.That(i3dm0.Positions.Count == 1);
Assert.That(i3dm0.GlbUrl.StartsWith("box.glb"));
Assert.That(i3dm0.Positions[0] == new Vector3(1, 2, 0));
Assert.That(i3dm0.Positions[0] == new Vector3(0, 0, 0));

var i3dm1 = I3dmReader.Read(new MemoryStream(cmpt.Tiles.ToList()[1]));
Assert.That(i3dm1.Positions.Count == 2);
Assert.That(i3dm1.GlbUrl.StartsWith("box1.glb"));
Assert.That(i3dm1.Positions[0] == new Vector3(3, 4, 0));
Assert.That(i3dm1.Positions[1] == new Vector3(5, 6, 0));
Assert.That(i3dm1.Positions[0] == new Vector3(0, 0, 0));
Assert.That(i3dm1.Positions[1] == new Vector3(2, 2, 0));
}

[Test]
Expand Down Expand Up @@ -182,8 +182,8 @@ public void GetTileWithRtcCenterTest()
// assert
Assert.That(tile.Length > 0);
Assert.That(i3dm.Positions.Count == 2);
Assert.That(i3dm.Positions[0] == new Vector3(1, 2, 0));
Assert.That(i3dm.Positions[1] == new Vector3(10, 20, 0));
Assert.That(i3dm.Positions[0] == new Vector3(0, 0, 0));
Assert.That(i3dm.Positions[1] == new Vector3(9, 18, 0));
}

[Test]
Expand Down

0 comments on commit 5e47f8e

Please sign in to comment.