Grasshopper

algorithmic modeling for Rhino

I'd like to apply a bitmap to a surface (a mesh representation of the surface would also be fine). 

Right now, to preview the mesh with solid colors, I'm doing this in my GH_Goo<MyClass>:

public virtual void DrawViewportMeshes(GH_PreviewMeshArgs args)
{
Mesh myMesh = new Mesh();
GH_Convert.ToMesh(Value.mySurface(), ref myMesh, GH_Conversion.Both);
DisplayMaterial myDisplayMat = new DisplayMaterial();
args.Pipeline.DrawMeshShaded(myMesh, myDisplayMat );

}

Is there a way to make a DisplayMaterial from a bitmap? I see the DisplayBitmap() class, but it doesn't seem to cast to/ be interchangeable with DisplayMaterial, though I have hope, since they both exist in the the Rhino.Display namespace.

Any help is appreciated!

Views: 600

Replies to This Discussion

I figured it out, in case anyone comes across this in the future:

public virtual void DrawViewportMeshes(GH_PreviewMeshArgs args)
{
Mesh myMesh = new Mesh();
GH_Convert.ToMesh(Value.mySurface(), ref myMesh, GH_Conversion.Both);
DisplayMaterial myDisplayMat = new DisplayMaterial();

bool check = myDisplayMat.SetBitmapTexture("C:\\Users\\Desktop\\e7b1f2c70b7.jpg", true);

args.Pipeline.DrawMeshShaded(myMesh, myDisplayMat )

}

GH_Convert.ToMesh(Value.mySurface(), ref myMesh, GH_Conversion.Both);

Yeah you definitely do not want to create a new mesh on every redraw. That'll really tank the viewport refresh rate.

You'll need to compute the mesh once and cache it, and probably the same with the material. Reading bitmaps off the disk is not exactly something you want to do on every frame (although at least I do believe Rhino has some caching of its own here).

Can you point me in the direction of a method I should use for caching the mesh and the material?

It may get used a lot.. I am using an image as a shorthand way of denoting the bounds of a panel.. (the screenshot is just using a jpg I threw together as a quick example). This custom panel class gets moved around a lot in my plugin, getting analyzed, having things added to it, being selected and filtered, etc.

Attachments:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service