MakeQuad

From Unify Community Wiki
Revision as of 23:05, 23 November 2011 by Tenebrous (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Description

This is a simple function that creates a quad mesh for you (with two triangles), and sets up the vertices, UVs and triangles appropriately. It returns a Mesh object.

Usage

<csharp> Mesh myQuad = MeshUtils.MakeQuad( 0, 0, 10, 10 ); </csharp>

Code

CSharp - MakeQuad.cs

<csharp> using UnityEngine; using System.Collections;

public class MeshUtils {

   public static Mesh MakeQuad( float originX, float originZ, float sizeX, float sizeZ )
   {
       Mesh newMesh = new Mesh();
       Vector3[] vertices = new Vector3[]
       {
           new Vector3( originX,         0, originZ ),
           new Vector3( originX + sizeX, 0, originZ ),
           new Vector3( originX + sizeX, 0, originZ + sizeZ ),
           new Vector3( originX,         0, originZ + sizeZ )
       };
       int[] triangles = new int[]
       {
           2, 1, 0,
           0, 3, 2
       };
       Vector2[] uvs = new Vector2[]
       {
           new Vector2( 0, 0 ),
           new Vector2( 1, 0 ),
           new Vector2( 1, 1 ),
           new Vector2( 0, 1 )
       };
       newMesh.vertices = vertices;
       newMesh.triangles = triangles;
       newMesh.uv = uvs;
       return ( newMesh );
   }

} </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox