Maya creating multiple nodes on MEL script

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
Old 05 May 2013   #1
Maya creating multiple nodes on MEL script

Ok I've been writing a MEL script for uni and it's killing me now. Basically I've set up in the code for 2 surface emitters to emit around a globe based on texture rate - green emitter for land, blue emitter for ocean. When I test the script step by step it seems to work. however whenever I run the whole thing it doesn't. The ocean emitter is supposed to read from oceanTexturerRate. But when I run the whole script it for some bizarre reason puts in another 2 texture rates so i end up with

oceanTextureRate
oceanTextureRate1
oceanTextureRate2

and only the texture is applied to the last 1. A similar thing happens with the land except it spurts out 2 nodes

landTextureRate
landTextureRate1

However, this still works because the texture is still applied to both.

Please help!!



Full Code:


file -f -new;

file -import -type "mayaBinary" "scenes/audio_visualiser_BG.mb";

DisplayShadedAndTextured;
//set playback range
playbackOptions -min 1 -max 1000;

proc makeSatellite(){

//create cube and group itself
polyCube -n satellite -w 0.2 -h 0.2 -d 0.2;
group -n satelliteGroup;

//create motion path for cube
circle -n motionPath -c 0 0 0 -nr 0 1 0 -r 15;

//connect satellite to motion path (second cycle)
select satelliteGroup motionPath;
pathAnimation -n motionPathAnimation -stu 0 -etu 90 -c motionPath satelliteGroup;

//select keys at frame 90 and make them linear curves (to remove easing)
selectKey -add -t 0 motionPathAnimation_uValue;
selectKey -add -t 90 motionPathAnimation_uValue;
keyTangent -itt linear -ott linear;

//cycle satellite animation
setAttr "motionPathAnimation_uValue.preInfinity" 3;
setAttr "motionPathAnimation_uValue.postInfinity" 3;

//make satellite spin
select satellite ;
setKeyframe -t 0 -at rotateX;
rotate -r -os 2000 0 0 ;
setKeyframe -t 90 -at rotateX;
keyTangent -itt linear -ott linear;

//make satellite spin animation cycle
select satellite;
setInfinity -poi cycle satellite.rotateX;

//create surface emitter on cube
select satellite;
emitter -n satelliteEmitter -type direction -r 100 -sro 0 -spd 1 -nsp 1;
nParticle -n satelliteParticles;
connectDynamic -em satelliteEmitter satelliteParticles;

//emitter settings
setAttr "satelliteEmitter.rate" 1000;
setAttr "satelliteEmitter.speed" 0;

//particle settings

//particle render type
setAttr "satelliteParticlesShape.particleRenderType" 7;

//lifespan
setAttr "satelliteParticlesShape.lifespanMode" 1;
setAttr "satelliteParticlesShape.lifespan" 0.3;

//size
setAttr "satelliteParticlesShape.radius" 0.05;
setAttr "satelliteParticlesShape.radiusScaleInput" 4;
setAttr "satelliteParticlesShape.radiusScale[1].radiusScale_Interp" 3;

setAttr "satelliteParticlesShape.radiusScale[0].radiusScale_FloatValue" 1;

setAttr "satelliteParticlesShape.radiusScale[1].radiusScale_Position" 0.13;

//turn off collisions and conserve
setAttr "satelliteParticlesShape.selfCollide" 0;
setAttr "satelliteParticlesShape.collide" 0;
setAttr "satelliteParticlesShape.conserve" 0;

//set colour attributes
setAttr "satelliteParticlesShape.colorInput" 1;
setAttr "satelliteParticlesShape.color[0].color_Interp" 2;

setAttr "satelliteParticlesShape.color[0].color_Position" 0;
setAttr "satelliteParticlesShape.color[0].color_Color" -type double3 0.82 0.14 0.13 ;


setAttr "satelliteParticlesShape.color[1].color_Position" 0.1;
setAttr "satelliteParticlesShape.color[1].color_Color" -type double3 0.82 0.5 0.15 ;


//hide satellite cube and motion path
select satellite motionPath;
createDisplayLayer -name "satelliteCubeAndMotionPath";
setAttr "satelliteCubeAndMotionPath.visibility" 0;

}


