Notifications
Clear all

[Closed] Realtime orientation to viewport

Hi all,

I’m currently trying to orient a node to the viewport (User or perspective) using scriptcontroller, but it doesn’t update in realtime.

Here is the rotation_script controller of the node

(inverse (viewport.GetTM()).rotationpart)

I read in other topics that I need to create a variable in the script controller to the reference object, but my reference object is the viewport itself, i.e not a node (as far as I know).

Is there a way to get this working?

7 Replies
 lo1

I think you need to add a viewport changed callback to reevaluate the script controller.

3 Replies
(@groutcho)
Joined: 11 months ago

Posts: 0

That’s what I finally did and it works. Thanks !

(@denist)
Joined: 11 months ago

Posts: 0

if you use #viewportChange callback anyway why do you need the scripted controller?

(@groutcho)
Joined: 11 months ago

Posts: 0

Actually I create billboards on mouseclicks on objects and add them scripted controllers.

You’re right, I could loop through all created billboards and set their rotation on #viewportChange. Let’s try this.

Erm… The result is quite different… and bad.

the original method :

function createBillboardText _text:"Billboard Text" _pos:[0,0,0] _size:100=
  (
  	currText = text text:_text wirecolor:white pos:_pos size:_size
  		
  	scriptController = rotation_script()
  	currText.rotation.controller = scriptController
  	scriptController.script = "(inverse (viewport.GetTM()).rotationpart)"
  	currText
  )

which is updated with the viewport change :

for annotation in rateItAnnotations where (isValidNode annotation.textNode) do 
  annotation.textNode.rotation.controller.Update()

the new method

for annotation in rateItAnnotations where (isValidNode annotation.textNode) do 
  	(annotation.textNode.rotation=(inverse (viewport.GetTM()).rotationpart))

Produces crappy results (object rotating in the wrong direction, and its position moving !)

Thanks, it works. Now I’ve got to figure it.