Skip to content

Conversation

@hx2A
Copy link
Collaborator

@hx2A hx2A commented Dec 28, 2025

@villares, below is a working example of our trimesh facets code in py5:

import numpy as np
import py5
from trimesh import creation

# %%

WIDTH, HEIGHT = 800, 800

# pay attention to clockwise vs counterclockwise
linestring = np.array(
    [[0.0, 0.0], [100.0, 0.0], [100.0, 100.0], [50.0, 150.0], [0.0, 100.0], [0.0, 0.0]]
) + np.array([[50.0, 0.0]])


def setup():
    global shape
    py5.size(WIDTH, HEIGHT, py5.P3D)

    py5.fill(255)
    py5.stroke(0)
    py5.stroke_weight(3)

    shape = py5.convert_shape(
        creation.revolve(linestring, angle=0.8 * py5.TWO_PI, sections=128, cap=True),
        draw_facets=True,
        facet_min_angle=0.1,
    )


def draw():
    py5.background(204)
    py5.lights()

    py5.translate(py5.width / 2, py5.height / 2, -200)
    py5.rotate_x(py5.frame_count * 0.01)
    py5.rotate_y(py5.frame_count * 0.02)
    py5.rotate_z(py5.frame_count * 0.015)
    py5.scale(2)

    py5.shape(shape)


py5.run_sketch()

The draw_facets kwarg is assumed to be True when facet_min_angle is used, so in the above example draw_facets=True can be omitted and will yield the same result. The facet_min_angle kwarg is assumed to be 0 when draw_facets=True is used but facet_min_angle is not. I think this is a good design choice and considers your thoughts on from discussion thread somewhere.

Do you like the kwarg names?

@hx2A hx2A merged commit 57facea into py5coding:main Dec 28, 2025
@hx2A hx2A deleted the trimesh-facets branch December 28, 2025 01:29
@villares
Copy link
Collaborator

villares commented Dec 28, 2025

Cool!

I'd have to check again my intuitions about the names and values...

Remind me, what is the result from draw_facets=True (default facet_min_angle=0)? It just cleans/hides the edges embedded in a coplanar region right?

Another complementary vocabulary I've seen in other contexts/software is to talk about the edges not the facets... like hide_edges=True and maybe min_edge_angle. What do you think?

@hx2A
Copy link
Collaborator Author

hx2A commented Dec 28, 2025

Remind me, what is the result from draw_facets=True (default facet_min_angle=0)? It just cleans/hides the edges embedded in a coplanar region right?

Right, exactly. This is the nice facet code we used at Python Brasil.

Another complementary vocabulary I've seen in other contexts/software is to talk about the edges not the facets... like hide_edges=True and maybe min_edge_angle. What do you think?

I like min_edge_angle, that is more clear than facet_min_angle. I find hide_edges=True to be confusing, it makes me think it does the equivalent of no_stroke(). How about instead we use something like draw_facet_edges or simply facet_edges? That would pair well with min_edge_angle.

@villares
Copy link
Collaborator

I'm glad you like min_edge_angle!

My first thought was something like clean_facet_edges ... I still find draw_facet_edges a bit confusing...
Maybe facet_edges is a good compromise, and it is shorter, I wouldn't mind it :)

But now I remember my first idea... not having two separate kwargs... then if needed you could set min_edge_angle to None and it would turn off the feature... I concede this would be harder to find out.

Yet one more option that doesn't require knowing what a facet is: draw_all_edges (True would means the facet feature is turned off, the opposite of the current kwarg way of setting it).

@hx2A
Copy link
Collaborator Author

hx2A commented Dec 28, 2025

My first thought was something like clean_facet_edges ... I still find draw_facet_edges a bit confusing...
Maybe facet_edges is a good compromise, and it is shorter, I wouldn't mind it :)

How about facet_edges and min_edge_angle? And although there are two kwargs, I set it up so that you only need to use one. If you set min_edge_angle to anything it assumes facet_edges is true, and setting facet_edges to true assumes that min_edge_angle is zero. I did it that way because I don't want to have to type min_edge_angle=0, I'd rather only use that kwarg when the angle I want is greater than 0, but it can work that way for people who want it.

@villares
Copy link
Collaborator

How about facet_edges and min_edge_angle ?

Yes this would be OK!

What is the general default if no kwarg is passed? Would the facet_edges be True by default?
I like the idea, even if changes the behaviour of previous sketches...

@hx2A
Copy link
Collaborator Author

hx2A commented Dec 28, 2025

What is the general default if no kwarg is passed? Would the facet_edges be True by default?
I like the idea, even if changes the behaviour of previous sketches...

The default was facet_edges = False, but after thinking about it for a while, I warmed up to the idea of making the default True. It does look cleaner and it adds more value above the default way of how Processing would render a mesh. After all, if you wanted to render a Trimesh object the way Processing does it with every triangle and py5's convert functionality was not available to you, you'd just need to write code like this:

    shape = sketch.create_shape()
    with shape.begin_shape(sketch.TRIANGLES):
        shape.vertices(obj.vertices[obj.faces.ravel()])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants