gpt4 book ai didi

crash - MXS:运行 'delete duplicates'脚本时3ds max崩溃

转载 作者:行者123 更新时间:2023-12-03 16:24:26 33 4
gpt4 key购买 nike

运行脚本时3ds max崩溃。产生一个Windows错误消息框(通过“Windows问题报告”过程)。 Maxscript中不会产生任何错误(脚本运行时侦听器不会显示任何错误)。在脚本运行时,CPU和RAM的使用处于可接受的水平。我的脚本工作正常,没有崩溃,并在只有标准原始对象的较小场景(10-20个对象)上产生了所需的结果。错误/崩溃发生在包含4051个多边形对象的较大场景上。
该脚本查看所有对象,找到相同的对象,并删除除其中一个相同的对象以外的所有对象,从而使您得到一个没有任何重复对象的场景。

在包含4051个对象的场景上运行脚本时,Windows给我一个错误消息框; “3ds max已停止工作-导致程序无法正常工作的问题。Windows将关闭程序并通知您是否有可用的解决方案。”
在脚本运行时,RAM和3ds max的CPU使用率仍然可以接受(根据任务管理器)(30-40%CPU(i5-6600k)和3-4GB RAM(16GB以上))。

“Windows问题报告”错误消息框的图像:
windows problem reporting error message box

该过程在任务管理器中的外观:
enter image description here

脚本运行时期间3ds max的CPU / RAM使用情况的图像:
enter image description here

注意:错误消息框出现后,3ds max的RAM / CPU / DISK使用率将下降到接近零的值。在出现错误消息框后,Windows除了关闭3ds max,没有其他选择。

我已经让脚本运行了很多次,以检查每次运行时是否在同一对象上发生错误消息,不是这样,错误消息发生在不同的对象上(当脚本正在处理不同的对象时) ),每次我运行脚本时。当脚本将场景中的第一个对象(“Mesh_000”)与场景中另一个对象的网格编号在“700”和“900”之间进行比较时,该脚本往往会崩溃。以下数组包含我在执行某些测试期间脚本在其上崩溃的网格的索引:#(805,832,733,766,877)。该脚本会在崩溃前运行10-20分钟。

可以在此处找到导致错误的.max场景:
larger .max scene which causes error

脚本的工作方式如下(伪代码):

duplicate_objs = #()
meshes_array = Collect all meshes in scene
for mesh in meshes_array do(
Compare mesh to all other meshes in meshes_array
if an identical mesh is found do(append duplicate_objs identical_mesh)
)
--Delete all the duplicate meshes:
delete duplicate_objs

我的脚本的代码:
fn fn_construct_objs_array x =(
清空选项()
选择几何
取消选择助手
objs =选择为数组
checked_objs_list =#()
items_to_delete_from_objs =#()
)

fn fn_delete_duplicates equal_pos_boolean =(
--print“删除重复项”
obj_dups =#()
    ConvertTo objs[1] Editable_Poly
PolyCount_src = polyop.getNumFaces objs[1]
TriCount_src = (objs[1].mesh.numFaces)
VertCount_src = (getnumverts objs[1])
Position_src = objs[1].pos

for i in 1 to objs.count do(
if i <= objs.count and objs[i] != objs[1] do(
format "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n--> Comp. original obj (%) to comparison-obj(%) \n" objs[1] objs[i]
ConvertTo objs[i] Editable_Poly
PolyCount = polyop.getNumFaces objs[i]
Tricount = (objs[i].mesh.numFaces)
Position = objs[i].pos
VertCount = (getnumverts objs[i])

if(Tricount == Tricount_src and PolyCount == PolyCount_src and VertCount == VertCount_src and ( if equal_pos_boolean then( Position == Position_src)else(true) )) do(
if((finditem checked_objs_list (objs[i]) == 0) ) do(
appendifunique obj_dups objs[i]; --print "||||||||||||||||||||| FOUND DUPLICATE OBJECT |||||||||||||||||||||| \n"
appendifunique checked_objs_list objs[i]
append items_to_delete_from_objs objs[i]
)-- end if(finditem checked_objs_array objs[i] == 0 ) do(
)-- end if(Tricount == Tricount_src and PolyCount == PolyCount_src and VertCount == VertCount_src and ( if equal_pos_boolean then( Position == Position_src)else(true) )) do(

)-- end if i <= objs.count(
)
for item in items_to_delete_from_objs do(
deleteitem objs (finditem objs item)
)
items_to_delete_from_objs = #()
deleteitem objs 1
for duplicate in obj_dups do(delete duplicate)

if objs.count > 0 do (
--format "objs left to process = % \n" objs.count ;
fn_delete_duplicates equal_pos_boolean
)--end if objs.count > 0 do(
)--end fn_delete_duplicates

fn_construct_objs_array 1
fn_delete_duplicates true

注意:在此情况下,相同的网格定义为具有相同的多边形数,顶点数,边数和位置的网格。

最佳答案

我不擅长调试其他人的代码,因此再次快速浏览一下-我绝对会避免for duplicate in obj_dups do(delete duplicate)中的for循环,delete是一个映射函数,您可以将集合作为参数传递给它。这样,就不会有太多的场景资源管理器更新,并且它应该快得多。我也更喜欢迭代而不是递归。总而言之,这就是我的写法:

struct objInfo
(
obj, polyCount, vertCount, pos,

fn isSamePos pos1 pos2 eps:1e-6 =
(
local diff = pos2 - pos1
dot diff diff < eps
),

fn isEqual info checkPos:off =
(
this.vertCount == info.vertCount and
this.polyCount == info.polyCount and
(not checkPos or isSamePos this.pos info.pos)
),

on create do
(
local polyVertCount = getPolygonCount obj
polyCount = polyVertCount[1]
vertCount = polyVertCount[2]
pos = obj.pos
)
)

fn collectDuplicates checkPos:off =
(
items = for obj in geometry collect objInfo obj:obj
itemCount = items.count
collected = #{}
duplicates = #()

for item = 1 to itemCount where not collected[item] do
(
local current = items[item]

for nextItem = item + 1 to itemCount
where not collected[nextItem] and
(
local next = items[nextItem]
next.isEqual current checkPos:checkPos
)
do
(
append duplicates next.obj
append collected nextItem
)
)

return duplicates
)

delete (collectDuplicates checkPos:off)

关于crash - MXS:运行 'delete duplicates'脚本时3ds max崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49580549/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com