删除重复项(相同的多边形计数)Maxscript
Delete Duplicates (same polycount) Maxscript
我想从场景中删除所有重复对象,我想通过比较所有对象的多边形数来找到重复对象。
当我找到每个对象的多边形计数后,我想将具有相同多边形计数的所有对象组合在一起,并删除除其中 1 个之外的所有对象。应该很简单,但是我在构建一个包含所有重复对象的数组时遇到了问题...
我的代码没有抛出任何错误,但没有向#(duplicates) 数组添加任何对象。我的代码确实确定了所有对象的多边形计数并将其放入 objs_info 数组。
-- Remove object duplicates
clearselection()
select geometry
deselect helpers
objs = selection as array
objS_info = #()
objS_info2 = #()
dups = #()
for obj in objs do(
obj_info = #()
obj_dups = #()
ConvertTo obj Editable_Poly
PolyCount_src = polyop.getNumFaces obj
--resetxform obj ; maxOps.CollapseNodeTo obj 1 true --reset Xform + collapse stack
delta_x_src = ((-1 * obj.min.x) + obj.max.x)
delta_z_src = ((-1 * obj.min.z) + obj.max.z)
append obj_info PolyCount_src
delta_ratio_src = delta_x_src/delta_z_src
for i in 1 to objs.count do(
obj_dups = #()
if objs[i] != obj do(
ConvertTo obj Editable_Poly
PolyCount = polyop.getNumFaces obj
--resetxform obj ; maxOps.CollapseNodeTo obj 1 true --reset Xform + collapse stack
delta_x = ((-1 * obj.min.x) + obj.max.x)
delta_z = ((-1 * obj.min.z) + obj.max.z)
delta_ratio = delta_x/delta_z
if(delta_ratio == delta_ratio_src and PolyCount == PolyCount_src) do(
append obj_dups objs[i]
)
)
)
append dups obj_dups
)
format "dups = % \n " obj_dups
非常感谢任何帮助,谢谢!
给猫剥皮的方法有很多种。请注意,测试浮动是否相等(比较边界框大小比率时所做的操作相当冒险(如果您想保留该检查,请参见例如 comparing float values)。按大小分组可以像这样完成:
objsByNumFaces = for obj in geometry where canConvertTo obj mesh collect
(
local snapshot = snapshotAsMesh obj
local data = dataPair obj:obj numFaces:snapshot.numFaces
delete snapshot
data
)
qsort objsByNumFaces (fn _ x y = x.numFaces - y.numFaces)
counter = 0
prevCount = -1
objsPartitioned = #()
for pair in objsByNumFaces do
(
if pair.numFaces == prevCount then
append objsPartitioned[objsPartitioned.count] pair.obj
else
(
prevCount = pair.numFaces
append objsPartitioned #(pair.obj)
)
)
objsPartitioned
数组将包含按面数分组的对象。
我想从场景中删除所有重复对象,我想通过比较所有对象的多边形数来找到重复对象。
当我找到每个对象的多边形计数后,我想将具有相同多边形计数的所有对象组合在一起,并删除除其中 1 个之外的所有对象。应该很简单,但是我在构建一个包含所有重复对象的数组时遇到了问题...
我的代码没有抛出任何错误,但没有向#(duplicates) 数组添加任何对象。我的代码确实确定了所有对象的多边形计数并将其放入 objs_info 数组。
-- Remove object duplicates
clearselection()
select geometry
deselect helpers
objs = selection as array
objS_info = #()
objS_info2 = #()
dups = #()
for obj in objs do(
obj_info = #()
obj_dups = #()
ConvertTo obj Editable_Poly
PolyCount_src = polyop.getNumFaces obj
--resetxform obj ; maxOps.CollapseNodeTo obj 1 true --reset Xform + collapse stack
delta_x_src = ((-1 * obj.min.x) + obj.max.x)
delta_z_src = ((-1 * obj.min.z) + obj.max.z)
append obj_info PolyCount_src
delta_ratio_src = delta_x_src/delta_z_src
for i in 1 to objs.count do(
obj_dups = #()
if objs[i] != obj do(
ConvertTo obj Editable_Poly
PolyCount = polyop.getNumFaces obj
--resetxform obj ; maxOps.CollapseNodeTo obj 1 true --reset Xform + collapse stack
delta_x = ((-1 * obj.min.x) + obj.max.x)
delta_z = ((-1 * obj.min.z) + obj.max.z)
delta_ratio = delta_x/delta_z
if(delta_ratio == delta_ratio_src and PolyCount == PolyCount_src) do(
append obj_dups objs[i]
)
)
)
append dups obj_dups
)
format "dups = % \n " obj_dups
非常感谢任何帮助,谢谢!
给猫剥皮的方法有很多种。请注意,测试浮动是否相等(比较边界框大小比率时所做的操作相当冒险(如果您想保留该检查,请参见例如 comparing float values)。按大小分组可以像这样完成:
objsByNumFaces = for obj in geometry where canConvertTo obj mesh collect
(
local snapshot = snapshotAsMesh obj
local data = dataPair obj:obj numFaces:snapshot.numFaces
delete snapshot
data
)
qsort objsByNumFaces (fn _ x y = x.numFaces - y.numFaces)
counter = 0
prevCount = -1
objsPartitioned = #()
for pair in objsByNumFaces do
(
if pair.numFaces == prevCount then
append objsPartitioned[objsPartitioned.count] pair.obj
else
(
prevCount = pair.numFaces
append objsPartitioned #(pair.obj)
)
)
objsPartitioned
数组将包含按面数分组的对象。