#plugin("object", "mesh", "N-Gon");
#parameter("<name>", <type>, <starting value>, <floor value>, <ceiling value>, <optional params>); #parameter("Scale", float, 1, 0.01, 10000, scale);
#button(<width>, <height>, <number of colors>, <data>);
<type> $<name> (<parameters>){} int $RoundDown (float $a) { return $a; }
float $plusOnePointOne (float $a) { $a = $a + 1.1; return $a; }
parameter("<name>");
point3 $p[0];
/* Local Variables */ float $s, $xs, $ys, $zs, $math; int $numSides, $i; point3 $p[0];
#parameter("Z Scale", float, 1, 0.01, 10000, scale_z);
#parameter("Number of Sides", float, 4, 3, 250, scale_z);
$zs = parameter("Z Scale");
$numSides = parameter("Number of Sides");
/* Main shape creation code goes here */ for $i = 0 to $numSides - 1 do { }
$p.push((0, 0, 0));
$p.push((cos($i*$math), sin($i*$math), 0));
$math = 2.0*PI/$numSides;
$p.push((cos(($i/$numSides)*2*PI), sin(($i/$numSides)*2*PI), 0));
#parameter("Scale", float, 1, 0.01, 10000, scale);
#parameter("Diameter", float, 1, 0.01, 10000, scale);
float $s, $xs, $ys, $math;
float $r, $xs, $ys, $math;
$s = parameter("Scale");
$r = parameter("Diameter") * 0.5;
for $i = 0 to $p.size - 1 do $S.AddPoint($p[$i]);
for $i = 0 to $numSides - 1 do $p.push((cos($i*$math), sin($i*$math), 0));
for $i = 0 to $numSides - 1 do $S.AddPoint((cos($i*$math), sin($i*$math), 0));
$S.AddPoint(($p[$i].x*$xs, $p[$i].y*$ys, 0)*$r);
/* * N-Gon Shape Plugin * Author: Randall Bezant (aka Raxx) * Version: 0.0001a * Date: 11/01/2014 * Summary: * This is an N-Gon shape, much like Anim8or's built-in * N-Gon spline shape, except already filled in and with UV * coordinates attached. */ /* Parametric Shape Directive */ #plugin("object", "mesh", "N-Gon"); /* Parameters */ #parameter("Diameter", float, 1, 0.01, 10000, scale); #parameter("X Scale", float, 1, 0.01, 10000, scale_x); #parameter("Y Scale", float, 1, 0.01, 10000, scale_y); #parameter("Number of Sides", float, 4, 3, 250, scale_z); /* #return directive - the shape that's being worked on */ #return($S); /* The Button */ #button(26, 26, 2, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000); /* Global Variables */ shape $S; file $output; object $obj; /* Main Function */ void $main() { /* Local Variables */ float $r, $xs, $ys, $math; int $numSides, $i; point3 $p[0]; /* Fill variables with the parameter data */ $r = parameter("Diameter")*0.5; $xs = parameter("X Scale"); $ys = parameter("Y Scale"); $numSides = parameter("Number of Sides"); /* Open up the console */ $output.open("$console", "w"); /* Current Object */ $obj = project.curObject; /* Open the shape */ $S.Open(); /* Main shape creation code goes here */ /* Some pre-math for the following for loop */ $math = 2.0*PI/$numSides; /* For each side of the face, create its point and assign it to $p */ for $i = 0 to $numSides - 1 do $p.push((cos($i*$math), sin($i*$math), 0)); /* For each point we just created, add it to the shape*/ for $i = 0 to $p.size - 1 do $S.AddPoint(($p[$i].x*$xs, $p[$i].y*$ys, 0)*$r); /* Scale it using the parameters */ /* Close the shape */ $S.Close(); /* Close the console */ $output.close(); }
$S.OpenFace(0,FACE_HAS_TEXCOORDS); for $i = $p.size - 1 to 0 step - 1 do { $S.TexCoordN($S.AddTexCoord(($p[$i].x + 1,$p[$i].y + 1)*0.5)); $S.VertexN($i); } $S.CloseFace();
$S.OpenFace(0,FACE_HAS_TEXCOORDS);
for $i = $p.size - 1 to 0 step - 1 do {}
$S.TexCoordN($S.AddTexCoord(($p[$i].x + 1,$p[$i].y + 1)*0.5));
/* Step through each point counterclockwise */ for $i = $p.size - 1 to 0 step - 1 do { /* This detects every instance the face reaches 250 points */ if ((($p.size - $i - 1) % 249 == 0) && $i > 0 && $i < $p.size - 1) { $S.CloseFace(); /* Close the current face */ $S.OpenFace(0, FACE_HAS_TEXCOORDS); /* Create a new face */ /* Add the texture coordinate for the first point */ $S.TexCoordN($S.AddTexCoord(($p[$p.size - 1].x + 1,$p[$p.size - 1].y + 1)*0.5)); /* Add the first point */ $S.VertexN($p.size - 1); /* Add the previous point to start off the face */ $S.TexCoordN($S.AddTexCoord(($p[$i + 1].x + 1,$p[$i + 1].y + 1)*0.5)); $S.VertexN($i + 1); } /* Add the texture coordinate for the current point */ $S.TexCoordN($S.AddTexCoord(($p[$i].x + 1,$p[$i].y + 1)*0.5)); /* Add the current point */ $S.VertexN($i); }