AWS Thinkbox Discussion Forums

2d Grid of Velocity Data to stoke field?

I’m very new to stoke and it’s initially a bit daunting. I need to be able to push around particles with data that I can format into something like a CSV sequence. The data in the CSV sequence won’t be moving. As in, it will have positional data that won’t move from the initial grid layout. But each grid element will have velocity vector information. Is this even possible with stoke? I could script up something that would turn this data into bitmaps along the lines of a pixel per grid data that r,g and b represent x,y and z.

I hope this makes sense.

Cheers,
Cg.

Hi Chris,

So you want the CSV to be the input of the grid, and then you push particles through it in 2D (no Z height)?
Sure, that should be rather easy, but it requires a Krakatoa PRT Loader.

  • The CSV file should contain Position X,Y,Z and then Velocity X,Y,Z.
    The first line of the CSV should define the header, followed by any number of lines with 6 comma-separated values (but other separators are supported, too):

float32 Position[0], float32 Position[1], float32 Position[2], float16 Velocity[0], float16 Velocity[1], float16 Velocity[2] 9.72161, -63.355, 262.092, 23.2188, -68.25, 291.25
See thinkboxsoftware.com/krak-csv-file-format/ for details.

  • Remember that the Velocity values are in units per second, not per frame or tick as elsewhere in 3ds Max.

  • If you want, you can write a PRT file using the MAXScript I/O interface - it will be faster to read than a CSV file. If your grid will be made by MAXScript, I would recommend that approach.

  • Next, create a PRT Loader and pick your CSV file.

  • Set the PRT Loader to “Load Single Frame Only” and set the display to 100% to see all particles in the CSV grid.

  • Now with the PRT Loader selected, go to the Stoke menu and create a Stoke Field Magma - it should be sized to the bounding box of the selected object.

  • Open its Magma editor and create a Stoke > PVelocitySplat node.

  • Uncheck the option >Remove Divergence in the PVelocitySplat properties. (When it is on, you will get a uncompressible fluid velocity field, with it off you will get the exact values from the source particles without changing them, except for any interpolation needed between the voxels)

  • Drag from the Particles input socket and release over empty area to create an InputParticles node and pick the PRT Loader.

  • Drag from the Position input socket and release over empty area to create a Position node.

  • Connect the Velocity output of the PVelocitySplat to the OUT:Velocity node. Do NOT connect the Density output.

  • You might want to adjust the spacing of the Stoke Field Magma to match the distribution of your samples in the CSV file - the PVelocitySplat will use by default the spacing of the host Stoke Field Magma to define its own spacing, but you can use Absolute or a scale factor relative to the host.
    Note that Stoke Field Magma does not allow for a truly 2D grid, it always makes sure the height has at least two voxels thickness. You might have to adjust the Z Min/Max and Spacing to get what you want.

  • In Stoke Field Magma, you can switch the Display to show Velocity channel as lines. Set the scale to 0.03 to make the velocities display as units/frame instead of units/second (the value varies depending on your Frame Rate, at 30 fps, 0.03 is close enough.

  • Change Viewport Display>Color to Velocity.

You should now have a velocity field that can drive PFlow particles using the Stoke Field operator, Stoke particles if picked as a source there, any other particles including legacy particles, Hair&Fur etc. by using the Stoke Field Force operator, etc. (In the latter case, you might need to scale the value in the Stoke Field Force to see an effect since Force and Velocity are not the same thing - the Force applies acceleration over time to produce Velocity). You can also export this field to FXD, VDB or F3D and use in FumeFX, Houdini or whatever application you have that can read any of these formats…

If you place a Plane over the grid and assign a Material with a Field Texmap that picks the Velocity as the color source, you can render the velocities as colors on the Plane. If the values need scaling, you can create a dedicated OUT:Color node in the Stoke Field Magma, connect to the Velocity socket of the PVelocitySplat and Divide by the maximum velocity expected on the grid. If you want to render a grayscale texture based on the Magnitude (how fast the particles are moving instead of a color representing the direction and magnitude), then you can connect a Vector>Magnitude node between the Velocity and the Divide, then a ToVector behind it where the Magnitude goes into X,Y and Z inputs to produce a grayscale value.

Please let me know how it goes!

Thanks Bobo, that worked pretty much perfectly as an initial lowres test.

When you say you can write a PRT file using the MAXScript I/O interface, is that part of Krakatoa or Stoke?

Cheers,
Cg.

The MAXScript I/O interfaces are part of Krakatoa MX:
Output: thinkboxsoftware.com/krak-pa … -mxscript/
Input: thinkboxsoftware.com/krak-pa … xscpt-val/

GOLD!!! Thats going to be amazingly useful for me to write straight to PRT with maxscript. Currently I’ve been writing out nearly 43,000 CSV files (by running a pre-render script on the farm) and then having an extra step to load all the CSV files into a prt loader on a single machine to then save out to PRT.

I’m freakin’ stoked. :stuck_out_tongue:

Cheers,
Cg.

Privacy | Site terms | Cookie preferences