how to trigger an expression - simulate object-oriented programming

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  01 January 2006
how to trigger an expression - simulate object-oriented programming

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)?

Last edited by jhall : 01 January 2006 at 06:14 PM.
 
  01 January 2006
Originally Posted by jhall: 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.
 
  01 January 2006
clarification...

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?
 
  01 January 2006
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.
 
  01 January 2006
Originally Posted by euph0rian: 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.
 
  01 January 2006
Originally Posted by jhall: 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...

Last edited by brubin : 01 January 2006 at 07:17 PM.
 
  01 January 2006
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.
 
  01 January 2006
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,
__________________
|| Loka samastaa sukhino bhavantu ||
ash
 
  01 January 2006
sweet. thx.

such a simple thing. extremely illuminating.

Last edited by jhall : 01 January 2006 at 09:53 AM.
 
  01 January 2006
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 11:29 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.