home *** CD-ROM | disk | FTP | other *** search
- #include "Mesh.h"
-
- //#include "Ac3dLoader.h"
- #include "log.h"
- #include "vectormath.h"
- #include "matrixmath.h"
- //#include "light.h"
- #include <stdlib.h>
-
- #include "Renderer.h"
- #include "RendererInfo.h"
-
-
- Mesh::Mesh(){
- name="uninitialized";
- parent=NULL;
- childs=NULL;
- numChilds=0;
-
- vertices=NULL;
- colors=NULL;
- secondaryColors=NULL;
- normals=NULL;
- texCoords1=NULL;
- texCoords2=NULL;
- indices=NULL;
- numVertices=0;
- numColors=0;
- numSecondaryColors=0;
- numNormals=0;
- numTexCoords=0;
- numIndices=0;
-
- vertexVBOName = 0;
- colorVBOName = 0;
- secondaryColorVBOName = 0;
- normalVBOName = 0;
- texCoord1VBOName = 0;
- texCoord2VBOName = 0;
- indexVBOName = 0;
-
- faces=NULL;
- materials=NULL;
- numFaces=0;
- numMaterials=0;
-
- matrixCopy(id4x4, transformationMatrix, 4);
-
- renderMode=MESH_RENDER_MODE_DO_NOT_RENDER;
- isTriangulation=false;
- hasTransparentFaces=false;
- hasLightmapsForAllFaces=false;
- hasSecondMappingChannel=false;
-
- //transformationMatrix;
-
- // for(int i=0;i<MESH_MAX_DYNAMIC_LIGHTS;i++){
- // dynamicLightParticleClusters[i]=NULL;
- // }
-
- }
-
- Mesh::Mesh(File* f, Model* model){
- name="uninitialized";
- parent=NULL;
- childs=NULL;
- numChilds=0;
-
- vertices=NULL;
- colors=NULL;
- secondaryColors=NULL;
- normals=NULL;
- texCoords1=NULL;
- texCoords2=NULL;
- indices=NULL;
- numVertices=0;
- numColors=0;
- numSecondaryColors=0;
- numNormals=0;
- numTexCoords=0;
- numIndices=0;
-
- vertexVBOName = 0;
- colorVBOName = 0;
- secondaryColorVBOName = 0;
- normalVBOName = 0;
- texCoord1VBOName = 0;
- texCoord2VBOName = 0;
- indexVBOName = 0;
-
- faces=NULL;
- materials=NULL;
- numFaces=0;
- numMaterials=0;
-
- matrixCopy(id4x4, transformationMatrix, 4);
-
- renderMode=MESH_RENDER_MODE_DO_NOT_RENDER;
- isTriangulation=false;
- hasTransparentFaces=false;
- hasLightmapsForAllFaces=false;
- hasSecondMappingChannel=false;
-
- //transformationMatrix;
-
- // for(int i=0;i<MESH_MAX_DYNAMIC_LIGHTS;i++){
- // dynamicLightParticleClusters[i]=NULL;
- // }
-
- if( !readFromFile(f, model) )
- error("(in Mesh::Mesh()): readFromFile() returned false.\n\n");
-
- }
-
- Mesh::~Mesh(){
- clearMesh();
- }
-
- void Mesh::clearMesh(){
- int i;
-
- if(vertices!=NULL){
- delete[] vertices;
- vertices=NULL;
- numVertices=0;
- }
- if(colors!=NULL){
- delete[] colors;
- colors=NULL;
- numColors=0;
- }
- if(secondaryColors!=NULL){
- delete[] secondaryColors;
- secondaryColors=NULL;
- numSecondaryColors=0;
- }
- if(normals!=NULL){
- delete[] normals;
- normals=NULL;
- numNormals=0;
- }
- if(texCoords1!=NULL || texCoords2!=NULL){ // THINKABOUTME: bisserl gefΣhrlich das zusammenzulegen...
- delete[] texCoords1;
- texCoords1=NULL;
- delete[] texCoords2;
- texCoords2=NULL;
- numTexCoords=0;
- }
- if(indices!=NULL){
- delete[] indices;
- indices=NULL;
- numIndices=0;
- }
-
- freeVBOs();
-
- //THINKABOUTME: wirklich alles l÷schen?? - mats k÷nne auch von anderen meshes noch verwendet werden!!
-
- if(materials!=NULL){
- for(i=0;i<numMaterials;i++){
- // delete materials[i]; // siehe oben!!
- }
- delete[] materials;
- materials=NULL;
- numMaterials=0;
- }
-
- if(faces!=NULL){
- for(i=0;i<numFaces;i++){
- delete faces[i];
- }
- delete[] faces;
- faces=NULL;
- numFaces=0;
- }
-
-
- renderMode=MESH_RENDER_MODE_DO_NOT_RENDER;
- isTriangulation=false;
- hasTransparentFaces=false;
- hasLightmapsForAllFaces=false;
-
- // for(i=0;i<MESH_MAX_DYNAMIC_LIGHTS;i++){
- // dynamicLightParticleClusters[i] = NULL;
- // }
- //transformationMatrix;
- }
-
- int Mesh::addMaterial(Material* mat){
- int i;
-
- for(i=0;i<numMaterials;i++){
- if(materials[i]==mat)
- return i;
- }
-
- numMaterials++;
- Material** newMat=new Material*[numMaterials];
- for(i=0;i<numMaterials-1;i++)
- newMat[i]=materials[i];
-
- newMat[numMaterials-1]=mat;
- delete[] materials;
- materials=newMat;
-
- return numMaterials-1;
- }
-
-
- int Mesh::addArrayElement(GLfloat v[3], GLfloat c[3], GLfloat n[3], GLfloat t1[2], GLfloat t2[2]){
- int i;
-
- // _ASSERTE(numVertices==numNormals==numTexCoords);
- for(i=0;i<numVertices;i++){
- if(vectorEqual3d(&vertices[i*3], v) && vectorEqual3d(&colors[i*3], c) && vectorEqual3d(&normals[i*3], n)
- && vectorEqual2d(&texCoords1[i*2], t1) && vectorEqual2d(&texCoords2[i*2], t2) ){
- return i;
- }
- }
-
- // add vertex
- numVertices++;
- GLfloat* newV=new GLfloat[numVertices*3];
- for(i=0;i<numVertices*3-3;i++){
- newV[i]=vertices[i];
- }
- newV[numVertices*3-3]=v[0];
- newV[numVertices*3-2]=v[1];
- newV[numVertices*3-1]=v[2];
-
- delete[] vertices;
- vertices=newV;
-
- // add color
- numColors++;
- GLfloat* newC=new GLfloat[numColors*3];
- for(i=0;i<numColors*3-3;i++){
- newC[i]=colors[i];
- }
- newC[numColors*3-3]=c[0];
- newC[numColors*3-2]=c[1];
- newC[numColors*3-1]=c[2];
-
- delete[] colors;
- colors=newC;
-
- // add normal
- numNormals++;
- GLfloat* newN=new GLfloat[numNormals*3];
- for(i=0;i<numNormals*3-3;i++){
- newN[i]=normals[i];
- }
- newN[numNormals*3-3]=n[0];
- newN[numNormals*3-2]=n[1];
- newN[numNormals*3-1]=n[2];
-
- delete[] normals;
- normals=newN;
-
- // add texCoord1
- numTexCoords++;
- GLfloat* newT1=new GLfloat[numTexCoords*2];
- for(i=0;i<numTexCoords*2-2;i++){
- newT1[i]=texCoords1[i];
- }
- newT1[numTexCoords*2-2]=t1[0];
- newT1[numTexCoords*2-1]=t1[1];
-
- delete[] texCoords1;
- texCoords1=newT1;
-
- // add texCoord2
- //numTexCoords++;
- GLfloat* newT2=new GLfloat[numTexCoords*2];
- for(i=0;i<numTexCoords*2-2;i++){
- newT2[i]=texCoords2[i];
- }
- newT2[numTexCoords*2-2]=t2[0];
- newT2[numTexCoords*2-1]=t2[1];
-
- delete[] texCoords2;
- texCoords2=newT2;
-
-
- // _ASSERTE(numVertices==numNormals==numTexCoords);
- return numVertices-1;
- }
-
- int Mesh::addFace(Face *face){
- int i;
- /*
- for(i=0;i<numFaces;i++){
- if(faces[i]==face)
- return i;
- }
- */
- numFaces++;
- Face** newF=new Face*[numFaces];
- for(i=0;i<numFaces-1;i++){
- newF[i]=faces[i];
- }
- newF[numFaces-1]=face;
-
-
- delete[] faces;
- faces=newF;
-
-
- // add Elements
- face->numIndices=face->numVertices;
- face->indices=new GLuint[face->numIndices];
- for(i=0;i<face->numIndices;i++){
- face->indices[i]=addArrayElement(&face->vertices[i*3], &face->colors[i*3], &face->normals[i*3], &face->texCoords1[i*2], &face->texCoords2[i*2]);
- }
- numIndices+=face->numIndices;
- GLuint* newInd=new GLuint[numIndices];
- for(i=0;i<numIndices-face->numIndices;i++){
- newInd[i]=indices[i];
- }
- for(i=numIndices-face->numIndices;i<numIndices;i++){
- newInd[i]=face->indices[i-(numIndices-face->numIndices)];
- }
- delete[] indices;
- indices=newInd;
-
- addMaterial(face->material);
- face->mesh=this;
-
- return numFaces-1;
- }
-
- int Mesh::addChild(Mesh* child){
- int i;
-
- numChilds++;
- Mesh** newChilds=new Mesh*[numChilds];
- for(i=0;i<numChilds-1;i++){
- newChilds[i]=childs[i];
- }
- newChilds[numChilds-1]=child;
-
-
- delete[] childs;
- childs=newChilds;
-
- child->parent=this;
-
- return numChilds-1;
- }
- /*
- void Mesh::addDynamicLightParticleCluster(DynamicLightParticleCluster* pc){
- for(int i=0;i<MESH_MAX_DYNAMIC_LIGHTS;i++){
- if(dynamicLightParticleClusters[i]==NULL){
- dynamicLightParticleClusters[i]=pc;
- return;
- }
- }
- // warn("(in Mesh::addDynamicLightmapParticleCluster()): Couldn't add particle cluster.\n\n");
- }
-
- void Mesh::removeDynamicLightParticleCluster(DynamicLightParticleCluster* pc){
- for(int i=0;i<MESH_MAX_DYNAMIC_LIGHTS;i++){
- if(dynamicLightParticleClusters[i]==pc){
- dynamicLightParticleClusters[i]=NULL;
- // return;
- }
- }
- //warn("(in Mesh::addDynamicLightmapParticleCluster()): Couldn't add particle cluster.\n\n");
- }
- */
-
- void Mesh::setRenderMode(){
- int i;
- //renderMode=MESH_RENDER_MODE_TRIANGLE_ARRAY;
- //renderMode=MESH_RENDER_MODE_SINGLE_POLYGON;
- //renderMode=MESH_RENDER_MODE_SINGLE_TRIANGLE;
-
- hasTransparentFaces=false;
- isTriangulation=true;
- hasLightmapsForAllFaces=true;
- hasSecondMappingChannel=true;
-
- for(i=0;i<numMaterials;i++){
- if(materials[i]->isTransparent){
- hasTransparentFaces=true;
- }
- if(!materials[i]->hasLightmap){
- hasLightmapsForAllFaces=false;
- }
- if(materials[i]->shader!=NULL && materials[i]->shader->mapChannel2!=NULL){
- hasSecondMappingChannel=true;
- }
- }
-
- for(i=0;i<numFaces;i++){
- if(faces[i]->numVertices!=3)
- isTriangulation=false;
- // if(!(faces[i]->flags & FACE_FLAG_TWO_SIDED))
- // hasOnlyTwoSidedFaces=false;
- }
-
-
- // if(_glGenBuffersARB!=NULL && Renderer::info.var.useVBOs==true)
- // createVBOs();
-
-
- if(numMaterials==1 && !hasTransparentFaces && isTriangulation){
- renderMode=MESH_RENDER_MODE_TRIANGLE_ARRAY;
- return;
- }
- if(isTriangulation){
- renderMode=MESH_RENDER_MODE_SINGLE_TRIANGLE;
- return;
- }
- renderMode=MESH_RENDER_MODE_SINGLE_POLYGON;
-
- }
-
- void Mesh::createVBOs(){
-
- if(_glGenBuffersARB==NULL || Renderer::info.var.useVBOs==false)
- return;
-
- _glGenBuffersARB( 1, &vertexVBOName );
- _glBindBufferARB( GL_ARRAY_BUFFER_ARB, vertexVBOName );
- _glBufferDataARB( GL_ARRAY_BUFFER_ARB, numVertices*3*sizeof(float), vertices, GL_STATIC_DRAW_ARB );
- _glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0);
-
- _glGenBuffersARB( 1, &colorVBOName );
- _glBindBufferARB( GL_ARRAY_BUFFER_ARB, colorVBOName );
- _glBufferDataARB( GL_ARRAY_BUFFER_ARB, numColors*3*sizeof(float), colors, GL_STATIC_DRAW_ARB );
- _glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0);
-
- _glGenBuffersARB( 1, &secondaryColorVBOName );
- _glBindBufferARB( GL_ARRAY_BUFFER_ARB, secondaryColorVBOName );
- _glBufferDataARB( GL_ARRAY_BUFFER_ARB, numSecondaryColors*3*sizeof(float), colors, GL_STATIC_DRAW_ARB );
- _glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0);
-
- _glGenBuffersARB( 1, &normalVBOName );
- _glBindBufferARB( GL_ARRAY_BUFFER_ARB, normalVBOName );
- _glBufferDataARB( GL_ARRAY_BUFFER_ARB, numNormals*3*sizeof(float), normals, GL_STATIC_DRAW_ARB );
- _glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0);
-
- _glGenBuffersARB( 1, &texCoord1VBOName );
- _glBindBufferARB( GL_ARRAY_BUFFER_ARB, texCoord1VBOName );
- _glBufferDataARB( GL_ARRAY_BUFFER_ARB, numTexCoords*2*sizeof(float), texCoords1, GL_STATIC_DRAW_ARB );
- _glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0);
-
- _glGenBuffersARB( 1, &texCoord2VBOName );
- _glBindBufferARB( GL_ARRAY_BUFFER_ARB, texCoord2VBOName );
- _glBufferDataARB( GL_ARRAY_BUFFER_ARB, numTexCoords*2*sizeof(float), texCoords2, GL_STATIC_DRAW_ARB );
- _glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0);
-
- // _glGenBuffersARB( 1, &indexVBOName );
- // _glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, indexVBOName );
- // _glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, numIndices*sizeof(GLuint), indices, GL_STATIC_DRAW_ARB );
- // _glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
-
- // printf("VBO created. (Names: %d, %d, %d, %d, %d)\n", vertexVBOName, colorVBOName, normalVBOName, texCoord1VBOName, texCoord2VBOName);
- }
-
- void Mesh::freeVBOs(){
- if(vertexVBOName!=0){
- _glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertexVBOName);
- _glBufferDataARB(GL_ARRAY_BUFFER_ARB, 0, NULL, GL_STATIC_DRAW_ARB );
- _glDeleteBuffersARB(1, &vertexVBOName);
- _glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
- vertexVBOName=0;
- }
-
- if(colorVBOName!=0){
- _glBindBufferARB(GL_ARRAY_BUFFER_ARB, colorVBOName);
- _glBufferDataARB(GL_ARRAY_BUFFER_ARB, 0, NULL, GL_STATIC_DRAW_ARB );
- _glDeleteBuffersARB(1, &colorVBOName);
- _glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
- colorVBOName=0;
- }
-
- if(secondaryColorVBOName!=0){
- _glBindBufferARB(GL_ARRAY_BUFFER_ARB, secondaryColorVBOName);
- _glBufferDataARB(GL_ARRAY_BUFFER_ARB, 0, NULL, GL_STATIC_DRAW_ARB );
- _glDeleteBuffersARB(1, &secondaryColorVBOName);
- _glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
- secondaryColorVBOName=0;
- }
-
- if(normalVBOName!=0){
- _glBindBufferARB(GL_ARRAY_BUFFER_ARB, normalVBOName);
- _glBufferDataARB(GL_ARRAY_BUFFER_ARB, 0, NULL, GL_STATIC_DRAW_ARB );
- _glDeleteBuffersARB(1, &normalVBOName);
- _glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
- normalVBOName=0;
- }
-
- if(texCoord1VBOName!=0){
- _glBindBufferARB(GL_ARRAY_BUFFER_ARB, texCoord1VBOName);
- _glBufferDataARB(GL_ARRAY_BUFFER_ARB, 0, NULL, GL_STATIC_DRAW_ARB );
- _glDeleteBuffersARB(1, &texCoord1VBOName);
- _glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
- texCoord1VBOName=0;
- }
-
- if(texCoord2VBOName!=0){
- _glBindBufferARB(GL_ARRAY_BUFFER_ARB, texCoord2VBOName);
- _glBufferDataARB(GL_ARRAY_BUFFER_ARB, 0, NULL, GL_STATIC_DRAW_ARB );
- _glDeleteBuffersARB(1, &texCoord2VBOName);
- _glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
- texCoord2VBOName=0;
- }
-
- // if(indexVBOName!=0){
- // _glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indexVBOName);
- // _glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0, NULL, GL_STATIC_DRAW_ARB );
- // _glDeleteBuffersARB(1, &indexVBOName);
- // _glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
- // indexVBOName=0;
- // }
-
- }
-
- void Mesh::createSecondaryColors(){
- numSecondaryColors = numVertices;
- secondaryColors = new GLfloat[numSecondaryColors*3];
-
- for(int i=0;i<numSecondaryColors;i++){
- vectorInit3d(0.0f, 0.0f, 0.0f, &secondaryColors[i*3]);
- }
- }
-
- void Mesh::updateSecondaryColorVBO(){
- if(secondaryColorVBOName == 0 || _glBindBufferARB == NULL)
- return;
-
-
- _glBindBufferARB( GL_ARRAY_BUFFER_ARB, secondaryColorVBOName );
- _glBufferDataARB( GL_ARRAY_BUFFER_ARB, numSecondaryColors*3*sizeof(float), secondaryColors, GL_STATIC_DRAW_ARB );
- _glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0);
- }
-
- int Mesh::getMaterialId(Material* m){
- for(int i=0;i<numMaterials;i++){
- if(materials[i]==m)
- return i;
- }
- return -1;
- }
-
- void Mesh::swapFaces(int i, int j){
- Face* tmp=faces[i];
- faces[i]=faces[j];
- faces[j]=tmp;
- }
-
- void Mesh::sortFacesByMaterial(){
- for(int i=0;i<numFaces;i++){
- for(int j=i+1;j<numFaces;j++){
- if(getMaterialId(faces[i]->material) > getMaterialId(faces[j]->material)){
- swapFaces(i,j);
- }
- }
- }
- /*
- for(int k=0;k<numFaces-1;k++){
- if(getMaterialId(faces[k]->material)>getMaterialId(faces[k+1]->material))
- printf("ACHTUNG: k: %i; matID: %i\n", k, getMaterialId(faces[k]->material));
- }
- */
- }
-
-
- bool Mesh::readFromFile(File* f, Model* model){
- char buff[256];
- Tokenizer t(" =\t\n\r\"", "\"");
-
- while(f->readLine(256, buff, true) != -1){
-
- t.tokenize(buff);
-
- if(t.tokc==0)
- continue;
-
- if(streq(t.tokv[0], "TRANSFORMATION_MATRIX")){
- // sscanf(t.tokv[1], "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f"
- // , &m->transformationMatrix[0], &m->transformationMatrix[1], &m->transformationMatrix[2], &m->transformationMatrix[3]
- // , &m->transformationMatrix[4], &m->transformationMatrix[5], &m->transformationMatrix[6], &m->transformationMatrix[7]
- // , &m->transformationMatrix[8], &m->transformationMatrix[9], &m->transformationMatrix[10], &m->transformationMatrix[11]
- // , &m->transformationMatrix[12], &m->transformationMatrix[13], &m->transformationMatrix[14], &m->transformationMatrix[15]
- // );
- //printf("N: %i\n", n);
- }else if(streq(t.tokv[0], "MATERIAL")){
- this->numMaterials = 1;
- this->materials = new Material*[1];
- this->materials[0] = model->materials[atoi(t.tokv[1])];
-
- // printf("MAT: %i, hasTex %i, hasLM %i\n", atoi(t.tokv[1]), m->materials[0]->hasTexture, m->materials[0]->hasLightmap);
- }else if(streq(t.tokv[0], "NUM_VERTICES")){
- this->numVertices = this->numColors = this->numNormals = this->numTexCoords = atoi(t.tokv[1]);
- this->vertices=new float[this->numVertices*3];
- this->colors=new float[this->numColors*3];
- this->normals=new float[this->numNormals*3];
- this->texCoords1=new float[this->numTexCoords*2];
- this->texCoords2=new float[this->numTexCoords*2];
- }else if(streq(t.tokv[0], "VERTEX_LIST")){
- f->readLine(256, buff, true);
-
- //int n;
- for(int i=0;i<this->numVertices;i++){
- f->readLine(256, buff, true);
- /*
- sscanf(buff, "VERTEX %i: %f %f %f %f %f %f %f %f %f %f"
- , &n
- , &m->vertices[i*3+0], &m->vertices[i*3+1], &m->vertices[i*3+2]
- , &m->colors[i*3+0], &m->colors[i*3+1], &m->colors[i*3+2]
- , &m->texCoords1[i*2+0], &m->texCoords1[i*2+1]
- , &m->texCoords2[i*2+0], &m->texCoords2[i*2+1]);
- */
- Tokenizer t2(buff, " ", "");
- vectorInit3d((float)atof(t2.tokv[2]), (float)atof(t2.tokv[3]), (float)atof(t2.tokv[4]), &this->vertices[i*3]);
- vectorInit3d((float)atof(t2.tokv[5]), (float)atof(t2.tokv[6]), (float)atof(t2.tokv[7]), &this->colors[i*3]);
- vectorInit2d((float)atof(t2.tokv[8]), (float)atof(t2.tokv[9]), &this->texCoords1[i*2]);
- vectorInit2d((float)atof(t2.tokv[10]), (float)atof(t2.tokv[11]), &this->texCoords2[i*2]);
-
- vectorInit3d(0.0f, 0.0f, 0.0f, &this->normals[i*3]);
- // printf(" -- %i --\n", i);
- }
-
- f->readLine(256, buff, true);
-
- }else if(streq(t.tokv[0], "NUM_FACES")){
- this->numFaces = atoi(t.tokv[1]);
- this->faces = new Face*[this->numFaces];
- this->numIndices = this->numFaces*3;
- this->indices = new GLuint[this->numIndices];
- }else if(streq(t.tokv[0], "FACE_LIST")){
- f->readLine(256, buff, true);
-
- int ind1, ind2, ind3;
- for(int i=0;i<this->numFaces;i++){
- Face* fa = new Face();
-
- f->readLine(256, buff, true);
- /*
- sscanf(buff, "FACE %i: %i %i %i %f %f %f"
- , &n
- , &ind1, &ind2, &ind3
- , &fa->normal[0], &fa->normal[1], &fa->normal[2]);
- */
- Tokenizer t2(buff, " ", "");
- ind1=atoi(t2.tokv[2]);
- ind2=atoi(t2.tokv[3]);
- ind3=atoi(t2.tokv[4]);
-
- this->indices[i*3+0] = ind1;
- this->indices[i*3+1] = ind2;
- this->indices[i*3+2] = ind3;
- //vectorInit3d((float)atof(t2.tokv[5]), (float)atof(t2.tokv[6]), (float)atof(t2.tokv[7]), fa->normal);
-
- fa->numIndices=3;
- fa->indices=new unsigned int[3];
- fa->indices[0]=ind1;
- fa->indices[1]=ind2;
- fa->indices[2]=ind3;
-
- fa->numVertices=3;
- fa->vertices=new float[9];
- vectorCopy3d(&this->vertices[ind1*3], &fa->vertices[0]);
- vectorCopy3d(&this->vertices[ind2*3], &fa->vertices[3]);
- vectorCopy3d(&this->vertices[ind3*3], &fa->vertices[6]);
-
- fa->numColors=3;
- fa->colors=new float[9];
- vectorCopy3d(&this->colors[ind1*3], &fa->colors[0]);
- vectorCopy3d(&this->colors[ind2*3], &fa->colors[3]);
- vectorCopy3d(&this->colors[ind3*3], &fa->colors[6]);
- /*
- fa->numNormals=3;
- fa->normals=new float[9];
- vectorCopy3d(&m->normals[ind1*3], &fa->normals[0]);
- vectorCopy3d(&m->normals[ind2*3], &fa->normals[3]);
- vectorCopy3d(&m->normals[ind3*3], &fa->normals[6]);
- */
- fa->numTexCoords=3;
- fa->texCoords1=new float[6];
- vectorCopy2d(&this->texCoords1[ind1*2], &fa->texCoords1[0]);
- vectorCopy2d(&this->texCoords1[ind2*2], &fa->texCoords1[2]);
- vectorCopy2d(&this->texCoords1[ind3*2], &fa->texCoords1[4]);
- fa->texCoords2=new float[6];
- vectorCopy2d(&this->texCoords2[ind1*2], &fa->texCoords2[0]);
- vectorCopy2d(&this->texCoords2[ind2*2], &fa->texCoords2[2]);
- vectorCopy2d(&this->texCoords2[ind3*2], &fa->texCoords2[4]);
-
- fa->material=this->materials[0];
-
- fa->calcNormal();
-
- // correct vertex normals!
- fa->numNormals=3;
- fa->normals=new float[9];
- vectorCopy3d(fa->normal, &fa->normals[0]);
- vectorCopy3d(fa->normal, &fa->normals[3]);
- vectorCopy3d(fa->normal, &fa->normals[6]);
- vectorCopy3d(fa->normal, &this->normals[ind1*3]);
- vectorCopy3d(fa->normal, &this->normals[ind2*3]);
- vectorCopy3d(fa->normal, &this->normals[ind3*3]);
-
-
- this->faces[i]=fa;
-
- }
-
- f->readLine(256, buff, true);
-
- }else if(streq(t.tokv[0], "{")){
- continue;
- }else if(streq(t.tokv[0], "}")){
- break;//return true;
- }else{
- warn("(in Mesh::readFromFile() (%s, line %i)): Unknown token '%s'.\n\n", f->filename, f->line, t.tokv[0]);
- }
- }
-
- this->setRenderMode();
-
- return true;
- }
-
- void Mesh::dump(){
- int i;
-
- printf("** Mesh '%s': numMaterials: %i, numFaces: %i, numVertices: %i, numChilds: %i\n", name, numMaterials, numFaces, numVertices, numChilds);
- printf(" matrix: ");
- matrixPrint(transformationMatrix, 4);
- // for(i=0;i<numFaces;i++){
- // faces[i]->dump();
- // }
- for(i=0;i<numChilds;i++){
- childs[i]->dump();
- }
- }
-
-