How to implement dynamic draw when scaling texture

Hi,
I want to implement a texture scaling command that has real-time draw/preview feedback similar to how other transform commands work - scale, rotate etc. that provide a real-time feedback with mouse events.

Currently, I am scaling a texture (which i fetch from a selected object) using the SetRepeat method but with simple command line inputs to get the U and V values for scaling the texture. I can then use those values to create the scaling vector required.

Select object with Get() → Retrieve RenderMaterial → Then RenderTexture() → SetRepeat()

public virtual void SetRepeat(
Vector3d value,
ChangeContexts changeContext
)

I had a look at the example command files on how to implement dynamic draw.
As far as I can understand, TransformObjects is reponsible for dynamic draw but the TransformObjectList only holds Rhino objects and grips (not textures). There is also the issue of how to apply texture scaling with transform but I might be missing something there. (assuming texture scaling can only be done with SetRepeat).
.
Is there any way/method with Transform commands that can implement dynamic draw on texture (RenderTexture object) ?

// example
var list = new TransformObjectList();
var xform = new Transform();
var _copy = true;
var _autoHistory = true;

// method responsible for dynamic draw preview?
TranformCommand.TransformObjects(list, xform, _copy, _autoHistory);

example command files below:

1 Like

found a way to do this using OnDynamicDraw() from Rhino.Input.Custom.GetTransform class.
override implementation and do what you want before calling base.OnDynamicDraw

 protected override void OnDynamicDraw(Rhino.Input.Custom.GetPointDrawEventArgs e)
 {
     Point3d basePoint;
     if (TryGetBasePoint(out basePoint))
     {
         e.Display.DrawLine(basePoint, RefPoint, System.Drawing.Color.Black);
         e.Display.DrawPoint(RefPoint, System.Drawing.Color.Black);

        // do your transformations here for live feedback
         var texture = exampleTexture; //RenderTexture
         var preview =  true; //preivew option toggle
         if (texture != null && preview)
         {
             var scaleVector = exampleScaleVector;
             var changeContext = RenderContent.ChangeContexts.Script;
             texture.BeginChange(changeContext);
             texture.SetRepeatLocked(false, changeContext);
             texture.SetRepeat(scaleVector, changeContext);
             texture.SetRepeatLocked(true, changeContext);
             texture.EndChange();
         }

         base.OnDynamicDraw(e);
     }
 }