Skip to content

Instantly share code, notes, and snippets.

@Hoikohroh
Created December 12, 2014 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hoikohroh/8edca90a3ed154b00e0e to your computer and use it in GitHub Desktop.
Save Hoikohroh/8edca90a3ed154b00e0e to your computer and use it in GitHub Desktop.
Maxscript:Vertex_To_Hpr
/*
Veetex_To_Hpr
スクリプト概要
・編集可能ポリゴン内の選択頂点位置にヘルパーを作成
・ヘルパーのZ軸方向を指定する事も可能
既知の問題
・選択オブジェクトのZ軸と、ヘルパーのZ軸が重なる場合、他2軸が定まらない。
*/
try destroyDialog VertToHpr catch()
Rollout VertToHpr "VertToHpr"(
Button btn_Do "ヘルパー作成" width:90 height:40 offset:[0,5]
checkbox chk_Parent "親子付け" offset:[0,5] align:#center
radiobuttons rdo_Axis "Z軸の方向" labels:#("ローカル","ワールド","平均化法線") offset:[0,5]
on btn_Do pressed do(
Temp = selection as array
if Temp.count == 1 then
OBJ = Temp[1]
if classof Temp[1] == Editable_Poly then
try (
Hpr = point()
VArray = polyop.getVertSelection OBJ
for i in VArray do(
V_Pos = polyop.GetVert OBJ i node:OBJ
Case rdo_Axis.state of(
1:(
MakeHpr = instance hpr
MakeHpr.rotation = OBJ.rotation
MakeHpr.Pos = V_Pos
MakeHpr.wirecolor = yellow
if chk_Parent.checked then(MakeHpr.parent = OBJ)
)
2:(
MakeHpr = instance hpr pos:(V_Pos)
MakeHpr.wirecolor = yellow
if chk_Parent.checked then(MakeHpr.parent = OBJ)
)
3:(
F_use_V = polyOp.getFacesUsingVert OBJ i
F_Axis = for n in F_use_V collect(Normal = polyOp.getFaceNormal OBJ n node:OBJ)
Add_Axis = [0,0,0];for o in F_Axis do Add_Axis += o
Axis_Z = normalize Add_Axis
if Axis_Z == OBJ.dir or Axis_Z == -OBJ.dir
then(
Comp = matrixFromNormal Axis_Z
Comp[4] = polyop.GetVert OBJ i
)
else(
Axis_X = normalize (cross (OBJ.dir) Axis_Z)
Axis_Y = normalize (cross Axis_Z Axis_X)
Comp = (matrix3 Axis_X Axis_Y Axis_Z (polyop.GetVert OBJ i))
)
MakeHpr = instance hpr
MakeHpr.transform = Comp
MakeHpr.wirecolor = yellow
if chk_Parent.checked then(MakeHpr.parent = OBJ)
)
)
)
delete Hpr
)
catch()
)
)
createDialog VertToHpr 130 160
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment