PDA

View Full Version : how to trigger an expression - simulate object-oriented programming


jhall
01-10-2006, 04:54 PM
i'm trying to program an abstract animation using simple geometry -- cubes and such -- utilizing a simulation approach (not physics based - only using collision). i need different shapes to execute methods i have designed in order to react to collision, for example changing color. from what i have read, it is suggested that expressions only push data to attributes and not get attributes. so other than time or frame, how can i have an expression arbitrarily execute?

at first i thought i could simply add attributes to the objects, such as needsRecoloring (boolean) and just monitor it from an expression ( if (someObj.needsRecoloring = 1) {} ), but that would violate the guideline of not getting attribute information. and i can see why: in a large simulation, each object would have to monitor potentially thousands of other nodes.

i investigated particles as they are designed to evaluate procedures and interact, but they seemed to be focused on what they do best, smoke, flames, etc.

how does one create a procedure for a behavior, attach it to an object, and execute it arbitrarliy (not everyframe)?

brubin
01-11-2006, 03:42 PM
i'm trying to program an abstract animation using simple geometry -- cubes and such -- utilizing a simulation approach (not physics based - only using collision). i need different shapes to execute methods i have designed in order to react to collision, for example changing color. from what i have read, it is suggested that expressions only push data to attributes and not get attributes. so other than time or frame, how can i have an expression arbitrarily execute?

at first i thought i could simply add attributes to the objects, such as needsRecoloring (boolean) and just monitor it from an expression ( if (someObj.needsRecoloring = 1) {} ), but that would violate the guideline of not getting attribute information. and i can see why: in a large simulation, each object would have to monitor potentially thousands of other nodes.

i investigated particles as they are designed to evaluate procedures and interact, but they seemed to be focused on what they do best, smoke, flames, etc.

how does one create a procedure for a behavior, attach it to an object, and execute it arbitrarliy (not everyframe)?

just as a suggestion:

you could create random numbers and see if they are -let's say- divideable by 3, or 17, and use that as a trigger... as arbitrary as it gets..! ;)
so:

int $randNr = rand(0,100) ;
if($randNr % 17 == 0)
{
doSomething();
}


just my 2 pennies worth...
HIH
s.

jhall
01-11-2006, 04:59 PM
brubin thanks for the reply. i think i need to clarify:

how does one trigger a procedure to modify an object based on an event? for example in a standard program, i could have an object with a method that will trigger when an event occurs anywhere in an app. i'm trying to get a similar functionality out of maya. so for example, when an object collides with another (the event), i want to trigger an expression in the object.

is there an efficient method to achieve this pseudo-object-oriented programming style in Maya?

euph0rian
01-11-2006, 05:58 PM
Have you looked into Particle Collision Events? These allow you to execute arbitrary commands when a particle collides with an object...this isn't quite as general as you seem to be looking for, but it does seem to fit the bill for the specific example you gave.

You might also look into the condition and scriptJob commands. This is messy, but you might be able to leverage it into something relatively stable and robust.

jhall
01-11-2006, 06:08 PM
You might also look into the condition and scriptJob commands. This is messy, but you might be able to leverage it into something relatively stable and robust.

thanks for the tip euphorian. i'll check out those two features. it's funny, there isn't a whole lot of documentation on scriptjob in the maya docs, but i'm sure i can find something here or on the web. i've never heard of condition, but i'll check that out too.

brubin
01-11-2006, 06:15 PM
brubin thanks for the reply. i think i need to clarify:

how does one trigger a procedure to modify an object based on an event? for example in a standard program, i could have an object with a method that will trigger when an event occurs anywhere in an app. i'm trying to get a similar functionality out of maya. so for example, when an object collides with another (the event), i want to trigger an expression in the object.

is there an efficient method to achieve this pseudo-object-oriented programming style in Maya?

there is a condition-command, so a fake-collision could be calculated based on proximity to -let's say- the boundingbox or likewise, and "entering the circle" would serve the condition the trigger to execute whatever you want...


scriptJob is a command that handles events and conditions.

drivenkeys are another option.

really depends on what you need done.

and what's a "standard program" anyway? ;)

edit: so while i was thinking 'all of this' up it's all been extensively covered. note to self: stupid do not feel... ;)

jhall
01-11-2006, 06:26 PM
good stuff brubin thanks. i'll check all of these things out in detail. i'm just coming at this from a c++ java background, so i think that way. with maya's node/strict procedural approach, everything seems to be about wiring and pushing as opposed to event driven. it's like designing circuits! lol. well you've given me some great things to check out. thanks.

ashishdantu
01-12-2006, 08:42 AM
hi jhall,,

if i understood it right, u r trying to fire ur custom functions when some "collisions" happen, EVEN if time isnt changing right ?

for this, yes, there can be two ways. one is expressions > in which u can have the collisions test (- like brubin mentioned. ), based on proximity or position matching and if its true, fire ur functions.

another can be same thing, but using utility nodes , where the condition node can be ur IF/else test node. these nodes can be better in terms of speed ... n by default they evaluate, irrespective of time change.

but if u want to try the expressions way, .. one thing i can tell u .. is, expressions have an input from the time node - which make them execute on time change. but theres a small twist to this. if ur expressions host some Direct-DAG connnections, they do evaluate even with out time change. eg : pCube.tx = pSphereShape.radius; << now if u change the radius of the sphere on its shape node, the pCube01 's TX will update... this is b'se its attribute is directly being connected to another objects's attribute which is being changed.

n you can have a look at these threads, which discuss the expressions in real time kinda stuff ..

http://forums.cgsociety.org/showthread.php?t=302746
http://forums.cgsociety.org/showthread.php?t=297118

hope this helps,

jhall
01-12-2006, 08:48 AM
sweet. thx.

such a simple thing. extremely illuminating.

CGTalk Moderation
01-12-2006, 08:48 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.