Anim8or Community
General Category => ASL Scripts => Topic started by: Kubajzz on September 19, 2008, 06: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:
#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!!!!!
-
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:
#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:
#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?
-
If you change:
if ($S.GetNumPoints != $NewS.GetNumPoints)
to
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.
-
If you change:
if ($S.GetNumPoints != $NewS.GetNumPoints)
to
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... ???
-
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.
-
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 :)
-
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.
-
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.
-
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)