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"

Pages: [1] 2

Author Topic: Help  (Read 22571 times)

Jdez

  • Full Member
  • ***
  • Posts: 105
    • View Profile
    • Tech Blog
Help
« on: June 26, 2009, 10:32:17 pm »

Hello again,

I have been looking closely at the plane plugin and I think I understand how it works. However if someone could please write up another simple plugin that has a Y value as well, such as a cube, it would probably help me a lot. If not could someone Explain the following code:


#plugin("object", "mesh", "plane");
#parameter("side", float, 10.0, 0.001, 99999, scale);
#return($plane);
#button(17, 25, 2,
    0x00000000, 0x00000000, 0x0fffffff, 0x00010001,
    0x00010001, 0x00010001, 0x00010001, 0x00010001,
    0x00010001, 0x00010001, 0x00010001, 0x00010001,
    0x00010001, 0x00010001, 0x00010001, 0x00010001,
    0x00010001, 0x00010001, 0x0fffffff, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0x00000000);
shape $plane; 
int $side,$i;
point3 $p;
$side = parameter("side");

$plane.Open();
$plane.OpenFace(0,4);
What does this line and the one before it do? Would it change if the shape was a cube instead of a plane?

$p.x = -$side;
$p.y = 0;
$p.z = -$side;
$plane.TexCoordN($plane.AddTexCoord((0,1)));
What do the numbers mean and again would they change if the shape was a cube instead of a plane?
$plane.VertexN($plane.AddPoint($p));

$p.x = $side;
$p.y = 0;
$p.z = -$side;
$plane.TexCoordN($plane.AddTexCoord((1,1)));
$plane.VertexN($plane.AddPoint($p));

$p.x = $side;
$p.y = 0;
$p.z = $side;
$plane.TexCoordN($plane.AddTexCoord((1,0)));
$plane.VertexN($plane.AddPoint($p));

$p.x = -$side;
$p.y = 0;
$p.z = $side;
$plane.TexCoordN($plane.AddTexCoord((0,0)));
$plane.VertexN($plane.AddPoint($p));

$plane.CloseFace();
$plane.Close();


Thanks
Jdez
Logged
Having fun with ASL!
Tech blog: http://jaydez-tech.blogspot.com

Claude

  • Sr. Member
  • ****
  • Posts: 285
    • View Profile
Re: Help
« Reply #1 on: June 26, 2009, 11:26:34 pm »

From the script spec(Mesh Members paragraph):

int Open(void);      // Open a mesh for editing

int OpenFace(int matNo, int flags);  // Begins the definition of a new face.

The parameter matNo sets the face’s material.  It is a zero based index into the mesh’s materials.  The bit vector flags specifies the additional properties the face will have.  A value of 4 or FACE_HAS_TEXCOORDS specifies that the face will have texture coordinates.  All other bits are ignored.

int AddTexCoord(point2 uv);  //  Add new texture coordinates to a mesh.

The return value is an integer index that is used to refer to the new  texture coordinate when adding new faces.

int TexCoordN(int index); //  Sets the texture coordinate for the  current     point.

index is the value returned by a call to AddTexCoord().

So the line
$plane.TexCoordN($plane.AddTexCoord((0,1)));
adds a new texture coordinate with the value u = 0 v =1
The function returns the index of that new tex coord which is used
to set the tex coord for the current point being added to the face on
the next line.

Right now the script is creating 1 face.If you want to create a cube,
you would need to create 5 more faces.
Logged

Jdez

  • Full Member
  • ***
  • Posts: 105
    • View Profile
    • Tech Blog
Re: Help
« Reply #2 on: June 27, 2009, 03:22:28 am »

Thanks Claude, This has helped me understand the plugin a lot.
Still if anyone could come up with a quick cube plugin it would be appreciated
Logged
Having fun with ASL!
Tech blog: http://jaydez-tech.blogspot.com

tiodiego

  • Newbie
  • *
  • Posts: 15
  • Quake 3 lover!
    • View Profile
    • Umriagplutix
Re: Help
« Reply #3 on: July 02, 2009, 01:10:41 am »

shouldn't be doing this because it is not working :-\ :-[ but maybe someone can explain what the problem is. At least I think this is the way...

Quote
#plugin("object", "mesh", "cube");
#parameter("side", float, 10, 1, 999, scale);
#return($cube);

shape $cube;
float $a;
int $pos[8];
point3 $p;

$a = parameter("side")/2;
$cube.Open();

