hello. i am new here, and my problem is probably a beginner problem but it is driving me crazy. my game idea needed a way to procedurally split objects(meshes), CSG boolean substraction would cut it but i am stuck at the beginning. here is the script:
function Start () {
var mesh : Mesh = GetComponent(MeshFilter).mesh;
var newvertices = new Vector3[mesh.triangles.Length];
var newtriangles = new int[mesh.triangles.Length];
for (v = 0; v < mesh.triangles.Length; v++)
{
newvertices[v] = mesh.vertices[mesh.triangles[v]];
newtriangles[v] = i;
}
//-----------------------------------------------------------------------------------------------------
var lenght : int = 0;
var c : int = 0;
for (l = 0; l < newtriangles.Length; l += 3)
{
if (newvertices[newtriangles[l].y < 0 || newvertices[newtriangles[l+1].y < 0 || newvertices[newtriangles[l+1].y < 0)
{
lenght += 3;
}
}
var vertices = new Vector3[lenght];
var triangles = new int[lenght];
for (i = 0; i < newtriangles.Length; i += 3)
{
if (newvertices[newtriangles[i].y < 0 || newvertices[newtriangles[i+1].y < 0 || newvertices[newtriangles[i+1].y < 0)
{
vertices[c] = newvertices[newtriangles[i];
vertices[c+1] = newvertices[newtriangles[i+1];
vertices[c+2] = newvertices[newtriangles[i+2];
triangles[c] = newtriangles[i];
triangles[c+1] = newtriangles[i+1];
triangles[c+2] = newtriangles[i+2];
c += 3;
}
}
//------------------------------------------------------------------------------------------------------------------------
mesh.vertices = vertices;
mesh.triangles = triangles;
var uvs : Vector2[] = new Vector2[mesh.vertices.Length];
for (var u = 0 ; u < uvs.Length; u++)
uvs[u] = Vector2 (mesh.vertices[u].x, mesh.vertices[u].z);
mesh.uv = uvs;
mesh.uv2 = uvs;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
}
basically, it is supposed to cut upper part of the mesh polygons at zero plane. first it copies vertices and rebuilds the triangle array so that every polygon would have 3 of its own. then comes the part of the code(between comment sections) which is supposed to first find the length of the new mesh arrays, declare them, and then fill them with “good” vertices and triangles entry’s. unity reports that errors are in the if conditionals by which vertices are iterated:
- Finished compile Library/ScriptAssemblies/Assembly-UnityScript.dll
Assets/backup.js(20,124): BCE0043: Unexpected token: ).
(Filename: Assets/backup.js Line: 20)
Assets/backup.js(26,35): BCE0043: Unexpected token: ;.
(Filename: Assets/backup.js Line: 26)
Assets/backup.js(27,32): BCE0043: Unexpected token: ;.
(Filename: Assets/backup.js Line: 27)
Assets/backup.js(32,124): BCE0043: Unexpected token: ).
(Filename: Assets/backup.js Line: 32)
Assets/backup.js(34,37): BCE0043: Unexpected token: =.
(Filename: Assets/backup.js Line: 34)
Assets/backup.js(34,66): BCE0044: expecting ), found ‘;’.
(Filename: Assets/backup.js Line: 34)
Assets/backup.js(35,70): BCE0043: Unexpected token: ;.
(Filename: Assets/backup.js Line: 35)
Assets/backup.js(36,70): BCE0043: Unexpected token: ;.
(Filename: Assets/backup.js Line: 36)
Assets/backup.js(56,1): BCE0044: expecting EOF, found ‘}’.
(Filename: Assets/backup.js Line: 56)
dont know what to do…any help i appreciated. thanks.