【问题标题】:MaxScript for picking an object name in 3ds Max用于在 3ds Max 中拾取对象名称的 MaxScript
【发布时间】:2017-10-31 11:03:13
【问题描述】:

您好 Stack Overflow 成员!首先,感谢您花时间阅读这个问题。

我正在学习 Maxscript,所以我可以做一些快速而复杂的面部装备。 我的脚本已经完成了 99%。唯一的问题是,现在脚本已经硬编码了要操纵的目标对象的名称(下面的代码中的“MYOBJECT”)。我不想在 MaxScript 中直接写下对象的名称,而是想创建一个函数,该函数将打开一个对话框窗口,要求我单击目标面部 abject,然后在用户单击目标对象后,我的代码将完成它已经能够完成的工作,但使用选定的对象名称而不是硬编码名称。

我的代码如下。非常感谢您的帮助!

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

【问题讨论】:

    标签: 3d max 3dsmax maxscript 3ds


    【解决方案1】:

    如果您有 UI,请使用 pickButton 并在运行前测试它是否包含节点。否则使用pickObject 获取对象——如果返回结果为undefined(我建议这样做),则退出并显示错误消息,或者将pickObject 调用包装在while result == undefined 循环中。

    【讨论】:

      猜你喜欢
      • 2016-01-30
      • 2020-10-28
      • 2015-05-11
      • 2012-10-02
      • 2013-12-08
      • 2010-09-30
      • 2012-03-10
      • 2014-10-18
      • 2020-11-29
      相关资源
      最近更新 更多