i am having rather a bit of trouble on how to multiply vertices from an object/model(Quad) across an axis(Z or X) like in Pic1 i gather the vertices from the object/model(Quad) then duplicate the vertices along an axis(but have it acceptable for triangles too), i'm having trouble doing this the results are in Pic2.
Would anyone know how to do this?
-Pic1.(what i am trying to achieve)
-Pic2.(the results i am getting)
And here is the code so you know what i have done.
using UnityEngine;
using System.Collections;
public class Extruder : MonoBehaviour {
public Mesh prefab;
public int length;
private Mesh mesh;
private Vector3[] vertices;
private Vector3[] mv;
// Use this for initialization
void Start()
{
vertices = prefab.vertices;
Generate();
}
// Update is called once per frame
void Generate () {
vertices = new Vector3[(length)];
for (int i = 0, x = 0; x <= length; i++, x++)
{
vertices[i] = new Vector3(0, 0, x);
}
mesh.vertices = vertices;
}
private void OnDrawGizmos()
{
Gizmos.color = Color.black;
for (int i = 0; i < vertices.Length; i++)
{
Gizmos.DrawSphere(vertices[i], 0.1f);
}
}
}
These are both pretty good, and recent:
http://jayelinda.com/modelling-by-numbers-part-1a/
http://catlikecoding.com/unity/tutorials/procedural-grid/
It's doing exactly what you asked.
You said:
Draw points along the Z-axis. (0,0,1), (0,0,2), (0,0,3), (0,0,4) .. etc
I think what you wanted was:
Draw points OFFSET FROM THE ORIGINAL by steps along the Z-axise. (x+0, y+0, z+1), (x+0, y+0, z+2), (x+0, y+0, z+3)... etc
So, you've got a lot of code to write:
You will, of course, only be able to do this once. After that, teh mesh is no longer a flat quad in the Z=0 plane, and your "extrusion" would extrude exponentially, and go horribly wrong. Probably you should check that the mesh has a maximum of 4 vertices before you start (except some quads have 6 vertices ...)
This is not how meshes work.
You are missing approximately 20-100 lines of code, minimum. Look for some of the tutorials on procedural mesh generation.
All the extra steps are NOT optional! If you miss them out, sometimes Unity will error, but usually it will silently corrupt the mesh, and/or break your lighting, and/or render nothing. There are no error messages for most of the steps if you forget to do them!
At the VERY LEAST, you MUST HAVE:
...without that, it's literally impossible for Unity to do anything.
You also need, in order to make Unity render it without crashes: