示例#1
0
NiTriStripsDataRef Exporter::makeTriStripsData(const TriStrips &strips)
{
	NiTriStripsDataRef stripData = new NiTriStripsData();

	if (strips.size() > 0)
	{
		stripData->SetStripCount(strips.size());

		int i = 0;
		TriStrips::const_iterator it;
		for (it=strips.begin(); it!=strips.end(); ++it)
			stripData->SetStrip(i++, *it);
	}

	return stripData;
}
void NiTriStripsData::SetTSTriangles( const vector<Triangle> & in ) {
   if ( in.size() > 65535 || in.size() < 0 ) {
      throw runtime_error("Invalid Triangle Count: must be between 0 and 65535.");
   }

   points.clear();
   numTriangles = 0;

   TriStrips strips;
   triangle_stripper::indices idcs(in.size()*3);
   size_t i, j;
   for (i=0; i<in.size(); i++)
   {
      idcs[i * 3 + 0] = in[i][0];
      idcs[i * 3 + 1] = in[i][1];
      idcs[i * 3 + 2] = in[i][2];
   }

   tri_stripper stripper(idcs);

   primitive_vector groups;
   stripper.Strip(&groups);

   // triangles left over
   vector<Triangle> stris;

   for (i=0; i<groups.size(); i++)
   {
      if (groups[i].Type == TRIANGLE_STRIP)
      {			
         strips.push_back(TriStrip(groups[i].Indices.size()));
         TriStrip &strip = strips.back();

         for (j=0; j<groups[i].Indices.size(); j++)
            strip[j] = groups[i].Indices[j];
      } else
      {
         int size = stris.size();
         stris.resize(size + groups[i].Indices.size()/3);
         for (j=(size>0)?(size-1):0; j<stris.size(); j++)
         {
            stris[j][0] = groups[i].Indices[j*3+0];
            stris[j][1] = groups[i].Indices[j*3+1];
            stris[j][2] = groups[i].Indices[j*3+2];
         }
      }
   }

   if (stris.size())
   {
      // stitch em
      TriStrip strip;
      if (strips.size() > 0)
      {
         strip.push_back(strips.back()[strips.back().size()-1]);
         strip.push_back(stris[0][0]);
      }
      for (i=0; i<stris.size(); i++)
      {
         if (i > 0)
         {
            strip.push_back(stris[i][0]);
            strip.push_back(stris[i][0]);
         }

         strip.push_back(stris[i][0]);
         strip.push_back(stris[i][1]);
         strip.push_back(stris[i][2]);
         if (i < stris.size()-1)
            strip.push_back(stris[i][2]);
      }
      strips.push_back(strip);
   }

   if (strips.size() > 0)
   {
      SetStripCount(strips.size());

      int i = 0;
      TriStrips::const_iterator it;
      for (it=strips.begin(); it!=strips.end(); ++it)
         SetStrip(i++, *it);
   }

   //Recalculate Triangle Count
   numTriangles = CalcTriangleCount();
}