PDA

View Full Version : this is my MEL for particle script


springyu
04-09-2003, 11:06 AM
I had edited a MEL for particle . this MEL can use for object moving follow particle moving . like the MAYA's instancer particle .
I think this MEL can help someone work for MAYA . and this MEL have a bug , I hope every friend can help me .

my english is't well , I am sorry !!!


// This proc is use Particle's position to creat Curves
// and useed those curves to make Path Animation ; So
// a lot of things can do same things .

global proc ParticleCurve()
{
int $start , $end ;
string $winName = "ParticleCurve" ;
if( ` window -ex ("ParticleCurve") ` )
{
deleteUI ParticleCurve ;
}
window -t " Particle Path Animation " -wh 520 300 $winName ;
formLayout MAIN ;

columnLayout -p MAIN TimeLine ;
text " " ;
radioButtonGrp -l " Time Range " -nrb 3 -l1 " Time Slider " -l2 " Start " -l3 " Start/End "
-cc timeMask -sl 1 timeButton ;
floatFieldGrp -l " Start Time " -pre 3 -en $start startTime ;
floatFieldGrp -l " End Time " -pre 3 -en $end endTime ;

checkBox -p MAIN -l " Path Animation " -onc turnOnPathAnimation
-ofc turnOffPathAnimation PathAnimationControl ;

columnLayout -p MAIN AnimationLine ;
radioButtonGrp -l " Front Axis " -nrb 3 -l1 " X " -l2 " Y " -l3 " Z "
-sl 1 -en 0 frontAxis ;
radioButtonGrp -l " Up Axis " -nrb 3 -l1 " X " -l2 " Y " -l3 " Z "
-sl 2 -en 0 upAxis ;

checkBox -p MAIN -l " Delete the Particle " deleteParticleBox ;

button -p MAIN -l " Attach " -w 100 -c CreatParticleCurve buttonOne ;
button -p MAIN -l " Apply " -w 100 buttonTwo ;
button -p MAIN -l " Close " -w 100 -c " deleteUI ParticleCurve " buttonThree ;

formLayout -e -af TimeLine top 5
-af TimeLine left 10
-ac PathAnimationControl top 5 TimeLine
-af PathAnimationControl left 80
-ac AnimationLine top 5 PathAnimationControl
-af AnimationLine left 10
-ac deleteParticleBox top 5 AnimationLine
-af deleteParticleBox left 80
-ac buttonOne top 15 deleteParticleBox
-af buttonOne left 80
-ac buttonTwo left 25 buttonOne
-ac buttonTwo top 15 deleteParticleBox
-ac buttonThree left 25 buttonTwo
-ac buttonThree top 15 deleteParticleBox
MAIN ;

showWindow ;
}

global proc timeMask ()
{
int $timeVolue = ` radioButtonGrp -q -sl timeButton ` ;

if( $timeVolue == 1 )
{
floatFieldGrp -e -en 0 startTime ;
floatFieldGrp -e -en 0 endTime ;
}
else if ( $timeVolue == 2 )
{
floatFieldGrp -e -en 1 startTime ;
floatFieldGrp -e -en 0 endTime ;
}
else if ( $timeVolue == 3 )
{
floatFieldGrp -e -en 1 startTime ;
floatFieldGrp -e -en 1 endTime ;
}
}

global proc turnOnPathAnimation()
{
radioButtonGrp -e -en 1 frontAxis ;
radioButtonGrp -e -en 1 upAxis ;
}

global proc turnOffPathAnimation()
{
radioButtonGrp -e -en 0 frontAxis ;
radioButtonGrp -e -en 0 upAxis ;
}

global proc getValueFront()
{
int $frontValue = ` radioButtonGrp -q -sl frontAxis ` ;
if ( $frontValue == 1 )
{
radioButtonGrp -e -sl 2 upAxis ;
}
else if ( $frontValue == 2 )
{
radioButtonGrp -e -sl 1 upAxis ;
}
}

global proc getValueUp()
{
int $upValue = ` radioButtonGrp -q -sl upAxis ` ;
if ( $upValue == 1 )
{
radioButtonGrp -e -sl 2 frontAxis ;
}
else if ( $upValue == 2 )
{
radioButtonGrp -e -sl 1 frontAxis ;
}
}