proc earthSphere(){ //create earth sphere
polySphere -r 10 -n globeSphere;
createDisplayLayer -name "globe";
setAttr "globe.visibility" 0;
}


/* Ocean Particles */
proc oceanParticles(){

//create particles
select globeSphere;
emitter -n oceanEmitter -type direction -r 100 -sro 0 -nsp 1;
nParticle -n oceanParticles;
connectDynamic -em oceanEmitter oceanParticles;

//set 'ocean' particle attributes
setAttr "oceanParticlesShape.lifespanMode" 1;

//set 'ocean' emitter attributes
setAttr "oceanEmitter.rate" 6000;
setAttr "oceanEmitter.emitterType" 2;
setAttr "oceanEmitter.speed" 0;

//set 'ocean' nucleus attributes
setAttr "nucleus1.gravity" 0;

setAttr "oceanParticlesShape.particleRenderType" 8;
//set colour interpolation to none
setAttr "oceanParticlesShape.color[0].color_Interp" 0;
//set particle colour
setAttr "oceanParticlesShape.color[0].color_Color" -type double3 0.01 0.25 0.80;

//enable texture rate
setAttr "oceanEmitter.enableTextureRate" 1;

//create shader node
string $globeShadeNode = `shadingNode -at file -n oceanTextureRate`;

//specify filepath of globe
string $filepath = "sourceimages/globe.tga";

//plug texture into shader node
setAttr -type "string" ( $globeShadeNode + ".fileTextureName" ) $filepath;

//connect texture to emitter texture rate
connectAttr oceanTextureRate.outColor oceanEmitter.textureRate;

}

/* Land Particles */

proc landParticles(){

//create particles
select globeSphere;
emitter -n landEmitter -type direction -r 100 -sro 0 -nsp 1;
nParticle -n landParticles;
connectDynamic -em landEmitter landParticles;

//set 'land' particle attributes
setAttr "landParticlesShape.lifespanMode" 1;

//set 'land' emitter attributes
setAttr "landEmitter.rate" 6000;
setAttr "landEmitter.emitterType" 2;
setAttr "landEmitter.speed" 0;

//set 'land' nucleus attributes
setAttr "nucleus1.gravity" 0;


setAttr "landParticlesShape.particleRenderType" 8;
//set colour interpolation to none
setAttr "landParticlesShape.color[0].color_Interp" 0;
//set particle colour
setAttr "landParticlesShape.color[0].color_Color" -type double3 0.20 0.80 0.20;
/*
if (`exists landParticlesShape.color[1]`) {
removeMultiInstance -break true |landParticles|landParticlesShape.color[1];
}*/

//enable texture rate and emit from dark
setAttr "landEmitter.enableTextureRate" 1;
setAttr "landEmitter.emitFromDark" 1;


//create shader node
string $globeShadeNode = `shadingNode -at file -n landTextureRate`;

//specify filepath of globe
string $filepath = "sourceimages/globe.tga";

//plug texture into shader node
setAttr -type "string" ( $globeShadeNode + ".fileTextureName" ) $filepath;

//connect texture to emitter texture rate
connectAttr -force landTextureRate.outColor landEmitter.textureRate;

//make playback in realtime
playbackOptions -e -playbackSpeed 1;


}

proc int onOpen(string $filename,string $type){

//import sound
doSoundImportArgList ("1", {$filename,"0.0"});

//create audiowave
createNode audioWave;

//plug sound into audiowave
setAttr -type "string" audioWave1.audio "/sound/Clark Kent & Yinyues - Cosmos.wav";

//add track to timeline
setSoundDisplay Clark_Kent___Yinyues___Cosmos 1;

//connect time to audio input
connectAttr -force time1.outTime audioWave1.input;


//connect audiowave to motion path of satellite
connectAttr -f audioWave1.output motionPath1.rotateX;
return true;
}

//select music track file
proc openFile(){
fileBrowser( "onOpen", "Open", "", 0 );
}



