Posted By: Grafton
Another Terrain Sewing Solution - 08/29/05 03:36
Here is some code I have used to sew terrains together that works well.
One function sews top/bottom and the other sews left/right. The code is
pretty self explanatory. I used this on MDLs not HMPs, but I dont think
it makes a difference. I hope this helps someone
Code:
One function sews top/bottom and the other sews left/right. The code is
pretty self explanatory. I used this on MDLs not HMPs, but I dont think
it makes a difference. I hope this helps someone
Code:
//two functions to sew seams together in MDL tiles
//models must not have the same file name or be duplicates!
//models must have the same number of verts along each side to be sewn
//the #1 vert is upper right in med, lower left in 3dsmax
//set the matrix variable in each sew function to the number of verts along a side.
//
//
function sew_top_to_bottom(ent1,ent2) // sew top of ent1 to the bottom of ent2
{
my = ent1;
you = ent2;
var matrix = 51; //<< set this to the amount of vertices along your models side
var vpos;
var vpos2;
var i=0;
while(i<matrix)
{
i+=1;
vec_for_mesh(vpos,my,i); //my top row
vec_for_mesh(vpos2,you,matrix*(matrix-1) + i);//your bottom row
vpos.z += (vpos2.z + you.z/you.scale_z) - (vpos.z + my.z/my.scale_z);
vpos.x += (vpos2.x + you.x/you.scale_x) - (vpos.x + my.x/my.scale_x);
vpos.y += (vpos2.y + you.y/you.scale_y) - (vpos.y + my.y/my.scale_y);
vec_to_mesh(vpos,my,i); //move my top row vert
}
}
//
function sew_left_to_right(ent1,ent2) // sew left of ent1 to the right of ent2
{
my = ent1;
you = ent2;
var matrix = 51; //<< set this to the amount of vertices along your models side
var vpos;
var vpos2;
var i=0;
while(i<matrix)
{
i+=1;
vec_for_mesh(vpos,my,matrix*i-(matrix-1)); //my left edge
vec_for_mesh(vpos2,you,matrix*i); //your right edge
vpos.z += (vpos2.z + you.z/you.scale_z) - (vpos.z + my.z/my.scale_z);
vpos.x += (vpos2.x + you.x/you.scale_x) - (vpos.x + my.x/my.scale_x);
vpos.y += (vpos2.y + you.y/you.scale_y) - (vpos.y + my.y/my.scale_y);
vec_to_mesh(vpos,my,matrix*i-(matrix-1)); //move my left edge vert
}
}
// Assuming there are nine entity tiles to be sewn together, named terrain1 to terrain9
// that are arranged 3x3 from left to right;
//
// 1 2 3
// 4 5 6
// 7 8 9
//
// we can sew them all together like this;
//
function init_terrain()
{
sew_top_to_bottom(terrain4,terrain1); //sew top of ent1 to bottom of ent2
sew_top_to_bottom(terrain5,terrain2);
sew_top_to_bottom(terrain6,terrain3);
sew_top_to_bottom(terrain7,terrain4);
sew_top_to_bottom(terrain8,terrain5);
sew_top_to_bottom(terrain9,terrain6);
//
sew_left_to_right(terrain2,terrain1); //sew left side of ent1 to right side of ent2
sew_left_to_right(terrain3,terrain2);
sew_left_to_right(terrain5,terrain4);
sew_left_to_right(terrain6,terrain5);
sew_left_to_right(terrain8,terrain7);
sew_left_to_right(terrain9,terrain8);
}