PDA

View Full Version : Zlax: Relax along Z value only


kopar
11-04-2008, 11:36 PM
Just thought I'd post this here. Had a question in the regular Max forum to see if I could relax along the Z only. Nothing in MAX allows this so I wrote this:
(
/*

Zlax

Relaxes verts only along the Z axis

2008 shannont@pbworld.com

*/
local theQuery = queryBox "This will convert your object into an editable poly.\nALL modifiers will be lost!\nDo you still want to do this?"
if theQuery != false do
(
--functions
fn geomFilt o = (superClassOf o == GeometryClass)

--variables
local theMessage = "Select the object to relax"
local theSourceObject = pickObject message:theMessage prompt:theMessage filter:geomFilt

convertToPoly theSourceObject

--Copy our object to a new one
local theCopy = copy theSourceObject

local numberOfVerts = theCopy.numVerts

--set the relax settings
theCopy.relaxAmount = .25
theCopy.relaxIterations = 4
theCopy.relaxHoldOuterPoints = false
theCopy.relaxHoldBoundaryPoints = false
theCopy.EditablePoly.Relax selLevel:#Object

--Change the Z values for all the original verts based on the z value of the relaxed object
for i = 1 to numberOfVerts do
(
theOriginalVertPos = polyOp.getVert theSourceObject i
theNewVertPos = polyOp.getVert theCopy i
theZrealxedPos = [theOriginalVertPos.x,theOriginalVertPos.y,theNewVertPos.z]
polyOp.setVert theSourceObject i theZrealxedPos
)

delete theCopy
select theSourceObject
)
)
I hope it helps somebody somewhere!

Airflow
11-05-2008, 12:53 AM
What about settings to allo combinations.
ZX XY ZY z x or y.

davius
11-05-2008, 04:15 AM
Wow! Just amazing how your script idea is simple, yet, it works! Thanks for sharing it! I can already see upgraded versions of zlax relaxing in another directions!

kopar
11-05-2008, 04:05 PM
Thanks! I'll probably upgrade it sometime, but what I wrote fits my needs perfectly.

When I do, I'll definitely do the combination (XY, XZ, Z, etc.) thing. Great idea!

PEN
11-05-2008, 04:13 PM
Simple solution, I like it.

PiXeL_MoNKeY
11-05-2008, 06:06 PM
You may want to change your first querybox since you are converting to poly, not mesh.

-Eric

Vsai
01-08-2009, 05:45 PM
Thanks simple and useful (bloody roads and terrains!)

here's a small modification so that it works only on the selected verts, didn't have a chance to add any of the ui bits :)


(
/*

Zlax

Relaxes verts only along the Z axis

2008 shannont@pbworld.com

adjusted to only work on selected verts by Dave Buchhofer dbuchhofer@gmail.com 01-2009

*/
--local theQuery = queryBox "This will convert your object into an editable poly.\nALL modifiers will be lost!\nDo you still want to do this?"
--if theQuery != false do
(
--functions
fn geomFilt o = (superClassOf o == GeometryClass)

local theSourceObject = selection[1]

if (ClassOf theSourceObject == Editable_Poly) and (subobjectLevel == 1) and (theSourceObject.selectedVerts.count != 0) then
(
--Copy our object to a new one
local theCopy = copy theSourceObject

verts = theCopy.selectedVerts as bitarray

--set the relax settings
theCopy.relaxAmount = .25
theCopy.relaxIterations = 4
theCopy.relaxHoldOuterPoints = false
theCopy.relaxHoldBoundaryPoints = false
theCopy.EditablePoly.Relax selLevel:#Object

--Change the Z values for all the original verts based on the z value of the relaxed object
for v in verts do
(
theOriginalVertPos = polyOp.getVert theSourceObject v
theNewVertPos = polyOp.getVert theCopy v
theZrealxedPos = [theOriginalVertPos.x,theOriginalVertPos.y,theNewVertPos.z]
polyOp.setVert theSourceObject v theZrealxedPos
)

delete theCopy
select theSourceObject
subobjectLevel = 1
)else messagebox "Z relax currently only works on Collapsed Editable Poly objects\nand requires a selection at the vertex level."
)
)

davestewart
01-08-2009, 06:56 PM
Maybe create a scripted modifier and allow the gizmo to define the direction...

kopar
01-09-2009, 01:33 PM
Good plan! I've never made a scripted modifier. This one is perfect for it. Thanks for the suggestion. I'll post it when I do it. :D

CGTalk Moderation
01-09-2009, 01:33 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.