proc shootingStar(){
//create shooting star motion path
circle -n starMotionPath -r 50;
//createDisplayLayer -name "starMotionPath";
setAttr "starMotionPath.visibility" 0;

// create emitter for star trail

emitter -n shootingStarEmitter -pos 0 50 0 -type direction -r 100 -spd 1;
nParticle -n shootingStarParticles;
connectDynamic -em shootingStarEmitter shootingStarParticles;

pathAnimation -n emitterMotionPathAnimation -stu 0 -etu 180 -c starMotionPath shootingStarEmitter;

//remove easing
selectKey -add -t 0 emitterMotionPathAnimation_uValue;
selectKey -add -t 180 emitterMotionPathAnimation_uValue;
keyTangent -itt linear -ott linear;

//cycle satellite animation
setAttr "emitterMotionPathAnimation_uValue.preInfinity" 3;
setAttr "emitterMotionPathAnimation_uValue.postInfinity" 3;

//make star particles constant
setAttr "shootingStarParticlesShape.lifespanMode" 0.5;

//set spread of star trail
setAttr "shootingStarEmitter.spread" 1;
setAttr "shootingStarParticlesShape.radius" 0.1;

//set emitter rate
setAttr "shootingStarEmitter.rate" 500;

//set radius scale input to normalised age
setAttr "shootingStarParticlesShape.radiusScaleInput" 2;

//make particles decrease in size over time
setAttr "shootingStarParticlesShape.radiusScale[0].radiusScale_Position" 0;
setAttr "shootingStarParticlesShape.radiusScale[0].radiusScale_FloatValue" 1;

setAttr "shootingStarParticlesShape.radiusScale[1].radiusScale_Position" 1;
setAttr "shootingStarParticlesShape.radiusScale[1].radiusScale_FloatValue" 0;

//set length of star trail
setAttr "shootingStarParticlesShape.lifespan" `floatSliderGrp -q -v trailLength`;

//set shooting star colour based on normalised age
setAttr "shootingStarParticlesShape.colorInput" 2;

//aet shooting star colour interpolation to smooth
setAttr "shootingStarParticlesShape.color[0].color_Interp" 2;
setAttr "shootingStarParticlesShape.color[1].color_Interp" 2;

//set birth colour
setAttr "shootingStarParticlesShape.color[0].color_Position" 0;
setAttr "shootingStarParticlesShape.color[0].color_Color" -type double3 1 0.8 0.4;

//set death colour
setAttr "shootingStarParticlesShape.color[1].color_Position" 1;
setAttr "shootingStarParticlesShape.color[1].color_Color" -type double3 1 1 1;

}




proc renderSet(){
//seperate particles to seperate render layers

select -r satelliteParticles ;
createRenderLayer -name "satelliteRenderLayer" -noRecurse `ls -selection`;

select oceanParticles landParticles;
createRenderLayer -name "globeRenderLayer" -noRecurse `ls -selection`;

select strokeGalaxy1 strokeGalaxy2;
createRenderLayer -name "BGRenderLayer" -noRecurse `ls -selection`;

select -r shootingStarEmitter shootingStarParticles;
createRenderLayer -name "shootingStarRenderLayer" -noRecurse `ls -selection`;

//set anti-aliasing to high quality
setAttr "defaultRenderQuality.edgeAntiAliasing" 1;

//set resolution
setAttr "defaultResolution.width" 1280;
setAttr "defaultResolution.height" 720;
setAttr "defaultResolution.deviceAspectRatio" 1.778;


//set number of samples
setAttr "defaultRenderQuality.shadingSamples" 1;
setAttr "defaultRenderQuality.maxShadingSamples" 4;
setAttr "defaultRenderQuality.particleSamples" 1;

//set animation
setAttr "defaultRenderGlobals.animation" 1;

//set memory used to max
setAttr "defaultRenderGlobals.maximumMemory" 2048;

//turn on render for camera view
setAttr "camera1.renderable" 1;
//turn off render for all other views
setAttr "frontShape.renderable" 0;
setAttr "perspShape.renderable" 0;
setAttr "sideShape.renderable" 0;
setAttr "topShape.renderable" 0;



//make satellite software render
editRenderLayerGlobals -currentRenderLayer satelliteRenderLayer;
editRenderLayerAdjustment "defaultRenderGlobals.currentRenderer";
setAttr "defaultRenderGlobals.currentRenderer" -type "string" "mayaSoftware";

//make BG software Render
editRenderLayerGlobals -currentRenderLayer BGRenderLayer;
editRenderLayerAdjustment "defaultRenderGlobals.currentRenderer";
setAttr "defaultRenderGlobals.currentRenderer" -type "string" "mayaSoftware";

//set default renderer to mental ray
setAttr "defaultRenderGlobals.currentRenderer" -type "string" "mentalRay";

//just to set the current layer to default
editRenderLayerGlobals -currentRenderLayer defaultRenderLayer;

}

