Anim8or Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

Ian Ross has just released a book on Anim8or. It's perect for a beginner and a good reference for experienced users. It contains detailed chapters on every aspect, with many examples. Get your own copy here: "Anim8or Tutorial Book"

Author Topic: Bad meshdata from subdivision?  (Read 6502 times)

CobraSpectre

  • Newbie
  • *
  • Posts: 39
    • View Profile
Bad meshdata from subdivision?
« on: September 26, 2008, 03: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]
#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");
}

}

Logged

CobraSpectre

  • Newbie
  • *
  • Posts: 39
    • View Profile
Re: Bad meshdata from subdivision?
« Reply #1 on: September 26, 2008, 07: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.
Logged