Merge branch 'master' into opengex_support

pull/502/head
Kim Kulling 2015-01-31 11:09:20 +01:00
commit 063b2733fc
19 changed files with 174 additions and 85 deletions

View File

@ -84,7 +84,7 @@ SET( ASSIMP_INCLUDE_INSTALL_DIR "include" CACHE PATH
SET( ASSIMP_BIN_INSTALL_DIR "bin" CACHE PATH
"Path the tool executables are installed to." )
SET(ASSIMP_DEBUG_POSTFIX "d" CACHE STRING "Debug Postfitx for lib, samples and tools")
SET(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Debug Postfitx for lib, samples and tools")
# Allow the user to build a shared or static library
option ( BUILD_SHARED_LIBS "Build a shared version of the library" ON )

View File

@ -40,9 +40,7 @@ set( ASSIMP_LINK_FLAGS "" )
set( ASSIMP_LIBRARY_DIRS "${ASSIMP_ROOT_DIR}/@ASSIMP_LIB_INSTALL_DIR@")
set( ASSIMP_INCLUDE_DIRS "${ASSIMP_ROOT_DIR}/@ASSIMP_INCLUDE_INSTALL_DIR@")
set( ASSIMP_LIBRARIES assimp${ASSIMP_LIBRARY_SUFFIX})
if (CMAKE_BUILD_TYPE EQUAL "DEBUG")
set( ASSIMP_LIBRARIES ${ASSIMP_LIBRARIES}D)
endif (CMAKE_BUILD_TYPE EQUAL "DEBUG")
set( ASSIMP_LIBRARIES ${ASSIMP_LIBRARIES}@CMAKE_DEBUG_POSTFIX@)
# search for the boost version assimp was compiled with
#set(Boost_USE_MULTITHREAD ON)

View File

@ -729,8 +729,6 @@ SET( assimp_src
ADD_LIBRARY( assimp ${assimp_src} )
SET_PROPERTY(TARGET assimp PROPERTY DEBUG_POSTFIX ${ASSIMP_DEBUG_POSTFIX})
TARGET_LINK_LIBRARIES(assimp ${ZLIB_LIBRARIES})
if(ANDROID AND ASSIMP_ANDROID_JNIIOSYSTEM)
@ -739,10 +737,24 @@ if(ANDROID AND ASSIMP_ANDROID_JNIIOSYSTEM)
target_link_libraries(assimp android_jniiosystem)
endif(ANDROID AND ASSIMP_ANDROID_JNIIOSYSTEM)
if( MSVC )
# in order to prevent DLL hell, each of the DLLs have to be suffixed with the major version and msvc prefix
if( MSVC70 OR MSVC71 )
set(MSVC_PREFIX "vc70")
elseif( MSVC80 )
set(MSVC_PREFIX "vc80")
elseif( MSVC90 )
set(MSVC_PREFIX "vc90")
else()
set(MSVC_PREFIX "vc100")
endif()
set(LIBRARY_SUFFIX "${ASSIMP_LIBRARY_SUFFIX}-${MSVC_PREFIX}-mt" CACHE STRING "the suffix for the assimp windows library" FORCE)
endif()
SET_TARGET_PROPERTIES( assimp PROPERTIES
VERSION ${ASSIMP_VERSION}
SOVERSION ${ASSIMP_SOVERSION} # use full version
OUTPUT_NAME assimp${ASSIMP_LIBRARY_SUFFIX}
OUTPUT_NAME assimp${LIBRARY_SUFFIX}
)
if (APPLE)
@ -772,7 +784,7 @@ if (ASSIMP_ANDROID_JNIIOSYSTEM)
endif(ASSIMP_ANDROID_JNIIOSYSTEM)
if(MSVC AND ASSIMP_INSTALL_PDB)
install(FILES ${Assimp_BINARY_DIR}/code/Debug/assimp${ASSIMP_DEBUG_POSTFIX}.pdb
install(FILES ${Assimp_BINARY_DIR}/code/Debug/assimp${CMAKE_DEBUG_POSTFIX}.pdb
DESTINATION ${ASSIMP_LIB_INSTALL_DIR}
CONFIGURATIONS Debug
)

View File

@ -985,6 +985,47 @@ void ColladaLoader::CreateAnimation( aiScene* pScene, const ColladaParser& pPars
entry.mTransformId = srcChannel.mTarget.substr( slashPos+1);
}
std::string::size_type bracketPos = srcChannel.mTarget.find('(');
if (bracketPos != std::string::npos)
{
entry.mTransformId = srcChannel.mTarget.substr(slashPos + 1, bracketPos - slashPos - 1);
std::string subElement = srcChannel.mTarget.substr(bracketPos);
if (subElement == "(0)(0)")
entry.mSubElement = 0;
else if (subElement == "(1)(0)")
entry.mSubElement = 1;
else if (subElement == "(2)(0)")
entry.mSubElement = 2;
else if (subElement == "(3)(0)")
entry.mSubElement = 3;
else if (subElement == "(0)(1)")
entry.mSubElement = 4;
else if (subElement == "(1)(1)")
entry.mSubElement = 5;
else if (subElement == "(2)(1)")
entry.mSubElement = 6;
else if (subElement == "(3)(1)")
entry.mSubElement = 7;
else if (subElement == "(0)(2)")
entry.mSubElement = 8;
else if (subElement == "(1)(2)")
entry.mSubElement = 9;
else if (subElement == "(2)(2)")
entry.mSubElement = 10;
else if (subElement == "(3)(2)")
entry.mSubElement = 11;
else if (subElement == "(0)(3)")
entry.mSubElement = 12;
else if (subElement == "(1)(3)")
entry.mSubElement = 13;
else if (subElement == "(2)(3)")
entry.mSubElement = 14;
else if (subElement == "(3)(3)")
entry.mSubElement = 15;
}
// determine which transform step is affected by this channel
entry.mTransformIndex = SIZE_MAX;
for( size_t a = 0; a < srcNode->mTransforms.size(); ++a)

View File

@ -549,7 +549,9 @@ void ReadBinaryDataArray(char type, uint32_t count, const char*& data, const cha
zstream.data_type = Z_BINARY;
// http://hewgill.com/journal/entries/349-how-to-decompress-gzip-stream-with-zlib
inflateInit(&zstream);
if(Z_OK != inflateInit(&zstream)) {
ParseError("failure initializing zlib");
}
zstream.next_in = reinterpret_cast<Bytef*>( const_cast<char*>(data) );
zstream.avail_in = comp_len;

View File

@ -91,7 +91,7 @@ public:
a = std::fmod(a,static_cast<IfcFloat>( AI_MATH_TWO_PI ));
b = std::fmod(b,static_cast<IfcFloat>( AI_MATH_TWO_PI ));
const IfcFloat setting = static_cast<IfcFloat>( AI_MATH_PI * conv.settings.conicSamplingAngle / 180.0 );
return static_cast<size_t>( std::ceil(abs( b-a)) / setting);
return static_cast<size_t>( std::ceil(std::abs( b-a)) / setting);
}
// --------------------------------------------------
@ -276,7 +276,7 @@ public:
IfcFloat acc = 0;
BOOST_FOREACH(const CurveEntry& entry, curves) {
const ParamRange& range = entry.first->GetParametricRange();
const IfcFloat delta = abs(range.second-range.first);
const IfcFloat delta = std::abs(range.second-range.first);
if (u < acc+delta) {
return entry.first->Eval( entry.second ? (u-acc) + range.first : range.second-(u-acc));
}
@ -295,7 +295,7 @@ public:
IfcFloat acc = 0;
BOOST_FOREACH(const CurveEntry& entry, curves) {
const ParamRange& range = entry.first->GetParametricRange();
const IfcFloat delta = abs(range.second-range.first);
const IfcFloat delta = std::abs(range.second-range.first);
if (a <= acc+delta && b >= acc) {
const IfcFloat at = std::max(static_cast<IfcFloat>( 0. ),a-acc), bt = std::min(delta,b-acc);
cnt += entry.first->EstimateSampleCount( entry.second ? at + range.first : range.second - bt, entry.second ? bt + range.first : range.second - at );
@ -569,7 +569,7 @@ bool Curve :: InRange(IfcFloat u) const
IfcFloat Curve :: GetParametricRangeDelta() const
{
const ParamRange& range = GetParametricRange();
return abs(range.second - range.first);
return std::abs(range.second - range.first);
}
// ------------------------------------------------------------------------------------------------

View File

@ -375,21 +375,21 @@ void ProcessSweptDiskSolid(const IfcSweptDiskSolid solid, TempMesh& result, Conv
bool take_any = false;
for (unsigned int i = 0; i < 2; ++i, take_any = true) {
if ((last_dir == 0 || take_any) && abs(d.x) > 1e-6) {
if ((last_dir == 0 || take_any) && std::abs(d.x) > 1e-6) {
q.y = startvec.y;
q.z = startvec.z;
q.x = -(d.y * q.y + d.z * q.z) / d.x;
last_dir = 0;
break;
}
else if ((last_dir == 1 || take_any) && abs(d.y) > 1e-6) {
else if ((last_dir == 1 || take_any) && std::abs(d.y) > 1e-6) {
q.x = startvec.x;
q.z = startvec.z;
q.y = -(d.x * q.x + d.z * q.z) / d.y;
last_dir = 1;
break;
}
else if ((last_dir == 2 && abs(d.z) > 1e-6) || take_any) {
else if ((last_dir == 2 && std::abs(d.z) > 1e-6) || take_any) {
q.y = startvec.y;
q.x = startvec.x;
q.z = -(d.y * q.y + d.x * q.x) / d.z;

View File

@ -1244,7 +1244,7 @@ bool GenerateOpenings(std::vector<TempOpening>& openings,
const IfcVector3& face_nor = ((profile_verts[vi_total+2] - profile_verts[vi_total]) ^
(profile_verts[vi_total+1] - profile_verts[vi_total])).Normalize();
const IfcFloat abs_dot_face_nor = abs(nor * face_nor);
const IfcFloat abs_dot_face_nor = std::abs(nor * face_nor);
if (abs_dot_face_nor < 0.9) {
vi_total += profile_vertcnts[f];
continue;

View File

@ -50,6 +50,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#if defined(_MSC_VER) && (_MSC_VER <= 1500)
#include "Compiler/pstdint.h"
#else
#include <limits.h>
#include <stdint.h>
#endif

View File

@ -273,11 +273,10 @@ template<typename TReal>
inline aiVector3t<TReal> aiQuaterniont<TReal>::Rotate (const aiVector3t<TReal>& v)
{
aiQuaterniont q2(0.f,v.x,v.y,v.z), q = *this, qinv = q;
q.Conjugate();
qinv.Conjugate();
q = q*q2*qinv;
return aiVector3t<TReal>(q.x,q.y,q.z);
}
#endif

View File

@ -1,5 +1,3 @@
#-*- coding: UTF-8 -*-
"""
PyAssimp
@ -21,37 +19,31 @@ logger = logging.getLogger("pyassimp")
logger.addHandler(logging.NullHandler())
from . import structs
from .errors import AssimpError
from . import helper
from . import postprocess
from .errors import AssimpError
from .formats import available_formats
assimp_structs_as_tuple = (
structs.Matrix4x4,
structs.Matrix3x3,
structs.Vector2D,
structs.Vector3D,
structs.Color3D,
structs.Color4D,
structs.Quaternion,
structs.Plane,
structs.Texel)
class AssimpLib(object):
"""
Assimp-Singleton
"""
load, load_mem, release, dll = helper.search_library()
_assimp_lib = AssimpLib()
def make_tuple(ai_obj, type = None):
res = None
if isinstance(ai_obj, structs.Matrix4x4):
res = numpy.array([getattr(ai_obj, e[0]) for e in ai_obj._fields_]).reshape((4,4))
#import pdb;pdb.set_trace()
elif isinstance(ai_obj, structs.Matrix3x3):
res = numpy.array([getattr(ai_obj, e[0]) for e in ai_obj._fields_]).reshape((3,3))
else:
res = numpy.array([getattr(ai_obj, e[0]) for e in ai_obj._fields_])
return res
# It is faster and more correct to have an init function for each assimp class
def _init_face(aiFace):
aiFace.indices = [aiFace.mIndices[i] for i in range(aiFace.mNumIndices)]
assimp_struct_inits = { structs.Face : _init_face }
def call_init(obj, caller = None):
@ -112,7 +104,7 @@ def _init(self, target = None, parent = None):
obj = getattr(self, m)
# Create tuples
if isinstance(obj, assimp_structs_as_tuple):
if isinstance(obj, structs.assimp_structs_as_tuple):
setattr(target, name, make_tuple(obj))
logger.debug(str(self) + ": Added array " + str(getattr(target, name)) + " as self." + name.lower())
continue
@ -142,7 +134,7 @@ def _init(self, target = None, parent = None):
try:
if obj._type_ in assimp_structs_as_tuple:
if obj._type_ in structs.assimp_structs_as_tuple:
setattr(target, name, numpy.array([make_tuple(obj[i]) for i in range(length)], dtype=numpy.float32))
logger.debug(str(self) + ": Added an array of numpy arrays (type "+ str(type(obj)) + ") as self." + name)
@ -180,17 +172,14 @@ def _init(self, target = None, parent = None):
raise e
else: # starts with 'm' but not iterable
else: # starts with 'm' but not iterable
setattr(target, name, obj)
logger.debug("Added " + name + " as self." + name + " (type: " + str(type(obj)) + ")")
if _is_init_type(obj):
call_init(obj, target)
if isinstance(self, structs.Mesh):
_finalize_mesh(self, target)
@ -200,14 +189,6 @@ def _init(self, target = None, parent = None):
return self
class AssimpLib(object):
"""
Assimp-Singleton
"""
load, load_mem, release, dll = helper.search_library()
#the loader as singleton
_assimp_lib = AssimpLib()
def pythonize_assimp(type, obj, scene):
""" This method modify the Assimp data structures
@ -247,17 +228,16 @@ def recur_pythonize(node, scene):
pythonize the assimp datastructures.
'''
node.meshes = pythonize_assimp("MESH", node.meshes, scene)
for mesh in node.meshes:
mesh.material = scene.materials[mesh.materialindex]
for cam in scene.cameras:
pythonize_assimp("ADDTRANSFORMATION", cam, scene)
for c in node.children:
recur_pythonize(c, scene)
def load(filename, processing=0, file_type=None):
def load(filename,
file_type = None,
processing = postprocess.aiProcess_Triangulate):
'''
Load a model into a scene. On failure throws AssimpError.
@ -267,12 +247,17 @@ def load(filename, processing=0, file_type=None):
If a file object is passed, file_type MUST be specified
Otherwise Assimp has no idea which importer to use.
This is named 'filename' so as to not break legacy code.
processing: assimp processing parameters
file_type: string, such as 'stl'
processing: assimp postprocessing parameters. Verbose keywords are imported
from postprocessing, and the parameters can be combined bitwise to
generate the final processing value. Note that the default value will
triangulate quad faces. Example of generating other possible values:
processing = (pyassimp.postprocess.aiProcess_Triangulate |
pyassimp.postprocess.aiProcess_OptimizeMeshes)
file_type: string of file extension, such as 'stl'
Returns
---------
Scene object with model-data
Scene object with model data
'''
if hasattr(filename, 'read'):

View File

@ -0,0 +1,41 @@
FORMATS = ["CSM",
"LWS",
"B3D",
"COB",
"PLY",
"IFC",
"OFF",
"SMD",
"IRRMESH",
"3D",
"DAE",
"MDL",
"HMP",
"TER",
"WRL",
"XML",
"NFF",
"AC",
"OBJ",
"3DS",
"STL",
"IRR",
"Q3O",
"Q3D"
"MS3D",
"Q3S",
"ZGL",
"MD2",
"X",
"BLEND",
"XGL",
"MD5MESH",
"MAX",
"LXO",
"DXF",
"BVH",
"LWO",
"NDO"]
def available_formats():
return FORMATS

View File

@ -897,3 +897,13 @@ class Scene(Structure):
# the scene.
("mCameras", POINTER(POINTER(Camera))),
]
assimp_structs_as_tuple = (Matrix4x4,
Matrix3x3,
Vector2D,
Vector3D,
Color3D,
Color4D,
Quaternion,
Plane,
Texel)

View File

@ -28,7 +28,7 @@ ADD_EXECUTABLE( assimp_simpleogl
Sample_SimpleOpenGL.c
)
SET_PROPERTY(TARGET assimp_simpleogl PROPERTY DEBUG_POSTFIX ${ASSIMP_DEBUG_POSTFIX})
SET_PROPERTY(TARGET assimp_simpleogl PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
TARGET_LINK_LIBRARIES( assimp_simpleogl assimp ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${M_LIB} )
SET_TARGET_PROPERTIES( assimp_simpleogl PROPERTIES

View File

@ -30,7 +30,7 @@ ADD_EXECUTABLE( assimp_simpletexturedogl WIN32
SimpleTexturedOpenGL/src/model_loading.cpp
)
SET_PROPERTY(TARGET assimp_simpletexturedogl PROPERTY DEBUG_POSTFIX ${ASSIMP_DEBUG_POSTFIX})
SET_PROPERTY(TARGET assimp_simpletexturedogl PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
TARGET_LINK_LIBRARIES( assimp_simpletexturedogl assimp ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} DevIL.lib )

View File

@ -52,7 +52,7 @@ add_executable( unit
${TEST_SRCS}
)
SET_PROPERTY( TARGET assimp PROPERTY DEBUG_POSTFIX ${ASSIMP_DEBUG_POSTFIX} )
SET_PROPERTY( TARGET assimp PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX} )
add_dependencies( unit gtest )
target_link_libraries( unit assimp

View File

@ -19,7 +19,7 @@ ADD_EXECUTABLE( assimp_cmd
Export.cpp
)
SET_PROPERTY(TARGET assimp_cmd PROPERTY DEBUG_POSTFIX ${ASSIMP_DEBUG_POSTFIX})
SET_PROPERTY(TARGET assimp_cmd PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
IF( WIN32 )
ADD_CUSTOM_COMMAND(TARGET assimp_cmd

View File

@ -112,12 +112,12 @@ unsigned int CountAnimChannels(const aiScene* scene)
// -----------------------------------------------------------------------------------
unsigned int GetAvgFacePerMesh(const aiScene* scene) {
return static_cast<unsigned int>(CountFaces(scene)/scene->mNumMeshes);
return (scene->mNumMeshes != 0) ? static_cast<unsigned int>(CountFaces(scene)/scene->mNumMeshes) : 0;
}
// -----------------------------------------------------------------------------------
unsigned int GetAvgVertsPerMesh(const aiScene* scene) {
return static_cast<unsigned int>(CountVertices(scene)/scene->mNumMeshes);
return (scene->mNumMeshes != 0) ? static_cast<unsigned int>(CountVertices(scene)/scene->mNumMeshes) : 0;
}
// -----------------------------------------------------------------------------------

View File

@ -42,7 +42,7 @@ ADD_EXECUTABLE( assimp_viewer WIN32
txi.bmp
)
SET_PROPERTY(TARGET assimp_viewer PROPERTY DEBUG_POSTFIX ${ASSIMP_DEBUG_POSTFIX})
SET_PROPERTY(TARGET assimp_viewer PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
IF ( MSVC )