一.分離一個特定元素(Detach Element)
要對一組相同的物體(Editable_Poly)進行分離物體下某一個部分的功能。
本來以爲Editable_Poly裏面會有相關的Element的API,結果全是點(Vert)線(Edge)面(Face),只有一個getElementsUsingFace
而它的參數是 faceList,問題是在polyop裏我還找不到getFace的函數....
也就是說這個界面上的基本操作實際上是封裝了一層的,api層至多到Face層級,沒有更高的層級了。
搜索了一番,找到了兩個有用的函數
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
)
參考:https://www.maxforums.org/forum/thread/maxscript_mesh_elements/1
function detachElements nin_Object =
(
naOut = #()
if classof nin_Object == Editable_Poly do
(
suspendediting()
try
(
undo off
(
with redraw off
(
while polyOp.getNumFaces nin_Object != 0 do
(
elementSel = (polyOp.getElementsUsingFace nin_Object #{1})
baseName = nin_Object.name
newName = (uniqueName baseName)
polyOp.detachFaces nin_Object elementSel asNode:true name:newName
detachedObj = (getNodeByName newName)
append naOut detachedObj
)
for o in naOut do
(
baseName = (substring o.name 1 (o.name.count-3))
uniquePart = (substring o.name (o.name.count-2) o.name.count)
finalName = (baseName + "_" + uniquePart)
o.name = finalName
centerPivot o
)
)
)
)
catch(messageBox "error: detach objects")
resumeediting()
delete nin_Object
)
naOut as array
)
參考:http://www.scriptspot.com/forums/3ds-max/general-scripting/edit-poly-modifier-quick-detach
接下來又是二次開發的工作了,我要把Element相關的操作封裝到一個ElementOp裏面