place2dTexture question

I have a scene with a rope bridge that has 60+ wooden planks...I'd like to use the same texture on each plank but obviously when rendered the planks will look exactly the same...
so what I thought I'd do is change the translateFrameV value for each plank...of course this would mean a new shader for each plank...which I don't mind as far as scene size goes but it will be very time consuming to create each shader and change the translateFrameV values.
...so...
over the last day or so I have been looking into doing something with mel that will:
1) duplicate one plank with it's SG as many time as I would like
2) change the translateFrameV value for each one using rand()

I am NOT a programmer.
However I have found a few things that I thought would be useful, like
setAttr place2dTexture1.translateV 0.5
which could be used inside a loop...but I can't find a few things:
1) how to select the place2dTexture node of either the currently selected object's SG or of all the SG in a scene
2) how to create a variable (an array I think) of these place2dTexture nodes and use them in a setAttr.. > setAttr place2dTexture"$nodeFromArray".translateV "$amountRandom"

I think this would be a useful script, it could be changed to modify any attribute, or a whole bunch...but I'm really not experienced with mel enough to really tackle this.
any hints or advice would be great.

Michael Goldfarb

Here's a script that plows through what you asked for.. it should be easy enough for you to modify it to taste

//------------------begin
string $oldshader;
string $oldobject;
//the following two strings are assigned manually which is the object that you want duplicated and the shader assigned to it
$oldshader="plankSG";
$oldobject="plank1";

string $newshader[];
string $newobject[];
float $XX;
int $CNT;
int $MAX;
$MAX=60;
$CNT=0;
while($CNT<=$MAX)
{

$XX =rand 1;

//you will have to edit the name of the place texture node to be the same as the one used in the oldshader

setAttr "place2dTexture1.translateFrameU" $XX;
$newshader=duplicate -upstreamNodes $oldshader;
$newobject=duplicate $oldobject;
print $newshader[0];
print $newobject[0];

// assigns new shader to new object
sets -e -forceElement $newshader[0] $newobject[0];
$CNT=$CNT+1;
}
//-------------------end

---a note from our sponsor---
Have you tried searching highend3d?

www.gmask.com
Edited by gmask on 05/31/01 12:36:22 PM.

cool...looks like it may do the trick, thanks
I'll try it tonight when I get back into school and let you know how it turns out...

it's frustrating...I'm finding more and more reasons to learn to program but less and less time to start

thanks again

Michael Goldfarb

it's frustrating...I'm finding more and more reasons to learn to program but less and less time to start

It's not as hard as it looks but it does take practice and it is ever so helpful to pick apart other peoples code :wink:

let me know how that works out for ya.

---a note from our sponsor---
Have you tried searching highend3d?

www.gmask.com

wow, that worked really well!

now all I have to do is figure out how to move all those little guys away from each other...I think I'll investigate "smart Transform" and see if I can't add a little something to that script

thanks again

Michael Goldfarb

well "smart transform" helped a bit but I couldn't get it to work..
so I tried just adding a few things:

//------------------begin
string $oldshader;
string $oldobject;
//the following two strings are assigned manually which is the object that you want

duplicated and the shader assigned to it
$oldshader="plankSG";
$oldobject="plank1";

string $newshader[];
string $newobject[];
float $XX;
float $YY;
int $CNT;
int $MAX;
//Change $gap to the amount of space you want in between each new object
int $gap;
$gap=0;
//$thick is 1/2 the width (or radius) of the object in the direction of translation
int $thick;
$thick=2;
//$moveZ is amount you want the object moved in Z
int $moveZ;
$moveZ=$thick + $gap;
$MAX=5;
$CNT=0;
while($CNT<=$MAX)
{

$XX =rand 1;
$YY =rand 1;

//you will have to edit the name of the place texture node to be the same as the one used

in the oldshader

setAttr "place2dTexture1.translateFrameV" $XX;
setAttr "place2dTexture1.translateFrameU" $YY;
$newshader=duplicate -upstreamNodes $oldshader;
$newobject=duplicate $oldobject; move -r 0 0 $moveZ $newobject;
print $newshader[0];
print $newobject[0];

// assigns new shader to new object
sets -e -forceElement $newshader[0] $newobject[0];
$moveZ=$moveZ+$thick;
$CNT=$CNT+1;
}
//-------------------end;

This works really well for all kinds of objects...except a nurbs cube...???....I get 1 new cube called plank2 then an error thay says "more than one object matches name: plank2"
hmmm...have to work on it somemore...

I figure this can be changed for all sorts of uses...crazy old Maya eh?...need something done? just write a script!!....got to learm programming... :]
thanks again.

Michael Goldafrb

Edited by arctor on 06/01/01 12:03:56 PM.