GetMaterialColor (inline)

This function returns the color definition of any material instance. It will return default material in case the material does not have that specific color component defined.

Syntax

//
//   Strong typing definition
//


static  inline  void    GetMaterialColor(
                                OwlInstance             owlInstanceMaterial,
                                uint32_t                * ambient,
                                uint32_t                * diffuse,
                                uint32_t                * emissive,
                                uint32_t                * specular
                            )
{
    assert(IsInstanceOfClass(owlInstanceMaterial, "Material"));

    OwlInstance * values = nullptr;
    int64_t     card = 0;

    GetObjectProperty(
            owlInstanceMaterial,
            GetPropertyByName(
                    GetModel(owlInstanceMaterial),
                    "color"
                ),
            &values,
            &card
        );

    OwlInstance owlInstanceColor = (card == 1) ? values[0] : 0;
    if (owlInstanceColor) {
        GetColor(
                owlInstanceColor,
                ambient,
                diffuse,
                emissive,
                specular
            );
    }
    else {
        GetDefaultColor(
                GetModel(owlInstanceMaterial),
                ambient,
                diffuse,
                emissive,
                specular
            );
    }
}


//
//   Weak typing definition
//


static  inline  void    GetMaterialColor(
                                int64_t                 owlInstanceMaterial,
                                uint32_t                * ambient,
                                uint32_t                * diffuse,
                                uint32_t                * emissive,
                                uint32_t                * specular
                            )
{
    assert(IsInstanceOfClass(owlInstanceMaterial, "Material"));

    OwlInstance * values = nullptr;
    int64_t     card = 0;

    GetObjectProperty(
            owlInstanceMaterial,
            GetPropertyByName(
                    GetModel(owlInstanceMaterial),
                    "color"
                ),
            &values,
            &card
        );

    OwlInstance owlInstanceColor = (card == 1) ? values[0] : 0;
    if (owlInstanceColor) {
        GetColor(
                owlInstanceColor,
                ambient,
                diffuse,
                emissive,
                specular
            );
    }
    else {
        GetDefaultColor(
                GetModel(owlInstanceMaterial),
                ambient,
                diffuse,
                emissive,
                specular
            );
    }
}
    

Property owlInstanceMaterial

Size: 64 bit / 8 byte (value)
The handle of the Material instance.

Property ambient

Size: 64 bit / 8 byte (reference)
Defines a pointer to the ambient color as a 32 bit value that will be filled by this call; the 32 bit value is build up as 8 : 8 : 8 : 8 bits representing RGBA (or sometimes called RGBW), i.e. Red, Green, Blue, Alpha (transparency) each defined as a unsigned char value 0 .. 255.

Property diffuse

Size: 64 bit / 8 byte (reference)
Defines a pointer to the diffuse color as a 32 bit value that will be filled by this call; the 32 bit value is build up as 8 : 8 : 8 : 8 bits representing RGBA (or sometimes called RGBW), i.e. Red, Green, Blue, Alpha (transparency) each defined as a unsigned char value 0 .. 255.

Property emissive

Size: 64 bit / 8 byte (reference)
Defines a pointer to the emissive color as a 32 bit value that will be filled by this call; the 32 bit value is build up as 8 : 8 : 8 : 8 bits representing RGBA (or sometimes called RGBW), i.e. Red, Green, Blue, Alpha (transparency) each defined as a unsigned char value 0 .. 255.

Property specular

Size: 64 bit / 8 byte (reference)
Defines a pointer to the specular color as a 32 bit value that will be filled by this call; the 32 bit value is build up as 8 : 8 : 8 : 8 bits representing RGBA (or sometimes called RGBW), i.e. Red, Green, Blue, Alpha (transparency) each defined as a unsigned char value 0 .. 255.

Example (based on pure and inline API calls)

Here you can find code snippits that show how the API call GetMaterialColor can be used.

#include    "./include/engine.h"

void    main()
{
    int64_t model = CreateModel();

    if (model) {
        //
        //  Classes
        //
        int64_t classBox = GetClassByName(model, "Box");

        //
        //  Datatype Properties (attributes)
        //
        int64_t propertyLength = GetPropertyByName(model, "length"),
                propertyWidth = GetPropertyByName(model, "width"),
                propertyHeight = GetPropertyByName(model, "height");

        //
        //  Instances (creating)
        //
        int64_t instanceBox = CreateInstance(classBox, nullptr);

        double  length = 2.8,
                width = 1.3,
                height = 1.4;

        SetDatatypeProperty(instanceBox, propertyLength, &length, 1);
        SetDatatypeProperty(instanceBox, propertyWidth, &width, 1);
        SetDatatypeProperty(instanceBox, propertyHeight, &height, 1);

        //
        //  Simple use of the derived information functions
        //
        double  centroid[3],
                volume = GetCentroid(instanceBox, nullptr, nullptr, &centroid);


        GetMaterialColor(instanceBox);

        int64_t vertexBufferSize = 0,
                indexBufferSize = 0;
        CalculateInstance(instanceBox, &vertexBufferSize, &indexBufferSize, 0);
        if (vertexBufferSize && indexBufferSize) {
            float   * vertexBuffer = new float[6 * vertexBufferSize];
            UpdateInstanceVertexBuffer(instanceBox, vertexBuffer);

            int32_t * indexBuffer = new int32_t[indexBufferSize];
            UpdateInstanceIndexBuffer(instanceBox, indexBuffer);

            //
            //  Reuse knowledge to improve performance (in case of single precision, with less accuracy)
            //
            volume = GetCentroid(instanceBox, vertexBuffer, indexBuffer, &centroid);
        }

        //
        //  The resulting model can be viewed in 3D-Editor.exe
        //
        SaveModel(model, "c:\\created\\myFile.bin");
        CloseModel(model);
    }
}