SpeckleProperties in Unity from Grasshopper geometry

Hey everyone, I’m new to Speckle and currently trying to find my way around this amazing tool. A few things are a bit unclear at this point. I am trying to use the Unity connector to send Grasshopper geometry to Unity. It works fine with regular meshes but what I am trying to do is also send some metadata together with the geometry. I found out that if you send an actual BIM model from Revit the SpeckleProperties component gets added to the geometry in Unity which lets you retrieve metadata. My question now is how I can achieve the same using only Grasshopper? I played around with “Speckle schema object” and “Create Speckle object” components in Grasshopper but no success so far. Could anyone here point me in the right direction, provide some resources on how to structure my GH script or even share an example GH script with me? Any help would be much appreciated!

Cheers,
Ben

EDIT:
I had a look at the ConverterUnity.cs file and realized that the Unity converter checks for the speckle type before attaching the SpeckleProperties:

//Object is not a raw geometry, convert it as display value element
                    GameObject? element = DisplayValueToNative(speckleObject);
                    if (element != null)
                    {
                        // if (!speckleObject.speckle_type.Contains("Objects.Geometry"))
                        AttachSpeckleProperties(element, speckleObject.GetType(), GetProperties(speckleObject));

                        return element;
                    }

                    return new GameObject();

By getting rid of the if check I’m successfully adding the SpeckleProperties component to my GameObjects which enables me to read the metadata.
I’m still not sure why per default the component does not get attached to objects of type Objects.Geometry. If anyone could clarify I’d be very grateful!

1 Like

Right now, the Unity connector will not attach SpeckleProperties for raw geometry types (Meshes, Breps etc…)

But it will attach for object types that contain geometry (under a displayValue property) e.g. Walls, Floors from Revit.

But you can also send these from grasshopper by wrapping the geometry in a base object, with your custom props using the Create Speckle Object node:

Just make sure the displayValue property is a detached list, where you can add your mesh/meshes. And then you can add as many custom properties to the object as you’d like!.

The result : Speckle

Unfortunately, in Grasshopper, you’ll need to convert the brep to a mesh to perform this workflow. But if your goal is GH → Unity, this should actually give you more control over how the brep is meshified.

3 Likes

To expand on your post edit.

The reason we have this check, is we don’t really want to add speckle properties for geometry.
Vertex data, faces loops, material data, they have all already been converted to the native Unity Mesh.

This is a lot of extra data to keep around in memory, even more so for Breps. And it’s unclear what should happen when this object gets send from Unity → Speckle

Now we could consider only attaching dynamic properties (not instance properties) for geometry types. But this would need some scoping on our end, and our general advice is to not attach dynamic props to raw geoemtry.


That being said, I do see some potential ways we can improve this, especially around breps which can’t currenty be used as displayValue items.

2 Likes

Ok, now it’s all starting to make sense. Thank you @Jedd !

1 Like