Another Terrain Sewing Solution

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:
 

//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);
}


Posted By: Grafton

Re: Another Terrain Sewing Solution - 06/19/07 04:56

Still works with A7!
Posted By: Blattsalat

Re: Another Terrain Sewing Solution - 06/19/07 05:46

thanks a ton!
was about to write one today for myself. your mind reading skills came quite handy

thanks and i will try it asap
cheers
Posted By: vlau

Re: Another Terrain Sewing Solution - 06/19/07 09:17

Looks great! Will try it later.
Thanks for your contribution.
Posted By: mpdeveloper_B

Re: Another Terrain Sewing Solution - 06/19/07 14:29

familiar code there, but nice job
Posted By: Xarthor

Re: Another Terrain Sewing Solution - 06/19/07 17:40

Why not throw the "matrix" var out of the function and pass it as parameter instead?
That way the developer does not have to adjust the code for each terrain and he can use it in multiple levels with different terrains:
Code:

function sew_top_to_bottom(ent1,ent2,matrix) // sew top of ent1 to the bottom of ent2
{
my = ent1;
you = ent2;

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,matrix) // sew left of ent1 to the right of ent2
{
my = ent1;
you = ent2;

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
}
}


Posted By: Grafton

Re: Another Terrain Sewing Solution - 06/19/07 20:19

Quote:

familiar code there, but nice job




Thanks Manslayer, Why is it familiar? The post is two years old, so maybe
you've seen it before?

Great Idea Thunder, I should have done it that way! This was ripped from a
project I was working on at the time and was customized for it.
Posted By: Realspawn

Re: Another Terrain Sewing Solution - 06/25/07 11:24

Since this code is still fully functional i added it to the wdl library
Posted By: Grafton

Re: Another Terrain Sewing Solution - 06/25/07 22:50

Great! I Should have thought to ask you about that!
Posted By: Yu_Une

Re: Another Terrain Sewing Solution - 02/29/08 12:45

sweet I've looking high and low for, since my old pc died, unfortunately I can't afford 3DSMax but I do have Blender 3D which does have 3DS extentions.
© 2024 lite-C Forums