文档


MotionBuilder插件开发常用功能——python_My梦的博客-CSDN博客_motionbuilder python

Environment Variables
==============
    MB_CONFIG_DIR
        The directory specified in this environment variable determines the
        location where MotionBuilder configuration will be stored. If not set,
        configuration files will be stored in document or home directory.

    MOTIONBUILDER_PLUGIN_PATH
        The list of directories contained in this environment variable
        determines the location from which MotionBuilder will load additional
        compiled plug-ins.

    MOTIONBUILDER_PYTHON_STARTUP
        The list of directories contained in this environment variable
        determines the location from which MotionBuilder will load additional
        Python startup scripts.

    MOBU_FBX_EXTENSION_PATH
        The list of directories contained in this environment variable
        determines the location from which MotionBuilder will load additional
        FBX MB extension plug-ins.

    FILMBOX_CONSOLE
        (Windows only) Setting this environment variable to 1 allows the
        console to appear, otherwise the console will not appear.

    K_NO_CRASH_RECOVERY
        (Linux only) Setting this environment variable to 1 enables the
        CrashRecoverySignalHandler, otherwise it is disabled.

    MOTIONBUILDER_SAVELOAD_EMBEDMEDIAS
        This environment variable is used for overriding the corresponding
        setting in a configuration file. Any other value except Yes is
        considered as false.

    MOTIONBUILDER_SAVELOAD_SHOWEMBEDMEDIASOPTION
        The ShowEmbedMediasOption preference item can be used in the SaveLoad
        section of a configuration file to control whether the Embed Medias
        checkbox appears in the Save dialog box. This environment variable can
        can also be used for overriding the corresponding setting in a
        configuration file. Any other value except Yes is considered as false.

    MOTIONBUILDER_ICON_PATH
        The list of directories contained in this environment variable
        determines the location from which MotionBuilder will load
        icons/images. In that list of directories, the first file named
        "MoBuStartupImage.{tif|png|bmp|jpg}" will be used by MotionBuilder
        for its splash screen image. This is the only usage of this
        environment variable at this moment.

    MOTIONBUILDER_MODULE_PATH
        The list of directories contained in this environment variable
        determines the location from which MotionBuilder will load additional
        module (*.mod) files.
        By default, there are two module search paths:
        - $(UserConfigDir)/config/Modules
        - $(UserConfigDir)/../../Modules
        Users can prepend additional module search paths by setting this
        environment variable before launching the application.

    MOBU_AUTOSEND_CER
        (Windows only) Setting this environment variable to any value
        allows sending the crash report silently (without dialog).

    MOBU_USER_CER_APP
        (Windows only) User supplied alternate CER application path to
        execute before the report is sent to Autodesk.

 
from pyfbsdk import *
# RootModel Characters Cameras Takes Sets Selected RootModel 
# Namespaces NamespaceGet NamespaceExist NamespaceRename 
# Notes 

# 打开文件
FBApplication().FileOpen('C:\Path\test.fbx',False)

# 获取当前take
current_take = FBSystem().CurrentTake
# 获取所有take及时间
for take in FBSystem().Scene.Takes:
    print(take.Name)
    print(take.LocalTimeSpan.GetStart().GetFrame())
    print(take.LocalTimeSpan.GetStop().GetFrame())
    print(dir(take))
# 列出摄像机
for camera in FBSystem().Scene.Cameras:
    print(camera.Name)
# 列出角色
for char in FBSystem().Scene.Characters:
    print(char.Name)

# 根据名字获取节点
node = FBFindObjectByFullName('Constraint::Aragor')
node.Selected = True

# 根据名字获取节点
ComponentList = FBComponentList()
# 把NS:Character放到ComponentList列表中
namespace_match = True # 匹配名称空间
model_match = False # 关闭仅匹配Model类型
FBFindObjectsByName('NS:Character', ComponentList, namespace_match, model_match)

# bake动画
lOptions = FBPlotOptions()
lOptions.ConstantKeyReducerKeepOneKey = False
lOptions.PlotAllTakes = False
lOptions.PlotOnFrame = True
lOptions.PreciseTimeDiscontinuities = False
lOptions.PlotLockedProperties = False
lOptions.RotationFilterToApply = FBRotationFilter.kFBRotationFilterUnroll
lOptions.PlotTranslationOnRootOnly = False
lOptions.UseConstantKeyReducer = False
char = FBApplication().CurrentCharacter
char.PlotAnimation(FBCharacterPlotWhere.kFBCharacterPlotOnSkeleton, lOptions)
# 合并动画层

