here is the new script... it does all the detached meshes in 80 seconds on my machine, but it takes longer to create the nodes... and for some unknown reason, the creation time is very long on my laptop (which I currently use while traveling).
It takes about 3 minutes to build all the detached elements on my machine for the above example.
try(destroydialog TakeApartRecurseRol) catch()
rollout TakeApartRecurseRol "Take Apart Recursive" width:191
(
fn memoryStatus = (int (100 * heapFree / heapSize))
fn splitMeshInHalf mesh temp:#() done:#() faces: detach:on pb: = if iskindof mesh TriMesh and mesh.numfaces > 0 do
(
local _detachfaces = meshop.detachfaces
local t0 = timestamp()
local numfaces = mesh.numfaces
local numverts = mesh.numverts
local allfaces = #{1..numfaces}
local verts = for v = 1 to numverts collect #()
for j in allfaces do
(
f = getface mesh j
for k = 1 to 3 do append verts[f[k]] j
)
local out = false
local element = #()
if faces == unsupplied do faces = allfaces
local elements = #{}
local num_elements = 0
for i in faces while not out and not keyboard.escPressed do
(
element = #(i)
for j in element where faces[j] do
(
faces[j] = false
f = getface mesh j
for k = 1 to 3 where verts[f[k]] != undefined do
(
join element verts[f[k]]
verts[f[k]] = undefined
)
)
element = makeuniquearray element
if (elements.numberset + element.count >= numfaces/2) then out = true
else
(
for i in element do append elements i
num_elements += 1
)
)
if num_elements == 0 do
(
for i in element do append elements i
num_elements += 1
)
donefaces = 0
if (elements.numberset < numfaces) then
(
half = _detachfaces mesh elements delete:true asmesh:true
if (num_elements == 1) then
(
append done half
donefaces = half.numfaces
)
else append temp half
--update mesh
)
else
(
if (k = finditem temp mesh) > 0 do deleteitem temp k
append done mesh
donefaces = mesh.numfaces
)
free verts
donefaces
)
label facetype_lb "Use Face: " align:#left offset:[0,4] across:2
radiobuttons facetype_rb labels:#("All", "Selected") columns:2 align:#left offset:[-28,3] offsets:#([0,0],[-13,0]) enabled:off
checkbox recurse_ch " Recursive" checked:on align:#left offset:[0,4] enabled:off across:2
checkbox detach_ch " Detach" align:#left offset:[11,4]
checkbutton mxs_detach_bt "MXS Process" highlightcolor:orange width:172 align:#left offset:[-4,2]
progressbar progress_pb color:orange width:172 height:8 align:#center offset:[0,0]
group "Statistics: "
(
checkbox curr_cb " All Elements" checked:on align:#left offset:[10,0] across:3
label info_01 "0" align:#right offset:[40,0]
label data_01 "" width:20 align:#right offset:[8,0]
checkbox mesh_cb " Element nodes" checked:on align:#left offset:[10,0] across:3
label info_02 "0" align:#right offset:[40,0]
label data_02 "" width:20 align:#right offset:[8,0]
checkbox time_cb " Time" checked:on align:#left offset:[10,0] across:3
label info_03 "0" align:#right offset:[40,0]
label data_03 "s" width:20 align:#right offset:[8,0]
checkbox heap_cb " Memory" checked:on align:#left offset:[10,0] across:3
label info_04 "0" align:#right offset:[40,0]
label data_04 "%" width:20 align:#right offset:[8,0]
)
group "Settings and Debug: "
(
checkbox debugh_ch " Debug" align:#left offset:[0,4] across:2 enabled:off
checkbox gclight_ch " GC Light" align:#left offset:[11,4]
button gc_bt "Garbage Collection" width:172 align:#left offset:[-4,2]
)
fn memoryDisplay =
(
info_04.text = memoryStatus() as string
)
on gc_bt pressed do
(
gc light:gclight_ch.state
memoryDisplay()
completeRedraw()
)
local num
local t0, t1
local h0, h1
on mxs_detach_bt changed state do if state do undo "Detach" off, with redraw off
(
node = selection[1]
if iskindof node GeometryClass do
(
gc light:on
memoryDisplay()
t0 = timestamp()
h0 = heapfree
mesh = snapshotasmesh node
numfaces = mesh.numfaces
donefaces = 0
progress_pb.value = 0
progress_pb.color = orange
factor = 100./numfaces
windows.processPostedMessages()
faces = if facetype_rb.state == 1 then #{1..mesh.numfaces} else (mesh.selectedfaces as bitarray)
done = #()
temp = #(mesh)
data = #(0,0,0,0)
while temp.count > 0 and not keyboard.escPressed and mxs_detach_bt.state do
(
count = temp.count
mesh = temp[1]
if curr_cb.state do
(
v = temp.count
if data[1] != v do info_01.text = (data[1] = v) as string
)
donefaces += splitMeshInHalf mesh temp:temp done:done detach:on
progress_pb.value = donefaces * factor
if curr_cb.state do
(
v = temp.count
if data[1] != v do info_01.text = (data[1] = v) as string
)
if mesh_cb.state do
(
v = done.count
if data[2] != v do info_02.text = (data[2] = v) as string
)
if time_cb.state do
(
v = (timestamp() - t0) / 1000
if data[3] != v do info_03.text = (data[3] = v) as string
)
if heap_cb.state do
(
v = memoryStatus()
if data[4] != v do info_04.text = (data[4] = v) as string
)
windows.processPostedMessages()
)
info_01.text = temp.count as string
info_02.text = done.count as string
info_03.text = ((timestamp() - t0) / 1000) as string
info_04.text = memoryStatus() as string
global _et = temp
global _ed = done
t1 = timestamp()
h1 = heapfree
format "DETACH ... count:% time:% heap:%\n" done.count (t1 - t0) (h0 - h1)
if detach_ch.state do if temp.count == 0 do with redraw off
(
t2 = timestamp()
h2 = heapfree
max create mode
progress_pb.value = 0
progress_pb.color = green
factor = 100./done.count
windows.processPostedMessages()
prefix = node.name + "_"
parts = for k = 1 to done.count while not keyboard.escPressed and mxs_detach_bt.state collect
(
m = done[k]
name = uniquename prefix
n = editable_mesh name:name parent:node
n.mesh = m
progress_pb.value = k * factor
windows.processPostedMessages()
n
)
t3 = timestamp()
h3 = heapfree
format "CREATE ... count:% time:% heap:%\n" parts.count (t3 - t2) (h2 - h3)
completeredraw()
)
)
mxs_detach_bt.state = off
)
on TakeApartRecurseRol open do
(
gc light:on
memoryDisplay()
)
)
createdialog TakeApartRecurseRol
What are your numbers?