class mrpt::viz::CAnimatedAssimpModel

Python API: mrpt.viz.CAnimatedAssimpModel

Overview

Extension of CAssimpModel with skeletal animation support.

Supports models that contain bone hierarchies and keyframed animations (FBX, glTF/GLB, Collada, etc. via Assimp).

CPU-side vertex skinning is performed each time the animation time changes: bind-pose vertex positions are stored on first load and then transformed through the active bone matrices every frame.

Usage:

auto model = CAnimatedAssimpModel::Create();
model->loadScene("character.glb");

// In simulation loop:
model->setAnimationTime(simTime);  // updates bone transforms & rebuilds geometry
#include <mrpt/viz/CAnimatedAssimpModel.h>

class CAnimatedAssimpModel: public mrpt::viz::CAssimpModel
{
public:
    // typedefs

    typedef std::shared_ptr<mrpt::viz ::CAnimatedAssimpModel> Ptr;
    typedef std::shared_ptr<const mrpt::viz ::CAnimatedAssimpModel> ConstPtr;
    typedef std::unique_ptr<mrpt::viz ::CAnimatedAssimpModel> UniquePtr;
    typedef std::unique_ptr<const mrpt::viz ::CAnimatedAssimpModel> ConstUniquePtr;

    // structs

    struct Animation;
    struct Bone;
    struct BoneAnimation;
    struct MeshBindPose;
    struct QuatKey;
    struct VectorKey;
    struct VertexBoneData;

    // fields

    static constexpr const char* className = "mrpt::viz" "::" "CAnimatedAssimpModel";

    // construction

    CAnimatedAssimpModel();

    // methods

    static constexpr auto getClassName();
    static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic();
    static std::shared_ptr<CObject> CreateObject();

    template <typename... Args>
    static Ptr Create(Args&&... args);

    template <typename Alloc, typename... Args>
    static Ptr CreateAlloc(
        const Alloc& alloc,
        Args&&... args
        );

    template <typename... Args>
    static UniquePtr CreateUnique(Args&&... args);

    virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const;
    virtual mrpt::rtti::CObject* clone() const;
    void loadScene(const std::string& file_name, int flags = LoadFlags::RealTimeMaxQuality|LoadFlags::FlipUVs|LoadFlags::Verbose);
    void setAnimationTime(double timeSeconds);
    double getAnimationDuration(size_t animIndex = 0) const;
    size_t getAnimationCount() const;
    std::string getAnimationName(size_t animIndex) const;
    void setActiveAnimation(size_t animIndex);
    void setActiveAnimation(const std::string& animName);
    void setLooping(bool loop);
    double getAnimationProgress() const;
    size_t getBoneCount() const;
    int getBoneIndex(const std::string& boneName) const;
    void setBoneLocalTransform(size_t boneIndex, const mrpt::math::CMatrixDouble44& localTransform);
    void clearBoneOverrides();
};

Inherited Members

