-
-
Notifications
You must be signed in to change notification settings - Fork 19
feat: prevent Z-fighting/flicker in OpenSCAD preview #141
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
base: main
Are you sure you want to change the base?
Conversation
This adds the constant EPSILON to prevent Z-fighting / Z-flicker. Could be conceded "code smell" but is well known OpenSCAD approach: * https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/FAQ#What_are_those_strange_flickering_artifacts_in_the_preview? * https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/CSG_Modelling (search for eps) This makes it easier for the eyes when working in OpenSCAD and preview.
|
This PR is mostly a way to start discussion. I don't know if the added code crud of EPSILON out weights the added bonus of better OpenSCAD experience. This does not limit nor benefit users of Makerworld, only ppl locally using OpenSCAD. |
|
Thanks for this improvement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces the EPSILON constant (0.001) to prevent Z-fighting/flickering artifacts in OpenSCAD preview mode. The constant is added to height/depth dimensions in CSG operations where geometric faces would otherwise be coplanar, following standard OpenSCAD best practices.
Key Changes
- Adds EPSILON constant to
models/core/lib/constants.scadwith clear documentation - Applies EPSILON to prismoid heights and cuboid dimensions in connector arms and lock pin holes across all core component files
- Updates both lib files (which include constants.scad) and makerworld files (which embed constants inline)
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| models/core/lib/constants.scad | Defines EPSILON constant (0.001) with documentation explaining its purpose for preventing Z-fighting |
| models/core/lib/support.scad | Applies EPSILON to lock_pin_hole prismoid height to prevent coplanar faces |
| models/core/lib/lockpin.scad | Applies EPSILON to tension_hole_half dimension to eliminate Z-fighting in tension holes |
| models/core/lib/connector.scad | Applies EPSILON to connector arm cuboids and inner arm dimensions for clean preview rendering |
| models/core/makerworld/support.scad | Duplicates EPSILON definition and applies to lock pins, connector arms, and tension holes |
| models/core/makerworld/lockpin.scad | Duplicates EPSILON definition and applies to lock pins, connector arms, and tension holes |
| models/core/makerworld/connector.scad | Duplicates EPSILON definition and applies to lock pins, connector arms, and tension holes |
|
just tested it locally. Additionally it would be good to adapt the |
|
Yeah, 0.01 is the example from the documentation, it's just me that used a smaller in my template, so should be good to change. The purpose is only to offset a small part that won't show in the final part. I have no experience with alter the epsilon for rendering, only $fn. I think that is doable, but I'm not sure if it might create bugs down the line when rendering. I'm guessing but like a thin wall that gets solid in render but not preview. Maybe doing it as simple as a tenary check? It is common to do for $fn: $fn = $preview ? 32 : 64; https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#$fn Maybe do the same for the value for EPSILON? |
Increase EPSILON in preview to limit Z-fighting artifacts, and decrease
when render.
If EPSILON is 0 it generates an error in BOSL2 math.scad, so I keep it
small even if rendering.
|
there's a |
|
Made a commit that difference the epsilon value depending if preview or rendering. I'm not sure that actually is beneficial or just a static value. The epsilon value in preview is now a magnitude bigger, still very small. I did some tries to setting the epslion to 0, but that generated errors in BOSL2 math.scad so I think that is a nogo. |
yes, it is most commonly used for the $fn setting as in my example. The library might benefit from setting a lower $fn in preview and a higher in render. Thinking of moving that to constants.scad or main.scad It might make gridfinity/base.scad render quicker. Have mostly looked in core and not the models yet so not sure. |
imho settings like $fn or EPSILON shouldn't be actively tweaked in library files. They should be agnostic to that.
Just a fair warning: This one is faulty! The filetting on the edges are not quite right, so the base plate generated from this doesn't 100% adhere to the Gridfinity standard. |
Yes, that seems correct, and the parts/ files. So it get set by the correct caller in respective use case. This is on me, but I always forget makerworld. As you might have noticed I'm mostly for local generated ^^
Yeah, I got that. Was just me trying to familiarise myself with the codebase and look around. I am no OpenSCAD expert, but the cases I'll seen regarding epsilon and the cousin "use a bigger piece to difference()" has been to over cut and dont care between preview and render. If the object that is differneced is a submodule it does not mater that the "diff object" is to big as the submodule will be used as a solid. I don't know which way is better. Anyhow I'm happy if the general concept is brought in as it makes the customisation in OpenSCAD a better user experience. |
|
Is there anything more to discuss or changes I need to do? I would like this to be merged unless it breaks makerworld (which I doubt). Regards |
kellervater
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to see EPSILON as a named parameter in the modules it is being used and ideally set to 0 per default. If that's not possible due to some bosl2 shenanigans, then it shall be set to the smallest value possible as default.
e.g.
module connectorArmOuter(is_foot=false)
---> module connectorArmOuter(is_foot=false, EPSILON=0) # or something very close to 0
This is to prevent a breaking change for the pure purpose of devex while giving everyone the opportunity to set the value higher.
This adds the constant EPSILON to prevent Z-fighting / Z-flicker. Could be conceded "code smell" but is well known OpenSCAD approach:
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/FAQ#What_are_those_strange_flickering_artifacts_in_the_preview?
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/CSG_Modelling (search for eps)
This makes it easier for the eyes when working in OpenSCAD and preview.