void MarchingCubesInterface::CreateMesh()
{
	//Begin the construction of the mesh
	GetMeshBuilder()->BeginMesh();

	//Sample the scalar field value on each vertice of grid
	SampleSpace();

	//For each cube defined by the grid, emit geometry if the cube intersect the surface.
	March();

	//Add a dummy triangle to avoid empty mesh     
	Vertex v;
	m_meshBuilder->AddVertex(v);
	m_meshBuilder->AddVertex(v);
	m_meshBuilder->AddVertex(v);

	m_meshBuilder->AddTriangle(0,1,2);

	//Finalize the mesh
	GetMeshBuilder()->EndMesh();
}
Beispiel #2
0
void RNFR067_IsoSplash::Prepare(Wz4RenderContext *ctx)
{
  for(sInt i=0;i<4;i++)
  {
    if(Mtrl[i]) 
      Mtrl[i]->BeforeFrame(Para.LightEnv);
  }

  SphereEnable = (Para.SphereAmp!=0.0f);
  SphereAmp.x = 1.0f / Para.SphereDirections.x;
  SphereAmp.y = 1.0f / Para.SphereDirections.y;
  SphereAmp.z = 1.0f / Para.SphereDirections.z;
  SphereAmp = SphereAmp * SphereAmp;

  CubeEnable = (Para.CubeAmp!=0.0f);
  CubeAmp.x = 1.0f / Para.CubeDirections.x;
  CubeAmp.y = 1.0f / Para.CubeDirections.y;
  CubeAmp.z = 1.0f / Para.CubeDirections.z;

  NoiseEnable = (Para.NoiseAmp1!=0.0f) || (Para.NoiseAmp2!=0.0f);
  NoiseFreq1 = Para.NoiseFreq1*0x10000;
  NoisePhase1 = Para.NoisePhase1*0x10000;
  NoiseAmp1 = Para.NoiseAmp1;
  NoiseFreq2 = Para.NoiseFreq2*0x10000;
  NoisePhase2 = Para.NoisePhase2*0x10000;
  NoiseAmp2 = Para.NoiseAmp2;

  RotEnable = 0;
  RubberEnable = 0;
  if(Para.Rot.x!=0 || Para.Rot.y!=0 || Para.Rot.z!=0)
    RotEnable = 1;
  if(Para.Rubber.x!=0 || Para.Rubber.y!=0 || Para.Rubber.z!=0)
    RotEnable = RubberEnable = 1;

  PolarEnable = (Para.PolarAmp!=0.0f);


  for(sInt i=0;i<Size;i++)
  {
    sF32 py = sF32(i-1)/sF32((1<<Para.OctreeDivisions)*8);
    RubberMat[i].EulerXYZ((Para.Rot.x+Para.Rubber.x*py)*sPI2F,
                          (Para.Rot.y+Para.Rubber.y*py)*sPI2F,
                          (Para.Rot.z+Para.Rubber.z*py)*sPI2F);
  }

  sF32 f = 1.0f/((1<<Para.OctreeDivisions)*8);
  for(sInt y=0;y<Size;y++)
  {
    for(sInt x=0;x<Size;x++)
    {
      sF32 px = (x-1)*f*2-1;
      sF32 py = (y-1)*f*2-1;

      NoiseXY[Size*y+x] = NoiseAmp1*sPerlin2D(sInt(px*NoiseFreq1.x+NoisePhase1.x),
                                              sInt(py*NoiseFreq1.y+NoisePhase1.y),255,Para.NoiseSeed1)
                        + NoiseAmp2*sPerlin2D(sInt(px*NoiseFreq2.x+NoisePhase2.x),
                                              sInt(py*NoiseFreq2.y+NoisePhase2.y),255,Para.NoiseSeed2);

      NoiseYZ[Size*y+x] = NoiseAmp1*sPerlin2D(sInt(px*NoiseFreq1.y+NoisePhase1.y),
                                              sInt(py*NoiseFreq1.z+NoisePhase1.z),255,Para.NoiseSeed1)
                        + NoiseAmp2*sPerlin2D(sInt(px*NoiseFreq2.y+NoisePhase2.y),
                                              sInt(py*NoiseFreq2.z+NoisePhase2.z),255,Para.NoiseSeed2);

      NoiseZX[Size*y+x] = NoiseAmp1*sPerlin2D(sInt(px*NoiseFreq1.z+NoisePhase1.z),
                                              sInt(py*NoiseFreq1.x+NoisePhase1.x),255,Para.NoiseSeed1)
                        + NoiseAmp2*sPerlin2D(sInt(px*NoiseFreq2.z+NoisePhase2.z),
                                              sInt(py*NoiseFreq2.x+NoisePhase2.x),255,Para.NoiseSeed2);

      PolarPhi[Size*y+x] = sFSin(sATan2(px,py)*Para.PolarXZ*0.5f);
    }
  }



  // do it

  MakeNodes();

  March();

  sAABBoxC box;
  sF32 s = Para.GridSize/2.0f;
  box.Radius.Init(s,s,s);
  box.Center.Init(0,0,0);
  for(sInt i=0;i<4;i++)
    if(Mtrl[i])
      Mtrl[i]->BeforeFrame(Para.LightEnv,1,&box,Matrices.GetCount(),Matrices.GetData());
}