Coder Social home page Coder Social logo

net3dbool's Introduction

Net3dBool

This is a port of the java j3dbool library to C#. Some optimazions are added to improve the performance.

Constructive Solid Geometry (CSG) is a modeling technique that uses Boolean operations like union and intersection to combine 3D solids. Read more about CSG on this Wikipedia page

This library implements CSG operations on meshes. All edge cases involving overlapping coplanar polygons in both solids are correctly handled.

screenshot

Documentation

This library provides three CSG operations: union, subtract, and intersect. See the sample Projct for more information.

Contribution

Every kind of contribution is welcome. Feel free to open a pull request. Special thanks to Lars Brubaker for the performance improvements.

net3dbool's People

Contributors

arakis avatar franzsardoma avatar larsbrubaker 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

net3dbool's Issues

Infinite loop in Object3D.splitFaces() method

Hello @arakis,
I noticed that in the class Object3D, under the method splitFaces, specifically in line 329, there are some cases where having this else makes that the 2 for loops enter into an infinite state.

else
{
    i--;
    break;
}

I am checking what could be the cause, I understand that it could be somehow related to the faces of a particular mesh. But do you think you can orientate me into where this issue could be?

I understand from the code, that once it enters to the else, it goes back to a previous face1 value, but if nothing changes and it advances again to i++, it enters again into the else, and the loop begins. But how can I avoid this?

Make Meshes from extrusions

Hi Sebastian,

First of all, thank you for already posting this library, it might be exactly what I was looking for. However, I seem to struggling with another issue. If I try to do the subtraction from Solids I generated myself, I have strange results. I try to do something like this:


