Exemple #1
0
void AtlasOldMesher::optimize()
{
   AssertISV(false, "This is probably broken right now - BJG");
#if 0
   // Shove everything through nvTriStrip
   SetCacheSize(24);

   // first, stripify our geometry...
   PrimitiveGroup *pg;
   U16 pgCount;

   GenerateStrips(mIndices.address(), mIndices.size(), &pg, &pgCount, AtlasOldActivationHeightfield::smDoChecks);

   // We're lazy.
   AssertISV(pgCount == 1,
      "AtlasOldMesher::optimize - Got unexpectedly complex geometry from NVTriStrip! (a)");
   AssertISV(pg->type == PT_STRIP,
      "AtlasOldMesher::optimize - Got unexpectedly complex geometry from NVTriStrip! (b)");

   // Remap indices! BJGTODO - how am I supposed to interpet the results?
   /*   PrimitiveGroup *pgRemapped;
   RemapIndices(pg, pgCount, mVerts.size(), &pgRemapped); */

   // Ok, let's suck this stuff back in.
   mIndices.clear();
   mIndices.reserve(pg->numIndices);

   for(S32 i=0; i<pg->numIndices; i++)
      mIndices[i] = pg->indices[i];

   // And clean up the memory from the stripper.
   delete[] pg;

#endif
}
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 nvMakeStrips(std::vector<Primitive> & primitives, std::vector<U16> & indices, S32 cacheSize, U32 matIndex)
   {
      // incoming indices may have some "holes" in them...e.g., may have index 1,2,3,6,7 only
      // map to 0..N-1
      std::vector<S16> map;
      std::vector<S16> remap;
      U16 next=0;
      S32 i;
      for (i=0; i<indices.size(); i++)
      {
         while (indices[i]>=map.size())
            map.push_back(-1);
         if (map[indices[i]]<0)
         {
            map[indices[i]]=next++;
            remap.push_back(indices[i]);
         }
         indices[i] = map[indices[i]];
      }

      PrimitiveGroup * primGroups;
      U16 numGroups;
      GenerateStrips(&indices[0],indices.size(),&primGroups,&numGroups);

      for (i=0; i<numGroups; i++)
      {
         assert(primGroups[i].type == PT_STRIP);
         Primitive strip;
         strip.type = matIndex;
         strip.firstElement = indices.size();
         strip.numElements  = primGroups[i].numIndices;
         primitives.push_back(strip);
         for (S32 j=0; j<primGroups[i].numIndices; j++)
            indices.push_back(primGroups[i].indices[j]);
      }
      delete [] primGroups;

      // remap indices...
      for (i=0; i<indices.size(); i++)
         indices[i] = remap[indices[i]];
   }
Exemple #5
0
	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;
	}
Exemple #6
0
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	();
}