Anim8or Community

General Category => ASL Scripts => Topic started by: Kubajzz on September 19, 2008, 10:51:11 pm

Title: Real time command scripts - is that an error?
Post by: Kubajzz on September 19, 2008, 10:51:11 pm
Hello Steve,

I've been experimenting a little bit... I was thinking about a script for real time mirroring and I found a way that works, but I'm not sure if it is allowed to use ASL this way...

If I want a script to keep running and updating one mesh according to the changes made to another mesh, the only way is an infinite "while" cycle:
Code: [Select]
#command("object");

shape $S, $NewS;
attribute $Attr;
int $i, $j;

$S = project.curObject.LookupShape("mesh01"); /*get the original shape */

if ($S != NULL) {

$Attr = project.curObject.LookupAttribute("STOP");

/* create a copy */
$NewS = mesh();
$NewS.Open();

while ($Attr == NULL) {
  if ($S.GetNumPoints != $NewS.GetNumPoints) {

    /* copy the points and faces */
    for $i = 0 to $NewS.GetNumPoints()-1 do {
      $NewS.SetPointSelected($i, true);
    }
    $NewS.DeleteSelectedPoints();
    for $i = 0 to $S.GetNumPoints()-1 do {
      $NewS.AddPoint($S.GetPoint($i));
    }
    for $i = 0 to $S.GetNumFaces()-1 do {
      $NewS.OpenFace(0, 0);
      for $j = 0 to $S.GetNumSides($i)-1 do {
        $NewS.VertexN($S.GetFacePointIndex($i, $j));
      }
      $NewS.CloseFace();
    }
  }

  /* check for attribute to stop the cycle */
  $Attr = project.curObject.LookupAttribute("STOP");
}

$NewS.Close();

}

The script will find a shape called "mesh01" and if it exists, it will create a copy of that shape. The script keeps running and if you change the number of points of the original shape, the new shape will be updated. You can stop the process by creating an attribute called "STOP".

The script worked fine for me and I can't see any reason why the scripts shouldn't be used this way, but I thought I'd better ask... What do you think about it?

If you want to try out this script, be careful. It worked fine for me, but I'm afraid it may cause many unexpected errors... Remember, it's just an experiment!
Be sure to stop the script (create a new attribute "STOP") before exiting Anim8or!!!!!



Title: Another ASL bug?
Post by: Kubajzz on September 22, 2008, 09:37:09 am
One more ASL problem here (it's not worth starting a new topic for this...): Float4x4 type arrays don't work.

I made a simple test - the following script will print global coordinates of each point to the console:
Code: [Select]
#command("object");

shape $Shapes[0], $S;
int $i;
file $file;
float4x4 $GlobalTransform;
point3 $GlobalCoords;

project.curObject.GetShapes($Shapes);

$S = $Shapes[0];

$GlobalTransform = $S.GetGlobalTransform();

for $i = 0 to $S.GetNumPoints()-1 do {

  $GlobalCoords = $GlobalTransform.Project($S.GetPoint($i));

  $file.open("$console", "w");
  $file.print(PrintToString("Point# %d, XYZ: (%f, %f, %f)\n", $i, $GlobalCoords.x, $GlobalCoords.y, $GlobalCoords.z));
  $file.close;

}

When I change the $GlobalTransform variable to an array, the script will return (0, 0, 0) for all the points:
Code: [Select]
#command("object");

shape $Shapes[0], $S;
int $i;
file $file;
float4x4 $GlobalTransform[1];
point3 $GlobalCoords;

project.curObject.GetShapes($Shapes);

$S = $Shapes[0];

$GlobalTransform[0] = $S.GetGlobalTransform();

for $i = 0 to $S.GetNumPoints()-1 do {

  $GlobalCoords = $GlobalTransform[0].Project($S.GetPoint($i));

  $file.open("$console", "w");
  $file.print(PrintToString("Point# %d, XYZ: (%f, %f, %f)\n", $i, $GlobalCoords.x, $GlobalCoords.y, $GlobalCoords.z));
  $file.close;

}

I didn't find anything about float4x4 arrays in the ASL specification. Is there a reason why they don't work? Is it a bug?
Title: Re: Real time command scripts
Post by: CobraSpectre on September 22, 2008, 05:03:50 pm
If you change:

Code: [Select]
if ($S.GetNumPoints != $NewS.GetNumPoints)
to

Code: [Select]
if ($S != $NewS)
It updates when you move points. However if I use the cut tool on the shape I get an several errors "SimpleSolid::VertexN: Bad point index" that I have to click through, but then it's okay.

Very cool capability.
Title: Re: Real time command scripts - is that an error?
Post by: Kubajzz on September 22, 2008, 05:10:09 pm
If you change:

Code: [Select]
if ($S.GetNumPoints != $NewS.GetNumPoints)
to

Code: [Select]
if ($S != $NewS)
It updates when you move points. However if I use the cut tool on the shape I get an several errors "SimpleSolid::VertexN: Bad point index" that I have to click through, but then it's okay.

Very cool capability.

Oh, that's a nice idea... very simple and effective :) thanks

But we still don't know if it is legal to use ASL this way... ???
Title: Re: Real time command scripts
Post by: CobraSpectre on September 22, 2008, 05:18:35 pm
It's probably not a good idea to use this. Anim8or starts using all the CPU, ram use climbs and page file climbs as well.
Title: Re: Real time command scripts - is that an error?
Post by: Kubajzz on September 22, 2008, 05:53:16 pm
It's probably not a good idea to use this. Anim8or starts using all the CPU, ram use climbs and page file climbs as well.

Yes, you're right... Maybe I'll write a short script for myself and use it on my own risk :)
Title: Re: Real time command scripts - is that an error?
Post by: Raxx on September 23, 2008, 09:41:52 pm
If you make a fully working mirror script (this one just copies?), please post it up even if it's a rather raw way of doing it.

I'd suggest also automatically placing the mirrored mesh in a group so that it doesn't get affected by most modeling routines.
Title: Re: Real time command scripts - is that an error?
Post by: computeruser28 on October 01, 2008, 03:49:20 pm
I'd suggest also automatically placing the mirrored mesh in a group so that it doesn't get affected by most modeling routines.
Yes, that's a good idea. However, points, edges and faces in meshes in a group can be still deleted while grouped, so I might suggest a no-delete function on the mirrored mesh. Well, I don't know much about ASL, so I'll just leave it up to you.
Title: Re: Real time command scripts - is that an error?
Post by: Kubajzz on October 01, 2008, 06:56:17 pm
There's no need to 'protect' the copied mesh from deleting/moving points. If you edit the copy, it will be automatically changed back to the original shape.

btw. fully working mirror script based on this concept was created by CobraSpectre, check it out here: http://www.anim8or.com/smf/index.php?topic=1335.0 (http://www.anim8or.com/smf/index.php?topic=1335.0)