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

public const string enginedll = @"engine.dll";

public static void GetMaterialColor(Int64 owlInstanceMaterial, out UInt32 ambient, out UInt32 diffuse, out UInt32 emissive, out UInt32 specular)
        {
            System.Diagnostics.Debug.Assert(IsInstanceOfClass(owlInstanceMaterial, "Material"));

            GetDefaultColor(GetModel(owlInstanceMaterial), out ambient, out diffuse, out emissive, out specular);

            Int64 card = 0;
            IntPtr valuesPtr = IntPtr.Zero;
            GetObjectProperty(owlInstanceMaterial, GetPropertyByName(GetModel(owlInstanceMaterial), "color"), out valuesPtr, out card);

            if (card == 1)
            {
                Int64[] values = new Int64[card];
                System.Runtime.InteropServices.Marshal.Copy(valuesPtr, values, 0, (int) card);
                if (values[0] != 0)
                {
                    GetColor(values[0], out ambient, out diffuse, out emissive, out specular);
                }
            }
        }    

Property owlInstanceMaterial

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

Property ambient

Size: 32 bit / 4 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: 32 bit / 4 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: 32 bit / 4 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: 32 bit / 4 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.

using RDF;      //  include at least engine.cs within your solution

...

static void Main(string[] args)
{
    Int64   model = RDF.engine.CreateModel();

    if (model != 0)
    {
        //
        //  Classes
        //
        Int64   classBox = RDF.engine.GetClassByName(model, "Box");

        //
        //  Datatype Properties (attributes)
        //
        Int64   propertyLength = RDF.engine.GetPropertyByName(model, "length"),
                propertyWidth = RDF.engine.GetPropertyByName(model, "width"),
                propertyHeight = RDF.engine.GetPropertyByName(model, "height");

        //
        //  Instances (creating)
        //
        Int64   instanceBox = RDF.engine.CreateInstance(classBox, (string) null);

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

        RDF.engine.SetDatatypeProperty(instanceBox, propertyLength, ref length, 1);
        RDF.engine.SetDatatypeProperty(instanceBox, propertyWidth, ref width, 1);
        RDF.engine.SetDatatypeProperty(instanceBox, propertyHeight, ref height, 1);

        //
        //  Simple use of the derived information functions
        //
        double[]    centroid = new double[3];
        double      volume = RDF.engine.GetCentroid(instanceBox, (IntPtr) 0, (IntPtr) 0, out centroid[0]);

        RDF.engine.GetMaterialColor(instanceBox);

        Int64   vertexBufferSize = 0,
                indexBufferSize = 0;
        RDF.engine.CalculateInstance(instanceBox, out vertexBufferSize, out indexBufferSize, (IntPtr) 0);
        if (vertexBufferSize != 0 && indexBufferSize != 0)
        {
            float[] vertexBuffer = new float[6 * vertexBufferSize];
            RDF.engine.UpdateInstanceVertexBuffer(instanceBox, ref vertexBuffer[0]);

            Int32[] indexBuffer = new Int32[indexBufferSize];
            RDF.engine.UpdateInstanceIndexBuffer(instanceBox, ref indexBuffer[0]);

            //
            //  Reuse knowledge to improve performance (in case of single precision, with less accuracy)
            //
            volume = RDF.engine.GetCentroid(instanceBox, ref vertexBuffer[0], ref indexBuffer[0], out centroid[0]);
        }

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