Giter Site home page Giter Site logo

pb_csg's Introduction

pb_CSG

A C# port of CSG.js by Evan W for use in the Unity game engine.

Install

To install, simply check out this repository in the My Project/Packages directory.

cd My\ Project/Packages
git clone https://github.com/karl-/pb_CSG.git co.parabox.csg

Quick Start

pb_CSG provides an interface in the CSG class for creating new meshes from boolean operations. Each function (Union, Subtract, Intersect) accepts 2 gameObjects: the left and right side. A new mesh is returned.

Example use:

// Include the library
using Parabox.CSG;

...

// Initialize two new meshes in the scene
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.localScale = Vector3.one * 1.3f;

// Perform boolean operation
Model result = CSG.Subtract(cube, sphere);

// Create a gameObject to render the result
var composite = new GameObject();
composite.AddComponent<MeshFilter>().sharedMesh = result.mesh;
composite.AddComponent<MeshRenderer>().sharedMaterials = result.materials.ToArray();

Result:

pb_csg's People

Contributors

garyholiday avatar karl- avatar mechwarrior99 avatar miguelcanosantana avatar neatsketch avatar paulo-els avatar paulorenanmelo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pb_csg's Issues

50% of the time causes a stackoverflow exception when using standard subtract demo

StackOverflowException: The requested operation caused a stack overflow.
System.Collections.Generic.List1[T].set_Capacity (System.Int32 value) (at <03bd9b261dff4c2b8b568aca27f561b2>:0) System.Collections.Generic.List1[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.List1[T] coplanarFront, System.Collections.Generic.List1[T] coplanarBack, System.Collections.Generic.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.List1[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.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

Mesh substraction results in non centered mesh

If I substract a cube from another one like this
image

Depending on the cutter mesh position it will result in a non centered mesh with an offset corresponding to the original meshToCut position

image

My MeshCutter is on the CubeCutter and looks like this

image

Thank you for your help !

2D drawing from 3d

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

TLS Allocator ALLOC_TEMP_TLS, underlying allocator ALLOC_TEMP_MAIN has unfreed allocations, size 96

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.

Is This Still Possible

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

Bug fix with u [CSG_Model.cs]

I just purchased this package off of the asset store and ran into an issue when performing a subtraction with no custom material.

U was not null, but the length is 0 which threw an exception.
I did the same check as the line below and it fixed the issue.

2022-05-31 19_16_49-Assignment1Testing (Debugging) - Microsoft Visual Studio
.

Subtraction does not work on 2d meshes

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.

Stack overflow with overlapping polygons

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)

Polygon multiplication bug in Node.AllPolygons()

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);

StackOverflowException because of repeated Union

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.List1[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.List1[T] list) (at Assets/Scripts/CustomLibrary/BooleanOperations/Classes/CSG_Node.cs:125)`

Crashing on high poly subtract

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;

Steps to reproduce

  1. Create a simple cube and simple sphere
  2. Scale sphere to 1.2
  3. Play. Everything works.
  4. Scale cube to 10 and sphere to 12.
  5. Play. Crashes.

image

Complete PR

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!

Trying to do mesh subtraction , of 2 obj's but getting this exception?

Screenshot 2021-08-06 163449
Screenshot 2021-08-06 163426

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.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.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.List1[T] list) (at Assets/pb_CSG-master/pb_CSG-master/CSG/Classes/CSG_Node.cs:117)

Big scale size wavefront mesh failed to intersect...

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.

model
m scale
mm 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?

Subtraction with a Plane does not work properly

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);

image

The name 'CSG' does not exist in the current context

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?)

Intersection creates artifact

When I intersect a standard cube and a standard sphere there is an artifact in the corner:
image
It doesn't matter if I move the objects. The problem also appears if there are no zero-width situations.

Error with subtraction

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)

Subtracting two meshes, this is the results, am I expecting too much or have I messed something up?

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"

https://youtu.be/Z0CE-OYvtvM

Cutting a hole in the wall (Cube in the center of the Cube)

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();

I am getting this error:
image

Are there any import instructions?

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

Mesh substraction issue

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)

Screenshot_13
from the first one (the mask)
Screenshot_11

the resulting mesh is broken like in the screenshot.
Screenshot_12

Is there something I'm missing or doing wrong? The meshes are created as 2d meshes, then ProBuilderized and the faces are extruded.

Check out my Repo for the best version with my own implementation, bug fixes and improvements

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.

Do not have Universal Render Pipeline Support

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.

Scaling mesh

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 ?

multiplying verts on conversion from csg model to unity mesh

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?

Code to be fixed.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.