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: ASL Attribute Functions  (Read 2465 times)

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 1532
    • View Profile
ASL Attribute Functions
« on: March 05, 2014, 10: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: 1532
    • View Profile
ASL Functions to make glass
« Reply #1 on: March 05, 2014, 11: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: 1447
    • View Profile
Re: ASL Attribute Functions
« Reply #2 on: March 06, 2014, 03:12:40 pm »

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: 1447
    • View Profile
Re: ASL Attribute Functions
« Reply #3 on: January 10, 2015, 04:13:35 am »

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