karl- / pb_csg Goto Github PK
View Code? Open in Web Editor NEWA C# port of CSG.js by Evan W (http://evanw.github.io/csg.js/).
License: MIT License
A C# port of CSG.js by Evan W (http://evanw.github.io/csg.js/).
License: MIT License
Hello, Karl, I'm a junior programmer from korea.
I have multiple meshes with different scales.
For example, I have a head model with an mm scale and an m scale.
And then, I tried Intersecting this model and cube.
SplitPolygon
method causes stack overflow when I try with an mm scale. (I saw at ver2 patch note about that)
Maybe too many polygons and face cause stack overflows...
On the other hand, I don't have a problem when I try with an m scale.
Is it sensitive at scale?
Do you have any solution in this case?
I'm not good at CSG Algorithm yet, So Could you advise to me?
StackOverflowException: The requested operation caused a stack overflow.
System.Collections.Generic.List1[T].set_Capacity (System.Int32 value) (at <03bd9b261dff4c2b8b568aca27f561b2>:0) System.Collections.Generic.List
1[T].EnsureCapacity (System.Int32 min) (at <03bd9b261dff4c2b8b568aca27f561b2>:0)
System.Collections.Generic.List1[T].AddWithResize (T item) (at <03bd9b261dff4c2b8b568aca27f561b2>:0) Parabox.CSG.Plane.SplitPolygon (Parabox.CSG.Polygon polygon, System.Collections.Generic.List
1[T] coplanarFront, System.Collections.Generic.List1[T] coplanarBack, System.Collections.Generic.List
1[T] front, System.Collections.Generic.List1[T] back) (at Packages/co.parabox.csg/CSG/Classes/Plane.cs:108) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:108)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119) Parabox.CSG.Node.Build (System.Collections.Generic.List
1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs:119)
Parabox.CSG.Node.Build (System.Collections.Generic.List`1[T] list) (at Packages/co.parabox.csg/CSG/Classes/Node.cs
I have two meshes generated at runtime from a set of vertices and triangles. When I try to substract the second mesh (the eyebrow area)
the resulting mesh is broken like in the screenshot.
Is there something I'm missing or doing wrong? The meshes are created as 2d meshes, then ProBuilderized and the faces are extruded.
public void Build(List<CSG_Polygon> list)
{
...
if (list_front.Count > 0)
{
if (this.front == null)
this.front = new CSG_Node();
this.front.Build(list_front);//This will cause a stack overflow.
}
...
}
Is this repository still being updated. I downloaded the example in 2019.4 but the namespace 'Parabox.CSG' was missing. Also package did not download from git from the manager if that was what was intended on the usage readme.
Thanks
Terence Daniels
wholebitmedia
Is it possible to make a hole in a Plane? Unfortunately, the subtraction doesn't work properly in this case.
Is there a solution how I can get a hole in a Plane?
GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
plane.transform.localScale = Vector3.one * 2;
CSG_Model result = Boolean.Subtract(plane, cube);
GameObject composite = new GameObject();
composite.AddComponent<MeshFilter>().sharedMesh = result.mesh;
composite.AddComponent<MeshRenderer>().sharedMaterials = result.materials.ToArray();
Destroy(plane);
Destroy(cube);
I'm subtracting a simple box from a larger, simple box. I think the problem is, the smaller box is completely inside the larger box, but one side is overlapping (think z-fighting) with the outer box. Not sure if this is the issue, but it could be.
StackOverflowException: The requested operation caused a stack overflow.
Parabox.CSG.CSG_Node.Build (System.Collections.Generic.List`1 list) (at Assets/T3DImporter/Submodules/pb_CSG-master/CSG/Classes/CSG_Node.cs:126)
Parabox.CSG.CSG_Node.Build (System.Collections.Generic.List`1 list) (at Assets/T3DImporter/Submodules/pb_CSG-master/CSG/Classes/CSG_Node.cs:126)
Parabox.CSG.CSG_Node.Build (System.Collections.Generic.List`1 list) (at Assets/T3DImporter/Submodules/pb_CSG-master/CSG/Classes/CSG_Node.cs:126)
Parabox.CSG.CSG_Node.Build (System.Collections.Generic.List`1 list) (at Assets/T3DImporter/Submodules/pb_CSG-master/CSG/Classes/CSG_Node.cs:126)
Parabox.CSG.CSG_Node.Build (System.Collections.Generic.List`1 list) (at Assets/T3DImporter/Submodules/pb_CSG-master/CSG/Classes/CSG_Node.cs:126)
I naively assumed that boolean operations would be easy to implement in unity, seeing how efficient they are in Blender, so I stupidly designed this whole concept around their use.
It should be kind of self-explanatory, but I'm generating a mesh for the saw blade and then trying to subtract that shape from a simple cube. Obviously, them staying in the air to visualize the mesh is temporary while figuring this out.
I'm not sure whether I have made a mistake while implementing it, or if my use-case is just too extreme for it to handle?
e: please note that the sawblade mesh is a closed 3d mesh, albeit pretty thin, not a single-sided "plane"
I've been trying to fix this for a couple hours and basically it's getting stuck in a loop and stack overflows. CSG_Node::Build is looping with the same list over and over. So, I put in a check to stop that just to see how far I could get. There's some side effects like this.plane
and this.polygons
don't get set, and the vertices count is off, but it works to about 10% then the rest of the mesh is broken. Still trying to figure that part out. Goal is to take a complex mesh, flip it upside down, and carve out a hole. I figure one problem is this is building the entire model for the brush (what I'm calling it), when it really doesn't need to, which I kind of fixed by putting a height check in CSG::Subtract.
public static List<CSG_Polygon> oldList;
public static List<CSG_Polygon> oldOldList;
public static int oldCount = 0;
// Build a BSP tree out of `polygons`. When called on an existing tree, the
// new polygons are filtered down to the bottom of the tree and become new
// nodes there. Each set of polygons is partitioned using the first polygon
// (no heuristic is used to pick a good split).
public void Build(List<CSG_Polygon> list)
{
if (this.plane == null)
{
this.plane = new CSG_Plane();
}
if (this.polygons == null)
this.polygons = new List<CSG_Polygon>();
if (oldList != null && oldList.Except(list).ToList().Count == 0 && oldOldList != null && oldOldList.Except(list).ToList().Count == 0)
{
oldCount++;
if (oldCount > 10)
{
oldCount = 0;
return;
}
}
oldOldList = oldList;
oldList = list;
Hi and thanks for your work :)
I am working on a project for architects.
I would like to use pb_CSG to insert elements (like doors, windows etc) in walls.
Walls are "just" Unity Cubes rescaled and elements are 3D Models.
When I use pb_CSG, I get this a very strange result where the result mesh is totally broken, too big (like x100), not at the same position etc
Do you have an idea of a solution ?
Hey, I'm new to using Unity and was wondering if you could include instructions in the readme.md about how to import the library into a Unity project, that would be awesome!
Thank you very much,
Hani
I created 2 planar 2d meshes and tried to subtract one from the other. In the method CSG_Node.Subtract, CSG_Node a.AllPolygons returns an empty list. Using 3d meshes it works. Union and Intersect work fine.
EDIT: I have made my repo private because since I uploaded it I have made so many changes and adaptations, and added my own implementations, I have fixed EVERYTHING, I can't believe it... years ago when I first touched this thing it seamed like an impossible feat, I was nowhere near knowledgeable enough to make it happen. I gave up but lately I was drawn back in and I found a way. I plan on selling my adaptation and implementation on the Unity Asset store, I'm so extremely happy with the results and I can't wait to share them and its potentials. I thought about giving it away for free but I have put so much time and effort in to the things that I do and I have nothing to show for it and I think it's about time I reap what I've sown so I can invest in my future and in to other projects I have big visions for.
I will come back when it's available.
I have a function that draws a Cube in 3D:
GameObject DrawMesh3D(Vector3 startPoint, Vector3 endPoint, float width, string name)
{
var between = endPoint - startPoint;
var distance = Vector3.Distance(startPoint, endPoint);
var mesh = GameObject.CreatePrimitive(PrimitiveType.Cube);
mesh.name = name;
mesh.transform.position = startPoint + (between / 2.0f);
mesh.transform.LookAt(endPoint);
mesh.transform.eulerAngles = new Vector3(mesh.transform.eulerAngles.x, mesh.transform.eulerAngles.y - 90f, mesh.transform.eulerAngles.z);
mesh.transform.localScale = new Vector3(distance, 5f, width);
mesh.transform.Translate(new Vector3(2000, 2.5f, 0), Space.World);
mesh.transform.parent = area3D.transform;
return mesh;
}
Next I would like to cut a hole in this Cube. It is a Wall for me. For this I am creating another Cube and want to call a function Subtract
GameObject wall = domaManager.HoleInWall2D.domaElement.DomaObject3D;
GameObject hole = GameObject.CreatePrimitive(PrimitiveType.Cube);
hole.transform.position = cube.transform.position;
hole.transform.localScale = Vector3.one * 1.5f;
// Perform boolean operation
CSG_Model result = Boolean.Subtract(wall, hole);
// Create a gameObject to render the result
var composite = new GameObject();
composite.name = "New Object TEST";
composite.AddComponent<MeshFilter>().sharedMesh = result.mesh;
composite.AddComponent<MeshRenderer>().sharedMaterials = result.materials.ToArray();
Hello man you are awsome i have a question can you help me to draw 2d from 3d object like cad software using unity and thanks
I wanted to use this in my application, but I found that when you perform a subtraction and it converts back from the model to a unity mesh, it multiplies the verticies by a good bit.... how can we avoid shit and get rid of the extra verticies when we convert back?
Hi, I may have found an issue which should be fixed.
When I used CGS.Substruct() for a couple of times, I found Node.polygons.Count had rapidly increased. This was actually caused by
List list = this.polygons;
in CGS/Classes/Node.cs line 171. Since when list changes, this.polygons also changes, the code above should be like
List list = new List(this.polygons);
Sorry if this is just my misunderstanding.
StackOverflowException: The requested operation caused a stack overflow.
Parabox.CSG.CSG_Node.Build (System.Collections.Generic.List1[T] list) (at Assets/pb_CSG-master/pb_CSG-master/CSG/Classes/CSG_Node.cs:104) Parabox.CSG.CSG_Node.Build (System.Collections.Generic.List
1[T] list) (at Assets/pb_CSG-master/pb_CSG-master/CSG/Classes/CSG_Node.cs:117)
Parabox.CSG.CSG_Node.Build (System.Collections.Generic.List1[T] list) (at Assets/pb_CSG-master/pb_CSG-master/CSG/Classes/CSG_Node.cs:117) Parabox.CSG.CSG_Node.Build (System.Collections.Generic.List
1[T] list) (at Assets/pb_CSG-master/pb_CSG-master/CSG/Classes/CSG_Node.cs:117)
I have made my own cube meshes and when I try to do a subtraction i get this error.
IndexOutOfRangeException: Array index is out of range.
Parabox.CSG.CSG_Model..ctor (UnityEngine.GameObject go) (at Assets/CSG/Classes/CSG_Model.cs:39)
Parabox.CSG.CSG.Subtract (UnityEngine.GameObject lhs, UnityEngine.GameObject rhs) (at Assets/CSG/CSG.cs:62)
I was trying to use this library in unity 2021 and the Visual Studio said that the "CSG " name does not exist in the namespace.
I went to look for the PR files to see if maybe that was a solution and it worked.
I just don't anyone else to have to go thorugh that struggle, since the PR fix edit.
Thanks again for this library, is helping me a lot!
i am try to Union 3 cube and i got error when i try union object with the result of the previous operation
StackOverflowException: The requested operation caused a stack overflow. Parabox.CSG.CSG_Node.Build (System.Collections.Generic.List
1[T] list) (at Assets/Scripts/CustomLibrary/BooleanOperations/Classes/CSG_Node.cs:102)
Parabox.CSG.CSG_Node.Build (System.Collections.Generic.List1[T] list) (at Assets/Scripts/CustomLibrary/BooleanOperations/Classes/CSG_Node.cs:125) Parabox.CSG.CSG_Node.Build (System.Collections.Generic.List
1[T] list) (at Assets/Scripts/CustomLibrary/BooleanOperations/Classes/CSG_Node.cs:125)`
The name space of Parabox.CSG can not be recognized when using URP, but run perfectly in normal setup.
Is it because this package dose not support URP?
Error CS0246 The type or namespace name 'Parabox' could not be found (are you missing a using directive or an assembly reference?)
Huge thanks in advance.
solved, I manually load the parabox in to the reference in visual studio, and it now works.
Calling Node.AllPolygons will multiplicate the polygons drastically due to:
List<Polygon> list = polygons;
This breaks the initial data structure due to not copying the data to a new list. The correct code should be:
List<Polygon> list = new List<Polygon>(polygons);
Hey everyone, after using the CGS, the console keep print:
TLS Allocator ALLOC_TEMP_TLS, underlying allocator ALLOC_TEMP_MAIN has unfreed allocations, size 96
Internal: Stack allocator ALLOC_TEMP_MAIN has unfreed allocations, size 96
To Debug, enable the define: DEBUG_STACK_LEAK in StackAllocator.h. This will output the callstacks of the leaked allocations
my Unity version is 2021.3.0f1
Do you have any insights for solving this? Huge thanks in advance.
I imported the project via the git url, but when I try to use it I get these errors:
Assets\Scripts\ShatterExample.cs(34,24): error CS0103: The name 'CSG' does not exist in the current context
Assets\Scripts\ShatterExample.cs(34,9): error CS0246: The type or namespace name 'Model' could not be found (are you missing a using directive or an assembly reference?)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.