Bradley "Luke" Hylton
  • Game Prototypes
    • Toy Soldiers
    • Sparkly Night
    • Snakes in a 3-Torus
    • Archimedes' Labyrinth
    • Dungeon Swim
  • Technical Art Demos
    • Manual Input Mesh Generation
    • Low Resolution Hand-painted Normal Map
    • Post-Process Shader
    • Miscellaneous Gallery
  • Publications
    • Project Realism
    • uGrounds
  • Art
    • 3D Art >
      • Steampunk Ragdoll
      • Poisoning Series
    • Sprites
    • Photography
    • Miscellaneous
  • Contact

 Manual Input Mesh Generation - Skateboard

Image:

Picture

Text Explanation:

The code (right) is a manual implementation of a basic skateboard deck (above). This demonstrates an ability to place 3D geometric points in space manually with the coordinate system and calculations involving sines for rounded edges. Though this is a simple example, this skill can be used to optimize terrain data, draw procedural meshes and other operations that require directly accessing and manipulating the mesh.

Video:

This tiny game demo demonstrates the mesh and a few simpler manually inputted meshes in an active short game demo.

Source Code:

private var newVertices : Vector3[];
private var newUV : Vector2[];
private var newTriangles : int[];

private var triangles : Array;
private var UVs : Array;
private var vertices : Array;

var width : float = 1.0;
var length : float = 3.0;
var depth : float = 0.1;
var duckHeight : float = 0.2;

private var currentLength : int;
 
function Start () {
        UVs = new Array ();
        newVertices = [Vector3(0,0,0), Vector3(0,0,width), Vector3(length,0,0), Vector3(length,0,width), Vector3(0,0,width/2),
       
                Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-30))),duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-30)))),
                Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-60))),2*duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-60)))),
                Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-90))),duckHeight,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-90)))),
                Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-120))),2*duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-120)))),
                Vector3((width/2)*(0+Mathf.Sin(Mathf.Deg2Rad*(0-150))),duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(0-150)))),
               
                Vector3(length,0,width/2),
                Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(30))),duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(30)))),
                Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(60))),2*duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(60)))),
                Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(90))),duckHeight,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(90)))),
                Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(120))),2*duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(120)))),
                Vector3(length+(width/2)*(Mathf.Sin(Mathf.Deg2Rad*(150))),duckHeight/3,(width/2)*(1+Mathf.Cos(Mathf.Deg2Rad*(150))))  
];     
        currentLength = newVertices.Length;
        vertices = Array(newVertices);

        for (j=0; j<currentLength; j++)
                vertices.Add(Vector3(newVertices[j].x,newVertices[j].y-depth,newVertices[j].z));

        newVertices = vertices.ToBuiltin(Vector3);

        newTriangles = [0,1,3, 0,3,2, 0,9,4, 5,4,6, 6,4,7, 7,4,8, 8,4,9, 5,1,4,
                2,10,15, 15,10,14, 14,10,13, 13,10,12, 12,10,11, 11,10,3 ];

        currentLength = (newTriangles.Length/3);
        triangles = Array(newTriangles);

        for (k=0; k< currentLength; k++){
                triangles.Add(newTriangles[k*3]+16);   
                triangles.Add(newTriangles[k*3+2]+16);
                triangles.Add(newTriangles[k*3+1]+16); 
}      
       triangles.Add(0,2,16, 18,16,2,
                2,15,18, 18,15,31,
                15,14,31, 31,14,30,
                14,13,30, 30,13,29,
                13,12,28, 13,28,29,
                12,11,27, 12,27,28,
                11,3,19, 11,19,27,
                3,1,19, 1,17,19,
                1,5,21, 1,21,17,
                5,6,22, 21,5,22,
                6,23,22, 23,6,7,
                23,7,24, 24,7,8,
                8,25,24, 25,8,9,
                16,25,9, 16,9,0);

        newTriangles = triangles.ToBuiltin(int);

        for (i=0; i< newVertices.length; i++)
                UVs.Add (Vector2(0,0));

        newUV = UVs.ToBuiltin(Vector2);
        var mesh : Mesh = new Mesh ();
        GetComponent.<MeshFilter>().mesh = mesh;

        mesh.vertices = newVertices;
        mesh.uv = newUV;
        mesh.triangles = newTriangles;
        mesh.RecalculateNormals();
}

Powered by Create your own unique website with customizable templates.
  • Game Prototypes
    • Toy Soldiers
    • Sparkly Night
    • Snakes in a 3-Torus
    • Archimedes' Labyrinth
    • Dungeon Swim
  • Technical Art Demos
    • Manual Input Mesh Generation
    • Low Resolution Hand-painted Normal Map
    • Post-Process Shader
    • Miscellaneous Gallery
  • Publications
    • Project Realism
    • uGrounds
  • Art
    • 3D Art >
      • Steampunk Ragdoll
      • Poisoning Series
    • Sprites
    • Photography
    • Miscellaneous
  • Contact