Giter Club home page Giter Club logo

Comments (3)

erictuvesson avatar erictuvesson commented on June 27, 2024

Hi,

I did a little bit of digging and came to the conclusion that the issue is when making a big polygon of all the vertices.
It creates a endless loop creating BSP nodes.
Should look into adding some check so it doesn't just crash without exception.

public void SplitPolygon(Polygon polygon,
List<Polygon> coplanarFront,
List<Polygon> coplanarBack,
List<Polygon> front,
List<Polygon> back)
{
var (type, types) = PossibleTypes(polygon);
switch (type)
{
default:
case PolygonType.Coplanar:
{
if (Vector3.Dot(this.Normal, polygon.Plane.Normal) > 0)
{
coplanarFront.Add(polygon);
}
else
{
coplanarBack.Add(polygon);
}
}
break;
case PolygonType.Front:
{
front.Add(polygon);
}
break;
case PolygonType.Back:
{
back.Add(polygon);
}
break;
case PolygonType.Spanning:
{
List<Vertex> f = new List<Vertex>();
List<Vertex> b = new List<Vertex>();
for (int i = 0; i < polygon.Vertices.Count; i++)
{
int j = (i + 1) % polygon.Vertices.Count;
var ti = types[i];
var tj = types[j];
var vi = polygon.Vertices[i];
var vj = polygon.Vertices[j];
if (ti != PolygonType.Back)
{
f.Add(vi);
}
if (ti != PolygonType.Front)
{
b.Add(vi);
}
if ((ti | tj) == PolygonType.Spanning)
{
var t = (this.W - Vector3.Dot(this.Normal, vi.Position)) /
Vector3.Dot(this.Normal, vj.Position - vi.Position);
var vertex = Helpers.Interpolate(vi, vj, t);
f.Add(vertex);
b.Add(vertex);
}
}
if (f.Count >= 3) front.Add(new Polygon(f));
if (b.Count >= 3) back.Add(new Polygon(b));
}
break;
}
}
private (PolygonType, PolygonType[]) PossibleTypes(Polygon polygon)
{
PolygonType result = 0;
var types = new List<PolygonType>();
for (int i = 0; i < polygon.Vertices.Count; i++)
{
float t = Vector3.Dot(this.Normal, polygon.Vertices[i].Position) - this.W;
var type = (t < -EPSILON) ? PolygonType.Back :
((t > EPSILON) ? PolygonType.Front : PolygonType.Coplanar);
types.Add(type);
result |= type;
}
return (result, types.ToArray());
}

I have not used this library in a production setting yet, so I am not sure how stable it is at scale.

I am a bit surprised this library is faster than something else, I find this extremely slow.
I started working on a big update to the internal workings which will start moving it to real-time performance, unfortunately it got put on hold for now.


I assumed that every 3 vertex builds a triangle based on the data, and got this result.

Hash1:
image

Hash2:
image

Subtract:
image

from csg.

kikootwo avatar kikootwo commented on June 27, 2024

First of all, thank you for the prompt and detailed reply!

I should have been more specific, you were correct in your assumption that the vertices are a large list of triangle data. Every 3 make up a triangle. In my implementation, I am doing the same thing as you (without the fancy linq chunk). I make 1 polygon per triangle.

I tried your newest committed code. I no longer get the stack overflow exception, but I am hitting your new BSPMaxDepthException. I tried returning there, instead of throwing an exception, but then the model is missing its back face. I even tried replacing my polygon building with your linq query version and got the same polygons and the same final result.

Maybe I misunderstood, were you saying this is a known limitation? Or am I still doing something wrong here?

And finally to comment on the speed: Yes, CSG modelling is slow. But you should take pride in the fact that your library is essentially the only C# implementation that I have found actively being developed and in rudimentary tests, performs 4x faster than the other solution I am using.

from csg.

erictuvesson avatar erictuvesson commented on June 27, 2024

I had a look at it, and tried one solution that made it not crash, but it caused a lot of artifacts.

I don't have have the bandwidth right now to look more at the issue. :(

from csg.

Related Issues (8)

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.