/* spline_text.txt */ /* * This script builds a varrying diameter tube along selected paths. * It shows how to use spline evaluation functions in ASL to build * geometry that follows tho path and orientation of a spline. * * Written by R. Steve Glanville. Fell free to use it as you like. * */ /* Declare some working variables: */ object $curObject; shape $shape, $shapes[0], $childShapes[1]; shape $tube; int $ii, $jj, $kk, $numSplines; point3 $p0, $p1; quaternion $q0; float $theta; /* Arrays to hold tube cross sections: */ point3 $smallSection[6], $largeSection[6]; /* Build cross sections: */ for $ii = 0 to 5 do { $theta = $ii/6.0; $p0.x = cos($theta*2*3.14159); $p0.y = sin($theta*2*3.14159); $p0.z = 0.0; $smallSection[$ii] = $p0; $p1 = $p0*5; $largeSection[$ii] = $p1; } $curObject = project.curObject; $curObject.GetShapes($childShapes); $shapes.size = 0; while ($childShapes.size > 0) $shapes.push($childShapes.pop()); while ($shapes.size > 0) { $shape = $shapes.pop(); if ($shape.GetKind() == SHAPE_KIND_PATH && $shape.Selected) { $tube = mesh(); $tube.Open(); $numSplines = $shape.GetNumSplines(); for $ii = 0 to $numSplines - 1 do { spline $spline; float $length, $t; int $num, $prev; float4x4 $xformMat; $spline = $shape.GetSpline($ii); $length = $spline.GetLength(); /* * Extrude a tube along a spline building in an enlarged * bump every 10 units. */ $num = $length/2.5; for $jj = 0 to $num do { $t = $jj/($num*1.0); $p0 = $spline.Eval($t); $q0 = $spline.Orientation($t); $xformMat = toFloat4x4($q0); if (($jj % 4) == 0 || ($jj % 4) == 1) { for $kk = 0 to 5 do { $p1 = $smallSection[$kk]; $p1 = $xformMat.Project($p1) + $p0; $tube.AddPoint($p1); } } else { for $kk = 0 to 5 do { $p1 = $largeSection[$kk]; $p1 = $xformMat.Project($p1) + $p0; $tube.AddPoint($p1); } } if ($jj > 0) { $prev = 5; for $kk = 0 to 5 do { $tube.OpenFace(0, 0); $tube.VertexN(($jj - 1)*6 + $prev); $tube.VertexN(($jj)*6 + $prev); $tube.VertexN(($jj)*6 + $kk); $tube.VertexN(($jj - 1)*6 + $kk); $tube.CloseFace(); $prev = $kk; } } } } $tube.Close(); } }