Merge branch 'master' into coverity_scan

This commit is contained in:
Kim Kulling
2016-09-12 12:42:11 +02:00
229 changed files with 86813 additions and 341 deletions

View File

@@ -365,7 +365,7 @@ void Discreet3DSExporter::WriteTexture(const aiMaterial& mat, aiTextureType type
aiTextureMapMode map_mode[2] = {
aiTextureMapMode_Wrap, aiTextureMapMode_Wrap
};
float blend = 1.0f;
ai_real blend = 1.0;
if (mat.GetTexture(type, 0, &path, NULL, NULL, &blend, NULL, map_mode) != AI_SUCCESS || !path.length) {
return;
}
@@ -560,6 +560,12 @@ void Discreet3DSExporter::WritePercentChunk(float f) {
writer.PutF4(f);
}
// ------------------------------------------------------------------------------------------------
void Discreet3DSExporter::WritePercentChunk(double f) {
ChunkWriter chunk(writer, Discreet3DS::CHUNK_PERCENTD);
writer.PutF8(f);
}
#endif // ASSIMP_BUILD_NO_3DS_EXPORTER
#endif // ASSIMP_BUILD_NO_EXPORT

View File

@@ -80,6 +80,7 @@ private:
void WriteString(const aiString& s);
void WriteColor(const aiColor3D& color);
void WritePercentChunk(float f);
void WritePercentChunk(double f);
private:

View File

@@ -129,6 +129,7 @@ public:
CHUNK_PERCENTW = 0x0030, // int2 percentage
CHUNK_PERCENTF = 0x0031, // float4 percentage
CHUNK_PERCENTD = 0x0032, // float8 percentage
// ********************************************************************
// Prj master chunk

View File

@@ -1270,6 +1270,11 @@ void Discreet3DSImporter::ParseTextureChunk(D3DS::Texture* pcOut)
break;
case Discreet3DS::CHUNK_PERCENTD:
// Manually parse the blend factor
pcOut->mTextureBlend = stream->GetF8();
break;
case Discreet3DS::CHUNK_PERCENTF:
// Manually parse the blend factor
pcOut->mTextureBlend = stream->GetF4();

View File

@@ -74,11 +74,10 @@ static int ioprintf( IOStream * io, const char *format, ... ) {
static const size_t Size = 4096;
char sz[ Size ];
size_t len( strlen( format ) );
::memset( sz, '\0', Size );
va_list va;
va_start( va, format );
int nSize = vsnprintf( sz, Size-1, format, va );
const unsigned int nSize = vsnprintf( sz, Size-1, format, va );
ai_assert( nSize < Size );
va_end( va );

View File

@@ -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;
}
};

View File

