class mrpt::viz::CAssimpModel

Python API: mrpt.viz.CAssimpModel

Overview

This class can load & render 3D models in a number of different formats (requires the library assimp).

Supported formats (via Assimp library): http://assimp.sourceforge.net/main_features_formats.html

Most common ones: AutoCAD DXF (.dxf), Collada (.dae), Blender 3D (.blend), 3ds Max 3DS (.3ds), 3ds Max ASE (.ase), Quake I (.mdl), Quake II (.md2), Quake III Mesh (.md3), Wavefront OBJ (.obj), Stanford PLY (.ply), glTF (.gltf, .glb), FBX (.fbx), etc.

Models are loaded via CAssimpModel::loadScene()

Architecture (MRPT 3.0) :

The class is a CSetOfObjects container that holds:

mrpt::viz::CAssimpModel

See also:

mrpt::viz::Scene, CSetOfObjects, CSetOfTexturedTriangles

#include <mrpt/viz/CAssimpModel.h>

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

    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 AssimpSceneWrapper;
    struct LoadFlags;
    struct LoadedTexture;
    struct TextureInfo;

    // fields

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

    // construction

    CAssimpModel();
    CAssimpModel(CAssimpModel&&);

    // 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 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&&);
};

// direct descendants

class CAnimatedAssimpModel;

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;

    // structs

    struct BuffersVersion;
    struct ChangeCounter;
    struct PoseAndScale;
    struct State;

    // fields

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

    // 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;

Typedefs

typedef std::shared_ptr<mrpt::viz ::CAssimpModel> 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 from a file in any Assimp-supported format.

This clears any previously loaded content and populates this object with the loaded model’s geometry, materials, and textures.

Example:

CAssimpModel model;
model.loadScene("robot.dae", CAssimpModel::LoadFlags::RealTimeMaxQuality);
scene->insert(model);

Textures are loaded from paths relative to the model file’s directory

Parameters:

file_name

Path to the 3D model file

flags

Combination of LoadFlags values (OR’d together)

std::runtime_error

On any error during loading or importing

void clear()

Clear the loaded model and all child objects.

const std::string& getModelPath() const

Returns the path of the currently loaded model, or empty string if none.

uint32_t getModelLoadFlags() const

Returns the flags used when loading the current model.

void setSplitTrianglesRenderingBBox(] float bbox_size)

Deprecated Does nothing.

Textures with transparent parts (alpha cutout) render correctly without splitting the model, see TAlphaMode.

float getSplitTrianglesRenderingBBox() const

Deprecated Always returns 0.

size_t getTexturedMeshCount() const

Returns the number of textured mesh groups in the loaded model.

size_t getNonTexturedTriangleCount() const

Returns the number of non-textured triangles in the model.

size_t getLineCount() const

Returns the number of line segments in the model.

size_t getTotalVertexCount() const

Returns the total vertex count across all meshes.

size_t getTotalTriangleCount() const

Returns the total triangle count across all meshes.

std::vector<TextureInfo> getTextureInfo() const

Returns information about all textures in the model.

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()

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