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 Attribute Functions  (Read 18379 times)

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 2126
    • View Profile
ASL Attribute Functions
« on: March 05, 2014, 05:48:43 pm »

ASL now has functions add new attributes and to change their types and values.  Previously you could only read existing attributes' values.  In addition attribute functions now work for materials.

Object attribute functions:
    attrubute object.NewAttribute(string name);

Material attribute functions:
    int material.GetNumAttributes(void);
    attribute material.GetAttribute(int index);
    attribute material.LookupAttribute(string name);
    attribute material.NewAttribute(string name);

Functions to set attribute values:
    int attribute.SetKind(AttributeTypes);
    int attribute.SetBoolValue(int);
    int attribute.SetIntValue(int);
    int attribute.SetFloatValue(float);
    int attribute.SetPoint3Value(point3);
    int attribute.SetQuaternionValue(quaternion);
    int attribute.SetStringValue(string);

Note: these functions automatically change the type of an attribute to match the type of the SetTypeValue call, so be careful when using them. I thought that this would make it easier to add new attributes but if you thing that they should check that the type matches, or convert the value, let me know.

They return 1 if they succeed which should always happen, for now. This will change if we decide that they should check the types in one form or another.

Logged

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 2126
    • View Profile
ASL Functions to make glass
« Reply #1 on: March 05, 2014, 06:15:27 pm »

Here is an example that builds a glass material using attributes:

material $MakeGlass(void)
{
    object $object;
    attribute $attribute;
    material $glass;

    $object = project.curObject;
    $glass = $object.NewMaterial("glass");
    $glass.diffuse = (0.96, 1.0, 0.98);
    $glass.Ks = 0.7;
    $glass.alpha = 0.1;
    $glass.roughness = 200;
    $attribute = $glass.NewAttribute("class");
    $attribute.SetStringValue("dielectric");
    $attribute = $glass.NewAttribute("IOR");
    $attribute.SetFloatValue(1.33);

    return $glass;
}

Logged

Raxx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1482
    • View Profile
Re: ASL Attribute Functions
« Reply #2 on: March 06, 2014, 10:12:40 am »

I tested some of this out, seems to work well enough :) I think the SetTypeValue approach is good enough.
Logged

Raxx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1482
    • View Profile
Re: ASL Attribute Functions
« Reply #3 on: January 09, 2015, 11:13:35 pm »

So, I'm working on something for the scene editor. Is attribute lookup and assignment for the scene editor not implemented yet?
Logged

2020 Hindsight

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: ASL Attribute Functions
« Reply #4 on: January 14, 2021, 01:24:39 pm »

Hi Steve,
I believe there should be a way to send data to a parametric plugin using attributes.

In the following code I am trying to define where I want a boat to be placed on my wave object (version 3 of the parametric plug-in script is called "ThirdWave").

As a first step towards doing this I tried the following code with the hope of being able to set a float called "boat1" in the .AN8 script, and read it (like time, and frame) in the .a8s script.

So in the .AN8 file I created the wave object like this: 
parameteric {
    name { "ThirdWave01" }
    script {
        object $object;
        attribute $attribute;
        $object = project.curObject;
        $attribute = $object.NewAttribute("boat1");
        $attribute = SetFloatValue( 123.45 );
    }
    plugin { "ThirdWave" }
    base {
      origin { (-347.68 65 -347.68) }
      orientation { (0.70711 0 0 0.70711) }
    }
    material { "dielectric 1.33" }
    parameter { "X Tiles" int 96 }
    parameter { "Y Tiles" int 96 }
    parameter { "Scale" float 10.865 "scale" "scale_x" }
    parameter { "Seed" int 3454 }
    parameter { "Wave origin count" int 23 }
    parameter { "Max wave height" float 1.8 }
    parameter { "Mean wavelength" float 15 }
    parameter { "Min wave distance" float 100 }
    parameter { "Wave direction" float -140 }
    parameter { "Time" float 92 }

  }


And in ThirdWave.a8s I tried the read the value of boat1 with this code:   

    file $c;
    $c.open("$console", "w");
    $c.print("time = %5.2f\tframe = %d\t boat1=%f\n", time, frame, boat1);


Anim8or didn't like this, and so reported "Unable to locate script for Parametric plug-in: ThirdWave". It is the variable boat1 it doesn't like. It runs if you comment out the print line - but the point of the test is to transfer a value in boat1.

Is what I'm trying to do even possible? If so how?

In addition to sending boat position to "ThirdWave.a8s" I want to return the wave height and angle of the water surface at that point back to the .AN8 controller script so that the boat can bob on the water. One of the objectives is that boats can be placed without editing the .a8s parametric plug-in script - and hopefully implement 'V' shape trails as they move across the water.

The references I have looked at are pages 135-136 of https://www.anim8or.com/learn/pdf/anim8or_manual_1.01.1318_mark.pdf
and this thread.
Logged

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 2126
    • View Profile
Re: ASL Attribute Functions
« Reply #5 on: January 14, 2021, 01:42:52 pm »

It isn't possible to read attributes from a parameteric plugin script. The origional idea of a parameteric object is that it should be statically defined, independent of it's environment and of time. So any reference to outside values was forbidden. Allowing them to reference time/frame number breaks this model, of course, but it is simpler than allowing arbitrary references which can be very complex to compute, so thay aren't allowed (at the present :))
Logged

2020 Hindsight

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: ASL Attribute Functions
« Reply #6 on: January 14, 2021, 05:26:33 pm »

:( And here was me hoping to talk you into making scan accept strings as well as file handles:

scanner $scan;
string $commandString; 
$commandString = "boat,15,20,4,1,30,6,1\nboat,30,10,4,1,-150,6,1\n";
$scan.initialize($commandStirng);
Logged