I’m currently trying to send some models saved as json files to Speckle via the API, but I’m having some trouble creating surfaces.
It’s straight forward enough to create a stream, create Point objects, and push these up to the stream, with the “Value” field given as xyz cordinates. However, I’m not sure how to create a surface defined by a set of points, or how to create a “zone” defined by a set of surfaces.
The SpeckleMesh object takes in a flattened list of the vertices as an array in the vertices field and then takes in the topology of the faces as such:
- The first entry is ‘0’ for triangles or ‘1’ for quads
- The next three/four entries is the index of the vertices.
For example, this would create a simple square out of triangles:
vertices = [0, 0, 0, 10, 0, 0, 10, 10, 0, 0, 10, 0]
faces = [0, 0, 1, 2, 0, 0, 2, 3]
or using quads:
faces = [1, 0, 1, 2, 3]
One tip for figuring out the schemas is to go into GH and serialize the object you want to convert.
Thanks for the reply Mishael.
I just noticed that when using the quads flag, the mesh is still constructed of triangles based on the order you specify (vertices 0, 1, 2 make up first triangle & vertices 1, 2, 3 make up the second), which means your example doesn’t make a solid rectangular surface but rather this kind of thing:
To make a rectangle work you’d need to specify the faces as something like [1, 1, 0, 2, 3]