Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9622613
Add boxes for cylinders
vegasten Jul 25, 2023
7a5d95b
Add shadow box for cones
vegasten Jul 25, 2023
fae052c
Refactor: Extract shadow from composer runner
vegasten Jul 25, 2023
54c4f1f
Create shadow boxes for eccentric cone and ellipsoid segment
vegasten Jul 25, 2023
8749eff
Add shadow for torus segment
vegasten Jul 25, 2023
cf2c74a
Create boxes from instanced meshes
vegasten Jul 27, 2023
cc07e23
Log triangles in shadow sectors
vegasten Jul 28, 2023
5222ed4
Convert the smaller or assumed axis aligned triangle meshes to boxes
vegasten Jul 28, 2023
7984e9e
Skip quads and remove trapeziums
vegasten Jul 28, 2023
7379999
Add size check on toruses to avoid weird stuff on trolla
vegasten Jul 31, 2023
0ee1b86
Return triangle meshes
vegasten Aug 1, 2023
c1663f2
Add priority options and add priorty to APrimitives
vegasten Aug 1, 2023
a002e84
Crudely push prioritized up in depth
vegasten Aug 1, 2023
93b04d7
Add simplify to large trianglemeshes
vegasten Aug 7, 2023
bb1b3b4
Disable simplify
vegasten Aug 7, 2023
b65281a
Fix tests
vegasten Aug 7, 2023
a76e65d
Create a pri sector with highly prioritized nodes
vegasten Aug 9, 2023
e80187b
Cleanup
vegasten Aug 9, 2023
2585f42
Cleanup
vegasten Aug 9, 2023
4838770
Merge branch 'Feature/PrioritizedNodes' into Feature/CourseAndNodesCo…
vegasten Aug 9, 2023
c6ba499
Don't shadow prioritized sectors
vegasten Aug 9, 2023
039925a
Tweak some values
vegasten Aug 10, 2023
22ff6ef
Add tests for shadow creators
vegasten Aug 10, 2023
c0d64f7
Fix torus scaling issue
vegasten Aug 11, 2023
4127403
Revert scaling fix
vegasten Aug 11, 2023
fc1363f
Add shadow of priority sectors
vegasten Aug 15, 2023
d23e4ec
Fix prioritized shadow sector name
vegasten Aug 15, 2023
140720a
Split prioritized sectors (not good)
vegasten Aug 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CadRevealComposer.Exe/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ public class CommandLineOptions
)]
public string? NodeNameExcludeRegex { get; init; } = null;

[Option(
longName: "PrioritizedDiscipline",
Required = false,
HelpText = "A regex matching disciplines to be prioritized in sector splitting. Not case sensitive."
)]
public string? PrioritizedDisciplineRegex { get; init; } = null;

[Option(
longName: "PrioritizedNodeName",
Required = false,
HelpText = "A regex matching node names to be prioritized in sector splitting. Not case sensitive."
)]
public string? PrioritizedNodeNameRegex { get; init; } = null;

[Option(longName: "SplitIntoZones", shortName: 'z', Required = false, HelpText = "Split models into zones.")]
public bool SplitIntoZones { get; init; }

Expand Down
22 changes: 21 additions & 1 deletion CadRevealComposer.Exe/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,31 @@ private static int RunOptionsAndReturnExitCode(CommandLineOptions options)
);
}

if (options.PrioritizedDisciplineRegex != null)
{ // Ensure regex is valid.
if (!RegexUtils.IsValidRegex(options.PrioritizedDisciplineRegex))
throw new ArgumentException(
$"The {nameof(options.PrioritizedDisciplineRegex)} is not a valid regex. Check its syntax. "
+ $"The input was: {options.PrioritizedDisciplineRegex}"
);
}

if (options.PrioritizedNodeNameRegex != null)
{ // Ensure regex is valid.
if (!RegexUtils.IsValidRegex(options.PrioritizedNodeNameRegex))
throw new ArgumentException(
$"The {nameof(options.PrioritizedNodeNameRegex)} is not a valid regex. Check its syntax. "
+ $"The input was: {options.PrioritizedNodeNameRegex}"
);
}

var toolsParameters = new ComposerParameters(
options.NoInstancing,
options.SingleSector,
options.SplitIntoZones,
new NodeNameExcludeRegex(options.NodeNameExcludeRegex)
new NodeNameExcludeRegex(options.NodeNameExcludeRegex),
new PrioritizedDisciplinesRegex(options.PrioritizedDisciplineRegex),
new PrioritizedNodeNamesRegex(options.PrioritizedNodeNameRegex)
);

