PDA

View Full Version : Spline with varying offsets


milfora
06-05-2008, 12:51 AM
Hi,

I'm quite new to MaxScript (and loving it!). Its just opening a whole world of possibilities!

I have a small query on a script I'm currently writing. It enables a user to offset a selected spline at varying offsets, with an option to control the amount of segments of the new spline, and creating a new spline object perpendicular to the base spline.

I'm quite happy with the initial functionality of creating a new spline, but what I would love for it to do is work as a modifier. I would like to take this program and create a modifier similar to the bevel modifier (ie. create a mesh between the two splines), and then have the ability to came back to the modifier and adjust the values at a later date.

I've scanned the MaxScript documentation (just keeps getting better Bobo!), and cannot seem to find anything to assist me.

Any thoughts/suggestions would be greatly appreciated

AM

I've attached the code up to now - just to get an idea of what I am looking to do.



/*
Create an offset string with varying widths (if the user specifies)
By Andrew Milford
SKM Consulting June 2008
*/
--macroScript OffsetMultipleVary category:"Drews Civil"
(
global OffsetMultipleVary
global sr = undefined -- global new offset splineShape variable (allows for dynamic movement)
try(destroy OffsetMultipleVary) catch()

on isEnabled return
(
selection.count == 1 and \
(classof selection[1] == SplineShape or \
classof selection[1] == Line) \
and selection[1].modifiers.count == 0
)

on execute do
(

rollout OffsetMultipleVary "Offset Multiple Vary"
(

spinner spn_OffsetStart "Start Offset" type:#float fieldwidth:50 align:#left range:[-1000,1000,0]
spinner spn_OffsetEnd "End Offset" type:#float fieldwidth:50 align:#left range:[-1000,1000,0]
spinner spn_Segments "Segments" type:#integer fieldwidth:50 align:#left range:[1,100,10]
checkbox chk_LockOffsets "Lock Offsets" type:#boolean fieldwidth:50 align:#left checked:true

fn OffsetSplineVary obj os1 os2 =
(
-- declare local variables
local sp = $
--Format "SP: %" sp
local curveLen = curveLength sp -- length of full spline curve
local offsetStart = os1
local offsetEnd = os2
local offsetDiff = os2 - os1
local arrOffset = #()
local counter = 1

--if chk_LockOffsets.checked == true then os2 = os1


-- cycle through spline - evenly distribute points according to number of specified segments
--loop = (1.0/spn_Segments.value)

--for i = 0.0 to 1.0 by (1.0/spn_Segments.value) do
for i = 0 to spn_Segments.value do
(
--local p = findLengthSegandParam sp 1 i
local percent = (i*1.0)/spn_Segments.value -- get percent along path as float
--Format "Segment: % \tPercent %\n" i percent
local p = findLengthSegandParam sp 1 percent
local segNum = p.x as integer
local pathDist = p.y
--format "Segment %, Distance %\n" segNum pathDist
local pathp = false
local pt = interpBezier3D sp 1 segnum pathDist pathParam:pathp
local tn = tangentBezier3D sp 1 segNum pathDist pathParam:pathp
local rot = quat 90 [0,0,1]
local os = (offsetDiff * i) + os1
arrOffset[counter] = (pt + (tn * rot * os))
--print i
counter += 1
)
--format "Offset: %\n" arrOffset.count
--format "Internal Loop: %\n" counter

-- loop through array offset
if sr != undefined then delete sr -- if object exists in this session, delete it
sr = splineShape() -- recreate splineShape
addnewSpline sr
for i = 1 to arrOffset.count do
(
addknot sr 1 #corner #line arrOffset[i]
)
--updateshape sr
sr.vertexTicks = true ; sr.wirecolor = blue

) -- end function

on spn_OffsetStart changed val do
(
--format "Start Offset: %\n" val
if $ != undefined do
(
if chk_LockOffsets.checked == true then spn_OffsetEnd.value = spn_OffsetStart.value
OffsetSplineVary $ spn_OffsetStart.value spn_OffsetEnd.value
)
)
on spn_OffsetEnd changed val do
(
--format "End Offset: %\n" val

if $ != undefined do
(
if chk_LockOffsets.checked == true then spn_OffsetStart.value = spn_OffsetEnd.value
OffsetSplineVary $ spn_OffsetStart.value spn_OffsetEnd.value
)
)
on spn_Segments changed val do
(
if $ != undefined do
(
if chk_LockOffsets.checked == true then spn_OffsetEnd.value = spn_OffsetStart.value
OffsetSplineVary $ spn_OffsetStart.value spn_OffsetEnd.value
)
)

on chk_LockOffsets changed theState do
(
if $ != undefined do
(
if theState == true then spn_OffsetEnd.value = spn_OffsetStart.value
OffsetSplineVary $ spn_OffsetStart.value spn_OffsetEnd.value
)
)

) -- end rollout
createdialog OffsetMultipleVary 200 100
) -- end on execute
) -- end macroScript

CGTalk Moderation
06-05-2008, 12:51 AM
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.