05-角色动画模块(CS)

3ds Max SDK 更新于 2026-11-09 content/docs 文件
目录(18)

# 3ds Max SDK - 角色动画模块 (Character Studio / Biped)

概述

Character Studio(CS)模块处理 3ds Max 的双足角色(Biped)动画。其公共 C++ API 以 IBipDriver10 接口为核心,并提供 Mixer(动画混合器)与 MoFlow(运动流)两组接口。

本文件仅记录已核实的公开 C++ API。下列内容属于内部 / MAXScript 层、不属于公开 C++ API,不应作为公开接口文档:CreateNewBiped、SaveBipFileDlg/LoadBipFileDlg(属 IBipDriver 基类,非 IBipDriver10 公开用法示例中的推荐入口)、BeginModes/EndModes、SetIKBlend、CreateFootsteps/DeleteFootsteps(以上为早期内部/脚本封装,不在公开的 IBipDriver10 推荐用法范围内)。


目录


1. 模块概述

1.1 核心组件

组件 说明 头文件
IBipDriver10 Biped 驱动接口(Max 10 Biped 导出接口) CS/Biped10Api.h
IBipDriver IBipDriver10 的基类(承载 GetMixer/GetMoFlow/SetBipedKey 等) CS/BipedApi.h
IMixer 动画混合器接口 CS/IMixer.h
IMXtrackgroup 混合器轨道组接口 CS/IMixer.h
IMXtrack 混合器轨道接口 CS/IMixer.h
IMoFlow 运动流接口 CS/IMoFlow.h
骨骼索引枚举 Biped 骨骼索引常量 CS/biped.h

1.2 接口标识宏

  • 头文件:CS/Biped10Api.h
#define I_BIPDRIVER10 0x9170                 // Biped 接口标识

// 获取接口(废弃的同义宏 I_BIPMASTER10 / GetBipMaster10Interface 自 2022 起建议替换)
#define GetBipDriver10Interface(anim) \
    ((IBipDriver10*)(anim)->GetInterface(I_BIPDRIVER10))

2. Biped 核心接口 IBipDriver10

  • 头文件:CS/Biped10Api.h
  • 继承链:IBipDriver10 : public IBipDriver9(→ IBipDriver8 → … → IBipDriver : public MaxHeapOperators),接口查询宏 I_BIPDRIVER10(值 0x9170)

IBipDriver10 是 Max 10 引入的 Biped 导出接口,通过宏 GetBipDriver10Interface(anim)(定义于 CS/Biped10Api.h)从实现了该接口的动画对象(通常为 Biped 根节点的控制器)上取得。下列节点/关键帧/混合器接口均继承自基类 IBipDriver(声明于 CS/BipedApi.h),IBipDriver10 本身在 CS/Biped10Api.h 中进一步扩展 Xtra、动画层 BIP I/O 等能力:

// 来自基类 IBipDriver(CS/BipedApi.h)
class IBipDriver : public MaxHeapOperators {
public:
    virtual bool IsNodeDeleted() = 0;
    virtual Interval GetCurrentRange() = 0;          // 当前动画范围
    virtual int  GetMaxNodes() = 0;                  // Biped 节点总数
    virtual int  GetMaxLinks() = 0;                  // 最大骨骼链接数
    virtual INode* GetNode(int id, int link = 0) = 0;

    // 关键帧设置
    virtual void SetBipedKey(TimeValue t, INode* node = NULL,
                             BOOL setHor = TRUE, BOOL setVer = TRUE,
                             BOOL setTurn = TRUE) = 0;
    virtual void SetPlantedKey(TimeValue t, INode* node = NULL) = 0;
    virtual void SetSlidingKey(TimeValue t, INode* node = NULL) = 0;
    virtual void SetFreeKey(TimeValue t, INode* node = NULL) = 0;

    // 变换读写(世界空间)
    virtual ScaleValue GetBipedScale(TimeValue t, INode* node) = 0;
    virtual Point3    GetBipedPos(TimeValue t, INode* node) = 0;
    virtual Quat      GetBipedRot(TimeValue t, INode* node, BOOL local = FALSE) = 0;
    virtual void SetBipedScale(BOOL relative, const ScaleValue& scale,
                               TimeValue t, INode* node) = 0;
    virtual void SetBipedPos(const Point3& p, TimeValue t, INode* node,
                             BOOL setKey = TRUE) = 0;
    virtual void SetBipedRot(const Quat& q, TimeValue t, INode* node,
                             BOOL setKey = TRUE) = 0;

