Skip to content

Conversation

@jonathanhogg
Copy link
Owner

@jonathanhogg jonathanhogg commented Nov 26, 2024

This PR adds support for generating meshes from signed distance functions (/fields). It adds a new !sdf model node that takes either a function= attribute or a set of sub-nodes.

The function= attribute takes an actual Flitter function taking a 3-vector position (in the model coordinate system) and returning a signed distance (with the positive is outside convention).

If a set of sub-nodes is given instead then these are evaluated in the same way that a CSG model hierarchy is evaluated except all of the operations and primitives are SDFs. This hierarchy may contain !sdf nodes specifying custom functions.

The !trim, !union, !intersect and !difference nodes are extended to have new smooth=, fillet= and chamfer= attributes that allow for various boundary effects. These only work in an SDF hierarchy and are ignored for normal mesh CSG operations.

The top level !sdf node should also be supplied with minimum= and maximum= attributes taking 3-vectors of the model-coordinate bounds to evaluate the SDF over, and a resolution= attribute giving the density to evaluate the function over as a length in the model coordinate system – smaller values require greater computation. maximum defaults to 1 and minimum defaults to negative maximum.

Add a `__hash__()` function and create missing bits of the context to 
allow for easy VM execution.
This allows creating meshes in new ways. Implementation is built on the 
existing `Model()` class hierarchy with a new `signed_distance()` 
method.
The positive outside convention is just more common in examples found 
online and so I think probably less confusing.
Picks 1/100th of the largest axis range.
Cython seems to be generating bad code with them being cpdef.
Also, ensure that we don't push a `!trim` through another CSG operation 
if either the `!trim` or the other operation involve boundary effects.
This is *very, very* slow and requires the `rtree` package be installed.
@jonathanhogg jonathanhogg added 🚀 enhancement New feature or request 🎨 render Anything to do with rendering (windows, physics, etc.) labels Nov 29, 2024
@jonathanhogg jonathanhogg merged commit fef7559 into main Nov 29, 2024
18 checks passed
@jonathanhogg jonathanhogg deleted the enh_sdf branch November 29, 2024 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🚀 enhancement New feature or request 🎨 render Anything to do with rendering (windows, physics, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants