Hi, it's really good to see you back!
It looks like you need to practice ASL more often

I looked into your code and I found a few problems:
#1if ($face < $total) {
for $face = 1 to $total do {
$grid.OpenFace(0,4);
$grid.VertexN($face);
$grid.VertexN($face + 1);
$grid.VertexN($xd + ($face + 2));
$grid.VertexN($xd + ($face + 1));
$grid.CloseFace();
$face = $face + 1; /* Useless... */
}
}
The "if ($face < $total)" condition is useless, because it is checked implicitly by the "for" cycle. Also the last line inside the cycle makes no sense to me - you don't have to increment the "$face" variable yourself, the "for" cycle does it for you...
Anyway, I think it would be better to write 2 nested cycles, the inner cycle will build one row and the outer cycle will build the whole plane... The reason is simple - your cycle goes through
all points, which also includes for example face {3, 4, 8, 7} (see your picture) and that makes no sense... Maybe the code in your last post solves this issue, but I really can't understand what that script is doing...
So this is what I think this piece of code should look like:
int $NumPointsInRow;
$NumPointsInRow = $xd + 1;
/* The outer cycle builds all rows */
for $i = 0 to $NumPointsInRow * ($zd - 1) step $NumPointsInRow do {
/* The inner cycle builds all faces in one row */
for $j = 0 to $xd-1 do {
$grid.OpenFace(0,4);
$grid.VertexN($i + $j);
$grid.VertexN($i + $j + 1);
$grid.VertexN(($i + $NumPointsInRow) + $j + 1);
$grid.VertexN(($i + $NumPointsInRow) + $j);
$grid.CloseFace();
}
}
#2The piece of code where you build your points was all pretty messy, too complicated and unreadable... The following code does the same and is in my opinion much easier to understand:
for $i = 0 to $zd do {
for $j = 0 to $xd do {
$p.x = $j * $stepx;
$p.z = $i * $stepz;
$grid.AddPoint($p);
}
}
...compared to your original code...
$index[$k] = $grid.AddPoint($p);
for $i = 1 to ($zd + 1) do {
$index[$k] = $grid.AddPoint($p);
for $j = 1 to $xd do {
$p.x = $p.x + $stepx;
$index[$k] = $grid.AddPoint($p);
$i = 1;
}
$p.z = $l * $stepz;
$l = $l + 1;
$p.x = 0;
}
I did a few more minor changes to make the whole thing more readable. I also noticed a few things in your code that might be considered "bad practice" (I hope you don't mind if I point them out...). For example:
- The "for" cycles should start from 0 in most cases, because most of things in ASL (arrays, points, faces) are indexed from 0
- It's generally considered "bad" and "dirty" programming style to edit the iteration variable inside a "for" cycle and it's a big source of impossible-to-find bugs
- As you surely know, it always helps to give your variables meaningful names...
- I personally like indenting the code inside enclosed blocks (such as "if" and "for") to make it more readable
- The most important rule: The code should always be readable and easy to understand. This does not necessarily mean "the shorter, the better". For example your script could be made much shorter by combining the point-building and face-building routines into one cycle, which might also increase the performance, but the result would be very difficult to read and debug. However, in most cases "short = simple = easy to read"...
This is what the final product looks like:
#plugin("object", "mesh", "gridtest");
#parameter("x division", int, 3, 1, 10);
#parameter("z division", int, 3, 1, 10);
#parameter("X scale", float, 40, 2, 1000.0,scale,scale_x);
#parameter("z scale", float, 40, 2, 1000.0,scale,scale_z);
#return($grid);
#button(24, 24, 2, 0x0000000000, 0x0000000000, 0x0000000000, 0x0000000000, 0x0000001800, 0x0000001800, 0x0000000000, 0x0000000000, 0x0000001800, 0x0000001800, 0x0000001800, 0x0000001800, 0x0000001800, 0x0000001800, 0x0000001800, 0x0000001800, 0x0000001800, 0x0000001800, 0x0000001800, 0x0000001800, 0x0000001800, 0x0000000000, 0x0000000000, 0x0000000000);
shape $grid;
float $xs,$zs,$stepx,$stepz;
int $xd,$zd,$i,$j,$NumPointsInRow;
point3 $p;
$xd = parameter("x division");
$zd = parameter("z division");
$xs = parameter("X scale");
$zs = parameter("z scale");
$stepx = $xs/$xd;
$stepz = $zs/$zd;
$grid.Open();
/* Build points here */
for $i = 0 to $zd do {
for $j = 0 to $xd do {
$p.x = $j * $stepx;
$p.z = $i * $stepz;
$grid.AddPoint($p);
}
}
/* Build faces here */
$NumPointsInRow = $xd + 1;
for $i = 0 to $NumPointsInRow * ($zd - 1) step $NumPointsInRow do {
for $j = 0 to $xd-1 do {
$grid.OpenFace(0,4);
$grid.VertexN($i + $j);
$grid.VertexN($i + $j + 1);
$grid.VertexN(($i + $xd + 1) + $j + 1);
$grid.VertexN(($i + $xd + 1) + $j);
$grid.CloseFace();
}
}
$grid.Close();
That's all. I hope I helped you, should you have any questions I'm here for you