Vertices + Indices => Speckle-Py, distorted results

We are trying to write a connector to our buerli.io CAD system using speckle-py. Our data format for simple meshes is straight forward, a list of x/y/z vertices and a list of indices.

with open('model.scg') as json_data:
    d = json.load(json_data)
    json_data.close()

meshes = d["graphic"]["containers"][0]["meshes"]
firstmesh = meshes[0]
vertices = firstmesh["vertices"]
faces = firstmesh["indices"]

block = Mesh(vertices=vertices, faces=faces)
new_stream_id = client.stream.create(name="triangle")
new_stream = client.stream.get(id=new_stream_id)
transport = ServerTransport(client=client, stream_id=new_stream_id)
hash = operations.send(base=block, transports=[transport])
commid_id = client.commit.create(stream_id=new_stream_id, object_id=hash, message="block made in speckle-py")

In speckle it ends up like this:

We bring the same data to generic threejs like this:

  protected createMesh(mesh: IGraphicMesh, container: IGraphicContainer, color?: number[]) {
    const graphicId = mesh.id
    const loops = mesh.loops
    const type = mesh.properties.surface.type as GraphicType

    const geometry = new THREE.BufferGeometry()
    geometry.setIndex(mesh.indices)
    geometry.setAttribute('position', new THREE.Float32BufferAttribute(mesh.vertices, 3))
    mesh.normals && geometry.setAttribute('normal', new THREE.Float32BufferAttribute(mesh.normals, 3))

What are we doing wrong? And is there a more detailed description available that explains constructs like Mesh in speckle? The source files don’t seem to go into much detail.

Hi @0ca0a

Here is a page describing how the current speckle mesh works. The more special part regards the indices, which are defined in a specific sequence so that n-gons can be supported alongside tris or quads. Basically, each face index sequence is prepended with it’s cardinality.

Let us know if you need more help

Cheers

@alex i think i don’t have access to the page.

Sorry about that :slight_smile: It should work now

The tldr of this is that the SpeckleMesh stores faces in the form of

[ n, v1, v2, v3, vn, … ] where n is usually 3 and the v1, v2, an d v3 are the vertex indices.

I recognised the mesh appearance on the call we had last week. I first suffered this when starting the Navisworks connector - its telltale :spockle_smirk: