PDA

View Full Version : expression between two nodes?


Sorath
01-13-2011, 03:59 PM
I think I completely miss the point on expressions.
For me they're completely useless.

have two grounds one low res, one high res.

I have one locator.
that one has a custom attr - ground visibility.
which is connected to the highresground.


so either the low res get shown or the highres.
but that seems not to be possible in expressions. since when I add an expression to the attr. I can't edit the attr anymore!!!

does not work:
if (ground_visibility_toggle.ground_visibility = 0) ground.visibility = 1;
if (ground_visibility_toggle.ground_visibility = 1) ground.visibility = 0;

should be a very common problem. how to you peeps proceed?
thxx

pixelranger
01-13-2011, 04:30 PM
Make a scriptJob that checks for attribute change on the locator and then toggles visibility of the grounds.

Sorath
01-13-2011, 04:34 PM
well..
where to put the script job?
I don't have problems with scripting it but I have no clue where to put since I mainly do python..

animatedfox
01-13-2011, 05:37 PM
Expressions are not useless...
If you want to use the expression you have you just need to make one little edit:
You are setting the value of your locator.visibility with your current if statement;
(ground_visibility_toggle.ground_visibility = 0)
You just need to add an extra "=" so that it reads;
(ground_visibility_toggle.ground_visibility == 0)
This will unlock that value as it isn't being set but only queried.

But for a connection as basic as this I would recommend using a reverse node which is lighter than an expression.
Connect the output of locator vis to the hi-res ground vis and then connect the same output to the lo-res ground vis with a reverse node in between.

just my opinion.
Rock it!

Sorath
01-13-2011, 07:40 PM
thanks for your help fox.
reverse in my opinion doesn't work since 0 reversed isn't 1...
or do I get smthng wrong? other than that It could work with a modulo. but where to get that other than through expressions.

but I try the other thing.

animatedfox
01-13-2011, 08:15 PM
Not sure if I was clear in my reverse node suggestion?
If you tried it and it didn't work for you please let me know...

In my experience in Maya land, a Reverse node makes 1s become 0s.
I have found direct connections using nodes are faster to calculate than expressions.
Not a big deal for something like this...but important to keep in mind as you build more elaborate creations.

Hope this helps...and glad we could get this working one way or the other.

pixelranger
01-13-2011, 08:19 PM
0 reversed (or inverted) is definately 1. At least when you invert within a fixed range (i.e. from 0 to 1).

float $inverted = 1-$value; // where $value is between 0 and 1

As for scriptJobs, you don't put them anywhere. They just float around in the virtual vacuum called Mayaland after being declared where they constantly check for events that you specify with the initialization command.
And then they "last" usually throught that Maya session. You kan kill them manually (using the 'scriptJob -k $jobId' command).

Doh, Benjamin beat me to it. Funny we both think of it as a "land" hehe.

norbertnacu
01-13-2011, 08:31 PM
global proc reverseNodeTest()
{
string $ctrlAttr = "groundvis";

string $cmd[] = `polyCube -w 5 -h 5 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 0`;
string $hiRes = $cmd[0];

$cmd = `polyCube -w 2 -h 2 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 0`;
string $loRes = $cmd[0];

$cmd = `spaceLocator`;
string $ctrl = $cmd[0];

addAttr -ln $ctrlAttr -at long -min 0 -max 1 $ctrl;
setAttr -e -k 1 ($ctrl + "." + $ctrlAttr);

string $revNode = `createNode reverse`;

connectAttr -f ($ctrl + "." + $ctrlAttr) ($revNode + ".ix");
connectAttr -f ($ctrl + "." + $ctrlAttr) ($loRes + ".v");
connectAttr -f ($revNode + ".ox") ($hiRes + ".v");

select $ctrl;
}


Select the locator and play around with the "groundvis" attribute.

Thank You,
nn

Sorath
01-13-2011, 08:31 PM
hey.

stupid me.. the first thing I was thinking of - simply do an expression and multiply the value by -1
then my rational thinking sayd, it won't work.

well easy that - the reverse node works like expected. thank you fox!!

for the script job - very nice command, I recommend it now. have seen people trying to embed it into scenes so whenever the scene get's reopened, the script job get's sourced again.
Is there a solution to this already? sourcing script jobs based as saved in proper files..
I can't use it in this case since it'll break out of this reason.

@norbert - woohoo, thanks for sharing! but meantime I got it working see above.

thanks everyone for the kind help.
cheers
B.

NaughtyNathan
01-13-2011, 08:33 PM
yes, 0 reversed is 1. What values do you think a black and white pixel have? :)

:nathaN

Sorath
01-13-2011, 08:34 PM
nathan, thank you.. and it is obvious since we're in binary space.
I was just too long in front of the computer today :(

CGTalk Moderation
01-13-2011, 08:34 PM
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.