Notifications
Clear all

[Closed] Node Event Callback Question

I want to make a callback that calls a function when the material of an object is changed.

I know that whit the node event callback i can do this, but i don’t understand well how to use it, how to register a callback and how to unregister.

The function i must use is the “materialOtherEvent:” but i don’t know how to use it.

Plase some help

Cheers!

13 Replies

I think i understand how it is working thanks to this post…
http://forums.cgsociety.org/showthread.php?f=98&t=725434&highlight=NodeEventCallback

But i still do not understand well…the node event callback is stored inside a variable?

So i can have a variable in my script, let the variable be undefined, when i want to activate it i store the callback inside the variable and when i want to deactivate it a change the variable to undefined and do a gc light.

Is this ok?

Cheers.

yep

make sure your variable ‘lives’ as long as you need it… which in most cases means you’ll have to make it a global.

mmm not sure if it’s working, i’ll report in a while

It’s not working.

i’m using this function with a checkbox:



fn prico a b = (
 print "i work"
)

on mats changed state do (
	if state == on then (
		callmat = NodeEventCallback materialOtherEvent:prico
		print "soy callbo"
	)
	else (
		callmat = undefined
		gc light:true
		print "me voy"
	)
)


but the callback is not working

ok, i don’t understand anythig…

when i check and uncheck the checkbox many fast times and in the end i left the checkbox checked then the callback is working, if i check only the first time…it is not working… :S

P.S. : but every time i check and uncheck the phrase “soy callbooo” is printed, so the function that activates the callback is working

first… like I said… make sure the variable you assign the node event callback ‘lives’ for as long as you need it… right now you’re assigning it to a variable inside the checkbox’s change state event handler, and then within an if-test at that. Outside of that if-test, the variable doesn’t exist. Make it global before the script.

The other thing you may want to change is the event type; the help file is slightly misleading, you need the ‘materialStructured’ event to detect material assignments;


 global callmat
 
 fn prico a b = (
  print "i work"
 )
 
 rollout roll_test "test" (
 	checkbox mats ""
 	on mats changed state do (
 		if state == on then (
 			callmat = NodeEventCallback materialStructured:prico
 			print "soy callbo"
 		)
 		else (
 			callmat = undefined
 			gc light:true
 			print "me voy"
 		)
 	)
 )
 
 createDialog roll_test
 

Edit: ‘materialOtherEvent’ is used to detect changes to the material itself… e.g. changing the diffuse color of the material used by a node will signal this event.

But i don’t need to see the material assignement, i need to see the material changes, i mean when i change a color, when i change the opacity, etc…

And the variable, sorry i did not write it here, i have the variable defined as global at the top of my script.

So i don’t understand why when i check and unchek 4 or five times fast the it’s working

P.S. :SORRY I DID NOT READ THE LAST PART OF THE POST, TESTING IT

P.S. 2 : that’s exactly what i need

ZeBoxxx your script is doing the same thing, it is working inly if i check and uncheck the checkbox a few times, i don’t understand why is doing that

err… lots of edits… just to make sure: does it work for you now, with the ‘materialOtherEvent’ back in? It works here, at least.

As for toggling quickly… don’t know, haven’t tried; given that you’re garbage collecting repeatedly, I’d say “don’t do that”
( not sure why the node event system was implemented the way it is )

Page 1 / 2