Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CSG operations to Shape Tool #25

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
20 changes: 10 additions & 10 deletions Assets/Editor/tests/model/csg/CsgCasesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void TestOne()
Model m = new Model(bounds);
m.AddMesh(shape1);

NUnit.Framework.Assert.IsTrue(CsgOperations.SubtractMeshFromModel(m, spatialIndex, shape2));
NUnit.Framework.Assert.IsTrue(CsgOperations.CsgMeshFromModel(m, spatialIndex, shape2));
}

[Test]
Expand All @@ -82,7 +82,7 @@ public void TestTwo()
Model m = new Model(bounds);
m.AddMesh(shape1);

NUnit.Framework.Assert.IsTrue(CsgOperations.SubtractMeshFromModel(m, spatialIndex, shape2));
NUnit.Framework.Assert.IsTrue(CsgOperations.CsgMeshFromModel(m, spatialIndex, shape2));
}

[Test]
Expand All @@ -109,7 +109,7 @@ public void TestThree()
Model m = new Model(bounds);
m.AddMesh(shape1);

NUnit.Framework.Assert.IsTrue(CsgOperations.SubtractMeshFromModel(m, spatialIndex, shape2));
NUnit.Framework.Assert.IsTrue(CsgOperations.CsgMeshFromModel(m, spatialIndex, shape2));
}

[Test]
Expand All @@ -136,7 +136,7 @@ public void TestFour()
Model m = new Model(bounds);
m.AddMesh(shape1);

NUnit.Framework.Assert.IsTrue(CsgOperations.SubtractMeshFromModel(m, spatialIndex, shape2));
NUnit.Framework.Assert.IsTrue(CsgOperations.CsgMeshFromModel(m, spatialIndex, shape2));
}

[Test]
Expand All @@ -163,7 +163,7 @@ public void TestFive()
Model m = new Model(bounds);
m.AddMesh(shape1);

NUnit.Framework.Assert.IsTrue(CsgOperations.SubtractMeshFromModel(m, spatialIndex, shape2));
NUnit.Framework.Assert.IsTrue(CsgOperations.CsgMeshFromModel(m, spatialIndex, shape2));
}

[Test]
Expand All @@ -190,7 +190,7 @@ public void TestSix()
Model m = new Model(bounds);
m.AddMesh(shape1);

NUnit.Framework.Assert.IsTrue(CsgOperations.SubtractMeshFromModel(m, spatialIndex, shape2));
NUnit.Framework.Assert.IsTrue(CsgOperations.CsgMeshFromModel(m, spatialIndex, shape2));
}

[Test]
Expand All @@ -216,7 +216,7 @@ public void TestSeven()
Model m = new Model(bounds);
m.AddMesh(shape1);

NUnit.Framework.Assert.IsTrue(CsgOperations.SubtractMeshFromModel(m, spatialIndex, shape2));
NUnit.Framework.Assert.IsTrue(CsgOperations.CsgMeshFromModel(m, spatialIndex, shape2));
}

[Test]
Expand All @@ -242,7 +242,7 @@ public void TestEight()
Model m = new Model(bounds);
m.AddMesh(shape1);

NUnit.Framework.Assert.IsTrue(CsgOperations.SubtractMeshFromModel(m, spatialIndex, shape2));
NUnit.Framework.Assert.IsTrue(CsgOperations.CsgMeshFromModel(m, spatialIndex, shape2));
}

[Test]
Expand All @@ -269,7 +269,7 @@ public void TestNine()
Model m = new Model(bounds);
m.AddMesh(shape1);

NUnit.Framework.Assert.IsTrue(CsgOperations.SubtractMeshFromModel(m, spatialIndex, shape2));
NUnit.Framework.Assert.IsTrue(CsgOperations.CsgMeshFromModel(m, spatialIndex, shape2));
}

[Test]
Expand All @@ -296,7 +296,7 @@ public void TestTen()
Model m = new Model(bounds);
m.AddMesh(shape1);

NUnit.Framework.Assert.IsTrue(CsgOperations.SubtractMeshFromModel(m, spatialIndex, shape2));
NUnit.Framework.Assert.IsTrue(CsgOperations.CsgMeshFromModel(m, spatialIndex, shape2));
}
}
}
12 changes: 6 additions & 6 deletions Assets/Editor/tests/model/csg/CsgOperationsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void TestSubtractFromModel()
spatialIndex.AddMesh(meshToAdd);

// Now subtract a big cube from the model:
bool subtracted = CsgOperations.SubtractMeshFromModel(
bool subtracted = CsgOperations.CsgMeshFromModel(
model, spatialIndex, Primitives.AxisAlignedBox(7, Vector3.zero, Vector3.one, 1));
NUnit.Framework.Assert.IsTrue(subtracted);

Expand All @@ -71,7 +71,7 @@ public void TestSubtractFromModel()
NUnit.Framework.Assert.AreEqual(15, model.GetMesh(toIntersect).faceCount);

// Subtract away from the scene to make sure the method returns false.
NUnit.Framework.Assert.IsFalse(CsgOperations.SubtractMeshFromModel(model, spatialIndex,
NUnit.Framework.Assert.IsFalse(CsgOperations.CsgMeshFromModel(model, spatialIndex,
Primitives.AxisAlignedBox(7, Vector3.one * -3, Vector3.one, 1)));
}

Expand Down Expand Up @@ -276,10 +276,10 @@ public void SubtractCubeWithinCube()
MMesh largeCube = Primitives.AxisAlignedBox(1, Vector3.zero, Vector3.one, 1);

// Subtracting large cube from small cube should result in empty space.
NUnit.Framework.Assert.IsNull(CsgOperations.Subtract(smallCube, largeCube));
NUnit.Framework.Assert.IsNull(CsgOperations.DoCsgOperation(smallCube, largeCube));

// Subtracting small cube from large cube should result in just the large cube with an invisible hole.
MMesh results = CsgOperations.Subtract(largeCube, smallCube);
MMesh results = CsgOperations.DoCsgOperation(largeCube, smallCube);
NUnit.Framework.Assert.AreEqual(12, results.faceCount);

// Mesh should still be valid:
Expand All @@ -290,7 +290,7 @@ public void SubtractCubeWithinCube()
public void SubtractCubeOverlappingCube()
{
// Two cubes next to each other, overlapping.
MMesh result = CsgOperations.Subtract(
MMesh result = CsgOperations.DoCsgOperation(
Primitives.AxisAlignedBox(1, new Vector3(-1, 0, 0), Vector3.one, 1),
Primitives.AxisAlignedBox(2, Vector3.zero, Vector3.one, 1));

Expand All @@ -301,7 +301,7 @@ public void SubtractCubeOverlappingCube()
public void SubtractSphereOverlappingCube()
{
// A cube and a sphere, overlapping.
MMesh result = CsgOperations.Subtract(
MMesh result = CsgOperations.DoCsgOperation(
Primitives.AxisAlignedBox(1, new Vector3(-1, -0.7f, -0.3f), Vector3.one, 2),
Primitives.AxisAlignedIcosphere(2, new Vector3(-.2f, 0, 0), Vector3.one, 1));

Expand Down
Binary file added Assets/Mogwai/Design/Icons/ic_csg_intersect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
116 changes: 116 additions & 0 deletions Assets/Mogwai/Design/Icons/ic_csg_intersect.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Mogwai/Design/Icons/ic_csg_subtract.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
116 changes: 116 additions & 0 deletions Assets/Mogwai/Design/Icons/ic_csg_subtract.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Mogwai/Design/Icons/ic_csg_union.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading