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: Real time command scripts - is that an error?  (Read 4919 times)

Kubajzz

  • Flying Platypus
  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 548
  • Little doggie ate my avatar...
    • View Profile
Real time command scripts - is that an error?
« 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!!!!!



« Last Edit: September 19, 2008, 10:53:50 pm by Kubajzz »
Logged

Kubajzz

  • Flying Platypus
  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 548
  • Little doggie ate my avatar...
    • View Profile
Another ASL bug?
« Reply #1 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?
Logged

CobraSpectre

  • Newbie
  • *
  • Posts: 39
    • View Profile
Re: Real time command scripts
« Reply #2 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.
Logged

Kubajzz

  • Flying Platypus
  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 548
  • Little doggie ate my avatar...
    • View Profile
Re: Real time command scripts - is that an error?
« Reply #3 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... ???
Logged

CobraSpectre

  • Newbie
  • *
  • Posts: 39
    • View Profile
Re: Real time command scripts
« Reply #4 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.
Logged

Kubajzz

  • Flying Platypus
  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 548
  • Little doggie ate my avatar...
    • View Profile
Re: Real time command scripts - is that an error?
« Reply #5 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 :)
Logged

Raxx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1446
    • View Profile
Re: Real time command scripts - is that an error?
« Reply #6 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.
Logged

computeruser28

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Real time command scripts - is that an error?
« Reply #7 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.
Logged

Kubajzz

  • Flying Platypus
  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 548
  • Little doggie ate my avatar...
    • View Profile
Re: Real time command scripts - is that an error?
« Reply #8 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
Logged