/* points /*

$p.x=$a;
$p.y=$a;
$p.z=-$a;
$pos[1]=$cube.AddPoint($p);

$p.x=$a;
$p.y=$a;
$p.z=$a;
$pos[2]=$cube.AddPoint($p);

$p.x=-$a;
$p.y=$a;
$p.z=$a;
$pos[3]=$cube.AddPoint($p);

$p.x=-$a;
$p.y=$a;
$p.z=-$a;
$pos[4]=$cube.AddPoint($p);

$p.x=$a;
$p.y=-$a;
$p.z=-$a;
$pos[5]=$cube.AddPoint($p);

$p.x=$a;
$p.y=-$a;
$p.z=$a;
$pos[6]=$cube.AddPoint($p);

$p.x=-$a;
$p.y=-$a;
$p.z=-$a;
$pos[7]=$cube.AddPoint($p);

$p.x=-$a;
$p.y=-$a;
$p.z=$a;
$pos[8]=$cube.AddPoint($p);

/* faces */

$cube.OpenFace(0,0);
$cube.VertexN($pos[1]);                 /* <----- line 58.
$cube.VertexN($pos[2]);
$cube.VertexN($pos[3]);
$cube.VertexN($pos[4]);
$cube.CloseFace();

$cube.OpenFace(0,0);
$cube.VertexN($pos[1]);
$cube.VertexN($pos[2]);
$cube.VertexN($pos[5]);
$cube.VertexN($pos[6]);
$cube.CloseFace();

$cube.OpenFace(0,0);
$cube.VertexN($pos[2]);
$cube.VertexN($pos[3]);
$cube.VertexN($pos[6]);
$cube.VertexN($pos[8]);
$cube.CloseFace();

$cube.OpenFace(0,0);
$cube.VertexN($pos[3]);
$cube.VertexN($pos[4]);
$cube.VertexN($pos[7]);
$cube.VertexN($pos[8]);
$cube.CloseFace();

$cube.OpenFace(0,0);
$cube.VertexN($pos[1]);
$cube.VertexN($pos[4]);
$cube.VertexN($pos[5]);
$cube.VertexN($pos[7]);
$cube.CloseFace();

$cube.OpenFace(0,0);
$cube.VertexN($pos[5]);
$cube.VertexN($pos[6]);
$cube.VertexN($pos[7]);
$cube.VertexN($pos[8]);
$cube.CloseFace();

$cube.Close();


it sends some error regarding a bad point index on line 58, so it has to be a problem with the pos vector.
Logged

Claude

  • Sr. Member
  • ****
  • Posts: 285
    • View Profile
Re: Help
« Reply #4 on: July 02, 2009, 02:57:53 am »

I had a quick look only because I have to go to bed.
One thing,I noticed:
int $pos[8];
Index goes from 0 to 7
Logged

tiodiego

  • Newbie
  • *
  • Posts: 15
  • Quake 3 lover!
    • View Profile
    • Umriagplutix
Re: Help
« Reply #5 on: July 02, 2009, 06:24:42 pm »

Thanks again Claude!, didn't noticed it, but I changed that and made some minor adjustments to the script and it didn't work neither  :-\ , so I made it again xD! and now it works  ;) here it is:

Quote
/* Cube Primitive Plugin by TioDiego */

#plugin("object", "mesh", "cube");
#parameter("side", float, 10, 1, 999, scale);
#return($cube);
#button(32, 32, 2,
0x0000000000, 0x0000000000, 0x0000000000, 0x0000000000,
0x0000000000, 0x00000fffe0, 0x0000100060, 0x00002800a0,
0x0000400120, 0x0000880220, 0x0001000420, 0x0003fff820,
0x0002000820, 0x0002080820, 0x0002000820, 0x0002080820,
0x0002000820, 0x0002080820, 0x0002000820, 0x00020aaaa0,
0x0002100840, 0x0002200880, 0x0002400900, 0x0002800a00,
0x0003000c00, 0x0003fff800, 0x0000000000, 0x0000000000,
0x0000000000, 0x0000000000, 0x0000000000, 0x0000000000);

shape $cube;
float $a;
int $in[8];
point3 $p;

$a = parameter("side")/2;
$cube.Open();

