Asked modifications and unit test
parent
8ebd48442e
commit
7d9e9aadbb
|
@ -173,12 +173,9 @@ void M3DExporter::doExport (
|
||||||
// recursive node walker
|
// recursive node walker
|
||||||
void M3DExporter::NodeWalk(const aiNode* pNode, aiMatrix4x4 m)
|
void M3DExporter::NodeWalk(const aiNode* pNode, aiMatrix4x4 m)
|
||||||
{
|
{
|
||||||
unsigned int i, j, k, l, n, idx;
|
|
||||||
aiMatrix4x4 nm = m * pNode->mTransformation;
|
aiMatrix4x4 nm = m * pNode->mTransformation;
|
||||||
m3dv_t vertex;
|
|
||||||
m3dti_t ti;
|
|
||||||
|
|
||||||
for(i = 0; i < pNode->mNumMeshes; i++) {
|
for(unsigned int i = 0; i < pNode->mNumMeshes; i++) {
|
||||||
const aiMesh *mesh = mScene->mMeshes[pNode->mMeshes[i]];
|
const aiMesh *mesh = mScene->mMeshes[pNode->mMeshes[i]];
|
||||||
unsigned int mi = (M3D_INDEX)-1U;
|
unsigned int mi = (M3D_INDEX)-1U;
|
||||||
if(mScene->mMaterials) {
|
if(mScene->mMaterials) {
|
||||||
|
@ -186,7 +183,8 @@ void M3DExporter::NodeWalk(const aiNode* pNode, aiMatrix4x4 m)
|
||||||
mi = addMaterial(mScene->mMaterials[mesh->mMaterialIndex]);
|
mi = addMaterial(mScene->mMaterials[mesh->mMaterialIndex]);
|
||||||
}
|
}
|
||||||
// iterate through the mesh faces
|
// iterate through the mesh faces
|
||||||
for(j = 0; j < mesh->mNumFaces; j++) {
|
for(unsigned int j = 0; j < mesh->mNumFaces; j++) {
|
||||||
|
unsigned int n;
|
||||||
const aiFace* face = &(mesh->mFaces[j]);
|
const aiFace* face = &(mesh->mFaces[j]);
|
||||||
// only triangle meshes supported for now
|
// only triangle meshes supported for now
|
||||||
if(face->mNumIndices != 3) {
|
if(face->mNumIndices != 3) {
|
||||||
|
@ -204,9 +202,12 @@ void M3DExporter::NodeWalk(const aiNode* pNode, aiMatrix4x4 m)
|
||||||
m3d->face[n].normal[0] = m3d->face[n].normal[1] = m3d->face[n].normal[2] =
|
m3d->face[n].normal[0] = m3d->face[n].normal[1] = m3d->face[n].normal[2] =
|
||||||
m3d->face[n].texcoord[0] = m3d->face[n].texcoord[1] = m3d->face[n].texcoord[2] = -1U;
|
m3d->face[n].texcoord[0] = m3d->face[n].texcoord[1] = m3d->face[n].texcoord[2] = -1U;
|
||||||
m3d->face[n].materialid = mi;
|
m3d->face[n].materialid = mi;
|
||||||
for(k = 0; k < face->mNumIndices; k++) {
|
for(unsigned int k = 0; k < face->mNumIndices; k++) {
|
||||||
// get the vertex's index
|
// get the vertex's index
|
||||||
l = face->mIndices[k];
|
unsigned int l = face->mIndices[k];
|
||||||
|
unsigned int idx;
|
||||||
|
m3dv_t vertex;
|
||||||
|
m3dti_t ti;
|
||||||
// multiply the position vector by the transformation matrix
|
// multiply the position vector by the transformation matrix
|
||||||
aiVector3D v = mesh->mVertices[l];
|
aiVector3D v = mesh->mVertices[l];
|
||||||
v *= nm;
|
v *= nm;
|
||||||
|
@ -245,7 +246,7 @@ void M3DExporter::NodeWalk(const aiNode* pNode, aiMatrix4x4 m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// repeat for the children nodes
|
// repeat for the children nodes
|
||||||
for (i = 0; i < pNode->mNumChildren; i++) {
|
for (unsigned int i = 0; i < pNode->mNumChildren; i++) {
|
||||||
NodeWalk(pNode->mChildren[i], nm);
|
NodeWalk(pNode->mChildren[i], nm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ typedef struct {
|
||||||
} aiMatProp;
|
} aiMatProp;
|
||||||
|
|
||||||
/* --- Scalar Properties --- !!!!! must match m3d_propertytypes !!!!! */
|
/* --- Scalar Properties --- !!!!! must match m3d_propertytypes !!!!! */
|
||||||
static aiMatProp aiProps[] = {
|
static const aiMatProp aiProps[] = {
|
||||||
{ AI_MATKEY_COLOR_DIFFUSE }, /* m3dp_Kd */
|
{ AI_MATKEY_COLOR_DIFFUSE }, /* m3dp_Kd */
|
||||||
{ AI_MATKEY_COLOR_AMBIENT }, /* m3dp_Ka */
|
{ AI_MATKEY_COLOR_AMBIENT }, /* m3dp_Ka */
|
||||||
{ AI_MATKEY_COLOR_SPECULAR }, /* m3dp_Ks */
|
{ AI_MATKEY_COLOR_SPECULAR }, /* m3dp_Ks */
|
||||||
|
@ -82,7 +82,7 @@ static aiMatProp aiProps[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* --- Texture Map Properties --- !!!!! must match m3d_propertytypes !!!!! */
|
/* --- Texture Map Properties --- !!!!! must match m3d_propertytypes !!!!! */
|
||||||
static aiMatProp aiTxProps[] = {
|
static const aiMatProp aiTxProps[] = {
|
||||||
{ AI_MATKEY_TEXTURE_DIFFUSE(0) }, /* m3dp_map_Kd */
|
{ AI_MATKEY_TEXTURE_DIFFUSE(0) }, /* m3dp_map_Kd */
|
||||||
{ AI_MATKEY_TEXTURE_AMBIENT(0) }, /* m3dp_map_Ka */
|
{ AI_MATKEY_TEXTURE_AMBIENT(0) }, /* m3dp_map_Ka */
|
||||||
{ AI_MATKEY_TEXTURE_SPECULAR(0) }, /* m3dp_map_Ks */
|
{ AI_MATKEY_TEXTURE_SPECULAR(0) }, /* m3dp_map_Ks */
|
||||||
|
|
|
@ -2144,6 +2144,10 @@ void _m3d_inv(M3D_FLOAT *m)
|
||||||
memcpy(m, &r, sizeof(r));
|
memcpy(m, &r, sizeof(r));
|
||||||
}
|
}
|
||||||
/* compose a coloumn major 4 x 4 matrix from vec3 position and vec4 orientation/rotation quaternion */
|
/* compose a coloumn major 4 x 4 matrix from vec3 position and vec4 orientation/rotation quaternion */
|
||||||
|
#ifndef M3D_EPSILON
|
||||||
|
/* carefully choosen for IEEE 754 don't change */
|
||||||
|
#define M3D_EPSILON ((M3D_FLOAT)1e-7)
|
||||||
|
#endif
|
||||||
void _m3d_mat(M3D_FLOAT *r, m3dv_t *p, m3dv_t *q)
|
void _m3d_mat(M3D_FLOAT *r, m3dv_t *p, m3dv_t *q)
|
||||||
{
|
{
|
||||||
if(q->x == (M3D_FLOAT)0.0 && q->y == (M3D_FLOAT)0.0 && q->z >=(M3D_FLOAT) 0.7071065 && q->z <= (M3D_FLOAT)0.7071075 &&
|
if(q->x == (M3D_FLOAT)0.0 && q->y == (M3D_FLOAT)0.0 && q->z >=(M3D_FLOAT) 0.7071065 && q->z <= (M3D_FLOAT)0.7071075 &&
|
||||||
|
@ -2151,15 +2155,15 @@ void _m3d_mat(M3D_FLOAT *r, m3dv_t *p, m3dv_t *q)
|
||||||
r[ 1] = r[ 2] = r[ 4] = r[ 6] = r[ 8] = r[ 9] = (M3D_FLOAT)0.0;
|
r[ 1] = r[ 2] = r[ 4] = r[ 6] = r[ 8] = r[ 9] = (M3D_FLOAT)0.0;
|
||||||
r[ 0] = r[ 5] = r[10] = (M3D_FLOAT)-1.0;
|
r[ 0] = r[ 5] = r[10] = (M3D_FLOAT)-1.0;
|
||||||
} else {
|
} else {
|
||||||
r[ 0] = 1 - 2 * (q->y * q->y + q->z * q->z); if(r[ 0]>(M3D_FLOAT)-1e-7 && r[ 0]<(M3D_FLOAT)1e-7) r[ 0]=(M3D_FLOAT)0.0;
|
r[ 0] = 1 - 2 * (q->y * q->y + q->z * q->z); if(r[ 0]>-M3D_EPSILON && r[ 0]<M3D_EPSILON) r[ 0]=(M3D_FLOAT)0.0;
|
||||||
r[ 1] = 2 * (q->x * q->y - q->z * q->w); if(r[ 1]>(M3D_FLOAT)-1e-7 && r[ 1]<(M3D_FLOAT)1e-7) r[ 1]=(M3D_FLOAT)0.0;
|
r[ 1] = 2 * (q->x * q->y - q->z * q->w); if(r[ 1]>-M3D_EPSILON && r[ 1]<M3D_EPSILON) r[ 1]=(M3D_FLOAT)0.0;
|
||||||
r[ 2] = 2 * (q->x * q->z + q->y * q->w); if(r[ 2]>(M3D_FLOAT)-1e-7 && r[ 2]<(M3D_FLOAT)1e-7) r[ 2]=(M3D_FLOAT)0.0;
|
r[ 2] = 2 * (q->x * q->z + q->y * q->w); if(r[ 2]>-M3D_EPSILON && r[ 2]<M3D_EPSILON) r[ 2]=(M3D_FLOAT)0.0;
|
||||||
r[ 4] = 2 * (q->x * q->y + q->z * q->w); if(r[ 4]>(M3D_FLOAT)-1e-7 && r[ 4]<(M3D_FLOAT)1e-7) r[ 4]=(M3D_FLOAT)0.0;
|
r[ 4] = 2 * (q->x * q->y + q->z * q->w); if(r[ 4]>-M3D_EPSILON && r[ 4]<M3D_EPSILON) r[ 4]=(M3D_FLOAT)0.0;
|
||||||
r[ 5] = 1 - 2 * (q->x * q->x + q->z * q->z); if(r[ 5]>(M3D_FLOAT)-1e-7 && r[ 5]<(M3D_FLOAT)1e-7) r[ 5]=(M3D_FLOAT)0.0;
|
r[ 5] = 1 - 2 * (q->x * q->x + q->z * q->z); if(r[ 5]>-M3D_EPSILON && r[ 5]<M3D_EPSILON) r[ 5]=(M3D_FLOAT)0.0;
|
||||||
r[ 6] = 2 * (q->y * q->z - q->x * q->w); if(r[ 6]>(M3D_FLOAT)-1e-7 && r[ 6]<(M3D_FLOAT)1e-7) r[ 6]=(M3D_FLOAT)0.0;
|
r[ 6] = 2 * (q->y * q->z - q->x * q->w); if(r[ 6]>-M3D_EPSILON && r[ 6]<M3D_EPSILON) r[ 6]=(M3D_FLOAT)0.0;
|
||||||
r[ 8] = 2 * (q->x * q->z - q->y * q->w); if(r[ 8]>(M3D_FLOAT)-1e-7 && r[ 8]<(M3D_FLOAT)1e-7) r[ 8]=(M3D_FLOAT)0.0;
|
r[ 8] = 2 * (q->x * q->z - q->y * q->w); if(r[ 8]>-M3D_EPSILON && r[ 8]<M3D_EPSILON) r[ 8]=(M3D_FLOAT)0.0;
|
||||||
r[ 9] = 2 * (q->y * q->z + q->x * q->w); if(r[ 9]>(M3D_FLOAT)-1e-7 && r[ 9]<(M3D_FLOAT)1e-7) r[ 9]=(M3D_FLOAT)0.0;
|
r[ 9] = 2 * (q->y * q->z + q->x * q->w); if(r[ 9]>-M3D_EPSILON && r[ 9]<M3D_EPSILON) r[ 9]=(M3D_FLOAT)0.0;
|
||||||
r[10] = 1 - 2 * (q->x * q->x + q->y * q->y); if(r[10]>(M3D_FLOAT)-1e-7 && r[10]<(M3D_FLOAT)1e-7) r[10]=(M3D_FLOAT)0.0;
|
r[10] = 1 - 2 * (q->x * q->x + q->y * q->y); if(r[10]>-M3D_EPSILON && r[10]<M3D_EPSILON) r[10]=(M3D_FLOAT)0.0;
|
||||||
}
|
}
|
||||||
r[ 3] = p->x; r[ 7] = p->y; r[11] = p->z;
|
r[ 3] = p->x; r[ 7] = p->y; r[11] = p->z;
|
||||||
r[12] = 0; r[13] = 0; r[14] = 0; r[15] = 1;
|
r[12] = 0; r[13] = 0; r[14] = 0; r[15] = 1;
|
||||||
|
|
|
@ -118,6 +118,7 @@ SET( IMPORTERS
|
||||||
unit/utColladaImportExport.cpp
|
unit/utColladaImportExport.cpp
|
||||||
unit/utCSMImportExport.cpp
|
unit/utCSMImportExport.cpp
|
||||||
unit/utB3DImportExport.cpp
|
unit/utB3DImportExport.cpp
|
||||||
|
unit/utM3DImportExport.cpp
|
||||||
unit/utMDCImportExport.cpp
|
unit/utMDCImportExport.cpp
|
||||||
unit/utAssbinImportExport.cpp
|
unit/utAssbinImportExport.cpp
|
||||||
unit/ImportExport/utAssjsonImportExport.cpp
|
unit/ImportExport/utAssjsonImportExport.cpp
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
Model 3D Samples
|
|
||||||
================
|
|
||||||
|
|
||||||
aliveai_character.m3d - from Minetest aliveai mod (textures, animations, original 47k, m3d 2.5k)
|
|
||||||
cube.m3d - smallest possible example, 119 bytes only
|
|
||||||
cube_normals.m3d - cube with normal vectors, 159 bytes
|
|
||||||
cube_usemtl.m3d - converted from Assimp sample OBJ by the same name, cube with materials
|
|
||||||
cube_with_vertexcolors.m3d - converted from Assimp sample OBJ by the same name, cube with vertex colors
|
|
||||||
cube_with_vertexcolors.a3d - same, but saved in ASCII variant with Windows line endings (\r\n)
|
|
||||||
mobs_dwarves_character.m3d - from Minetest mobs_dwarves mod (with Assimp artifacts converted perfectly too...)
|
|
||||||
suzanne.m3d - exported from Blender (monkey face, with normals and texture UVs and materials)
|
|
||||||
WusonBlitz0.m3d - from Assimp sample by the same name (was 87k, triangle mesh) with int8 coordinates, minor quality degradation
|
|
||||||
WusonBlitz1.m3d - same, but uses int16 coordinates (no noticable difference to the original, but just 35k)
|
|
||||||
WusonBlitz2.m3d - same, but with 32 bit floating point numbers (same precision as the original, half the file size, 42k)
|
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
Open Asset Import Library (assimp)
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2006-2019, 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 "SceneDiffer.h"
|
||||||
|
#include "AbstractImportExportBase.h"
|
||||||
|
|
||||||
|
#include <assimp/Importer.hpp>
|
||||||
|
#include <assimp/postprocess.h>
|
||||||
|
|
||||||
|
using namespace Assimp;
|
||||||
|
|
||||||
|
class utM3DImportExport : public AbstractImportExportBase {
|
||||||
|
public:
|
||||||
|
virtual bool importerTest() {
|
||||||
|
Assimp::Importer importer;
|
||||||
|
const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/M3D/WusonBlitz0.m3d", aiProcess_ValidateDataStructure );
|
||||||
|
#ifndef ASSIMP_BUILD_NO_M3D_IMPORTER
|
||||||
|
return nullptr != scene;
|
||||||
|
#else
|
||||||
|
return nullptr == scene;
|
||||||
|
#endif // ASSIMP_BUILD_NO_M3D_IMPORTER
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F( utM3DImportExport, importM3DFromFileTest ) {
|
||||||
|
EXPECT_TRUE( importerTest() );
|
||||||
|
}
|
Loading…
Reference in New Issue