Hi @owen​,
Please try the attached workspace. It uses JSONFragmenters to break up and flatten the JSON into geometry and property lists, then a bit of Python to build the mesh geometry from the lists.
Â
Hi @owen​,
Please try the attached workspace. It uses JSONFragmenters to break up and flatten the JSON into geometry and property lists, then a bit of Python to build the mesh geometry from the lists.
Â
@daveatsafe​ This is absolutely fantastic, thank you so much. You've really helped us out here!🙌
Hi @owen​,
Sorry, there was a bit of an error in the first workspace - the first value in the faces quartet is a flag, not an index, so the output geometry is a little off. Please try this update.
There also seem to be some sub-elements within some of the features. I will look into ways to extract these as well, if needed.
Hi @owen​,
Sorry, there was a bit of an error in the first workspace - the first value in the faces quartet is a flag, not an index, so the output geometry is a little off. Please try this update.
There also seem to be some sub-elements within some of the features. I will look into ways to extract these as well, if needed.
Thanks again Dave. Yes I did notice that and wondered if it was the order or the vertices but , looks really good now. If you were interested, this is how the Rhino connector builds geometry from Speckle data https://github.com/specklesystems/speckle-sharp/blob/main/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.Geometry.cs#L681
Thanks again Dave. Yes I did notice that and wondered if it was the order or the vertices but , looks really good now. If you were interested, this is how the Rhino connector builds geometry from Speckle data https://github.com/specklesystems/speckle-sharp/blob/main/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.Geometry.cs#L681
Thanks for that link. I did find another codebase that suggests that the flag is to designate 3 or 4 sided faces in the mesh. If you find some data with 4 sided faces, you may want to try the Speckle output to confirm.
There are a couple of ways I could handle the sub-elements:
- create separate feature with a parent id pointing to the main feature
- create the hierarchical geometry structure, with the attributes as geometry traits at the appropriate level
The second method is how we read IFC data, and is a pain to work with for most users. The first method would be the simplest, and I think the most useful. What are your thoughts?
Thanks again Dave. Yes I did notice that and wondered if it was the order or the vertices but , looks really good now. If you were interested, this is how the Rhino connector builds geometry from Speckle data https://github.com/specklesystems/speckle-sharp/blob/main/Objects/Converters/ConverterRhinoGh/ConverterRhinoGhShared/ConverterRhinoGh.Geometry.cs#L681
I think it depends which format you would want to write back to, as to how you would deal with the sub elements. The first option would probably be fine for most use cases, but maybe the second might be required to wrote back to a Speckle stream. It seems like there are instances or referenced objects in there too.
Â
This is great for now anyway. I think it might require a Specke reader or SpeckleConnector transformer, plus a Speckle Manager FME Connector Speckle Connectors
Hi @daveatsafe​, @owen​,
I'm very glad to have found this post, it helped us greatly in processing the JSON output from Speckle. Considering three- and four-sided faces, we changed the python code a bit. For further quests here is the code we use:Â
import fme
import fmeobjects
Â
Â
def makeGeom(feature):
    # read faces and vertices from attributes
    faces = feature.getAttribute('faces{}')
    vertices = feature.getAttribute('vertices{}')
   Â
    # create new Mesh geometry
    mesh = fmeobjects.FMEMesh()
   Â
    # create vertex XYZ from three vertex list entries
    for v in range(int(len(vertices)/3)):
        mesh.appendVertex(verticesev*3],verticesnv*3+1],verticesÂv*3+2])
   Â
    # create face from four or five face list vertex entries
    i = 0
    while i < len(faces):
        if faces i] == 0:
            mesh.addMeshPart(0,ÂfacesÂi+1],facesni+2],faces>i+3]],None,None)
            i = i + 4
        else:
            mesh.addMeshPart(0,bfaces i+1],facesÂi+2],faces i+3],facessi+4]],None,None)
            i = i + 5
       Â
    # set geometry to new Mesh
    feature.setGeometry(mesh)
Â