Visualize vector field using python scripting?

Visualize vector field using python scripting?

Anonymous
Not applicable
2,923 Views
6 Replies
Message 1 of 7

Visualize vector field using python scripting?

Anonymous
Not applicable

Dear Folks,

I am new to Maya. I want to visualize a vector field similar to the attached picture. Is this possible to do in Maya using python scripting?

Suppose that for each point in space there is vx,vy and vz vector values. I appreciate if someone can post a sample script to do such a thing.

 

0 Likes
Accepted solutions (1)
2,924 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

Hi Amir

 

Not sure what that was a picture of, but its pretty much identical to a fluid container inside Maya. Fluids are essentially 2D or 3D volumes which have information on all the points in that volume, including velocity (there's also stuff like density and temparature etc, but you can ignore that if you don't need it) so you could mimic your image by using them.

 

Docs are here:

 

http://download.autodesk.com/global/docs/maya2014/en_us/files/Creating_Fluid_Effects_What_are_the_co...

 

If you wanted to see a simple example of how a script can create a similar effect, just run the attached python script and hit the play button to advance the time slider in Maya. Bear in mind that much of Maya is controlled via mel, so I am using python to call some mel functions for convenience, but you could always convert the mel scripts to pure python if you wanted to:

 

Hope it helps

 

P.S. Autodesk wont let me attach python files to this ticket, so I have renamed it to .txt

Message 3 of 7

Anonymous
Not applicable

Thanks for your answer. The result is similar to what I want. Can you define the velocity at each point? Since the only thing that I need is to read the velocities from a file and display them. No simulation whatsoever is needed. Thanks again

0 Likes
Message 4 of 7

Steve_Curley
Mentor
Mentor

Autodesk wont let me attach python files to this ticket
The forums only allow certain filetypes, the best way around it is to zip (not .rar or .7z or anything else, just zip) the file - renaming files is not "best practice".

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 5 of 7

Anonymous
Not applicable
Accepted solution

Hi again Amir

 

OK thats a bit more complicated but still not too bad. You will need to write your own text parser in Python but there will be plenty of examples of that on the web.

 

As for the Maya side, I've changed the previous script so that it now doesn't bother with the turbulence field and instead loops over the entire fluid container and sets each vector to be (0, 1, 0). You will simply need to add your code to replace that vector with the correct one from your text file:

 

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

# Create a fluid container
fluid = mel.eval("create3DFluid 20 20 20 10 10 10")

# Enable velocity draw on the fluid container
cmds.setAttr((fluid+".velocityDraw"), 1)

# Get the resolution (Even though we specified it above)
res = cmds.getAttr(fluid + ".res");

# Nested loops to cycle over each voxel
for z in range(0, int(res[0][2])):
    for y in range(0, int(res[0][1])):
        for x in range(0, int(res[0][0])):
            
            # This command sets the velocity value on the selected fluid container.
            # You will need some file reading code to replace the vv=(0,1,0) and set
            # it to your vector value
            cmds.setFluidAttr(at="velocity", vv=(0,1,0), xi=x, yi=y, zi=z)

Message 6 of 7

Anonymous
Not applicable

This is exactly what I want and I accept it as the solution. Just as an optional note What do you suggest for aesthetical aspect? A little bit thicker more beautiful arrows for example? I am asking this because i've never worked with maya. Thanks.

0 Likes
Message 7 of 7

Anonymous
Not applicable

Glad to be of help

 

As for the line thickness, I don't think you can control this as its really just a debug thing in the fluid container. But you could make the lines longer using the "Draw Length" attribute. This can be found in the attribute editor for the fluid container under "Display" (See attached image)

 

VelocityDraw.jpg

0 Likes