praeclarum / csg Goto Github PK
View Code? Open in Web Editor NEWSolid modeling library for .NET
License: MIT License
Solid modeling library for .NET
License: MIT License
When writing the result of a Subtract operation to an stl file using .ToStlString() it appears that the result has triangles with open edges:
(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?
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();
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();
}
}
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
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.
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:
But instead, the substract
function leaves trailing vertices, like this:
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]]]
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:
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?
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.
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.
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
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.