|
Another Terrain Sewing Solution
#53533
08/29/05 03:36
08/29/05 03:36
|
Joined: Jun 2005
Posts: 656
Grafton
OP
User
|
OP
User
Joined: Jun 2005
Posts: 656
|
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); }
Not two, not one.
|
|
|
Re: Another Terrain Sewing Solution
[Re: Grafton]
#53535
06/19/07 05:46
06/19/07 05:46
|
Joined: Jul 2002
Posts: 5,181 Austria
Blattsalat
Senior Expert
|
Senior Expert
Joined: Jul 2002
Posts: 5,181
Austria
|
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
|
|
|
Re: Another Terrain Sewing Solution
[Re: vlau]
#53537
06/19/07 14:29
06/19/07 14:29
|
Joined: Feb 2006
Posts: 2,185
mpdeveloper_B
Expert
|
Expert
Joined: Feb 2006
Posts: 2,185
|
familiar code there, but nice job
- aka Manslayer101
|
|
|
Re: Another Terrain Sewing Solution
[Re: mpdeveloper_B]
#53538
06/19/07 17:40
06/19/07 17:40
|
Joined: Jul 2002
Posts: 4,436 Germany, Luebeck
Xarthor
Expert
|
Expert
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
|
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 } }
|
|
|
Re: Another Terrain Sewing Solution
[Re: Realspawn]
#53541
06/25/07 22:50
06/25/07 22:50
|
Joined: Jun 2005
Posts: 656
Grafton
OP
User
|
OP
User
Joined: Jun 2005
Posts: 656
|
Great! I Should have thought to ask you about that!
Not two, not one.
|
|
|
Re: Another Terrain Sewing Solution
[Re: Grafton]
#53542
02/29/08 12:45
02/29/08 12:45
|
Joined: Sep 2003
Posts: 265 Coupeville,Wa,USA
Yu_Une
Member
|
Member
Joined: Sep 2003
Posts: 265
Coupeville,Wa,USA
|
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.
Last edited by Yu_Une; 03/01/08 11:00.
Windows Vista Ultimate AMD Phonomn III X2 Biostar T series TA790GX A3+ AMD Radeon HD 4830 in SLI mode 8Gb DDR2 ram
3D Game Studio Commercial upgrade Edition 6.60
Never give up on your dreams.
|
|
|
|