Notifications
Clear all

[Closed] Add lines between old and new spline positions

Hello everyone,

I am trying to make a maxscript that can move the splines of a shape upward in the z direction and then make lines from the starting position to the new height. Does that make sense? I’ll start with this:


And end with this:


| | | | | |
| | | | | |
| | | | | |

So I’ll go from flat lines to square arches. I have a script that has spinner called rail_height that can be dialed up to create the new height, a value called height_holder to keep track of the change in height, and a value called height_master that is the difference between the rail_height and height_holder. The important part of my script so far looks like this:

on rail_height changed val do
(
height_master = (rail_height.value – height_holder)
new_z = $.pos.z
for s = 1 to (numSplines $) do
(
for k = 1 to (numKnots $ s) do
(
knt = getKnotPoint $ s k
in_vec = getInVec $ s k
out_vec = getOutVec $ s k
knt.z = knt.z + height_master
setInVec $ s k in_vec
setOutVec $ s k out_vec
setKnotPoint $ s k knt
updateshape $
height_holder = rail_height.value
)
)
)

That all works fine, so what I need to do now is add something to draw lines between the old knot positions and the new knot positions. I unfortunately don’t have any idea of how to do that. Whether the new lines are independent splines or if they are just knots added to the current lines, either is fine. Any help on this matter would be greatly appreciated.

Thanks in advance

3 Replies

Something like this, maybe?

try destroyDialog railingTest catch()

rollout railingTest "Railing Test"
(
	pickButton pbRailing "Railing Object" autoDisplay:true \
		filter:(fn'' obj = isKindOf obj Shape)
	spinner spnOffset "Offset: " enabled:false range:[-1e6,1e6,0]

	local obj, basePosZ, pickets, ctrl

	on pbRailing picked node do
	(
		obj = node
		basePosZ = obj.objectOffsetPos.z
		pickets = splineShape prefix:"Pickets"
		ctrl = Bezier_Float()

		local pointCount = numPoints obj
		local propStart = (getPropNames pickets).count + 1
		local points = for i = 2 to pointCount by 3 collect
		(
			addNewSpline pickets
			addKnot pickets (i/3 + 1) #corner #line (getPointPos obj i)
			addKnot pickets (i/3 + 1) #corner #line (getPointPos obj i)
			2*i + 1
		)
		updateShape pickets

		for pt in points do animateVertex pickets pt
		local props = getPropNames pickets

		for i = propStart to props.count do
		(
			getPropertyController pickets props[i]
			local pointCtrl = setPropertyController pickets props[i] (Point3_XYZ())
			pointCtrl.z.controller = Float_List()
			pointCtrl.z.controller.available.controller = ctrl
		)
		
		spnOffset.enabled = true
	)

	on spnOffset changed val do with undo on
	(
		if isValidNode obj do obj.objectOffsetPos.z = basePosZ + val
		if isValidNode pickets do ctrl.value = val
	)
)
createDialog railingTest

hey Swordslayer, that worked great! I do need to have one spline in the end, though, so I added your code to mine and tried to do an addAndWeld to attach the two together. When I do, though, it seems to snap the lower vertices to the upper vertices, and I can’t figure out why. I’ve got:

(
obj = $
basePosZ = $.objectOffsetPos.z
pickets = splineShape prefix:“Pickets”
ctrl = Bezier_Float()

            local pointCount = numPoints $
            local propStart = (getPropNames pickets).count + 1
            local points = for i = 2 to pointCount by 3 collect
            (
                addNewSpline pickets
                addKnot pickets (i/3 + 1) #corner #line (getPointPos $ i)
                addKnot pickets (i/3 + 1) #corner #line (getPointPos $ i)
                2*i + 1
            )
            updateShape pickets
            
            for pt in points do animateVertex pickets pt
            local props = getPropNames pickets
            
            for i = propStart to props.count do
            (
                getPropertyController pickets props[i]
                local pointCtrl = setPropertyController pickets props[i] (Point3_XYZ())
                pointCtrl.z.controller = Float_List()
                pointCtrl.z.controller.available.controller = ctrl
            )
            
            if isValidNode pickets do ctrl.value = -height_master
            
        )
        
        if height_changed == 0 do
        (
            addAndWeld $ $Pickets001 0.1
        )

Where $ is the shape I start with and height_changed is just a value that changes from 0 to 1 if the script has run through once so that if you change the height in the spinner, it doesn’t create new splines every time. When I run this, I end up my original spline in the right spot but with two vertices everywhere there should be one, and a shape called Pickets001 with no vertices in it. Again, I am stumped.

I was waiting to reply to you to see if I could figure this out, and then of course 10 minutes after I replied to you I figured it out. I took the weld function out of the changing spinner event and put it in it’s own button, and then it worked great. Thanks for your help.