|
-
August 19th, 2010, 03:44 PM
#1
Construction issue
ModelLoader.h
Code:
//..................................
struct Mesh
{
unsigned int* indices;
float* vertices;
Matrix4x4 matrix;
unsigned int numVertex;
unsigned int numFace;
};
int loadNode(const aiScene* scene, aiNode* ptr, Mesh* mesh, unsigned int j =0);
class Scene
{
public:
Scene(const char* fileName);
public:
unsigned int numMesh;
Mesh* mesh;
};
ModelLoader.cpp
Code:
Scene::Scene(const char* fileName) : numMesh(0), mesh(0)
{
Assimp::Importer importer;
const aiScene* scene = importer.ReadFile( fileName,
aiProcess_CalcTangentSpace |
aiProcess_Triangulate |
aiProcess_JoinIdenticalVertices |
aiProcess_SortByPType);
numMesh = scene->mNumMeshes;
mesh = new Mesh[numMesh];
loadNode(scene, scene->mRootNode, mesh);
}
int loadNode(const aiScene* scene, aiNode* ptr, Mesh* mesh, unsigned int j)
{
unsigned int numMesh = ptr->mNumMeshes;
if(numMesh > 0)
{
Matrix4x4 tempMatrix;
Matrix4x4 parentMatrix;
for(unsigned int i = 0; i < numMesh; ++i)
{
unsigned int meshID = ptr->mMeshes[i];
mesh[j].numVertex = scene->mMeshes[meshID]->mNumVertices;
mesh[j].numFace = scene->mMeshes[meshID]->mNumFaces;
mesh[j].vertices = new float[3*mesh[j].numVertex];
mesh[j].indices = new unsigned int[3*mesh[j].numFace];
tempMatrix.setMatrix(ptr->mTransformation.a1, ptr->mTransformation.a2, ptr->mTransformation.a3, ptr->mTransformation.a4,
ptr->mTransformation.b1, ptr->mTransformation.b2, ptr->mTransformation.b3, ptr->mTransformation.b4,
ptr->mTransformation.c1, ptr->mTransformation.c2, ptr->mTransformation.c3, ptr->mTransformation.c4,
ptr->mTransformation.d1, ptr->mTransformation.d2, ptr->mTransformation.d3, ptr->mTransformation.d4);
aiNode* parentNode = ptr->mParent;
while(parentNode != NULL)
{
parentMatrix.setMatrix(parentNode->mTransformation.a1, parentNode->mTransformation.a2, parentNode->mTransformation.a3, parentNode->mTransformation.a4,
parentNode->mTransformation.b1, parentNode->mTransformation.b2, parentNode->mTransformation.b3, parentNode->mTransformation.b4,
parentNode->mTransformation.c1, parentNode->mTransformation.c2, parentNode->mTransformation.c3, parentNode->mTransformation.c4,
parentNode->mTransformation.d1, parentNode->mTransformation.d2, parentNode->mTransformation.d3, parentNode->mTransformation.d4);
tempMatrix = parentMatrix * tempMatrix;
parentNode = parentNode->mParent;
}
mesh[j].matrix = tempMatrix;
//Vertex datayı al
for(unsigned int i = 0; i < mesh[j].numVertex; ++i)
{
mesh[j].vertices[3*i] = scene->mMeshes[meshID]->mVertices[i].x;
mesh[j].vertices[3*i+1] = scene->mMeshes[meshID]->mVertices[i].y;
mesh[j].vertices[3*i+2] = scene->mMeshes[meshID]->mVertices[i].z;
}
//index datayı al
for(unsigned int i = 0; i < mesh[j].numFace; ++i)
{
mesh[j].indices[3*i] = scene->mMeshes[meshID]->mFaces[i].mIndices[0];
mesh[j].indices[3*i+1] = scene->mMeshes[meshID]->mFaces[i].mIndices[1];
mesh[j].indices[3*i+2] = scene->mMeshes[meshID]->mFaces[i].mIndices[2];
}
++j;
}
}
unsigned int numChild = ptr->mNumChildren;
if(numChild > 0)
{
aiNode** child = ptr->mChildren;
for(unsigned int i = 0; i < numChild; ++i)
{
loadNode(scene, child[i], mesh, j);
}
}
return 1;
}
Matrix4x4 class has attribution following
class Matrix4x4
{
public:
Matrix4x4(); // !!! make identity matrix
Matrix4x4(const float* arr);
Matrix4x4(const Matrix4x4& matrix1);
Matrix4x4(const Matrix3x3& matrix1);
...........................................
...........................................
Matrix4x4& operator=(const Matrix4x4& matrix1);
public:
float m[16];
};
i make matrix and mesh computing in recursive loadNode() function. when matrix comptuion done in loadNode(). i control each mesh's matrix in loadNode(). all matrix computing is OK. but if i control each mesh's matrix after loadNode() execution i get wrong matrix that is identity matrix. where is the problem. i apologize for my english
thanks in advance
Last edited by glsl09; August 20th, 2010 at 03:16 AM.
-
August 19th, 2010, 04:10 PM
#2
Re: Construction issue
You don't have constructor for Mesh, your number of mesh's is also doubtful for its zeroed value being assigned by the compiler. Constructor as its name says is meant to do something simple, inline initialization instead of complex code duplication
-
August 20th, 2010, 03:01 AM
#3
Re: Construction issue
i write construction for Mesh structure. only first object of Mesh structure is valid. rest have problem why
-
August 20th, 2010, 04:00 AM
#4
Re: Construction issue
 Originally Posted by glsl09
