本文整理汇总了C#中Mesh.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.Clone方法的具体用法?C# Mesh.Clone怎么用?C# Mesh.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mesh
的用法示例。
在下文中一共展示了Mesh.Clone方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Model
/// <summary>
/// Loads a Model from the given path and takes a reference to the
/// device it should be draw on.
/// </summary>
/// <param name="path">Path of model.</param>
/// <param name="device">Device to draw to.</param>
public Model(string path, Vector3 drawRotationOffset, Device device)
{
ExtendedMaterial[] exMaterials;
this.drawRotationOffset = drawRotationOffset;
this.models = new List<Model>();
this.mesh = Mesh.FromFile(path, MeshFlags.SystemMemory, device, out exMaterials);
this.textures = new Texture[exMaterials.Length];
this.materials = new Material[exMaterials.Length];
for (int i = 0; i < exMaterials.Length; i++)
{
this.materials[i] = exMaterials[i].Material3D;
this.materials[i].Ambient = materials[i].Diffuse;
if (!String.IsNullOrEmpty(exMaterials[i].TextureFilename))
{
string texturePath = Path.Combine(Path.GetDirectoryName(path), exMaterials[i].TextureFilename);
this.textures[i] = TextureLoader.FromFile(device, texturePath);
}
}
this.mesh = mesh.Clone(mesh.Options.Value, CustomVertex.PositionNormalTextured.Format, device);
this.mesh.ComputeNormals();
}
示例2: onDeviceCreate
protected override void onDeviceCreate(object sender, EventArgs e)
{
base.onDeviceCreate(sender, e);
mesh = Mesh.Box(_device,2.0f,2.0f,2.0f);
meshMaterial = new Material();
meshMaterial.Ambient = Color.White;
meshMaterial.Diffuse = Color.White;
texture = TextureLoader.FromFile(_device,@"..\..\0030.jpg");
Mesh mesh1 = mesh.Clone(mesh.Options.Value,VertexFormats.Position|VertexFormats.Normal|VertexFormats.Texture0|VertexFormats.Texture1,mesh.Device);
using (VertexBuffer vb = mesh1.VertexBuffer) {
CustomVertex.PositionNormalTextured[] verts = (CustomVertex.PositionNormalTextured[])vb.Lock(0, typeof(CustomVertex.PositionNormalTextured), LockFlags.None, mesh1.NumberVertices);
try
{
for (int i = 0; i < verts.Length; i += 4)
{
verts[i].Tu = 0.0f;
verts[i].Tv = 0.0f;
verts[i + 1].Tu = 1.0f;
verts[i + 1].Tv = 0.0f;
verts[i + 2].Tu = 1.0f;
verts[i + 2].Tv = 1.0f;
verts[i + 3].Tu = 0.0f;
verts[i + 3].Tv = 1.0f;
}
mesh = mesh1;
}
finally {
vb.Unlock();
}
}
}
示例3: ChangeMeshColor
/// <summary>
/// Changing the mesh color
/// </summary>
/// <param name="_mesh"></param>
/// <param name="_color"></param>
/// <param name="_device"></param>
/// <returns></returns>
public static Mesh ChangeMeshColor(Mesh _mesh, Color _color, Device _device)
{
Mesh tempMesh = _mesh.Clone(_mesh.Options.Value, Vertex.FVF_Flags, _device);
var vertData =
(Vertex[]) tempMesh.VertexBuffer.Lock(0, typeof (Vertex),
LockFlags.None,
tempMesh.NumberVertices);
for (int i = 0; i < vertData.Length; ++i)
{
vertData[i].color = _color.ToArgb();
}
tempMesh.VertexBuffer.Unlock();
return tempMesh;
}
示例4: MeshClass
/// <summary>
/// For creating shape objects
/// </summary>
/// <param name="type">the name of the object you wish to create</param>
public MeshClass(MeshType type = MeshType.Cube)
{
if (type == MeshType.Cube)
{
ObjectMesh = Mesh.CreateBox(Engine.GameEngine.LocalDevice.ThisDevice, 1f, 1f, 1f);
ObjectMesh.ComputeNormals();
ObjectMesh.Optimize(MeshOptimizeFlags.Compact);
ApplyColor(Color.White);
}
else if (type == MeshType.Sphere)
{
ObjectMesh = Mesh.CreateSphere(Engine.GameEngine.LocalDevice.ThisDevice, .1f, 10, 10);
ObjectMesh.ComputeNormals();
ObjectMesh.Optimize(MeshOptimizeFlags.Compact);
ApplyColor(Color.White);
}
else if (type == MeshType.Teapot)
{
ObjectMesh = Mesh.CreateTeapot(Engine.GameEngine.LocalDevice.ThisDevice);
ObjectMesh.ComputeNormals();
ObjectMesh.OptimizeInPlace(MeshOptimizeFlags.Compact);
ApplyColor(Color.White);
}
else if (type == MeshType.Triangle)
{
VertexPositionColor[] ShapeVertices = new VertexPositionColor[] {
new VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(-1f, 0f, 1f) },
new VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(1f, 0f, 1f) },
new VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(-1f, 0f, -1f) },
new VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(1f, 0f, -1f) },
new VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(0f, 1f, 0f) },
};
var ShapeIndices = new short[] {
0, 2, 1, // base
1, 2, 3,
0, 1, 4, // sides
1, 3, 4,
3, 2, 4,
2, 0, 4,
};
ObjectMesh = new Mesh(Engine.GameEngine.LocalDevice.ThisDevice, ShapeIndices.Length, ShapeVertices.Length, MeshFlags.Managed, VertexPositionColor.Format);
ObjectMesh.LockVertexBuffer(LockFlags.None).WriteRange<VertexPositionColor>(ShapeVertices);
ObjectMesh.UnlockVertexBuffer();
ObjectMesh.LockIndexBuffer(LockFlags.None).WriteRange<short>(ShapeIndices);
ObjectMesh.UnlockIndexBuffer();
Mesh other = ObjectMesh.Clone(Engine.GameEngine.LocalDevice.ThisDevice, MeshFlags.Managed, ObjectMesh.VertexFormat | VertexFormat.Normal | VertexFormat.Texture2);
ObjectMesh.Dispose();
ObjectMesh = null;
//other.ComputeNormals();
ObjectMesh = other.Clone(Engine.GameEngine.LocalDevice.ThisDevice, MeshFlags.Managed, other.VertexFormat);
other.Dispose();
ObjectMesh.Optimize(MeshOptimizeFlags.Compact);
ApplyColor(Color.White);
}
ObjectPosition = Vector3.Zero;
ObjectRotate = Vector3.Zero;
ObjectScale = new Vector3(1, 1, 1);
_world = Matrix.Translation(ObjectPosition);
IsShapeObject = true;
}
示例5: Mesh3D
public Mesh3D(Device device3D, string xFileName,
Vector3 scal, VertexFormats vertexFormat)
{
_device3d = device3D;
Scal = scal;
_vertexFormat = vertexFormat;
string currentDirectory = Application.StartupPath;
try
{
ExtendedMaterial[] materialArray;
//
// Check DirectX |*.x file name
//
if (!xFileName.EndsWith(".x", true, new System.Globalization.CultureInfo("en-US")))
{
throw new Exception(@"Your File is not a DirectX file |*.x" + "\n\rPlease Enter correct FileName.");
}
if (!System.IO.File.Exists(System.Windows.Forms.Application.StartupPath + @"\myMeshs\" + xFileName))
{
throw new NotFoundException("Given path was not found.");
}
Directory.SetCurrentDirectory(Application.StartupPath + @"\myMeshs\");
mesh = Mesh.FromFile(xFileName, MeshFlags.Managed, device3D, out materialArray);
//
// Compute Normals
//
if (vertexFormat == CustomVertex.PositionNormalTextured.Format)
{
mesh = mesh.Clone(mesh.Options.Value, CustomVertex.PositionNormalTextured.Format, device3D);
mesh.ComputeNormals();
}
else if (vertexFormat == CustomVertex.PositionNormalColored.Format)
{
mesh = mesh.Clone(mesh.Options.Value, CustomVertex.PositionNormalColored.Format, device3D);
mesh.ComputeNormals();
}
//
// set data
//
if (materialArray != null && materialArray.Length > 0)
{
MeshMaterials = new Material[materialArray.Length];
MeshTexturs = new Texture[materialArray.Length];
for (int i = 0; i < materialArray.Length; i++)
{
MeshMaterials[i] = materialArray[i].Material3D;
MeshMaterials[i].Ambient = MeshMaterials[i].Diffuse;
if (!string.IsNullOrEmpty(materialArray[i].TextureFilename))
{
MeshTexturs[i] = TextureLoader.FromFile(device3D, materialArray[i].TextureFilename);
}
}
}
ComputeRadius();
optimaize(Math.Max(Math.Max(scal.X, scal.Y), scal.Z));
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, ex.Source,
System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
hasError = true;
}
finally
{
Directory.SetCurrentDirectory(currentDirectory);
}
}
示例6: Render
public void Render(Device device)
{
if (!Loaded)
{
mesh = Mesh.FromFile(Name, MeshFlags.Managed, device, out materialarray);
if ((materialarray != null) && (materialarray.Length > 0))
{
meshmaterials = new Material[materialarray.Length];
meshtextures = new Texture[materialarray.Length];
for (int i = 0; i < materialarray.Length; i++)
{
meshmaterials[i] = materialarray[i].Material3D;
meshmaterials[i].Ambient = meshmaterials[i].Diffuse;
if ((materialarray[i].TextureFilename != null) && (materialarray[i].TextureFilename != string.Empty))
{
meshtextures[i] = TextureLoader.FromFile(device, materialarray[i].TextureFilename);
}
}
}
mesh = mesh.Clone(mesh.Options.Value, CustomVertex.PositionNormalTextured.Format, device);
mesh.ComputeNormals();
Loaded = true;
}
for (int i = 0; i < meshmaterials.Length; i++)
{
device.Material = meshmaterials[i];
device.SetTexture(0, meshtextures[i]);
mesh.DrawSubset(i);
}
//device.DrawUserPrimitives(PrimitiveType.LineList, 12, vertices);
}
示例7: LoadMesh
public void LoadMesh(string Meshname)
{
string sModel;
List<ExtendedMaterial> mtrlBuffer = new List<ExtendedMaterial>();
string sTemp;
sModel = OuterSpace.meshdir + Meshname;
if (File.Exists(sModel))
{
ExtendedMaterial[] mtrlArray = mtrlBuffer.ToArray();
moMesh = Mesh.FromFile(sModel, MeshFlags.Managed, OuterSpace.device, out adj, out mtrlArray);
mtrlBuffer.InsertRange(0, mtrlArray);
if ((moMesh.VertexFormat & VertexFormats.Normal) != VertexFormats.Normal)
{
Mesh tempMesh = moMesh.Clone(moMesh.Options.Value, moMesh.VertexFormat |
VertexFormats.Normal, OuterSpace.device);
tempMesh.ComputeNormals();
moMesh.Dispose();
moMesh = tempMesh;
}
// now initialize our materials and textures
mlMeshMaterials = mtrlBuffer.Count;
materialsList.Clear();
texturesList.Clear();
// Now load our textures and materials
for (int x = 0; x < mtrlBuffer.Count; x++)
{
Material mtrl = new Material();// materialsList[x];
mtrl = mtrlBuffer[x].Material3D;
mtrl.Ambient = mtrl.Diffuse; // because directx sometimes doesnt do this for you
materialsList.Insert(x, mtrl);
if (mtrlBuffer[x].TextureFilename != String.Empty)
{
sTemp = OuterSpace.meshdir + mtrlBuffer[x].TextureFilename;
texturesList.Insert(x, TextureLoader.FromFile(OuterSpace.device, sTemp));
}
}
havemesh = true;
}
else
havemesh = false;
}
示例8: BuildGridGeometry
void BuildGridGeometry()
{
Vector3[] globalverts, gridverts;
int[] globalindices, gridindices, gridindices2;
float dx = 10.0f;
float dz = 10.0f;
// Generate global grid
GenTriGrid(inputImageHeight, inputImageWidth, dx, dz, new Vector3(0.0f, -1000f, 0f), out globalverts, out globalindices);
// Number of sub-grids
int nGridsY = GetGoodAverage(inputImageHeight);
int nGridsX = GetGoodAverage(inputImageWidth);
// Subgrid size
int GridW = inputImageWidth / nGridsX;
int GridD = inputImageHeight / nGridsY;
int gridNumVerts = (GridW+1) * (GridD+1);
int gridNumTris = (GridD ) * (GridW ) * 2;
// Generate subgrid indices
GenTriGrid(GridD+1, GridW+1, dx, dz, new Vector3(0.0f, -5000f, 0f), out gridverts, out gridindices);
GenTriGrid(GridD, GridW, dx, dz, new Vector3(0.0f, -5000f, 0f), out gridverts, out gridindices2);
// Define some often used variables
bool overflowX = false, overflowY = false;
float w = (GridW*nGridsX) * dx;
float d = (GridD * nGridsY) * dz;
Vector3 normal = new Vector3(0f, 1f, 0f);
Mesh mesh;
VertexPositionNormalTextured[] vertexData = new VertexPositionNormalTextured[gridNumVerts];
int subgridX, subgridY, globalIndex, gridIndex;
// foreach subgrid
for (int gridX = 0; gridX < nGridsX; gridX++)
{
for (int gridY = 0; gridY < nGridsY; gridY++)
{
overflowY = false;
overflowX = false;
mesh = new Mesh(Renderer.Instance.device, gridNumTris, gridNumVerts, MeshFlags.Use32Bit, VertexPositionNormalTextured.Format);
// Check for overflow
if ((gridX+1) * (GridW + 1) > inputImageWidth)
overflowX = true;
else if ((gridY+1) * (GridD + 1) > inputImageHeight)
overflowY = true;
if (overflowY || overflowX)
{
}
else
{
for (int subD = 0; subD < GridD + 1; ++subD)
{
for (int subW = 0; subW < GridW + 1; ++subW)
{
subgridX = gridX * GridW + subW;
subgridY = gridY * GridD + subD;
globalIndex = (subgridY * inputImageHeight) + subgridX;
gridIndex = (subD * (GridD + 1)) + subW;
vertexData[gridIndex].Position = globalverts[globalIndex];
//vertexData[gridIndex].Y += GetHeightFromImage(subgridY, subgridX) * scale;
vertexData[gridIndex].Position.Y += SampleHeightMap3x3(subgridY, subgridX) * scale;
vertexData[gridIndex].Normal = normal;
vertexData[gridIndex].TextureCoordinate = new Vector2((vertexData[gridIndex].Position.X + (0.5f * w)) / w, (vertexData[gridIndex].Position.Z - (0.5f * d)) / -d);
}
}
DataStream gs = mesh.LockVertexBuffer(LockFlags.None);
gs.WriteRange<VertexPositionNormalTextured>(vertexData);
gs.Seek(0, SeekOrigin.Begin);
// Todo: Fix AABB and frustrum culling
Vector3 min, max;
//Geometry.ComputeBoundingBox(gs, gridNumVerts, VertexPositionNormalTextured.Format, out min, out max);
mesh.UnlockVertexBuffer();
//int[] meshIndices = new int[gridNumTris * 3];
DataStream ds = mesh.LockAttributeBuffer(LockFlags.None);
for (int i = 0; i < gridNumTris; ++i)
{
ds.Write<int>(0);
}
mesh.UnlockAttributeBuffer();
//meshIndices = ;
gs = mesh.LockIndexBuffer(LockFlags.None);
gs.WriteRange<int>(gridindices);
mesh.UnlockIndexBuffer();
//gs = mesh.LockAttributeBuffer(LockFlags.None);
//gs.Write(meshAttr);
mesh.ComputeNormals();
int[] adj = new int[mesh.FaceCount * 3];
mesh.GenerateAdjacency(float.Epsilon);
//mesh.OptimizeInPlace(MeshFlags.OptimizeAttributeSort | MeshFlags.OptimizeVertexCache | MeshFlags.OptimizeCompact, adj);
Mesh newmesh = mesh.Clone(Renderer.Instance.device, MeshFlags.Managed, VertexPosTexNormalTanBitan.Elements);
//.........这里部分代码省略.........
示例9: LoadMesh
// 메쉬를 불러오는 함수
private void LoadMesh(string filenameWithPath, ref Mesh mesh, ref Material[] meshmaterials, ref Texture[] meshtextures)
{
ExtendedMaterial[] materialarray;
mesh = Mesh.FromFile(filenameWithPath, MeshFlags.Managed, m_device, out materialarray);
if ((materialarray != null) && (materialarray.Length > 0))
{
meshmaterials = new Material[materialarray.Length];
meshtextures = new Texture[materialarray.Length];
for (int i = 0; i < materialarray.Length; i++)
{
meshmaterials[i] = materialarray[i].Material3D;
meshmaterials[i].Ambient = meshmaterials[i].Diffuse;
if ((materialarray[i].TextureFilename != null) && (materialarray[i].TextureFilename != string.Empty))
{
meshtextures[i] = TextureLoader.FromFile(m_device, Class.Renderer.FOLDER_PATH + materialarray[i].TextureFilename);
}
}
}
mesh = mesh.Clone(mesh.Options.Value, CustomVertex.PositionNormalTextured.Format, m_device);
mesh.ComputeNormals();
int[] adjacency = new int[mesh.NumberFaces * 3];
mesh.GenerateAdjacency(0.01F, adjacency);
mesh.OptimizeInPlace(MeshFlags.OptimizeVertexCache, adjacency);
}
示例10: ConvertPosOnlyVertexToPosNormCol
//Converts the positiononly vertices generated from the Mesh.?? creation functions to be positionnomralcolored instead.
public static void ConvertPosOnlyVertexToPosNormCol(Microsoft.DirectX.Direct3D.Device d3dDevice, ref Mesh meshOriginal)
{
Mesh pTempMesh = meshOriginal.Clone(meshOriginal.Options.Value, meshOriginal.VertexFormat | VertexFormats.Normal | VertexFormats.Diffuse, d3dDevice);
pTempMesh.ComputeNormals();
meshOriginal.Dispose();
meshOriginal = pTempMesh;
}
示例11: MeshClass
/// <summary>
/// For creating shape objects
/// </summary>
/// <param name="type">the name of the object you wish to create</param>
public MeshClass(MeshType type)
{
if (type == MeshType.Cube)
{
objectMesh = Mesh.CreateBox(DeviceManager.LocalDevice, 1f, 1f, 1f);
objectMesh.ComputeNormals();
objectMesh.Optimize(MeshOptimizeFlags.Compact);
ApplyColor(Color.White);
}
else if (type == MeshType.Triangle)
{
var ShapeVertices = new CustomVertex.VertexPositionColor[] {
new CustomVertex.VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(-1f, 0f, 1f) },
new CustomVertex.VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(1f, 0f, 1f) },
new CustomVertex.VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(-1f, 0f, -1f) },
new CustomVertex.VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(1f, 0f, -1f) },
new CustomVertex.VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(0f, 1f, 0f) },
};
var ShapeIndices = new short[] {
0, 2, 1, // base
1, 2, 3,
0, 1, 4, // sides
1, 3, 4,
3, 2, 4,
2, 0, 4,
};
objectMesh = new Mesh(DeviceManager.LocalDevice, ShapeIndices.Length, ShapeVertices.Length, MeshFlags.Managed, VertexFormat.Position | VertexFormat.Diffuse);
objectMesh.LockVertexBuffer(LockFlags.None).WriteRange<CustomVertex.VertexPositionColor>(ShapeVertices);
objectMesh.UnlockVertexBuffer();
objectMesh.LockIndexBuffer(LockFlags.None).WriteRange<short>(ShapeIndices);
objectMesh.UnlockIndexBuffer();
Mesh other = objectMesh.Clone(DeviceManager.LocalDevice, MeshFlags.Managed, objectMesh.VertexFormat | VertexFormat.Normal | VertexFormat.Texture2);
objectMesh.Dispose();
objectMesh = null;
other.ComputeNormals();
objectMesh = other.Clone(DeviceManager.LocalDevice, MeshFlags.Managed, other.VertexFormat);
other.Dispose();
objectMesh.Optimize(MeshOptimizeFlags.Compact);
}
ObjectPosition = Vector3.Zero;
ObjectRotate = Vector3.Zero;
ObjectScale = new Vector3(1, 1, 1);
world = Matrix.Translation(ObjectPosition);
Name = type.ToString();
IsShapeObject = true;
}