'''
fluidCreation.py v2.0
Author: Nate Lang
web: natelang3d.com
Install:
Copy this file into your maya scripts folder
------Copy below code into a python shelf button------
import fluidCreation
fluidCreation.fluidContainerStart()
------------------------------------------------------
Use:
Creates a UI with buttons which create different
desired 3d fluid containers
*Feel free to edit as needed
'''
from maya import cmds
import maya.mel as mel
#----------
# entrance proc
#----------
def fluidContainerStart():
fluidWindow()
#----------
# make window
#----------
def fluidWindow():
fluidContainerWindow = 'fluidContainerWindow'
if cmds.window(fluidContainerWindow, exists=True):
cmds.deleteUI(fluidContainerWindow)
if cmds.windowPref(fluidContainerWindow, exists=True):
cmds.windowPref(fluidContainerWindow, remove=True)
noEmitter = 1
volumeEmitter = 2
cmds.window(fluidContainerWindow, width=300, sizeable=False, menuBar=True, title="Fluid Creation UI" )
cmds.columnLayout( adjustableColumn=True )
cmds.button(label='Pyroclastic: Container Only', command="pyroclasticFluidContainer('"+str(noEmitter)+"')")
cmds.button(label='Wispy: Container Only', command="wispyFluidContainer('"+str(noEmitter)+"')")
cmds.button(label='Pyroclastic: Containter + Emitter', command="pyroclasticFluidContainer('"+str(volumeEmitter)+"')")
cmds.button(label='Wispy: Container + Emitter', command="wispyFluidContainer('"+str(volumeEmitter)+"')")
cmds.button(label='Pyroclastic: Containter + Geo Emitter', command="getGeoPyroclastic()")
cmds.button(label='Wispy: Container + Geo Emitter', command="getGeoWispy()")
cmds.showWindow(fluidContainerWindow)
def pyroclasticFluidContainer(emitType):
# create a new fluid container
fluidName = mel.eval('create3DFluid 10 10 10 10 10 10;')
fluidContainer = cmds.listRelatives(fluidName, parent=True)
cmds.setAttr(fluidContainer[0]+".translateY", 1.5)
#------------------
# set attributes
# cmds.setAttr(fluidName+"", )
#------------------
# container properties
cmds.setAttr(fluidName+".baseResolution", 30)
cmds.setAttr(fluidName+".boundaryX", 0)
cmds.setAttr(fluidName+".boundaryY", 0)
cmds.setAttr(fluidName+".boundaryZ", 0)
# dynamic simulation
cmds.setAttr(fluidName+".highDetailSolve", 3)
# auto resize
cmds.setAttr(fluidName+".autoResize", 1)
cmds.setAttr(fluidName+".maxResolution", 300)
cmds.setAttr(fluidName+".autoResizeThreshold", 0.001)
cmds.setAttr(fluidName+".autoResizeMargin", 6)
# contents details
cmds.setAttr(fluidName+".velocitySwirl", 10)
cmds.setAttr(fluidName+".turbulenceStrength", .15)
cmds.setAttr(fluidName+".densityBuoyancy", 8)
# shading
cmds.setAttr(fluidName+".colorInput", 5)
cmds.setAttr(fluidName+".color[0].color_Position", 1)
'''add new color slider dot'''
cmds.setAttr(fluidName+".color[1]color_Color", .25, .25, .25, type='double3')
cmds.setAttr(fluidName+".color[1]color_Position", .25)
cmds.setAttr(fluidName+".color[1]color_Interp", 1)
'''set old incandesence color dots to black'''
cmds.setAttr(fluidName+".incandescence[1].incandescence_Color", 0, 0, 0, type='double3')
cmds.setAttr(fluidName+".incandescence[2].incandescence_Color", 0, 0, 0, type='double3')
'''opacity box'''
cmds.setAttr(fluidName+".opacity[0].opacity_Interp", 3)
cmds.setAttr(fluidName+".opacity[1].opacity_Interp", 3)
cmds.setAttr(fluidName+".opacity[2].opacity_FloatValue", 0)
cmds.setAttr(fluidName+".opacity[2].opacity_Position", .25)
cmds.setAttr(fluidName+".opacity[2].opacity_Interp", 3)
cmds.setAttr(fluidName+".opacity[3].opacity_FloatValue", .75)
cmds.setAttr(fluidName+".opacity[3].opacity_Position", .5)
cmds.setAttr(fluidName+".opacity[3].opacity_Interp", 3)
cmds.setAttr(fluidName+".opacityInputBias", .4)
# shading quality
cmds.setAttr(fluidName+".renderInterpolator", 3)
# lighting
cmds.setAttr(fluidName+".selfShadowing", 1)
cmds.setAttr(fluidName+".shadowOpacity", 1)
if emitType == '2':
attachVolumeEmitter(fluidName)
else:
pass
return fluidName
def wispyFluidContainer(emitType):
# create a new fluid container
fluidName = mel.eval('create3DFluid 10 10 10 10 10 10;')
fluidContainer = cmds.listRelatives(fluidName, parent=True)
cmds.setAttr(fluidContainer[0]+".translateY", 1.5)
#------------------
# set attributes
# cmds.setAttr(fluidName+"", )
#------------------
# container properties
cmds.setAttr(fluidName+".baseResolution", 30)
cmds.setAttr(fluidName+".boundaryX", 0)
cmds.setAttr(fluidName+".boundaryY", 0)
cmds.setAttr(fluidName+".boundaryZ", 0)
# dynamic simulation
cmds.setAttr(fluidName+".highDetailSolve", 3)
cmds.setAttr(fluidName+".forwardAdvection", 1)
# auto resize
cmds.setAttr(fluidName+".autoResize", 1)
cmds.setAttr(fluidName+".maxResolution", 300)
cmds.setAttr(fluidName+".autoResizeThreshold", 0.001)
cmds.setAttr(fluidName+".autoResizeMargin", 6)
# contents details
cmds.setAttr(fluidName+".densityDissipation", 0)
cmds.setAttr(fluidName+".velocitySwirl", 5)
# shading
cmds.setAttr(fluidName+".colorInput", 5)
cmds.setAttr(fluidName+".transparency", .25,.25,.25, type='double3')
'''set old incandesence color dots to black'''
cmds.setAttr(fluidName+".incandescence[1].incandescence_Color", 0, 0, 0, type='double3')
cmds.setAttr(fluidName+".incandescence[2].incandescence_Color", 0, 0, 0, type='double3')
cmds.setAttr(fluidName+".opacity[0].opacity_Interp", 3)
cmds.setAttr(fluidName+".opacity[1].opacity_Interp", 3)
# shading quality
cmds.setAttr(fluidName+".renderInterpolator", 3)
# lighting
cmds.setAttr(fluidName+".selfShadowing", 1)
cmds.setAttr(fluidName+".shadowOpacity", .5)
if emitType == '2':
attachVolumeEmitter(fluidName)
else:
pass
return fluidName
def attachVolumeEmitter(fluidShapeName):
emitterName = cmds.fluidEmitter(pos=(0, 0, 0), type='volume', volumeShape='sphere', der=1, her=2, fer=3, fdr=1.5, r=100.0, cye='none', cyi=1, mxd=0, mnd=0)
cmds.connectDynamic(fluidShapeName, em=emitterName)
cmds.setAttr(emitterName[0]+".densityMethod", 2)
def getGeoPyroclastic():
objNameList = cmds.ls(selection=True)
objName = objNameList[0]
fluidName = pyroclasticFluidContainer("pass")
attachGeoEmitter(fluidName, objName)
fluidParent = cmds.listRelatives(fluidName, parent=True)
#rename emitter based on geo name
cmds.rename(fluidParent[0], objName+'_fluid')
objChildList = cmds.listRelatives(objName, children=True)
for eachChild in objChildList:
if cmds.objectType(eachChild, isType='fluidEmitter'):
cmds.rename(eachChild, objName+'_fluidEmitter')
def getGeoWispy():
objNameList = cmds.ls(selection=True)
objName = objNameList[0]
fluidName = wispyFluidContainer("pass")
attachGeoEmitter(fluidName, objName)
fluidParent = cmds.listRelatives(fluidName, parent=True)
#rename emitter based on geo name
cmds.rename(fluidParent[0], objName+'_fluid')
objChildList = cmds.listRelatives(objName, children=True)
for eachChild in objChildList:
if cmds.objectType(eachChild, isType='fluidEmitter'):
cmds.rename(eachChild, objName+'_fluidEmitter')
def attachGeoEmitter(fluidShapeName, geoName):
cmds.select(fluidShapeName, geoName, replace=True)
mel.eval('EmitFluidFromObject;')
childArray = cmds.listRelatives(geoName, children=True)
for each in childArray:
if cmds.objectType(each, isType='fluidEmitter'):
cmds.setAttr(each+".densityMethod", 2)