Anim8or Community

General Category => Anim8or v0.98 Discussion Forum => Topic started by: CobraSpectre on September 26, 2008, 07:05:06 am

Title: Bad meshdata from subdivision?
Post by: CobraSpectre on September 26, 2008, 07:05:06 am
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"

Code: [Select]

/* 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();


  /* copy the points and faces */
  for $i = 0 to $NewS.GetNumPoints()-1 do {
    $NewS.SetPointSelected($i, true);

  /* 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 */

  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));


  /* check for attribute to stop the cycle */
  $Attr = project.curObject.LookupAttribute("STOP");


Title: Re: Bad meshdata from subdivision?
Post by: CobraSpectre on September 26, 2008, 11:50:25 pm
It appears the meshdata can change while faces are being added.

If you put a refresh() after $NewS.VertexN or $NewS.CloseFace() the display is refreshed after every face is added, which slows it down and you can see what's happening. If a subd's points are moved they begin drawing to produce a messed up mesh or it causes an error.

If $M = $S.GetMeshData() is moved above the while loop, it will draw correctly until the points are moved on a subd. The original mesh is then drawn instead, but does not update point changes.