You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.
Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.
rem load all planes...
rem merge all planes into one mesh (for easier manipulation)
level_object_id = 1000 : rem this will be the object ID of the level object once all planes have been merged
make object plain level_object level_object_id, 0, 0
for n = 1 to plane_count
make mesh from object 1, n
add limb level_object_id, n-1, n
rem may have to "offset limb" and "rotate limb" according to object position and object rotation, not sure if those are inherited or not
delete mesh n
rem little trick to merge all limbs into the same mesh...
make mesh from object 1, level_object_id
delete object level_object_id
make object 1, level_object_id, 0
delete mesh 1
rem Now the fun begins! The basic idea is this: iterate through every vertex and search for
rem another vertex that is within a threshold distance. If two are found then they can be
rem merged. This is done by calculating the average position of both and then positioning
rem them both at said average position.
rem complexity is O(n²/2)
threshold_distance# = 1.0 : rem adjust accordingly, should be about a half the size of one plane
lock vertexdata for limb level_object_id, 0
for i = 0 to get vertexdata vertex count() - 1
for j = i to get vertexdata vertex count () - 1
rem get positions of current vertices
this_vert_x# = get vertexdata position x(i)
this_vert_y# = get vertexdata position y(i)
this_vert_z# = get vertexdata position z(i)
other_vert_x# = get vertexdata position x(j)
other_vert_y# = get vertexdata position y(j)
other_vert_z# = get vertexdata position z(j)
rem if distance is smaller than threshold distance... (fast pythagoras algorithm)
if (this_vert_x#-other_vert_x#)^2 + (this_vert_y#-other_vert_y#)^2 + (this_vert_z#-other_vert_z#)^2 < threshold_distance#*threshold_distance
rem calculate average position of both vertices, then position them both at said average position
avg_x# = (this_vert_x# + other_vert_x#) / 2.0
avg_y# = (this_vert_y# + other_vert_y#) / 2.0
avg_z# = (this_vert_z# + other_vert_z#) / 2.0
set vertexdata position i, avg_x#, avg_y#, avg_z#
set vertexdata position j, avg_x#, avg_y#, avg_z#
Login to post a reply