FIX: AseLoader is no stateless and can thus be called repeatedly.

Shut up gcc in LWOMaterial.cpp by adding an assertion, not all enumeration values handled.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@625 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
aramis_acg 2010-03-23 18:22:45 +00:00
parent c58dcee5b9
commit 63d6ca8669
3 changed files with 40 additions and 30 deletions

View File

@ -194,8 +194,9 @@ void ASEImporter::InternReadFile( const std::string& pFile,
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// Copy all scene graph nodes - lights, cameras, dummies and meshes // Copy all scene graph nodes - lights, cameras, dummies and meshes
// into one large array. FIXME: do this during parsing ... // into one huge list.
//------------------------------------------------------------------ //------------------------------------------------------------------
std::vector<BaseNode*> nodes;
nodes.reserve(mParser->m_vMeshes.size() +mParser->m_vLights.size() nodes.reserve(mParser->m_vMeshes.size() +mParser->m_vLights.size()
+ mParser->m_vCameras.size() + mParser->m_vDummies.size()); + mParser->m_vCameras.size() + mParser->m_vDummies.size());
@ -213,10 +214,10 @@ void ASEImporter::InternReadFile( const std::string& pFile,
end = mParser->m_vDummies.end();it != end; ++it)nodes.push_back(&(*it)); end = mParser->m_vDummies.end();it != end; ++it)nodes.push_back(&(*it));
// build the final node graph // build the final node graph
BuildNodes(); BuildNodes(nodes);
// build output animations // build output animations
BuildAnimations(); BuildAnimations(nodes);
// build output cameras // build output cameras
BuildCameras(); BuildCameras();
@ -261,10 +262,10 @@ void ASEImporter::GenerateDefaultMaterial()
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void ASEImporter::BuildAnimations() void ASEImporter::BuildAnimations(const std::vector<BaseNode*>& nodes)
{ {
// check whether we have at least one mesh which has animations // check whether we have at least one mesh which has animations
std::vector<ASE::BaseNode*>::iterator i = nodes.begin(); std::vector<ASE::BaseNode*>::const_iterator i = nodes.begin();
unsigned int iNum = 0; unsigned int iNum = 0;
for (;i != nodes.end();++i) { for (;i != nodes.end();++i) {
@ -331,13 +332,13 @@ void ASEImporter::BuildAnimations()
// Allocate the key array and fill it // Allocate the key array and fill it
nd->mNumPositionKeys = (unsigned int) me->mTargetAnim.akeyPositions.size(); nd->mNumPositionKeys = (unsigned int) me->mTargetAnim.akeyPositions.size();
nd->mPositionKeys = new aiVectorKey[nd->mNumPositionKeys]; nd->mPositionKeys = new aiVectorKey[nd->mNumPositionKeys];
::memcpy(nd->mPositionKeys,&me->mTargetAnim.akeyPositions[0], ::memcpy(nd->mPositionKeys,&me->mTargetAnim.akeyPositions[0],
nd->mNumPositionKeys * sizeof(aiVectorKey)); nd->mNumPositionKeys * sizeof(aiVectorKey));
} }
if (me->mAnim.akeyPositions.size() > 1 || me->mAnim.akeyRotations.size() > 1 || me->mAnim.akeyScaling.size() > 1) { if (me->mAnim.akeyPositions.size() > 1 || me->mAnim.akeyRotations.size() > 1 || me->mAnim.akeyScaling.size() > 1) {
// Begin a new node animation channel for this node // Begin a new node animation channel for this node
aiNodeAnim* nd = pcAnim->mChannels[iNum++] = new aiNodeAnim(); aiNodeAnim* nd = pcAnim->mChannels[iNum++] = new aiNodeAnim();
nd->mNodeName.Set(me->mName); nd->mNodeName.Set(me->mName);
@ -347,7 +348,7 @@ void ASEImporter::BuildAnimations()
{ {
// Allocate the key array and fill it // Allocate the key array and fill it
nd->mNumPositionKeys = (unsigned int) me->mAnim.akeyPositions.size(); nd->mNumPositionKeys = (unsigned int) me->mAnim.akeyPositions.size();
nd->mPositionKeys = new aiVectorKey[nd->mNumPositionKeys]; nd->mPositionKeys = new aiVectorKey[nd->mNumPositionKeys];
::memcpy(nd->mPositionKeys,&me->mAnim.akeyPositions[0], ::memcpy(nd->mPositionKeys,&me->mAnim.akeyPositions[0],
nd->mNumPositionKeys * sizeof(aiVectorKey)); nd->mNumPositionKeys * sizeof(aiVectorKey));
@ -356,7 +357,7 @@ void ASEImporter::BuildAnimations()
if (me->mAnim.akeyRotations.size() > 1 ) { if (me->mAnim.akeyRotations.size() > 1 ) {
// Allocate the key array and fill it // Allocate the key array and fill it
nd->mNumRotationKeys = (unsigned int) me->mAnim.akeyRotations.size(); nd->mNumRotationKeys = (unsigned int) me->mAnim.akeyRotations.size();
nd->mRotationKeys = new aiQuatKey[nd->mNumRotationKeys]; nd->mRotationKeys = new aiQuatKey[nd->mNumRotationKeys];
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Rotation keys are offsets to the previous keys. // Rotation keys are offsets to the previous keys.
@ -385,7 +386,7 @@ void ASEImporter::BuildAnimations()
if (me->mAnim.akeyScaling.size() > 1 ) { if (me->mAnim.akeyScaling.size() > 1 ) {
// Allocate the key array and fill it // Allocate the key array and fill it
nd->mNumScalingKeys = (unsigned int) me->mAnim.akeyScaling.size(); nd->mNumScalingKeys = (unsigned int) me->mAnim.akeyScaling.size();
nd->mScalingKeys = new aiVectorKey[nd->mNumScalingKeys]; nd->mScalingKeys = new aiVectorKey[nd->mNumScalingKeys];
::memcpy(nd->mScalingKeys,&me->mAnim.akeyScaling[0], ::memcpy(nd->mScalingKeys,&me->mAnim.akeyScaling[0],
nd->mNumScalingKeys * sizeof(aiVectorKey)); nd->mNumScalingKeys * sizeof(aiVectorKey));
@ -404,7 +405,7 @@ void ASEImporter::BuildCameras()
pcScene->mCameras = new aiCamera*[pcScene->mNumCameras]; pcScene->mCameras = new aiCamera*[pcScene->mNumCameras];
for (unsigned int i = 0; i < pcScene->mNumCameras;++i) { for (unsigned int i = 0; i < pcScene->mNumCameras;++i) {
aiCamera* out = pcScene->mCameras[i] = new aiCamera(); aiCamera* out = pcScene->mCameras[i] = new aiCamera();
ASE::Camera& in = mParser->m_vCameras[i]; ASE::Camera& in = mParser->m_vCameras[i];
// copy members // copy members
@ -425,9 +426,8 @@ void ASEImporter::BuildLights()
pcScene->mNumLights = (unsigned int)mParser->m_vLights.size(); pcScene->mNumLights = (unsigned int)mParser->m_vLights.size();
pcScene->mLights = new aiLight*[pcScene->mNumLights]; pcScene->mLights = new aiLight*[pcScene->mNumLights];
for (unsigned int i = 0; i < pcScene->mNumLights;++i) for (unsigned int i = 0; i < pcScene->mNumLights;++i) {
{ aiLight* out = pcScene->mLights[i] = new aiLight();
aiLight* out = pcScene->mLights[i] = new aiLight();
ASE::Light& in = mParser->m_vLights[i]; ASE::Light& in = mParser->m_vLights[i];
// The direction is encoded in the transformation matrix of the node. // The direction is encoded in the transformation matrix of the node.
@ -459,7 +459,7 @@ void ASEImporter::BuildLights()
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void ASEImporter::AddNodes(std::vector<BaseNode*>& nodes, void ASEImporter::AddNodes(const std::vector<BaseNode*>& nodes,
aiNode* pcParent,const char* szName) aiNode* pcParent,const char* szName)
{ {
aiMatrix4x4 m; aiMatrix4x4 m;
@ -521,7 +521,7 @@ void ASEImporter::AddMeshes(const ASE::BaseNode* snode,aiNode* node)
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Add child nodes to a given parent node // Add child nodes to a given parent node
void ASEImporter::AddNodes (std::vector<BaseNode*>& nodes, void ASEImporter::AddNodes (const std::vector<BaseNode*>& nodes,
aiNode* pcParent, const char* szName, aiNode* pcParent, const char* szName,
const aiMatrix4x4& mat) const aiMatrix4x4& mat)
{ {
@ -617,7 +617,7 @@ void ASEImporter::AddNodes (std::vector<BaseNode*>& nodes,
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Build the output node graph // Build the output node graph
void ASEImporter::BuildNodes() { void ASEImporter::BuildNodes(std::vector<BaseNode*>& nodes) {
ai_assert(NULL != pcScene); ai_assert(NULL != pcScene);
// allocate the one and only root node // allocate the one and only root node
@ -1294,7 +1294,7 @@ bool ASEImporter::GenerateNormals(ASE::Mesh& mesh) {
} }
} }
} }
// The array <EFBFBD>s reused // The array is reused.
ComputeNormalsWithSmoothingsGroups<ASE::Face>(mesh); ComputeNormalsWithSmoothingsGroups<ASE::Face>(mesh);
return false; return false;
} }

View File

@ -53,15 +53,11 @@ struct aiNode;
namespace Assimp { namespace Assimp {
class MaterialHelper; class MaterialHelper;
using namespace ASE;
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
/** Importer class for the 3DS ASE ASCII format /** Importer class for the 3DS ASE ASCII format.
* *
* fixme: consider code cleanup
*/ */
class ASEImporter : public BaseImporter class ASEImporter : public BaseImporter {
{
friend class Importer; friend class Importer;
protected: protected:
@ -88,6 +84,7 @@ protected:
*/ */
void GetExtensionList(std::set<std::string>& extensions); void GetExtensionList(std::set<std::string>& extensions);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Imports the given file into the given scene structure. /** Imports the given file into the given scene structure.
* See BaseImporter::InternReadFile() for details * See BaseImporter::InternReadFile() for details
@ -95,6 +92,7 @@ protected:
void InternReadFile( const std::string& pFile, aiScene* pScene, void InternReadFile( const std::string& pFile, aiScene* pScene,
IOSystem* pIOHandler); IOSystem* pIOHandler);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Called prior to ReadFile(). /** Called prior to ReadFile().
* The function is a request to the importer to update its configuration * The function is a request to the importer to update its configuration
@ -102,6 +100,9 @@ protected:
*/ */
void SetupProperties(const Importer* pImp); void SetupProperties(const Importer* pImp);
private:
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Generate normal vectors basing on smoothing groups /** Generate normal vectors basing on smoothing groups
* (in some cases the normal are already contained in the file) * (in some cases the normal are already contained in the file)
@ -110,6 +111,7 @@ protected:
*/ */
bool GenerateNormals(ASE::Mesh& mesh); bool GenerateNormals(ASE::Mesh& mesh);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Create valid vertex/normal/UV/color/face lists. /** Create valid vertex/normal/UV/color/face lists.
* All elements are unique, faces have only one set of indices * All elements are unique, faces have only one set of indices
@ -118,42 +120,50 @@ protected:
*/ */
void BuildUniqueRepresentation(ASE::Mesh& mesh); void BuildUniqueRepresentation(ASE::Mesh& mesh);
/** Create one-material-per-mesh meshes ;-) /** Create one-material-per-mesh meshes ;-)
* \param mesh Mesh to work with * \param mesh Mesh to work with
* \param Receives the list of all created meshes * \param Receives the list of all created meshes
*/ */
void ConvertMeshes(ASE::Mesh& mesh, std::vector<aiMesh*>& avOut); void ConvertMeshes(ASE::Mesh& mesh, std::vector<aiMesh*>& avOut);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Convert a material to a MaterialHelper object /** Convert a material to a MaterialHelper object
* \param mat Input material * \param mat Input material
*/ */
void ConvertMaterial(ASE::Material& mat); void ConvertMaterial(ASE::Material& mat);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Setup the final material indices for each mesh /** Setup the final material indices for each mesh
*/ */
void BuildMaterialIndices(); void BuildMaterialIndices();
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Build the node graph /** Build the node graph
*/ */
void BuildNodes(); void BuildNodes(std::vector<ASE::BaseNode*>& nodes);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Build output cameras /** Build output cameras
*/ */
void BuildCameras(); void BuildCameras();
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Build output lights /** Build output lights
*/ */
void BuildLights(); void BuildLights();
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Build output animations /** Build output animations
*/ */
void BuildAnimations(); void BuildAnimations(const std::vector<ASE::BaseNode*>& nodes);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Add sub nodes to a node /** Add sub nodes to a node
@ -161,10 +171,10 @@ protected:
* \param szName Name of the parent node * \param szName Name of the parent node
* \param matrix Current transform * \param matrix Current transform
*/ */
void AddNodes(std::vector<BaseNode*>& nodes, void AddNodes(const std::vector<ASE::BaseNode*>& nodes,
aiNode* pcParent,const char* szName); aiNode* pcParent,const char* szName);
void AddNodes(std::vector<BaseNode*>& nodes, void AddNodes(const std::vector<ASE::BaseNode*>& nodes,
aiNode* pcParent,const char* szName, aiNode* pcParent,const char* szName,
const aiMatrix4x4& matrix); const aiMatrix4x4& matrix);
@ -188,8 +198,6 @@ protected:
/** Scene to be filled */ /** Scene to be filled */
aiScene* pcScene; aiScene* pcScene;
std::vector<BaseNode*> nodes;
/** Config options: Recompute the normals in every case - WA /** Config options: Recompute the normals in every case - WA
for 3DS Max broken ASE normal export */ for 3DS Max broken ASE normal export */
bool configRecomputeNormals; bool configRecomputeNormals;

View File

@ -132,6 +132,8 @@ bool LWOImporter::HandleTextures(MaterialHelper* pcMat, const TextureList& in, a
mapping = aiTextureMapping_UV; mapping = aiTextureMapping_UV;
} }
break; break;
default:
ai_assert(false);
}; };
if (mapping != aiTextureMapping_UV) { if (mapping != aiTextureMapping_UV) {