Last active
May 6, 2020 16:34
-
-
Save taikomatsu/260a290111c6fd78831c53eda0ae4025 to your computer and use it in GitHub Desktop.
Convert Maya Fluid into vdb and render with Redshift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Maya FluidからRedshift用のVolumeオブジェクトを作成 | |
# Redshiftでは現状Maya Fluidが直接レンダリング出来ないので、BE_OpenVDBを使用して一旦.vdbに出力する | |
# その際あれこれ接続したりとか諸々面倒なので自動化 | |
# 今回は煙が作れればOKだったのでRSVolumeにはdensityだけ設定してある。 | |
# 位置は元のFluidに合わせてあるが、シーンの作り方によっては合わないので要調整。 | |
# MayaFluidは一応キャッシュをとってから実行した方がより安心です。 | |
from pymel.core import * | |
import os | |
import os.path | |
loadPlugin('BE_OpenVDB', qt=True) | |
# list fluids | |
fluids = [o.getShape() for o in selected() if o.getShape().type() == 'fluidShape'] | |
# get current path | |
proj = '/'.join(sceneName().split('/')[:-2]) | |
# setup vdb write | |
writes = [] | |
for o in fluids: | |
vdb = createNode('BE_VDBFromMayaFluid') | |
w = createNode('BE_VDBWrite') | |
writes.append(w) | |
vdb.VdbOutput >> w.VdbInput | |
vdb.FluidNodeName.set(o.name()) | |
vdbpath = '{proj}/vdb/{name}/{name}.####.vdb'.format(proj=proj, name=o.name()) | |
vdbdir = os.path.dirname(vdbpath) | |
if not os.path.isdir(vdbdir): | |
os.makedirs(vdbdir) | |
print('[INFO] Create Directory: {}'.format(vdbdir)) | |
w.VdbFilePath.set(vdbpath) | |
# export all | |
st = int(playbackOptions(q=True, min=True)) | |
ed = int(playbackOptions(q=True, max=True)) | |
for i in range(st, ed+1): | |
currentTime(i) | |
for w in writes: | |
w.VdbOutput.evaluate() | |
currentTime(st) | |
print('[INFO] VDB Exported.') | |
# create redshift volume | |
vols = [] | |
for o, w in zip(fluids, writes): | |
vol = createNode('RedshiftVolumeShape') | |
filename = re.sub('####', '0001', w.VdbFilePath.get()) | |
vol.fileName.set(filename) | |
vol.useFrameExtension.set(1) | |
vols.append(vol) | |
shad = shadingNode('RedshiftVolume', asShader=True) | |
shad.density_name.set('density') | |
sg = sets(renderable=True, noSurfaceShader=True, empty=True, name='{}SG'.format(vol.name())) | |
shad.outColor >> sg.volumeShader | |
mel.eval('assignSG "{}" "{}";'.format(sg.name(), vol.name())) | |
# constraint to original fluid | |
delete(parentConstraint(o.getParent(), vol.getParent())) | |
print('# Done') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment