Scaling 'sweep' spline sub-object.

As part of the Tyre-Tire script I wanted to include an option which would scale the 'Sweep Modifier' custom shape in proportion to changing the radius of the created object.

Whilst a simple 'scale' on the whole object would have done the job perfectly well I was intrigued to see if I could replicate the really easy 'manual' method with some mxs code.

The end result was to add a Linked XForm modifier to the spline object and apply the scale to 'it'......thus scaling the spline sub-object and also updating the 'sweep' modifier.....in real-time.

I have since been reliably informed that this can also be achieved without using the Linked XForm modifier for a more elegant solution.....cue barigazy!

So although a solution is found I very much look forward to seeing the alternative.

Cheers.....(esp barigazy)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
MrTom's picture

Very nice.....

Sorry its been a while since you posted that code....had to do some 'real' work for a change.

Nice code there Barigazy, much cleaner than I had managed.

I'll implement it and tidy up my sloppy code with all haste......once I've had a coffee.

Thanks again.

Regards.

barigazy's picture

...

Yup. It's been a while :)
My pleasure
Cheers!

bga

barigazy's picture

...

I already post the solution how to manually extract custom profile from sweep modifier but just in case...

fn extractSweepSection mody = if isKindOf mody sweep do
(
	local customSection
	if isValidNode (customSection = getNodeByName mody.CustomShapeName) then customSection else
	(
		customSection = if mody.shapes[1] != undefined do (splineshape baseobject:mody.shapes[1])
		if customSection != undefined do mody.shapes[1] = customSection 
	) ; customSection
)
extractSweepSection $.sweep

bga

barigazy's picture

,,,

This is the one of few solutions (maybe someone have better idea) that can solve your problem

fn scaleSpline spl perc: = if isKindOf spl SplineShape or isKindOf spl Line do
(
	fn scaleDist p1: p2: sf: = (p1 + ((p2 - p1) * (sf / 100.)))
	for s = 1 to numSplines spl do
	(
		for k = 1 to numKnots spl s do
		(
			inVec = (scaleDist p1:spl.pivot p2:(getInVec spl s k) sf:perc)
			outVec = (scaleDist p1:spl.pivot p2:(getOutVec spl s k) sf:perc)
			setKnotPoint spl s k (scaleDist p1:spl.pivot p2:(getKnotPoint spl s k) sf:perc)
			setInVec spl s k inVec ; setOutVec spl s k outVec
		)
	)
	updateShape spl
)

Next example shows how to scale star shape 50% that is used as sweep profile

-- example helix spline with star profile
delete objects
guide = Helix radius1:50 radius2:50 height:200 turns:1.5 bias:.2 direction:0 pos:[0,0,0] isSelected:on
profile = convertToSplineShape (Star radius1:20 radius2:10 fillet1:3 fillet2:2 numPoints:5 distort:20 pos:[50,50,0] isSelected:on)
mody = sweep CustomShape:1 ; mody.Shapes[1] = profile
addModifier guide mody
-- scale star shape (profile) 50%
scaleSpline profile perc:50

bga

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.