Coder Social home page Coder Social logo

csg's People

Contributors

praeclarum 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

csg's Issues

Writing .STL string doesn't create convex model

When writing the result of a Subtract operation to an stl file using .ToStlString() it appears that the result has triangles with open edges:
image
(Made visible using Autodesk Meshmixer (freeware))
Feeding such a model back into the library for new boolean operations causes issues, eventually leading to an infinite loop.

Is it possible to:
Write a convex .stl file, in which all triangle edges share 2, and only 2, triangles?
Or skip the .stl part all together and get a list of triangles, in which all edges share 2, and only 2, triangles?

Vertices Orden

Hello,

First of all, Great work! I think you have done very hard work with your CSG library.

Now, I am trying to create a Viewer on SharpGL to visualize the SOLIDS. So I am trying to convert your polygons to be drawn by SharopGL however I dont get any good results at all. I tried two main methods, but non of them worked well. And basically it is because, I dont know exactly the order of the vertices.

To illustrate my situation, I created the following simple case:

float radius_gear  = 10;
float radius_teeth = 1;
Solid gear   = Solids.Cylinder(radius_gear, 0.6, true);
Solid tooth = Solids.Cylinder(radius_teeth, 1.2, true).Translate(radius_gear, 0, 0);
Solid final   = Solids.Difference(gear, tooth);

Approach 1 Simple Straight forward approach

// Get the Vertices from the Solid
var verts = csg.
                  Polygons.
                   SelectMany(x => x.Vertices).
                    Select(ToSCNVector3).
                    ToArray();
.
.
.
// Draw the Mesh based on the grabbed vertices
gl.Begin(OpenGL.GL_TRIANGLE_STRIP);  // I tried different methods here

for (int i = 0; i < verts .Length; i += 3)
    gl.Vertex((float)verts [i].X, (float)verts [i].Y, (float)verts [i].Z);  
            
gl.End();

image

Approach 2 Converting Polygon to Polygon in Quads

        private void DrawSolid(OpenGL gl, Solid pSolid)
        {
            foreach (var poly in pSolid.Polygons)
            {
                gl.Begin(OpenGL.GL_QUADS);
                for(int i=0; i < poly.Vertices.Count; i++)
                    gl.Vertex((float)poly.Vertices[i].Pos.X, (float)poly.Vertices[i].Pos.Y, (float)poly.Vertices[i].Pos.Z);  
                gl.End();    
            }
        }

image

Please, could you tell me how the vertices are organized? Or can you point me what i am doing wrong?

Thank you very much in advance!!

Kind Regards,
Ting

Licence?

I think you're forgetting something here.

You wrote in the readme: "This library is a manual port of OpenJsCad's csg.js". that library has the MIT licence, but I didn't find a copy of it anywhere in your project. Porting software to another language is a kind of modification, so you've got to include that licence file.

Subtract leaves trailing vertices

I'm using the substract function to subtract two concave solids from each other, and I've run into an issue where vertices are "left over" from the subtraction process.

Here is a graphical representation of the issue. The subtract process should leave something like this:
CSGeometrySuccess

But instead, the substract function leaves trailing vertices, like this:
CSGeometryFail

Do you know what might be the issue here? Attached is the link to a failing test, and a .json file with the points of a test solid.
https://github.com/OGPowell/Csg/blob/master/Csg.Test/SubtractTest.cs#L62

[[[744.585, 734.575, 97.125],
[1062.208, 734.575, 97.125],
[1062.208, 276.028, 97.125],
[889.654, 276.028, 97.125],
[889.654, 504.099, 97.125],
[744.585, 504.099, 97.125]],

[[744.585, 734.575, 1297.125],
[1062.208, 734.575, 1297.125],
[1062.208, 734.575, 97.125],
[744.585, 734.575, 97.125]],

[[1062.208, 734.575, 1297.125],
[1062.208, 276.028, 1297.125],
[1062.208, 276.028, 97.125],
[1062.208, 734.575, 97.125]],

[[1062.208, 276.028, 1297.125],
[889.654, 276.028, 1297.125],
[889.654, 276.028, 97.125],
[1062.208, 276.028, 97.125]],

[[889.654, 276.028, 1297.125],
[889.654, 504.099, 1297.125],
[889.654, 504.099, 97.125],
[889.654, 276.028, 97.125]],

[[889.654, 504.099, 1297.125],
[744.585, 504.099, 1297.125],
[744.585, 504.099, 97.125],
[889.654, 504.099, 97.125]],
    
[[744.585, 504.099, 1297.125],
[744.585, 734.575, 1297.125],
[744.585, 734.575, 97.125],
[744.585, 504.099, 97.125]],

[[744.585, 734.575, 1297.125],
[744.585, 504.099, 1297.125],
[889.654, 504.099, 1297.125],
[889.654, 276.028, 1297.125],
[1062.208, 276.028, 1297.125],
[1062.208, 734.575, 1297.125]]]

Split solid into disconnected parts

Say I had a solid that represented a large box, and then subtracted from it a large skinny plane through the middle, basically cutting the large box into 2 pieces. Is there a way to detect the fact that the result actually contains 2 separate watertight entities?
I have a simple attempt at this working based on:

  1. Enumerating all of the polygons in the solid
  2. Build a set of graphs where each node is a polygon and each edge means a pair of polygons share a vertex
  3. Detecting the number of connected graphs generated

The above approach feels a bit brute-force, and there are cases where it will fail, such as a pair of cubes whose interiors do not overlap in space but the cubes share a single corner vertex, or share a single edge without faces touching.

Is this idea of "a Solid contains multiple bounded regions" somehow available via your API directly?

using the library from IronPython

hi,

interesting library to be use, i'm loading from IronPython and almost works except in saving. Any hint or suggestion?

regards

2023-10-24 13_24_01-test38 py - SciTE

Unexpected output in some cases.

I'm trying to subtract one mesh from another but it gives a unexpected output.

I have uploaded a zip file with 3 stl files in it.
http://downloads.icore9.com/2019-07-04-09-44-50.zip

I'm running the nuget version 0.3.26.

The first mesh is a representation of a slab of a building, and the second mesh that represents a hole in the slab.
The third is the slab - the hole.

The hole is generated correctly, but other parts of the slab are totally broken.

By the way, some faces of the hole and the slab seem to be coplanar, I don't know if this could cause the problem.

Any help would be appreciated.

Coplanar polygons are not joined

Hi,
Assume that I have a Polygon which is nothing but a rectangle.
I have another Polygon which is also a rectangle and I am subtracting it from the 1st polygon.
(Like subtracting a window from a wall). Both polygons are co-planar.
For simplicity, lets forget about the 3rd dimension

I expect a polygon with 8 points but I am getting 4 polygons.

  1. The rectangle above the window.
  2. The rectangle right side of the window
  3. The rectangle left side of the window
  4. The rectangle below the window.

As all these Polygons are co-planar and connected, I expect a single polygon.

Is it a bug? or Is there a way to join them?

Thanks

Torus implementation

Is there any chance that you might do/have a Torus implementation? So far you have the primitives for:

public static Solid Cube(CubeOptions options)

public static Solid Sphere(SphereOptions options)

public static Solid Cylinder(CylinderOptions options)

Would it be too difficult to develop a Torus method? Or point to somewhere with the code to port it to this library?

Thanks.

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.