0
您好同胞堆棧溢出成員!首先,感謝您花時間閱讀這個問題。用於在3ds Max中選取對象名稱的MaxScript
我正在學習Maxscript,所以我可以做一些快速和複雜的面部鑽機。 我的腳本已完成99%。唯一的問題是,現在腳本已經硬編碼了要被操縱的目標對象的名字(下面代碼中的「MYOBJECT」)。我不想在MaxScript中忽略對象的名稱,而是想創建一個函數,該函數將打開一個對話窗口,要求我單擊目標面對象,然後在用戶單擊目標對象後,我的代碼將完成它已經能夠完成的工作,但使用選定的對象名稱而不是硬編碼名稱。
我的代碼是波紋管。非常感謝您的幫助!
/*
Script wrote by RDlady:
This script was created following the example from
Paul Neale's tutorial class: https://youtu.be/SKomaUCHAko
Comments and little modifications added by RDlady.
*/
struct facialBoneHelpers (
targetNode=undefined,
controlSize=10,
fn makeControl hit= (
--If the user clicks somewhere, do the code bellow
if hit!=undefined do (
print hit.pos
print hit.dir
--Creates the first helper, the root one (red)
pt=point box:true cross:false axisTripod:true centerMarker:false size:(controlSize/2) wireColor:red name:(uniqueName "PT_ControlRoot)
Zv=hit.Dir
Yv=[0,0,1]
Xv=normalize(cross Yv Zv)
Yv=normalize(cross Zv Xv)
pt.transform=matrix3 Xv Yv Zv hit.pos
--Creates the second helper (green, bigger then the first), which will have the first one as parent
pt2=point box:true cross:false axisTripod:true centerMarker:false size:(controlSize) wireColor:green name:(uniqueName "PT_ControlPos")
pt2.transform=pt.transform
pt2.parent=pt
--Creates an outer circle connector (blue) that will have the second helper as parent
cnt=circle radius:(controlSize) wireColor:blue name:(uniqueName "CNT_Face")
cnt.transform=pt.transform
cnt.parent=pt2
--Converts the circle to a spline, and moves the gizmo out a little bit, so it can be handled more easily
--First, creates a xForm modifier
xf=xForm()
--adds the created modifier to the circle connector
addModifier cnt xf
--defines the Z position of the gizmo of the modifier as the control size, moving it outside
xf.gizmo.pos.z=controlSize
--Finally converts the circle to a spline
convertToSplineShape cnt
)
),
fun runTool= (
tool mouseHit (
on mousePoint clickNo do (
if clickNo>1 do (
r=(mapScreenToWorldRay mouse.pos)
hit=intersectRay targetNode r
makeControl hit
--Creates a mirror helper
if queryBox "Do tou want to make a mirror control" title:"Set mirror" do (
oppositePos = targetNode(ray(r.pos*[-1,1,1])(r.dir*[-1,1,1]))
hit=intersectRay oppositePos
makeControl hit
)
)
)
)
startTool mouseHit
)
)
facialBoneHelpers=facialBoneHelpers()
facialBoneHelpers.targetNode=MYOBJECT
facialBoneHelpers.runTool()
謝謝! pickObject解決了我的問題。 – RDlady