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"

Author Topic: ASL issues  (Read 13161 times)

Trevor

  • Full Member
  • ***
  • Posts: 220
  • Goldfinger64 Dev OS:10 CPU:5960x Gfx:RX480
    • View Profile
    • LS Tech Services
ASL issues
« on: May 05, 2020, 09:46:24 pm »

ASL Bugs and Feature requests as of Build 1379

Nested If statements cannot return to caller, an8 hangs, turns white, titlebar states (Not Responding) and console stops output.
Code: [Select]
// Return True if Vertex Exists, Save NewID Mapping to $gVtxIDMap
int $VertexExists(point3 $xyz, string $uv, point3 $rgb, int $a)
{
int $i, $r;

for ($i = 0; $i < $gXYZs.size; $i++)
{
$DebugPrint(PrintToString("Compare to %d", $i));
// cant do && "Illegal Type arg"
if (($xyz.x == $gXYZs[$i].x) && ($xyz.y == $gXYZs[$i].y) && ($xyz.z == $gXYZs[$i].z))
{
if ($uv == $gSTs[$i])
{
if (($rgb.x == $gRGBs[$i].x) && ($rgb.y == $gRGBs[$i].y) && ($rgb.z == $gRGBs[$i].z))
{
if ($a == $gAs[$i])
{
$gVtxIDMap[$gVtxIDMap.size - 1] = $i;
//return true;
$r = 1; //BUG cannot return from here, this makes script wasteful
}
}
}
}
}
return $r;
}

Attributes cannot return NULL...
workaround: Use a global Attribute and use Push/Size = 0
Code: [Select]
//return $gCurObject.GetAttribute($i);
$gLookupAttributeUcase.push($gCurObject.GetAttribute($i));
return;
}
}
//return NULL;
$gLookupAttributeUcase.size = 0;
}


As Documented already Recursion is not supported, however it would be good to support for parsing trees.
Code: [Select]
void $ParseChildren(shape $Shape)
{
...
$DebugPrint("Parsing Children " + $Shape.name);

if ($Shape.GetKind() == SHAPE_KIND_GROUP)
{
//Recursion Not Supported
$ConsolePrint("Groups are not supported\n");
//$ParseChildren($Shape);
}
...
}


I also put together some functions for people to use but hope for native support for them instead.
Code: [Select]
// Returns Index to start of $Contains if within $Base.
// Returns False if $Base does not contain $Contains
int $StringContains(string $Base, string $Contains)
{
int $i, $r;
string $Comparitor;
//$DebugPrint(PrintToString("looking for %s in %s", $Contains, $Base));
for ($i = 0; $i < max(0,($Base.length - $Contains.length)); $i++)
{
$Comparitor = $Base.SubString($i, ($i + ($Contains.length-1)));
$DebugPrint(PrintToString("contains %s at %d", $Comparitor, $i));
if ($Comparitor == $Contains)
{
$r = $i +1;
break;
}
}
//$DebugPrint(PrintToString("returning %d", $r));

return $r;
}

// Split String $Base anywhere $Split occurs
// Returns Array (via $gSplit) of Strings
int $StringSplit(string $Base, string $Split)
{
int $r, $Start, $End;
$gSplit.size = 0;
while (1)//$StringContains($Base.SubString($Start, $Base.length), $Split))
{
$End = $StringContains($Base.SubString($Start, $Base.length), $Split);

if (!$End)
{
//$r = 0;
$DebugPrint($Base.SubString($Start, $Base.length));
$gSplit.push($Base.SubString($Start, $Base.length));
break;
}
$r++;

$DebugPrint($Base.SubString($Start, $End - 1 - $Split.length));
$gSplit.push($Base.SubString($Start, $End - 1 - $Split.length));
$Start = $Start + ($End-1) + ($Split.length);
}
$DebugPrint(PrintToString("Split legnth %d, contains %s", $gSplit.size, $gSplit[$gSplit.size-1]));
return $r;
}

// Returns String from Array (via $gSplit) of Strings
string $StringJoin()
{
int $i;
string $t;

for($i=0; $i< $gSplit.size; $i++)
{
$t = $t + $gSplit[$i];
}
$gSplit.size = 0;
return $t;
}

// Returns String as UPPER CASE
string $StringToUpper(string $str)
{
int $i, $t;
for ($i = 0; $i < $str.length; $i++)
{
$t = $str.GetChar($i);
if (($t >= 97) && ($t <= 122))
{
$t = $t - 32;
$str = $str.SetChar($t, $i);
}
}
return $str;
}

