- Home /
joining heightmap on planes
I've got a cube which consist of 6 planes i created. to those planes i attach some height map. i created them myself and the edges of the different height maps are copied to adjacent planes. now because of some rounding errors or something the seems between the two planes have gaps in them. eventually i want to make the planes so big that simply joining meshes wont work
my question, how can i weld two vertices's
i tried putting them on the same spot in space, but i still have some distance between them.
void Connectsectors(GameObject bottom,GameObject front,GameObject left,GameObject rear, GameObject right,GameObject top){
int[] topSide=new int[Size+1];
int[] bottomSide=new int[Size+1];
int[] leftSide=new int[Size+1];
int[] rightSide=new int[Size+1];
for (int i=0;i<(Size+1);i++) {
Debug.Log(i);
leftSide[i]=i;
rightSide[i]=(Size+1)*Size+i;
bottomSide[i]=i*(Size+1);
topSide[i]=(i+1)*(Size+1)-1;
Debug.Log("left"+leftSide[i]);
Debug.Log("right"+rightSide[i]);
Debug.Log("top"+topSide[i]);
Debug.Log("bottom"+bottomSide[i]);
}
Vector3[] verticesBottom=new Vector3[(Size+1)*(Size+1)];
Vector3[] verticesFront=new Vector3[(Size+1)*(Size+1)];
Vector3[] verticesLeft=new Vector3[(Size+1)*(Size+1)];
Vector3[] verticesRear=new Vector3[(Size+1)*(Size+1)];
Vector3[] verticesRight=new Vector3[(Size+1)*(Size+1)];
Vector3[] verticesTop=new Vector3[(Size+1)*(Size+1)];
verticesBottom=bottom.GetComponent<MeshFilter>().mesh.vertices;
verticesFront=front.GetComponent<MeshFilter>().mesh.vertices;
verticesLeft=left.GetComponent<MeshFilter>().mesh.vertices;
verticesRear=rear.GetComponent<MeshFilter>().mesh.vertices;
verticesRight=right.GetComponent<MeshFilter>().mesh.vertices;
verticesTop=top.GetComponent<MeshFilter>().mesh.vertices;
for (int j=0;j<(Size+1);j++){
verticesFront[leftSide[j]]=verticesLeft[rightSide[j]];
verticesLeft[leftSide[j]]=verticesRear[rightSide[j]];
verticesRear[leftSide[j]]=verticesRight[rightSide[j]];
verticesRight[leftSide[j]]=verticesFront[rightSide[j]];
verticesBottom[bottomSide[j]]=verticesRear[bottomSide[Size+1-j]];
verticesBottom[leftSide[j]]=verticesLeft[bottomSide[j]];
verticesBottom[rightSide[j]]=verticesRight[bottomSide[Size+1-j]];
verticesBottom[topSide[j]]=verticesFront[bottomSide[j]];
verticesTop[bottomSide[j]]=verticesFront[topSide[j]];
verticesTop[leftSide[j]]=verticesLeft[topSide[Size+1-j]];
verticesTop[rightSide[j]]=verticesRight[topSide[j]];
verticesTop[topSide[j]]=verticesRear[topSide[Size+1-j]];
}
bottom.GetComponent<MeshFilter>().mesh.vertices = verticesBottom;
bottom.GetComponent<MeshFilter>().mesh.RecalculateBounds();
bottom.GetComponent<MeshFilter>().mesh.RecalculateNormals();
front.GetComponent<MeshFilter>().mesh.vertices = verticesFront;
front.GetComponent<MeshFilter>().mesh.RecalculateBounds();
front.GetComponent<MeshFilter>().mesh.RecalculateNormals();
left.GetComponent<MeshFilter>().mesh.vertices = verticesLeft;
left.GetComponent<MeshFilter>().mesh.RecalculateBounds();
left.GetComponent<MeshFilter>().mesh.RecalculateNormals();
rear.GetComponent<MeshFilter>().mesh.vertices = verticesRear;
rear.GetComponent<MeshFilter>().mesh.RecalculateBounds();
rear.GetComponent<MeshFilter>().mesh.RecalculateNormals();
right.GetComponent<MeshFilter>().mesh.vertices = verticesRight;
right.GetComponent<MeshFilter>().mesh.RecalculateBounds();
right.GetComponent<MeshFilter>().mesh.RecalculateNormals();
top.GetComponent<MeshFilter>().mesh.vertices = verticesTop;
top.GetComponent<MeshFilter>().mesh.RecalculateBounds();
top.GetComponent<MeshFilter>().mesh.RecalculateNormals();
}
i fixed it. placing the vertices's did work, but there is a fault in the code above. where i paste the vertices's onto other planes and the edge is revert i have to use [Size-j] ins$$anonymous$$d of [Size+1-j]. now all i have to do is copy the mesh into the collider, but that is easy
Your answer
Follow this Question
Related Questions
Issue with importing raw heightmaps (made in photoshop) 5 Answers
Animated Height map driving terrain 0 Answers
Spherical Terrain or screenshot to texture 0 Answers
Writing a Custom Collider 0 Answers
ngui input help 0 Answers