Texture rotation / scale / offset using RhinoCommon

I am trying to achieve texture transformations using RhinoCommon.
As far as I understand, there might be two way to do this -

  1. Using Rhino.DocObjects.Texture and changing its properties
  2. Using Rhino.Render.RenderTexture and using its methods (SetRotation etc.)

The 2nd approach works for me, although I am interested in knowing how to make the first one work.
I am changing the correct properties and its reflected in the variables when debugging but the viewport does not update and render the texture as expected.

// example using UVW transform property
var material = obj.GetMaterial(true);
var texture = material.GetBitmapTexture();

var xRotate = Transform.Rotation(angleDegrees, basePoint);
var xScale = Transform.Scale(basePoint, 1);
var xTranslate = Transform.Translation(new Vector3d(0,0,0));
texture.UvwTransform = xScale * xRotate * xTranslate;
//example by changing the individual rotation, scale and offset properties
texture.Repeat = new Vector2d(500, 500);
texture.Rotation = 50;
texture.Offset = new Vector2d(100, 0);

I have attached a sample code file and rhino file for testing.

test_TextureRotation.3dm (420.6 KB)
test_TextureRotation.cs (2.6 KB)

Do not attempt the first way, the second way through RenderTexture is the recommended way.

1 Like