OpenJSCAD.org icon indicating copy to clipboard operation
OpenJSCAD.org copied to clipboard

New Feature: mesh smoothing

Open gfwilliams opened this issue 8 years ago • 9 comments

Hi! I'm really liking OpenJSCAD.

Something I've been after for a while with OpenSCAD is the ability to 'smooth' models (probably via Catmull-Clark subdivision).

For example, if I'm making a box to 3D print, I might want to make a case out of cubes and cylinders, but then 'smooth' out the harsh edges, and finally difference the smooth model with some shapes I want to cut out of the middle of the box.

I had a quick go at it, but I'm a bit stuck by the way the models that come out don't have polygons with vertices that exactly join.

For instance I might get some polygons like this:

+----------------------------------------------+
|                                              |
|                                              |
|                                              |
|                                              |
|                                              |
|                                              |
|                                              |
+--------------A-------------B-----------------+
|              |             |                 |
|              |             |                 |
|              |             |                 |
|              |             |                 |
|              |             |                 |
|              |             |                 |
|              |             |                 |
+--------------+-------------+-----------------+

Where vertices A and B aren't part of the big polygon above, so trying to smooth out triangles will open up a gap. Is there a method like 'getTriangles' that will come up with a properly joined up model?

gfwilliams avatar Mar 06 '17 14:03 gfwilliams

@gfwilliams Not that I know of today. The library is built to optimize the internal mathematics, not optimize the polygons.

Having said that, there are many ways to do one thing. You may find that the library produces the desired polygons using one of those. It's flexible but definitely NOT optimal.

z3dev avatar Mar 24 '17 12:03 z3dev

@gfwilliams I know it has been a while, but to generate triangulated models, what you need to use is CSG.reTesselated()or even better CSG.reTesselated().fixTJunctions() There have been a lot of changes in the past few months and this is now done by default when you export to stl or other formats.

Btw I am a huge fan of Espruino (both the boards and the esp8266 port :)

kaosat-dev avatar Dec 01 '17 19:12 kaosat-dev

For Catmull-Clark subdivision and other types of smoothing, there might be some operators to do that in the future (emphasis on might, we might go through a rewrite of the geometric core of jscad first)

kaosat-dev avatar Dec 01 '17 19:12 kaosat-dev

Great - thanks! I'll take a look.

That'll be a huge help - there's loads of fun stuff you can do on the underlying mesh :)

Should I close this? My underlying question is answered.

If I complete this would you be interested in a PR? I know I did one for adding metaballs a while back (as a way to get some smooth objects :) ) but it didn't really fit with the direction you were headed in.

gfwilliams avatar Dec 02 '17 09:12 gfwilliams

by 'complete this' : do you mean Catmull-Clark subdivision ? Then yes , please! :) I can see that fitting into a general 'smoothing/refinement' operations category.

Very sorry about the Metaballs :( , it is not lost though ! We are still trying to figure out the best way to have a small(er) core and API surface (it is a giant mess right now) and an easy way to add additional utilities easily, but we are slowly getting there. Also your code style used for Metaballs was a nice fit to the direction we are headed (ie functional, a simple function doing one thing well)

Also per our previous discussions : modules WILL be present in the next major release one way or the other, because I still think that is the biggest issue with Jscad (reusable utilities and designs).

kaosat-dev avatar Dec 02 '17 11:12 kaosat-dev

by 'complete this' : do you mean Catmull-Clark subdivision ?

Yes :) Given the likelihood of API changes in the next version I'll probably just paste up a JSCad function and leave you to include it however you want to though?

Can't promise anything though - I'm a bit busy at the moment I'm afraid.

gfwilliams avatar Dec 04 '17 10:12 gfwilliams

@gfwilliams are you still interested in writing some smoothing functionality for JSCAD geometry?

V2 internals are pretty much complete now, so it should be possible to write some additional libraries. I’ve written a few user level functions already, and put those on the JSCAD Community site.

z3dev avatar May 12 '20 10:05 z3dev

See https://rosettacode.org/wiki/Catmull–Clark_subdivision_surface#Python

z3dev avatar Apr 24 '22 06:04 z3dev

Even closer to home... https://github.com/Erkaman/gl-catmull-clark/blob/master/index.js

z3dev avatar Apr 24 '22 07:04 z3dev