[Closed] MeshOps_Explode_By_element
i’m sorry cause i think i’ve seen this ques. before but i just can’t find it
just like the topic says … i wanna explode the mesh by its elements
i can’t figure out how to do it
meshOps.explode returns OK in the listener , so what 🙁 ?
fn explodeEMesh mesh_obj =
(
if classOf mesh_obj != Editable_Mesh do return false
local fCount = meshop.getNumFaces mesh_obj
max modify mode
subObjectLevel = 4
while fCount > 0 do
(
local element = meshop.getElementsUsingFace mesh_obj 1
if element.numberset == 0 do return ok
local element_pos = [0,0,0]
for i in element do element_pos += meshop.getFaceCenter mesh_obj i
element_pos = element_pos/element.numberset
local newMesh = meshop.detachFaces mesh_obj element delete:true asMesh:true
update mesh_obj
local emesh = Editable_mesh pos:element_pos
emesh.mesh = newMesh
update emesh
CenterObject emesh
fCount = meshop.getNumFaces mesh_obj
)
)
explodeEMesh $
here are some things for you.
this fn will return an objects elements as an array or arrays:
fn getelements obj=
(
try
(
f=obj.numfaces
eles=#()
done=#()
for i=1 to f do
(
if (finditem done i)==0 then
(
case (classof obj) of
(
editable_mesh:(faces=(meshop.getElementsUsingFace obj #(i)) as array)
editable_poly:(faces=(polyop.getElementsUsingFace obj #(i)) as array)
)
append eles faces
join done faces
)
)
)
catch(eles=undefined)
return eles
)
this routine will detach faces based on a threshold. Use a threshold of 180 to detach by element.
-- www.joshuanewman.net
obj=selection[1]
while obj.faces.count>0 do
(
newmesh=editable_mesh() -- create an empty mesh object
newmesh.pos=obj.pos -- position the new mesh
newmesh.name=(obj.name+"_"+(i as String)) -- name the new mesh
fce=(meshop.getpolysusingface obj #(1) threshold:100) as array
newmesh.mesh=meshop.detachFaces obj fce delete:true asmesh:true
update newmesh -- update the new mesh
update obj -- update the old mesh
)
create yourself a frankenstein if you like or use Merlins exemplary code.
J.
MerlinEl
wooha , thanks for help , i apreciate it
j-man
lots to see in yourr code , naming …also …hehe …thanks …
one more technical ques.
i’ve seen a lot of fragmentation scripts based on slicing , caping … and i’m working on my
own lame version here , but the original idea i was thinking of is using procutter fro the
fragmentation … anyone tried that before and got good results with it ?
i mean based on slicing … its always random Slice_Plane.ROt …and pos …
anyone did a procutter fragmentation version with neat results ?