I’m trying to integrate Rhino.Inside® into a Unity3D application. I have used the Sample project. But I found I can’t use Grasshopper API if I just copied the “Grasshopper.dll” into Unity Asset folder along with “RhinoCommon” dll. The “Grasshopper.dll” can not be loaded. I had following message:
Assembly 'Assets/Standard Assets/RhinoInside/Grasshopper.dll' will not be loaded due to errors:
Unable to resolve reference 'Microsoft.VisualBasic'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'Eto'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'Mono.Cecil'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'GH_Util'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'QWhale.Editor'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'QWhale.Syntax.Parsers'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'Yak'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'Eto.Wpf'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'Rhino.UI'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'QWhale.Common'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'QWhale.Syntax'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
I also managed to copy all the files above or use a csc.rsp file, but it doesn’t work at all.
I have been experimenting with this and have concluded, along with @kike that this is not a good use case for Rhino.Inside. I went through all of the same attempts as you:
Copying the Grasshopper.dll into the project assets folder
Copying other dependencies into the folder
attempting to use the csc.rsp
Using assembly resolving
etc…
The idea for all of these attempts, unfortunately, are based on bad assumptions that I had about how Unity dealt with .Net dlls, and by being blinded by the awesome Sample that @kike posted with the help of @LongNguyen.
The reason this is not a good use case for Rhino.Inside is that the potential solutions which involve Rhino.Inside (described in the link) circumvent the primary benefit of Rhino.Inside, namely having RhinoCommon and Grasshopper’s APIs next to the Unity API.
Though Rhino.Inside.Unity is not a good use case for now, RhinoCommon.Inside.Unity (or RhinoCore.Inside.Unity) is still a great options. Having the abilities to perform advanced modelling operations (especially NURBS) inside Unity app domain is still a big win.
Definitely!
It’s also not as bad as when I wrote before. There might be ways to detect when Rhino is running inside an app with a different runtime (as is the case with Unity and Mono). @stevebaer might have some ideas.
@LongNguyen, thanks to @stevebaer, we have a method of calling into the GH dll which Rhino loads. You can check out Sample 2 to see an example of utilizing this functionality.
You can try to download the sample Unity project here. It has all the instructions you need:
If you want to set up a brand new Unity project manually. There are two main requirement for using RhinoCommon:
The RhinoCommon.dll has to be copied into the Asset folder of your Unity project
Create a C# Script in your Unity project that tells Unity about the main Rhino System folder (in ProgramFiles), because RhinoCommon.dll requires other dlls in that Rhino System folder to function correctly. You can see a sample of this C# script in the sample Unity project above
As you already noticed, using Point3d was working fine for you because Point3d was defined as a struct in RhinoCommon.dll and this struct does not depend on any other classes from other dlls in the Rhino System folder. So it was working fine (same is true for Vector3d and some other lightweight data types that do not depends on the main Rhino System infrastructure). But other things like Mesh, Brep, PointCloud, etc depends on other dlls (typically developed using C++) inside Rhino System so they won’t work unless you tell Unity about Rhino System
I have just updated Rhino WIP, and there is the problem with Unity and RhinoCommon.
Before it worked fine.
I can reference RhinoCommon as before for calling Rhino datastructures in unity.
The problem:
If I load any .dll that references RhinoCommon from RhinoWIP, that .dll cannot be loaded to Unity.
Is it possible to replicate this error in your computer?
I tested simply C# class library with this code that breaks the worfklow:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestUnityRhino
{
public static class Class1
{
public static Rhino.Geometry.Mesh GetMesh() {
Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh();
return mesh;
}
}
}
Och , when I updated the RhinoWIP, the RhinoCommon.dll in Unity was copied from the last build.
When unity was searching for the Rhino directory it gave the error with mis-matching versions.
You cannot see anywhere this error, until you write some code with rhino in unity in not compiled code.
To enable RhinoCommon at runtime, if I remember correctly, you need to use the Unity attribute RuntimeInitializeOnLoadMethod (instead of InitializeOnLoad) for the static class Startup (defined inside Assets/Standard Assets/RhinoInside/Unity.cs)