if (options.SplitIntoZones)
Expand Down
4 changes: 4 additions & 0 deletions CadRevealComposer.Tests/Operations/DrawCallEstimatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public void ConeAndCylinder()
var geometry = new APrimitive[]
{
new Cone(
Matrix4x4.Identity,
0f,
0f,
Vector3.One,
Expand All @@ -40,6 +41,7 @@ public void ConeAndCylinder()
new BoundingBox(-Vector3.One, Vector3.One)
),
new GeneralCylinder(
Matrix4x4.Identity,
0f,
0f,
Vector3.One,
Expand All @@ -64,6 +66,7 @@ public void SolidClosedGeneralConeTorusAndClosedCylinder()
var geometry = new APrimitive[]
{
new Cone(
Matrix4x4.Identity,
0f,
0f,
Vector3.One,
Expand All @@ -85,6 +88,7 @@ public void SolidClosedGeneralConeTorusAndClosedCylinder()
new BoundingBox(-Vector3.One, Vector3.One)
),
new GeneralCylinder(
Matrix4x4.Identity,
0f,
0f,
Vector3.One,
Expand Down
65 changes: 65 additions & 0 deletions CadRevealComposer.Tests/Shadow/ConeShadowCreatorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
namespace CadRevealComposer.Tests.Shadow;

using CadRevealComposer.Primitives;
using CadRevealComposer.Shadow;
using CadRevealComposer.Utils;
using System;
using System.Drawing;
using System.Numerics;

[TestFixture]
public class ConeShadowCreatorTests
{
[Test]
public void ConvertToBox()
{
var matrix = Matrix4x4.Identity;

var centerA = new Vector3(0, 0, 0);
var centerB = new Vector3(0, 0, 2);

var min = new Vector3(-1, -1, 0);
var max = new Vector3(1, 1, 2);
var bb = new BoundingBox(min, max);

var radiusA = 1f;
var radiusB = 2f;
var height = Vector3.Distance(centerA, centerB);

var cone = new Cone(
matrix,
0f,
2 * MathF.PI,
centerA,
centerB,
Vector3.UnitX,
radiusA,
radiusB,
0,
Color.Red,
bb
);

var result = cone.CreateShadow();

Assert.IsTrue(result is Box);

Assert.AreEqual(cone.TreeIndex, result.TreeIndex);
Assert.AreEqual(cone.Color, result.Color);
Assert.AreEqual(cone.AxisAlignedBoundingBox, result.AxisAlignedBoundingBox);

var box = (Box)result;

if (!box.InstanceMatrix.DecomposeAndNormalize(out var scale, out var rotation, out var position))
{
throw new Exception("Failed to decompose matrix to transform. Input Matrix: " + box.InstanceMatrix);
}

var largestRadius = MathF.Max(radiusA, radiusB);
var expectedScale = new Vector3(largestRadius * 2, largestRadius * 2, height);

Assert.AreEqual(expectedScale, scale);
Assert.AreEqual(Quaternion.Identity, rotation);
Assert.AreEqual(Vector3.Zero, position);
}
}
65 changes: 65 additions & 0 deletions CadRevealComposer.Tests/Shadow/CylinderShadowCreatorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
namespace CadRevealComposer.Tests.Shadow;

using CadRevealComposer.Primitives;
using CadRevealComposer.Shadow;
using CadRevealComposer.Utils;
using NUnit.Framework;
using System;
using System.Drawing;
using System.Numerics;

[TestFixture]
public class CylinderShadowCreatorTests
{
[Test]
public void ConvertToBox()
{
var matrix = Matrix4x4.Identity;

var centerA = new Vector3(0, 0, 0);
var centerB = new Vector3(0, 0, 2);

var min = new Vector3(-1, -1, 0);
var max = new Vector3(1, 1, 2);
var bb = new BoundingBox(min, max);

var radius = 2f;
var height = Vector3.Distance(centerA, centerB);

var cylinder = new GeneralCylinder(
matrix,
0f,
2 * MathF.PI,
centerA,
centerB,
Vector3.UnitX,
Vector4.UnitZ,
Vector4.UnitZ,
radius,
0,
Color.Red,
bb
);

var result = cylinder.CreateShadow();

Assert.IsTrue(result is Box);

Assert.AreEqual(cylinder.TreeIndex, result.TreeIndex);
Assert.AreEqual(cylinder.Color, result.Color);
Assert.AreEqual(cylinder.AxisAlignedBoundingBox, result.AxisAlignedBoundingBox);

var box = (Box)result;

if (!box.InstanceMatrix.DecomposeAndNormalize(out var scale, out var rotation, out var position))
{
throw new Exception("Failed to decompose matrix to transform. Input Matrix: " + box.InstanceMatrix);
}

var expectedScale = new Vector3(radius * 2, radius * 2, height);

Assert.AreEqual(expectedScale, scale);
Assert.AreEqual(Quaternion.Identity, rotation);
Assert.AreEqual(Vector3.Zero, position);
}
}
63 changes: 63 additions & 0 deletions CadRevealComposer.Tests/Shadow/EccentricConeShadowCreatorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
namespace CadRevealComposer.Tests.Shadow;

using CadRevealComposer.Primitives;
using CadRevealComposer.Shadow;
using CadRevealComposer.Utils;
using System;
using System.Drawing;
using System.Numerics;

[TestFixture]
public class EccentricConeShadowCreatorTests
{
[Test]
public void ConvertToBox()
{
var matrix = Matrix4x4.Identity;

var centerA = new Vector3(0, 0, 0);
var centerB = new Vector3(0, 0, 2);

var min = new Vector3(-1, -1, 0);
var max = new Vector3(1, 1, 2);
var bb = new BoundingBox(min, max);

var radiusA = 2f;
var radiusB = 3f;
var height = Vector3.Distance(centerA, centerB);

var eccentricCone = new EccentricCone(
matrix,
centerA,
centerB,
Vector3.UnitX,
radiusA,
radiusB,
0,
Color.Red,
bb
);

var result = eccentricCone.CreateShadow();

Assert.IsTrue(result is Box);

Assert.AreEqual(eccentricCone.TreeIndex, result.TreeIndex);
Assert.AreEqual(eccentricCone.Color, result.Color);
Assert.AreEqual(eccentricCone.AxisAlignedBoundingBox, result.AxisAlignedBoundingBox);

var box = (Box)result;

if (!box.InstanceMatrix.DecomposeAndNormalize(out var scale, out var rotation, out var position))
{
throw new Exception("Failed to decompose matrix to transform. Input Matrix: " + box.InstanceMatrix);
}

var largestRadius = MathF.Max(radiusA, radiusB);
var expectedScale = new Vector3(largestRadius * 2, largestRadius * 2, height);

Assert.AreEqual(expectedScale, scale);
Assert.AreEqual(Quaternion.Identity, rotation);
Assert.AreEqual(Vector3.Zero, position);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
namespace CadRevealComposer.Tests.Shadow;

using CadRevealComposer.Primitives;
using CadRevealComposer.Shadow;
using CadRevealComposer.Utils;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

[TestFixture]
public class EllipsoidSegmentShadowCreatorTests
{
[Test]
public void ConvertToBox()
{
var matrix = Matrix4x4.Identity;

var center = new Vector3(0, 0, 0);

var min = new Vector3(-1, -1, 0);
var max = new Vector3(1, 1, 2);
var bb = new BoundingBox(min, max);

var horizontalRadius = 2f;
var verticalRadius = 3f;
var height = 4f;

var ellipsoidSegment = new EllipsoidSegment(
matrix,
horizontalRadius,
verticalRadius,
height,
center,
Vector3.UnitX,
0,
Color.Red,
bb
);

var result = ellipsoidSegment.CreateShadow();

Assert.IsTrue(result is Box);

Assert.AreEqual(ellipsoidSegment.TreeIndex, result.TreeIndex);
Assert.AreEqual(ellipsoidSegment.Color, result.Color);
Assert.AreEqual(ellipsoidSegment.AxisAlignedBoundingBox, result.AxisAlignedBoundingBox);

var box = (Box)result;

if (!box.InstanceMatrix.DecomposeAndNormalize(out var scale, out var rotation, out var position))
{
throw new Exception("Failed to decompose matrix to transform. Input Matrix: " + box.InstanceMatrix);
}

var expectedScale = new Vector3(horizontalRadius * 2, horizontalRadius * 2, height);

Assert.AreEqual(expectedScale, scale);
Assert.AreEqual(Quaternion.Identity, rotation);
Assert.AreEqual(Vector3.Zero, position);
}
}
Loading