    // 混合器 / 运动流
    virtual IMixer*  GetMixer() = 0;
    virtual IMoFlow* GetMoFlow() = 0;
};

// IBipDriver10 自身(CS/Biped10Api.h):class IBipDriver10 : public IBipDriver9
class IBipDriver10 : public IBipDriver9 {
public:
    // Xtras
    virtual INode *CreateXtra(int nlinks, const MCHAR *name) = 0;
    virtual INode *CreateXtraOpposite(INode& xtra, bool doChildren) = 0;
    virtual INode *GetXtraOpposite(INode& xtra) = 0;
    virtual bool DeleteXtra(INode& xtraBase) = 0;
    virtual bool AttachXtra(INode& xtraBase, INode& parent) = 0;
    virtual void SetXtraName(INode& xtraBase, const MCHAR *name) = 0;
    virtual const MCHAR* GetXtraName(INode& xtraBase) = 0;
    virtual bool PastePostureToXtras(IBipedCopy *CP, INodeTab& nodes, int KeyPasteType) = 0;
    virtual bool PasteTrackToXtras(IBipedCopy *CP, INodeTab& nodes) = 0;

    // Animation Layer I/O
    virtual bool SaveBipedAnimationLayer(const MCHAR *fname, int layerIndex) = 0;
    virtual bool LoadBipedAnimationLayer(const MCHAR *fname, int layerIndex) = 0;
    virtual bool SaveBipedBaseAnimationLayer(const MCHAR *fname,
                int saveMaxObjects, INodeTab *maxObjects,
                int saveControllers, Tab<SaveSubAnimInfo> *controllers) = 0;
    virtual bool LoadBipedBaseAnimationLayer(const MCHAR *fname, BOOL MatchFile, BOOL ZeroFootHeight,
                BOOL promptForDuplicates, int retargetType, BOOL scaleIKObjectSize,
                int loadMaxObjects, Tab<const MCHAR *> *maxObjectNames,
                int loadControllers, Tab<LoadSubAnimInfo> *controllers) = 0;
};

IBipDriver10 并非继承自 BaseInterface/FPInterface,而是 IBipDriver9 的派生类;GetBipDriver10Interface(anim) 通过 anim->GetInterface(I_BIPDRIVER10) 返回。上面列出的节点访问、关键帧设置、变换读写以及 GetMixer()/GetMoFlow() 均定义在基类 IBipDriver(CS/BipedApi.h)中。


3. 骨骼索引枚举

  • 头文件:biped.h

Biped 的骨骼索引(用于 GetNode(id, link) 的 id 参数)在 biped.h 中以枚举常量形式定义,例如 BIP_PELVIS、BIP_SPINE、BIP_NECK、BIP_HEAD、左右锁骨/上臂/前臂/手、左右大腿/小腿/脚/趾等。具体枚举名与取值以本地 biped.h 为准。


4. 动画混合器 IMixer

  • 头文件:CS/IMixer.h
  • 继承链:IMixer : public MaxHeapOperators(抽象接口)
class IMixer : public MaxHeapOperators {
public:
    virtual ~IMixer() {;}

    // trackgroups
    virtual int          NumTrackgroups() = 0;
    virtual IMXtrackgroup *GetTrackgroup(int index) = 0;
    virtual BOOL         InsertTrackgroup(int index) = 0;
    virtual BOOL         DeleteTrackgroup(int index) = 0;

    // balance
    virtual float        GetBalancePropagation() = 0;   // between 0.0 and 1.0
    virtual BOOL         SetBalancePropagation(float val) = 0;
    virtual float        GetBalanceLateralRatio() = 0;  // between 0.0 and 1.0
    virtual BOOL         SetBalanceLateralRatio(float val) = 0;
    virtual BOOL         GetBalanceMute() = 0;
    virtual BOOL         SetBalanceMute(BOOL val) = 0;

    // mixer
    virtual BOOL         IsPerformingMixdown() = 0;
    virtual void         InvalidateRawMix() = 0;
    virtual void         EffectRawMix() = 0;
    virtual void         EffectMixdown() = 0;
    virtual BOOL         Mixdown(BOOL KeyPerFrame, BOOL EnforceIkConstraints,
                                 int ContinuityRange, BOOL FilterHyperExtLegs,
                                 float MaxKneeAngle) = 0;
    virtual void         CopyClipSourceToBiped(IMXclip *iCP) = 0;
    virtual void         CopyMixdownToBiped() = 0;
    virtual BOOL         LoadMixFile(const MCHAR *fname, BOOL redraw) = 0;
    virtual BOOL         SaveMixFile(const MCHAR *fname) = 0;
    virtual void         GetInterval(Interval& iv) = 0;
    virtual BOOL         ExistingMixdown() = 0;
    virtual void         ClearMixer() = 0;

