Quads V triangles from Rhino

hello :slight_smile:

I have a sample commit from Rhino using 2 layers and 1 mesh per layer.

── layer 1
    ├── mesh 1
── layer 2
    ├── mesh 2

Each mesh has a mix of quads and triangle faces. In this particular example these are cubes with 6 faces that are composed of 4 triangles and 4 quads.

I am able to separate layers and iterate over meshes in each layer. At this stage obj is a base mesh. (from specklepy/objects/geometry.py) I then use obj.vertices to get vertices and obj.faces to get indices.

I am looking for a way to extract whether the vertices and indices are coming from a quad or a triangle face. Is this information stored on the speckle mesh? if not would you have any pointers how to extract this information?

thank you,

Hi @esek,
I think I can answer your question.

For Speckle Mesh objects, the face list should have all the information you need.
Mesh.faces is a flat list of ints. The first int in each face represents the number of vertices in that face.
For example.
3, 0, 1, 2 would be a triangle of points 0, 1, and 2.
4, 2, 3, 4, 5 is a quad of points 2, 3, 4, 5.
5, 0, 1, 2, 3, 4 is an n-gon with 5 vertices, 0, 1, 2, 3, 4.
We also support n-gons of arbitrary size.

If we had a mesh with the above three faces, the face list would look like this (I’ve bolded the first index of each face)

3, 0, 1, 2, 4, 2, 3, 4, 5, 5, 0, 1, 2, 3, 4

However :warning: it is worth noting that most of our connectors (including Rhino) use a slightly different system for triangles and quads. Basically, we used to use a 0 to denote a triangle, and a 1 to denote a quad. Meshes sent from Rhino will use 0 instead of 3, and 1 instead of 4 to keep compatibility with the old system.

So 3, 0, 1, 2 and 0, 0, 1, 2 are equivalent triangles
As are quads 4, 2, 3, 4, 5 and 1, 2, 3, 4, 5

So to be clear, All of our connectors accept receiving either system, but will still send using the old system for tris and quads. The new system was introduced to support n-gons.

1 Like

This is a topic that has been discussed on the forum before Python: Cube created in py not showing up in the viewer - #12 by r_c
Now all of our connectors support the new system, we might consider fully switching to the new system just to make explanations like this simpler :grin:

1 Like

@Jedd thank you for the clarification -this solved my issue. and I will keep an eye for the update so I know when to switch over to the new system for receiving :slight_smile:

Excellent, any other questions feel free to ask.

I’ll let you know if/when we decided to make the switch.
But if you wanted, you should be able to write your code in a way that accepts both systems.

Here is an example of how we convert a speckle mesh to a rhino mesh on receive. That one line if (n < 3) n += 3 handles the old encoding scheme.

Nice! Long live the n-gon

1 Like

In case anyone is interested in handling n-gons, and needs a stream with a few to test with, I thought I’d link a little test stream we use internally.

1 Like