Merge branch 'master' into step-import
commit
b191754863
|
@ -30,6 +30,8 @@ One-off donations via PayPal:
|
||||||
|
|
||||||
Please check our Wiki as well: https://github.com/assimp/assimp/wiki
|
Please check our Wiki as well: https://github.com/assimp/assimp/wiki
|
||||||
|
|
||||||
|
If you want to check our Model-Database, use the following repo: https://github.com/assimp/assimp-mdb
|
||||||
|
|
||||||
#### Supported file formats ####
|
#### Supported file formats ####
|
||||||
|
|
||||||
__Importers__:
|
__Importers__:
|
||||||
|
|
|
@ -62,33 +62,30 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
using namespace Assimp;
|
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
size_t Write(IOStream * stream, const T& v)
|
size_t Write(IOStream * stream, const T& v) {
|
||||||
{
|
|
||||||
return stream->Write( &v, sizeof(T), 1 );
|
return stream->Write( &v, sizeof(T), 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
// Serialize an aiString
|
// Serialize an aiString
|
||||||
template <>
|
template <>
|
||||||
inline size_t Write<aiString>(IOStream * stream, const aiString& s)
|
inline
|
||||||
{
|
size_t Write<aiString>(IOStream * stream, const aiString& s) {
|
||||||
const size_t s2 = (uint32_t)s.length;
|
const size_t s2 = (uint32_t)s.length;
|
||||||
stream->Write(&s,4,1);
|
stream->Write(&s,4,1);
|
||||||
stream->Write(s.data,s2,1);
|
stream->Write(s.data,s2,1);
|
||||||
|
|
||||||
return s2+4;
|
return s2+4;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
// Serialize an unsigned int as uint32_t
|
// Serialize an unsigned int as uint32_t
|
||||||
template <>
|
template <>
|
||||||
inline size_t Write<unsigned int>(IOStream * stream, const unsigned int& w)
|
inline
|
||||||
{
|
size_t Write<unsigned int>(IOStream * stream, const unsigned int& w) {
|
||||||
const uint32_t t = (uint32_t)w;
|
const uint32_t t = (uint32_t)w;
|
||||||
if (w > t) {
|
if (w > t) {
|
||||||
// this shouldn't happen, integers in Assimp data structures never exceed 2^32
|
// this shouldn't happen, integers in Assimp data structures never exceed 2^32
|
||||||
|
@ -96,114 +93,123 @@ inline size_t Write<unsigned int>(IOStream * stream, const unsigned int& w)
|
||||||
}
|
}
|
||||||
|
|
||||||
stream->Write(&t,4,1);
|
stream->Write(&t,4,1);
|
||||||
|
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
// Serialize an unsigned int as uint16_t
|
// Serialize an unsigned int as uint16_t
|
||||||
template <>
|
template <>
|
||||||
inline size_t Write<uint16_t>(IOStream * stream, const uint16_t& w)
|
inline
|
||||||
{
|
size_t Write<uint16_t>(IOStream * stream, const uint16_t& w) {
|
||||||
static_assert(sizeof(uint16_t)==2, "sizeof(uint16_t)==2");
|
static_assert(sizeof(uint16_t)==2, "sizeof(uint16_t)==2");
|
||||||
stream->Write(&w,2,1);
|
stream->Write(&w,2,1);
|
||||||
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
// Serialize a float
|
// Serialize a float
|
||||||
template <>
|
template <>
|
||||||
inline size_t Write<float>(IOStream * stream, const float& f)
|
inline
|
||||||
{
|
size_t Write<float>(IOStream * stream, const float& f) {
|
||||||
static_assert(sizeof(float)==4, "sizeof(float)==4");
|
static_assert(sizeof(float)==4, "sizeof(float)==4");
|
||||||
stream->Write(&f,4,1);
|
stream->Write(&f,4,1);
|
||||||
|
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
// Serialize a double
|
// Serialize a double
|
||||||
template <>
|
template <>
|
||||||
inline size_t Write<double>(IOStream * stream, const double& f)
|
inline
|
||||||
{
|
size_t Write<double>(IOStream * stream, const double& f) {
|
||||||
static_assert(sizeof(double)==8, "sizeof(double)==8");
|
static_assert(sizeof(double)==8, "sizeof(double)==8");
|
||||||
stream->Write(&f,8,1);
|
stream->Write(&f,8,1);
|
||||||
|
|
||||||
return 8;
|
return 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
// Serialize a vec3
|
// Serialize a vec3
|
||||||
template <>
|
template <>
|
||||||
inline size_t Write<aiVector3D>(IOStream * stream, const aiVector3D& v)
|
inline
|
||||||
{
|
size_t Write<aiVector3D>(IOStream * stream, const aiVector3D& v) {
|
||||||
size_t t = Write<float>(stream,v.x);
|
size_t t = Write<float>(stream,v.x);
|
||||||
t += Write<float>(stream,v.y);
|
t += Write<float>(stream,v.y);
|
||||||
t += Write<float>(stream,v.z);
|
t += Write<float>(stream,v.z);
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
// Serialize a color value
|
// Serialize a color value
|
||||||
template <>
|
template <>
|
||||||
inline size_t Write<aiColor3D>(IOStream * stream, const aiColor3D& v)
|
inline
|
||||||
{
|
size_t Write<aiColor3D>(IOStream * stream, const aiColor3D& v) {
|
||||||
size_t t = Write<float>(stream,v.r);
|
size_t t = Write<float>(stream,v.r);
|
||||||
t += Write<float>(stream,v.g);
|
t += Write<float>(stream,v.g);
|
||||||
t += Write<float>(stream,v.b);
|
t += Write<float>(stream,v.b);
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
// Serialize a color value
|
// Serialize a color value
|
||||||
template <>
|
template <>
|
||||||
inline size_t Write<aiColor4D>(IOStream * stream, const aiColor4D& v)
|
inline
|
||||||
{
|
size_t Write<aiColor4D>(IOStream * stream, const aiColor4D& v) {
|
||||||
size_t t = Write<float>(stream,v.r);
|
size_t t = Write<float>(stream,v.r);
|
||||||
t += Write<float>(stream,v.g);
|
t += Write<float>(stream,v.g);
|
||||||
t += Write<float>(stream,v.b);
|
t += Write<float>(stream,v.b);
|
||||||
t += Write<float>(stream,v.a);
|
t += Write<float>(stream,v.a);
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
// Serialize a quaternion
|
// Serialize a quaternion
|
||||||
template <>
|
template <>
|
||||||
inline size_t Write<aiQuaternion>(IOStream * stream, const aiQuaternion& v)
|
inline
|
||||||
{
|
size_t Write<aiQuaternion>(IOStream * stream, const aiQuaternion& v) {
|
||||||
size_t t = Write<float>(stream,v.w);
|
size_t t = Write<float>(stream,v.w);
|
||||||
t += Write<float>(stream,v.x);
|
t += Write<float>(stream,v.x);
|
||||||
t += Write<float>(stream,v.y);
|
t += Write<float>(stream,v.y);
|
||||||
t += Write<float>(stream,v.z);
|
t += Write<float>(stream,v.z);
|
||||||
ai_assert(t == 16);
|
ai_assert(t == 16);
|
||||||
|
|
||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
// Serialize a vertex weight
|
// Serialize a vertex weight
|
||||||
template <>
|
template <>
|
||||||
inline size_t Write<aiVertexWeight>(IOStream * stream, const aiVertexWeight& v)
|
inline
|
||||||
{
|
size_t Write<aiVertexWeight>(IOStream * stream, const aiVertexWeight& v) {
|
||||||
size_t t = Write<unsigned int>(stream,v.mVertexId);
|
size_t t = Write<unsigned int>(stream,v.mVertexId);
|
||||||
|
|
||||||
return t+Write<float>(stream,v.mWeight);
|
return t+Write<float>(stream,v.mWeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
// Serialize a mat4x4
|
// Serialize a mat4x4
|
||||||
template <>
|
template <>
|
||||||
inline size_t Write<aiMatrix4x4>(IOStream * stream, const aiMatrix4x4& m)
|
inline
|
||||||
{
|
size_t Write<aiMatrix4x4>(IOStream * stream, const aiMatrix4x4& m) {
|
||||||
for (unsigned int i = 0; i < 4;++i) {
|
for (unsigned int i = 0; i < 4;++i) {
|
||||||
for (unsigned int i2 = 0; i2 < 4;++i2) {
|
for (unsigned int i2 = 0; i2 < 4;++i2) {
|
||||||
Write<float>(stream,m[i][i2]);
|
Write<float>(stream,m[i][i2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 64;
|
return 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
// Serialize an aiVectorKey
|
// Serialize an aiVectorKey
|
||||||
template <>
|
template <>
|
||||||
inline size_t Write<aiVectorKey>(IOStream * stream, const aiVectorKey& v)
|
inline
|
||||||
{
|
size_t Write<aiVectorKey>(IOStream * stream, const aiVectorKey& v) {
|
||||||
const size_t t = Write<double>(stream,v.mTime);
|
const size_t t = Write<double>(stream,v.mTime);
|
||||||
return t + Write<aiVector3D>(stream,v.mValue);
|
return t + Write<aiVector3D>(stream,v.mValue);
|
||||||
}
|
}
|
||||||
|
@ -211,16 +217,16 @@ inline size_t Write<aiVectorKey>(IOStream * stream, const aiVectorKey& v)
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
// Serialize an aiQuatKey
|
// Serialize an aiQuatKey
|
||||||
template <>
|
template <>
|
||||||
inline size_t Write<aiQuatKey>(IOStream * stream, const aiQuatKey& v)
|
inline
|
||||||
{
|
size_t Write<aiQuatKey>(IOStream * stream, const aiQuatKey& v) {
|
||||||
const size_t t = Write<double>(stream,v.mTime);
|
const size_t t = Write<double>(stream,v.mTime);
|
||||||
return t + Write<aiQuaternion>(stream,v.mValue);
|
return t + Write<aiQuaternion>(stream,v.mValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline size_t WriteBounds(IOStream * stream, const T* in, unsigned int size)
|
inline
|
||||||
{
|
size_t WriteBounds(IOStream * stream, const T* in, unsigned int size) {
|
||||||
T minc,maxc;
|
T minc, maxc;
|
||||||
ArrayBounds(in,size,minc,maxc);
|
ArrayBounds(in,size,minc,maxc);
|
||||||
|
|
||||||
const size_t t = Write<T>(stream,minc);
|
const size_t t = Write<T>(stream,minc);
|
||||||
|
@ -230,10 +236,11 @@ inline size_t WriteBounds(IOStream * stream, const T* in, unsigned int size)
|
||||||
// We use this to write out non-byte arrays so that we write using the specializations.
|
// We use this to write out non-byte arrays so that we write using the specializations.
|
||||||
// This way we avoid writing out extra bytes that potentially come from struct alignment.
|
// This way we avoid writing out extra bytes that potentially come from struct alignment.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline size_t WriteArray(IOStream * stream, const T* in, unsigned int size)
|
inline
|
||||||
{
|
size_t WriteArray(IOStream * stream, const T* in, unsigned int size) {
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
for (unsigned int i=0; i<size; i++) n += Write<T>(stream,in[i]);
|
for (unsigned int i=0; i<size; i++) n += Write<T>(stream,in[i]);
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,19 +300,25 @@ inline size_t WriteArray(IOStream * stream, const T* in, unsigned int size)
|
||||||
void * GetBufferPointer() { return buffer; }
|
void * GetBufferPointer() { return buffer; }
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
virtual size_t Read(void* /*pvBuffer*/, size_t /*pSize*/, size_t /*pCount*/) { return 0; }
|
virtual size_t Read(void* /*pvBuffer*/, size_t /*pSize*/, size_t /*pCount*/) {
|
||||||
virtual aiReturn Seek(size_t /*pOffset*/, aiOrigin /*pOrigin*/) { return aiReturn_FAILURE; }
|
return 0;
|
||||||
virtual size_t Tell() const { return cursor; }
|
}
|
||||||
virtual void Flush() { }
|
virtual aiReturn Seek(size_t /*pOffset*/, aiOrigin /*pOrigin*/) {
|
||||||
|
return aiReturn_FAILURE;
|
||||||
|
}
|
||||||
|
virtual size_t Tell() const {
|
||||||
|
return cursor;
|
||||||
|
}
|
||||||
|
virtual void Flush() {
|
||||||
|
// not implemented
|
||||||
|
}
|
||||||
|
|
||||||
virtual size_t FileSize() const
|
virtual size_t FileSize() const {
|
||||||
{
|
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
virtual size_t Write(const void* pvBuffer, size_t pSize, size_t pCount)
|
virtual size_t Write(const void* pvBuffer, size_t pSize, size_t pCount) {
|
||||||
{
|
|
||||||
pSize *= pCount;
|
pSize *= pCount;
|
||||||
if (cursor + pSize > cur_size) {
|
if (cursor + pSize > cur_size) {
|
||||||
Grow(cursor + pSize);
|
Grow(cursor + pSize);
|
||||||
|
@ -332,7 +345,6 @@ inline size_t WriteArray(IOStream * stream, const T* in, unsigned int size)
|
||||||
bool compressed;
|
bool compressed;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
void WriteBinaryNode( IOStream * container, const aiNode* node)
|
void WriteBinaryNode( IOStream * container, const aiNode* node)
|
||||||
{
|
{
|
||||||
|
|
|
@ -696,8 +696,12 @@ void AssbinImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
|
||||||
|
|
||||||
stream->Seek( 44, aiOrigin_CUR ); // signature
|
stream->Seek( 44, aiOrigin_CUR ); // signature
|
||||||
|
|
||||||
/*unsigned int versionMajor =*/ Read<unsigned int>(stream);
|
unsigned int versionMajor = Read<unsigned int>(stream);
|
||||||
/*unsigned int versionMinor =*/ Read<unsigned int>(stream);
|
unsigned int versionMinor = Read<unsigned int>(stream);
|
||||||
|
if (versionMinor != ASSBIN_VERSION_MINOR || versionMajor != ASSBIN_VERSION_MAJOR) {
|
||||||
|
throw DeadlyImportError( "Invalid version, data format not compatible!" );
|
||||||
|
}
|
||||||
|
|
||||||
/*unsigned int versionRevision =*/ Read<unsigned int>(stream);
|
/*unsigned int versionRevision =*/ Read<unsigned int>(stream);
|
||||||
/*unsigned int compileFlags =*/ Read<unsigned int>(stream);
|
/*unsigned int compileFlags =*/ Read<unsigned int>(stream);
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,7 @@ public:
|
||||||
aiScene* pScene,
|
aiScene* pScene,
|
||||||
IOSystem* pIOHandler
|
IOSystem* pIOHandler
|
||||||
);
|
);
|
||||||
|
void ReadHeader();
|
||||||
void ReadBinaryScene( IOStream * stream, aiScene* pScene );
|
void ReadBinaryScene( IOStream * stream, aiScene* pScene );
|
||||||
void ReadBinaryNode( IOStream * stream, aiNode** mRootNode, aiNode* parent );
|
void ReadBinaryNode( IOStream * stream, aiNode** mRootNode, aiNode* parent );
|
||||||
void ReadBinaryMesh( IOStream * stream, aiMesh* mesh );
|
void ReadBinaryMesh( IOStream * stream, aiMesh* mesh );
|
||||||
|
|
|
@ -434,11 +434,13 @@ void MDCImporter::InternReadFile(
|
||||||
else if (1 == pScene->mNumMeshes)
|
else if (1 == pScene->mNumMeshes)
|
||||||
{
|
{
|
||||||
pScene->mRootNode = new aiNode();
|
pScene->mRootNode = new aiNode();
|
||||||
|
if ( nullptr != pScene->mMeshes[0] ) {
|
||||||
pScene->mRootNode->mName = pScene->mMeshes[0]->mName;
|
pScene->mRootNode->mName = pScene->mMeshes[0]->mName;
|
||||||
pScene->mRootNode->mNumMeshes = 1;
|
pScene->mRootNode->mNumMeshes = 1;
|
||||||
pScene->mRootNode->mMeshes = new unsigned int[1];
|
pScene->mRootNode->mMeshes = new unsigned int[1];
|
||||||
pScene->mRootNode->mMeshes[0] = 0;
|
pScene->mRootNode->mMeshes[0] = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pScene->mRootNode = new aiNode();
|
pScene->mRootNode = new aiNode();
|
||||||
|
|
|
@ -66,6 +66,13 @@ def make_tuple(ai_obj, type = None):
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
# Returns unicode object for Python 2, and str object for Python 3.
|
||||||
|
def _convert_assimp_string(assimp_string):
|
||||||
|
try:
|
||||||
|
return unicode(assimp_string.data, errors='ignore')
|
||||||
|
except:
|
||||||
|
return str(assimp_string.data, errors='ignore')
|
||||||
|
|
||||||
# It is faster and more correct to have an init function for each assimp class
|
# It is faster and more correct to have an init function for each assimp class
|
||||||
def _init_face(aiFace):
|
def _init_face(aiFace):
|
||||||
aiFace.indices = [aiFace.mIndices[i] for i in range(aiFace.mNumIndices)]
|
aiFace.indices = [aiFace.mIndices[i] for i in range(aiFace.mNumIndices)]
|
||||||
|
@ -118,14 +125,9 @@ def _init(self, target = None, parent = None):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if m == 'mName':
|
if m == 'mName':
|
||||||
obj = self.mName
|
target.name = str(_convert_assimp_string(self.mName))
|
||||||
try:
|
target.__class__.__repr__ = lambda x: str(x.__class__) + "(" + getattr(x, 'name','') + ")"
|
||||||
uni = unicode(obj.data, errors='ignore')
|
target.__class__.__str__ = lambda x: getattr(x, 'name', '')
|
||||||
except:
|
|
||||||
uni = str(obj.data, errors='ignore')
|
|
||||||
target.name = str( uni )
|
|
||||||
target.__class__.__repr__ = lambda x: str(x.__class__) + "(" + x.name + ")"
|
|
||||||
target.__class__.__str__ = lambda x: x.name
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
name = m[1:].lower()
|
name = m[1:].lower()
|
||||||
|
@ -220,6 +222,9 @@ def _init(self, target = None, parent = None):
|
||||||
if isinstance(self, structs.Texture):
|
if isinstance(self, structs.Texture):
|
||||||
_finalize_texture(self, target)
|
_finalize_texture(self, target)
|
||||||
|
|
||||||
|
if isinstance(self, structs.Metadata):
|
||||||
|
_finalize_metadata(self, target)
|
||||||
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@ -412,6 +417,43 @@ def _finalize_mesh(mesh, target):
|
||||||
faces = [f.indices for f in target.faces]
|
faces = [f.indices for f in target.faces]
|
||||||
setattr(target, 'faces', faces)
|
setattr(target, 'faces', faces)
|
||||||
|
|
||||||
|
def _init_metadata_entry(entry):
|
||||||
|
from ctypes import POINTER, c_bool, c_int32, c_uint64, c_float, c_double, cast
|
||||||
|
|
||||||
|
entry.type = entry.mType
|
||||||
|
if entry.type == structs.MetadataEntry.AI_BOOL:
|
||||||
|
entry.data = cast(entry.mData, POINTER(c_bool)).contents.value
|
||||||
|
elif entry.type == structs.MetadataEntry.AI_INT32:
|
||||||
|
entry.data = cast(entry.mData, POINTER(c_int32)).contents.value
|
||||||
|
elif entry.type == structs.MetadataEntry.AI_UINT64:
|
||||||
|
entry.data = cast(entry.mData, POINTER(c_uint64)).contents.value
|
||||||
|
elif entry.type == structs.MetadataEntry.AI_FLOAT:
|
||||||
|
entry.data = cast(entry.mData, POINTER(c_float)).contents.value
|
||||||
|
elif entry.type == structs.MetadataEntry.AI_DOUBLE:
|
||||||
|
entry.data = cast(entry.mData, POINTER(c_double)).contents.value
|
||||||
|
elif entry.type == structs.MetadataEntry.AI_AISTRING:
|
||||||
|
assimp_string = cast(entry.mData, POINTER(structs.String)).contents
|
||||||
|
entry.data = _convert_assimp_string(assimp_string)
|
||||||
|
elif entry.type == structs.MetadataEntry.AI_AIVECTOR3D:
|
||||||
|
assimp_vector = cast(entry.mData, POINTER(structs.Vector3D)).contents
|
||||||
|
entry.data = make_tuple(assimp_vector)
|
||||||
|
|
||||||
|
return entry
|
||||||
|
|
||||||
|
def _finalize_metadata(metadata, target):
|
||||||
|
""" Building the metadata object is a bit specific.
|
||||||
|
|
||||||
|
Firstly, there are two separate arrays: one with metadata keys and one
|
||||||
|
with metadata values, and there are no corresponding mNum* attributes,
|
||||||
|
so the C arrays are not converted to Python arrays using the generic
|
||||||
|
code in the _init function.
|
||||||
|
|
||||||
|
Secondly, a metadata entry value has to be cast according to declared
|
||||||
|
metadata entry type.
|
||||||
|
"""
|
||||||
|
length = metadata.mNumProperties
|
||||||
|
setattr(target, 'keys', [str(_convert_assimp_string(metadata.mKeys[i])) for i in range(length)])
|
||||||
|
setattr(target, 'values', [_init_metadata_entry(metadata.mValues[i]) for i in range(length)])
|
||||||
|
|
||||||
class PropertyGetter(dict):
|
class PropertyGetter(dict):
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
|
@ -443,11 +485,8 @@ 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
|
||||||
try:
|
key = str(_convert_assimp_string(p.mKey))
|
||||||
uni = unicode(p.mKey.data, errors='ignore')
|
key = (key.split('.')[1], p.mSemantic)
|
||||||
except:
|
|
||||||
uni = str(p.mKey.data, errors='ignore')
|
|
||||||
key = (str(uni).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
|
||||||
|
@ -455,11 +494,7 @@ def _get_properties(properties, length):
|
||||||
arr = cast(p.mData, POINTER(c_float * int(p.mDataLength/sizeof(c_float)) )).contents
|
arr = cast(p.mData, POINTER(c_float * int(p.mDataLength/sizeof(c_float)) )).contents
|
||||||
value = [x for x in arr]
|
value = [x for x in arr]
|
||||||
elif p.mType == 3: #string can't be an array
|
elif p.mType == 3: #string can't be an array
|
||||||
try:
|
value = _convert_assimp_string(cast(p.mData, POINTER(structs.MaterialPropertyString)).contents)
|
||||||
uni = unicode(cast(p.mData, POINTER(structs.MaterialPropertyString)).contents.data, errors='ignore')
|
|
||||||
except:
|
|
||||||
uni = str(cast(p.mData, POINTER(structs.MaterialPropertyString)).contents.data, errors='ignore')
|
|
||||||
value = uni
|
|
||||||
|
|
||||||
elif p.mType == 4:
|
elif p.mType == 4:
|
||||||
arr = cast(p.mData, POINTER(c_int * int(p.mDataLength/sizeof(c_int)) )).contents
|
arr = cast(p.mData, POINTER(c_int * int(p.mDataLength/sizeof(c_int)) )).contents
|
||||||
|
|
|
@ -214,6 +214,41 @@ class MeshKey(Structure):
|
||||||
("mValue", c_uint),
|
("mValue", c_uint),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
class MetadataEntry(Structure):
|
||||||
|
"""
|
||||||
|
See 'metadata.h' for details
|
||||||
|
"""
|
||||||
|
AI_BOOL = 0
|
||||||
|
AI_INT32 = 1
|
||||||
|
AI_UINT64 = 2
|
||||||
|
AI_FLOAT = 3
|
||||||
|
AI_DOUBLE = 4
|
||||||
|
AI_AISTRING = 5
|
||||||
|
AI_AIVECTOR3D = 6
|
||||||
|
AI_META_MAX = 7
|
||||||
|
_fields_ = [
|
||||||
|
# The type field uniquely identifies the underlying type of the data field
|
||||||
|
("mType", c_uint),
|
||||||
|
("mData", c_void_p),
|
||||||
|
]
|
||||||
|
|
||||||
|
class Metadata(Structure):
|
||||||
|
"""
|
||||||
|
See 'metadata.h' for details
|
||||||
|
"""
|
||||||
|
_fields_ = [
|
||||||
|
# Length of the mKeys and mValues arrays, respectively
|
||||||
|
("mNumProperties", c_uint),
|
||||||
|
|
||||||
|
# Arrays of keys, may not be NULL. Entries in this array may not be NULL
|
||||||
|
# as well.
|
||||||
|
("mKeys", POINTER(String)),
|
||||||
|
|
||||||
|
# Arrays of values, may not be NULL. Entries in this array may be NULL
|
||||||
|
# if the corresponding property key has no assigned value.
|
||||||
|
("mValues", POINTER(MetadataEntry)),
|
||||||
|
]
|
||||||
|
|
||||||
class Node(Structure):
|
class Node(Structure):
|
||||||
"""
|
"""
|
||||||
See 'aiScene.h' for details.
|
See 'aiScene.h' for details.
|
||||||
|
@ -253,6 +288,10 @@ Node._fields_ = [
|
||||||
|
|
||||||
# The meshes of this node. Each entry is an index into the mesh
|
# The meshes of this node. Each entry is an index into the mesh
|
||||||
("mMeshes", POINTER(c_uint)),
|
("mMeshes", POINTER(c_uint)),
|
||||||
|
|
||||||
|
# Metadata associated with this node or NULL if there is no metadata.
|
||||||
|
# Whether any metadata is generated depends on the source file format.
|
||||||
|
("mMetadata", POINTER(Metadata)),
|
||||||
]
|
]
|
||||||
|
|
||||||
class Light(Structure):
|
class Light(Structure):
|
||||||
|
@ -896,6 +935,11 @@ class Scene(Structure):
|
||||||
# array (if existing) is the default camera view into
|
# array (if existing) is the default camera view into
|
||||||
# the scene.
|
# the scene.
|
||||||
("mCameras", POINTER(POINTER(Camera))),
|
("mCameras", POINTER(POINTER(Camera))),
|
||||||
|
|
||||||
|
# This data contains global metadata which belongs to the scene like
|
||||||
|
# unit-conversions, versions, vendors or other model-specific data. This
|
||||||
|
# can be used to store format-specific metadata as well.
|
||||||
|
("mMetadata", POINTER(Metadata)),
|
||||||
]
|
]
|
||||||
|
|
||||||
assimp_structs_as_tuple = (Matrix4x4,
|
assimp_structs_as_tuple = (Matrix4x4,
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -113,6 +113,7 @@ SET( IMPORTERS
|
||||||
unit/utColladaImportExport.cpp
|
unit/utColladaImportExport.cpp
|
||||||
unit/utCSMImportExport.cpp
|
unit/utCSMImportExport.cpp
|
||||||
unit/utB3DImportExport.cpp
|
unit/utB3DImportExport.cpp
|
||||||
|
unit/utMDCImportExport.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
SET( MATERIAL
|
SET( MATERIAL
|
||||||
|
|
Binary file not shown.
|
@ -0,0 +1,17 @@
|
||||||
|
####
|
||||||
|
#
|
||||||
|
# OBJ File Generated by Meshlab
|
||||||
|
#
|
||||||
|
####
|
||||||
|
# Object up.obj
|
||||||
|
#
|
||||||
|
# Vertices: 3
|
||||||
|
# Faces: 0
|
||||||
|
#
|
||||||
|
####
|
||||||
|
vn -0.281034 -0.057252 0.957989
|
||||||
|
v -0.207717 -0.953997 2.554110
|
||||||
|
vn -0.139126 -0.135672 0.980937
|
||||||
|
v -0.275607 -0.965401 2.541530
|
||||||
|
vn -0.163133 -0.131576 0.977791
|
||||||
|
v -0.270155 -0.963170 2.548000
|
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
Open Asset Import Library (assimp)
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2006-2018, assimp team
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
with or without modification, are permitted provided that the following
|
||||||
|
conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above
|
||||||
|
copyright notice, this list of conditions and the
|
||||||
|
following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
copyright notice, this list of conditions and the
|
||||||
|
following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
* Neither the name of the assimp team, nor the names of its
|
||||||
|
contributors may be used to endorse or promote products
|
||||||
|
derived from this software without specific prior
|
||||||
|
written permission of the assimp team.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "UnitTestPCH.h"
|
||||||
|
#include "AbstractImportExportBase.h"
|
||||||
|
#include <assimp/Importer.hpp>
|
||||||
|
#include <assimp/postprocess.h>
|
||||||
|
|
||||||
|
using namespace Assimp;
|
||||||
|
|
||||||
|
class utMDCImportExport : public AbstractImportExportBase {
|
||||||
|
public:
|
||||||
|
virtual bool importerTest() {
|
||||||
|
Assimp::Importer importer;
|
||||||
|
const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/MDC/spider.mdc", 0);
|
||||||
|
return true;
|
||||||
|
return nullptr != scene;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F( utMDCImportExport, importMDCFromFileTest ) {
|
||||||
|
EXPECT_TRUE( importerTest() );
|
||||||
|
}
|
|
@ -389,3 +389,10 @@ TEST_F( utObjImportExport, mtllib_after_g ) {
|
||||||
ASSERT_EQ(aiReturn_SUCCESS, mat->Get(AI_MATKEY_NAME, name));
|
ASSERT_EQ(aiReturn_SUCCESS, mat->Get(AI_MATKEY_NAME, name));
|
||||||
EXPECT_STREQ("MyMaterial", name.C_Str());
|
EXPECT_STREQ("MyMaterial", name.C_Str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(utObjImportExport, import_point_cloud) {
|
||||||
|
::Assimp::Importer importer;
|
||||||
|
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/OBJ/point_cloud.obj", 0 );
|
||||||
|
ASSERT_NE(nullptr, scene);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue