Skip to content

Commit

Permalink
Start of assimp render class
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Sep 2, 2014
1 parent 6e6e665 commit 441a11a
Show file tree
Hide file tree
Showing 7 changed files with 574 additions and 5 deletions.
8 changes: 8 additions & 0 deletions cmakemodules/script_assimp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ IF (NOT ASSIMP_FOUND OR "${ASSIMP_DIR}" STREQUAL "${EMBEDDED_ASSIMP_DIR}")
set(ASSIMP_LIBRARIES "")
LIST(APPEND ASSIMP_LIBRARIES optimized "assimp-mrpt" debug "assimp-mrptd")

# Override binary output dir:
SET_TARGET_PROPERTIES(assimp PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/"
)



SET(CMAKE_MRPT_HAS_ASSIMP 1)
SET(CMAKE_MRPT_HAS_ASSIMP_SYSTEM 0)
ENDIF (BUILD_ASSIMP)
Expand Down
1 change: 1 addition & 0 deletions libs/opengl/include/mrpt/opengl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <mrpt/opengl/CText3D.h>
#include <mrpt/opengl/CTexturedPlane.h>
#include <mrpt/opengl/C3DSScene.h>
#include <mrpt/opengl/CAssimpModel.h>
//#include <mrpt/opengl/CPlanarLaserScan.h> // It's in the lib mrpt-maps now
//#include <mrpt/opengl/CAngularObservationMesh.h> // It's in the lib mrpt-maps now
#include <mrpt/opengl/CCylinder.h>
Expand Down
107 changes: 107 additions & 0 deletions libs/opengl/include/mrpt/opengl/CAssimpModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/* +---------------------------------------------------------------------------+
| Mobile Robot Programming Toolkit (MRPT) |
| http://www.mrpt.org/ |
| |
| Copyright (c) 2005-2014, Individual contributors, see AUTHORS file |
| See: http://www.mrpt.org/Authors - All rights reserved. |
| Released under BSD License. See details in http://www.mrpt.org/License |
+---------------------------------------------------------------------------+ */
#ifndef opengl_CAssimpModel_H
#define opengl_CAssimpModel_H

#include <mrpt/opengl/CRenderizableDisplayList.h>
#include <mrpt/opengl/COpenGLScene.h>
#include <mrpt/utils/CMemoryChunk.h>

namespace mrpt
{
namespace opengl
{
class OPENGL_IMPEXP CAssimpModel;

// This must be added to any CSerializable derived class:
DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CAssimpModel, CRenderizableDisplayList, OPENGL_IMPEXP )

/** This class can load & render 3D models in a number of different formats (requires the library assimp).
* - All supported formats: 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 ), etc.
*
* \sa opengl::COpenGLScene
* \ingroup mrpt_opengl_grp
* \note Class introduced in MRPT 1.2.2
*/
class OPENGL_IMPEXP CAssimpModel : public CRenderizableDisplayList
{
DEFINE_SERIALIZABLE( CAssimpModel )

public:

/** Render child objects.
*/
void render_dl() const;

/** Evaluates the bounding box of this object (including possible children) in the coordinate frame of the object parent. */
virtual void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const;

/** Loads a scene from a 3DS file (3D Studio format) into this object, from either plain .3ds format, or in gzip compressed .3ds.gz format.
* Previous contents are lost.
* If the file ends in ".gz", it'll be automatically decompressed using gzip (see mrpt::compress::zip).
*/
void loadFrom3DSFile( const std::string &file_name );

/** Initializes all textures in the scene (See opengl::CTexturedPlane::loadTextureInOpenGL)
*/
void initializeAllTextures();

/** Empty the object */
void clear();

/** Evaluates the scene at a given animation time
*/
void evaluateAnimation( double time_anim );

/** Enables an extra ambient light */
void enableExtraAmbientLight(bool enable=true) { m_enable_extra_lighting=enable; CRenderizableDisplayList::notifyChange(); }

/* Simulation of ray-trace. */
virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;

private:
/** Default constructor
*/
CAssimpModel( );

/** Private, virtual destructor: only can be deleted from smart pointers */
virtual ~CAssimpModel();

/** A container for automatic deletion of lib3ds's scene when the last reference of the smart_ptr's is destroyed.
*/
struct TImpl3DS
{
TImpl3DS();
~TImpl3DS();
void *file; //!< Lib3dsFile*
};

/** An internal pointer to the lib3ds library's object of type "Lib3dsFile"
*/
stlplus::smart_ptr<TImpl3DS> m_3dsfile;

/** Scale of the object */
//double m_scale_x,m_scale_y,m_scale_z;
mrpt::math::TPoint3D m_bbox_min, m_bbox_max; //!< Bounding box

bool m_enable_extra_lighting;

//float m_light_cons_attenuation; //!< OpenGL Light attenuation factor (default=1.0)
//float m_light_lin_attenuation; //!< OpenGL Light attenuation factor (default=0.0)
//float m_light_quad_attenuation; //!< OpenGL Light attenuation factor (default=0.0)
};


} // end namespace

} // End of namespace


#endif
2 changes: 2 additions & 0 deletions libs/opengl/src/C3DSScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include "opengl-precomp.h" // Precompiled header

MRPT_TODO("Replace this class with a wrapper to assimp")

// Include the lib3ds library:
#include <lib3ds/file.h>
#include <lib3ds/background.h>
Expand Down

0 comments on commit 441a11a

Please sign in to comment.