General Category > ASL Scripts
Help
Jdez:
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
Claude:
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.
Jdez:
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
tiodiego:
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();
--- End quote ---
it sends some error regarding a bad point index on line 58, so it has to be a problem with the pos vector.
Claude:
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
Navigation
[0] Message Index
[#] Next page
Go to full version