algorithmic modeling for Rhino
Hi,
Couldn't find much information about this on the forum and I'm still quite a noob...
Is there a way to embed meshes into a C# plugin? I mean, using resources - same way as the icons are specified - is there a method to turn standard mesh formats (.obj, .ply, .stl, etc.) into Rhino meshes without writing my own import functions?
Thanks!
Tags:
Yes this can be done, in several ways (from most recommended to least recommended):
You can use the CommonObjectToByteArray and ByteArrayToCommonObject methods in the Grasshopper.Kernel.GH_Convert class to help you with the first approach.
--
David Rutten
david@mcneel.com
A simple 2 block C# implementation of the first idea:
First block:
private void RunScript(GeometryBase x, ref object A)
{
A = System.Convert.ToBase64String( Grasshopper.Kernel.GH_Convert.CommonObjectToByteArray(x););
}
Second block:
private void RunScript(string x, ref object A)
{
A = GH_Convert.ByteArrayToCommonObject<GeometryBase>(System.Convert.FromBase64String(x));
}
Since the mesh used in this example has many duplicate vertices, there's a good chance it can become quite a bit smaller using easily available techniques (GZipping the bytearray).
It's quite trivial to zip byte arrays using C#, see http://www.dotnetperls.com/gzipstream
Big thanks, both! That's very helpful. Serialization makes a lot of sense, shouldn't be too hard to do.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by