class mrpt::opengl::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
// (buffers are rebuilt automatically on next render)
#include <mrpt/opengl/CAnimatedAssimpModel.h>

class CAnimatedAssimpModel: public mrpt::opengl::CAssimpModel
{
public:
    // structs

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

    // construction

    CAnimatedAssimpModel();

    // methods

    virtual void render(const RenderContext& rc) const;
    virtual shader_list_t requiredShaders() const;
    virtual void onUpdateBuffers_Wireframe();
    virtual void onUpdateBuffers_Triangles();
    virtual void onUpdateBuffers_Points();
    virtual void freeOpenGLResources();
    virtual bool isCompositeObject() const;
    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();
    void loadScene(const std::string& file_name, const int flags = LoadFlags::RealTimeMaxQuality|LoadFlags::FlipUVs|LoadFlags::Verbose);
    void clear();
    virtual bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const;
    virtual mrpt::math::TBoundingBoxf internalBoundingBoxLocal() const;
    void split_triangles_rendering_bbox(const float bbox_size);
    auto texturedObjects();
    void setPointSize(float p);
    void enableVariablePointSize(bool enable = true);
    void setVariablePointSize_k(float v);
    void setVariablePointSize_DepthScale(float v);
};

Inherited Members

public:
    // typedefs

    typedef std::string filepath_t;

    // structs

    struct OutdatedState;
    struct RenderContext;
    struct State;
    struct GlState;
    struct GlsHandle;
    struct GlState;
    struct GlsHandle;
    struct GlState;
    struct GlsHandle;
    struct Impl;
    struct LoadFlags;
    struct TInfoPerTexture;

    // methods

    virtual void render(const RenderContext& rc) const = 0;
    virtual void renderUpdateBuffers() const = 0;
    virtual shader_list_t requiredShaders() const;
    virtual void freeOpenGLResources() = 0;
    virtual void onUpdateBuffers_Triangles() = 0;
    virtual void onUpdateBuffers_Wireframe() = 0;
    virtual void onUpdateBuffers_Points() = 0;
    virtual void renderUpdateBuffers() const;
    virtual void onUpdateBuffers_all();
    void enqueueForRenderRecursive(const mrpt::opengl::TRenderMatrices& state, RenderQueue& rq, bool wholeInView, bool is1stShadowMapPass) const;
    float split_triangles_rendering_bbox() const;

Methods

virtual void render(const RenderContext& rc) const

Implements the rendering of 3D objects in each class derived from CRenderizable.

This can be called more than once (one per required shader program) if the object registered several shaders.

See also:

renderUpdateBuffers

virtual shader_list_t requiredShaders() const

Returns the ID of the OpenGL shader program required to render this class.

See also:

DefaultShaderID

virtual void onUpdateBuffers_Wireframe()

Must be implemented in derived classes to update the geometric entities to be drawn in “m_*_buffer” fields.

virtual void onUpdateBuffers_Triangles()

Must be implemented in derived classes to update the geometric entities to be drawn in “m_*_buffer” fields.

virtual void onUpdateBuffers_Points()

Must be implemented in derived classes to update the geometric entities to be drawn in “m_*_buffer” fields.

virtual void freeOpenGLResources()

Free opengl buffers.

virtual bool isCompositeObject() const

Should return true if enqueueForRenderRecursive() is defined since the object has inner children.

Examples: CSetOfObjects, CAssimpModel.

void setAnimationTime(double timeSeconds)

Set current animation time in seconds.

Updates all bone transforms for the active animation and marks render buffers for rebuild.

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.

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

Loads a scene from a file in any supported file.

Parameters:

std::runtime_error

On any error during loading or importing the file.

void clear()

Empty the object.

virtual bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const

Simulation of ray-trace, given a pose.

Returns true if the ray effectively collisions with the object (returning the distance to the origin of the ray in “dist”), or false in other case. “dist” variable yields undefined behaviour when false is returned

virtual mrpt::math::TBoundingBoxf internalBoundingBoxLocal() const

Must be implemented by derived classes to provide the updated bounding box in the object local frame of coordinates.

This will be called only once after each time the derived class reports to notifyChange() that the object geometry changed.

See also:

getBoundingBox(), getBoundingBoxLocal(), getBoundingBoxLocalf()

void split_triangles_rendering_bbox(const float bbox_size)

Enable (or disable if set to .0f) a feature in which textured triangles are split into different renderizable smaller objects.

This is required only for semitransparent objects with overlaping regions.

auto texturedObjects()

Read-only access to textured objects.

[New in MRPT 2.6.0]

void setPointSize(float p)

By default is 1.0.

See also:

enableVariablePointSize()

void enableVariablePointSize(bool enable = true)

Enable/disable variable eye distance-dependent point size (default=true)

void setVariablePointSize_k(float v)

see CRenderizableShaderPoints for a discussion of this parameter.

void setVariablePointSize_DepthScale(float v)

see CRenderizableShaderPoints for a discussion of this parameter.