$cube.OpenFace(0,0);
$p.x=$a;
$p.y=$a;
$p.z=-$a;
$in[0]=$cube.AddPoint($p);
$cube.VertexN($in[0]);
$p.x=$a;
$p.y=$a;
$p.z=$a;
$in[1]=$cube.AddPoint($p);
$cube.VertexN($in[1]);
$p.x=-$a;
$p.y=$a;
$p.z=$a;
$in[2]=$cube.AddPoint($p);
$cube.VertexN($in[2]);
$p.x=-$a;
$p.y=$a;
$p.z=-$a;
$in[3]=$cube.AddPoint($p);
$cube.VertexN($in[3]);
$cube.CloseFace();


$cube.OpenFace(0,0);
$p.x=$a;
$p.y=-$a;
$p.z=-$a;
$in[4]=$cube.AddPoint($p);
$cube.VertexN($in[4]);
$p.x=$a;
$p.y=-$a;
$p.z=$a;
$in[5]=$cube.AddPoint($p);
$cube.VertexN($in[5]);
$p.x=-$a;
$p.y=-$a;
$p.z=$a;
$in[6]=$cube.AddPoint($p);
$cube.VertexN($in[6]);
$p.x=-$a;
$p.y=-$a;
$p.z=-$a;
$in[7]=$cube.AddPoint($p);
$cube.VertexN($in[7]);
$cube.CloseFace();

$cube.OpenFace(0,0);
$cube.VertexN($in[0]);
$cube.VertexN($in[1]);
$cube.VertexN($in[5]);
$cube.VertexN($in[4]);
$cube.CloseFace();

$cube.OpenFace(0,0);
$cube.VertexN($in[1]);
$cube.VertexN($in[2]);
$cube.VertexN($in[6]);
$cube.VertexN($in[5]);
$cube.CloseFace();

$cube.OpenFace(0,0);
$cube.VertexN($in[2]);
$cube.VertexN($in[3]);
$cube.VertexN($in[7]);
$cube.VertexN($in[6]);
$cube.CloseFace();

$cube.OpenFace(0,0);
$cube.VertexN($in[3]);
$cube.VertexN($in[0]);
$cube.VertexN($in[4]);
$cube.VertexN($in[7]);
$cube.CloseFace();

$cube.Close();
I attached a simple paint drawing that explains the order the script works, if someone needs it  :)

( I still would like to know what was wrong with the old version, so I attached it in case someone has the time  ::) )
« Last Edit: July 02, 2009, 06:34:11 pm by tiodiego »
Logged

Claude

  • Sr. Member
  • ****
  • Posts: 285
    • View Profile
Re: Help
« Reply #6 on: July 02, 2009, 09:07:56 pm »

Still a small problem with your mesh.
Your top face normal is correct.
The 5 other face normals are reversed.
They are facing toward the centre of the cube.
Easy to fix by changing the winding,the order you
use the points.
When you look at the top,you're going
clockwise.Do the same for the other faces.
Logged

tiodiego

  • Newbie
  • *
  • Posts: 15
  • Quake 3 lover!
    • View Profile
    • Umriagplutix
Re: Help
« Reply #7 on: July 03, 2009, 12:15:22 am »

now it is ready  ;D

Quote
/* Cube Primitive Plugin by TioDiego */

#plugin("object", "mesh", "cube");
#parameter("side", float, 10, 1, 999, scale);
#return($cube);
#button(32, 32, 2,
0x0000000000, 0x0000000000, 0x0000000000, 0x0000000000,
0x0000000000, 0x00000fffe0, 0x0000100060, 0x00002800a0,
0x0000400120, 0x0000880220, 0x0001000420, 0x0003fff820,
0x0002000820, 0x0002080820, 0x0002000820, 0x0002080820,
0x0002000820, 0x0002080820, 0x0002000820, 0x00020aaaa0,
0x0002100840, 0x0002200880, 0x0002400900, 0x0002800a00,
0x0003000c00, 0x0003fff800, 0x0000000000, 0x0000000000,
0x0000000000, 0x0000000000, 0x0000000000, 0x0000000000);

shape $cube;
float $a;
int $in[8];
point3 $p;

$a = parameter("side")/2;
$cube.Open();

$cube.OpenFace(0,0);
$p.x=$a;
$p.y=$a;
$p.z=-$a;
$in[0]=$cube.AddPoint($p);
$cube.VertexN($in[0]);
$p.x=$a;
$p.y=$a;
$p.z=$a;
$in[1]=$cube.AddPoint($p);
$cube.VertexN($in[1]);
$p.x=-$a;
$p.y=$a;
$p.z=$a;
$in[2]=$cube.AddPoint($p);
$cube.VertexN($in[2]);
$p.x=-$a;
$p.y=$a;
$p.z=-$a;
$in[3]=$cube.AddPoint($p);
$cube.VertexN($in[3]);
$cube.CloseFace();


