Rhino Inside Unity

Dear @stevebaer,

I am trying to load RhinoCommon in Unity.

I have followed the steps in:

I clicked on bat file. Do you know how to solve the issue?
Which files I need to copy to Unity Assets folder to make it work?

The copied one of standard assets to my unity project, but it cannot found rhino:

1 Like

That .bat file is just attempting to copy RhinoCommon.dll out of the Rhino WIP and into the same directory where the .bat file exists.

Your path to the WIP may be different

Thank you for the answer.

But there is a problem with other data structures.
Point3d type is loaded without problem, but Pointcloud data structure searches for other dll from c++.

Is it solvable somehow?

In order for any of this to work, Rhino itself needs to be loaded into the Unity process (Rhino.Inside). Once Rhino is loaded, then the C++ DLLs that things like pointclouds are trying to access will be available.

That is what this code is attempting to do:

It sounds like that code is not properly executing and loading Rhino on your system.

Is it enough to place this file inside Assets folder or do I need to run the script in play mode?

It is enough to just place the dll in that folder. You may want to try Sample 2 to see if that works for you. I wrote it in a slightly different form.

Hi @stevebaer @fraguada , thanks for the amazing work with Rhino.Inside. I am running the 2 samples successfully. I am mostly trying to work in sample2, as I want to use grasshopper and visualize real time in Unity. I am trying to follow what you did with Unreal but I am having a hard time as I have absolutely no idea how Ureal works. Would it be possible for you to upload similar documentation (which is amazing) for Unity as the one you have here:

Thanks again for the great work!

Also noticed that in sample2, when I press show grasshopper, Rhino and GH fire up etc, as they should, but when I press play they shut down.

Solved based on previous solution found here: RhinoCore.Dispose() · Issue #14 · mcneel/rhino.inside · GitHub

Add the line GC.SuppressFinalize(_rhinoCore); at the end of the Launch() method.

This should stop RhinoCore getting Disposed when Unity recompiles (a case of which is going into playMode)

@stevebaer @fraguada the Sample files for Unity are great. In playing with it I am trying to write conversion functions that take the mesh vertices current colors and convert them to unityengine.color types. The code I wrote appears to be fine but I have the recurring issue of not being able to access System.Drawing.Color. Hoping you could provide some insight as to why.


Thanks in advance for your time!
M

I’m not sure if System.Drawing is supported on Unity. You may want to check with Unity on their forums.

As an alternative, I could add a function to give you the list of vertex colors as a list of integers that you could then convert into Unity Colors. Just let me know if this is something you need.

Sure I’d like to see that!

Cheers,

M

Ok, I should be able to get this in for next week’s build
https://mcneel.myjetbrains.com/youtrack/issue/RH-56582

1 Like

I took some Unity programming classes at my local library. It’s a nice engine, but unlike Id-family engines, it doesn’t support NURBS, which is a real killjoy for level design as an art.

With a few ladditional texture-maping methods for repeating textures, nowdraw materials, and a little material-preview work, Rhino could be the defacto computer game level design tool.

Then I guess it is a good thing we have Rhino.Inside😀

Unity use its own system.drawing. Rhino normally references this dll somewhere in pc, while unity wants to compile everything in one package. Just remove that reference and use the unity one.

I had the same issue. Just need to add the System.Drawing dll in your assets. You don’t need to download from external source, it is already in your system. In these folders (or similar of course)

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\

and

C:\Program Files\Unity\Editor\Data\MonoBleedingEdge\lib\mono\

Then add this line in the Convert.cs:

static public Color ToHost(this System.Drawing.Color c) => new Color(c.R,c.G,c.B);

And for the mesh vertex colours add:

 static public List<Color> ToHost(this MeshVertexColorList colors)
    {
        var result = new List<Color>();
        foreach (var c in colors)
            result.Add(c.ToHost());
        return result;
    }

That reference is already removed in the Sample2 project files… Where do you suggest removing that reference from?

Unfortunately, it mapping is presently much too slow, compared to level-editors.

@stevebaer FYI got around it by sending the colors as a text string that gets parsed and assigned to vertex colors in Unity :sweat_smile: . Then assigning a material that uses the ‘Particle/Standard Surface’ shader previews the mesh correctly. This may be a useful temporary solution for those faced with the same problem.