i write construction for Mesh structure. only first object of Mesh structure is valid. rest have problem why
Give us a full program that demonstrates the problem. A program that has the full class definitions, and a main() program that shows construction "not working".
Secondly, you have a lot of (too much) manual memory management going on. Why not use container classes such as std::vector instead of pointers and new[]/delete[]? This would simplify your program greatly, and probably would resolve whatever problem(s) you have. For example:
Code:
#include <vector>
//...
struct Mesh
{
std::vector<unsigned int> indices;
std::vector<float> vertices;
Matrix4x4 matrix;
};
class Scene
{
public:
Scene(const char* fileName);
public:
std::vector<Mesh> mesh;
};
Scene::Scene(const char* fileName) : numMesh(0), mesh(0)
{
Assimp::Importer importer;
const aiScene* scene = importer.ReadFile( fileName,
aiProcess_CalcTangentSpace |
aiProcess_Triangulate |
aiProcess_JoinIdenticalVertices |
aiProcess_SortByPType);
int numMesh = scene->mNumMeshes;
mesh.resize(numMesh);
loadNode(scene, scene->mRootNode, mesh);
}
loadNode(const aiScene* scene, aiNode* ptr, std::vector<Mesh>& mesh, unsigned int j)
{
unsigned int numMesh = ptr->mNumMeshes;
if(numMesh > 0)
{
Matrix4x4 tempMatrix;
Matrix4x4 parentMatrix;
for(unsigned int i = 0; i < numMesh; ++i)
{
unsigned int meshID = ptr->mMeshes[i];
mesh[j].numVertex = scene->mMeshes[meshID]->mNumVertices;
mesh[j].numFace = scene->mMeshes[meshID]->mNumFaces;
mesh[j].vertices.resize(3*mesh[j].numVertex);
mesh[j].indices.resize(3*mesh[j].numFace);
//...
}
//...
}
}
Not one call to "new:" or "delete". And please post your entire Matrix4x4 class, not bits and pieces.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; August 20th, 2010 at 04:10 AM.
-
August 20th, 2010, 06:35 AM
#5
Re: Construction issue
 Originally Posted by Pocoya
