I wanted to create procedural cylinder with some noise. Here is my code:
var mf: MeshFilter;
var cube : GameObject;
var mesh : Mesh;
var iter : int;
var num : int;
var leng : int;
function Start()
{
leng = 10;
iter = 5;
num=0;
var mf: MeshFilter = GetComponent(MeshFilter);
mesh = new Mesh();
mf.mesh = mesh;
MakingVertices(1,iter,leng,0.5f,0.1);
}
function MakingVertices (radius : int, iterations : int, lenggth : int, gap : float, noise : float)
{
var noise_x : float;
var noise_y : float;
var noise_z : float;
var x : float;
var y : float;
var z : float;
var i : int;
var p : int;
var angle : float;
var vertices: Vector3[] = new Vector3[iterations*lenggth];
while(p < lenggth)
{
i=0;
while(i<iterations)
{
noise_x = Random.Range(noise,noise);
noise_y = Random.Range(noise,noise);
noise_z = Random.Range(noise,noise);
angle = (i * 1.0) / iterations * Mathf.PI * 2;
x = Mathf.Sin(angle) * radius;
y = Mathf.Cos(angle) * radius;
vertices *= new Vector3(x+noise_x,y+noise_y,z+noise_z);*

Instantiate(cube,new Vector3(x+noise_x,y+noise_y,z+noise_z),Quaternion.identity);*

i++;*

num++;*

}*

z = z + gap;*

p++;*
 }*
 Debug.Log("Vertices: "+num);*
 mesh.vertices = vertices;*
 MakingTrianges();*
}
function MakingTrianges()
{
 var i : int=0;*
 var j : int=0;*
 var r : int = 0;*
_ var tris: int = new int[3*(leng1)*iter];_  if(tris.Length % 3 == 0) Debug.Log(“Array Correct”);*
_ while(i<(leng1)*iter)_  {*
_ tris[i*3] = i;_
_ if((i+1) % iter == 0) { Debug.Log(“Podzielnosc!”); tris[i*3+1] = 1+i iter; }_
_ else { tris[i*3+1] = 1+i; }_
_ tris[i*3+2] = iter+i;_ 
i++;*
 } *
 mesh.triangles = tris;*
 MakingNormals();*
}
function MakingNormals()
{
 var i : int=0;*
 var normals: Vector3 = new Vector3[num];*
 while(i<num)*
 {*
_ normals = Vector3.forward;_
* i++;*
* }*
* mesh.normals = normals;*
}
I think that there is a problem with MakingTriangles function.
[11185problem.jpg11185]_
As you can see, cubes are instantiated in right position so the vertices should be.
Here is visualization of algorithm that i tried to implement.
_[11186algorytm.jpg*11186]*
_*
_*