/* 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]
MAXScript: a fast weld method?
Hi, In MAXScript: Anybody knows a fast weld method? I have my method below:
Apocalypse, the End of the World!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement