So, I have a two-part problem. I’ve started playing around with mesh/vertex manipulation in code with the information available in the docs. I have a planar that, when hit with a raycast takes the closest x amount of vertices from the hit point and lowers their Y position by 0.02. This works fine.
I wanted to keep the hard, visible edges, so I exported a plane (both flat and curved, to test both) from 3DS with all smoothing groups cleared. With the flat plane, it works fine, but automatically smooths all of the normals, which I don’t want. With the curved plane, it smooths some of the normals, but also breaks some of the edges.
I’ve made sure there are no overlapping vertices, tried messing with the normals and tangents settings in the importer dialog but nothing seems to be working so far.
Does anyone know how to stop both/either of these from happening?
#pragma strict
private var distances : float[];
private var allVerts : Vector3[];
private var indexNum : int[];
var theMesh : Mesh;
var countLength : int;
function Start(){
theMesh = this.GetComponent.<MeshFilter>().mesh;
}
function CheckVerts(hitPos : Vector3){
indexNum = new int[countLength];
var targetPosition : Vector3 = transform.TransformPoint(hitPos);
allVerts = theMesh.vertices;
distances = new float[allVerts.Length];
for(var xx : int = 0; xx < allVerts.Length; xx++){
var myPosition : Vector3 = transform.TransformPoint(allVerts[xx]);
distances[xx] = Vector3.Distance(targetPosition, myPosition);
}
for(var yy : int = 0; yy < indexNum.Length; yy++){
var currentLowestIndex : int;
var lowestNum : float = 1000;
for(var zz : int = 0; zz < distances.Length; zz++){
if(distances[zz] >= 0 && distances[zz] < lowestNum){
currentLowestIndex = zz;
lowestNum = distances[zz];
}
}
indexNum[yy] = currentLowestIndex;
distances[currentLowestIndex] = -100;
}
ChangePositions();
}
function ChangePositions(){
for(var xx : int = 0; xx < indexNum.Length; xx++){
allVerts[indexNum[xx]] = Vector3(allVerts[indexNum[xx]].x, allVerts[indexNum[xx]].y - 0.02, allVerts[indexNum[xx]].z);
}
theMesh.vertices = allVerts;
theMesh.RecalculateBounds();
theMesh.RecalculateNormals();
this.GetComponent.<MeshCollider>().sharedMesh = theMesh;
}