#include #include #include "GeoLodStripsConstructor.h" using namespace Geometry; //-------------------------------------------------------------------------- //Call GenerarModeloV and CopiarVectorsArraysNUEVAED to make changes //--------------------------------------------------------------------------- // Se utiliza en el constructor sobrecargado. void LodStripsConstructor::GenerarModeloCompleto(TIPOFUNC upb) { float percent; percent = 10; this->GenerarModeloV(upb); this->CopiarVectors2ArraysNUEVAED(); // Last updtate of the progress bar. upb(percent); } //----------------------------------------------------------------------------------- //It makes Lods changes and count them //----------------------------------------------------------------------------------- void LodStripsConstructor::CalcularCambiosLODsVNuevaED(TIPOFUNC upb) { // LODPosition pos; // vector listaPos; long int k; long int i; unsigned long int t; long int r; unsigned long int v; long int p0; long int lod = 0; long int sigue; long int ac[3] = {0,0,0}; long int totalRegs = 0; long int RegsCambios; vector TiraOriginal; LODData regLOD; LODChanges listaCambios; float percent; long int update; // Guardamos copia original. TiraOriginal = this->cStrips; this->MARCAVACIO = int(10 * this->cVerts.size()); listaCambios.clear(); update = 0; for (lod = 0; ((this->cVerts[lod].Next) != -1); lod++) { update++; } update = update / 20; percent = 0.5; this->LodsDisp = this->TOTALCAMBIOS = lod; pCambios = new uint32[this->TOTALCAMBIOS]; pCambios[0] = 0; // 5 min. for (lod = 0; ((this->cVerts[lod].Next) != -1); lod++) { if ((lod % update) == 0) { upb(percent); } RegsCambios = 0; regLOD.obligatory = this->Ordenacion[lod].obligatorio; for(t = 0; t < this->cStrips.size(); t++) { //Inicializar regLOD.strip = this->MARCAVACIO; //PRIMERO: los cambios de los vertices totalRegs = 0; for (v = 0; v < this->cStrips[t].size(); v++) { // RESOLUCION VARIABLE MAL. if (this->cStrips[t][v] == lod) { //Gestion de Tiras. if (regLOD.strip == this->MARCAVACIO) { regLOD.strip = t; } ++totalRegs; cDatos.push_back(v); this->cStrips[t][v] = this->cVerts[lod].Next; } } regLOD.nP = char(totalRegs); //SEGUNDO: Simplificaciones de Longitud 1 // Cambio para simplifaciones de nivel 1 mayores de 2 totalRegs = 0; i = 0; r = 0; sigue = 0; k = long(this->cStrips[t].size()-3); while (i < k) { if ( (this->cStrips[t][i] == this->cStrips[t][i+1]) && (this->cStrips[t][i+1] == this->cStrips[t][i+2]) ) { // Salvar el inicio de la repeticion. if (!r) { p0 = i; } this->cStrips[t].erase(this->cStrips[t].begin()+i); i--; r++; if ((i+1) != this->cStrips[t].size()-1) { sigue = 1; } else { sigue = 0; } } else { sigue = 0; } if (!sigue && r) { if (regLOD.strip == this->MARCAVACIO) { regLOD.strip = t; } ++totalRegs; cDatos.push_back(p0); cDatos.push_back(r); r = 0; k = long(this->cStrips[t].size()-r-3); } i++; } regLOD.nL1 = char(totalRegs); //TERCERO: Simplificaciones de Longitud 2 tipo V1 V2 V1 V2 -> V1 V2 totalRegs = 0; i = 0; r = 0; sigue = 0; k = long(this->cStrips[t].size() - 4); while (i < k) { if ( (this->cStrips[t][i] == this->cStrips[t][i+2]) && (this->cStrips[t][i+1] == this->cStrips[t][i+3]) ) { if (!r) { p0 = i; } this->cStrips[t].erase(this->cStrips[t].begin()+i); this->cStrips[t].erase(this->cStrips[t].begin()+i); r++; i -= 2; if ((i+1) != this->cStrips[t].size()-3) { sigue = 1; } else { sigue = 0; } } else { sigue = 0; } if (!sigue && r) { if (regLOD.strip == this->MARCAVACIO) { regLOD.strip = t; } ++totalRegs; cDatos.push_back(p0); cDatos.push_back(r); r = 0; k = long((this->cStrips[t].size()-4-2*r)); } i++; } regLOD.nL2 = char(totalRegs); if (regLOD.strip != this->MARCAVACIO) { RegsCambios++; listaCambios.push_back(regLOD); } }// End for t. pCambios[lod] = RegsCambios; }// End for lod. this->cCambios = listaCambios; // Guardar el numero de LODS disponibles. this->TOTALCAMBIOS = this->LodsDisp=lod; //Retornar a la lista original this->cStrips = TiraOriginal; } //----------------------------------------------------------------------- //Put in order vertex of Mesh from simplification sequence //----------------------------------------------------------------------- void LodStripsConstructor::OrdenarModeloVQSLIM(TIPOFUNC upb) { unsigned long int i; unsigned long int j; unsigned long int t; unsigned long int v; long int vSig; long int k; VECTORVERTEX Vertices; VECTORVERTEX NuevosVerts; vector NuevasTiras; VECTORINT tira; vector mV1Aux; tipoOrden Orden; tipoOrden *Ord; bool bEncontrado; long int c1; long int c2; // Progress bar float percent; long int update; bEncontrado = false; c1 = 0; c2 = 0; update = long(geoMeshSQ->mSteps.size() / 20); percent = 0.5; for (i = 0; i < this->geoMeshSQ->mSteps.size(); i++) { if ((i % update) == 0) { upb(percent); } mV1Aux.push_back(this->geoMeshSQ->mSteps[i].mV1); Orden.vQslimNext = this->geoMeshSQ->mSteps[i].mV0; Orden.vQslim = this->geoMeshSQ->mSteps[i].mV1; Orden.obligatorio = this->geoMeshSQ->mSteps[i].obligatorio; Orden.vLS = i; Orden.x = this->geoMeshSQ->mSteps[i].x; Orden.vLSNext = -1; Orden.cambio = "n"; Ordenacion.push_back(Orden); } this->NumVertsRepetidos = c2; update = long(Ordenacion.size() / 20); percent = 0.5; // 1 min. // Change all vertices that have x != 0. for(i=0;ix!=0) { // Change the simplification order. v = Ord->vQslim; Ord->vQslim = Ord->vQslimNext; Ord->vQslimNext = v; for (j = i+1; j < Ordenacion.size(); j++) { if (Ordenacion[j].vQslim == Ord->vQslim) { Ordenacion[j].vQslim = Ord->vQslimNext; Ordenacion[j].cambio = "y"; } else if (Ordenacion[j].vQslimNext == Ord->vQslim) { Ordenacion[j].vQslimNext = Ord->vQslimNext; Ordenacion[j].cambio = "y"; } } } } update = long(Ordenacion.size() / 20); percent = 0.5; // 3 seg. //Ordenacion de los vertices for(i = 0; i < Ordenacion.size(); i++) { if ((i % update) == 0) { upb(percent); } c1++; NuevosVerts.push_back(this->cVerts[Ordenacion[i].vQslim]); cVerts[Ordenacion[i].vQslim].Next = -1; } // Añadir aquellos vertices que no estaban en NuevosVerts // y no se simplificaban. int cont = 0; int contestaban = 0; for(i = 0; i < this->cVerts.size(); i++) { if (this->cVerts[i].Next != -1) { cont++; NuevosVerts.push_back(this->cVerts[i]); Orden.vLS = int(Ordenacion.size()); Orden.obligatorio = 0; Orden.vLSNext = -1; Orden.vQslim = i; Orden.vQslimNext = -1; Ordenacion.push_back(Orden); } else { contestaban++; } } update = long(Ordenacion.size() / 20); percent = 0.5; // 2 min. // Calcular los siguiente teniendo en cuenta el QSLIM. for (i = 0; i < Ordenacion.size(); i++) { if ((i % update) == 0) { upb(percent); } v = Ordenacion[i].vQslimNext; //Buscar ese vertice v cual es ahora vSig = 0; for (t = 0; t < Ordenacion.size() && !vSig;t++) { if (Ordenacion[t].vQslim==v) { vSig=Ordenacion[t].vLS; } } if (vSig!=0) { Ordenacion[i].vLSNext = vSig; } } //Creacion de nuevas tiras con las mismas dimensiones for(t = 0; t < this->cStrips.size(); t++) { tira.clear(); for(i = 0; i < this->cStrips[t].size(); i++) { tira.push_back(0); } NuevasTiras.push_back(tira); } update = long(NuevosVerts.size() / 40); percent = 0.5; k = 0; // 2 min. //Cambiar los vertices de las tiras for(v = 0; v < NuevosVerts.size(); v++) { if ((v % update) == 0) { upb(percent); } for(t = 0; t < this->cStrips.size(); t++) { for(i = 0; i < this->cStrips[t].size(); i++) { if (this->cStrips[t][i] == Ordenacion[v].vQslim) { k++; NuevasTiras[t][i] = v; } } } } //Cambiar a Tiras Nuevas this->cStrips = NuevasTiras; //NuevosVerts y Ordenacion = tamaño. for(i = 0; i < NuevosVerts.size(); i++) { NuevosVerts[i].Next = Ordenacion[i].vLSNext; } //Cambiar cVerts por nuevosVerts. this->cVerts = NuevosVerts; percent = 10; upb(percent); } //----------------------------------------------------------------------------- // Constructor of LodStripsConstructor object from // a Mesh and MeshSimplificationSequence // Constructor del objeto LodStripsConstructor. // Tomamos el Mesh y la secuencia de simplificacion que se pasan // como parametros y llamamos a la funcion GenerarModeloCompleto para // que se realicen las modificaciones a efectuar //----------------------------------------------------------------------------- LodStripsConstructor::LodStripsConstructor(const Mesh *m, const MeshSimplificationSequence *ms, size_t submesh, TIPOFUNC upb) { MARCA = TOTALTIRAS = TOTALVERTS = TOTALCAMBIOS = 0; meshoriginal = m; this->geoMesh = new Geometry::Mesh(); *this->geoMesh = *m; this->geoMeshSQ = ms; // Set the leaves submesh. mSubMeshLeaves = submesh; this->GenerarModeloCompleto(upb); } //--------------------------------------------- // Destructor LodStripsConstructor object // Destructor de la clase LodStripsConstructor //--------------------------------------------- LodStripsConstructor::~LodStripsConstructor() { delete [] vDatos; delete [] vCambios; vector cCambiosTemp; cCambios.swap(cCambiosTemp); VECTORUNINT cDatosTemp; cDatos.swap(cDatosTemp); delete [] vStrips; delete [] vVerts; vector cStripsTemp; cStrips.swap(cStripsTemp);; VECTORVERTEX cVertsTemp; cVerts.swap(cVertsTemp); delete [] pCambios; delete this->geoMesh; } //------------------------------------------------------------------------------ // build lod file with necessary information and save all changes at // lodStripConstructor object // Construimos el archivo Lod donde se guarda la informacion sobre los // cambios realizados en el mesh // y copiamos todos los cambios realizados sobre las estructuras que // contienen los vertices y los indices // modificados sobre el objeto Mesh de la clase //------------------------------------------------------------------------------ void LodStripsConstructor::Save(Serializer &oSerializer) { unsigned int i, j; int k=0; char simp[256]; //****************** 1º CONSTRUCCION DEL FICHERO.LOD ********************* // VERTICES. for(i = 0; i < this->cVerts.size(); i++) { sprintf(simp,"v %d\n",cVerts[i].Next); oSerializer.WriteData(simp,sizeof(char),strlen(simp)); } // CSTRIPS. this->TOTALINDICES = 0; for(i = 0; i < this->cStrips.size(); i++) { this->TOTALINDICES += int(this->cStrips[i].size()); } // lines starting with a d. // Changes for(i = 0; i < this->cCambios.size(); i++) { sprintf(simp,"c\n"); oSerializer.WriteData(simp,sizeof(char),strlen(simp)); sprintf(simp, "d %u %u %u %u %u\n", cCambios[i].strip, cCambios[i].nP, cCambios[i].nL1, cCambios[i].nL2, cCambios[i].obligatory); oSerializer.WriteData(simp,sizeof(char),strlen(simp)); } // Lines starting with a b. // Data. sprintf(simp,"a\n"); oSerializer.WriteData(simp,sizeof(char),strlen(simp)); for(i = 0; i < this->cDatos.size(); i++) { sprintf(simp,"b %d\n",cDatos[i]); oSerializer.WriteData(simp,sizeof(char),strlen(simp)); } // lines starting with a p. // Chages made in a LOD. for(i = 0; i < this->TOTALCAMBIOS; i++) { sprintf(simp,"p %d\n",this->pCambios[i]); oSerializer.WriteData(simp,sizeof(char),strlen(simp)); } oSerializer.WriteData("\n",sizeof(char),1); //******************* 2º DEVOLVER EL MESH CON LAS MODIFICACIONES EFECTUADAS ********************* int num_no = 0; if(this->geoMesh->mSubMesh[0].mSharedVertexBuffer == true) { //mPosition delete[] this->geoMesh->mVertexBuffer->mPosition; this->geoMesh->mVertexBuffer->mPosition = new Vector3[this->cVerts.size()]; //mNormal if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) { delete[] this->geoMesh->mVertexBuffer->mNormal; this->geoMesh->mVertexBuffer->mNormal = new Vector3[this->cVerts.size()]; } //mTexCoords if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) { delete[] this->geoMesh->mVertexBuffer->mTexCoords; this->geoMesh->mVertexBuffer->mTexCoords = new Vector2[this->cVerts.size()]; } this->geoMesh->mVertexBuffer->mVertexCount = this->cVerts.size(); this->geoMesh->mVertexBuffer->mVertexInfo = this->meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo; for(i = 0; i < this->geoMesh->mSubMeshCount; i++) { this->geoMesh->mSubMesh[i].mVertexBuffer = this->geoMesh->mVertexBuffer; this->geoMesh->mSubMesh[i].mSharedVertexBuffer = true; } int indice = 0; for (j = 0; j < this->cVerts.size(); j++) { //Copiamos las coordeandas de posicion this->geoMesh->mVertexBuffer->mPosition[indice].x = this->cVerts[j].Vertex[0]; this->geoMesh->mVertexBuffer->mPosition[indice].y = this->cVerts[j].Vertex[1]; this->geoMesh->mVertexBuffer->mPosition[indice].z = this->cVerts[j].Vertex[2]; //Copiamos las normales if (meshoriginal->mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) { this->geoMesh->mVertexBuffer->mNormal[indice].x = this->cVerts[j].Normal[0]; this->geoMesh->mVertexBuffer->mNormal[indice].y = this->cVerts[j].Normal[1]; this->geoMesh->mVertexBuffer->mNormal[indice].z = this->cVerts[j].Normal[2]; } //Copiamos las coordenadas de textura if (meshoriginal->mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) { this->geoMesh->mVertexBuffer->mTexCoords[indice].x = this->cVerts[j].TexCoords[0]; this->geoMesh->mVertexBuffer->mTexCoords[indice].y = this->cVerts[j].TexCoords[1]; } indice++; } this->geoMesh->mVertexBuffer->mVertexCount = indice; } else //OSCAR { //Supondre que solo tengo un submesh con vertices no compartidos //mPosition delete[] this->geoMesh->mSubMesh[0].mVertexBuffer->mPosition; this->geoMesh->mSubMesh[0].mVertexBuffer->mPosition = new Vector3[this->cVerts.size()]; //mNormal if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) { delete[] this->geoMesh->mSubMesh[0].mVertexBuffer->mNormal; this->geoMesh->mSubMesh[0].mVertexBuffer->mNormal = new Vector3[this->cVerts.size()]; } //mTexCoords if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) { delete[] this->geoMesh->mSubMesh[0].mVertexBuffer->mTexCoords; this->geoMesh->mSubMesh[0].mVertexBuffer->mTexCoords = new Vector2[this->cVerts.size()]; } this->geoMesh->mSubMesh[0].mVertexBuffer->mVertexCount =this->cVerts.size(); this->geoMesh->mSubMesh[0].mVertexBuffer->mVertexInfo = this->meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo; this->geoMesh->mSubMesh[0].mSharedVertexBuffer=false; int indice=0; for (j=0; jcVerts.size(); j++) { //Copiamos las coordeandas de posicion this->geoMesh->mSubMesh[0].mVertexBuffer->mPosition[indice].x=this->cVerts[j].Vertex[0]; this->geoMesh->mSubMesh[0].mVertexBuffer->mPosition[indice].y=this->cVerts[j].Vertex[1]; this->geoMesh->mSubMesh[0].mVertexBuffer->mPosition[indice].z=this->cVerts[j].Vertex[2]; //Copiamos las normales if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) { this->geoMesh->mSubMesh[0].mVertexBuffer->mNormal[indice].x=this->cVerts[j].Normal[0]; this->geoMesh->mSubMesh[0].mVertexBuffer->mNormal[indice].y=this->cVerts[j].Normal[1]; this->geoMesh->mSubMesh[0].mVertexBuffer->mNormal[indice].z=this->cVerts[j].Normal[2]; } //Copiamos las coordenadas de textura if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) { this->geoMesh->mSubMesh[0].mVertexBuffer->mTexCoords[indice].x=this->cVerts[j].TexCoords[0]; this->geoMesh->mSubMesh[0].mVertexBuffer->mTexCoords[indice].y=this->cVerts[j].TexCoords[1]; } indice++; } this->geoMesh->mSubMesh[0].mVertexBuffer->mVertexCount =indice; } int indice_acum = 0; for(i=0;igeoMesh->mSubMeshCount;i++) { for (size_t ind=0; ind < meshoriginal->mSubMesh[i].mIndexCount; ind++) { if (meshoriginal->mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) { //Hay coordenadas de textura y normales if(meshoriginal->mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) { for (size_t indvo=0; indvogeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount; indvo++) { if (igual(meshoriginal->mSubMesh[i].mVertexBuffer->mPosition[meshoriginal->mSubMesh[i].mIndex[ind]],this->geoMesh->mSubMesh[i].mVertexBuffer->mPosition[indvo])) { if (igual(meshoriginal->mSubMesh[i].mVertexBuffer->mNormal[meshoriginal->mSubMesh[i].mIndex[ind]],this->geoMesh->mSubMesh[i].mVertexBuffer->mNormal[indvo])) { if (igual(meshoriginal->mSubMesh[i].mVertexBuffer->mTexCoords[meshoriginal->mSubMesh[i].mIndex[ind]],this->geoMesh->mSubMesh[i].mVertexBuffer->mTexCoords[indvo])) { this->geoMesh->mSubMesh[i].mIndex[ind]= int(indvo);//+indice_acum; } } } } } else //Hay coordenadas de textura pero no hay normales { for (size_t indvo=0; indvogeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount; indvo++) { if (igual(meshoriginal->mSubMesh[i].mVertexBuffer->mPosition[meshoriginal->mSubMesh[i].mIndex[ind]],this->geoMesh->mSubMesh[i].mVertexBuffer->mPosition[indvo])) { if (igual(meshoriginal->mSubMesh[i].mVertexBuffer->mTexCoords[meshoriginal->mSubMesh[i].mIndex[ind]],this->geoMesh->mSubMesh[i].mVertexBuffer->mTexCoords[indvo])) { this->geoMesh->mSubMesh[i].mIndex[ind]=int(indvo);//+indice_acum; } } } } } else { // No hay coordenadas de textura pero si normales if(meshoriginal->mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) { for (size_t indvo=0; indvogeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount; indvo++) { if (igual(meshoriginal->mSubMesh[i].mVertexBuffer->mPosition[meshoriginal->mSubMesh[i].mIndex[ind]],this->geoMesh->mSubMesh[i].mVertexBuffer->mPosition[indvo])) { if (igual(meshoriginal->mSubMesh[i].mVertexBuffer->mNormal[meshoriginal->mSubMesh[i].mIndex[ind]],this->geoMesh->mSubMesh[i].mVertexBuffer->mNormal[indvo])) { this->geoMesh->mSubMesh[i].mIndex[ind]=int(indvo);//+indice_acum; } } } } else //No hay coordenadas de texturas ni normales { for (size_t indvo=0; indvogeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount; indvo++) { if (igual(meshoriginal->mSubMesh[i].mVertexBuffer->mPosition[meshoriginal->mSubMesh[i].mIndex[ind]],this->geoMesh->mSubMesh[i].mVertexBuffer->mPosition[indvo])) { this->geoMesh->mSubMesh[i].mIndex[ind]=int(indvo);//+indice_acum; } } } } } } } int LodStripsConstructor::igual(Geometry::Vector3 vo,Geometry::Vector3 vc) { if (vo.x==vc.x && vo.y==vc.y && vo.z==vc.z) return 1; else return 0; } int LodStripsConstructor::igual(Geometry::Vector2 vo,Geometry::Vector2 vc) { if (vo.x==vc.x && vo.y==vc.y) return 1; else return 0; } void LodStripsConstructor::Load(Serializer &oSerializer) { } //----------------------------------------------------------------------------------------------- //Call leeVerticesyTirasDeMesh, OrdenarModeloVQSLIM and CalcularCambiosLODsVNuevaED to make changes //at vertex and index strutures //Llama a los metodos que realizan los cambios sobre las estructuras que contienen la informacion //de los vertices y los indices //----------------------------------------------------------------------------------------------- void LodStripsConstructor::GenerarModeloV(TIPOFUNC upb) { long int max; long int t; unsigned long int i; float percent; percent = 10; this->leeVerticesyTirasDeMesh(); upb(percent); // 6 min. this->OrdenarModeloVQSLIM(upb); //Calcular el tamaño maximo de tira max = 0; for(i = 0; i < this->TOTALTIRAS; i++) { t = long(this->cStrips[i].size()); if (t > max) { max = t; } } this->MARCA = max + 1; // 5 min. this->CalcularCambiosLODsVNuevaED(upb); } //----------------------------------------------------------------------------------------- //It fills structs with vertex and index information //Rellena estructuras de datos que contienen la informacion de vertices y tiras modificadas //----------------------------------------------------------------------------------------- void LodStripsConstructor::CopiarVectors2ArraysNUEVAED() { unsigned int i; unsigned int j; uint32 max; uint32 t; VECTORINT tira; LODChanges listaCambios; // ALLOCATE---------------- this->TOTALVERTS = int(this->cVerts.size()); this->TOTALTIRAS = int(this->cStrips.size()); this->vVerts = new tipoVertice[this->TOTALVERTS]; this->lStripsV = new VECTORINT[this->TOTALTIRAS]; this->vDatos = new uint32[cDatos.size()]; // Calcular el tamaño maximo de tira y el numero de caras total. max = 0; this->TOTALCARAS = 0; for (i = 0; i < this->cStrips.size(); i++) { t = int(this->cStrips[i].size()); if (t > max) { max = t; } this->TOTALCARAS += (t-2); } this->vStrips = Allocate2DArrayINT(this->TOTALTIRAS,max+1); this->MARCA = int(this->cVerts.size()); vCambios = new LODData[this->cCambios.size()]; // Rellenar vChanges. for (i = 0; i < this->cCambios.size();++i) { vCambios[i] = cCambios[i]; } for (i = 0; i < this->cStrips.size(); i++) { for (j = 0; j < this->cStrips[i].size(); j++) { // Rellenar el array vStrips. this->vStrips[i][j] = this->cStrips[i][j]; // Rellenar el vVector. this->lStripsV[i].push_back(this->cStrips[i][j]); } this->vStrips[i][j] = this->MARCA; } for (i = 0; i < cDatos.size(); i++) { vDatos[i] = cDatos[i]; } pCurrentData = vDatos; // Meter los vertices en vVerts. for (i = 0; i < this->cVerts.size(); i++) { this->vVerts[i] = this->cVerts[i]; } } //--------------------------------------------------------------------------------------------------- //It fills cVerts and cStrips with original Mesh vertex and strips information //Rellena las estructuras cVerts Y cStrips a partir de de los vertices y las tiras del mesh original //--------------------------------------------------------------------------------------------------- void LodStripsConstructor::leeVerticesyTirasDeMesh() { tipoVertice vAux; VECTORINT tira; size_t i; size_t j; bool error; error = false; if(this->geoMesh->mSubMeshCount == 1) { error = false; } else { for (i = 0; i < this->geoMesh->mSubMeshCount;i++) { if (this->geoMesh->mSubMesh[i].mSharedVertexBuffer == true) { error = false; } else { error = true; break; } } } if(!error) { if ( (this->geoMesh->mSubMesh[0].mSharedVertexBuffer == true) && (this->geoMesh->mSubMeshCount > 1) ) { for (j = 0; j < this->geoMesh->mVertexBuffer->mVertexCount; j++) { // Si hay mas de un submesh ListaIndices no se rellena correctamente vAux.Vertex[0] = this->geoMesh->mVertexBuffer->mPosition[j].x; vAux.Vertex[1] = this->geoMesh->mVertexBuffer->mPosition[j].y; vAux.Vertex[2] = this->geoMesh->mVertexBuffer->mPosition[j].z; // Añadimos las normales en cVerts. if ( this->geoMesh->mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL ) { vAux.Normal[0] = this->geoMesh->mVertexBuffer->mNormal[j].x; vAux.Normal[1] = this->geoMesh->mVertexBuffer->mNormal[j].y; vAux.Normal[2] = this->geoMesh->mVertexBuffer->mNormal[j].z; } // Añadimos las coordenadas de textura a cVerts. if ( this->geoMesh->mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS ) { vAux.TexCoords[0] = this->geoMesh->mVertexBuffer->mTexCoords[j].x; vAux.TexCoords[1] = this->geoMesh->mVertexBuffer->mTexCoords[j].y; } vAux.Next = -10; vAux.numMesh = 0; vAux.obligatorio = 0; this->cVerts.push_back(vAux); } } else { for (i = 0; i < this->geoMesh->mSubMeshCount; i++) { for ( j = 0; j < this->geoMesh->mSubMesh[i].mVertexBuffer->mVertexCount; j++) { // Si hay mas de un submesh ListaIndices // no se rellena correctamente. vAux.Vertex[0] = this->geoMesh->mSubMesh[i]. mVertexBuffer->mPosition[j].x; vAux.Vertex[1] = this->geoMesh->mSubMesh[i]. mVertexBuffer->mPosition[j].y; vAux.Vertex[2] = this->geoMesh->mSubMesh[i]. mVertexBuffer->mPosition[j].z; // Añadimos las normales en cVerts. vAux.Normal[0] = this->geoMesh->mSubMesh[i]. mVertexBuffer->mNormal[j].x; vAux.Normal[1] = this->geoMesh->mSubMesh[i]. mVertexBuffer->mNormal[j].y; vAux.Normal[2] = this->geoMesh->mSubMesh[i]. mVertexBuffer->mNormal[j].z; // Añadimos las coordenadas de textura a cVerts. vAux.TexCoords[0] = this->geoMesh->mSubMesh[i]. mVertexBuffer->mTexCoords[j].x; vAux.TexCoords[1] = this->geoMesh->mSubMesh[i]. mVertexBuffer->mTexCoords[j].y; vAux.Next = -10; vAux.numMesh = int(i); this->cVerts.push_back(vAux); } } } Index indice_acum; Index num_vert; num_vert = 0; for (i = 0; i < this->geoMesh->mSubMeshCount; i++) { // If is not the leaves submesh. if (mSubMeshLeaves != i) { indice_acum = 0; for (j = 0; j < this->geoMesh->mSubMesh[i].mStripCount; j++) { Index *aux = this->geoMesh->mSubMesh[i].mStrip[j]; /* if (j != 0) { // La primera tira no empieza por índices repetidos. aux = aux+1; indice_acum++; } */ if (j+1 < this->geoMesh->mSubMesh[i].mStripCount) { Index *siguiente = this->geoMesh->mSubMesh[i].mStrip[j+1]; tira.clear(); while (aux != siguiente) { tira.push_back(*aux); indice_acum++; aux = aux + 1; } //tira.pop_back(); this->cStrips.push_back(tira); } else { // Insertar los indices de la última tira en el cStrips tira.clear(); for ( unsigned int k = indice_acum; k < this->geoMesh->mSubMesh[i].mIndexCount; k++) { tira.push_back(this->geoMesh->mSubMesh[i].mIndex[k]); } this->cStrips.push_back(tira); } } num_vert += int(this->geoMesh->mSubMesh[i]. mVertexBuffer->mVertexCount); } } this->TOTALVERTS = int(cVerts.size()); this->TOTALTIRAS = int(cStrips.size()); } else { // Error. } } /// GetMesh: Return de current Mesh. Mesh * LodStripsConstructor::GetMesh() { Mesh *mesh_built; mesh_built = new Mesh(); *mesh_built = *geoMesh; return mesh_built; } // Sets what is the submesh that stores the leaves. void LodStripsConstructor::SetSubMeshLeaves(size_t submesh) { mSubMeshLeaves = submesh; }