proc animation(){
makeSatellite;

shootingStar;

play;
}

proc createWindow(){ //GUI
DisplayShadedAndTextured;

string $window = `window -title "Audio Visualiser" -widthHeight 500 600` ; //title bar
columnLayout;

frameLayout -label "Music Track" -borderStyle "etchedIn" -collapsable true -width 150 -bgc 0.0 0.345 0.735;

//MUSIC TRACK
rowColumnLayout -numberOfColumns 2;
text " Select Music Track ";
//textField();
iconTextButton -style "iconAndTextVertical" -command "openFile()" -image1 "fileOpen.xpm";

setParent ..;//rowColumn layout
setParent ..;//frame layout

//GLOBE PARTICLES

frameLayout -label "Globe Particles Settings" -borderStyle "etchedIn" -collapsable true -width 400 -bgc 0.0 0.345 0.735;

string $oceanParticleColour = "oceanParticlesShape.color[0]";
string $landParticleColour = "landParticlesShape.color[0]";

// attach a colour control to the particles colour
attrColorSliderGrp -at ($oceanParticleColour+".color_Color") -l "Ocean Particle Colour ";
attrColorSliderGrp -at ($landParticleColour+".color_Color") -l "Land Particle Colour ";

setParent ..;//globe particles frame layout


frameLayout -label "Shooting Star Settings" -borderStyle "etchedIn" -collapsable true -width 400 -bgc 0.0 0.345 0.735;
floatSliderGrp -cw3 90 40 200 -l "Trail Length" -field true -min 0.0 -max 2.0 -s 0.1 trailLength;

button -w 200 -h 25 -label "Play" -command "animation;";

//button -bgc 0 0.5 0.3 -label "button1";

showWindow;

// define the layout of controls added
// to the window.
columnLayout;
// create a couple of buttons
button -label "button1";
button -label "button2";
button -label "button3";
// show the window we last created



}

earthSphere;
oceanParticles;
landParticles;


createWindow;
 
Old 05 May 2013   #2
That's a lot of code to read through and I'm short of time, so can't right now, but one tip that might help :

It's generally bad practice to refer to things by their name directly. Better to cast them in a variable and then refer to that variable.
For example, instead of doing this :
polyCube -n satellite -w 0.2 -h 0.2 -d 0.2;

Do this :
string $myCube[]= `polyCube -n satellite -w 0.2 -h 0.2 -d 0.2`;

Then any time you want to access that object use the variable instead of the name, ie :
delete $myCube;

HTH,
Cheers,
Brian
 
Old 05 May 2013   #3
thanks for the tip!

sorry it is a lot of code, it's just that i've been looking at it so long i'm wondering if there's something in there somewhere I can't see.
 
Old 05 May 2013   #4
Originally Posted by mccabe86: thanks for the tip!

sorry it is a lot of code, it's just that i've been looking at it so long i'm wondering if there's something in there somewhere I can't see.


Do as Horganovski said first; 'catch' objects that are created; most often you'll have name clashes. It's more code but it's cleaner.

For instance:

//although it's better to pass objects to the function instead of using a selection
//this will return your object and the emitter
string $emitterArray[] = `emitter -n satelliteEmitter -type direction -r 100 -sro 0 -spd 1 -nsp 1`;
string $emitter = $emitterArray[1];

//will return the transform & shape name, we mostly want the shape name
string $particles[] = `nParticle -n satelliteParticles`;
string $particle = $particles[1];

//use variables instead
connectDynamic -em $emitter $particles[0];

//emitter settings
setAttr ($emitter+".rate") 1000;
setAttr ($emitter+".speed") 0;

//etc...



ALso please use the 'code' tags on the forum so that it makes it easier to read.
__________________
maya@reddit r/maya
 
Old 05 May 2013   #5
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 07:04 PM.


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