$cube.OpenFace(0,0);
$p.x=$a;
$p.y=-$a;
$p.z=-$a;
$in[4]=$cube.AddPoint($p);
$cube.VertexN($in[4]);
$p.x=-$a;
$p.y=-$a;
$p.z=-$a;
$in[5]=$cube.AddPoint($p);
$cube.VertexN($in[5]);
$p.x=-$a;
$p.y=-$a;
$p.z=$a;
$in[6]=$cube.AddPoint($p);
$cube.VertexN($in[6]);
$p.x=$a;
$p.y=-$a;
$p.z=$a;
$in[7]=$cube.AddPoint($p);
$cube.VertexN($in[7]);
$cube.CloseFace();

$cube.OpenFace(0,0);
$cube.VertexN($in[1]);
$cube.VertexN($in[0]);
$cube.VertexN($in[4]);
$cube.VertexN($in[7]);
$cube.CloseFace();

$cube.OpenFace(0,0);
$cube.VertexN($in[2]);
$cube.VertexN($in[1]);
$cube.VertexN($in[7]);
$cube.VertexN($in[6]);
$cube.CloseFace();

$cube.OpenFace(0,0);
$cube.VertexN($in[3]);
$cube.VertexN($in[2]);
$cube.VertexN($in[6]);
$cube.VertexN($in[5]);
$cube.CloseFace();

$cube.OpenFace(0,0);
$cube.VertexN($in[0]);
$cube.VertexN($in[3]);
$cube.VertexN($in[5]);
$cube.VertexN($in[4]);
$cube.CloseFace();

$cube.Close();

thanks AGAIN Claude xD!
Logged

Claude

  • Sr. Member
  • ****
  • Posts: 285
    • View Profile
Re: Help
« Reply #8 on: July 03, 2009, 01:04:31 am »

Great.
For your other request.
Problem is here:
/* points /*
Should have been:
/* points */
All your point creation code was seen as a long comment
until the next */ on this line:
/* faces */
Result was illegal point index use in VertexN statement.

Bye
Claude
Logged

tiodiego

  • Newbie
  • *
  • Posts: 15
  • Quake 3 lover!
    • View Profile
    • Umriagplutix
Re: Help
« Reply #9 on: July 03, 2009, 01:33:39 am »

OMG!!!!! D:>
I search the error for hours xdddddddddddddd
and it was that simple little super detail  :o
cant believe it  :P
thanks for taking your time Claude xD!
Logged

Jdez

  • Full Member
  • ***
  • Posts: 105
    • View Profile
    • Tech Blog
Re: Help
« Reply #10 on: July 03, 2009, 05:09:59 am »

This is very interesting to look at! After working myself up I tried to creat a Cube primitive as well. (Attached). It is quite different so any suggestions will be welcome.

By the way If anyone could explain how the button code works(where you create a button) That would be much appreciated as well.
Logged
Having fun with ASL!
Tech blog: http://jaydez-tech.blogspot.com

Claude

  • Sr. Member
  • ****
  • Posts: 285
    • View Profile
Re: Help
« Reply #11 on: July 03, 2009, 11:09:12 am »

If you want to learn scripting,you need the ASL spec
open in your browser at all time so that you can read
the description of each function you encounter.

Here's the relevant section:

#button Directive

A button directive defines an image that Anim8or uses on a toolbar button.  The syntax is:

#button(<width>, <height>, <num-colors>, <data>…);

<width> and <height> are the dimensions of the image.  <num-colors> is the number of colors.  This must be 2.  <data> is a comma separated list of 32 bit decimal or hexadecimal integer constants that define the image.  The data is ordered by row starting at the top of the image.  Each new row starts a new value.

Images with 2 colors are bit-masks.  They use one bit per pixel.  Zeros represent the background color and ones the foreground color.

Here is an example bitmap directive for a 17 pixel wide, 25 pixel high bitmap:

#button(17, 25, 2,
    0x00000fc6, 0x00007079, 0x00008009, 0x00010f89,
    0x00013871, 0x000107e1, 0x0000c003, 0x0000300d,
    0x00000ff9, 0x00007079, 0x00008009, 0x00010f89,
    0x00013871, 0x000107e1, 0x0000c003, 0x0000300d,
    0x00000ff9, 0x00007079, 0x00008009, 0x00010f89,
    0x00013871, 0x000107e1, 0x0000c002, 0x0000300c,
    0x00000ff0);

