View Full Version : Fluid expression
Bernard397 10292005, 10:54 PM Hello,
Does anyone know an expression to make one fluidcontainer (2D) control another fluidcontainer (3D), where the actual burning goes on.
I've seen the first free lesson, but don't know how to go further...:
http://www.digitaltutors.com/digital_tutors/display_video_store.php?vid=695
many thanks,
bernard


RoundRobbin
10302005, 02:10 AM
hey man, that looks sweet
thirddan
10302005, 06:12 AM
the basics are that you create a 2d container and a 3d container with the same resolution then have a for loop that will check thru the x voxels of the 2d, and a nested for loop that will check thru the z voxels...you then store the density/heat/fuel or whatever values into a float array using the getFluidAttr...then inside the main loop you will go thru the x and z voxels of the 3d container and use the setFluidAttr to assign those values to the 3d container...hope that makes sense...
Bernard397
10302005, 04:19 PM
Hello Duncan,
Maybe you can help...You are the Fluids Master after all...
So far I have:
float $heat[]='getFluidAttr... (2D fluid)
float $gasdensity[]='getFluidAttr... (3D fluid)
if $heat[]>0 &&...
(I don't know how to complete and correct the mel expression)
many thanks,
bernard
Duncan
10312005, 08:51 PM
You need a nested "for" loop on the 2D fluid coordinates. For each x,y coordinate use fluidVoxelInfo to find the 3D position of that voxel(and getFluidAttr to get the heat of that voxel). Then use fluidVoxelInfo to find the x,y,z coordinate of the 3D fluid at location. You can then use setFluidAttr with those coordinates to update the 3D fluid.
Duncan
Bernard397
11012005, 06:28 PM
Hello Duncan, many thanks.
I tried the following mel expression, but it doesn't seem to work. What am I doing wrong here. In the forinstruction, do I have to start with 0 or 1 ? ( does the voxel count from 0 or 1?) With the fluidVoxelInfo instruction , I have to use the 3 coordinates (x,y,z). Otherwise Maya gives an error... For the 2d Fluid do I have to make z =1 or what ?
A lot of questions I know..
int $xres=`getAttr fluidShape1.resolutionW`;
int $yres=`getAttr fluidShape1.resolutionH`;
int $xi,$yi,$zi;
$zi=1;
for($xi=1;$xi<$xres;$xi++){
for($yi=1;$yi<$yres;$yi++){
int $vox[]=`fluidVoxelInfo objectSpace false cb voxel ($xi) ($yi) ($zi) fluidShape1`;
float $heat[]=`getFluidAttr at "temperature" xi $vox[0] yi $vox[1] zi $vox[2] fluidShape1`;
int $vox2[]=`fluidVoxelInfo objectSpace false cb voxel ($xi) ($yi) ($zi) fluidShape2`;
if($heat[0]>0){
setFluidAttr at "temperature" xi $vox2[0] yi $vox2[1] zi $vox[2] fv ($heat[0]) fluidShape2;
}
}
}
AndersEgleus
11012005, 08:29 PM
int $vox[]=`fluidVoxelInfo objectSpace false cb voxel ($xi) ($yi) ($zi) fluidShape1`;
If you're iterating over all the voxels, you don't need to use fluidVoxelInfo. It's supposed to be used to query the index of the voxel corresponding to a world (or local) space coordinate or vice versa.
And voxel indices start with 0, like all arrays in maya.
Your code should prob. look like this:int $xres= fluidShape1.resolutionW;
int $yres= fluidShape1.resolutionH; // avoid getAttr in expressions if possible
int $xi,$yi,$zi;
$zi=0;
for($xi=0;$xi<$xres;$xi++){
for($yi=0;$yi<$yres;$yi++){
float $heat[]=`getFluidAttr at "temperature" xi $vox[0] yi $vox[1] zi $vox[2] fluidShape1`;
if($heat[0]>0){
setFluidAttr at "temperature" xi $vox2[0] yi $vox2[1] zi $vox[2] fv ($heat[0]) fluidShape2;
}
}
}
Duncan
11012005, 08:43 PM
Anders... he is emitting from a 2d fluid into a 3d one, and wishes to emit where they overlap. Thus he needs to use fluidVoxelInfo.
Bernard..Thats getting close. I think you need to loop from zero, not 1(as Anders pointed out). Set the voxel z to zero, not 1 on the 2d fluid.
You need to get the 3d position of the 2d fluid voxel then find the indices of the 3d fluid. You are currently getting the indices from the indices on the 2d fluid. Try the following instead:
float $heat[] = `getFluidAttr at "temperature" xi $xi yi $yi zi $zi fluidShape1`;
float $pos[] = `fluidVoxelInfo voxelCenter xi $xi yi $yi zi $zi fluidShape1`;
int $vox[] = `fluidVoxelInfo cb voxel $pos[0] $pos[1] $pos[2] fluidShape2`;
Also you have a typo in the last line:
$vox[2]
should be
$vox2[2]
Duncan
Do we really need to use expressions? Coudn't we just map the 2d container's temperature as a texture on a plane and then use that plane as an emitter in the 3d container?
(it feels like this is a very stupid question...)
Bernard397
11012005, 09:38 PM
Hello Duncan,
I tried your expression, but it doesn't give any positive results for the moment...
I my 2D fluid I generate heat, but in the second (3D) Fluid Container I get No Heat (go to Display > Numeric Display > Temperature of the fluidShape2 node in the attribute editor to see the result)
What can be the cause ? This is the used Mel script:
int $xres=`getAttr fluidShape1.resolutionW`;
int $yres=`getAttr fluidShape1.resolutionH`;
int $xi,$yi,$zi;
$zi=0;
for($xi=0;$xi<$xres;$xi++){
for($yi=0;$yi<$yres;$yi++){
float $heat[] = `getFluidAttr at "temperature" xi $xi yi $yi zi $zi fluidShape1`;
float $pos[] = `fluidVoxelInfo voxelCenter xi $xi yi $yi zi $zi fluidShape1`;
int $vox[] = `fluidVoxelInfo cb voxel $pos[0] $pos[1] $pos[2] fluidShape2`;
if($heat[0]>0){
setFluidAttr at "temperature" xi $vox[0] yi $vox[1] zi $vox[2] fv ($heat[0]) fluidShape2;
}
}
}
Duncan
11032005, 07:19 PM
I tried your expression and it works fine for me. Make sure that your 3D fluid has a temperature grid(dynamic or static). Also make sure you've not got a cache on it( if so simply delete the cache).
Duncan
Duncan
11032005, 07:22 PM
Do we really need to use expressions? Coudn't we just map the 2d container's temperature as a texture on a plane and then use that plane as an emitter in the 3d container?
(it feels like this is a very stupid question...)
This is a good question, but unfortunately fluids don't currently support textured emission.
Duncan
AndersEgleus
11042005, 07:29 AM
I see now I was a bit off the mark when I posted that, also the expression I posted would give a compile error (undeclared variable  $vox). I think I thought the two fluids had the same size and resolution on the xyplane (it wouldn't have worked anyway thought if the 2d fluid was lying down).unfortunately fluids don't currently support textured emissionThat would be so cool :)
CGTalk Moderation
11042005, 07:29 AM
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.
vBulletin v3.0.5, Copyright ©20002015, Jelsoft Enterprises Ltd.