Merge branch 'master' of github.com:assimp/assimp

pull/76/head
Alexander Gessler 2013-08-12 23:43:01 +02:00
commit 48b47464fd
16 changed files with 80 additions and 37 deletions

View File

@ -47,6 +47,10 @@ The library provides importers for a lot of file formats, including:
- Ogre XML - Ogre XML
- Q3D - Q3D
Additionally, the following formats are also supported, but not part of the core library as they depend on proprietary libraries.
- C4D (https://github.com/acgessler/assimp-cinema4d)
Exporters include: Exporters include:
- DAE (Collada) - DAE (Collada)

View File

@ -73,7 +73,7 @@ static const aiImporterDesc desc = {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer // Constructor to be privately used by Importer
ColladaLoader::ColladaLoader() ColladaLoader::ColladaLoader()
: noSkeletonMesh() : noSkeletonMesh(), ignoreUpDirection(false)
{} {}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -108,6 +108,7 @@ bool ColladaLoader::CanRead( const std::string& pFile, IOSystem* pIOHandler, boo
void ColladaLoader::SetupProperties(const Importer* pImp) void ColladaLoader::SetupProperties(const Importer* pImp)
{ {
noSkeletonMesh = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_NO_SKELETON_MESHES,0) != 0; noSkeletonMesh = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_NO_SKELETON_MESHES,0) != 0;
ignoreUpDirection = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION,0) != 0;
} }
@ -160,7 +161,7 @@ void ColladaLoader::InternReadFile( const std::string& pFile, aiScene* pScene, I
0, parser.mUnitSize, 0, 0, 0, parser.mUnitSize, 0, 0,
0, 0, parser.mUnitSize, 0, 0, 0, parser.mUnitSize, 0,
0, 0, 0, 1); 0, 0, 0, 1);
if( !ignoreUpDirection ) {
// Convert to Y_UP, if different orientation // Convert to Y_UP, if different orientation
if( parser.mUpDirection == ColladaParser::UP_X) if( parser.mUpDirection == ColladaParser::UP_X)
pScene->mRootNode->mTransformation *= aiMatrix4x4( pScene->mRootNode->mTransformation *= aiMatrix4x4(
@ -174,7 +175,7 @@ void ColladaLoader::InternReadFile( const std::string& pFile, aiScene* pScene, I
0, 0, 1, 0, 0, 0, 1, 0,
0, -1, 0, 0, 0, -1, 0, 0,
0, 0, 0, 1); 0, 0, 0, 1);
}
// store all meshes // store all meshes
StoreSceneMeshes( pScene); StoreSceneMeshes( pScene);

View File

@ -234,6 +234,7 @@ protected:
std::vector<aiAnimation*> mAnims; std::vector<aiAnimation*> mAnims;
bool noSkeletonMesh; bool noSkeletonMesh;
bool ignoreUpDirection;
}; };
} // end of namespace Assimp } // end of namespace Assimp

View File