    // display / UI state (GetShow* / SetShow* 系列)
    virtual BOOL         GetSnapFrames() = 0;
    virtual void         SetSnapFrames(BOOL onOff) = 0;
    virtual BOOL         GetShowTgRangebars() = 0;
    virtual void         SetShowTgRangebars(BOOL onOff) = 0;
    virtual BOOL         GetShowWgtCurves() = 0;
    virtual void         SetShowWgtCurves(BOOL onOff) = 0;
    virtual BOOL         GetShowTimeWarps() = 0;
    virtual void         SetShowTimeWarps(BOOL onOff) = 0;
    virtual BOOL         GetShowClipBounds() = 0;
    virtual void         SetShowClipBounds(BOOL onOff) = 0;
    virtual BOOL         GetShowGlobal() = 0;
    virtual void         SetShowGlobal(BOOL onOff) = 0;
    virtual BOOL         GetShowClipNames() = 0;
    virtual void         SetShowClipNames(BOOL onOff) = 0;
    virtual BOOL         GetShowClipScale() = 0;
    virtual void         SetShowClipScale(BOOL onOff) = 0;
    virtual BOOL         GetShowTransStart() = 0;
    virtual void         SetShowTransStart(BOOL onOff) = 0;
    virtual BOOL         GetShowTransEnd() = 0;
    virtual void         SetShowTransEnd(BOOL onOff) = 0;
    virtual BOOL         GetShowBalance() = 0;
    virtual void         SetShowBalance(BOOL onOff) = 0;
    virtual BOOL         GetSnapToClips() = 0;
    virtual void         SetSnapToClips(BOOL onOff) = 0;
    virtual BOOL         GetLockTransitions() = 0;
    virtual void         SetLockTransitions(BOOL onOff) = 0;

    // dialog / display
    virtual void         SetAnimationRange() = 0;
    virtual void         ZoomExtents() = 0;
    virtual void         UpdateDisplay() = 0;
    virtual void         AddToDisplay() = 0;
    virtual void         RemoveFromDisplay() = 0;
    virtual void         ShowMixer() = 0;
    virtual void         HideMixer() = 0;
};

IMXtrackgroup 与 IMXtrack 为 IMixer 体系内的真实接口(位于 IMixer.h),用于管理轨道组与轨道;具体方法(如 NumTracks、GetTrack 等)以本地头文件为准。


5. 运动流 IMoFlow

  • 头文件:CS/IMoFlow.h
  • 继承链:IMoFlow : public MaxHeapOperators(抽象接口)
class IMoFlow : public MaxHeapOperators {
public:
    virtual ~IMoFlow() {;}

    virtual int     NumScripts() const = 0;
    virtual int     NumSelected() const = 0;
    virtual Script* GetScript(int index) = 0;
    virtual Script* GetActiveScript() = 0;
    virtual void    SetActiveScript(Script* scr) = 0;
    virtual int     GetScriptIndex(Script *theSCR) const = 0;

    virtual int     AddScript(const MCHAR *newscriptname, bool activate = true) = 0;
    virtual void    DeleteScript(Script *delSCR) = 0;
    virtual void    DeleteScript(int ind) = 0;
    virtual void    DeleteAllScripts() = 0;

    virtual int     NumSnippets() const = 0;
    virtual const BitArray& GetSelected() const = 0;
    virtual void    SetSelected(const BitArray& sel) = 0;
    virtual Snippet* GetSnip(int index) = 0;
    virtual Snippet* GetSnip(const MCHAR *str) = 0;
    virtual int     GetIndex(Snippet *theSN) const = 0;
    virtual int     LoadSnippetFiles(bool UpdateTheUI = true, int ErrorType = 3, bool UpdateSNLengths = false) = 0;

    virtual int     GetActiveStartFrame() const = 0;
    virtual int     GetActiveEndFrame() const = 0;

    virtual int     Save(const MCHAR *fname) = 0;
    virtual int     Load(const MCHAR *fname, bool Append = false, bool UpdateTheUI = true, int ErrorType = 3) = 0;

    virtual IBipDriver* GetBipDriver() = 0;          // 反查 Biped 驱动
    virtual const IBipDriver* GetBipDriver() const = 0;

