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

//
//   Linux, MacOS and non-Visual Studio Windows solutions (pure C++11 / C++98)
//

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

    int64_t * values = nullptr, card = 0;
    GetObjectProperty(
            owlInstanceMaterial,
            GetPropertyByName(
                    GetModel(owlInstanceMaterial),
                    (char*) "color"
                ),
            &values,
            &card
        );

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


//
//   Visual Studio for Windows
//

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

    int64_t * values = nullptr, card = 0;
    GetObjectProperty(
            owlInstanceMaterial,
            GetPropertyByName(
                    GetModel(owlInstanceMaterial),
                    (char*) "color"
                ),
            &values,
            &card
        );

    int64_t 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/engineinline.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, ¢roid);

        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, ¢roid);
        }

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