You don't have constructor for Mesh
To add to that, there is also no copy constructor or assignment operator (required by classes that manage their own memory) which makes the class uncopyable, or more correctly, will cause nasty bugs when it gets copied.
Use Paul's suggestion of using std::vector and the problem will go away.
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
August 20th, 2010, 07:59 AM
#6
Re: Construction issue
Can I ask why you are using a c string to pass the file name?
I also don't see any destructors, so I'm guessing that your program leaks memory.
-
August 20th, 2010, 02:17 PM
#7
Re: Construction issue
thank you all for replys. i changed class declaration and definiton the way you said.
/////// Matrix4x4.h
Code:
ifndef matrix4x4
#define matrix4x4
class Vector2D;
class Vector3D;
class Vector4D;
class Matrix3x3;
class Matrix4x4
{
public:
Matrix4x4();
Matrix4x4(const float* arr);
Matrix4x4(const Matrix4x4& matrix1);
Matrix4x4(const Matrix3x3& matrix1);
Matrix4x4(const Vector4D& v1, const Vector4D& v2, const Vector4D& v3, const Vector4D& v4);
void setColumnMatrix(const Vector4D& v1, const Vector4D& v2, const Vector4D& v3, const Vector4D& v4);
Matrix4x4& operator=(const Matrix4x4& matrix1);
friend Matrix4x4 operator*(const Matrix4x4& matrix1, const Matrix4x4& matrix2);
void print();
public:
float m[16];
};
/////// Matrix4x4.cpp
Code:
Matrix4x4::Matrix4x4()
{
m[0] = 1.0f; m[4] = 0.0f; m[8] = 0.0f; m[12] = 0.0f;
m[1] = 0.0f; m[5] = 1.0f; m[9] = 0.0f; m[13] = 0.0f;
m[2] = 0.0f; m[6] = 0.0f; m[10] = 1.0f; m[14] = 0.0f;
m[3] = 0.0f; m[7] = 0.0f; m[11] = 0.0f; m[15] = 1.0f;
}
Matrix4x4::Matrix4x4(const float* arr)
{
for(int i=0; i<16; ++i)
m[i] = arr[i];
}
Matrix4x4::Matrix4x4(const Matrix4x4& matrix4)
{
for(int i=0; i<16; ++i)
m[i] = matrix4.m[i];
}
Matrix4x4::Matrix4x4(const Matrix3x3& matrix1)
{
m[0] = matrix1.m[0];
m[1] = matrix1.m[1];
m[2] = matrix1.m[2];
m[3] = 0.0f;
m[4] = matrix1.m[3];
m[5] = matrix1.m[4];
m[6] = matrix1.m[5];
m[7] = 0.0f;
m[8] = matrix1.m[6];
m[9] = matrix1.m[7];
m[10] = matrix1.m[8];
m[11] = 0.0f;
m[12] = 0.0f;
m[13] = 0.0f;
m[14] = 0.0f;
m[15] = 1.0f;
}
Matrix4x4::Matrix4x4(const Vector4D& v1, const Vector4D& v2, const Vector4D& v3, const Vector4D& v4)
{
m[0] = v1.x; m[1] = v1.y; m[2] = v1.z; m[3] = v1.w;
m[4] = v2.x; m[5] = v2.y; m[6] = v2.z; m[7] = v2.w;
m[8] = v3.x; m[9] = v3.y; m[10] = v3.z; m[11] = v3.w;
m[12] = 0.0f; m[13] = 0.0f; m[14] = 0.0f; m[15] = v4.w;
}
void Matrix4x4::setColumnMatrix(const Vector4D& v1, const Vector4D& v2, const Vector4D& v3, const Vector4D& v4)
{
m[0] = v1.x; m[1] = v1.y; m[2] = v1.z; m[3] = v1.w;
m[4] = v2.x; m[5] = v2.y; m[6] = v2.z; m[7] = v2.w;
m[8] = v3.x; m[9] = v3.y; m[10] = v3.z; m[11] = v3.w;
m[12] = v4.x; m[13] = v4.y; m[14] = v4.z; m[15] = v4.w;
}
Matrix4x4& Matrix4x4::operator =(const Matrix4x4& matrix1)
{
if(this == &matrix1)
return *this;
m[0] = matrix1.m[0];
m[1] = matrix1.m[1];
m[2] = matrix1.m[2];
m[3] = matrix1.m[3];
m[4] = matrix1.m[4];
m[5] = matrix1.m[5];
m[6] = matrix1.m[6];
m[7] = matrix1.m[7];
m[8] = matrix1.m[8];
m[9] = matrix1.m[9];
m[10] = matrix1.m[10];
m[11] = matrix1.m[11];
m[12] = matrix1.m[12];
m[13] = matrix1.m[13];
m[14] = matrix1.m[14];
m[15] = matrix1.m[15];
return *this;
}
Matrix4x4 operator*(const Matrix4x4& m1, const Matrix4x4& m2)
{
Matrix4x4 temp;
temp.m[0] = m1.m[0]*m2.m[0] + m1.m[4]*m2.m[1] + m1.m[8]*m2.m[2] + m1.m[12]*m2.m[3];
temp.m[1] = m1.m[1]*m2.m[0] + m1.m[5]*m2.m[1] + m1.m[9]*m2.m[2] + m1.m[13]*m2.m[3];
temp.m[2] = m1.m[2]*m2.m[0] + m1.m[6]*m2.m[1] + m1.m[10]*m2.m[2] + m1.m[14]*m2.m[3];
temp.m[3] = m1.m[3]*m2.m[0] + m1.m[7]*m2.m[1] + m1.m[11]*m2.m[2] + m1.m[15]*m2.m[3];
temp.m[4] = m1.m[0]*m2.m[4] + m1.m[4]*m2.m[5] + m1.m[8]*m2.m[6] + m1.m[12]*m2.m[7];
temp.m[5] = m1.m[1]*m2.m[4] + m1.m[5]*m2.m[5] + m1.m[9]*m2.m[6] + m1.m[13]*m2.m[7];
temp.m[6] = m1.m[2]*m2.m[4] + m1.m[6]*m2.m[5] + m1.m[10]*m2.m[6] + m1.m[14]*m2.m[7];
temp.m[7] = m1.m[3]*m2.m[4] + m1.m[7]*m2.m[5] + m1.m[11]*m2.m[6] + m1.m[15]*m2.m[7];
temp.m[8] = m1.m[0]*m2.m[8] + m1.m[4]*m2.m[9] + m1.m[8]*m2.m[10] + m1.m[12]*m2.m[11];
temp.m[9] = m1.m[1]*m2.m[8] + m1.m[5]*m2.m[9] + m1.m[9]*m2.m[10] + m1.m[13]*m2.m[11];
temp.m[10] = m1.m[2]*m2.m[8] + m1.m[6]*m2.m[9] + m1.m[10]*m2.m[10] + m1.m[14]*m2.m[11];
temp.m[11] = m1.m[3]*m2.m[8] + m1.m[7]*m2.m[9] + m1.m[11]*m2.m[10] + m1.m[15]*m2.m[11];
temp.m[12] = m1.m[0]*m2.m[12] + m1.m[4]*m2.m[13] + m1.m[8]*m2.m[14] + m1.m[12]*m2.m[15];
temp.m[13] = m1.m[1]*m2.m[12] + m1.m[5]*m2.m[13] + m1.m[9]*m2.m[14] + m1.m[13]*m2.m[15];
temp.m[14] = m1.m[2]*m2.m[12] + m1.m[6]*m2.m[13] + m1.m[10]*m2.m[14] + m1.m[14]*m2.m[15];
temp.m[15] = m1.m[3]*m2.m[12] + m1.m[7]*m2.m[13] + m1.m[11]*m2.m[14] + m1.m[15]*m2.m[15];
return temp;
}
#endif
//// ModelLoader.h
Code:
#ifndef ModelLoader
#define ModelLoader
#include <assimp.hpp>
#include <aiScene.h>
#include <aiPostProcess.h>
#include "Matematik.h"
#include <vector>
#include <string>
using namespace std;
class Mesh
{
public:
Mesh();
public:
vector<unsigned int> indices;
vector<float> vertices;
Matrix4x4 matrix;
};
int loadNode(const aiScene* scene, aiNode* ptr, vector<Mesh>& mesh, unsigned int j =0);
class Scene
{
public:
Scene();
void load(string fileName);
public:
vector<Mesh> mesh;
};
#endif
///// ModelLoader.cpp
Code:
#include "ModelLoader.h"
#include <iostream>
using namespace std;
int loadNode(const aiScene* scene, aiNode* ptr, vector<Mesh>& mesh, unsigned int j)
{
unsigned int numMesh = ptr->mNumMeshes;
if(numMesh > 0)
{
Matrix4x4 tempMatrix;
Matrix4x4 parentMatrix;
for(unsigned int i = 0; i < numMesh; ++i)
{
unsigned int meshID = ptr->mMeshes[i];
mesh[j].vertices.resize(3*(scene->mMeshes[meshID]->mNumVertices));
mesh[j].indices.resize(3*(scene->mMeshes[meshID]->mNumFaces));
tempMatrix.setColumnMatrix(Vector4D(ptr->mTransformation.a1, ptr->mTransformation.a2, ptr->mTransformation.a3, ptr->mTransformation.a4),
Vector4D(ptr->mTransformation.b1, ptr->mTransformation.b2, ptr->mTransformation.b3, ptr->mTransformation.b4),
Vector4D(ptr->mTransformation.c1, ptr->mTransformation.c2, ptr->mTransformation.c3, ptr->mTransformation.c4),
Vector4D(ptr->mTransformation.d1, ptr->mTransformation.d2, ptr->mTransformation.d3, ptr->mTransformation.d4));
aiNode* parentNode = ptr->mParent;
while(parentNode != NULL)
{
parentMatrix.setColumnMatrix(Vector4D(parentNode->mTransformation.a1, parentNode->mTransformation.a2, parentNode->mTransformation.a3, parentNode->mTransformation.a4),
Vector4D(parentNode->mTransformation.b1, parentNode->mTransformation.b2, parentNode->mTransformation.b3, parentNode->mTransformation.b4),
Vector4D(parentNode->mTransformation.c1, parentNode->mTransformation.c2, parentNode->mTransformation.c3, parentNode->mTransformation.c4),
Vector4D(parentNode->mTransformation.d1, parentNode->mTransformation.d2, parentNode->mTransformation.d3, parentNode->mTransformation.d4));
tempMatrix = parentMatrix * tempMatrix;
parentNode = parentNode->mParent;
}
mesh[j].matrix = tempMatrix;
// this matrix value is different after loadNode() function execution done
//problem here
mesh[i].matrix.print();
unsigned int numVertices = scene->mMeshes[meshID]->mNumVertices;
for(unsigned int i = 0; i < numVertices; ++i)
{
mesh[j].vertices.push_back(scene->mMeshes[meshID]->mVertices[i].x);
mesh[j].vertices.push_back(scene->mMeshes[meshID]->mVertices[i].y);
mesh[j].vertices.push_back(scene->mMeshes[meshID]->mVertices[i].z);
}
unsigned int numFace = scene->mMeshes[meshID]->mNumFaces;
for(unsigned int i = 0; i < numFace; ++i)
{
mesh[j].indices.push_back(scene->mMeshes[meshID]->mFaces[i].mIndices[0]);
mesh[j].indices.push_back(scene->mMeshes[meshID]->mFaces[i].mIndices[1]);
mesh[j].indices.push_back(scene->mMeshes[meshID]->mFaces[i].mIndices[2]);
}
++j;
}
}
unsigned int numChild = ptr->mNumChildren;
if(numChild > 0)
{
aiNode** child = ptr->mChildren;
for(unsigned int i = 0; i < numChild; ++i)
{
loadNode(scene, child[i], mesh, j);
}
}
return 1;
}
Mesh::Mesh()
{
}
Scene::Scene()
{
}
void Scene::load(string fileName)
{
Assimp::Importer importer;
const aiScene* scene = importer.ReadFile( fileName,
aiProcess_CalcTangentSpace |
aiProcess_Triangulate |
aiProcess_JoinIdenticalVertices |
aiProcess_SortByPType);
unsigned int numMesh = scene->mNumMeshes;
mesh.resize(numMesh);
loadNode(scene, scene->mRootNode, mesh);
// here shows all mesh' s matrix value is identity why
//for(unsigned int i=0; i<numMesh; ++i)
// mesh[i].matrix.print();
}
i apologize to you. the code is too long. it is working without problem. but i want to learn why each mesh's matrix element is identity matrix after execution loadNode() function. i marked the problem with comment line on the code. thanks.
have a good evening
-
August 20th, 2010, 02:37 PM
#8
Re: Construction issue
 Originally Posted by glsl09