global proc CreatParticleCurve()
{
string $selectObject[] = ` ls -sl ` ;
string $selectObjectHistory[] = ` listHistory -f 1 $selectObject ` ;
int $numberOfHistory = size ( $selectObjectHistory ) ;
int $maskHistory ;
int $PathAnimationMask = ` checkBox -q -v PathAnimationControl ` ;
string $ParticleName[] ;
int $ObjectNum ;

for( $maskHistory = 0 ; $maskHistory <= $numberOfHistory ; $maskHistory++ )
{
string $objectType = ` objectType $selectObjectHistory[$maskHistory] ` ;

switch ( $objectType )
{
case "particle" :

//Make Particle Path and Creat the Curve

{

waitCursor -st true ;

string $workSpace = ` workspace -q -rd ` ;
string $fileDir = ( $workSpace + "particles" + "/" + "particleY" + "/" ) ;
string $fileName ;
float $startFrame , $endFrame ;
float $tempStartFrame[] , $tempEndFrame[] ;
int $fileNum , $fileID ;
int $afterNum = 0 ;
int $nowNum = 0 ;
float $xPos , $yPos , $zPos ;

int $deleteParticleMask = ` checkBox -q -v deleteParticleBox ` ;

//Get the Animation's startFrame and endFrame

int $timeVolue = ` radioButtonGrp -q -sl timeButton ` ;

if( $timeVolue == 1 )
{
$startFrame = ` playbackOptions -q -min ` ;
$endFrame = ` playbackOptions -q -max ` ;
}
else if ( $timeVolue == 2 )
{
$tempStartFrame = ` floatFieldGrp -q -v startTime ` ;
$endFrame = ` playbackOptions -q -max ` ;
$startFrame = $tempStartFrame[0] ;
}
else if ( $timeVolue == 3 )
{
$tempStartFrame = ` floatFieldGrp -q -v startTime ` ;
$tempEndFrame = ` floatFieldGrp -q -v endTime ` ;
$startFrame = $tempStartFrame[0] ;
$endFrame = $tempEndFrame[0] ;
}

//write the particle's position data in the MAYA's file

playButtonStart ;
dynExport -atr position -mnf $startFrame -mxf $endFrame -f ascii -p "ParticleY" $selectObjectHistory[$maskHistory] ;

//read the particle's data from MAYA's file and creat the curves

for( $fileNum=$startFrame ; $fileNum<=$endFrame ; $fileNum++ )
{
$fileName = ( $fileDir + $selectObjectHistory[$maskHistory] + "." + $fileNum + ".pda" ) ;
$ParticleName[$fileNum] = $fileName ;

//Define the fileID

$fileID = ` fopen $fileName r ` ;
for( $i=0 ; $i<4 ; $i++ )
{
fgetline $fileID ;
}
fgetword $fileID ;
$nowNum = ` fgetword $fileID ` ;

if( $afterNum == 0 )
{
fgetline $fileID ;

for($i=1 ; $i<=$nowNum ; $i++)
{
$xPos = ` fgetword $fileID ` ;
$yPos = ` fgetword $fileID ` ;
$zPos = ` fgetword $fileID ` ;
curve -d 1 -p $xPos $yPos $zPos -name ( "myCurve" + $i ) ;
}
fclose $fileID ;
$afterNum = $nowNum ;
}
else
{
fgetline $fileID ;

for($i=1 ; $i<=( $afterNum ) ; $i++)
{
$xPos = ` fgetword $fileID ` ;
$yPos = ` fgetword $fileID ` ;
$zPos = ` fgetword $fileID ` ;
curve -a -p $xPos $yPos $zPos ( "myCurve" + $i ) ;
}
for($i=( $afterNum + 1 ); $i<=$nowNum ; $i++)
{
$xPos = ` fgetword $fileID ` ;
$yPos = ` fgetword $fileID ` ;
$zPos = ` fgetword $fileID ` ;
curve -d 1 -p $xPos $yPos $zPos -name ( "myCurve" + $i ) ;
}
fclose $fileID ;
$afterNum = $nowNum ;
$ObjectNum = $nowNum ;
}
}

select -cl ;

if( $deleteParticleMask )
{
select -r $selectObjectHistory[$maskHistory] ;
HideSelectedObjects ;
}
/*
for( $i=1 ; $i<= $afterNum ; $i++ )
{
select -tgl ( "myCurve" + $i ) ;
}
group -name MyCurveGroup ;
*/

select -cl ;

waitCursor -st false ;
continue ;

}

case "nurbsSurface" :
case "mesh" :
case "subdiv" :

//Path Animation Object in The Curve
// 此程序应用的是路径动籣,所以各粒子与相应的物体运动速度有不一致的现象。

{

if ( $PathAnimationMask )
{
select -r $selectObjectHistory[$maskHistory] ;
string $tempObjectName[] = ` pickWalk -d up ` ;
string $sourceObject = $tempObjectName[0] ;
select -r $sourceObject ;
for( $i = 1 ; $i < $ObjectNum ; $i++ )
{
duplicate -rr ;
rename ( "myObject" + $i ) ;
}
select -cl ;

// group -name MyObjectGroup ;
// select -cl ;

waitCursor -st true ;

string $workSpace = ` workspace -q -rd ` ;
string $fileDir = ( $workSpace + "particles" + "/" + "particleY" + "/" ) ;
string $fileName ;
float $startFrame , $endFrame ;
float $tempStartFrame[] , $tempEndFrame[] ;
int $fileNum , $fileID ;
int $nowNum = 0 ;
int $afterNum = 0 ;
int $count = 0 ;
float $PathStartFrame[] ;
float $PathEndFrame[] ;


//Get the Animation's startFrame and endFrame

int $timeVolue = ` radioButtonGrp -q -sl timeButton ` ;

if( $timeVolue == 1 )
{
$startFrame = ` playbackOptions -q -min ` ;
$endFrame = ` playbackOptions -q -max ` ;
}
else if ( $timeVolue == 2 )
{
$tempStartFrame = ` floatFieldGrp -q -v startTime ` ;
$endFrame = ` playbackOptions -q -max ` ;
$startFrame = $tempStartFrame[0] ;
}
else if ( $timeVolue == 3 )
{
$tempStartFrame = ` floatFieldGrp -q -v startTime ` ;
$tempEndFrame = ` floatFieldGrp -q -v endTime ` ;
$startFrame = $tempStartFrame[0] ;
$endFrame = $tempEndFrame[0] ;
}

for ( $fileNum = $startFrame ; $fileNum <= $endFrame ; $fileNum++ )
{

$fileID = ` fopen $ParticleName[$fileNum] r ` ;
for( $i=0 ; $i<4 ; $i++ )
{
fgetline $fileID ;
}
fgetword $fileID ;
$nowNum = ` fgetword $fileID ` ;

if ( $afterNum != $nowNum )
{
$PathStartFrame[$count] = $fileNum ;
$count++ ;
$afterNum = $nowNum ;
}

fclose $fileID ;
}

// start the Path Animation

int $selectFrontAxis = ` radioButtonGrp -q -sl frontAxis ` ;
int $selectUpAxis = ` radioButtonGrp -q -sl upAxis ` ;
string $frontAxis , $upAxis ;
if ( $selectFrontAxis == 1 )
{
$frontAxis = "x" ;
}
else if ( $selectFrontAxis == 2 )
{
$frontAxis = "y" ;
}
else if ( $selectFrontAxis == 3 )
{
$frontAxis = "z" ;
}
if ( $selectUpAxis == 1 )
{
$upAxis = "x" ;
}
else if ( $selectUpAxis == 2 )
{
$upAxis = "y" ;
}
else if ( $selectUpAxis == 3 )
{
$upAxis = "z" ;
}

select -r ( "myCurve1" ) ;
select -add $sourceObject ;
pathAnimation -fractionMode false -follow true -followAxis $frontAxis -upAxis $upAxis
-worldUpType "vector" -worldUpVector 0 1 0 -inverseUp false
-inverseFront false -bank false -startTimeU $PathStartFrame[1]
-endTimeU $endFrame ;

select -r ( "myCurve1" ) ;
select -add $sourceObject ;
group -name ( "PathObject0" ) ;

for( $i = 1 ; $i < $ObjectNum ; $i++ )
{
int $k = $i + 1 ;
select -r ( "myCurve" + $k ) ;
select -add ( "myObject" + $i ) ;
pathAnimation -fractionMode false -follow true -followAxis $frontAxis -upAxis $upAxis
-worldUpType "vector" -worldUpVector 0 1 0 -inverseUp false
-inverseFront false -bank false -startTimeU $PathStartFrame[$k]
-endTimeU $endFrame ;
select -cl ;
select -r ( "myCurve" + $k ) ;
select -add ( "myObject" + $i ) ;
group -name ("PathObject" + $i ) ;
select -cl ;
}

for ( $i = 0 ; $i < $ObjectNum ; $i++ )
{
select -tgl ("PathObject"+$i) ;
}
group -name AllObject ;
select -cl ;


waitCursor -st false ;
break ;
}
}
}
}
}
ParticleCurve ;

BadKarma
04-11-2003, 09:20 PM
wow thats intense... n damn big... ! nice work man i will try it out.

dont worry bout ur english too much everyone speaks it differently as it is lol

BadKarma

Nicool
04-13-2003, 01:53 AM
:thumbsup:
A professionnal would say you that you should work with a max with independant proc.

BadKarma
04-13-2003, 05:33 PM
"max with independant proc" - What what what?? lol

BadKarma

CGTalk Moderation
01-14-2006, 09:00 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.