MakeQuad

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Code)
(CSharp - MakeQuad.cs)
 
(One intermediate revision by one user not shown)
Line 15: Line 15:
  
 
<syntaxhighlight lang="csharp">
 
<syntaxhighlight lang="csharp">
 +
// I'd love to hear from you if you do anything cool with this or have any suggestions :)
 +
// www.tenebrous.co.uk
 +
 
using UnityEngine;
 
using UnityEngine;
 
using System.Collections;
 
using System.Collections;

Latest revision as of 11:12, 19 May 2013

Contents

[edit] 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.

[edit] Usage

Mesh myQuad = MeshUtils.MakeQuad( 0, 0, 10, 10 );

[edit] Code

Please feel free to do what you like with this code. The only thing I ask is that you let me know if you use it for anything interesting :)


[edit] CSharp - MakeQuad.cs

// I'd love to hear from you if you do anything cool with this or have any suggestions :)
// www.tenebrous.co.uk
 
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 );
    }
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox