UVW モディファイヤのギズモの位置を、選択した面に合わせる方法はありますか。

次のコードは、UVW_Map モディファイヤの「法線位置合わせ」機能を実装します。[法線位置合わせ](Normal Align)ボタンを押しても、MAXScript には直接アクセスできません。この関数は置換関数として使用でき、ベクトルの乗積の有用性を理解する場合に役立ちます。

スクリプト:

clearListener()
try(DestroyDialog AlignRollout)catch()
Rollout AlignRollout "Align Gizmo"
(    

    button bn_test "Align Gizmo"

     fn alignUVGizmo theObj theFace =
     (        
        -- First get the face normal vector.
        local faceNormal = coordsys theObj (polyop.getFaceNormal theObj theFace)

        -- Get the face center from the editable poly to put the gizmo at that place
        local translation                 = [0,0,0]
        local FaceVertexsIndicesArray    = (polyop.GetFaceVerts theObj theFace)
        local numVerts = FaceVertexsIndicesArray.count
        for i in FaceVertexsIndicesArray do(
            translation += (theObj.GetVertex i)    --Assuming it's an editable poly object
        )
        translation /= numVerts

        -- Create a matrix from the normal
        local theMatrix = MatrixFromNormal faceNormal
        theMatrix.translation = translation --Set our computed translation to be on the face

        -- Create UVWMap modifier
        theMap = Uvwmap()
        -- Add it to the selection
        modPanel.addModToSelection theMap ui:on
        -- Set the transform on it
        theMap.gizmo.transform = theMatrix
    )


    on bn_test pressed do
    (
        if (undefined != $)do
        (
            convertToPoly $        

            -- Align the gizmo of the uv map modifier to the first face of the mesh
            alignUVGizmo $ 2
        )
    )


)
CreateDialog AlignRollout