Receiving Grids and Levels in Unity

I am using the VR example to Receive models into Unity, and it is working incredibly well.
I am keen to gain a bit more control over what is being received, particularly Grids and Levels. Ideally these need to be visualized and referenceable with their associated name. I can see these elements in the online speckle app viewer, so they are being sent from Revit.

How can I go about controlling the incoming information? Which scripts define the objects that come in at runtime? Is there something that I can call to get the receiver to pull in specific stuff, like the grid lines? How can I control the properties that are coming in with each object?

I am hoping that I can simply extend or override classes with my own scripts, or do I have to modify the package? If I have to adjust scripts in the package, what is the recommendation on working with the Speckle Package in Unity?

Thank you very much

Hi,

This does sound like an interesting use case. We’ve tried to expose some ways that you can extend the functionality of the Unity connector, and so I’ll present some options that you may wish to explore.

While we have put some thought into this use case, you may find some rough edges that perhaps you’re willing to help us fix, both for your self and others wanting to extend the conversion capabilities of the Unity Connector.


What we currently expose:

If you take a look at the serialised properties exposed by the RecursiveConverter component, you should find that one of the properties ConverterInstance is of type ISpeckleConverter.

The ISpeckleConverter interface is a broad interface that defines a ConvertToSpeckle, CanConvertToSpeckle, ConvertToNative, and CanConvertToNative` functions, (as well as a couple other members)

By default this will use an instance of a ConverterUnity, and this contains the logic to convert Meshes, Collections, Views etc…
But it is entirely possible for you to swap this out for your own custom implementation of the ISpeckleConverter

How? You may need to re-assign this property on the RecursiveConverter from code, and extend or implement your own ISpeckleConverter. I’ve outlined a couple ideas for how you could do this.


Option 1 : Implement your own ISpeckleCovnerter, copy pasting from ConverterUnity:

You could try implementing your own implementation of ISpeckleConverter, you may need to copy paste a lot from the existing ConverterUnity, as there are many functions you’ll need to reuse.

You can then add your own functionality for Grids etc…

We don’t have the most robust docs, so there may will be some trial and error required. I’m happy to provide some assistance in this regard.


Option 2: Implement your own ISpeckleCovnerter, wrapping a ConverterUnity object:

This should require far less code to pull off. But I think you could write a new class, implementing ISpeckleConverter such that it wraps a ConverterUnity object

You can then add any grid support in the ConvertToNative function, and for other types of objects (like Mesh, simply call the existing converter instance).


Option X:

If the above sill sounds like too much work, and you can see a better path that we could expose or you would like to contribute. Let us know!

We could consider making some of the ConverterUnity functions such as ConvertToNativeGameObject and ConvertGameObjectToSpeckle virtual to allow developers like your selves to make a subclass of ConverterUnity to extend the behaviour as you see fit.

In other connectors we’ve implemented discreet classes for individual conversions, which allows for a more extendable and scalable design.