PDA

View Full Version : DetachFacesBy ID 4Fun :-)


MerlinEl
06-24-2011, 03:36 PM
Hi

Here is a script for detaching faces by material ID
Do you know a better way? ;)


fn randomColor=(color (random 1 255) (random 1 255) (random 1 255))
fn createTestMesh =
(
local obj = (convertToPoly (sphere segments:100 radius:200))

polyOp.setFaceMatID obj #{1..1000} 2
polyOp.setFaceMatID obj #{1000..2000} 8
polyOp.setFaceMatID obj #{2000..3000} 9
polyOp.setFaceMatID obj #{3000..4000} 22
local mm = multimaterial numsubs:10
for i in mm do i.diffusecolor = randomColor()
obj.material = mm
select obj
)



fn getSimilarFacesByID obj id =
(
for f in obj.faces where polyOp.getFaceMatID obj f.index == id collect f.index
)

fn detachFacesByID =
(
local start = timeStamp()

createTestMesh()
local obj = selection[1]
if classOf obj != Editable_Poly do return false
local cnt = 0
while obj.faces.count > 0 and not keyboard.escPressed do
(
cnt+=1
local faces = getSimilarFacesByID obj cnt
polyOp.detachFaces obj faces delete:true asNode:true name:(uniqueName obj.name)
)
delete obj

local end = timeStamp()
format "Processing took % seconds\n" ((end - start) / 1000.0)
)
detachFacesByID()

denisT
06-24-2011, 05:56 PM
fn setMatID node:selection[1] rangeID:[1,64] =
(
for f in (node.faces as bitarray) do polyop.setfacematid node f (random rangeID[1] rangeID[2])
)
fn getMatID node:selection[1] =
(
ids = #{}
for f in (node.faces as bitarray) do append ids (polyop.getfacematid node f)
ids
)
fn detachByID node:selection[1] =
(
ids = getMatID node:node
with redraw off for id in ids do
(
node.selectByMaterial id
if (polyop.detachfaces node node.selectedfaces delete:on asnode:on name:("id_" + id as string)) do objects[objects.count].parent = node
)
)
/*
delete objects
sp = converttopoly (sphere name:"sp" segments:32)
setMatID node:sp
detachByID node:sp
*/

MerlinEl
06-24-2011, 06:07 PM
fn setMatID node:selection[1] rangeID:[1,64] =
(
for f in (node.faces as bitarray) do polyop.setfacematid node f (random rangeID[1] rangeID[2])
)
fn getMatID node:selection[1] =
(
ids = #{}
for f in (node.faces as bitarray) do append ids (polyop.getfacematid node f)
ids
)
fn detachByID node:selection[1] =
(
ids = getMatID node:node
with redraw off for id in ids do
(
node.selectByMaterial id
if (polyop.detachfaces node node.selectedfaces delete:on asnode:on name:("id_" + id as string)) do objects[objects.count].parent = node
)
)
/*
delete objects
sp = converttopoly (sphere name:"sp" segments:32)
setMatID node:sp
detachByID node:sp
*/


Very Nice Denis :-D wow! clean and fast way, thanks for you share :thumbsup:

CGTalk Moderation
06-24-2011, 06:07 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.