public:
    // typedefs

    typedef std::shared_ptr<CObject> Ptr;
    typedef std::shared_ptr<const CObject> ConstPtr;
    typedef std::unique_ptr<CObject> UniquePtr;
    typedef std::unique_ptr<const CObject> ConstUniquePtr;
    typedef std::shared_ptr<CSerializable> Ptr;
    typedef std::shared_ptr<const CSerializable> ConstPtr;
    typedef std::shared_ptr<CVisualObject> Ptr;
    typedef std::shared_ptr<const CVisualObject> ConstPtr;
    typedef std::shared_ptr<mrpt::viz ::CSetOfObjects> Ptr;
    typedef std::shared_ptr<const mrpt::viz ::CSetOfObjects> ConstPtr;
    typedef std::unique_ptr<mrpt::viz ::CSetOfObjects> UniquePtr;
    typedef std::unique_ptr<const mrpt::viz ::CSetOfObjects> ConstUniquePtr;
    typedef mrpt::containers::deep_const_iterator<ListVisualObjects::const_iterator> const_iterator;
    typedef ListVisualObjects::iterator iterator;
    typedef std::shared_ptr<mrpt::viz ::CAssimpModel> Ptr;
    typedef std::shared_ptr<const mrpt::viz ::CAssimpModel> ConstPtr;
    typedef std::unique_ptr<mrpt::viz ::CAssimpModel> UniquePtr;
    typedef std::unique_ptr<const mrpt::viz ::CAssimpModel> ConstUniquePtr;

    // structs

    struct BuffersVersion;
    struct ChangeCounter;
    struct PoseAndScale;
    struct State;
    struct AssimpSceneWrapper;
    struct LoadFlags;
    struct LoadedTexture;
    struct TextureInfo;

    // fields

    static constexpr const char* className = "mrpt::viz" "::" "CSetOfObjects";
    static constexpr const char* className = "mrpt::viz" "::" "CAssimpModel";

    // methods

    mrpt::rtti::CObject::Ptr duplicateGetSmartPtr() const;
    static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic();
    virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const;
    virtual CObject* clone() const = 0;
    virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const;
    static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic();
    virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const;
    static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic();
    void setName(const std::string& n);
    std::string getName() const;
    bool isVisible() const;
    void setVisibility(bool visible = true);
    bool castShadows() const;
    void castShadows(bool doCast);
    void enableShowName(bool showName = true);
    bool isShowNameEnabled() const;
    CVisualObject& setPose(const mrpt::poses::CPose3D& o);
    CVisualObject& setPose(const mrpt::poses::CPose2D& o);
    CVisualObject& setPose(const mrpt::math::TPose3D& o);
    CVisualObject& setPose(const mrpt::math::TPose2D& o);
    CVisualObject& setPose(const mrpt::poses::CPoint3D& o);
    CVisualObject& setPose(const mrpt::poses::CPoint2D& o);
    mrpt::math::TPose3D getPose() const;
    PoseAndScale getPoseAndScale() const;
    mrpt::poses::CPose3D getCPose() const;
    CVisualObject& setLocation(double x, double y, double z);
    CVisualObject& setLocation(const mrpt::math::TPoint3D& p);
    mrpt::img::TColorf getColor() const;
    mrpt::img::TColor getColor_u8() const;
    CVisualObject& setColorA(const float a);
    virtual CVisualObject& setColorA_u8(const uint8_t a);
    float materialShininess() const;
    void materialShininess(float shininess);
    float materialSpecularExponent() const;
    void materialSpecularExponent(float exponent);
    mrpt::img::TColorf materialEmissive() const;
    void materialEmissive(const mrpt::img::TColorf& color);
    CVisualObject& setScale(float s);
    CVisualObject& setScale(float sx, float sy, float sz);
    float getScaleX() const;
    float getScaleY() const;
    float getScaleZ() const;
    CVisualObject& setColor(const mrpt::img::TColorf& c);
    CVisualObject& setColor(float R, float G, float B, float A = 1);
    virtual CVisualObject& setColor_u8(const mrpt::img::TColor& c);
    CVisualObject& setColor_u8(uint8_t R, uint8_t G, uint8_t B, uint8_t A = 255);
    virtual bool cullElegible() const;
    virtual void toYAMLMap(mrpt::containers::yaml& propertiesMap) const;
    virtual bool isCompositeObject() const;
    virtual const std::deque<std::shared_ptr<CVisualObject>>& getInternalChildren() const;
    void notifyChange() const;
    void notifyTransformChange() const;
    void clearChangedFlag() const;
    void notifyBBoxChange() const;
    bool hasToUpdateBuffers() const;
    uint64_t dataVersion() const;
    uint64_t transformVersion() const;
    bool hasToUpdateBuffersSince(uint64_t sinceVersion) const;
    void updateBuffersIfNeeded() const;
    virtual void updateBuffers() const;
    virtual bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const;
    auto getBoundingBox() const;
    auto getBoundingBoxLocal() const;
    auto getBoundingBoxLocalf() const;
    virtual mrpt::math::TPoint3Df getLocalRepresentativePoint() const;
    void setLocalRepresentativePoint(const mrpt::math::TPoint3Df& p);
    mrpt::viz::CText& labelObject() const;
    std::shared_ptr<mrpt::viz::CText> labelObjectPtr() const;
    static constexpr auto getClassName();
    static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic();
    static std::shared_ptr<CObject> CreateObject();

    template <typename... Args>
    static Ptr Create(Args&&... args);

    template <typename Alloc, typename... Args>
    static Ptr CreateAlloc(
        const Alloc& alloc,
        Args&&... args
        );

    template <typename... Args>
    static UniquePtr CreateUnique(Args&&... args);

    virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const;
    virtual mrpt::rtti::CObject* clone() const;
    static CSetOfObjects::Ptr posePDF2opengl(const mrpt::poses::CPosePDF& o);
    static CSetOfObjects::Ptr posePDF2opengl(const mrpt::poses::CPointPDF& o);
    static CSetOfObjects::Ptr posePDF2opengl(const mrpt::poses::CPose3DPDF& o);
    static CSetOfObjects::Ptr posePDF2opengl(const mrpt::poses::CPose3DQuatPDF& o);
    const_iterator begin() const;
    const_iterator end() const;
    iterator begin();
    iterator end();

    template <class T>
    void insertCollection(const T& objs);

    void insert(const CVisualObject::Ptr& newObject);

    template <class T_it>
    void insert(const T_it& begin, const T_it& end);

    void clear();
    size_t size() const;
    bool empty() const;
    CVisualObject::ConstPtr getByName(const std::string& str) const;
    CVisualObject::Ptr getByName(const std::string& str);

    template <typename T>
    T::ConstPtr getByClass(size_t ith = 0) const;

    template <typename T>
    T::Ptr getByClass(size_t ith = 0);

    void removeObject(const CVisualObject::Ptr& obj);
    void dumpListOfObjects(std::vector<std::string>& lst) const;
    mrpt::containers::yaml asYAML() const;
    virtual bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const;
    virtual CVisualObject& setColor_u8(const mrpt::img::TColor& c);
    virtual CVisualObject& setColorA_u8(const uint8_t a);
    bool contains(const CVisualObject::Ptr& obj) const;
    virtual mrpt::math::TBoundingBoxf internalBoundingBoxLocal() const;
    static constexpr auto getClassName();
    static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic();
    static std::shared_ptr<CObject> CreateObject();

    template <typename... Args>
    static Ptr Create(Args&&... args);

    template <typename Alloc, typename... Args>
    static Ptr CreateAlloc(
        const Alloc& alloc,
        Args&&... args
        );

    template <typename... Args>
    static UniquePtr CreateUnique(Args&&... args);

    virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const;
    virtual mrpt::rtti::CObject* clone() const;
    void loadScene(const std::string& file_name, int flags = LoadFlags::RealTimeMaxQuality|LoadFlags::FlipUVs|LoadFlags::Verbose);
    void clear();
    const std::string& getModelPath() const;
    uint32_t getModelLoadFlags() const;
    void setSplitTrianglesRenderingBBox(] float bbox_size);
    float getSplitTrianglesRenderingBBox() const;
    size_t getTexturedMeshCount() const;
    size_t getNonTexturedTriangleCount() const;
    size_t getLineCount() const;
    size_t getTotalVertexCount() const;
    size_t getTotalTriangleCount() const;
    std::vector<TextureInfo> getTextureInfo() const;
    virtual mrpt::math::TBoundingBoxf internalBoundingBoxLocal() const;
    virtual bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const;
    CAssimpModel& operator = (CAssimpModel&&);