// Looks up Attribute by Name (Case-insensitive)
void $LookupAttribute(string $str, int $CaseCompare)
{
int $i, $r;
attribute $temp;
if (!$CaseCompare)
{
$str = $StringToUpper($str);
}

$DebugPrint("Looking up Attribute " + $str);

for ($i = 0; $i < $gCurObject.GetNumAttributes(); $i++)
{
$temp = $gCurObject.GetAttribute($i);
if (($StringToUpper($temp.GetName()) == $str) && (!$CaseCompare || ($temp.GetName() == $str)))
{
//return $gCurObject.GetAttribute($i);
$DebugPrint("Found Attribute " + $str);
$gLookupAttribute.push($temp);
$r = true;
break;
}
}
if ($r) return;
//return NULL;
$gLookupAttribute.size = 0;
}

// Convert quaternion to xyz (PYR)
point3 $QuaternionToPYR(quaternion $q) {
point3 $angles;
float $sin_cos, $cos_cos;

// pitch (x-axis rotation)
$sin_cos = 2 * ($q.w * $q.x + $q.y * $q.z);
$cos_cos = 1 - 2 * ($q.x * $q.x + $q.y * $q.y);
$angles.x = atan2($sin_cos, $cos_cos);

// yaw (y-axis rotation)
$sin_cos = 2 * ($q.w * $q.y - $q.z * $q.x);
if (abs($sin_cos) >= 1)
{
$angles.y = clamp($sin_cos, -PI / 2, PI / 2); // use 90 degrees if out of range
}
else
{
$angles.y = asin($sin_cos);
}

// role (z-axis rotation)
$sin_cos = 2 * ($q.w * $q.z + $q.x * $q.y);
$cos_cos = 1 - 2 * ($q.y * $q.y + $q.z * $q.z);
$angles.z = atan2($sin_cos, $cos_cos);

return $angles;
}

// Returns the integral value that is nearest to val, with halfway cases rounded away from zero.
int $round(float $val)
{
if ($val >= 0)
{
if (fract($val) >= 0.5)
{
return ceil($val);
}
else
{
return floor($val);
}
}
if (fract($val) > -0.5)
{
return ceil($val);
}
//else
return floor($val);
}

//Cast To Integer
int $int(float $val)
{
return $val;
}

//Cast to Float
float $float(int $val)
{
return $val;
}


I also took the documentation and put it in a h file for use in VS.
I shifted the comments round so it works with Intellisense and word completion as you type.

Which reminds me, any chance of ignoring #include "a8s.h" and then including other script files?
Also #if(0) #endif would be good to block certain code blocks from functioning

Many Thanks
Trev[/code]
« Last Edit: June 09, 2020, 05:52:58 pm by Trevor »
Logged

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 2124
    • View Profile
Re: ASL issues
« Reply #1 on: May 06, 2020, 09:57:05 am »

Trevor, I split this into a separate topic to make it more visible.
« Last Edit: May 06, 2020, 04:33:35 pm by Steve »
Logged

Trevor

  • Full Member
  • ***
  • Posts: 220
  • Goldfinger64 Dev OS:10 CPU:5960x Gfx:RX480
    • View Profile
    • LS Tech Services
Re: ASL issues
« Reply #2 on: May 06, 2020, 01:38:07 pm »

Thanks, I wasn't sure where to post, its ASL but its related to current dev so I chose the later:)

Ive noticed that tridata doesn't seem to keep triangle RGB separate, i.e. I had one triangle which was green, but the tridata only had one of the verticies use that material with the other 2 using other materials.
Is there a pattern here? or is it random?

Trev
« Last Edit: May 06, 2020, 01:39:54 pm by Trevor »
Logged

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 2124
    • View Profile
Re: ASL issues
« Reply #3 on: May 06, 2020, 04:35:45 pm »

In Anim8or polygons use a single material. You can't assign different materials to the vertices.
Logged

Trevor

  • Full Member
  • ***
  • Posts: 220
  • Goldfinger64 Dev OS:10 CPU:5960x Gfx:RX480
    • View Profile
    • LS Tech Services
Re: ASL issues
« Reply #4 on: May 06, 2020, 05:41:18 pm »

Yes, all the more confusing as to why tridata only has 1 coloured vertex


Possibly my bad... I missed something from the obj plugin


Trev
« Last Edit: May 06, 2020, 05:46:14 pm by Trevor »
Logged

Trevor

  • Full Member
  • ***
  • Posts: 220
  • Goldfinger64 Dev OS:10 CPU:5960x Gfx:RX480
    • View Profile
    • LS Tech Services
Re: ASL issues
« Reply #5 on: June 09, 2020, 05:48:30 pm »

I fixed and added some more "basic" functions above but would still prefer to se language support for them instead including ToUpper, Split, Join, casting (Int/Float), case insensitive attributes and quaternionToPYR

Trev
Logged

Trevor

  • Full Member
  • ***
  • Posts: 220
  • Goldfinger64 Dev OS:10 CPU:5960x Gfx:RX480
    • View Profile
    • LS Tech Services
Re: ASL issues
« Reply #6 on: June 18, 2020, 03:13:23 pm »

