I've been working on the mirroring script so that it supports subdivision elements as its source. In order to do this I've changed the code so that it pulls point data from a meshdata and not a shape.
At this point, the script works fine, until it doesn't. When using a subd it will occasionally get an error of "*** Out of bounds memory reference in script ***". Based on the line errors it appears to happen on commands like $M.GetNumSides().
I've never had it fail on a mesh or a mesh > subd > mesh.
The most reliable way to get it to error is to have a subd, select some or all points, then keep moving or rotating them to different positions. Eventually, it causes an error.
Using .97d. Remember, the subd has to be named "mesh01"
#command("object");
/* Y axis mesh mirror, USE AT YOUR OWN RISK */
shape $S, $NewS;
meshdata $M;
attribute $Attr;
int $i, $j, $sides;
point3 $pointedit;
quaternion $rotation;
$S = project.curObject.LookupShape("mesh01"); /*get the original shape */
if ($S != NULL) {
$Attr = project.curObject.LookupAttribute("STOP");
/* create a copy */
$NewS = mesh();
while ($Attr == NULL) {
$M = $S.GetMeshData();
$NewS.Open();
/* copy the points and faces */
for $i = 0 to $NewS.GetNumPoints()-1 do {
$NewS.SetPointSelected($i, true);
}
$NewS.DeleteSelectedPoints();
/* correct orientaton */
$rotation = $S.orientation;
$rotation.y = -$rotation.y;
$rotation.z = -$rotation.z;
$NewS.orientation = $rotation;
for $i = 0 to $M.GetNumPoints()-1 do {
$pointedit = $M.GetPoint($i);
$pointedit.x = -$pointedit.x; /* mirror around Y axis, make x points negative */
$NewS.AddPoint($pointedit);
}
for $i = 0 to $M.GetNumFaces()-1 do {
$sides = $M.GetNumSides($i);
$NewS.OpenFace(0, 0);
for $j = 0 to $M.GetNumSides($i)-1 do {
$NewS.VertexN($M.GetFacePointIndex($i, $sides-1-$j));
}
$NewS.CloseFace();
}
$NewS.Close();
/* check for attribute to stop the cycle */
$Attr = project.curObject.LookupAttribute("STOP");
}
}