Search code examples
three.jsmayamel

Export Maya fluid so that it can be imported into a three.js game


Please forgive my ignorance in the area, but does anyone know how to go about exporting a maya fluid so that it is importable into three.js?

I'm new to Maya and I just made my first model to a game I'm making, see below:

enter image description here

The afterburner effect from the endgine are created with Maya fluids. I have no problem exporting the aircraft, and weapons, but I have no idea how to use the fluid in a three.js game. I've done hours of research trying to find any information on this topic without avail. Any references or assistance would be greatly appreciated!

EDIT: Here is an update to the steps I'm taking and the errors I'm receiving. Really hope this is meaningful and solvable. I can't find any good information online in relation to these errors.

Step 1: Modify > Convert > Fluid to Polygons ( all works as expected ) Step 2: Select created geometry > Edit > Keys > Bake Simulation, screenshot of options below. ( all works as expected )

enter image description here

Step 3: Select the generated geometry from the Fluid to Polygons step, select my fluidShape2 in the hypershader and perform Hypershade Edit > Convert to File Texture (Maya Software) ( does not work as expected, get an error )

Here is a screenshot of hypershader and polygons:

enter image description here

Here is the error Maya spits out :

// Error: file: /Applications/Autodesk/maya2017/Maya.app/Contents/scripts/others/copyConvertSolidTx.mel line 93: Cannot convert a texture connected to initialShadingGroup

To me it seems like the fluidShape2 node in the hypershader is not actually a shader and the created polygons are really assigned lambert1. I'm not really sure though considering I started using Maya last week.

EDIT #2:

Ok so here is a screenshot showing the fluidShape set as the surface material.

enter image description here

Here is a screenshot of the fluid shading attributes.

enter image description here

As you can see the color is black and the only illumination for this object is that which it produces. It is not lit from outside sources at all.

Cast / Receive shadows are unchecked in Render Stats as well.

Question: Is there any way to bake incandesces?

EDIT #3:

After following your 10 step program, I am having the same results I did previously. Here are screenshots to show before and after. A green plane has been added behind the flame to show it easier in it's second state.

As a fluid:

enter image description here

As polygons with 10 steps applied:

enter image description here

Here is attribute editor:

enter image description here

And here is the material applied through hypershader:

enter image description here

I repeated the 10 steps you gave me several times with the same results each time.


Solution

  • Before exporting you need to convert fluid to polygons.

    Here's a MEL script for testing. Run it in Script Editor.

    // opening nuke explosion example 
    file -import -type "mayaAscii" -ignoreVersion -ra true -mergeNamespacesOnClash false -namespace "Nuke" -options "v=0;" -pr "/Applications/Autodesk/maya2016.5/Maya.app/Contents/Examples/FX/Fluid_Examples/Explosions/Nuke.ma" ;
    
    // selecting fluid container
    select -r Nuke:fluid ;
    
    // converting fluid to polygons
    fluidToPoly ;
    
    // changing mesh resolution under shapeNode/outputMesh tab in Attribute Editor
    setAttr "Nuke:fluidShape.meshResolution" 3 ; 
    

    To convert fluids to polygons via menu, select fluid container and choose:

    ModifyConvertFluid to Polygons

    then select Shape node's tab in Attribute Editor and change Mesh Resolution in Output Mesh area.

    Look at useful information on exporting: Three.js Maya Export

    When conversion is done, default Maya shader (Lambert1) is assigned to new poly mesh. You have to reassign your fluid texture to new poly mesh. For this, open Hypershade and MMB-drag-and-drop fluid texture to Surface Material slot of poly mesh.

    enter image description here enter image description here enter image description here

    Remember: if you've got animation in your scene you need to bake it before export using:

    EditKeysBake Simulation

    bakeResults -simulation true -t "1:100" -sampleBy 1 -disableImplicitControl true -preserveOutsideKeys true -sparseAnimCurveBake false -removeBakedAttributeFromLayer false -removeBakedAnimFromLayer false -bakeOnOverrideLayer false -minimizeRotation true -controlPoints false -shape true {"nurbsSphere1"} ;
    

    You don't need any type of curve interpolation (linear or bezier), just baked key on every frame. You can export animation via FBX or ABC file formats. There's additional method to export animated mesh as OBJ sequence: Free OBJ Sequences Import/Export.

    Also, If you have any problems with exporting the light, bake the light and its shadows in object's texture. The better way for you to export animation and textures on per vertex basis.

    enter image description here

    STEP-BY-STEP INSTRUCTION:

    1. Select a fluid container and apply Modify–Convert–FluidToPolygons. You'll see in Viewport a polygonal Object with Lambert1 shader.

    2. Select FluidObject in Outliner, then in AE (Attribute Editor) change Mesh Resolution and Mesh Smoothing Iterations (for example 0.5 and 2 respectively) in fluidShape–Output Mesh area.

    3. After that select PolyObject in Outliner and choose tab with its initialShadingGroup in AE.

    4. Open Windows–RenderingEditors–Hypershade, select FluidTexture and assign it using MMB-drag-and-drop to Surface Material Slot in initialShadingGroup of PolyObject in AE.

    5. Create Spot Light in the scene. Run test Render. You'll see a lit Poly.

    6. To change Transparency, Opacity or Incandescence just select PolyObject in Outliner and in AE go to fluidShape tab and choose Shading area.

    7. Bake a Light (and Shadows if needed) using Arnold Renderer properties in Maya 2017 or Mental Ray properties in Maya 2016 and earlier.

    8. To output a Poly Mesh from Maya you need to select mesh and apply a command Edit–Keys–BakeSimulation.

    9. To export a sequence of textures for every frame you need to select a FluidTexture in Hypershade and apply to it Edit–RenderTextureRange (you have to assign a frame range for exported texture sequence, for example 1-200, as well as file format, for example TIFF)

    10. Export OBJ sequence.