Dienstag, 27. August 2013

in the meantime while we doing the final steps on lighthockey, i had to try something. the idea is a house intern fluid simulator.

here the first impression about. works in maya > 2011

the python code, which is creating the splash shaper. the idea is to get a absolut controll about splash and how it will look.

#fluid splash creator
#(c) 2013 dirk hochegger

import maya.cmds as cmds
import maya.mel as mel

class createWIN():
def __init__(win):
pass

def createRIG(*args):
createRIG_shape().create()
createRIG_shape().createEXPRESSION()

def window(win):
window = cmds.window( title="Long Name", iconName='Short Name', widthHeight=(200, 55) )
cmds.columnLayout( adjustableColumn=True )
cmds.button( label='create rig', command = win.createRIG)
cmds.setParent( '..' )
cmds.showWindow( window )

class createRIG_shape():
def __init__(rig):
pass

def create(rig):
rig.createRIG_circle()
locCNT = rig. getINFO()

rig.connectLOC_KNT(locCNT)

def getINFO(rig):
locCNT = cmds.getAttr('splashCIRCLE.spans')
return locCNT

def createRIG_circle(rig):
cmds.circle(n = 'splashCIRCLE')
cmds.xform('splashCIRCLE',a=1,ro = [90,0,0])
cmds.makeIdentity(apply = 1,t=1,r=1,s=1,n=0)

def connectLOC_KNT(rig,locCNT):
for i in range(locCNT):
knt = 'splashCIRCLE.cv['+str(i)+']'
kntPOS = cmds.xform(knt,q=1,t=1)
cmds.cluster(knt,n='splashCLUSTER0')
clstr = 'splashCLUSTER'+str(i)
origin = cmds.getAttr((clstr+'Handle.origin'))
trans = cmds.getAttr((clstr+'Handle.translate'))
cPOS = [origin[0][0]+trans[0][0],origin[0][1]+trans[0][1],origin[0][2]+trans[0][2]]

createWIN().window()

here the fluid splash expression:

//fluid dirk hochegger (c) 2013

int $rootLST[];

proc float distance(float $ax,float $ay,float $az,float $bx,float $by,float $bz){
return sqrt((($ax-$bx)*($ax-$bx))+(($ay-$by)*($ay-$by))+(($az-$bz)*($az-$bz)));
}

proc nbVELO(){
int $particleCNT = `getAttr particleShape1.count`;
for($p=0;$p<$particleCNT/4;$p++){

string $rootPARTICLE = "particle1.pt["+$rootLST[$p]+"]";
$rootVELO = `getParticleAttr -at velocity $rootPARTICLE`;
$rootPOS = `getParticleAttr -at position $rootPARTICLE`;
float $rpx = $rootPOS[0];
float $rpy = $rootPOS[1];
float $rpz = $rootPOS[2];

float $sizeBOUND = 0.7;
string $boundX = ($rpx - $sizeBOUND) + "=" + ($rpx + $sizeBOUND);
string $boundY = ($rpy - $sizeBOUND) + "=" + ($rpy + $sizeBOUND);
string $boundZ = ($rpz - $sizeBOUND) + "=" + ($rpz + $sizeBOUND);

string $bx[];
string $by[];
string $bz[];
tokenize $boundX "=" $bx;
tokenize $boundY "=" $by;
tokenize $boundZ "=" $bz;

for($i=0;$i<$particleCNT;$i++){
string $testPARTICLE = "particle1.pt["+$i+"]";
$particlePOS = `getParticleAttr -at position $testPARTICLE`;
float $tpx = $particlePOS[0];
float $tpy = $particlePOS[1];
float $tpz = $particlePOS[2];

float $bx0 = $bx[0];
float $bx1 = $bx[1];

float $by0 = $by[0];
float $by1 = $by[1];

float $bz0 = $bz[0];
float $bz1 = $bz[1];

if(($bx0 < $tpx)&&($bx1 > $tpx)){
if(($by0 < $tpy)&&($by1 > $tpy)){
if(($bz0 < $tpz)&&($bz1 > $tpz)){
if($i != $rootLST[$p]){
$testVELO = `getParticleAttr -at velocity $testPARTICLE`;
float $dis = distance($tpx,$tpy,$tpz,$rpx,$rpy,$rpz);
float $veloX = (($testVELO[0]/1.005)+($rootVELO[0]/1.4)/2)/1.4;
float $veloY = (($testVELO[1]/1.005)+($rootVELO[1]/1.4)/2)/1.4;
float $veloZ = (($testVELO[2]/1.005)+($rootVELO[2]/1.4)/2)/1.4;

select -r $testPARTICLE;
setParticleAttr -at velocity -vv $veloX $veloY $veloZ;
}
}
}
}
}
}
}
nbVELO();
if(frame == 1){
int $particleCNT = `getAttr particleShape1.count`;
vector $center = <<0,0,0>>;
for($p=0;$p<$particleCNT;$p++){
$pos = `getParticleAttr -at position ("particle1.pt["+$p+"]")`;
float $px = $pos[0];
float $py = $pos[1];
float $pz = $pos[2];
vector $posP = <<$px,$py,$pz>>;
vector $direction = $posP - ($center*10);
select -r ("particle1.pt["+$p+"]");
setParticleAttr -at velocity -vv ($direction.x) 0 ($direction.z);
}
for($p=0;$p<$particleCNT/4;$p++){
$rootLST[$p] = int(rand(0,$particleCNT));
}

}

Keine Kommentare:

Kommentar veröffentlichen