Advertisement

MAXScript: a fast weld method?

Started by April 14, 2006 10:19 AM
1 comment, last by Professor420 18 years, 9 months ago
Hi, In MAXScript: Anybody knows a fast weld method? I have my method below:
/* texcoords is an array of point2s representing texture coordinates (not welded)
   and texcoordcount contains the number of texture coordinates (it's texcoords.count at start)
   faces is an array of point3s representing the three texture coordinate indices (not welded) for each face */

-- this function tests if two texture coordinate values are equal
fn IsSame v1 v2 =
(
  local v = v1-v2
  return abs v.x < 0.00001 and abs v.y < 0.00001
)

-- go through all texture coordinates
local old_texcoordcount = texcoordcount
local tverts = #(); tverts.count = texcoordcount
for i = 1 to old_texcoordcount do
(
  -- check for duplications
  local dupl_index = 0
  for j = 1 to i-1 while dupl_index == 0 where IsSame texcoords texcoords[j] do dupl_index = j

  -- if we found something
  if dupl_index != 0 then
  (
    -- decrement the number of texture coordinates
    texcoordcount -= 1

    -- set the duplicated texture coordinate to point to the original texture coordinate
    tverts = dupl_index
  )
)

-- create and assign texture coordinates
setNumTVerts node texcoordcount
local j = 1, k = 0
for i = 1 to old_texcoordcount do
(
  if tverts == undefined then (
    tverts = k
    setTVert node j [texcoords.x, texcoords.y, 0]
    j += 1
  ) else (
    k -= 1
  )
)

-- create and assign texture faces
buildTVFaces node
for i = 1 to faces.count do
(
  local temp = tverts[faces.x]
  if temp > 0 then
    faces.x = temp + tverts[temp]
  else
    faces.x += temp

  temp = tverts[faces.y]
  if temp > 0 then
    faces.y = temp + tverts[temp]
  else
    faces.y += temp

  temp = tverts[faces.z]
  if temp > 0 then
    faces.z = temp + tverts[temp]
  else
    faces.z += temp

  setTVFace node i faces
)
But this method is at least five times slower than meshop.weldVertsByThreshold After some tests, I found that the following line gives me trouble: for j = 1 to i-1 while dupl_index == 0 where IsSame texcoords texcoords[j] do dupl_index = j if I comment it out, the method becomes as fast as meshop.weldVertsByThreshold (I don't know exactly). With the line it took me 5.5 seconds to weld (on a ~2000 polys object), without it < 1 second! (okay, I know I don't even weld without that line, but...) I know: it has to go through 1+2+3+....+number_of_vertices tests of equality, but I didn't come up with something better, so please help me. Anybody know how meshop.weldVertsByThreshold is implemented (sooo fast)? P.S.: I need this to weld texture vertices by a small threshold value (0.00001). It seems there doesn't exist such a feature in MAXScript (like meshop.weldVertsByThreshold for vertices...)[sad]
Apocalypse, the End of the World!
Anyone?
Apocalypse, the End of the World!
Advertisement
Try CGTalk.com
-------------www.robg3d.com

This topic is closed to new replies.

Advertisement