Typedefs

typedef std::shared_ptr<mrpt::viz ::CAnimatedAssimpModel> Ptr

A type for the associated smart pointer.

Methods

virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const

Returns information about the class of an object in runtime.

virtual mrpt::rtti::CObject* clone() const

Returns a deep copy (clone) of the object, indepently of its class.

void loadScene(const std::string& file_name, int flags = LoadFlags::RealTimeMaxQuality|LoadFlags::FlipUVs|LoadFlags::Verbose)

Loads a 3D scene and extracts skeleton/animation data.

void setAnimationTime(double timeSeconds)

Set current animation time in seconds.

Updates all bone transforms for the active animation and rebuilds the mesh geometry with skinned positions.

double getAnimationDuration(size_t animIndex = 0) const

Get animation duration in seconds.

size_t getAnimationCount() const

Get number of animations in the model.

std::string getAnimationName(size_t animIndex) const

Get animation name by index.

void setActiveAnimation(size_t animIndex)

Select which animation to play (by index).

void setActiveAnimation(const std::string& animName)

Select which animation to play (by name).

Does nothing if the name is not found.

void setLooping(bool loop)

Enable/disable animation looping.

double getAnimationProgress() const

Get current normalized animation progress [0,1].

size_t getBoneCount() const

Get number of bones.

int getBoneIndex(const std::string& boneName) const

Get bone index by name, or -1 if not found.

void setBoneLocalTransform(size_t boneIndex, const mrpt::math::CMatrixDouble44& localTransform)

Override a bone’s local transform (for procedural animation).

void clearBoneOverrides()

Clear all bone overrides, return to animation-driven transforms.