PDA

View Full Version : Loft-like script in progress, need a little help


Malkalypse
11-27-2011, 08:02 PM
This script is VERY basic at this point. For the first step, I'm just looking to more or less duplicate the effect of a renderable spline.

Right now, what I have works generally well for a spline with only minor deviations from a straight path, but anything too loopy and it starts to twist. I've included some code to make a couple example splines. For debugging purposes, I'm having it create point helpers at the places where the mesh vertices will be. Right now I'm looking for suggestions for making the points be non-twisted.

-- Function to create a wavy line
---------------------------------------------------------------------------------------------------------------
fn createWavyLine startPos len den str theName =
(
theSpline = splineShape name:theName
addNewSpline theSpline
addKnot theSpline 1 #smooth #curve startPos
segLength = len / den

for i = 1 to den do addKnot theSpline 1 #smooth #curve [startPos.x + (i * segLength), startPos.y, startPos.z]

addModifier theSpline (noiseModifier())
theSpline.modifiers[1].strength = [str, str, str]
) -- end function (createWavyLine)
---------------------------------------------------------------------------------------------------------------


fn scriptedLoft theObj theRadius =
(
-- Build spline knot position array
------------------------------------------------------------------
splineKnotPosArray = #()

for s = 1 to numSplines theObj do -- for each spline
(
append splineKnotPosArray #()

for k = 1 to numKnots theObj s do -- for each knot in the spline
(
-- Collect the knot position
kPos = getKnotPoint theObj s k
append splineKnotPosArray[s] kPos
) -- end k loop
) -- end s loop
------------------------------------------------------------------


splineKnotVectorArray = #()
worldUpVector = [0,0,1]

for s in splineKnotPosArray do -- for each spline
(
for i = 1 to s.count do -- for the position of each knot in the spline
(
normalArray = #()

-- Get the vectors between each point, and the preceding and following points
if i != 1 do append normalArray (normalize (s[i] - s[i - 1]))
if i != s.count do append normalArray (normalize (s[i + 1] - s[i]))

local theNormal
if normalArray.count == 1
then theNormal = normalArray[1]
else theNormal = normalize (normalArray[1] + normalArray[2])

--theMatrix = matrixFromNormal theNormal; theMatrix.translation = s[i]

/* I guess I need something other than the world up vector ... */
rightVector = normalize (cross worldUpVector theNormal)
upVector = normalize (cross rightVector theNormal)
theMatrix = matrix3 rightVector upVector theNormal s[i]
/* ... but I don't know what I should use instead */


-- Helper points for debugging purposes
-----------------------------------------------
p1 = point size:10 cross:true wirecolor:red
p1.transform = theMatrix
coordSys theMatrix p1.pos = [10, 0, 0]

p2 = point size:10 cross:true wirecolor:green
p2.transform = theMatrix
coordSys theMatrix p2.pos = [0, 10, 0]

p3 = point size:10 cross:true wirecolor:blue
p3.transform = theMatrix
coordSys theMatrix p3.pos = [-10, 0, 0]

p4 = point size:10 cross:true wirecolor:yellow
p4.transform = theMatrix
coordSys theMatrix p4.pos = [0, -10, 0]
----------------------------------------------


) -- end i loop
) -- end s loop
)-- end function (scriptedLoft)



createWavyLine [0,0,0] 320 32 100 "SplineA"
createWavyLine [0,250,0] 320 128 1000 "SplineB"

convertToSplineShape $SplineA
convertToSplineShape $SplineB

scriptedLoft $SplineA 20
scriptedLoft $SplineB 10

denisT
11-28-2011, 03:46 PM
simply (and temporary) create shape's mesh using render_displayRenderMesh flag.
#if you know number of render_sides you know number of loops
#get average plane for every loop
#average normal of the plane gives you the UP vector
#vector from loop's average center to vertex with lowest index gives you SIDE vector
#to get plane's transform is trivial: PSEUDO (matrix3 (cross SIDE UP) SIDE UP CENTER)

that all that you need

CGTalk Moderation
11-28-2011, 03:46 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.