[Closed] Separate highres objects quickly
I got inspired to take a stab at this by reading the previous thread about a faster method for retrieving the number of elements of a poly-object,
I have actually searched around for this, but there’s a gazillion people that have posted these kind’s of script, but all that I have found are using the same old slow methods.
I usually deal with lowres objects. so I found that instead of doing detach-operations, I rather snapshot the object and delete every element except the current element to keep. This works great in most cases (whenever I have lowres objects). However when testing on a model with a couple of million polys, it’s embarrassingly slow, logically enough.
I’ve posted my current method longer down, and I don’t expect people to give me a full solution, but if you could give me some hints in regards to a better way to do this it would be greatly appreciated I have thought about preface-script that quickly breaks the object down to X separate (smaller) parts before running the main detacher-functionality, but I feel like that’s just a lazy attempt at “bypassing” the actual problem.
Here’s the current code, any tips and hints are more than welcome
-- FUNCTION: DETACH ALL ELEMENTS OF INPUT OBJECT
function fnDetachElements inputObj =
(
-- For speed purposes
clearSelection()
disableSceneRedraw()
setCommandPanelTaskMode #create
SceneExplorerManager.ClearAllExplorers()
-- Collect all of the elements of the input object
objElements = #()
objFaces = inputObj.faces as bitArray
for faceIndex in objFaces where (objFaces[faceIndex] == true) do
(
currentElement = polyop.getElementsUsingFace inputObj faceIndex
objFaces -= currentElement
append objElements currentElement
)
-- Create a variable to store all detached parts in
detachedParts = #()
-- For each element of the object
for elmIndex=1 to objElements.count do
(
-- Exit/interrupt if escape is pressed
windows.processPostedMessages()
if keyboard.escPressed do ((print ("Interrupted: EscPressed")); enableSceneRedraw(); exit;)
-- Detach the current element (by snapshotting and removing all except current element)
polyOp.setFaceSelection inputObj objElements[elmIndex]
detachedPart = snapShot inputObj
detachedPart.wirecolor = inputObj.wirecolor
convertToPoly detachedPart
polyop.deleteFaces detachedPart -(polyop.getFaceSelection detachedPart)
polyop.deleteIsoVerts detachedPart
detachedPart.pivot = detachedPart.center
inputObj.layer.addNode detachedPart
-- Calculate and print the current progress
currentProgressPerc = (1000.0 / (objElements.count * 10.0 / elmIndex)) as string
print ("Progress: " + currentProgressPerc + "%" + " (" + inputObj.name + ")")
-- Append the detached element to the result
append detachedParts detachedPart
)
-- Cleanup
delete inputObj
select detachedParts
enableSceneRedraw()
-- Return the detached parts
return detachedParts
)
-- Detach the selected object
detachedObjParts = fnDetachElements selection[1]