Sabtu, 10 Januari 2015

MESH






Meshes terdiri atas vertices dan triangle arrays. Triangle arrays diindeks dalam array vertex. Tiga index untuk setiap triangle. Untuk setiap vertex terdiri atas normal, koordinat dua texture, warna, dan tangent, ini opsional dan dapat dihilangkan jika diinginkan. Semua informasi vertex disimpan dalam array terpisah pada ukuran yang sama, jadi jika sebuah mesh memiliki 10 verticesmaka kita juga akan memiliki array berukuran 10 untuk normal dan atribut lain. Ada 3 kemungkinan terhadap mofidikasi sebuah mesh.

a.) Membuat sebuah mesh dari awal
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public Vector3[] newVertices;
    public Vector2[] newUV;
    public int[] newTriangles;
    void Start() {
        Mesh mesh = new Mesh();
        GetComponent<MeshFilter>().mesh = mesh;
        mesh.vertices = newVertices;
        mesh.uv = newUV;
        mesh.triangles = newTriangles;
    }
}


b.) Memodikasi atribut vertex setiap frame
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Update() {
        Mesh mesh = GetComponent<MeshFilter>().mesh;
        Vector3[] vertices = mesh.vertices;
        Vector3[] normals = mesh.normals;
        int i = 0;
        while (i < vertices.Length) {
            vertices[i] += normals[i] * Mathf.Sin(Time.time);
            i++;
        }
        mesh.vertices = vertices;
    }
}


c.) Merubah mesh triangle dan vertices terus menerus

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public Vector3[] newVertices;
    public Vector2[] newUV;
    public int[] newTriangles;
    void Update() {
        Mesh mesh = GetComponent<MeshFilter>().mesh;
        mesh.Clear();
        mesh.vertices = newVertices;
        mesh.uv = newUV;
        mesh.triangles = newTriangles;
    }
}



Variables

bindposes The bind poses. The bind pose at each index refers to the bone with the same index.
blendShapeCount Returns BlendShape count on this mesh.
boneWeights The bone weights of each vertex.
bounds The bounding volume of the mesh.
colors Vertex colors of the mesh.
colors32 Vertex colors of the mesh.
isReadable Returns state of the Read/Write Enabled checkbox when model was imported.
normals The normals of the mesh.
subMeshCount The number of submeshes. Every material has a separate triangle list.
tangents The tangents of the mesh.
triangles An array containing all triangles in the mesh.
uv The base texture coordinates of the mesh.
uv2 The second texture coordinate set of the mesh, if present.
vertexCount Returns the number of vertices in the mesh (Read Only).
vertices Returns a copy of the vertex positions or assigns a new vertex positions array.

Constructors

Mesh Creates an empty mesh.

Functions

Clear Clears all vertex data and all triangle indices.
CombineMeshes Combines several meshes into this mesh.
GetBlendShapeName Returns name of BlendShape by given index.
GetIndices Returns the index buffer for the submesh.
GetTopology Gets the topology of a submesh.
GetTriangles Returns the triangle list for the submesh.
MarkDynamic Optimize mesh for frequent updates.
Optimize Optimizes the mesh for display.
RecalculateBounds Recalculate the bounding volume of the mesh from the vertices.
RecalculateNormals Recalculates the normals of the mesh from the triangles and vertices.
SetIndices Sets the index buffer for the submesh.
SetTriangles Sets the triangle list for the submesh.

Inherited members

Variables

hideFlags Should the object be hidden, saved with the scene or modifiable by the user?
name The name of the object.

Functions

GetInstanceID Returns the instance id of the object.
ToString Returns the name of the game object.

Static Functions

Destroy Removes a gameobject, component or asset.
DestroyImmediate Destroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoad Makes the object target not be destroyed automatically when loading a new scene.
FindObjectOfType Returns the first active loaded object of Type type.
FindObjectsOfType Returns a list of all active loaded objects of Type type.
Instantiate Clones the object original and returns the clone.

Operators

bool Does the object exist?
operator != Compares if two objects refer to a different object.
operator == Compares if two objects refer to the same.


Sumber :
1. http://docs.unity3d.com/ScriptReference/Mesh.html

Tidak ada komentar:

Posting Komentar