예제 #1
0
NodeGroup *StrokeTesselator::Tesselate(StrokeVertexIterator begin, StrokeVertexIterator end)
{
  NodeGroup *group = new NodeGroup;
  NodeShape *tshape = new NodeShape;
  group->AddChild(tshape);
  // tshape->material().setDiffuse(0.0f, 0.0f, 0.0f, 1.0f);
  tshape->setFrsMaterial(_FrsMaterial);

  for (StrokeVertexIterator c = begin, cend = end; c != cend; c++) {
    tshape->AddRep(Tesselate((*c)));
  }

  return group;
}
예제 #2
0
void CMeshMathSurface::BuildParametricSurface(unsigned long nVx, unsigned long nVy, float x0, float y0, float du, float dv, VECTOR4D(*pFn)(float u, float v)) {
  float x, y = y0;

  m_Indices.clear();
  m_Vertices.clear();
  m_nVx = nVx;
  m_nVy = nVy;
  m_Vertices.resize(m_nVx * m_nVy);
  for (unsigned long j = 0; j < m_nVy; j++) {
    x = x0;
    for (unsigned long i = 0; i < m_nVx; i++) {
      VECTOR4D P = pFn(x, y);
      m_Vertices[j * m_nVx + i].Position = P;
      x += du;
    }
    y += dv;
  }
  Tesselate();
}
예제 #3
0
void CMeshMathSurface::BuildAnalyticSurface(unsigned long nVx, unsigned long nVy, float x0, float y0, float dx, float dy, float(*pFn)(float x, float y)) {
  float x, y = y0;

  m_Indices.clear();
  m_Vertices.clear();
  m_nVx = nVx;
  m_nVy = nVy;
  m_Vertices.resize(m_nVx * m_nVy);
  for (unsigned long j = 0; j < m_nVy; j++) {
    x = x0;
    for (unsigned long i = 0; i < m_nVx; i++) {
      VECTOR4D P = { x, y, pFn(x, y), 1 };
      m_Vertices[j * m_nVx + i].Position = P;
      x += dx;
    }
    y += dy;
  }
  Tesselate();
}
CIdentitySphere::CIdentitySphere(unsigned slices, unsigned stacks)
{
    Tesselate(slices, stacks);
}
예제 #5
0
static bool LoadBIN(const char* filename, SurfaceManager& test, const float* scale=null, bool mergeMeshes=false, udword tesselation=0, TesselationScheme ts = TESS_BUTTERFLY)
{
	IceFile BinFile(filename);
	if(!BinFile.IsValid())
		return false;

	const udword NbMeshes = BinFile.LoadDword();
	printf("LoadBIN: loading %d meshes...\n", NbMeshes);

	AABB GlobalBounds;
	GlobalBounds.SetEmpty();
	udword TotalNbTris = 0;
	udword TotalNbVerts = 0;
	if(!mergeMeshes)
	{
		for(udword i=0;i<NbMeshes;i++)
		{
			const udword Collidable = BinFile.LoadDword();
			const udword Renderable = BinFile.LoadDword();

			const udword NbVerts = BinFile.LoadDword();
			const udword NbFaces = BinFile.LoadDword();

//			TotalNbTris += NbFaces;
//			TotalNbVerts += NbVerts;

			IndexedSurface* IS = test.CreateManagedSurface();
			bool Status = IS->Init(NbFaces, NbVerts);
			ASSERT(Status);

			Point* Verts = IS->GetVerts();
			for(udword j=0;j<NbVerts;j++)
			{
				Verts[j].x = BinFile.LoadFloat();
				Verts[j].y = BinFile.LoadFloat();
				Verts[j].z = BinFile.LoadFloat();
				if(scale)
					Verts[j] *= *scale;

				if(0)
				{
					Matrix3x3 RotX;
					RotX.RotX(HALFPI*0.5f);
					Verts[j] *= RotX;
					Verts[j] += Point(0.1f, -0.2f, 0.3f);
				}

				GlobalBounds.Extend(Verts[j]);
			}

			IndexedTriangle* F = IS->GetFaces();
			for(udword j=0;j<NbFaces;j++)
			{
				F[j].mRef[0] = BinFile.LoadDword();
				F[j].mRef[1] = BinFile.LoadDword();
				F[j].mRef[2] = BinFile.LoadDword();
			}

/*			if(tesselation)
			{
				for(udword j=0;j<tesselation;j++)
				{
					if(ts==TESS_BUTTERFLY)
					{
						ButterflyScheme BS;
						IS->Subdivide(BS);
					}
					else if(ts==TESS_POLYHEDRAL)
					{
						PolyhedralScheme PS;
						IS->Subdivide(PS);
					}
				}
			}*/
			if(tesselation)
				Tesselate(IS, tesselation, ts);

			if(gUseMeshCleaner)
			{
				MeshCleaner Cleaner(IS->GetNbVerts(), IS->GetVerts(), IS->GetNbFaces(), IS->GetFaces()->mRef);
				IS->Init(Cleaner.mNbTris, Cleaner.mNbVerts, Cleaner.mVerts, (const IndexedTriangle*)Cleaner.mIndices);
			}

			TotalNbTris += IS->GetNbFaces();
			TotalNbVerts += IS->GetNbVerts();

//			SaveBIN("c:\\TessBunny.bin", *IS);
		}
	}
	else
	{
		IndexedSurface* IS = test.CreateManagedSurface();

		for(udword i=0;i<NbMeshes;i++)
		{
			const udword Collidable = BinFile.LoadDword();
			const udword Renderable = BinFile.LoadDword();

			const udword NbVerts = BinFile.LoadDword();
			const udword NbFaces = BinFile.LoadDword();

			IndexedSurface LocalIS;
			bool Status = LocalIS.Init(NbFaces, NbVerts);
			ASSERT(Status);

			Point* Verts = LocalIS.GetVerts();
			for(udword j=0;j<NbVerts;j++)
			{
				Verts[j].x = BinFile.LoadFloat();
				Verts[j].y = BinFile.LoadFloat();
				Verts[j].z = BinFile.LoadFloat();
				if(scale)
					Verts[j] *= *scale;
				GlobalBounds.Extend(Verts[j]);
			}

			IndexedTriangle* F = LocalIS.GetFaces();
			for(udword j=0;j<NbFaces;j++)
			{
				F[j].mRef[0] = BinFile.LoadDword();
				F[j].mRef[1] = BinFile.LoadDword();
				F[j].mRef[2] = BinFile.LoadDword();
			}

			IS->Merge(&LocalIS);
		}

/*		if(tesselation)
		{
			for(udword j=0;j<tesselation;j++)
			{
				ButterflyScheme BS;
				IS->Subdivide(BS);
			}
		}*/
		if(tesselation)
			Tesselate(IS, tesselation, ts);

		TotalNbTris = IS->GetNbFaces();
		TotalNbVerts = IS->GetNbVerts();
	}

	test.SetGlobalBounds(GlobalBounds);

	const udword GrandTotal = sizeof(Point)*TotalNbVerts + sizeof(IndexedTriangle)*TotalNbTris;
	printf("LoadBIN: loaded %d tris and %d verts, for a total of %d Kb.\n", TotalNbTris, TotalNbVerts, GrandTotal/1024);
	printf("LoadBIN: min bounds: %f | %f | %f\n", GlobalBounds.GetMin(0), GlobalBounds.GetMin(1), GlobalBounds.GetMin(2));
	printf("LoadBIN: max bounds: %f | %f | %f\n", GlobalBounds.GetMax(0), GlobalBounds.GetMax(1), GlobalBounds.GetMax(2));
	return true;
}