@ -232,7 +232,7 @@ void ReadData(const char*& sbegin_out, const char*& send_out, const char* input,
// compute length based on type and check against the stored value // compute length based on type and check against the stored value
if(encoding == 0) { if(encoding == 0) {
uint32_t stride; uint32_t stride = 0;
switch(type) switch(type)
{ {
case 'f': case 'f':
@ -248,6 +248,7 @@ void ReadData(const char*& sbegin_out, const char*& send_out, const char* input,
default: default:
ai_assert(false); ai_assert(false);
}; };
ai_assert(stride > 0);
if(length * stride != comp_len) { if(length * stride != comp_len) {
TokenizeError("cannot ReadData, calculated data stride differs from what the file claims",input, cursor); TokenizeError("cannot ReadData, calculated data stride differs from what the file claims",input, cursor);
} }

View File

@ -548,6 +548,10 @@ private:
ai_assert(false); ai_assert(false);
} }
ai_assert((order[0] >= 0) && (order[0] <= 2));
ai_assert((order[1] >= 0) && (order[1] <= 2));
ai_assert((order[2] >= 0) && (order[2] <= 2));
if(!is_id[order[0]]) { if(!is_id[order[0]]) {
out = temp[order[0]]; out = temp[order[0]];
} }
@ -1844,7 +1848,7 @@ private:
}} }}
#endif #endif
const AnimationCurveNode* curve_node; const AnimationCurveNode* curve_node = NULL;
BOOST_FOREACH(const AnimationCurveNode* node, curves) { BOOST_FOREACH(const AnimationCurveNode* node, curves) {
ai_assert(node); ai_assert(node);

View File

@ -50,8 +50,8 @@ namespace Util {
/* DOM/Parse error reporting - does not return */ /* DOM/Parse error reporting - does not return */
void DOMError(const std::string& message, const Token& token); AI_WONT_RETURN void DOMError(const std::string& message, const Token& token) AI_WONT_RETURN_SUFFIX;
void DOMError(const std::string& message, const Element* element = NULL); AI_WONT_RETURN void DOMError(const std::string& message, const Element* element = NULL) AI_WONT_RETURN_SUFFIX;
// does return // does return
void DOMWarning(const std::string& message, const Token& token); void DOMWarning(const std::string& message, const Token& token);

View File

@ -512,7 +512,7 @@ void ReadBinaryDataArray(char type, uint32_t count, const char*& data, const cha
ai_assert(data + comp_len == end); ai_assert(data + comp_len == end);
// determine the length of the uncompressed data by looking at the type signature // determine the length of the uncompressed data by looking at the type signature
uint32_t stride; uint32_t stride = 0;
switch(type) switch(type)
{ {
case 'f': case 'f':

View File

@ -102,7 +102,7 @@ aiReturn aiGetMaterialFloatArray(const aiMaterial* pMat,
} }
// data is given in floats, simply copy it // data is given in floats, simply copy it
unsigned int iWrite; unsigned int iWrite = 0;
if( aiPTI_Float == prop->mType || aiPTI_Buffer == prop->mType) { if( aiPTI_Float == prop->mType || aiPTI_Buffer == prop->mType) {
iWrite = prop->mDataLength / sizeof(float); iWrite = prop->mDataLength / sizeof(float);
if (pMax) { if (pMax) {
@ -175,7 +175,7 @@ aiReturn aiGetMaterialIntegerArray(const aiMaterial* pMat,
} }
// data is given in ints, simply copy it // data is given in ints, simply copy it
unsigned int iWrite; unsigned int iWrite = 0;
if( aiPTI_Integer == prop->mType || aiPTI_Buffer == prop->mType) { if( aiPTI_Integer == prop->mType || aiPTI_Buffer == prop->mType) {
iWrite = prop->mDataLength / sizeof(int32_t); iWrite = prop->mDataLength / sizeof(int32_t);
if (pMax) { if (pMax) {

View File

@ -47,6 +47,7 @@ corresponding preprocessor flag to selectively disable steps.
*/ */
#include "AssimpPCH.h" #include "AssimpPCH.h"
#include "ProcessHelper.h"
#ifndef ASSIMP_BUILD_NO_CALCTANGENTS_PROCESS #ifndef ASSIMP_BUILD_NO_CALCTANGENTS_PROCESS
# include "CalcTangentsProcess.h" # include "CalcTangentsProcess.h"
@ -215,7 +216,7 @@ void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out)
#if (!defined ASSIMP_BUILD_NO_FLIPWINDINGORDER_PROCESS) #if (!defined ASSIMP_BUILD_NO_FLIPWINDINGORDER_PROCESS)
out.push_back( new FlipWindingOrderProcess()); out.push_back( new FlipWindingOrderProcess());
#endif #endif
#if (!defined ASSIMP_BUILD_DEBONE_PROCESS) #if (!defined ASSIMP_BUILD_NO_DEBONE_PROCESS)
out.push_back( new DeboneProcess()); out.push_back( new DeboneProcess());
#endif #endif
#if (!defined ASSIMP_BUILD_NO_LIMITBONEWEIGHTS_PROCESS) #if (!defined ASSIMP_BUILD_NO_LIMITBONEWEIGHTS_PROCESS)

View File

@ -193,7 +193,7 @@ public:
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/** Increase the file pointer (relative seeking) */ /** Increase the file pointer (relative seeking) */
void IncPtr(int plus) { void IncPtr(size_t plus) {
current += plus; current += plus;
if (current > limit) { if (current > limit) {
throw DeadlyImportError("End of file or read limit was reached"); throw DeadlyImportError("End of file or read limit was reached");

View File

@ -82,7 +82,7 @@ protected:
/** Report a validation error. This will throw an exception, /** Report a validation error. This will throw an exception,
* control won't return. * control won't return.
* @param msg Format string for sprintf().*/ * @param msg Format string for sprintf().*/
AI_WONT_RETURN void ReportError(const char* msg,...); AI_WONT_RETURN void ReportError(const char* msg,...) AI_WONT_RETURN_SUFFIX;
// ------------------------------------------------------------------- // -------------------------------------------------------------------

View File

@ -16,6 +16,7 @@
#define __FAST_A_TO_F_H_INCLUDED__ #define __FAST_A_TO_F_H_INCLUDED__
#include <math.h> #include <math.h>
#include <limits.h>
namespace Assimp namespace Assimp
{ {

View File

@ -841,4 +841,6 @@ enum aiComponent
*/ */
#define AI_CONFIG_IMPORT_IFC_CUSTOM_TRIANGULATION "IMPORT_IFC_CUSTOM_TRIANGULATION" #define AI_CONFIG_IMPORT_IFC_CUSTOM_TRIANGULATION "IMPORT_IFC_CUSTOM_TRIANGULATION"
#define AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION "IMPORT_COLLADA_IGNORE_UP_DIRECTION"
#endif // !! AI_CONFIG_H_INC #endif // !! AI_CONFIG_H_INC

View File

@ -162,6 +162,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# define AI_FORCE_INLINE inline # define AI_FORCE_INLINE inline
#endif // (defined _MSC_VER) #endif // (defined _MSC_VER)
#ifdef __clang__
# define AI_WONT_RETURN_SUFFIX __attribute__((analyzer_noreturn))
#else
# define AI_WONT_RETURN_SUFFIX
#endif // (defined __clang__)
#ifdef __cplusplus #ifdef __cplusplus
/* No explicit 'struct' and 'enum' tags for C++, this keeps showing up /* No explicit 'struct' and 'enum' tags for C++, this keeps showing up
* in doxydocs. * in doxydocs.

View File

@ -313,7 +313,7 @@ def _finalize_mesh(mesh, target):
data = numpy.array([make_tuple(getattr(mesh, name)[i]) for i in range(nb_vertices)], dtype=numpy.float32) data = numpy.array([make_tuple(getattr(mesh, name)[i]) for i in range(nb_vertices)], dtype=numpy.float32)
setattr(target, name[1:].lower(), data) setattr(target, name[1:].lower(), data)
else: else:
setattr(target, name[1:].lower(), []) setattr(target, name[1:].lower(), numpy.array([], dtype="float32"))
def fillarray(name): def fillarray(name):
mAttr = getattr(mesh, name) mAttr = getattr(mesh, name)
@ -336,6 +336,27 @@ def _finalize_mesh(mesh, target):
faces = numpy.array([f.indices for f in target.faces], dtype=numpy.int32) faces = numpy.array([f.indices for f in target.faces], dtype=numpy.int32)
setattr(target, 'faces', faces) setattr(target, 'faces', faces)
class PropertyGetter(dict):
def __getitem__(self, key):
semantic = 0
if isinstance(key, tuple):
key, semantic = key
return dict.__getitem__(self, (key, semantic))
def keys(self):
for k in dict.keys(self):
yield k[0]
def __iter__(self):
return self.keys()
def items(self):
for k, v in dict.items(self):
yield k[0], v
def _get_properties(properties, length): def _get_properties(properties, length):
""" """
Convenience Function to get the material properties as a dict Convenience Function to get the material properties as a dict
@ -346,7 +367,7 @@ def _get_properties(properties, length):
for p in [properties[i] for i in range(length)]: for p in [properties[i] for i in range(length)]:
#the name #the name
p = p.contents p = p.contents
key = str(p.mKey.data.decode("utf-8")).split('.')[1] key = (str(p.mKey.data.decode("utf-8")).split('.')[1], p.mSemantic)
#the data #the data
from ctypes import POINTER, cast, c_int, c_float, sizeof from ctypes import POINTER, cast, c_int, c_float, sizeof
@ -366,7 +387,7 @@ def _get_properties(properties, length):
result[key] = value result[key] = value
return result return PropertyGetter(result)
def decompose_matrix(matrix): def decompose_matrix(matrix):
if not isinstance(matrix, structs.Matrix4x4): if not isinstance(matrix, structs.Matrix4x4):

View File

@ -10,6 +10,7 @@ import logging
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
import pyassimp import pyassimp
import pyassimp.postprocess
def recur_node(node,level = 0): def recur_node(node,level = 0):
print(" " + "\t" * level + "- " + str(node)) print(" " + "\t" * level + "- " + str(node))
@ -19,7 +20,7 @@ def recur_node(node,level = 0):
def main(filename=None): def main(filename=None):
scene = pyassimp.load(filename) scene = pyassimp.load(filename, pyassimp.postprocess.aiProcess_Triangulate)
#the model we load #the model we load
print("MODEL:" + filename) print("MODEL:" + filename)