protected Solid Extrude_Element_List_To_Net3DBoolSolid(CS2DElmList povElmList, double ldvZ_Start, double ldvZ_End)
        {
            var lovNewCollection = ConvertToCCWPointList(povElmList);

            var lovTuple = Convert_From_Point_Collection_To_Triangles_And_Vertices(lovNewCollection);

            int livNmb_Of_Vertices = lovNewCollection.Count();
            Vector3d[] lovVertices = new Vector3d[livNmb_Of_Vertices * 2];

            List<CSBG_Triangle> lovTriangles = lovTuple.Item1;
            List<CSBG_Vertex> lovCSBG_Vertices = lovTuple.Item2;

            var lovList_Of_Indices = new List<int>();


            foreach (var lovTriangle in lovTriangles)
            {
                double ldvA = lovTriangle.Vertex_B.X * lovTriangle.Vertex_A.Y + lovTriangle.Vertex_C.X * lovTriangle.Vertex_B.Y + lovTriangle.Vertex_A.X * lovTriangle.Vertex_C.Y;
                double ldvB = lovTriangle.Vertex_A.X * lovTriangle.Vertex_B.Y + lovTriangle.Vertex_B.X * lovTriangle.Vertex_C.Y + lovTriangle.Vertex_C.X * lovTriangle.Vertex_A.Y;

                //A = x2y1 + x3y2 + x1y3 and B = x1y2 + x2y3 + x3y1

                if (ldvA < ldvB)
                {
                    lovList_Of_Indices.Add(lovCSBG_Vertices.IndexOf(lovTriangle.Vertex_C));
                    lovList_Of_Indices.Add(lovCSBG_Vertices.IndexOf(lovTriangle.Vertex_B));
                    lovList_Of_Indices.Add(lovCSBG_Vertices.IndexOf(lovTriangle.Vertex_A));


                }
                else
                {
                    lovList_Of_Indices.Add(lovCSBG_Vertices.IndexOf(lovTriangle.Vertex_A));
                    lovList_Of_Indices.Add(lovCSBG_Vertices.IndexOf(lovTriangle.Vertex_B));
                    lovList_Of_Indices.Add(lovCSBG_Vertices.IndexOf(lovTriangle.Vertex_C));

                }

                _ = 5;
            }


            for (int i = 0; i < livNmb_Of_Vertices; i++)
            {
                lovVertices[i] = Convert_From_CSG_Vertex_To_OpenTKVector(lovCSBG_Vertices[i], ldvZ_Start);
                lovVertices[i + livNmb_Of_Vertices] = Convert_From_CSG_Vertex_To_OpenTKVector(lovCSBG_Vertices[i], ldvZ_End);

                lovList_Of_Indices.Add((i + 1) % livNmb_Of_Vertices);
                lovList_Of_Indices.Add(i);
                lovList_Of_Indices.Add(i + livNmb_Of_Vertices);

                lovList_Of_Indices.Add((i + 1) % livNmb_Of_Vertices);
                lovList_Of_Indices.Add(i + livNmb_Of_Vertices);
                lovList_Of_Indices.Add(((i + 1) % livNmb_Of_Vertices) + livNmb_Of_Vertices);
            }

            int livCounter_AWins = 0;
            int livCounter_BWins = 0;

            foreach (var lovTriangle in lovTriangles)
            {
                double ldvA = lovTriangle.Vertex_B.X * lovTriangle.Vertex_A.Y + lovTriangle.Vertex_C.X * lovTriangle.Vertex_B.Y + lovTriangle.Vertex_A.X * lovTriangle.Vertex_C.Y;
                double ldvB = lovTriangle.Vertex_A.X * lovTriangle.Vertex_B.Y + lovTriangle.Vertex_B.X * lovTriangle.Vertex_C.Y + lovTriangle.Vertex_C.X * lovTriangle.Vertex_A.Y;

                //A = x2y1 + x3y2 + x1y3 and B = x1y2 + x2y3 + x3y1

                if (ldvA < ldvB)
                {


                    lovList_Of_Indices.Add(lovCSBG_Vertices.IndexOf(lovTriangle.Vertex_A) + livNmb_Of_Vertices);
                    lovList_Of_Indices.Add(lovCSBG_Vertices.IndexOf(lovTriangle.Vertex_B) + livNmb_Of_Vertices);
                    lovList_Of_Indices.Add(lovCSBG_Vertices.IndexOf(lovTriangle.Vertex_C) + livNmb_Of_Vertices);
                    livCounter_AWins++;
                }
                else
                {


                    lovList_Of_Indices.Add(lovCSBG_Vertices.IndexOf(lovTriangle.Vertex_C) + livNmb_Of_Vertices);
                    lovList_Of_Indices.Add(lovCSBG_Vertices.IndexOf(lovTriangle.Vertex_B) + livNmb_Of_Vertices);
                    lovList_Of_Indices.Add(lovCSBG_Vertices.IndexOf(lovTriangle.Vertex_A) + livNmb_Of_Vertices);
                    livCounter_BWins++;
                }

                _ = 5;
            }

            return new Solid(lovVertices, lovList_Of_Indices.ToArray());
        } ```

and yes, if I draw with Helix toolkit I have the correct drawing, but I think there is something wrong with my orientation and it would be nice if in the library there is a method to generate solids from polygons, just like I described in my StackOverflow Question from a few days ago: [ https://stackoverflow.com/questions/66646403/how-can-i-extrude-a-list-of-2dpoints-to-a-mesh-and-subtract-these-extrusions-in ](this link). Can you please help me out? 


If we find it, I am of course willing to contribute further and also on StackOverflow mention that this library and its possible improvements helped me to solve the problem. :) 


Regards, 
Joachim

Solid.Translate on z axis

public void Translate(double dx, double dy)

You cannot move a Solid object on the z axis.

Happy to do the work, let me know if you want a PR for this.

    /**
    * Applies a translation into a solid
    * 
    * @param dx translation on the x axis
    * @param dy translation on the y axis
    * @param dz translation on the z axis
    */
    public void Translate(double dx, double dy, double dz)
    {
        if (dx != 0 || dy != 0 || dz != 0)
        {
            for (int i = 0; i < Vertices.Length; i++)
            {
                Vertices[i].X += dx;
                Vertices[i].Y += dy;
                Vertices[i].Z += dz;
            }

            DefineGeometry();
        }
    }

Unit Tests

As you already know, this is "just a port" of j3dbool. I never added any unit tests.

If someone could create some unit tests, that would be awesome. The reason is, in the history, we had breaking changes in a few edge cases. So we need fully automated testing in future.

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.