@@ -792,7 +792,7 @@ void BlenderImporter::ConvertMesh(const Scene& /*in*/, const Object* /*obj*/, co
ConversionData& conv_data, TempArray<std::vector,aiMesh>& temp
)
{
// TODO: Resolve various problems with BMesh triangluation before re-enabling.
// TODO: Resolve various problems with BMesh triangulation before re-enabling.
// See issues #400, #373, #318 #315 and #132.
#if defined(TODO_FIX_BMESH_CONVERSION)
BlenderBMeshConverter BMeshConverter( mesh );
@@ -854,7 +854,7 @@ void BlenderImporter::ConvertMesh(const Scene& /*in*/, const Object* /*obj*/, co
//out->mNumVertices = 0
out->mFaces = new aiFace[it.second]();
// all submeshes created from this mesh are named equally. this allows
// all sub-meshes created from this mesh are named equally. this allows
// curious users to recover the original adjacency.
out->mName = aiString(mesh->id.name+2);
// skip over the name prefix 'ME'
@@ -1306,5 +1306,4 @@ aiNode* BlenderImporter::ConvertNode(const Scene& in, const Object* obj, Convers
return node.dismiss();
}
#endif
#endif // ASSIMP_BUILD_NO_BLEND_IMPORTER

View File

@@ -275,9 +275,6 @@ void BlenderModifier_Mirror :: DoIt(aiNode& out, ConversionData& conv_data, co
orig_object.id.name,"`");
}
// ------------------------------------------------------------------------------------------------
bool BlenderModifier_Subdivision :: IsActive (const ModifierData& modin)
{
@@ -323,4 +320,4 @@ void BlenderModifier_Subdivision :: DoIt(aiNode& out, ConversionData& conv_data
orig_object.id.name,"`");
}
#endif
#endif // ASSIMP_BUILD_NO_BLEND_IMPORTER

View File

@@ -806,4 +806,4 @@ void DNA::RegisterConverters() {
}
#endif
#endif ASSIMP_BUILD_NO_BLEND_IMPORTER

View File

@@ -64,7 +64,7 @@ namespace Blender {
// * C++ style comments only
//
// * Structures may include the primitive types char, int, short,
// float, double. Signedness specifiers are not allowed on
// float, double. Signed specifiers are not allowed on
// integers. Enum types are allowed, but they must have been
// defined in this header.
//
@@ -85,9 +85,9 @@ namespace Blender {
// provided they are neither pointers nor arrays.
//
// * One of WARN, FAIL can be appended to the declaration (
// prior to the semiolon to specifiy the error handling policy if
// prior to the semicolon to specify the error handling policy if
// this field is missing in the input DNA). If none of those
// is specified the default policy is to subtitute a default
// is specified the default policy is to substitute a default
// value for the field.
//
@@ -102,16 +102,16 @@ struct Image;
#define AI_BLEND_MESH_MAX_VERTS 2000000000L
static const size_t MaxNameLen = 1024;
// -------------------------------------------------------------------------------
struct ID : ElemBase {
char name[1024] WARN;
char name[ MaxNameLen ] WARN;
short flag;
};
// -------------------------------------------------------------------------------
struct ListBase : ElemBase {
std::shared_ptr<ElemBase> first;
std::shared_ptr<ElemBase> last;
};
@@ -126,7 +126,6 @@ struct PackedFile : ElemBase {
// -------------------------------------------------------------------------------
struct GroupObject : ElemBase {
std::shared_ptr<GroupObject> prev,next FAIL;
std::shared_ptr<Object> ob;
};
@@ -142,7 +141,6 @@ struct Group : ElemBase {
// -------------------------------------------------------------------------------
struct World : ElemBase {
ID id FAIL;
};
// -------------------------------------------------------------------------------
@@ -217,7 +215,6 @@ struct TFace : ElemBase {
// -------------------------------------------------------------------------------
struct MTFace : ElemBase {
float uv[4][2] FAIL;
char flag;
short mode;
@@ -235,7 +232,6 @@ struct MDeformWeight : ElemBase {
// -------------------------------------------------------------------------------
struct MDeformVert : ElemBase {
vector<MDeformWeight> dw WARN;
int totweight;
};
@@ -264,7 +260,6 @@ struct Material : ElemBase {
float darkness;
float refrac;
float amb;
float ang;
float spectra;

View File

@@ -618,7 +618,6 @@ ADD_ASSIMP_IMPORTER( 3MF
D3MFOpcPackage.cpp
)
SET( Step_SRCS
StepExporter.h
StepExporter.cpp
@@ -661,7 +660,6 @@ SET( Clipper_SRCS
)
SOURCE_GROUP( Clipper FILES ${Clipper_SRCS})
SET( Poly2Tri_SRCS
../contrib/poly2tri/poly2tri/common/shapes.cc
../contrib/poly2tri/poly2tri/common/shapes.h

View File

@@ -66,35 +66,32 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef ASSIMP_BUILD_NO_3MF_IMPORTER
namespace Assimp {
namespace D3MF {
namespace XmlTag {
const std::string model = "model";
const std::string metadata = "metadata";
const std::string resources = "resources";
const std::string object = "object";
const std::string mesh = "mesh";
const std::string vertices = "vertices";
const std::string vertex = "vertex";
const std::string triangles = "triangles";
const std::string triangle = "triangle";
const std::string x = "x";
const std::string y = "y";
const std::string z = "z";
const std::string v1 = "v1";
const std::string v2 = "v2";
const std::string v3 = "v3";
const std::string id = "id";
const std::string name = "name";
const std::string type = "type";
const std::string build = "build";
const std::string item = "item";
const std::string objectid = "objectid";
const std::string transform = "transform";
static const std::string model = "model";
static const std::string metadata = "metadata";
static const std::string resources = "resources";
static const std::string object = "object";
static const std::string mesh = "mesh";
static const std::string vertices = "vertices";
static const std::string vertex = "vertex";
static const std::string triangles = "triangles";
static const std::string triangle = "triangle";
static const std::string x = "x";
static const std::string y = "y";
static const std::string z = "z";
static const std::string v1 = "v1";
static const std::string v2 = "v2";
static const std::string v3 = "v3";
static const std::string id = "id";
static const std::string name = "name";
static const std::string type = "type";
static const std::string build = "build";
static const std::string item = "item";
static const std::string objectid = "objectid";
static const std::string transform = "transform";
}
@@ -342,15 +339,12 @@ D3MFImporter::~D3MFImporter()
bool D3MFImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const
{
const std::string extension = GetExtension(pFile);
if(extension == "3mf")
{
if(extension == "3mf") {
return true;
}
else if(!extension.length() || checkSig)
{
if(!pIOHandler)
} else if ( !extension.length() || checkSig ) {
if (nullptr == pIOHandler ) {
return true;
}
}
return false;
@@ -368,8 +362,6 @@ const aiImporterDesc *D3MFImporter::GetInfo() const
void D3MFImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler)
{
D3MF::D3MFOpcPackage opcPackage(pIOHandler, pFile);
std::unique_ptr<CIrrXML_IOStreamReader> xmlStream(new CIrrXML_IOStreamReader(opcPackage.RootStream()));
@@ -377,12 +369,9 @@ void D3MFImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOS
D3MF::XmlSerializer xmlSerializer(xmlReader.get());
xmlSerializer.ImportXml(pScene);
}
}
} // Namespace Assimp
#endif // ASSIMP_BUILD_NO_3MF_IMPORTER

View File

@@ -61,26 +61,21 @@ namespace Assimp {
namespace D3MF {
namespace XmlTag {
const std::string CONTENT_TYPES_ARCHIVE = "[Content_Types].xml";
const std::string ROOT_RELATIONSHIPS_ARCHIVE = "_rels/.rels";
const std::string SCHEMA_CONTENTTYPES = "http://schemas.openxmlformats.org/package/2006/content-types";
const std::string SCHEMA_RELATIONSHIPS = "http://schemas.openxmlformats.org/package/2006/relationships";
const std::string RELS_RELATIONSHIP_CONTAINER = "Relationships";
const std::string RELS_RELATIONSHIP_NODE = "Relationship";
const std::string RELS_ATTRIB_TARGET = "Target";
const std::string RELS_ATTRIB_TYPE = "Type";
const std::string RELS_ATTRIB_ID = "Id";
const std::string PACKAGE_START_PART_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel";
const std::string PACKAGE_PRINT_TICKET_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/printticket";
const std::string PACKAGE_TEXTURE_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dtexture";
const std::string PACKAGE_CORE_PROPERTIES_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
const std::string PACKAGE_THUMBNAIL_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail";
static const std::string CONTENT_TYPES_ARCHIVE = "[Content_Types].xml";
static const std::string ROOT_RELATIONSHIPS_ARCHIVE = "_rels/.rels";
static const std::string SCHEMA_CONTENTTYPES = "http://schemas.openxmlformats.org/package/2006/content-types";
static const std::string SCHEMA_RELATIONSHIPS = "http://schemas.openxmlformats.org/package/2006/relationships";
static const std::string RELS_RELATIONSHIP_CONTAINER = "Relationships";
static const std::string RELS_RELATIONSHIP_NODE = "Relationship";
static const std::string RELS_ATTRIB_TARGET = "Target";
static const std::string RELS_ATTRIB_TYPE = "Type";
static const std::string RELS_ATTRIB_ID = "Id";
static const std::string PACKAGE_START_PART_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel";
static const std::string PACKAGE_PRINT_TICKET_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/printticket";
static const std::string PACKAGE_TEXTURE_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dtexture";
static const std::string PACKAGE_CORE_PROPERTIES_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
static const std::string PACKAGE_THUMBNAIL_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail";
}
class IOSystem2Unzip {
@@ -461,9 +456,8 @@ public:
ParseRootNode(xmlReader);
}
}
}
void ParseRootNode(XmlReader* xmlReader)
{
ParseAttributes(xmlReader);
@@ -476,13 +470,13 @@ public:
ParseChildNode(xmlReader);
}
}
}
void ParseAttributes(XmlReader*)
{
}
void ParseChildNode(XmlReader* xmlReader)
{
OpcPackageRelationshipPtr relPtr(new OpcPackageRelationship());
@@ -494,26 +488,22 @@ public:
m_relationShips.push_back(relPtr);
}
std::vector<OpcPackageRelationshipPtr> m_relationShips;
};
// ------------------------------------------------------------------------------------------------
D3MFOpcPackage::D3MFOpcPackage(IOSystem* pIOHandler, const std::string& rFile)
: m_RootStream(nullptr)
{
zipArchive.reset(new D3MF::D3MFZipArchive( pIOHandler, rFile ));
if(!zipArchive->isOpen())
if(!zipArchive->isOpen()) {
throw DeadlyImportError("Failed to open file " + rFile+ ".");
}
std::vector<std::string> fileList;
zipArchive->getFileList(fileList);
for(auto& file: fileList){
if(file == D3MF::XmlTag::ROOT_RELATIONSHIPS_ARCHIVE)
{
if(file == D3MF::XmlTag::ROOT_RELATIONSHIPS_ARCHIVE) {
//PkgRelationshipReader pkgRelReader(file, archive);
ai_assert(zipArchive->Exists(file.c_str()));

View File

@@ -321,7 +321,7 @@ aiReturn Exporter :: Export( const aiScene* pScene, const char* pFormatId, const
// Always create a full copy of the scene. We might optimize this one day,
// but for now it is the most pragmatic way.
aiScene* scenecopy_tmp;
aiScene* scenecopy_tmp = NULL;
SceneCombiner::CopyScene(&scenecopy_tmp,pScene);
std::unique_ptr<aiScene> scenecopy(scenecopy_tmp);

View File

@@ -116,14 +116,14 @@ const aiImporterDesc* IRRMeshImporter::GetInfo () const
return &desc;
}
static void releaseMaterial( aiMaterial **mat ) {
static void releaseMaterial( aiMaterial *mat ) {
delete mat;
*mat = nullptr;
mat = nullptr;
}
static void releaseMesh( aiMesh **mesh ) {
static void releaseMesh( aiMesh *mesh ) {
delete mesh;
*mesh = nullptr;
mesh = nullptr;
}
// ------------------------------------------------------------------------------------------------
@@ -170,8 +170,8 @@ 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");
releaseMaterial( &curMat );
releaseMesh( &curMesh );
releaseMaterial( curMat );
releaseMesh( curMesh );
} else {
materials.push_back(curMat);
meshes.push_back(curMesh);
@@ -192,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");
releaseMaterial( &curMat );
releaseMaterial( curMat );
}
curMat = ParseMaterial(curMatFlags);
}
@@ -204,8 +204,8 @@ 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");
releaseMaterial( &curMat );
releaseMesh( &curMesh );
releaseMaterial( curMat );
releaseMesh( curMesh );
textMeaning = 0;
continue;
}
@@ -248,7 +248,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
vertexFormat = 2;
}
else if (ASSIMP_stricmp("standard", t)) {
releaseMaterial( &curMat );
releaseMaterial( curMat );
DefaultLogger::get()->warn("IRRMESH: Unknown vertex format");
}
else vertexFormat = 0;
@@ -256,7 +256,7 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
}
else if (!ASSIMP_stricmp(reader->getNodeName(),"indices")) {
if (curVertices.empty() && curMat) {
releaseMaterial( &curMat );
releaseMaterial( curMat );
throw DeadlyImportError("IRRMESH: indices must come after vertices");
}
@@ -272,10 +272,10 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
DefaultLogger::get()->warn("IRRMESH: Found mesh with zero indices");
// mesh - away
releaseMesh( &curMesh );
releaseMesh( curMesh );
// material - away
releaseMaterial( &curMat );
releaseMaterial( curMat );
textMeaning = 0;
continue;
@@ -487,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");
releaseMaterial( &curMat );
releaseMesh( &curMesh );
releaseMaterial( curMat );
releaseMesh( curMesh );
}
else {
materials.push_back(curMat);

View File

@@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <assimp/version.h>
#include <assimp/config.h>
// ------------------------------------------------------------------------------------------------
/* Uncomment this line to prevent Assimp from catching unknown exceptions.

View File

@@ -93,7 +93,7 @@ aiReturn aiGetMaterialFloatArray(const aiMaterial* pMat,
const char* pKey,
unsigned int type,
unsigned int index,
float* pOut,
ai_real* pOut,
unsigned int* pMax)
{
ai_assert (pOut != NULL);
@@ -105,7 +105,7 @@ aiReturn aiGetMaterialFloatArray(const aiMaterial* pMat,
return AI_FAILURE;
}
// data is given in floats, simply copy it
// data is given in floats, convert to ai_real
unsigned int iWrite = 0;
if( aiPTI_Float == prop->mType || aiPTI_Buffer == prop->mType) {
iWrite = prop->mDataLength / sizeof(float);
@@ -113,7 +113,20 @@ aiReturn aiGetMaterialFloatArray(const aiMaterial* pMat,
iWrite = std::min(*pMax,iWrite); ;
}
for (unsigned int a = 0; a < iWrite;++a) {
pOut[a] = static_cast<float> ( reinterpret_cast<float*>(prop->mData)[a] );
pOut[a] = static_cast<ai_real> ( reinterpret_cast<float*>(prop->mData)[a] );
}
if (pMax) {
*pMax = iWrite;
}
}
// data is given in doubles, convert to float
else if( aiPTI_Double == prop->mType) {
iWrite = prop->mDataLength / sizeof(double);
if (pMax) {
iWrite = std::min(*pMax,iWrite); ;
}
for (unsigned int a = 0; a < iWrite;++a) {
pOut[a] = static_cast<ai_real> ( reinterpret_cast<double*>(prop->mData)[a] );
}
if (pMax) {
*pMax = iWrite;
@@ -126,7 +139,7 @@ aiReturn aiGetMaterialFloatArray(const aiMaterial* pMat,
iWrite = std::min(*pMax,iWrite); ;
}
for (unsigned int a = 0; a < iWrite;++a) {
pOut[a] = static_cast<float> ( reinterpret_cast<int32_t*>(prop->mData)[a] );
pOut[a] = static_cast<ai_real> ( reinterpret_cast<int32_t*>(prop->mData)[a] );
}
if (pMax) {
*pMax = iWrite;
@@ -141,7 +154,7 @@ aiReturn aiGetMaterialFloatArray(const aiMaterial* pMat,
const char* cur = prop->mData+4;
ai_assert(prop->mDataLength>=5 && !prop->mData[prop->mDataLength-1]);
for (unsigned int a = 0; ;++a) {
cur = fast_atoreal_move<float>(cur,pOut[a]);
cur = fast_atoreal_move<ai_real>(cur,pOut[a]);
if(a==iWrite-1) {
break;
}
@@ -241,11 +254,11 @@ aiReturn aiGetMaterialColor(const aiMaterial* pMat,
aiColor4D* pOut)
{
unsigned int iMax = 4;
const aiReturn eRet = aiGetMaterialFloatArray(pMat,pKey,type,index,(float*)pOut,&iMax);
const aiReturn eRet = aiGetMaterialFloatArray(pMat,pKey,type,index,(ai_real*)pOut,&iMax);
// if no alpha channel is defined: set it to 1.0
if (3 == iMax) {
pOut->a = 1.0f;
pOut->a = 1.0;
}
return eRet;
@@ -260,7 +273,7 @@ aiReturn aiGetMaterialUVTransform(const aiMaterial* pMat,
aiUVTransform* pOut)
{
unsigned int iMax = 4;
return aiGetMaterialFloatArray(pMat,pKey,type,index,(float*)pOut,&iMax);
return aiGetMaterialFloatArray(pMat,pKey,type,index,(ai_real*)pOut,&iMax);
}
// ------------------------------------------------------------------------------------------------
@@ -326,7 +339,7 @@ aiReturn aiGetMaterialTexture(const C_STRUCT aiMaterial* mat,
C_STRUCT aiString* path,
aiTextureMapping* _mapping /*= NULL*/,
unsigned int* uvindex /*= NULL*/,
float* blend /*= NULL*/,
ai_real* blend /*= NULL*/,
aiTextureOp* op /*= NULL*/,
aiTextureMapMode* mapmode /*= NULL*/,
unsigned int* flags /*= NULL*/

View File

@@ -285,8 +285,6 @@ struct Model
ObjFile::Material *m_pDefaultMaterial;
//! Vector with all generated materials
std::vector<std::string> m_MaterialLib;
//! Vector with all generated group
std::vector<std::string> m_GroupLib;
//! Vector with all generated vertices
std::vector<aiVector3D> m_Vertices;
//! vector with all generated normals

View File

@@ -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;

View File

@@ -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;

View File

@@ -692,38 +692,36 @@ int ObjFileParser::getMaterialIndex( const std::string &strMaterialName )
// -------------------------------------------------------------------
// Getter for a group name.
void ObjFileParser::getGroupName()
{
std::string strGroupName;
void ObjFileParser::getGroupName() {
std::string groupName;
// here we skip 'g ' from line
m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
m_DataIt = getName<DataArrayIt>(m_DataIt, m_DataItEnd, strGroupName);
m_DataIt = getName<DataArrayIt>(m_DataIt, m_DataItEnd, groupName);
if( isEndOfBuffer( m_DataIt, m_DataItEnd ) ) {
return;
}
// Change active group, if necessary
if ( m_pModel->m_strActiveGroup != strGroupName )
{
if ( m_pModel->m_strActiveGroup != groupName ) {
// Search for already existing entry
ObjFile::Model::ConstGroupMapIt it = m_pModel->m_Groups.find(strGroupName);
ObjFile::Model::ConstGroupMapIt it = m_pModel->m_Groups.find(groupName);
// We are mapping groups into the object structure
createObject( strGroupName );
createObject( groupName );
// New group name, creating a new entry
if (it == m_pModel->m_Groups.end())
{
std::vector<unsigned int> *pFaceIDArray = new std::vector<unsigned int>;
m_pModel->m_Groups[ strGroupName ] = pFaceIDArray;
m_pModel->m_Groups[ groupName ] = pFaceIDArray;
m_pModel->m_pGroupFaceIDs = (pFaceIDArray);
}
else
{
m_pModel->m_pGroupFaceIDs = (*it).second;
}
m_pModel->m_strActiveGroup = strGroupName;
m_pModel->m_strActiveGroup = groupName;
}
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
}

View File

@@ -942,7 +942,7 @@ void SceneCombiner::MergeMaterials(aiMaterial** dest,
// ------------------------------------------------------------------------------------------------
template <typename Type>
inline void CopyPtrArray (Type**& dest, const Type* const * src, unsigned int num)
inline void CopyPtrArray (Type**& dest, const Type* const * src, ai_uint num)
{
if (!num)
{
@@ -950,14 +950,14 @@ inline void CopyPtrArray (Type**& dest, const Type* const * src, unsigned int nu
return;
}
dest = new Type*[num];
for (unsigned int i = 0; i < num;++i) {
for (ai_uint i = 0; i < num;++i) {
SceneCombiner::Copy(&dest[i],src[i]);
}
}
// ------------------------------------------------------------------------------------------------
template <typename Type>
inline void GetArrayCopy (Type*& dest, unsigned int num )
inline void GetArrayCopy (Type*& dest, ai_uint num )
{
if (!dest)return;
Type* old = dest;

View File

@@ -719,7 +719,7 @@ void ValidateDSProcess::Validate( const aiMaterial* pMaterial)
}
// make some more specific tests
float fTemp;
ai_real fTemp;
int iShading;
if (AI_SUCCESS == aiGetMaterialInteger( pMaterial,AI_MATKEY_SHADING_MODEL,&iShading)) {
switch ((aiShadingMode)iShading)
@@ -741,7 +741,7 @@ void ValidateDSProcess::Validate( const aiMaterial* pMaterial)
};
}
if (AI_SUCCESS == aiGetMaterialFloat( pMaterial,AI_MATKEY_OPACITY,&fTemp) && (!fTemp || fTemp > 1.01f)) {
if (AI_SUCCESS == aiGetMaterialFloat( pMaterial,AI_MATKEY_OPACITY,&fTemp) && (!fTemp || fTemp > 1.01)) {
ReportWarning("Invalid opacity value (must be 0 < opacity < 1.0)");
}

View File

@@ -49,6 +49,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "StringComparison.h"
#include "ByteSwapper.h"
#include "SplitLargeMeshes.h"
#include "SceneCombiner.h"
#include <assimp/version.h>
#include <assimp/IOSystem.hpp>
#include <assimp/Exporter.hpp>
@@ -70,8 +73,20 @@ namespace Assimp {
// Worker function for exporting a scene to GLTF. Prototyped and registered in Exporter.cpp
void ExportSceneGLTF(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties)
{
aiScene* sceneCopy_tmp;
SceneCombiner::CopyScene(&sceneCopy_tmp, pScene);
std::unique_ptr<aiScene> sceneCopy(sceneCopy_tmp);
SplitLargeMeshesProcess_Triangle tri_splitter;
tri_splitter.SetLimit(0xffff);
tri_splitter.Execute(sceneCopy.get());
SplitLargeMeshesProcess_Vertex vert_splitter;
vert_splitter.SetLimit(0xffff);
vert_splitter.Execute(sceneCopy.get());
// invoke the exporter
glTFExporter exporter(pFile, pIOSystem, pScene, pProperties, false);
glTFExporter exporter(pFile, pIOSystem, sceneCopy.get(), pProperties, false);
}
// ------------------------------------------------------------------------------------------------