/////////////////////////////////////////////////////////////////////////////// // // // Weaver 1.0 // by Simon Greenwold // Copyright 2001, Emergent Design Group // // // Invoke weaver with the the following parameters: // // weavePattern "surfaceName" UGrid VGrid $UPattern $VPattern "sweepCurve" // // "surfaceName" -> the name of the surface to be woven onto // UGrid -> the number of cells to divide the surface into in the U direction // VGrid -> the number of cells to divide the surface into in the V direction // $UPattern -> the name of the pattern to use in the U direction // $VPattern -> the name of the pattern to use in the V direction // "sweepCurve" -> the name of the curve to use as a sweep profile ("" for no sweep) // /////////////////////////////////////////////////////////////////////////////// global float $UNodes[]; global int $numUNodes; global float $VNodes[]; global int $numVNodes; global string $curveName; global string $vstrands[]; global int $numVStrands; global string $ustrands[]; global int $numUStrands; //////////////////////////////////////////////////////////////////////////// // // 1. Add new strand names to the list below just as the existing ones are // /////////////////////////////////////////////////////////////////////////// global int $DownStrand[]; global int $StraightStrand[]; global int $UpStrand[]; global int $WiggleStrand[]; ///////////////////////////////////////////////////////////////////////////// // // 2. Add new pattern names to the list below just as the existing ones are // ///////////////////////////////////////////////////////////////////////////// global string $StraightPattern[]; global string $CrossPattern[]; global string $UpPattern[]; global string $DownPattern[]; global string $WigglePattern[]; global proc initValues(int $UGrid, int $VGrid) { global string $vstrands[]; global string $ustrands[]; makeGrid($UGrid, $VGrid); ///////////////////////////////////////////////////////////////////////////// // // 3. Define new strands below just as existing ones are: // // global int $NewStrand[]; // $NewStrand = {0, 1, 2, -3}; // Strart node, (any number of) deltas // ///////////////////////////////////////////////////////////////////////////// global int $StraightStrand[]; $StraightStrand = {0, 0}; // Strart node, deltas global int $DownStrand[]; $DownStrand = {0, 1}; // Strart node, deltas global int $UpStrand[]; $UpStrand = {0, -1}; // Strart node, deltas global int $WiggleStrand[]; $WiggleStrand = {0, 1, -1}; // Strart node, deltas //////////////////////////////////////////////////////////////////////////////////////////////////// // // 4. Define new strands below just as existing ones are: // // global int $NewPattern[]; // $NewPattern = {"$StrandType1", "1", "0", "$StrandType2", "1", "0"}; // Sets of Strand name, // repeat frequency, // starting offset // /////////////////////////////////////////////////////////////////////////////////////////////////// global string $StraightPattern[]; $StraightPattern = {"$StraightStrand", "1", "0"}; global string $CrossPattern[]; $CrossPattern = {"$DownStrand", "1", "0", "$UpStrand", "1", "0"}; global string $DownPattern[]; $DownPattern = {"$DownStrand", "1", "0"}; global string $UpPattern[]; $UpPattern = {"$UpStrand", "1", "0"}; global string $WigglePattern[]; $WigglePattern = {"$WiggleStrand", "1", "0"}; } global proc setPattern(string $Upattern[], string $Vpattern[]) { global int $numUNodes; global int $numVNodes; global int $numUStrands; global int $numVStrands; int $index; int $curveNum = 1; int $repeatEvery; int $startAt; int $location; int $firstTime = 1; string $strandSet = "$ustrands = {"; string $strandName = ""; for ($index = 0; $index < size($Upattern); $index += 3) { $repeatEvery = $Upattern[$index + 1]; $startAt = $Upattern[$index + 2]; if ($repeatEvery > 0) { for ($location = $startAt; $location < $numUNodes; $location += $repeatEvery) { $strandName = "UStrand" + $curveNum; eval("global int $" + $strandName + "[]"); eval("$" + $strandName + " = " + $Upattern[$index]); eval("$" + $strandName + "[0] = " + $location); if ($firstTime) { $strandSet += "\"$" + $strandName + "\""; $firstTime = 0; } else { $strandSet += ", \"$" + $strandName + "\""; } $curveNum++; } } else { $strandName = "UStrand" + $curveNum; eval("global int $" + $strandName + "[]"); eval("$" + $strandName + " = " + $Upattern[$index]); eval("$" + $strandName + "[0] = " + $startAt); if ($firstTime) { $strandSet += "\"$" + $strandName + "\""; $firstTime = 0; } else { $strandSet += ", \"$" + $strandName + "\""; } $curveNum++; } } $strandSet += "};"; eval($strandSet); $numUStrands = $curveNum - 1; $curveNum = 1; $firstTime = 1; $strandSet = "$vstrands = {"; for ($index = 0; $index < size($Vpattern); $index += 3) { $repeatEvery = $Vpattern[$index + 1]; $startAt = $Vpattern[$index + 2]; if ($repeatEvery > 0) { for ($location = $startAt; $location < $numVNodes; $location += $repeatEvery) { $strandName = "VStrand" + $curveNum; eval("global int $" + $strandName + "[]"); eval("$" + $strandName + " = " + $Vpattern[$index]); eval("$" + $strandName + "[0] = " + $location); if ($firstTime) { $strandSet += "\"$" + $strandName + "\""; $firstTime = 0; } else { $strandSet += ", \"$" + $strandName + "\""; } $curveNum++; } } else { $strandName = "VStrand" + $curveNum; eval("global int $" + $strandName + "[]"); eval("$" + $strandName + " = " + $Vpattern[$index]); eval("$" + $strandName + "[0] = " + $startAt); if ($firstTime) { $strandSet += "\"$" + $strandName + "\""; $firstTime = 0; } else { $strandSet += ", \"$" + $strandName + "\""; } $curveNum++; } } $strandSet += "};"; eval($strandSet); $numVStrands = $curveNum - 1; } global proc makeGrid(int $nUNodes, int $nVNodes) { global int $numUNodes; global int $numVNodes; global float $UNodes[]; global float $VNodes[]; int $index; for ($index = 0; $index < $nUNodes; $index++) { $UNodes[$index] = (1.0 / ($nUNodes - 1)) * $index; } for ($index = 0; $index < $nVNodes; $index++) { $VNodes[$index] = (1.0 / ($nVNodes - 1)) * $index; } $numUNodes = $nUNodes; $numVNodes = $nVNodes; } global proc weavePattern(string $surface, int $UGrid, int $VGrid, string $Upat[], string $Vpat[], string $profile) { initValues($UGrid, $VGrid); setPattern($Upat, $Vpat); initializeSurface($surface); weaveVStrands($surface, $profile); weaveUStrands($surface, $profile); } global proc weave(string $surface, int $UGrid, int $VGrid, string $profile) { initValues($UGrid, $VGrid); initializeSurface($surface); weaveVStrands($surface, $profile); weaveUStrands($surface, $profile); } global proc weaveCurves(string $surface, int $UGrid, int $VGrid, string $pattern) { initValues($UGrid, $VGrid); initializeSurface($surface); weaveVStrands($surface, ""); weaveUStrands($surface, ""); } global proc weaveVStrands(string $surface, string $profile) { string $strand; global string $vstrands[]; global int $numVStrands; int $index; for ($index = 0; $index < $numVStrands; $index++) { string $command = "weaveVStrand(" + $vstrands[$index] + ", \"" + $surface + "\", \"" + $profile + "\");"; eval($command); } } global proc weaveUStrands(string $surface, string $profile) { string $strand; global string $ustrands[]; global int $numUStrands; int $index; for ($index = 0; $index < $numUStrands; $index++) { string $command = "weaveUStrand(" + $ustrands[$index] + ", \"" + $surface + "\", \"" + $profile + "\");"; eval($command); } } global proc string weaveUStrand(int $ustrand[], string $surface, string $profile) { string $command = "curveOnSurface -d 1 "; global float $UNodes[]; global float $VNodes[]; global string $weaveSurface; global int $numUNodes; global int $numVNodes; global string $curveName; global string $makeCurveCommand; global string $profileCurve; int $done = false; int $umarker = $ustrand[0]; int $vmarker = 0; int $ustrandDeltaPointer = 0; int $numDeltas = size($ustrand) - 1; float $ULocation; float $VLocation; while (! $done) { $ULocation = $UNodes[$umarker]; $VLocation = $VNodes[$vmarker]; $command += "-uv " + $ULocation + " " + $VLocation + " "; $vmarker++; if ($vmarker >= $numVNodes) $done = true; $ustrandDeltaPointer++; if ($ustrandDeltaPointer > $numDeltas) $ustrandDeltaPointer= 1; $umarker += $ustrand[$ustrandDeltaPointer]; if ($umarker < 0) $done = true; if ($umarker >= $numUNodes) $done = true; } $command += $surface; $makeCurveCommand = $command; catch(`eval("$curveName = eval($makeCurveCommand)")`); catch(`eval("rebuildCurve $curveName")`); if ($profile != "") { catch(`eval("makeStrip($curveName, $profileCurve)")`); } return $curveName; } global proc string weaveVStrand(int $vstrand[], string $surface, string $profile) { string $command = "curveOnSurface -d 1 "; global float $UNodes[]; global float $VNodes[]; global string $weaveSurface; global int $numUNodes; global int $numVNodes; global string $curveName; global string $makeCurveCommand; global string $profileCurve; $profileCurve = $profile; int $done = false; int $umarker = 0; int $vmarker = $vstrand[0]; int $vstrandDeltaPointer = 0; int $numDeltas = size($vstrand) - 1; float $ULocation; float $VLocation; while (! $done) { $ULocation = $UNodes[$umarker]; $VLocation = $VNodes[$vmarker]; $command += "-uv " + $ULocation + " " + $VLocation + " "; $umarker++; if ($umarker >= $numUNodes) $done = true; $vstrandDeltaPointer++; if ($vstrandDeltaPointer > $numDeltas) $vstrandDeltaPointer= 1; $vmarker += $vstrand[$vstrandDeltaPointer]; if ($vmarker < 0) $done = true; if ($vmarker >= $numVNodes) $done = true; } $command += $surface; $makeCurveCommand = $command; catch(`eval("$curveName = eval($makeCurveCommand)")`); catch(`eval("rebuildCurve $curveName")`); if ($profile != "") { catch(`eval("makeStrip($curveName, $profileCurve)")`); } return $curveName; } global proc string[] makeStrip(string $curveName, string $profileName) { string $command = "xform -cp "; $command += $profileName; eval($command); $command = "extrude -ch true -rn false -po 0 -et 2 -ucp 1 -fpt 1 -upn 1 -rotation 0 -scale 1 -rsp 1 \""; $command += $profileName; $command += "\" "; $command += $curveName; return eval($command); } global proc string[] initializeSurface(string $surfaceName) { string $command = "rebuildSurface -ch 1 -rpo 1 -rt 0 -end 1 -kr 0 -kcp 0 -kc 0 -su 9 -du 3 -sv 9 -dv 3 -tol 0.01 -dir 2 "; $command += $surfaceName; return eval($command); }