vinjn / articles

Everything is possible
8 stars 0 forks source link

play_with_assimp #3

Open vinjn opened 11 years ago

vinjn commented 11 years ago

download 3.0

Assimp Viewer is a DX9-based model viewer, it doesn't support animation though.

To build it in vc9, click assimp--3.0.1270\workspaces\vc9\assimp.sln Recommend configurations are debug-dll and release-dll, since the code size is very huge, 100M+ IFC (.ifc, Industry Foundation Classes) is not necessary for game dev/creative coding, it's fine to remove it.

vinjn commented 11 years ago

ASSIMP does not support vertex keyframes (only bone animation is supported). The library reads only one frame of models with vertex animations. By default this is the first frame.

vinjn commented 11 years ago

\assimp--3.0.1270\include\assimp\defs.h

//#define ASSIMP_BUILD_NO_X_IMPORTER
#define ASSIMP_BUILD_NO_3DS_IMPORTER
#define ASSIMP_BUILD_NO_MD3_IMPORTER
#define ASSIMP_BUILD_NO_MDL_IMPORTER
//#define ASSIMP_BUILD_NO_MD2_IMPORTER
//#define ASSIMP_BUILD_NO_PLY_IMPORTER
#define ASSIMP_BUILD_NO_ASE_IMPORTER
//#define ASSIMP_BUILD_NO_OBJ_IMPORTER
#define ASSIMP_BUILD_NO_HMP_IMPORTER
#define ASSIMP_BUILD_NO_SMD_IMPORTER
#define ASSIMP_BUILD_NO_MDC_IMPORTER
#define ASSIMP_BUILD_NO_MD5_IMPORTER
//#define ASSIMP_BUILD_NO_STL_IMPORTER
//#define ASSIMP_BUILD_NO_LWO_IMPORTER
#define ASSIMP_BUILD_NO_DXF_IMPORTER
#define ASSIMP_BUILD_NO_NFF_IMPORTER
#define ASSIMP_BUILD_NO_RAW_IMPORTER
#define ASSIMP_BUILD_NO_OFF_IMPORTER
#define ASSIMP_BUILD_NO_AC_IMPORTER
#define ASSIMP_BUILD_NO_BVH_IMPORTER
#define ASSIMP_BUILD_NO_IRRMESH_IMPORTER
#define ASSIMP_BUILD_NO_IRR_IMPORTER
#define ASSIMP_BUILD_NO_Q3D_IMPORTER
#define ASSIMP_BUILD_NO_B3D_IMPORTER
//#define ASSIMP_BUILD_NO_COLLADA_IMPORTER
#define ASSIMP_BUILD_NO_TERRAGEN_IMPORTER
#define ASSIMP_BUILD_NO_CSM_IMPORTER
#define ASSIMP_BUILD_NO_3D_IMPORTER
//#define ASSIMP_BUILD_NO_LWS_IMPORTER
#define ASSIMP_BUILD_NO_OGRE_IMPORTER
#define ASSIMP_BUILD_NO_MS3D_IMPORTER
#define ASSIMP_BUILD_NO_COB_IMPORTER
//#define ASSIMP_BUILD_NO_BLEND_IMPORTER
#define ASSIMP_BUILD_NO_Q3BSP_IMPORTER
#define ASSIMP_BUILD_NO_NDO_IMPORTER
#define ASSIMP_BUILD_NO_IFC_IMPORTER
#define ASSIMP_BUILD_NO_M3_IMPORTER
#define ASSIMP_BUILD_NO_XGL_IMPORTER
vinjn commented 11 years ago

http://ephenationopengl.blogspot.com/2012/06/doing-animations-in-opengl.html

image

vinjn commented 11 years ago

Assimp::Importer

An sample

#include <assimp/Importer.hpp>      // C++ importer interface
#include <assimp/scene.h>           // Output data structure
#include <assimp/postprocess.h>     // Post processing flags

bool DoTheImportThing( const std::string& pFile)
{
  // Create an instance of the Importer class
  Assimp::Importer importer;

  // And have it read the given file with some example postprocessing
  // Usually - if speed is not the most important aspect for you - you'll 
  // propably to request more postprocessing than we do in this example.
  const aiScene* scene = importer.ReadFile( pFile, 
    aiProcess_CalcTangentSpace       | 
    aiProcess_Triangulate            |
    aiProcess_JoinIdenticalVertices  |
    aiProcess_SortByPType);

  // If the import failed, report it
  if( !scene)
  {
    DoTheErrorLogging( importer.GetErrorString());
    return false;
  }

  // Now we can access the file's contents. 
  DoTheSceneProcessing( scene);

  // We're done. Everything will be cleaned up by the importer destructor
  return true;
}
    // -------------------------------------------------------------------
    /** Reads the given file and returns its contents if successful. 
     * 
     * If the call succeeds, the contents of the file are returned as a 
     * pointer to an aiScene object. The returned data is intended to be 
     * read-only, the importer object keeps ownership of the data and will
     * destroy it upon destruction. If the import fails, NULL is returned.
     * A human-readable error description can be retrieved by calling 
     * GetErrorString(). The previous scene will be deleted during this call.
     * @param pFile Path and filename to the file to be imported.
     * @param pFlags Optional post processing steps to be executed after 
     *   a successful import. Provide a bitwise combination of the 
     *   #aiPostProcessSteps flags. If you wish to inspect the imported
     *   scene first in order to fine-tune your post-processing setup,
     *   consider to use #ApplyPostProcessing().
     * @return A pointer to the imported data, NULL if the import failed.
     *   The pointer to the scene remains in possession of the Importer
     *   instance. Use GetOrphanedScene() to take ownership of it.
     *
     * @note Assimp is able to determine the file format of a file
     * automatically. 
     */
    const aiScene* ReadFile(
        const char* pFile, 
        unsigned int pFlags);
vinjn commented 11 years ago

aiPostProcessSteps

aiProcess_CalcTangentSpace: for normal mappping aiProcess_JoinIdenticalVertices: remove identical vertices aiProcess_MakeLeftHanded: left-handed system is (somewhat) default for d3d, while opengl (usually) uses right-handed system aiProcess_Triangulate: for meshes made of quads aiProcess_RemoveComponent: remove unimportant vertex attributes aiProcess_GenNormals/aiProcess_GenSmoothNormals: you can't use them both aiProcess_SplitLargeMeshes: break huge mesh to sub-meshes aiProcess_PreTransformVertices: remove the original scene graph by performing global transform on all the vertices aiProcess_LimitBoneWeights: for hardware skinning aiProcess_ValidateDataStructure:This makes sure that all indices are valid, all animations and bones are linked correctly, all material references are correct. aiProcess_ImproveCacheLocality: for better cache-hit aiProcess_RemoveRedundantMaterials: remove unnecessary materials aiProcess_FixInfacingNormals: aiProcess_SortByPType: splits meshes with more than one primitive type aiProcess_FindDegenerates: converts degenerate primitives to lines or points aiProcess_FindInvalidData: aiProcess_GenUVCoords: aiProcess_TransformUVCoords: aiProcess_FindInstances: find duplicate meshes aiProcess_OptimizeMeshes: aiProcess_OptimizeGraph: aiProcess_FlipUVs: aiProcess_FlipWindingOrder: CCW -> CW aiProcess_SplitByBoneCount: aiProcess_Debone:

// The output data matches Direct3D's conventions: left-handed geometry, upper-left
// origin for UV coordinates and finally clockwise face order, suitable for CCW culling.
#define aiProcess_ConvertToLeftHanded ( \
    aiProcess_MakeLeftHanded     | \
    aiProcess_FlipUVs            | \
    aiProcess_FlipWindingOrder   | \
    0 ) 

#define aiProcessPreset_TargetRealtime_Fast ( \
    aiProcess_CalcTangentSpace      |  \
    aiProcess_GenNormals            |  \
    aiProcess_JoinIdenticalVertices |  \
    aiProcess_Triangulate           |  \
    aiProcess_GenUVCoords           |  \
    aiProcess_SortByPType           |  \
    0 )

#define aiProcessPreset_TargetRealtime_Quality ( \
    aiProcess_CalcTangentSpace              |  \
    aiProcess_GenSmoothNormals              |  \
    aiProcess_JoinIdenticalVertices         |  \
    aiProcess_ImproveCacheLocality          |  \
    aiProcess_LimitBoneWeights              |  \
    aiProcess_RemoveRedundantMaterials      |  \
    aiProcess_SplitLargeMeshes              |  \
    aiProcess_Triangulate                   |  \
    aiProcess_GenUVCoords                   |  \
    aiProcess_SortByPType                   |  \
    aiProcess_FindDegenerates               |  \
    aiProcess_FindInvalidData               |  \
    0 )

#define aiProcessPreset_TargetRealtime_MaxQuality ( \
    aiProcessPreset_TargetRealtime_Quality   |  \
    aiProcess_FindInstances                  |  \
    aiProcess_ValidateDataStructure          |  \
    aiProcess_OptimizeMeshes                 |  \
    aiProcess_Debone                         |  \
    0 )