ModifyTextureMapping question

It seems that there is some transform(s) that get associated with a texture mapping that I haven’t been able to figure out. When I ‘modify’ an objects mapping, they don’t always end up where I think they should go. I am modifying the rotation and intervals on a box mapping.

I looked at the primitive and normal transforms in the properties of the mapping, but I can’t decipher what they mean by drawing lines from the object origin to the the transformed point.

So if someone can explain what is going on, that would be good, or just tell me if there is a way to delete the mapping before I modify it. I think that would work as well, as what I am doing now seems to always works as expected on a fresh object with no mapping.

Thanks for any help.

@andy is this something you can help with?

The delete mapping button works as far as allowing my script to run on objects multiple times without the offset:

But the xyz button doesn’t.

If there is a rhinocommon way to do what the delete mapping button does that would be great. If it exists already and I just haven’t found it, please point me in the right direction.

Also, I don’t think I was very clear on what I am doing so here is the texture modifiy part, where mappingPlane and baseInterval are predefined:

objectBoxMap = Rhino.Render.TextureMapping.CreateBoxMapping(plane=mappingPlane, dx=baseInterval, dy=baseInterval, dz=baseInterval, capped=True)
sc.doc.Objects.ModifyTextureMapping(object, 1, objectBoxMap)


I think I can use:
rs.Command("_RemoveMappingChannel 1")
for now.


The additional transform that gets included in the texture mapping calculations is the localXform in the MappingRef on the object attributes. This is used to ensure that when an object is moved, the mapping does not change on the object - the translation is added.

I feel like a dork but I still can’t find this transform. Are you talking about this?:

Which in python I think is:

But I only ever get back the mapping, and never a tuple with a transform…

I can’t find anything about ‘MappingRef’ in the python Rhino tree or on the rhinocommon doc page…do you mean MappingTag? It looks like it has a transform:

But I can’t figure out how to get to it from the doc object.

If you can explain how to get to this localXform it would be good to know. Otherwise I found I can use:

sc.doc.Objects.Select(objectIds=objects, select=True)
rs.Command("_RemoveMappingChannel 1")

It works and isn’t too slow, but seems inelegant.

Also, if I can get this localXform then my script could work in world or the local space, which would be quite useful.

I finally figured out my problem with the Rhino.DocObjects.RhinoObject.GetTextureMapping() function. I thought I would post it here in case anyone else is stuck.

First, I was not familiar with this practice of passing an object to a function and the function modifies or ‘fills in’ that object. This is required for the transform part.

Secondly, for some reason, you have to use a ‘Strong Box’ version of the transform object. I have no idea what this really means, but, thanks to some other post I found out it is something to do with VB and/or CLR.

So here is a working (at least here) way to get the mapping object and the transform that is applied to keep the mapping lined up with the geometric object:

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
import clr

guid = rs.GetObject("select texture mapped object")

rObject = rs.coercerhinoobject(guid)
#Rhino.Geometry.Transform object to be 'filled in' by the GetTextureMapping function
#Also the mystery 'StrongBox' version, otherwise you get an error...
mapXform = clr.StrongBox[Rhino.Geometry.Transform]()

print "this is the Rhino.Render.TextureMapping object:"
print rObject.GetTextureMapping(1, mapXform)
print "this is the 'filled in' 'localXform':"
print mapXform
1 Like