Displaying $sphere01.pos on $text01.text in real time

Hi!

I saw Bobo doing an interesting trick in one of his videos where a text displays in real time (on the fly) at the viewport the current position of a sphere while he moves it, I've done a little research and found out that if you use the WHEN construct you can do that:
-

when transform $sphere01 changes do $text01.text = $sphere01.pos as string

-
The problem is that it is too heavy due to the way it computes it (as explained in the end of the help "Change Handlers and When Constructs").

Is there a better way to do that? I wonder how Bobo did it...

Thank you!

-Nelson Baietti

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Nelson Baietti's picture

I've done

I've done it!

----------

text size:30 wirecolor:black dir:[0,-1,0] text:"[0,0,0]"
sphere pos:[0,0,100] wirecolor:black

fn nsnSphCoord =
(
$text01.text = $sphere01.pos as string
)

registerRedrawViewsCallback nsnSphCoord

----------

The code above is just a rough test and not fool proof at all, but it works! Select the sphere and move it around, the text updates with the sphere coords. I hope this helps to automate several other things when required.

Nelson Baietti's picture

I've altered an example from

I've altered an example from the MAXScript help to get to this:

--

tool sphereCoord
(
local theText = text size:30 wirecolor:black dir:[0,-1,0] text:"[0,0,0]"
local theSphere
on mousePoint clickno do
if clickno == 1 then theSphere = sphere pos:worldPoint else #stop
on mouseMove clickno do
(
theSphere.pos = worldPoint
theText.text = theSphere.pos as string
)
)
startTool sphereCoord

--

When you evaluate it it creates a text object and when you (click and drag) the mouse on the viewport, a sphere is created and moved while the text below is updated on the fly with the coordinates. Unfortunately, when when you release the mouse button, the coords cease to update.

I'm still a newb, of course, but I'm still wondering what would work better here, maybe a callback?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.