Merge branch 'master' of https://github.com/assimp/assimp
commit
ccf1b368c8
|
@ -123,7 +123,7 @@ namespace Blender {
|
||||||
|
|
||||||
struct ObjectCompare {
|
struct ObjectCompare {
|
||||||
bool operator() (const Object* left, const Object* right) const {
|
bool operator() (const Object* left, const Object* right) const {
|
||||||
return ::strncmp(left->id.name, right->id.name, strlen( left->id.name ) ) == -1;
|
return ::strncmp(left->id.name, right->id.name, strlen( left->id.name ) ) == 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ namespace Blender {
|
||||||
|
|
||||||
struct ObjectCompare {
|
struct ObjectCompare {
|
||||||
bool operator() (const Object* left, const Object* right) const {
|
bool operator() (const Object* left, const Object* right) const {
|
||||||
return ::strncmp( left->id.name, right->id.name, strlen( left->id.name ) ) == -1;
|
return ::strncmp( left->id.name, right->id.name, strlen( left->id.name ) ) == 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -437,7 +437,7 @@ void ComputeUVMappingProcess::Execute( aiScene* pScene)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int idx;
|
unsigned int idx( 99999999 );
|
||||||
|
|
||||||
// Check whether we have this mapping mode already
|
// Check whether we have this mapping mode already
|
||||||
std::list<MappingInfo>::iterator it = std::find (mappingStack.begin(),mappingStack.end(), info);
|
std::list<MappingInfo>::iterator it = std::find (mappingStack.begin(),mappingStack.end(), info);
|
||||||
|
|
|
@ -116,6 +116,16 @@ const aiImporterDesc* IRRMeshImporter::GetInfo () const
|
||||||
return &desc;
|
return &desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void releaseMaterial( aiMaterial *mat ) {
|
||||||
|
delete mat;
|
||||||
|
mat = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void releaseMesh( aiMesh *mesh ) {
|
||||||
|
delete mesh;
|
||||||
|
mesh = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Imports the given file into the given scene structure.
|
// Imports the given file into the given scene structure.
|
||||||
void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
|
@ -135,7 +145,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
std::vector<aiMaterial*> materials;
|
std::vector<aiMaterial*> materials;
|
||||||
std::vector<aiMesh*> meshes;
|
std::vector<aiMesh*> meshes;
|
||||||
materials.reserve (5);
|
materials.reserve (5);
|
||||||
meshes.reserve (5);
|
meshes.reserve(5);
|
||||||
|
|
||||||
// temporary data - current mesh buffer
|
// temporary data - current mesh buffer
|
||||||
aiMaterial* curMat = NULL;
|
aiMaterial* curMat = NULL;
|
||||||
|
@ -160,10 +170,9 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
// end of previous buffer. A material and a mesh should be there
|
// end of previous buffer. A material and a mesh should be there
|
||||||
if ( !curMat || !curMesh) {
|
if ( !curMat || !curMesh) {
|
||||||
DefaultLogger::get()->error("IRRMESH: A buffer must contain a mesh and a material");
|
DefaultLogger::get()->error("IRRMESH: A buffer must contain a mesh and a material");
|
||||||
delete curMat;
|
releaseMaterial( curMat );
|
||||||
delete curMesh;
|
releaseMesh( curMesh );
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
materials.push_back(curMat);
|
materials.push_back(curMat);
|
||||||
meshes.push_back(curMesh);
|
meshes.push_back(curMesh);
|
||||||
}
|
}
|
||||||
|
@ -183,7 +192,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
if (!ASSIMP_stricmp(reader->getNodeName(),"material")) {
|
if (!ASSIMP_stricmp(reader->getNodeName(),"material")) {
|
||||||
if (curMat) {
|
if (curMat) {
|
||||||
DefaultLogger::get()->warn("IRRMESH: Only one material description per buffer, please");
|
DefaultLogger::get()->warn("IRRMESH: Only one material description per buffer, please");
|
||||||
delete curMat;curMat = NULL;
|
releaseMaterial( curMat );
|
||||||
}
|
}
|
||||||
curMat = ParseMaterial(curMatFlags);
|
curMat = ParseMaterial(curMatFlags);
|
||||||
}
|
}
|
||||||
|
@ -195,17 +204,16 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
// This is possible ... remove the mesh from the list and skip further reading
|
// This is possible ... remove the mesh from the list and skip further reading
|
||||||
DefaultLogger::get()->warn("IRRMESH: Found mesh with zero vertices");
|
DefaultLogger::get()->warn("IRRMESH: Found mesh with zero vertices");
|
||||||
|
|
||||||
delete curMat;curMat = NULL;
|
releaseMaterial( curMat );
|
||||||
|
releaseMesh( curMesh );
|
||||||
curMesh = NULL;
|
|
||||||
textMeaning = 0;
|
textMeaning = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
curVertices.reserve (num);
|
curVertices.reserve(num);
|
||||||
curNormals.reserve (num);
|
curNormals.reserve(num);
|
||||||
curColors.reserve (num);
|
curColors.reserve(num);
|
||||||
curUVs.reserve (num);
|
curUVs.reserve(num);
|
||||||
|
|
||||||
// Determine the file format
|
// Determine the file format
|
||||||
const char* t = reader->getAttributeValueSafe("type");
|
const char* t = reader->getAttributeValueSafe("type");
|
||||||
|
@ -240,7 +248,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
vertexFormat = 2;
|
vertexFormat = 2;
|
||||||
}
|
}
|
||||||
else if (ASSIMP_stricmp("standard", t)) {
|
else if (ASSIMP_stricmp("standard", t)) {
|
||||||
delete curMat;
|
releaseMaterial( curMat );
|
||||||
DefaultLogger::get()->warn("IRRMESH: Unknown vertex format");
|
DefaultLogger::get()->warn("IRRMESH: Unknown vertex format");
|
||||||
}
|
}
|
||||||
else vertexFormat = 0;
|
else vertexFormat = 0;
|
||||||
|
@ -248,7 +256,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
}
|
}
|
||||||
else if (!ASSIMP_stricmp(reader->getNodeName(),"indices")) {
|
else if (!ASSIMP_stricmp(reader->getNodeName(),"indices")) {
|
||||||
if (curVertices.empty() && curMat) {
|
if (curVertices.empty() && curMat) {
|
||||||
delete curMat;
|
releaseMaterial( curMat );
|
||||||
throw DeadlyImportError("IRRMESH: indices must come after vertices");
|
throw DeadlyImportError("IRRMESH: indices must come after vertices");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,10 +272,10 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
DefaultLogger::get()->warn("IRRMESH: Found mesh with zero indices");
|
DefaultLogger::get()->warn("IRRMESH: Found mesh with zero indices");
|
||||||
|
|
||||||
// mesh - away
|
// mesh - away
|
||||||
delete curMesh; curMesh = NULL;
|
releaseMesh( curMesh );
|
||||||
|
|
||||||
// material - away
|
// material - away
|
||||||
delete curMat;curMat = NULL;
|
releaseMaterial( curMat );
|
||||||
|
|
||||||
textMeaning = 0;
|
textMeaning = 0;
|
||||||
continue;
|
continue;
|
||||||
|
@ -469,7 +477,6 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
// GCC complains here ...
|
// GCC complains here ...
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -480,8 +487,8 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||||
if (curMat || curMesh) {
|
if (curMat || curMesh) {
|
||||||
if ( !curMat || !curMesh) {
|
if ( !curMat || !curMesh) {
|
||||||
DefaultLogger::get()->error("IRRMESH: A buffer must contain a mesh and a material");
|
DefaultLogger::get()->error("IRRMESH: A buffer must contain a mesh and a material");
|
||||||
delete curMat;
|
releaseMaterial( curMat );
|
||||||
delete curMesh;
|
releaseMesh( curMesh );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
materials.push_back(curMat);
|
materials.push_back(curMat);
|
||||||
|
|
|
@ -387,8 +387,7 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
|
||||||
const ObjFile::Object* pCurrentObject,
|
const ObjFile::Object* pCurrentObject,
|
||||||
unsigned int uiMeshIndex,
|
unsigned int uiMeshIndex,
|
||||||
aiMesh* pMesh,
|
aiMesh* pMesh,
|
||||||
unsigned int numIndices)
|
unsigned int numIndices) {
|
||||||
{
|
|
||||||
// Checking preconditions
|
// Checking preconditions
|
||||||
ai_assert( NULL != pCurrentObject );
|
ai_assert( NULL != pCurrentObject );
|
||||||
|
|
||||||
|
@ -398,8 +397,9 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
|
||||||
|
|
||||||
// Get current mesh
|
// Get current mesh
|
||||||
ObjFile::Mesh *pObjMesh = pModel->m_Meshes[ uiMeshIndex ];
|
ObjFile::Mesh *pObjMesh = pModel->m_Meshes[ uiMeshIndex ];
|
||||||
if ( NULL == pObjMesh || pObjMesh->m_uiNumIndices < 1)
|
if ( NULL == pObjMesh || pObjMesh->m_uiNumIndices < 1 ) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Copy vertices of this mesh instance
|
// Copy vertices of this mesh instance
|
||||||
pMesh->mNumVertices = numIndices;
|
pMesh->mNumVertices = numIndices;
|
||||||
|
@ -427,27 +427,25 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
|
||||||
|
|
||||||
// Copy vertices, normals and textures into aiMesh instance
|
// Copy vertices, normals and textures into aiMesh instance
|
||||||
unsigned int newIndex = 0, outIndex = 0;
|
unsigned int newIndex = 0, outIndex = 0;
|
||||||
for ( size_t index=0; index < pObjMesh->m_Faces.size(); index++ )
|
for ( size_t index=0; index < pObjMesh->m_Faces.size(); index++ ) {
|
||||||
{
|
|
||||||
// Get source face
|
// Get source face
|
||||||
ObjFile::Face *pSourceFace = pObjMesh->m_Faces[ index ];
|
ObjFile::Face *pSourceFace = pObjMesh->m_Faces[ index ];
|
||||||
|
|
||||||
// Copy all index arrays
|
// Copy all index arrays
|
||||||
for ( size_t vertexIndex = 0, outVertexIndex = 0; vertexIndex < pSourceFace->m_pVertices->size(); vertexIndex++ )
|
for ( size_t vertexIndex = 0, outVertexIndex = 0; vertexIndex < pSourceFace->m_pVertices->size(); vertexIndex++ ) {
|
||||||
{
|
|
||||||
const unsigned int vertex = pSourceFace->m_pVertices->at( vertexIndex );
|
const unsigned int vertex = pSourceFace->m_pVertices->at( vertexIndex );
|
||||||
if ( vertex >= pModel->m_Vertices.size() )
|
if ( vertex >= pModel->m_Vertices.size() ) {
|
||||||
throw DeadlyImportError( "OBJ: vertex index out of range" );
|
throw DeadlyImportError( "OBJ: vertex index out of range" );
|
||||||
|
}
|
||||||
|
|
||||||
pMesh->mVertices[ newIndex ] = pModel->m_Vertices[ vertex ];
|
pMesh->mVertices[ newIndex ] = pModel->m_Vertices[ vertex ];
|
||||||
|
|
||||||
// Copy all normals
|
// Copy all normals
|
||||||
if ( !pModel->m_Normals.empty() && vertexIndex < pSourceFace->m_pNormals->size())
|
if ( !pModel->m_Normals.empty() && vertexIndex < pSourceFace->m_pNormals->size()) {
|
||||||
{
|
|
||||||
const unsigned int normal = pSourceFace->m_pNormals->at( vertexIndex );
|
const unsigned int normal = pSourceFace->m_pNormals->at( vertexIndex );
|
||||||
if ( normal >= pModel->m_Normals.size() )
|
if ( normal >= pModel->m_Normals.size() ) {
|
||||||
throw DeadlyImportError("OBJ: vertex normal index out of range");
|
throw DeadlyImportError( "OBJ: vertex normal index out of range" );
|
||||||
|
}
|
||||||
pMesh->mNormals[ newIndex ] = pModel->m_Normals[ normal ];
|
pMesh->mNormals[ newIndex ] = pModel->m_Normals[ normal ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,20 +542,21 @@ void ObjFileImporter::countObjects(const std::vector<ObjFile::Object*> &rObjects
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Add clamp mode property to material if necessary
|
// Add clamp mode property to material if necessary
|
||||||
void ObjFileImporter::addTextureMappingModeProperty(aiMaterial* mat, aiTextureType type, int clampMode)
|
void ObjFileImporter::addTextureMappingModeProperty( aiMaterial* mat, aiTextureType type, int clampMode) {
|
||||||
{
|
if ( nullptr == mat ) {
|
||||||
ai_assert( NULL != mat);
|
return;
|
||||||
mat->AddProperty<int>(&clampMode, 1, AI_MATKEY_MAPPINGMODE_U(type, 0));
|
}
|
||||||
mat->AddProperty<int>(&clampMode, 1, AI_MATKEY_MAPPINGMODE_V(type, 0));
|
|
||||||
|
mat->AddProperty<int>( &clampMode, 1, AI_MATKEY_MAPPINGMODE_U( type, 0 ) );
|
||||||
|
mat->AddProperty<int>( &clampMode, 1, AI_MATKEY_MAPPINGMODE_V( type, 0 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Creates the material
|
// Creates the material
|
||||||
void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pScene )
|
void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pScene ) {
|
||||||
{
|
if ( NULL == pScene ) {
|
||||||
ai_assert( NULL != pScene );
|
|
||||||
if ( NULL == pScene )
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const unsigned int numMaterials = (unsigned int) pModel->m_MaterialLib.size();
|
const unsigned int numMaterials = (unsigned int) pModel->m_MaterialLib.size();
|
||||||
pScene->mNumMaterials = 0;
|
pScene->mNumMaterials = 0;
|
||||||
|
|
|
@ -37,8 +37,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef OBJ_FILE_IMPORTER_H_INC
|
#ifndef OBJ_FILE_IMPORTER_H_INC
|
||||||
#define OBJ_FILE_IMPORTER_H_INC
|
#define OBJ_FILE_IMPORTER_H_INC
|
||||||
|
|
||||||
|
@ -49,11 +47,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
struct aiMesh;
|
struct aiMesh;
|
||||||
struct aiNode;
|
struct aiNode;
|
||||||
|
|
||||||
namespace Assimp
|
namespace Assimp {
|
||||||
{
|
|
||||||
|
|
||||||
namespace ObjFile
|
namespace ObjFile {
|
||||||
{
|
|
||||||
struct Object;
|
struct Object;
|
||||||
struct Model;
|
struct Model;
|
||||||
}
|
}
|
||||||
|
@ -62,8 +58,7 @@ struct Model;
|
||||||
/// \class ObjFileImporter
|
/// \class ObjFileImporter
|
||||||
/// \brief Imports a waveform obj file
|
/// \brief Imports a waveform obj file
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
class ObjFileImporter : public BaseImporter
|
class ObjFileImporter : public BaseImporter {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
/// \brief Default constructor
|
/// \brief Default constructor
|
||||||
ObjFileImporter();
|
ObjFileImporter();
|
||||||
|
@ -77,7 +72,6 @@ public:
|
||||||
bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const;
|
bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//! \brief Appends the supported extension.
|
//! \brief Appends the supported extension.
|
||||||
const aiImporterDesc* GetInfo () const;
|
const aiImporterDesc* GetInfo () const;
|
||||||
|
|
||||||
|
|
|
@ -74,20 +74,22 @@ static const aiImporterDesc desc = {
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Constructor to be privately used by Importer
|
// Constructor to be privately used by Importer
|
||||||
SMDImporter::SMDImporter()
|
SMDImporter::SMDImporter()
|
||||||
: configFrameID(),
|
: configFrameID(),
|
||||||
mBuffer(),
|
mBuffer(),
|
||||||
pScene(),
|
pScene( nullptr ),
|
||||||
iFileSize(),
|
iFileSize( 0 ),
|
||||||
iSmallestFrame(),
|
iSmallestFrame( -1 ),
|
||||||
dLengthOfAnim(),
|
dLengthOfAnim( 0.0 ),
|
||||||
bHasUVs(),
|
bHasUVs(false ),
|
||||||
iLineNumber()
|
iLineNumber(-1) {
|
||||||
{}
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Destructor, private as well
|
// Destructor, private as well
|
||||||
SMDImporter::~SMDImporter()
|
SMDImporter::~SMDImporter() {
|
||||||
{}
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Returns whether the class can handle the format of the given file.
|
// Returns whether the class can handle the format of the given file.
|
||||||
|
@ -133,9 +135,8 @@ void SMDImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
|
||||||
// Allocate storage and copy the contents of the file to a memory buffer
|
// Allocate storage and copy the contents of the file to a memory buffer
|
||||||
this->pScene = pScene;
|
this->pScene = pScene;
|
||||||
|
|
||||||
std::vector<char> buff(iFileSize+1);
|
mBuffer.resize( iFileSize + 1 );
|
||||||
TextFileToBuffer(file.get(),buff);
|
TextFileToBuffer(file.get(), mBuffer );
|
||||||
mBuffer = &buff[0];
|
|
||||||
|
|
||||||
iSmallestFrame = (1 << 31);
|
iSmallestFrame = (1 << 31);
|
||||||
bHasUVs = true;
|
bHasUVs = true;
|
||||||
|
@ -694,7 +695,7 @@ void SMDImporter::CreateOutputMaterials()
|
||||||
// Parse the file
|
// Parse the file
|
||||||
void SMDImporter::ParseFile()
|
void SMDImporter::ParseFile()
|
||||||
{
|
{
|
||||||
const char* szCurrent = mBuffer;
|
const char* szCurrent = &mBuffer[0];
|
||||||
|
|
||||||
// read line per line ...
|
// read line per line ...
|
||||||
for ( ;; )
|
for ( ;; )
|
||||||
|
|
|
@ -372,7 +372,7 @@ private:
|
||||||
unsigned int configFrameID;
|
unsigned int configFrameID;
|
||||||
|
|
||||||
/** Buffer to hold the loaded file */
|
/** Buffer to hold the loaded file */
|
||||||
const char* mBuffer;
|
std::vector<char> mBuffer;
|
||||||
|
|
||||||
/** Output scene to be filled
|
/** Output scene to be filled
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -494,21 +494,11 @@ more information can be found in the <tt>aiPostProcess.h</tt> header.
|
||||||
<td><tt>--transform-uv-coords</tt></td>
|
<td><tt>--transform-uv-coords</tt></td>
|
||||||
<td>Will transform uv-coordinates if possible.</td>
|
<td>Will transform uv-coordinates if possible.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<td><tt>-guv</tt></td>
|
|
||||||
<td><tt>--gen-uvcoords</tt></td>
|
|
||||||
<td>Will generate uv-coordinates for textures if possible.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td><tt>-fid</tt></td>
|
<td><tt>-fid</tt></td>
|
||||||
<td><tt>--find-invalid-data</tt></td>
|
<td><tt>--find-invalid-data</tt></td>
|
||||||
<td>Will look for invalid data in the imported model structure.</td>
|
<td>Will look for invalid data in the imported model structure.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<td><tt>-fixn</tt></td>
|
|
||||||
<td><tt>--fix normals</tt></td>
|
|
||||||
<td>Imported normal vector will be fixed.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td><tt>-db</tt></td>
|
<td><tt>-db</tt></td>
|
||||||
<td><tt>--debone</tt></td>
|
<td><tt>--debone</tt></td>
|
||||||
|
|
Loading…
Reference in New Issue