void TriangleBatch::Stripify( TriangleBatch& pNewBatch ) { #if GD_PLATFORM == GD_PLATFORM_WIN32 GD_ASSERT( mIndices ); PrimitiveGroup* strip; UInt16 numGroups; SetCacheSize(CACHESIZE_GEFORCE1_2); SetStitchStrips(true); SetMinStripSize(0); SetListsOnly(false); // Stripify! GenerateStrips( mIndices, mIndicesCount, &strip, &numGroups ); GD_ASSERT( numGroups == 1 ); // Copy the result in our triangle batch. pNewBatch.Allocate( TriangleStrip, strip->numIndices ); memcpy( pNewBatch.GetIndices(), strip->indices, strip->numIndices*sizeof(UInt16) ); //GD_DELETE_ARRAY(strip); #else debugBreak(); #endif }
bool Stripify(model_t *model) { int n; for (n=0; n<model->num_meshes; n++) { int count = 0; mesh_t *mesh = &model->meshes[n]; PrimitiveGroup *outPrims; unsigned short outNum; unsigned short *indices = new unsigned short[mesh->num_faces * 3]; if (!mesh->num_faces) continue; //copy the face list into an unsigned short array for (int face=0; face<mesh->num_faces; face++) { for (int v=0; v<3; v++) { indices[count++] = (unsigned short)mesh->facelist[face][v]; } } //make sure we output a triangle list SetListsOnly(true); GenerateStrips(indices, count, &outPrims, &outNum); //should only ouput 1 list if (outNum != 1) { delete [] indices; return false; } //map the faces back into the mesh count = 0; for (int face=0; face<mesh->num_faces; face++) { for (int v=0; v<3; v++) { mesh->facelist[face][v] = indices[count++]; } } delete [] indices; } return true; }
void nvStripWrap(std::vector<Primitive> & faces, std::vector<U16> & indices, S32 cacheSize) { // set stripper parameters...we'll just set some default ones SetCacheSize(cacheSize); SetStitchStrips(true); // engine can handle this, so let it SetListsOnly(false); // engine can handle this, so let it SetMinStripSize(0); // engine can handle this, so let it // main strip loop... U32 start, end, i; std::vector<Primitive> someStrips; std::vector<Primitive> retStrips; std::vector<U16> someIndices; std::vector<U16> retIndices; for (start = 0; start<faces.size(); start=end) { for (end=start; end<faces.size() && faces[start].type==faces[end].type; end++) ; // copy start to end faces into new list -- this is so we end up doing less copying // down the road (when we are doing the look ahead simulation) someStrips.clear(); someIndices.clear(); for (i=start;i<end;i++) { someIndices.push_back(indices[faces[i].firstElement + 0]); someIndices.push_back(indices[faces[i].firstElement + 1]); someIndices.push_back(indices[faces[i].firstElement + 2]); } U32 matIndex = faces[start].type ^ (Primitive::Triangles|Primitive::Strip); nvMakeStrips(someStrips,someIndices,cacheSize,matIndex); // now move strips and indices into larger list S32 startStrips = retStrips.size(); retStrips.resize(startStrips+someStrips.size()); S32 startIndices = retIndices.size(); retIndices.resize(startIndices+someIndices.size()); memcpy(&retStrips[startStrips],&someStrips[0],someStrips.size()*sizeof(Primitive)); memcpy(&retIndices[startIndices],&someIndices[0],someIndices.size()*sizeof(U16)); // now adjust start of new strips for (i=startStrips; i<retStrips.size(); i++) retStrips[i].firstElement += startIndices; } indices = retIndices; faces = retStrips; }
void optimizeFaces(int index) { assert(index >= 0 && index < LOD_AMOUNT); int faceAmount = faces[index].size(); unsigned short *oldIndices = new unsigned short[faceAmount * 3]; for(int i = 0; i < faceAmount; ++i) for(int j = 0; j < 3; ++j) { int oldIndex = faces[index][i].getVertexIndex(j); assert(oldIndex >= 0 && oldIndex < int(vertices.size())); oldIndices[i * 3 + j] = oldIndex; } PrimitiveGroup *primitiveGroup = 0; unsigned short groupAmount = 0; SetCacheSize(CACHESIZE_GEFORCE3); SetListsOnly(true); GenerateStrips(oldIndices, faceAmount * 3, &primitiveGroup, &groupAmount); faces[index].resize(primitiveGroup->numIndices / 3); { for(unsigned int i = 0; i < primitiveGroup->numIndices / 3; ++i) for(int j = 0; j < 3; ++j) { int newIndex = primitiveGroup->indices[i * 3 + j]; assert(newIndex >= 0 && newIndex < int(vertices.size())); faces[index][i].setVertexIndex(j, newIndex); } } delete[] oldIndices; delete[] primitiveGroup; }
void xrStripify (xr_vector<u16> &indices, xr_vector<u16> &perturb, int iCacheSize, int iMinStripLength) { SetCacheSize (iCacheSize); SetMinStripSize (iMinStripLength); SetListsOnly (true); // Generate strips xr_vector<PrimitiveGroup> PGROUP; GenerateStrips (&*indices.begin(),(u32)indices.size(),PGROUP); R_ASSERT (PGROUP.size()==1); R_ASSERT (PGROUP[0].type==PT_LIST); if (indices.size()!=PGROUP[0].numIndices) throw "Stripify failed."; // Remap indices xr_vector<PrimitiveGroup> xPGROUP; RemapIndices (PGROUP,u16(perturb.size()),xPGROUP); R_ASSERT (xPGROUP.size()==1); R_ASSERT (xPGROUP[0].type==PT_LIST); // Build perturberation table for(u32 index = 0; index < PGROUP[0].numIndices; index++) { u16 oldIndex = PGROUP[0].indices [index]; int newIndex = xPGROUP[0].indices [index]; R_ASSERT(oldIndex<(int)perturb.size()); R_ASSERT(newIndex<(int)perturb.size()); perturb[newIndex] = oldIndex; } // Copy indices Memory.mem_copy (&*indices.begin(),xPGROUP[0].indices,(u32)indices.size()*sizeof(u16)); // Release memory xPGROUP.clear (); PGROUP.clear (); }