Anim8or Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

An update to Anim8or, v1.00b, is available with a few bug fixes. Get your copy HERE. See the "ReadMe" file for details.

Author Topic: difficulty creating mesh with script  (Read 4017 times)

nitsua60

  • Newbie
  • *
  • Posts: 3
    • View Profile
difficulty creating mesh with script
« on: February 27, 2008, 02:55:53 am »

Hello all- I'm trying to use anim8or to visualize data coming out of another program. Basically, I have a working trial script, but when I have my program write a script, it displays nothing (though the console claims no errors and successful exit). Below are excerpts of both -- any ideas why the 1st works and the 2nd doesn't? Thanks.

This one works:
Code: [Select]
$mymesh.Open();
for $i = 0 to 99 step 1 do {
  $index[$i] = $mymesh.AddPoint(($i%10, $i/10, 1));
}

/* assigning meshpoints to faces (or is it faces to meshpoints?) */
for $y = 0 to 8 step 1 do {
  for $x = 0 to 8 step 1 do {
    $mymesh.OpenFace(0,0);
    $mymesh.VertexN($index[10*($y) + ($x)]);
    $mymesh.VertexN($index[10*($y) + ($x + 1)]);
    $mymesh.VertexN($index[10*($y + 1) + ($x + 1)]);
    $mymesh.VertexN($index[10*($y + 1) + ($x)]);
    $mymesh.CloseFace();
  }
}

$mymesh.RemoveUnusedData();
$mymesh.Close();

But this one doesn't:
Code: [Select]
$heightmesh.Open();

/* creating mesh, point by point */
$index[0] = $heightmesh.AddPoint((0, 0, 1));
$index[1] = $heightmesh.AddPoint((1, 0, 1));
$index[2] = $heightmesh.AddPoint((2, 0, 1));
$index[3] = $heightmesh.AddPoint((3, 0, 1));
$index[4] = $heightmesh.AddPoint((4, 0, 1));
$index[5] = $heightmesh.AddPoint((5, 0, 1));
$index[6] = $heightmesh.AddPoint((6, 0, 1));
$index[7] = $heightmesh.AddPoint((7, 0, 1));
$index[8] = $heightmesh.AddPoint((8, 0, 1));
$index[9] = $heightmesh.AddPoint((9, 0, 1));
$index[10] = $heightmesh.AddPoint((0, 1, 1));
$index[11] = $heightmesh.AddPoint((1, 1, 1));
$index[12] = $heightmesh.AddPoint((2, 1, 1));
...
$index[97] = $heightmesh.AddPoint((7, 9, 1));
$index[98] = $heightmesh.AddPoint((8, 9, 1));
$index[99] = $heightmesh.AddPoint((9, 9, 1));

/* assigning meshpoints to facees (or vice versa?)
$heightmesh.OpenFace(0,0);
$heightmesh.VertexN($index[0]);
$heightmesh.VertexN($index[1]);
$heightmesh.VertexN($index[11]);
$heightmesh.VertexN($index[10]);
$heightmesh.CloseFace();

$heightmesh.OpenFace(0,0);
$heightmesh.VertexN($index[1]);
$heightmesh.VertexN($index[2]);
$heightmesh.VertexN($index[12]);
$heightmesh.VertexN($index[11]);
$heightmesh.CloseFace();

...

$heightmesh.OpenFace(0,0);
$heightmesh.VertexN($index[88]);
$heightmesh.VertexN($index[89]);
$heightmesh.VertexN($index[99]);
$heightmesh.VertexN($index[98]);
$heightmesh.CloseFace();

$heightmesh.RemoveUnusedData();
$heightmesh.Close();

Logged

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 1532
    • View Profile
Re: difficulty creating mesh with script
« Reply #1 on: February 27, 2008, 06:37:34 am »

I can't see what's wrong.  Check your variable declarations perhaps?  Both your first one and this script works for me (it's a portion of your second example).  After you run it, do a Edit->SelectAll and view it in wirefreame mode in the point editor.  You may be able to see somthing  that helps.  Also save it as an .an8 file and look at that in any ordinary text editor.
Quote
/* script_2.an8 */

shape $mymesh;

int $i, $x, $y, $index[100];

$mymesh = mesh();
$mymesh.Open();

$index[0] = $mymesh.AddPoint((0, 0, 1));
$index[1] = $mymesh.AddPoint((1, 0, 1));
$index[2] = $mymesh.AddPoint((2, 0, 1));
$index[3] = $mymesh.AddPoint((3, 0, 1));
$index[4] = $mymesh.AddPoint((4, 0, 1));
$index[5] = $mymesh.AddPoint((5, 0, 1));
$index[6] = $mymesh.AddPoint((6, 0, 1));
$index[7] = $mymesh.AddPoint((7, 0, 1));
$index[8] = $mymesh.AddPoint((8, 0, 1));
$index[9] = $mymesh.AddPoint((9, 0, 1));
$index[10] = $mymesh.AddPoint((0, 1, 1));
$index[11] = $mymesh.AddPoint((1, 1, 1));

/* assigning meshpoints to faces (or is it faces to meshpoints?) */

$mymesh.OpenFace(0,0);
$mymesh.VertexN($index[0]);
$mymesh.VertexN($index[1]);
$mymesh.VertexN($index[11]);
$mymesh.VertexN($index[10]);
$mymesh.CloseFace();

$mymesh.RemoveUnusedData();
$mymesh.Close();
Logged

nitsua60

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: difficulty creating mesh with script
« Reply #2 on: February 27, 2008, 07:38:04 pm »

Hi Steve-

   thanks -- that seems to do it (selecting -> all and going to point-edit mode). However, this belies a clear underlying misunderstanding of mine: I assumed that by creating meshpoints and assigning them  as vertices of faces, they would be visible in all of the views. Do I need to explicitly add a texture to each face? Is there a default texture that I can apply in one fell swoop to all faces? Is my confusion that this is not a closed solid, or that I haven't explicitly associated these faces with a shape object?
Logged

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 1532
    • View Profile
Re: difficulty creating mesh with script
« Reply #3 on: February 28, 2008, 01:25:13 am »

The topology depends entirely on what you add to the mesh.  It will be a closed mesh if you add all the right faces for it.  If everything is in the same plane, however, it will not be visible as a solid object when viewed edge-on of course.  The example I posted only adds one planar quad which can dissappear like that.
Logged

nitsua60

  • Newbie
  • *
  • Posts: 3
    • View Profile
Still: difficulty creating mesh with script
« Reply #4 on: February 28, 2008, 04:03:33 am »

Hi-

   I'm clearly far too dependent on syntax highlighting -- I missed the omission of a "*/" before the blocks of face declarations. Solves everything. Sorry for the trouble. (it's visible on line 32 of the second code in my original post if you're curious). Thanks for all the help.
Logged