Giter VIP home page Giter VIP logo

mayafbx's Introduction

mayafbx

Latest Release Github Tests Docs

Python wrapper for the FBX plugin of Maya.

Visit the github repo for source code and the command reference for documentation.

Before:

from maya import mel

mel.eval("FBXResetExport")  # Reset options.
mel.eval("FBXProperty Export|IncludeGrp|Animation -v true")
mel.eval("FBXProperty Export|IncludeGrp|Animation|ExtraGrp|RemoveSingleKey -v true")
mel.eval("FBXProperty Export|IncludeGrp|CameraGrp|Camera -v false")

mel.eval('FBXExport -f "C:/outfile.fbx" -s')  # '-s' for selected.

After:

from mayafbx import FbxExportOptions, export_fbx

options = FbxExportOptions()
options.animation = True
options.remove_single_key = True
options.cameras = True
options.selected = True

export_fbx("C:/outfile.fbx", options)

Alternative:

from mayafbx import FbxExportOptions, export_fbx

options = FbxExportOptions(
    animation=True,
    remove_single_key=True,
    cameras=True,
    selected=True)

export_fbx("C:/outfile.fbx", options)

Installation

pip install git+git://github.com/tahv/mayafbx#egg=mayafbx

Requirements

Run Maya >= 2020. It may run on older version but was not tested on them.

Usage

import tempfile, os
from maya import cmds
from mayafbx import FbxExportOptions, export_fbx
from mayafbx import FbxImportOptions, import_fbx, MergeMode

cmds.file(new=True, force=True)

# Create a cube with 2 keyframes.
cube = cmds.polyCube()[0]
cmds.setKeyframe(cube, attribute="translateX", time=1, value=0)
cmds.setKeyframe(cube, attribute="translateX", time=24, value=10)

# Setup options to export the scene with baked animation.
options = FbxExportOptions()
options.animation = True
options.bake_animation = True
options.bake_resample_all = True

# Export the scene as FBX.
filepath = os.path.join(tempfile.gettempdir(), "testcube.fbx")
export_fbx(filepath, options)

# Remove all keys from our cube.
cmds.cutKey(cube, attribute="translateX", option="keys")

# Setup options to import our animation back on our cube.
options = FbxImportOptions()
options.merge_mode = MergeMode.kMerge
options.animation = True

# Import our FBX.
import_fbx(filepath, options)

Contributing

Pull requests are welcome. Please make sure to update tests as appropriate.

The main purpose of this package is to have clear documentation, and I did not had the opportunity to try all export on different softwares, so don't hesitate to improve the docstrings if you have a better example.

The FbxExportOptions and FbxImportOptions are not feature complete yet, mainly because I couldn't find good documentation for some of the commands.

mayafbx's People

Contributors

tahv avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.