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: GetNumEdges() function gone wrong?  (Read 10584 times)

Kubajzz

  • Flying Platypus
  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 548
  • Little doggie ate my avatar...
    • View Profile
GetNumEdges() function gone wrong?
« on: August 21, 2008, 12:57:36 pm »

Try out this simple script:
Code: [Select]
#command("object");

file $file;
string $output;
shape $shape[0];

project.curObject.GetShapes($shape);

$output = PrintToString("edges: %d", $shape[0].GetNumEdges());
$file.open("$console", "w");
$file.print("-------\n\n"+$output+"\n\n-------\n");
$file.close;

You must have only one mesh in your object...
Run the script and you will get a console output which should contain the number of edges in that mesh... but the number in the console will allways be (number of edges + 1)!

Why does this happen? Is it a bug?

I found this problem accidentally and it scared me pretty much, because I've been using the GetNumEdges function without any problems until now...
Logged

NickE

  • Full Member
  • ***
  • Posts: 167
    • View Profile
Re: GetNumEdges() function gone wrong?
« Reply #1 on: August 21, 2008, 06:46:32 pm »

I ran into this issue a while back. 

I added a little to your code to try to flesh out the problem:
Code: [Select]
#command("object");

file $file;
string $output;
shape $shape[0];

int $i;

project.curObject.GetShapes($shape);

$output = PrintToString("edges: %d", $shape[0].GetNumEdges());


$file.open("$console", "w");
$file.print("-------\n\n"+$output+"\n\n-------\n");

for $i=1 to $shape[0].GetNumEdges() do
{
  $file.print("Edge: %d Point1: %d Point2: %d\n",$i,$shape[0].GetEdgeIndex0($i),$shape[0].GetEdgeIndex1($i));


$file.close;

I just drew a cube and converted to mesh for a test shape.  The output:
Code: [Select]
begin script "F:\anim8or_v097b_preview\scripts\edgecounttest.txt
-------

edges: 13

-------
Edge: 1 Point1: 0 Point2: 4
Edge: 2 Point1: 4 Point2: 6
Edge: 3 Point1: 2 Point2: 6
Edge: 4 Point1: 0 Point2: 2
Edge: 5 Point1: 1 Point2: 3
Edge: 6 Point1: 3 Point2: 7
Edge: 7 Point1: 5 Point2: 7
Edge: 8 Point1: 1 Point2: 5
Edge: 9 Point1: 2 Point2: 3
Edge: 10 Point1: 0 Point2: 1
Edge: 11 Point1: 4 Point2: 5
Edge: 12 Point1: 6 Point2: 7
Edge: 13 Point1: 0 Point2: 0
exit script "F:\anim8or_v097b_preview\scripts\edgecounttest.txt"

It appears that the last edge is from point 0 to point 0.  You can probably work around this by just using GetNumEdges()-1.  That is what I have done.
Logged

Kubajzz

  • Flying Platypus
  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 548
  • Little doggie ate my avatar...
    • View Profile
Re: GetNumEdges() function gone wrong?
« Reply #2 on: August 21, 2008, 07:01:27 pm »

I did exactly the same when I was trying to find out why my script doesn't work... And I found the same thing:
Quote from: NickE
It appears that the last edge is from point 0 to point 0.
I think the point numbers "0, 0" don't mean the starting and ending point in this case, it just means that edge #13 does not not exist (and has no point data...); you will get the same output if you try to get the data for edge number 0, which also doesn't exist... Also if you try to click Options>Info, you'll see that your mesh really has only 12 edges, there cannot be edge number 13...

I know there's an easy way to go around (using "GetNumEdges()-1" instead of "GetNumEdges()") but what if this is really a bug and it will be fixed in the next version? The scripts wouldn't work then... That's why I wanted to ask about it...
Logged

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 2126
    • View Profile
Re: GetNumEdges() function gone wrong?
« Reply #3 on: August 25, 2008, 10:00:30 pm »

I will fix GetNumEdges().  It should return 12 for a cube.
Logged

Kubajzz

  • Flying Platypus
  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 548
  • Little doggie ate my avatar...
    • View Profile
Re: GetNumEdges() function gone wrong?
« Reply #4 on: August 31, 2008, 06:21:32 pm »

Thanks Steve!

I found an easy way how to write a script that would work in the current version of Anim8or and it would still work correctly in the next versions. Something from the ASL specification:

Quote from: ASL specification
Predefined Variables

string version;
  The version of Anim8or is available in version.

I always thought "version" variable is one of the most useless features... But it's going to be extremely useful here :)
Logged

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 2126
    • View Profile
Re: GetNumEdges() function gone wrong?
« Reply #5 on: September 10, 2008, 01:17:49 am »

Heh heh.  I knew it would be useful for *something*!

In addition the the version() function that returns a string, I'm adding a int VERSION predefined constant that will just have the numeric part of the version.  V0.97 would have a value of 97.  It won't help here because it would not compile on earlier versions of Anim8or but it may make similar work arounds easier in the future.
Logged