- Home /
mesh.vertices.position stuck in memory error?
I am coding a level design program, and did a rampyfier to make ramps and stairs from corridors.
the code is written ok and works for all the other objects except the first and last tiles of the roof, the code is telling those objects to line up same as the others but they aren't, in fact one is still flat and the other is being slanted twice. it's as if the first and last obj in the array are being exchanged outside of the code instructions?
i think i may have imported the roof tile wrong? the primitives all are ok but imported mesh = that error. do i have to clear the memory before writing vertices to the next object?
for (var mymeshfilter in mymeshfilters){
var vtxArray : Vector3[];
//Debug.Log ("name "+mymeshfilter.gameObject.transform.name+" objspos "+mymeshfilter.gameObject.transform.position );
var mesh : Mesh = mymeshfilter.gameObject.GetComponent(MeshFilter).mesh;
var scale = basescale;
if (vtxArray == null)
vtxArray = mesh.vertices;
var vertices = new Vector3[vtxArray.Length];
for (var i=0;i<vertices.Length;i++)
{
//var vertex = vtxArray[i];
vtxArray[i] = mymeshfilter.gameObject.transform.TransformPoint(vtxArray[i]);
var vertex = vtxArray[i];
if ( df.z < 0 ){ //depending on travel vector of digger, set joint as maximum or minimum of selected tunnel
if (vtxArray[i].z<=floatmax.z-9){vertex.y += (vtxArray[i].z-floatmin.z+basescale/2)* df.z*extentz*multiplier;}
if (vtxArray[i].z>floatmax.z-9){vertex.y += -3*multiplier;}//convert tunnel to points and mult by slope
}
vertices[i] = mymeshfilter.gameObject.transform.InverseTransformPoint(vertex);
//Debug.Log ("vtx "+vtxArray[i]);
}
mesh.vertices = vertices;
mesh.RecalculateNormals();
mesh.RecalculateBounds();
DestroyImmediate(mymeshfilter.gameObject.collider);
mymeshfilter.gameObject.AddComponent("MeshCollider");
}
}
bump, the only difference between the mesh that makes array errors and the others which tile fine, is that it is an object from sketchup, and it has more vertices than the others. Perhaps I have to try and reimport it from blender ins$$anonymous$$d. maybe it is already but I will do it again.