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()
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()