If something is not clear,just ask.

Tyson Collins made a program to make icons for plug-in buttons.
It's named plugicon, I think.You'll find it on the Scripts page of the site.
Logged

Claude

  • Sr. Member
  • ****
  • Posts: 285
    • View Profile
Re: Help
« Reply #12 on: July 03, 2009, 12:06:49 pm »

Here's the mesh,you have created:
Code: [Select]
  mesh {
    name { "mesh01" }
    base {
      origin { (-5.1975 -3.0146 0) }
    }
    material { " -- default --" }
    smoothangle { 45 }
    /* 24 points, 6 faces, 24 uvCoords */
    materiallist {
      materialname { " -- default --" }
    }
    points {
      (-19 -19 -19) (19 -19 -19) (19 -19 19) (-19 -19 19) (-19 19 -19)
      (19 19 -19) (19 19 19) (-19 19 19) (-19 -19 -19) (-19 19 -19) (-19 19 19)
      (-19 -19 19) (-19 -19 -19) (-19 19 -19) (19 19 -19) (19 -19 -19)
      (19 -19 -19) (19 19 -19) (19 19 19) (19 -19 19) (-19 19 19) (19 19 19)
      (19 -19 19) (-19 -19 19)
    }
    texcoords {
      (0 1) (1 1) (1 0) (0 0) (0 1) (1 1) (1 0) (0 0) (0 1) (1 1) (1 0) (0 0)
      (0 1) (1 1) (1 0) (0 0) (0 1) (1 1) (1 0) (0 0) (0 1) (1 1) (1 0) (0 0)
    }
    faces {
      4 4 0 -1 ( (0 0) (1 1) (2 2) (3 3) )
      4 4 0 -1 ( (4 4) (5 5) (6 6) (7 7) )
      4 4 0 -1 ( (8 8) (9 9) (10 10) (11 11) )
      4 4 0 -1 ( (12 12) (13 13) (14 14) (15 15) )
      4 4 0 -1 ( (16 16) (17 17) (18 18) (19 19) )
      4 4 0 -1 ( (20 20) (21 21) (22 22) (23 23) )
    }
  }
It has 24 points and 24 uvCoords.
8 points and 4 uvCoords are enough.
See tiodiego's script to reuse the points by storing the indices.

int $length;
int $width;
int $height;
They should be float.You're rounding values by casting float to integer.

$length,$width and $height should be divided by 2.0 to keep dimensions
correct.

Bottom and 2 sides have reversed normals.See preceeding comment.
Logged

Jdez

  • Full Member
  • ***
  • Posts: 105
    • View Profile
    • Tech Blog
Re: Help
« Reply #13 on: July 03, 2009, 08:52:54 pm »

Oh right! I thought about dividing it in two but the in the plane script I don't recall it being done so I figured I wouldn't do it. About the button. What I don't understand Is what all the other letters and numbers are for.

#button(17, 25, 2,
    0x00000fc6, 0x00007079, 0x00008009, 0x00010f89,
What is the difference beetween 0x00008009 and 0x00010f89? couldn't it just be 0x11111111 and 0x00000000
    0x00013871, 0x000107e1, 0x0000c003, 0x0000300d,
    0x00000ff9, 0x00007079, 0x00008009, 0x00010f89,
    0x00013871, 0x000107e1, 0x0000c003, 0x0000300d,
    0x00000ff9, 0x00007079, 0x00008009, 0x00010f89,
    0x00013871, 0x000107e1, 0x0000c002, 0x0000300c,
    0x00000ff0);

Thanks for the advice claude
Logged
Having fun with ASL!
Tech blog: http://jaydez-tech.blogspot.com

Claude

  • Sr. Member
  • ****
  • Posts: 285
    • View Profile
Re: Help
« Reply #14 on: July 04, 2009, 12:07:06 am »

He could have use a binary format,but it takes lot of room.
So,he uses an hexadecimal format:
0x indicates that the following characters are hexadecimal.
Each character represents 4 bits(4 zeros or ones).
Example:
Code: [Select]
0x0       0       0       0       0        f         c        6
  0000    0000    0000    0000    0000     1111      1100     0110

Read the first 2 paragraphs and look at the table lower on the right
side.
http://en.wikipedia.org/wiki/Hexadecimal

Hope it helps.
Claude
« Last Edit: July 04, 2009, 12:08:53 am by Claude »
Logged
Pages: [1] 2