    virtual void    ComputeAnimation(int redraw, int globalsToo = FALSE) = 0;
    virtual void    CurscriptToActiveLinks() = 0;
    virtual Snippet* NewSnippet(const MCHAR *fname, POINT &mp, bool load = false, bool redraw = false) = 0;
    virtual void    DeleteSnip(Snippet *DelSnip) = 0;
    virtual void    RedrawGraphWnd() = 0;
    virtual void    UpdateUI() = 0;
    virtual void    HoldTrack(int HoldAnimals, BOOL HoldScriptOffsetOnly = false) = 0;
};

IMXclip/IMXtransition/IMXscript 等运动流相关类型在 IMoFlow 体系中以 Script/Snippet 等正式名称存在;文档中旧版的 IMXclip/IMXtransition 命名与部分虚构方法(如 Start/Stop/IsRunning)并非公开接口,已移除。


6. 使用示例

6.1 获取 IBipDriver10 并读取节点

#include "CS/Biped10Api.h"
#include "CS/biped.h"
#include "INode.h"

void InspectBiped(Animatable* bipRoot) {
    IBipDriver10* bip = GetBipDriver10Interface(bipRoot);
    if (!bip) return;

    if (bip->IsNodeDeleted()) return;

    int maxNodes = bip->GetMaxNodes();
    int maxLinks = bip->GetMaxLinks();

    // 取骨盆节点(BIP_PELVIS 为 biped.h 中枚举值)
    INode* pelvis = bip->GetNode(BIP_PELVIS, 0);

    // 取混合器与运动流
    IMixer*  mixer  = bip->GetMixer();
    IMoFlow* moflow = bip->GetMoFlow();
    if (mixer)  mixer->EffectRawMix();
    if (moflow) moflow->GetBipDriver();
}

6.2 设置关键帧

#include "CS/Biped10Api.h"
#include "quat.h"

void KeyBiped(IBipDriver10* bip, INode* node, TimeValue t) {
    // 在当前帧为指定节点设置默认关键帧
    bip->SetBipedKey(t, node);

    // 设置旋转
    Quat q;            // 由旋转构造
    bip->SetBipedRot(q, t, node, TRUE);
}

7. 已移除的杜撰内容

以下内容经核实不属于公开 C++ API,已从本文件删除:

  • IBipDriver(旧基类接口名)下的 CreateNewBiped、SaveBipFileDlg/LoadBipFileDlg、BeginModes/EndModes、SetIKBlend、CreateFootsteps/DeleteFootsteps —— 属内部/MAXScript 封装。
  • BipedApi/CSConstants/Tracks 等虚构头文件与 GetBipedInterface() 虚构函数。
  • IMXclip/IMXtransition/IMXscript 中以 Start/Stop/IsRunning/SetName 等命名的虚构方法集。
  • 自定义运动模式常量 BIP_FOOTSTEP_MODE 等(属内部实现细节,未作为公开枚举文档化)。

本文档基于 3ds Max 2022 SDK 官方 C++ API Reference 核对编写

最小可编译工程模板与 .lib 精确组合

本模块对应插件类型与产物后缀

通常在一个 Utility(.dlu)里访问 Biped。

需链接的 .lib(精确组合)

  • 通用核心(任何插件都链):core.lib maxutil.lib geom.lib maxscrpt.lib Paramblk2.lib
  • 本模块专用:biped.lib
  • 原则:用到哪个子系统才链哪个。

最小代码骨架

#include "max.h"
#include "CS/Biped10Api.h"
#include "CS/biped.h"

class BipedUtility : public UtilityObj {
public:
    void BeginEditParams(Interface* ip, IUtil* iu) override {
        INode* node = ip->GetSelNode(0);
        if (!node) return;

        // 经节点控制器取得 IBipDriver10(接口 ID 0x9170)
        Animatable* anim = node->GetTMController();
        IBipDriver10* bip = GetBipDriver10Interface(anim);
        if (!bip) return;

        if (!bip->IsNodeDeleted()) {
            int maxNodes = bip->GetMaxNodes();
            INode* pelvis = bip->GetNode(BIP_PELVIS, 0);
            bip->SetBipedKey(ip->GetTime(), pelvis);

            IMixer*  mixer  = bip->GetMixer();
            IMoFlow* moflow = bip->GetMoFlow();
            if (mixer)  mixer->EffectRawMix();
            if (moflow) moflow->ComputeAnimation(TRUE);
        }
    }
    void EndEditParams(Interface* ip, IUtil* iu) override {}
    void DeleteThis() override {}
};

链接器 / CMake 配置

target_link_libraries(<Target> PRIVATE core maxutil geom maxscrpt Paramblk2 biped)