Skip to content

Instantly share code, notes, and snippets.

@Hoikohroh
Created May 5, 2017 06:08
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/b0c76c9f32d4250df46f8ffe2873fc48 to your computer and use it in GitHub Desktop.
Save Hoikohroh/b0c76c9f32d4250df46f8ffe2873fc48 to your computer and use it in GitHub Desktop.
Maxscript:Slice_Axis
/*
Slice Axis
2017/5/5
description
add SliceModifier and GUI
if button pressed , the SliceModifier's sliceplane rotate.
*/
function AddSliceMod obj =(
local sliceMod = sliceModifier()
sliceMod.name = "Slice Axis"
addModifier obj sliceMod
sliceMod
)
function AddCutomAttr mod = (
local setAxis = attributes "setAxis"(
rollout params "SlicePlane Axis"(
radiobuttons coordinate labels:#("Local","World")
-- radiobuttons coordinate labels:#("Local","World","WorkingPivot")
group "Axis"(
button x_axis_btn "x" across:3
button y_axis_btn "y"
button z_axis_btn "z"
)
on x_axis_btn pressed do (
local tmpAngle = (quat 90[0,1,0])
local tmp = selection [1]
local tmpMod = modPanel.getCurrentObject()
if classof(tmpMod) == SliceModifier do(
local tmpPos = tmpMod.slice_plane.position
if coordinate.state == 2 then(
tmpMod.slice_plane.rotation = (quat 0[0,0,1])
local modTM = getModContextTM tmp tmpMod
local offsetTM = rotate tmp.transform tmpAngle
tmpMod.slice_plane.rotation = ((inverse modTM) * (offsetTM)) as quat
tmpMod.slice_plane.position = tmpPos
)else(
tmpMod.slice_plane.rotation = (quat 0[0,0,1])
tmpMod.slice_plane.rotation = tmpAngle
local modTM = getModContextTM tmp tmpMod
local offsetTM = xformMat (inverse modTM) tmp.transform
offsetTM = rotate offsetTM (inverse tmpAngle)
tmpMod.slice_plane.rotation = offsetTM as quat
tmpMod.slice_plane.position = tmpPos
)
)
)
on y_axis_btn pressed do (
local tmpAngle = (quat 90[1,0,0])
local tmp = selection [1]
local tmpMod = modPanel.getCurrentObject()
if classof(tmpMod) == SliceModifier do(
local tmpPos = tmpMod.slice_plane.position
if coordinate.state == 2 then(
tmpMod.slice_plane.rotation = (quat 0[0,0,1])
local modTM = getModContextTM tmp tmpMod
local offsetTM = rotate tmp.transform tmpAngle
tmpMod.slice_plane.rotation = ((inverse modTM) * (offsetTM)) as quat
tmpMod.slice_plane.position = tmpPos
)else(
tmpMod.slice_plane.rotation = (quat 0[0,0,1])
tmpMod.slice_plane.rotation = tmpAngle
local modTM = getModContextTM tmp tmpMod
local offsetTM = xformMat (inverse modTM) tmp.transform
offsetTM = rotate offsetTM (inverse tmpAngle)
tmpMod.slice_plane.rotation = offsetTM as quat
tmpMod.slice_plane.position = tmpPos
)
)
)
on z_axis_btn pressed do (
local tmpAngle = (quat 0[0,0,1])
local tmp = selection [1]
local tmpMod = modPanel.getCurrentObject()
if classof(tmpMod) == SliceModifier do(
local tmpPos = tmpMod.slice_plane.position
if coordinate.state == 2 then(
tmpMod.slice_plane.rotation = (quat 0[0,0,1])
local modTM = getModContextTM tmp tmpMod
local offsetTM = rotate tmp.transform tmpAngle
tmpMod.slice_plane.rotation = ((inverse modTM) * (offsetTM)) as quat
tmpMod.slice_plane.position = tmpPos
)else(
tmpMod.slice_plane.rotation = (quat 0[0,0,1])
tmpMod.slice_plane.rotation = tmpAngle
local modTM = getModContextTM tmp tmpMod
local offsetTM = xformMat (inverse modTM) tmp.transform
offsetTM = rotate offsetTM (inverse tmpAngle)
tmpMod.slice_plane.rotation = offsetTM as quat
tmpMod.slice_plane.position = tmpPos
)
)
)
)
)
custAttributes.add mod setAxis
)
if validModifier $ sliceModifier do(
tmpMod = AddSliceMod $
AddCutomAttr tmpMod
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment