本文整理汇总了C#中UnityEngine.Mesh.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.Clear方法的具体用法?C# Mesh.Clear怎么用?C# Mesh.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Mesh
的用法示例。
在下文中一共展示了Mesh.Clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateArena
// Mesh Generation
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Generate the playground
/// </summary>
public void GenerateArena()
{
//Set the camera
Camera.main.transform.position = transform.position + new Vector3(SizeX / 2.0f, 0, SizeY / 2.0f) + Camera.main.transform.forward * -(Mathf.Max(SizeX, SizeY) + 10);
Camera.main.orthographicSize = Mathf.Max(SizeX, SizeY) * 0.75f;
Camera.main.transform.GetChild(0).localScale = new Vector3(3.6f * Camera.main.orthographicSize, 2.025f * Camera.main.orthographicSize, 1);
//Clean old and set new mesh
mesh = new Mesh();
mesh.name = "Arena";
mesh.Clear();
//Set up the arrays
vertices = new Vector3[(SizeX + 1) * (SizeY + 1)];
triangles = new int[SizeX * SizeY * 6];
uvs1 = new Vector2[vertices.Length];
uvs2 = new Vector2[vertices.Length];
colors = new Color[vertices.Length];
//Set the vertices and vertex colors and uvs
for(int i = 0; i < vertices.Length; i++){
int x = i % (SizeX + 1);
int y = Mathf.FloorToInt(i / (SizeX + 1));
vertices[i] = new Vector3(x, 0, y);
colors[i] = new Color(0.05f, 0.05f, 0.05f, 1);
uvs1[i] = new Vector2((float) x / SizeX, (float) y / SizeY); //Main UV over the full mesh
uvs2[i] = new Vector2(x, y); //Sub uv over only one tile
}
//Set the triangles
for(int i = 0; i < triangles.Length / 6; i++){
int firstTri = i + Mathf.FloorToInt(i / SizeX); //Position of the first tri of the quad
triangles[i * 6] = firstTri;
triangles[i * 6 + 1] = firstTri + (SizeX + 1);
triangles[i * 6 + 2] = firstTri + 1;
triangles[i * 6 + 3] = firstTri + 1;
triangles[i * 6 + 4] = firstTri + (SizeX + 1);
triangles[i * 6 + 5] = firstTri + (SizeX + 2);
}
//Set mesh parts
mesh.vertices = vertices;
mesh.triangles = triangles;
mesh.uv = uvs1;
mesh.uv2 = uvs2;
mesh.colors = colors;
mesh.RecalculateBounds ();
mesh.RecalculateNormals ();
//Assign to components
GetComponent<MeshFilter>().mesh = mesh;
GetComponent<MeshRenderer>().material = FloorMaterial;
generateEdge();
Debug.Log("Arena generated");
}
示例2: addMesh
public static void addMesh(List<MeshAttributes> meshAttributesList, Mesh shipMesh)
{
List<Vector3> shipVertices = new List<Vector3>();
List<int> shipTris = new List<int>();
if (shipMesh.vertices.Count() > 0)
shipVertices = shipMesh.vertices.ToList();
if (shipMesh.triangles.Count() > 0)
shipTris = shipMesh.triangles.ToList();
int lastVertices = shipVertices.Count;
foreach (MeshAttributes meshAttributes in meshAttributesList) {
for (int i = 0; i < meshAttributes.triangles.Length; i++) {
meshAttributes.triangles[i] = meshAttributes.triangles[i] + shipVertices.Count;
}
shipVertices.AddRange(meshAttributes.vertices);
lastVertices = meshAttributes.vertices.Count();
shipTris.AddRange(meshAttributes.triangles);
}
shipMesh.Clear();
shipMesh.vertices = shipVertices.ToArray();
shipMesh.triangles = shipTris.ToArray();
shipMesh.RecalculateNormals();
}
示例3: Begin
public void Begin()
{
gameObject.transform.position = Vector3.zero;
Min = Vector3.one * 1000;
Max = Vector3.one * -1000;
if (gameObject.GetComponent<MeshFilter>() == null)
gameObject.AddComponent<MeshFilter>();
if (gameObject.GetComponent<MeshRenderer>() == null)
gameObject.AddComponent<MeshRenderer>();
mesh = GetComponent<MeshFilter>().mesh;
mesh.Clear();
var rnd = GetComponent<MeshRenderer>();
rnd.material = material;
rnd.receiveShadows = true;
rnd.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
//back = GameObject.Find("BACK");
//if (back.GetComponent<MeshFilter>() == null)
// back.AddComponent<MeshFilter>();
//if (back.GetComponent<MeshRenderer>() == null)
// back.AddComponent<MeshRenderer>();
//mesh_b = back.GetComponent<MeshFilter>().mesh;
//mesh_b.Clear();
//var rnd_b = back.GetComponent<MeshRenderer>();
//rnd_b.material = material;
//rnd_b.receiveShadows = true;
//rnd_b.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
GO = true;
}
示例4: ComputeMesh
public override Mesh ComputeMesh()
{
Vector3 p0 = new Vector3(0, 0, 0);
Vector3 p1 = new Vector3(0, 0.66f, 0);
Vector3 p2 = new Vector3(0.33f, 1, 0);
Vector3 p3 = new Vector3(1, 1, 0);
Vector3 p4 = new Vector3(0.4f, 0.6f, 0);
Vector3 anchor = new Vector3(0.25f, 0.75f, 0);
var vertices = new Vector3[] { p0, p1, p2, p3, p4 };
for(int i = 0; i < vertices.Length; i++)
{
vertices[i].Set(vertices[i].x - anchor.x, vertices[i].y - anchor.y, vertices[i].z - anchor.z);
}
var mesh = new Mesh();
mesh.Clear();
mesh.vertices = vertices;
mesh.triangles = new int[]{
0,1,4,
1,2,4,
2,3,4
};
mesh.colors = new Color[] { new Color(0, 0, 0, 0), new Color(255, 255, 255, 0), new Color(0, 0, 0, 0), new Color(0, 0, 0, 0), new Color(0, 0, 0, 0) };
mesh.RecalculateNormals();
mesh.RecalculateBounds();
mesh.Optimize();
return mesh;
}
示例5: ratio
float gr = (1.0f + Mathf.Sqrt(5.0f)) / 2.0f; //golen ratio (a+b is to a as a is to b)
#endregion Fields
#region Methods
void Start()
{
Nose = GameObject.Find("Nose");
Nose.AddComponent<MeshFilter>();
Nose.AddComponent<MeshRenderer>();
noseMesh = GetComponent<MeshFilter>().mesh;//attach mesh to nose
noseMesh.Clear();
noseMesh.vertices = new Vector3[] {//construct pyramid for nose
new Vector3( gr, 1, 0),
new Vector3( gr-1, -gr*0.6f, -gr*0.75f),
new Vector3( gr-1, -gr*0.6f, gr*0.75f),
new Vector3( gr*1.5f, -gr*0.6f, 0)};
List<int> noseTrianglesIndices = new List<int>() {//arrange triangles
0, 1, 2,
0, 3, 1,
0, 2, 3,
1, 3, 2};
noseMesh.triangles = noseTrianglesIndices.ToArray();
//Set Colour
Material material = new Material(Shader.Find("Standard"));
Color fleshtone = new Color(10, 205, 180);
material.SetColor("fleshtone", fleshtone);
Nose.GetComponent<Renderer>().material = material;
noseMesh.RecalculateBounds();
noseMesh.RecalculateNormals();
noseMesh.Optimize();
}
示例6: Start
void Start()
{
m_meshFilter = gameObject.GetComponent<MeshFilter>();
m_meshRenderer = gameObject.GetComponent<MeshRenderer>();
Mesh mesh = new Mesh();
mesh.name = "testMesh";
mesh.Clear();
Vector3[] vertices = new Vector3[m_triangleCount * 3];
Vector2[] uv = new Vector2[m_triangleCount * 3];
int[] triangles = new int[m_triangleCount * 3];
for (int i = 0; i < m_triangleCount * 3; i++) {
vertices[i] = Random.insideUnitSphere * m_size;
uv[i] = new Vector2(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));
triangles[i] = i;
}
mesh.vertices = vertices;
mesh.uv = uv;
mesh.triangles = triangles;
mesh.RecalculateNormals();
m_meshFilter.mesh = mesh;
m_meshRenderer.renderer.material.color = Color.black;
}
示例7: CreateQuad
static void CreateQuad(Mesh mesh, float W, float H)
{
Vector3[] verts = new Vector3[4];
Vector2[] uvs = new Vector2[4];
verts[0] = new Vector3(-W/2, H/2, 0);
verts[1] = new Vector3(W/2, H/2, 0);
verts[2] = new Vector3(W/2, -H/2, 0);
verts[3] = new Vector3(-W/2, -H/2, 0);
uvs[0] = new Vector2(0, 1);
uvs[1] = new Vector2(1, 1);
uvs[2] = new Vector3(1, 0);
uvs[3] = new Vector3(0, 0);
int[] triangles = new int[6];
triangles[0] = 0;
triangles[1] = 1;
triangles[2] = 3;
triangles[3] = 3;
triangles[4] = 1;
triangles[5] = 2;
mesh.Clear();
mesh.vertices = verts;
mesh.uv = uvs;
mesh.triangles = triangles;
}
示例8: ApplyChunkSettings
public void ApplyChunkSettings(Chunk chunk, CubedObjectBehaviour parent) {
this.chunk = chunk;
renderer.materials = new Material[] { chunk.blockMaterial };
var mesh = new Mesh();
mesh.Clear();
mesh.vertices = chunk.meshData.RenderableVertices.ToArray();
mesh.triangles = chunk.meshData.RenderableTriangles.ToArray();
mesh.uv = chunk.meshData.RenderableUvs.ToArray();
mesh.RecalculateNormals();
var meshFilter = GetComponent<MeshFilter>();
// sharedMesh is null during generation
// TODO: Fix this as the generator shows errors in the console when using mesh vs. sharedMesh
//mesh = (meshFilter.mesh if EditorApplication.isPlayingOrWillChangePlaymode else meshFilter.sharedMesh)
if(Application.isPlaying) meshFilter.mesh = mesh;
else meshFilter.sharedMesh = mesh;
if(parent.colliderType == ColliderType.MeshColliderPerChunk) {
var colliderMesh = new Mesh();
colliderMesh.vertices = chunk.meshData.CollidableVertices.ToArray();
colliderMesh.triangles = chunk.meshData.CollidableTriangles.ToArray();
var meshCollider = GetComponent<MeshCollider>();
if(colliderMesh != null) {
if(meshCollider == null) meshCollider = gameObject.AddComponent<MeshCollider>();
meshCollider.sharedMesh = colliderMesh;
meshCollider.convex = false;
meshCollider.enabled = true;
}
else {
if(meshCollider != null) meshCollider.enabled = false;
}
}
transform.localPosition = (chunk.gridPosition * parent.chunkDimensions).ToVector3() * parent.cubeSize;
}
示例9: Start
public void Start()
{
_mushroom = new GameObject("Mushroom");
_mushroom.AddComponent<MeshFilter>();
_mushroom.AddComponent<MeshRenderer>();
_mesh = new Mesh();
_vertices = new List<Vector3>();
_indices = new List<int>();
_uvs = new List<Vector2>();
_mesh.Clear();
GenerateVertices();
GenerateIndices();
GenerateUvs();
//DrawVertices();
_mesh.vertices = _vertices.ToArray();
_mesh.triangles = _indices.ToArray();
_mesh.uv = _uvs.ToArray();
_mesh.RecalculateBounds();
_mesh.RecalculateNormals();
_mushroom.GetComponent<MeshFilter>().mesh = _mesh;
_mushroom.renderer.material.color = Color.grey;
}
示例10: initialize
private void initialize()
{
if (_sharedMesh == null) {
_sharedMesh = new Mesh ();
}
p_Mesh = _sharedMesh;
p_Vertices = new Vector3[4];
p_Triangles = new int[6];
p_UVs = new Vector2[4];
p_Renderer = GetComponent<MeshRenderer> ();
if (p_Renderer.sharedMaterial == null) {
p_Renderer.sharedMaterial = Resources.GetBuiltinResource <Material> ("Sprites-Default.mat");
}
p_Mesh.Clear ();
p_Filter = GetComponent<MeshFilter>();
p_Triangles[0] = 0;
p_Triangles[1] = 1;
p_Triangles[2] = 2;
p_Triangles[3] = 2;
p_Triangles[4] = 3;
p_Triangles[5] = 0;
}
示例11: AddTypeElement
public bool AddTypeElement(System.Xml.Linq.XElement elemtype)
{
XAttribute fileAtt = elemtype.Attribute("file");
if (fileAtt == null)
{
//Add error message here
return false;
}
string filePath = Path.Combine(Path.GetDirectoryName(new Uri(elemtype.BaseUri).LocalPath), fileAtt.Value);
filePath = Path.GetFullPath(filePath);
// Load the OBJ in
var lStream = new FileStream(filePath, FileMode.Open);
var lOBJData = OBJLoader.LoadOBJ(lStream);
lStream.Close();
meshData = new MeshData[(int)MeshLayer.Count];
Mesh tempMesh = new Mesh();
for (int i = 0; i < meshData.Length; i++)
{
tempMesh.LoadOBJ(lOBJData, ((MeshLayer)i).ToString());
meshData[i] = new MeshData(tempMesh);
tempMesh.Clear();
}
lStream = null;
lOBJData = null;
return true;
}
示例12: BuildMesh
private void BuildMesh (MeshFilter mf, MeshRenderer mr, MeshCollider mc, int i, int j) {
Mesh mesh = new Mesh();
mesh.Clear();
// the vertices of our new mesh, separated into two groups
Vector3[] inner = new Vector3[grid.smoothness + 1]; // the inner vertices (closer to the centre)
Vector3[] outer = new Vector3[grid.smoothness + 1]; // the outer vertices
// vertices must be given in local space
Transform trnsfrm = mf.gameObject.transform;
// the amount of vertices depends on how much the grid is smoothed
for (int k = 0; k < grid.smoothness + 1; k++) {
// rad is the current distance from the centre, sctr is the current sector and i * (1.0f / grid.smoothness) is the fraction inside the current sector
inner[k] = trnsfrm.InverseTransformPoint(grid.GridToWorld(new Vector3(i, j + k * (1.0f / grid.smoothness), 0)));
outer[k] = trnsfrm.InverseTransformPoint(grid.GridToWorld(new Vector3(i + 1, j + k * (1.0f / grid.smoothness), 0)));
}
//this is wher the actual vertices go
Vector3[] vertices = new Vector3[2 * (grid.smoothness + 1)];
// copy the sorted vertices into the new array
inner.CopyTo(vertices, 0);
// for each inner vertex its outer counterpart has the same index plus grid.smoothness + 1, this will be relevant later
outer.CopyTo(vertices, grid.smoothness + 1);
// assign them as the vertices of the mesh
mesh.vertices = vertices;
// now we have to assign the triangles
int[] triangles = new int[6 * grid.smoothness]; // for each smoothing step we need two triangles and each triangle is three indices
int counter = 0; // keeps track of the current index
for (int k = 0; k < grid.smoothness; k++) {
// triangles are assigned in a clockwise fashion
triangles[counter] = k;
triangles[counter+1] = k + (grid.smoothness + 1) + 1;
triangles[counter+2] = k + (grid.smoothness + 1);
triangles[counter+3] = k + 1;
triangles[counter+4] = k + (grid.smoothness + 1) + 1;
triangles[counter+5] = k;
counter += 6; // increment the counter for the nex six indices
}
mesh.triangles = triangles;
// add some dummy UVs to keep the shader happy or else it complains, but they are not used in this example
Vector2[] uvs = new Vector2[vertices.Length];
for (int k = 0; k < uvs.Length; k++) {
uvs[k] = new Vector2(vertices[k].x, vertices[k].y);
}
mesh.uv = uvs;
// the usual cleanup
mesh.RecalculateNormals();
mesh.RecalculateBounds();
mesh.Optimize();
// assign the mesh to the mesh filter and mesh collider
mf.mesh = mesh;
mc.sharedMesh = mesh;
}
示例13: Start
// Use this for initialization
void Start()
{
mesh = new Mesh();
mesh.name = "testMesh";
mesh.Clear();
Vector3[] vertices = new Vector3[4];
vertices[0] = new Vector3(0.0f, 0.0f, 0.0f);
vertices[1] = new Vector3(1.0f, 0.0f, 0.0f);
vertices[2] = new Vector3(1.0f, 1.0f, 0.0f);
vertices[3] = new Vector3(0.0f, 1.0f, 0.0f);
mesh.vertices = vertices;
//TraceMesh(mesh);
int[] triangles = new int[6] { 3, 2, 0, 2, 1, 0};
mesh.triangles = triangles;
mesh.uv = new Vector2[] {
new Vector2 (0, 0),
new Vector2 (0, 1),
new Vector2 (1, 1),
new Vector2 (1, 0)
};
//Vector3[] normals = new Vector3[4] { Vector3.forward, Vector3.forward, Vector3.forward, Vector3.forward };
//mesh.normals = normals;
mesh.RecalculateNormals();
MeshFilter mf = (MeshFilter)gameObject.GetComponent(typeof(MeshFilter));
MeshRenderer mr = (MeshRenderer)gameObject.GetComponent(typeof(MeshRenderer));
mf.mesh = mesh;
mr.material.color = Color.white;
}
示例14: Start
// Use this for initialization
void Start()
{
mesh = GetComponent<MeshFilter> ().mesh;
float x = transform.position.x;
float y = transform.position.y;
float z = transform.position.z;
newVertices.Add( new Vector3 (x , y , z ));
newVertices.Add( new Vector3 (x + 1 , y , z ));
newVertices.Add( new Vector3 (x + 1 , y-1 , z ));
newVertices.Add( new Vector3 (x , y-1 , z ));
newTriangles.Add(0);
newTriangles.Add(1);
newTriangles.Add(3);
newTriangles.Add(1);
newTriangles.Add(2);
newTriangles.Add(3);
mesh.Clear ();
mesh.vertices = newVertices.ToArray();
mesh.triangles = newTriangles.ToArray();
mesh.Optimize ();
mesh.RecalculateNormals ();
}
示例15: ShowMarquee
public void ShowMarquee(RaycastHit hit)
{
verts.Clear ();
uvs.Clear ();
tris.Clear ();
WorldPos pos = RaycastUtility.GetBlockPos (hit);
Block.Direction direction = Block.Direction.up;
float norX = hit.normal.x;
float norY = hit.normal.y;
float norZ = hit.normal.z;
if (norX > 0)
direction = Block.Direction.east;
if (norX < 0)
direction = Block.Direction.west;
if (norY > 0)
direction = Block.Direction.up;
if (norY < 0)
direction = Block.Direction.down;
if (norZ > 0)
direction = Block.Direction.north;
if (norZ < 0)
direction = Block.Direction.south;
BuildFace (pos, direction);
mesh = GetComponent<MeshFilter> ().mesh;
mesh.Clear ();
mesh.vertices = verts.ToArray ();
mesh.triangles = tris.ToArray ();
mesh.uv = uvs.ToArray ();
mesh.RecalculateNormals ();
}