Skip to content

Commit

Permalink
upgrading dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
bertt committed Jul 30, 2024
1 parent f32d22a commit d987cf0
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Triangulator

.NET 6 library for triangulating 2D/3D WKB geometries (PolyhedralSurface/MultiPolygon/Polygon/Multiline/Line) using Earcut algorithm. Lines
.NET 8 library for triangulating 2D/3D WKB geometries (PolyhedralSurface/MultiPolygon/Polygon/Multiline/Line) using Earcut algorithm. Lines
can be triangulated using the TubeGeometry algorithm from Three.JS.

## NuGet
Expand Down
1 change: 0 additions & 1 deletion nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="myget.org" value="https://www.myget.org/F/bertt/api/v3/index.json"/>
</packageSources>
</configuration>
12 changes: 6 additions & 6 deletions src/triangulator.tests/triangulator.tests.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>

<RootNamespace>Triangulate.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="nunit" Version="4.0.1" />
<PackageReference Include="NUnit.Analyzers" Version="4.0.1">
<PackageReference Include="nunit" Version="4.1.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />

<PackageReference Include="SharpGLTF.Toolkit" Version="1.0.0-alpha0031" />
<PackageReference Include="SharpGLTF.Toolkit" Version="1.0.1" />
<PackageReference Include="Wkx" Version="0.5.1" />
</ItemGroup>

Expand Down
70 changes: 70 additions & 0 deletions src/triangulator/Triangulator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using EarcutNet;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Wkx;

Expand Down Expand Up @@ -53,6 +54,75 @@ public static MultiPolygon Triangulate(MultiLineString lineString, float radius
}


public static MultiPolygon Triangulate1(LineString lineString, float radius = 1, int? tubularSegments = 64, int? radialSegments = 8, bool closed = false)
{
if (lineString.Points.Count < 2)
{
throw new ArgumentException("LineString must contain at least 2 points");
}

var polygons = new List<Polygon>();

var points = new List<THREE.Vector3>();
foreach (var point in lineString.Points)
{
points.Add(new THREE.Vector3((float)point.X, (float)point.Y, (float)point.Z));
Debug.WriteLine($"new THREE.Vector3({point.X}, {point.Y}, {point.Z}),");
}

THREE.Curve curve = points.Count == 2 ? new THREE.LineCurve3(points[0], points[1]) : new THREE.CatmullRomCurve3(points);

var divisions = 2;


var splinePoints = new List<THREE.Vector3>();
for (var i = 0; i < points.Count - 1; i++)
{
var start = points[i];
var end = points[i + 1];

splinePoints.Add(start);

for (var j = 1; j <= divisions; j++)
{
var t = j / divisions;
var intermediatePoint = curve.GetPointAt((i + t) / (points.Count - 1));
splinePoints.Add(intermediatePoint);
}

splinePoints.Add(end);
}


var splineCurve = new THREE.CatmullRomCurve3(splinePoints);

var tubeGeometry = new THREE.TubeGeometry(splineCurve, tubularSegments, radius, radialSegments, closed);

foreach (var face in tubeGeometry.Faces)
{
var p0 = tubeGeometry.Vertices[face.a];
var p1 = tubeGeometry.Vertices[face.b];
var p2 = tubeGeometry.Vertices[face.c];

var polygon = new Polygon();
polygon.ExteriorRing.Points.Add(new Point(p0.X, p0.Y, p0.Z));
polygon.ExteriorRing.Points.Add(new Point(p1.X, p1.Y, p1.Z));
polygon.ExteriorRing.Points.Add(new Point(p2.X, p2.Y, p2.Z));
polygon.ExteriorRing.Points.Add(new Point(p0.X, p0.Y, p0.Z));

polygons.Add(polygon);
}

var result = new MultiPolygon
{
Dimension = Dimension.Xyz
};
result.Geometries.AddRange(polygons);
return result;
}



public static MultiPolygon Triangulate(LineString lineString, float radius = 1, int? tubularSegments = 64, int? radialSegments = 8, bool closed = false)
{
if(lineString.Points.Count < 2)
Expand Down
6 changes: 3 additions & 3 deletions src/triangulator/triangulator.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>bertt.triangulator</PackageId>
<Authors>Bert Temme</Authors>
Expand All @@ -21,8 +21,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="THREE" Version="1.0.0" />
<PackageReference Include="Wkx" Version="0.5.1" />
<PackageReference Include="THREE.OpenGL" Version="1.0.0" />
<PackageReference Include="Wkx" Version="0.5.1" />
</ItemGroup>

</Project>

0 comments on commit d987cf0

Please sign in to comment.