Merge branch 'master' of https://github.com/assimp/assimp
commit
ccf1b368c8
|
@ -123,7 +123,7 @@ namespace Blender {
|
|||
|
||||
struct ObjectCompare {
|
||||
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 {
|
||||
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
|
||||
std::list<MappingInfo>::iterator it = std::find (mappingStack.begin(),mappingStack.end(), info);
|
||||
|
|
|
@ -116,6 +116,16 @@ const aiImporterDesc* IRRMeshImporter::GetInfo () const
|
|||
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.
|
||||
void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
||||
|
@ -135,7 +145,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
|||
std::vector<aiMaterial*> materials;
|
||||
std::vector<aiMesh*> meshes;
|
||||
materials.reserve (5);
|
||||
meshes.reserve (5);
|
||||
meshes.reserve(5);
|
||||
|
||||
// temporary data - current mesh buffer
|
||||
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
|
||||
if ( !curMat || !curMesh) {
|
||||
DefaultLogger::get()->error("IRRMESH: A buffer must contain a mesh and a material");
|
||||
delete curMat;
|
||||
delete curMesh;
|
||||
}
|
||||
else {
|
||||
releaseMaterial( curMat );
|
||||
releaseMesh( curMesh );
|
||||
} else {
|
||||
materials.push_back(curMat);
|
||||
meshes.push_back(curMesh);
|
||||
}
|
||||
|
@ -183,7 +192,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
|||
if (!ASSIMP_stricmp(reader->getNodeName(),"material")) {
|
||||
if (curMat) {
|
||||
DefaultLogger::get()->warn("IRRMESH: Only one material description per buffer, please");
|
||||
delete curMat;curMat = NULL;
|
||||
releaseMaterial( curMat );
|
||||
}
|
||||
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
|
||||
DefaultLogger::get()->warn("IRRMESH: Found mesh with zero vertices");
|
||||
|
||||
delete curMat;curMat = NULL;
|
||||
|
||||
curMesh = NULL;
|
||||
releaseMaterial( curMat );
|
||||
releaseMesh( curMesh );
|
||||
textMeaning = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
curVertices.reserve (num);
|
||||
curNormals.reserve (num);
|
||||
curColors.reserve (num);
|
||||
curUVs.reserve (num);
|
||||
curVertices.reserve(num);
|
||||
curNormals.reserve(num);
|
||||
curColors.reserve(num);
|
||||
curUVs.reserve(num);
|
||||
|
||||
// Determine the file format
|
||||
const char* t = reader->getAttributeValueSafe("type");
|
||||
|
@ -240,7 +248,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
|||
vertexFormat = 2;
|
||||
}
|
||||
else if (ASSIMP_stricmp("standard", t)) {
|
||||
delete curMat;
|
||||
releaseMaterial( curMat );
|
||||
DefaultLogger::get()->warn("IRRMESH: Unknown vertex format");
|
||||
}
|
||||
else vertexFormat = 0;
|
||||
|
@ -248,7 +256,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
|||
}
|
||||
else if (!ASSIMP_stricmp(reader->getNodeName(),"indices")) {
|
||||
if (curVertices.empty() && curMat) {
|
||||
delete curMat;
|
||||
releaseMaterial( curMat );
|
||||
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");
|
||||
|
||||
// mesh - away
|
||||
delete curMesh; curMesh = NULL;
|
||||
releaseMesh( curMesh );
|
||||
|
||||
// material - away
|
||||
delete curMat;curMat = NULL;
|
||||
releaseMaterial( curMat );
|
||||
|
||||
textMeaning = 0;
|
||||
continue;
|
||||
|
@ -469,7 +477,6 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
|||
break;
|
||||
|
||||
default:
|
||||
|
||||
// GCC complains here ...
|
||||
break;
|
||||
|
||||
|
@ -480,8 +487,8 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
|
|||
if (curMat || curMesh) {
|
||||
if ( !curMat || !curMesh) {
|
||||
DefaultLogger::get()->error("IRRMESH: A buffer must contain a mesh and a material");
|
||||
delete curMat;
|
||||
delete curMesh;
|
||||
releaseMaterial( curMat );
|
||||
releaseMesh( curMesh );
|
||||
}
|
||||
else {
|
||||
materials.push_back(curMat);
|
||||
|
|
|
@ -387,8 +387,7 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
|
|||
const ObjFile::Object* pCurrentObject,
|
||||
unsigned int uiMeshIndex,
|
||||
aiMesh* pMesh,
|
||||
unsigned int numIndices)
|
||||
{
|
||||
unsigned int numIndices) {
|
||||
// Checking preconditions
|
||||
ai_assert( NULL != pCurrentObject );
|
||||
|
||||
|
@ -398,8 +397,9 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
|
|||
|
||||
// Get current mesh
|
||||
ObjFile::Mesh *pObjMesh = pModel->m_Meshes[ uiMeshIndex ];
|
||||
if ( NULL == pObjMesh || pObjMesh->m_uiNumIndices < 1)
|
||||
if ( NULL == pObjMesh || pObjMesh->m_uiNumIndices < 1 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Copy vertices of this mesh instance
|
||||
pMesh->mNumVertices = numIndices;
|
||||
|
@ -427,27 +427,25 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
|
|||
|
||||
// Copy vertices, normals and textures into aiMesh instance
|
||||
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
|
||||
ObjFile::Face *pSourceFace = pObjMesh->m_Faces[ index ];
|
||||
|
||||
// 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 );
|
||||
if ( vertex >= pModel->m_Vertices.size() )
|
||||
if ( vertex >= pModel->m_Vertices.size() ) {
|
||||
throw DeadlyImportError( "OBJ: vertex index out of range" );
|
||||
}
|
||||
|
||||
pMesh->mVertices[ newIndex ] = pModel->m_Vertices[ vertex ];
|
||||
|
||||
// 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 );
|
||||
if ( normal >= pModel->m_Normals.size() )
|
||||
throw DeadlyImportError("OBJ: vertex normal index out of range");
|
||||
|
||||
if ( normal >= pModel->m_Normals.size() ) {
|
||||
throw DeadlyImportError( "OBJ: vertex normal index out of range" );
|
||||
}
|
||||
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
|
||||
void ObjFileImporter::addTextureMappingModeProperty(aiMaterial* mat, aiTextureType type, int clampMode)
|
||||
{
|
||||
ai_assert( NULL != mat);
|
||||
mat->AddProperty<int>(&clampMode, 1, AI_MATKEY_MAPPINGMODE_U(type, 0));
|
||||
mat->AddProperty<int>(&clampMode, 1, AI_MATKEY_MAPPINGMODE_V(type, 0));
|
||||
void ObjFileImporter::addTextureMappingModeProperty( aiMaterial* mat, aiTextureType type, int clampMode) {
|
||||
if ( nullptr == mat ) {
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pScene )
|
||||
{
|
||||
ai_assert( NULL != pScene );
|
||||
if ( NULL == pScene )
|
||||
void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pScene ) {
|
||||
if ( NULL == pScene ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const unsigned int numMaterials = (unsigned int) pModel->m_MaterialLib.size();
|
||||
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
|
||||
#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 aiNode;
|
||||
|
||||
namespace Assimp
|
||||
{
|
||||
namespace Assimp {
|
||||
|
||||
namespace ObjFile
|
||||
{
|
||||
namespace ObjFile {
|
||||
struct Object;
|
||||
struct Model;
|
||||
}
|
||||
|
@ -62,8 +58,7 @@ struct Model;
|
|||
/// \class ObjFileImporter
|
||||
/// \brief Imports a waveform obj file
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
class ObjFileImporter : public BaseImporter
|
||||
{
|
||||
class ObjFileImporter : public BaseImporter {
|
||||
public:
|
||||
/// \brief Default constructor
|
||||
ObjFileImporter();
|
||||
|
@ -77,7 +72,6 @@ public:
|
|||
bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const;
|
||||
|
||||
private:
|
||||
|
||||
//! \brief Appends the supported extension.
|
||||
const aiImporterDesc* GetInfo () const;
|
||||
|
||||
|
|
|
@ -74,20 +74,22 @@ static const aiImporterDesc desc = {
|
|||
// ------------------------------------------------------------------------------------------------
|
||||
// Constructor to be privately used by Importer
|
||||
SMDImporter::SMDImporter()
|
||||
: configFrameID(),
|
||||
mBuffer(),
|
||||
pScene(),
|
||||
iFileSize(),
|
||||
iSmallestFrame(),
|
||||
dLengthOfAnim(),
|
||||
bHasUVs(),
|
||||
iLineNumber()
|
||||
{}
|
||||
: configFrameID(),
|
||||
mBuffer(),
|
||||
pScene( nullptr ),
|
||||
iFileSize( 0 ),
|
||||
iSmallestFrame( -1 ),
|
||||
dLengthOfAnim( 0.0 ),
|
||||
bHasUVs(false ),
|
||||
iLineNumber(-1) {
|
||||
// empty
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Destructor, private as well
|
||||
SMDImporter::~SMDImporter()
|
||||
{}
|
||||
SMDImporter::~SMDImporter() {
|
||||
// empty
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// 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
|
||||
this->pScene = pScene;
|
||||
|
||||
std::vector<char> buff(iFileSize+1);
|
||||
TextFileToBuffer(file.get(),buff);
|
||||
mBuffer = &buff[0];
|
||||
mBuffer.resize( iFileSize + 1 );
|
||||
TextFileToBuffer(file.get(), mBuffer );
|
||||
|
||||
iSmallestFrame = (1 << 31);
|
||||
bHasUVs = true;
|
||||
|
@ -694,7 +695,7 @@ void SMDImporter::CreateOutputMaterials()
|
|||
// Parse the file
|
||||
void SMDImporter::ParseFile()
|
||||
{
|
||||
const char* szCurrent = mBuffer;
|
||||
const char* szCurrent = &mBuffer[0];
|
||||
|
||||
// read line per line ...
|
||||
for ( ;; )
|
||||
|
|
|
@ -372,7 +372,7 @@ private:
|
|||
unsigned int configFrameID;
|
||||
|
||||
/** Buffer to hold the loaded file */
|
||||
const char* mBuffer;
|
||||
std::vector<char> mBuffer;
|
||||
|
||||
/** 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>Will transform uv-coordinates if possible.</td>
|
||||
</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>
|
||||
<td><tt>-fid</tt></td>
|
||||
<td><tt>--find-invalid-data</tt></td>
|
||||
<td>Will look for invalid data in the imported model structure.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><tt>-fixn</tt></td>
|
||||
<td><tt>--fix normals</tt></td>
|
||||
<td>Imported normal vector will be fixed.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><tt>-db</tt></td>
|
||||
<td><tt>--debone</tt></td>
|
||||
|
|
Loading…
Reference in New Issue