-
Notifications
You must be signed in to change notification settings - Fork 516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
union of 5 simple objects crashes browser #598
Comments
@SebiTimeWaster interesting... I have a few comments. Math.cos() and Math.sin() expect angles as per radians (0 - 2*PI). And the JSCAD V1 rotate() expects angles as per degrees (0 - 360). So, you need to be careful with those calculations. The bend() function doesn't look correct. I suggest that you test that function heavy. Incorrect calculations on vertices will result in a solid with gaps and / or incorrect polygons. |
can you elaborate on what does not look correct? at least optically i cannot see any gaps or wrong rotated faces. btw, when i do 1, 2, 3, 4 or 6 slices instead of 5, 7, 8, 9 or 10 it works in under 2 seconds, so i presume it is an endless loop / memory leak problem. maybe it happens when a cut directly hits a vertice or something like that. |
Here's something to ponder.. 👍 Try using this test object, and bend it. The result is totally different.
|
yeah, it looks fine and renders in a reasonable time ~10secs, when the parameters are correctly adjusted (segmentation): if you run this with a very low segmentation it produces wrong faces since the curvature of the object is too high for something low poly like a cube. low poly objects is the reason the segments parameter exists. |
There is now an ongoing attempt to fix this in #898 ... with original code from this bug report converted to V2. |
Did some investigation here. The short version is that this To understand what's happening, first I took the script that @hrgdavor made in #898 which was the V2 port of the bug here. It generates a geometry with gaps in it. I simplified the example, replacing the sphere and cylinder with a cuboid. And I reduced the number of slices to 1 so that I could just use the bend function directly: const jscad = require('@jscad/modeling')
const { cuboid } = jscad.primitives
const { union } = jscad.booleans
function main() {
let out = union(
cuboid({ size: [10, 10, 10], center: [0, 0, 10] }),
cuboid({ size: [1, 1, 10], center: [0, 5, 15] }),
)
out = bend(out, 20)
return out
}
const bend = (obj, objRadius) => {
const csg = jscad.geometries.geom3.create()
obj.polygons.forEach((polygon) => {
const vertices = []
polygon.vertices.forEach((vertex) => {
const angleAlpha = vertex[2] / objRadius
const newRadius = objRadius + vertex[1]
const posY = Math.cos(angleAlpha) * newRadius - objRadius
const posZ = Math.sin(angleAlpha) * newRadius
vertices.push([vertex[0], posY, posZ])
})
csg.polygons.push({vertices})
})
return csg
}
module.exports = { main } This shows the There are a couple ways to look at this:
In my opinion, the ideal fix would be that the |
Personally, I was thinking of doing the bend function without booleans, by creating new mesh with polygons split manually, and then applying the bend without changing their association. |
it would be nice to have a native bend function in jscad, my code was just a workaround. |
@SebiTimeWaster not sure what to do now... there's still some hope for a native bend function but that will probably have limitations. How about creating a new issue with some of your thoughts about what the new bend function should be able to do...? |
i dont know how to further proceed here. if im in the mood i might try to fix it (one way could be to cut at all nodes z points, but on complex shapes that would produce incredibly thin slices), but the chances for success are probably rather slim. |
Expected Behavior
that it works
Actual Behavior
when i try to union the 5 elements the attached below script generated or click on "generate stl" (i presume it does a union in the background) the browser tab is not responding anymore until it crashes
Steps to Reproduce the Problem
Specifications
The text was updated successfully, but these errors were encountered: