Load Material via Editor

57 views
Skip to first unread message

Alexander M

unread,
Oct 4, 2013, 4:13:39 PM10/4/13
to urh...@googlegroups.com
Hi!
Is it possible to assign Material (Shader etc) type variable in the ScriptInstance (AngelScript API) through the Editor?
Thanks.

Chris Friesen

unread,
Oct 4, 2013, 6:20:18 PM10/4/13
to urh...@googlegroups.com
Yup.

class AddMat : ScriptObject
{
    void Start()
    {
        StaticModel@ model = node.GetComponent("StaticModel");
        Material@ mat = cache.GetResource("Material", "Materials/CloudPlane.xml");
        model.material = mat;
    }
}

Is that what you are trying to do?

Chris Friesen

unread,
Oct 4, 2013, 6:42:59 PM10/4/13
to urh...@googlegroups.com
node is a reference to the current node

all variables in the class that are not prefixed with an _ are available in the editor.

class AddMat : ScriptObject
{
    string materialName;
    void Start()
    {
        StaticModel@ model = node.GetComponent("StaticModel");
        Material@ mat = cache.GetResource("Material", materialName);
        model.material = mat;
    }
}

Alexander M

unread,
Oct 5, 2013, 6:59:45 AM10/5/13
to urh...@googlegroups.com
Thanks for the replies!
Sorry, I'm not exactly described the problem. Is there any possibility to call Resource Picker for Material like in the BillboardSet component?



Lasse Öörni

unread,
Oct 5, 2013, 7:25:04 AM10/5/13
to urh...@googlegroups.com
Right now handles to Resource objects are not supported by ScriptInstance variable introspection, only Node & Component subclasses.

I believe it is doable, but requires expansion of the information stored for registered object classes. Basically, need a way to determine at runtime (preferably without hardcoding) when a class name is a Resource subclass.


Lasse Öörni

unread,
Oct 5, 2013, 5:15:38 PM10/5/13
to urh...@googlegroups.com
There's now support for assigning script object's resource handle variables from the editor. Here's a (stupid) example script which would set a different material out of two for a StaticModel each frame:

class MaterialChanger : ScriptObject
{
    Material@ mat1;
    Material@ mat2;
    uint index = 0;

    void Update(float timeStep)

    {
        StaticModel@ model = node.GetComponent("StaticModel");
        if (model is null)
            return;

        index++;
        if (index & 1 != 0)
            model.material = mat1;
        else
            model.material = mat2;
    }
}


Reply all
Reply to author
Forward
0 new messages