Steve, would you be able to say if asl function recursion is possible and if so how long it might take to implement?
Just wondering because I would like to parse groups as groups and might have to make a workaround but obviously recursion would be great and an instant fix for my loop.

thanks,
Trev
Logged

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 2124
    • View Profile
Re: ASL issues
« Reply #7 on: June 18, 2020, 03:39:50 pm »

Sorry, Trevor, but adding recursion is a whole lot of work and I don't have plans to add it in the near future. I agree that it would be quite useful, though, so I'll keep it in mind.
Logged

Trevor

  • Full Member
  • ***
  • Posts: 220
  • Goldfinger64 Dev OS:10 CPU:5960x Gfx:RX480
    • View Profile
    • LS Tech Services
Re: ASL issues
« Reply #8 on: June 18, 2020, 03:51:02 pm »

ok no probs

trev
Logged

Trevor

  • Full Member
  • ***
  • Posts: 220
  • Goldfinger64 Dev OS:10 CPU:5960x Gfx:RX480
    • View Profile
    • LS Tech Services
Re: ASL issues
« Reply #9 on: June 24, 2020, 08:29:07 pm »

YAY, I managed to implement my own recursion in an8 script :)

this is the specific function;
Code: [Select]
int $ParseChildren(shape $Shape)
{
// Set up Stacks instead of normal vars
int   $si[0];
shape $sShape[0];
int   $Result, $i, $j;
shape $CurShape, $ChildShapes[0];

//Push Shape to stack
$sShape.push($Shape);
//Push Stacked Counter
$si.push(0);

$Result = true;

//While shapes are on stack and result is still true (No Fail)
while ($sShape.size && $Result)
{
//Get current shape
$CurShape = $sShape.pop;

if ($CurShape.GetKind() == SHAPE_KIND_GROUP)
{
//Recursion would happen here
// $ParseChildren($CurShape)
//… however ...

//Get Children
$CurShape.GetShapes($ChildShapes);
$DebugPrint("getting Children " + $CurShape.name);

$i = $si.pop; //get last i off stack
$DebugPrint(PrintToString("getting i %d, stacksize %d ", $i, $si.size));

if ($i < $ChildShapes.size)
{
$DebugPrint("Parsing Children " + $CurShape.name);
//Has Children, traverse tree
$sShape.push($CurShape); //Push current Node to stack
$sShape.push($ChildShapes[$i]); //push next Node to stack
$DebugPrint("pushing child  " + $ChildShapes[$i].name);

if(!($StringContains($ChildShapes[$i].name, "BSP")))
{
$PrintTree.push("-"+$ChildShapes[$i].name);
for ($j = 1; $j < $sShape.size; $j++)
{
$PrintTree[$PrintTree.size - 1] = "\t|" + $PrintTree[$PrintTree.size - 1];
}
}


$i++;
$si.push($i); //Push(save) current nodes counter to counter stack
$DebugPrint(PrintToString("getting i %d, stacksize %d ", $i, $si.size));
if ($ChildShapes[$i-1].GetKind() == SHAPE_KIND_GROUP)
{
$si.push(0); //Stack new counter
$DebugPrint(PrintToString("accidental infinit group? getting i %d, stacksize %d ", $i, $si.size));
}
}
else
{
$DebugPrint("end of branch");
//reached end of branch
$C_File.print("/*\n");
$C_File.print("* Group: \n");
$C_File.print("*        Name      = %s\n", $CurShape.name);
$C_File.print("*        Objects   = %d\n", $ChildShapes.size);
$C_File.print("*/\n");

$C_File.print("static Gfx %s_dl[] = {\n", $CurShape.name);
for ($i = 0; $i < $ChildShapes.size; $i++)
{
if ($StringContains($ChildShapes[$i].name, "BSP"))
{
$ParseBSPNode($ChildShapes[$i]);
}
else
{
$C_File.print("    gsSPDisplayList(&%s_dl),\n", $ChildShapes[$i].name);
}
}

$C_File.print("    gsSPEndDisplayList(),\n};\n\n");



}
}
else if ($CurShape.GetKind() == SHAPE_KIND_PATH ||
$CurShape.GetKind() == SHAPE_KIND_MODIFIER ||
$CurShape.GetKind() == SHAPE_KIND_TEXT)
{
/* No 3D mesh to output. */
}
else
{
//Print mesh
if ($StringContains($CurShape.name, "BSP"))
{
//Do Nothing
}
else
{
$Result = $GenerateArray($CurShape);
//$PrintTree.push( PrintToString("%s", $CurShape.name));
}
}


}
return $Result;
}
Logged

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 2124
    • View Profile
Re: ASL issues
« Reply #10 on: June 25, 2020, 05:32:25 pm »

Nice job. I know it's more work to implement it this way. Maybe someday I'll get recursion done!
Logged