Grasshopper

algorithmic modeling for Rhino

I thought this may be the ticket to applying texture maps to some objects in GH using

Rhino.sdk in a Legacy component. The geometry component outs okay and I dont have any errors but it doesn't succeed in applying the custom texture map. Any help would be great.

Thanks

Sam

 

 

Private Sub RunScript(ByVal x As OnBrep, ByVal y As Object, ByRef A As Object)
'Trying to apply some custom uvmapping but it's not working!

'Create a Box mapping
Dim ren As New OnTextureMapping

Dim pt1 As New On3dPoint(0, 0, 0)
Dim pt2 As New On3dPoint(5, 0, 0)
Dim pt3 As New On3dPoint(0, 5, 0)
Dim pl As New OnPlane(pt1, pt2, pt3)
Dim dx As New OnInterval(0, 56)

ren.SetBoxMapping(pl, dx, dx, dx, True)


'Add to Texture Map Table
Dim textu As MRhinoTextureMappingTable = doc.m_texture_mapping_table
textu.AddTextureMapping(ren)


'Merge with Geometry
Dim cyl As New MRhinoBrepObject

Dim ty As New onxform
ty.IsZero
Dim renmp As New onmeshparameters
renmp.Default

cyl.SetBrep(x)
cyl.CreateMeshes(ion.mesh_type.render_mesh, renmp)
cyl.SetTextureCoordinates(ren, ty)

'Abject failure
doc.AddObject(cyl)

Views: 3396

Replies to This Discussion

Whaaaa success!!

Nobody cares but its a good feeling anyway

Animation here we come

 


Dim someref As New System.Guid("26dd7978-c4fa-4e59-967f-033cf9249e86")

'Create a Box mapping
Dim ren As New OnTextureMapping

Dim pt1 As New On3dPoint(0, 0, 0)
Dim pt2 As New On3dPoint(5, 0, 0)
Dim pt3 As New On3dPoint(0, 5, 0)
Dim pl As New OnPlane(pt1, pt2, pt3)
Dim dx As New OnInterval(0, 56)

ren.SetBoxMapping(pl, dx, dx, dx, True)
ren.m_mapping_id = someref

'Add to Texture Map Table
Dim textu As MRhinoTextureMappingTable = doc.m_texture_mapping_table
textu.AddTextureMapping(ren)

Dim MCh As New OnMappingChannel
MCh.m_mapping_channel_id = 8
MCh.m_mapping_id = someref

Dim render_uuid As System.Guid = RhUtil.RhinoApp().GetDefaultRenderApp()

Dim RenAttr As New OnObjectRenderingAttributes
RenAttr.AddMappingChannel(render_uuid, 8, someref)


Dim Att As New mrhinoobjectattributes
Att.m_rendering_attributes = RenAttr


Dim cyl As New MRhinoBrepObject
cyl.SetBrep(x)
cyl.ModifyAttributes(att)

doc.AddObject(cyl)

Nice start Thomas,

 

someref could also be System.Guid.NewGuid()

this way you will always have a new Id.

 

- Giulio
________________
giulio@mcneel.com
McNeel Europe

Thanks Giulio,

May I push my luck and also ask if there is any way to exchange objects between Legacy and RhinoCommon components?

In my case this would be attributes or MRhinoBrep objects etc

 If not I guess it is a case of  re writting the rest(not much) of my RhinoCommon stuff back into Legacy for now.

 

Cheers

Hi Thomas,

This is what the Rhino.Runtime.Interop class in RhinoCommon is for.

http://www.rhino3d.com/5/rhinocommon/html/Methods_T_Rhino_Runtime_I...

 

If you aren't finding a function that exchanges what you need, let me know and I'll see what I can do about adding it.

Great pointer Steve, thanks

 Most of these seem to deal with just the underlying geometry though.

It would be nice to have a way to copy through an MRhinoObjectAttributes into RhinoCommon that could then be repatriated to it's geometry. Right now it looks like texture mapping could be sometime before coming in rhinocommon which is a pain for animating.

 

fingers crossed

 

I'm going to bring this thread back to life. I'm trying to map a single bitmap image to a bunch of different triangular panels. I'd like to use a planar mapping that is aligned U along the horizontal matching the triangle's width and V matching the height.

This bit of code seems the most promising, but I'm not sophisticated enough with scripting in Grasshopper to make this work myself. A little help and guidance (hand-holding to be frank) would be greatly appreciated.

if you don't need to use a scripting solution, the Human plug-in offers tools for texture mapping geometry. 

www.food4rhino.com/project/human

I'd be happy to use the Human plug-in, but I couldn't get it to do what I wanted. That may be that I don't know how to use it, so if you have an example definition, I'd be grateful to see it.

Hi Damon - here is an example of how to set up a planar mapping on triangular panels. I've tried to match your description - U is aligned to the triangle's width, and V is aligned to its height. However, the particulars of how the mapping plane/dimensions are obtained may vary with your geometry. 

Attachments:

This works very well... except that I must be missing something: this is only for a preview in Grasshopper, right? Ideally, I'd be creating a texture mapping as part of a property of the object. And furthermore, I think I'd prefer to keep the objects I have in Rhino and just generate the texture mapping, not a new mesh or surface object.

Andrew, thank you for your response. I've learned something that I can definitely use in the future.

PS - I like your plugin very much. I use quite a few of the components on a regular basis.

If you bake the mesh output of the "Planar Mapping" component, and assign it a material in rhino, it will preserve its mapping. As far as modifying the mapping of an object already present in Rhino, this should be possible, but is not something I've incorporated into human. 

Ahh! I see. Well, the only other solution I had found besides using Human was to recreate the surfaces anyway, so I probably recreated the functionality of Human anyway. The biggest difference is that my definition creates surfaces whereas Human creates meshes. I'll see if I convert the mesh to a surface if it keeps the UV mapping and then I bet your version is faster and more simple than mine.

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