thank you all for replys. i changed class declaration and definiton the way you said.
You didn't show us a main() program. A class doesn't just live by itself -- it must be used in the flow of a program, and we would like to see a simple program that uses this class that duplicates the error.
Secondly, a lot of that code could be removed very easily. You are writing assignment operators and copy constructors when they need not be written.
For example Matrix4(const Matrix4&) need not be written, as the compiler's version will suffice.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; August 20th, 2010 at 02:45 PM.
-
August 20th, 2010, 02:42 PM
#9
Re: Construction issue
 Originally Posted by glsl09
it is working without problem.
This two line program will have your class failing:
Code:
int main()
{
float myarray[3] = {0};
Matrix4x4 test( myarray );
}
You have no test to see if there are really 16 items available in the array.
Your code would not pass a test of being very safe or secure. A usage of containers rids you of these bugs.
Regards,
Paul McKenzie
-
August 20th, 2010, 03:44 PM
#10
Re: Construction issue
i use Assimp library to load my model. yes you are right my matrix class is not too safe.
only i want to control if i fill each mesh's member correctly or not.
Code:
#include "ModelLoader.h"
#include <iostream>
using namespace std;
int main()
{
char ch;
Scene model;
model.load("cart_wheel.3DS");
for(unsigned int i=0; i<model.mesh.size(); ++i)
cout<<model.mesh[i].vertices.size()<<endl;
/********************SCREEN OUTPUT*******************
// 3072
// 0
// 0
// 0
// 0
// 0
// 0
// 0
// 0
// 0
// 0
// 0
// 0
/*******************************************************
cin>>ch;
}
in the main.cpp if i control each mesh's vertices size it shows 0 . also compiler gives no error or warning. if i control mesh's vertices size just in loadNode() function it shows all member of mesh is filled correctly.
// LoaderModel.cpp ................... Full definition of loadNode()
Code:
int loadNode(const aiScene* scene, aiNode* ptr, vector<Mesh>& mesh, unsigned int j)
{
unsigned int numMesh = ptr->mNumMeshes;
if(numMesh > 0)
{
Matrix4x4 tempMatrix;
Matrix4x4 parentMatrix;
for(unsigned int i = 0; i < numMesh; ++i)
{
unsigned int meshID = ptr->mMeshes[i];
mesh[j].vertices.resize(3*(scene->mMeshes[meshID]->mNumVertices));
mesh[j].indices.resize(3*(scene->mMeshes[meshID]->mNumFaces));
tempMatrix.setColumnMatrix(Vector4D(ptr->mTransformation.a1, ptr->mTransformation.a2, ptr->mTransformation.a3, ptr->mTransformation.a4),
Vector4D(ptr->mTransformation.b1, ptr->mTransformation.b2, ptr->mTransformation.b3, ptr->mTransformation.b4),
Vector4D(ptr->mTransformation.c1, ptr->mTransformation.c2, ptr->mTransformation.c3, ptr->mTransformation.c4),
Vector4D(ptr->mTransformation.d1, ptr->mTransformation.d2, ptr->mTransformation.d3, ptr->mTransformation.d4));
aiNode* parentNode = ptr->mParent;
while(parentNode != NULL)
{
parentMatrix.setColumnMatrix(Vector4D(parentNode->mTransformation.a1, parentNode->mTransformation.a2, parentNode->mTransformation.a3, parentNode->mTransformation.a4),
Vector4D(parentNode->mTransformation.b1, parentNode->mTransformation.b2, parentNode->mTransformation.b3, parentNode->mTransformation.b4),
Vector4D(parentNode->mTransformation.c1, parentNode->mTransformation.c2, parentNode->mTransformation.c3, parentNode->mTransformation.c4),
Vector4D(parentNode->mTransformation.d1, parentNode->mTransformation.d2, parentNode->mTransformation.d3, parentNode->mTransformation.d4));
tempMatrix = parentMatrix * tempMatrix;
parentNode = parentNode->mParent;
}
mesh[j].matrix = tempMatrix;
//Vertex datayı al
unsigned int numVertices = scene->mMeshes[meshID]->mNumVertices;
for(unsigned int i = 0; i < numVertices; ++i)
{
mesh[j].vertices.push_back(scene->mMeshes[meshID]->mVertices[i].x);
mesh[j].vertices.push_back(scene->mMeshes[meshID]->mVertices[i].y);
mesh[j].vertices.push_back(scene->mMeshes[meshID]->mVertices[i].z);
}
//index datayı al
unsigned int numFace = scene->mMeshes[meshID]->mNumFaces;
for(unsigned int i = 0; i < numFace; ++i)
{
mesh[j].indices.push_back(scene->mMeshes[meshID]->mFaces[i].mIndices[0]);
mesh[j].indices.push_back(scene->mMeshes[meshID]->mFaces[i].mIndices[1]);
mesh[j].indices.push_back(scene->mMeshes[meshID]->mFaces[i].mIndices[2]);
}
++j;
}
// if i control all mesh in turn
// mesh's vertices is filled correctly here
cout<<mesh[j-1].vertices.size()<<endl;
// some number is the same because model only has distinct 4 mesh.
/********************SCREEN OUTPUT*******************
// 1536
// 144
// 144
// 144
// 144
// 144
// 144
// 144
// 144
// 144
// 144
// 3072
// 3072
/*******************************************************
}
unsigned int numChild = ptr->mNumChildren;
if(numChild > 0)
{
aiNode** child = ptr->mChildren;
for(unsigned int i = 0; i < numChild; ++i)
{
loadNode(scene, child[i], mesh, j);
}
}
return 1;
}
i would like to know where i make mistake. thanks you Paul McKenzie for your replys
Last edited by glsl09; August 20th, 2010 at 03:46 PM.
-
August 20th, 2010, 03:53 PM
#11
Re: Construction issue
 Originally Posted by glsl09
i use Assimp library to load my model. yes you are right my matrix class is not too safe.
only i want to control if i fill each mesh's member correctly or not.
Before going any further, are you using a debugger? You can't write all of this code and not use a debugger to solve programming issues.
Regards,
Paul McKenzie
-
August 20th, 2010, 04:48 PM
#12
Re: Construction issue
problem arises from default parameter of loadNode() function. j is always 0. i removed default j variable and made it as static int j =0 begining of the function. problem is now solved. also i changed assign of mesh's member vertices and indices following.
Code:
//Vertex datayı al
unsigned int numVertices = scene->mMeshes[meshID]->mNumVertices;
for(unsigned int i = 0; i < numVertices; ++i)
{
mesh[j].vertices[3*i] = scene->mMeshes[meshID]->mVertices[i].x;
mesh[j].vertices[3*i+1] = scene->mMeshes[meshID]->mVertices[i].y;
mesh[j].vertices[3*i+2] = scene->mMeshes[meshID]->mVertices[i].z;
}
//index datayı al
unsigned int numFace = scene->mMeshes[meshID]->mNumFaces;
for(unsigned int i = 0; i < numFace; ++i)
{
mesh[j].indices[3*i] = scene->mMeshes[meshID]->mFaces[i].mIndices[0];
mesh[j].indices[3*i+1] = scene->mMeshes[meshID]->mFaces[i].mIndices[1];
mesh[j].indices[3*i+2] = scene->mMeshes[meshID]->mFaces[i].mIndices[2];
}
Thanks you.
-
August 20th, 2010, 04:49 PM
#13
Re: Construction issue
problem arises from default parameter of loadNode() function. j is always 0. i removed default j variable and made it as static int j =0 begining of the function. problem is now solved. also i changed assign of mesh's member vertices and indices following.
/// LoaderModel.cpp ..........definition of loadNoe()
Code:
//Vertex datayı al
unsigned int numVertices = scene->mMeshes[meshID]->mNumVertices;
for(unsigned int i = 0; i < numVertices; ++i)
{
mesh[j].vertices[3*i] = scene->mMeshes[meshID]->mVertices[i].x;
mesh[j].vertices[3*i+1] = scene->mMeshes[meshID]->mVertices[i].y;
mesh[j].vertices[3*i+2] = scene->mMeshes[meshID]->mVertices[i].z;
}
//index datayı al
unsigned int numFace = scene->mMeshes[meshID]->mNumFaces;
for(unsigned int i = 0; i < numFace; ++i)
{
mesh[j].indices[3*i] = scene->mMeshes[meshID]->mFaces[i].mIndices[0];
mesh[j].indices[3*i+1] = scene->mMeshes[meshID]->mFaces[i].mIndices[1];
mesh[j].indices[3*i+2] = scene->mMeshes[meshID]->mFaces[i].mIndices[2];
}
Thanks you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|