# 导出动画
itemName = 'C:\Path\Test.fbx'
options = FBFbxOptions(False)
# 只保存选中项,格式为ASCII
options.UseASCIIFormat = True
options.SaveSelectedModelsOnly = True
# 不保存默认选项
options.BaseCameras = False
options.CameraSwitcherSettings = False
options.CurrentCameraSettings = False
options.GlobalLightingSettings = False
options.TransportSettings = False
FBApplication().FileSave(itemName, options)

# 获取子物体
for i in range(node.GetSrcCount()):
    print node.GetSrc(i)

# 删除物体
FBComponent.FBDelete(i)

# 创建自定义属性

# 属性设置为可key帧

# 创建relation约束

# 将属性加入relation约束

# 获取relation节点内的盒子
[i for i in get_object_by_name('RightWristEffector') if type(i) in ['FBModelPlaceHolder', 'FBBox']]

# 创建约束
constraint = pyfbsdk.FBConstraintManager().TypeCreateConstraint('Parent/Child')
# 约束操作
constraint.Snap()
constraint.Active = True
constraint.Lock = True

# 创建物体
FBCreateObject( "Browsing/Templates/Elements", "Marker", "MilaMarker" )


# 刷新输出
import pythonidelib
pythonidelib.FlushOutput()

FBTime(int pHour, int pMinute, int pSecond = 0, int pFrame = 0, int pField = 0, FBTimeMode pTimeMode = kFBTimeModeDefault) 
https://help.autodesk.com/cloudhelp/2018/ENU/MotionBuilder-SDK/cpp_ref/class_o_r_s_d_k2018_1_1_f_b_time.html#aab020e5a61eda9ed8101041528925c83

awforsythe.com

  • MotionBuilder的场景对象基类是FBComponent。您在大纲中看到的所有内容都是一个组件。

  • 全名采用 groupname::namespace:name 的形式,并且在场景中必须是唯一的。组名是静态的,基于组件的类型。
    每个组件都有一个包含其所有属性的 FBPropertyManager 实例。属性可以通过 PropertyList.Find()按名称获取。

  • 当您需要根据名称、命名空间或选择状态获取对场景对象的引用时,可以使用 pyfbsdk 模块中定义的全局函数。如果做不到这一点,您可以通过 FBScene 类访问特定类型的所有组件的列表。

  • FBFindModelByLabelName 返回一个给定其确切长名称的模型。FBFindObjectByFullName 返回一个给定其全名的组件。
    FBFindObjectsByNamespace 和 FBFindObjectsByName 根据名称搜索多个组件。它们通过填充 FBComponentList 返回其结果。

  • FBGetSelectedModels 使用当前选择的所有模型填充 FBModelList。

    selectedModels = FBModelList()
    
    topModel = None # 搜索所有模型,而不仅仅是一个特定的分支
    selectionState = True # 返回选择物体
    sortBySelectOrder = True # 按照选择顺序排序
    FBGetSelectedModels(selectedModels, topModel, selectionState, sortBySelectOrder)
    
    for model in selectedModels:
        print model, model.LongName
    
  • FBScene 类(可通过 FBSystem().Scene) 可用于循环访问特定类型的所有组件。

  • FBScene.Components是场景中每个组件的列表。

  • FBScene还为各种组件子类提供了许多列表,包括Cameras, Actors, ControlSets(control rigs), Groups等。

  • 与其他类型的组件不同,模型是分层的(即,它们具有子级)。FBScene.RootModel 是场景中最顶层的单个模型。FBModel.子函数允许我们迭代模型,我们通常使用递归函数对整个分支进行操作。

# 选择所有模型
def SelectBranch(topModel):
    for childModel in topModel.Children:
        SelectBranch(childModel)
    topModel.Selected = True

for model in FBSystem().Scene.RootModel.Children:
    SelectBranch(model)
  • Actors and Characters (and, as it happens, story tracks) 是FBConstraint的特定子类。
  • 默认摄像机(Producer Perspective, Producer Front, etc.)_位于_“摄像机”列表中,并且它们是实际的 FBCamera 对象。但是,它们不存在于场景中作为模型,删除它们会使 MotionBuilder 崩溃. 这些默认摄像机的FBCamera.SystemCamera属性是True
Group Name Associated Navigator Categories Base Class
Model Scene, Cameras, Lights FBModel
Constraint Constraints, Actors, Characters FBConstraint
MarkerSet Marker Sets FBMarkerSet
Audio Audio FBAudioClip
Device Devices FBDevice
Material Materials FBMaterial
Pose Poses FBPose
Shader Shaders FBShader
Take Takes FBTake
Texture Textures FBTexture
Video Videos FBVideo

评论
  目录