GetCentroid

Syntax

public const string EngineDLL = @"engine.dll";[DllImport(EngineDLL, EntryPoint = "GetCentroid")]
public static extern double GetCentroid(Int64 owlInstance, ref float vertices, ref Int32 indices, out double centroid);

[DllImport(EngineDLL, EntryPoint = "GetCentroid")]
public static extern double GetCentroid(Int64 owlInstance, ref float vertices, ref Int64 indices, out double centroid);

[DllImport(EngineDLL, EntryPoint = "GetCentroid")]
public static extern double GetCentroid(Int64 owlInstance, ref double vertices, ref Int32 indices, out double centroid);

[DllImport(EngineDLL, EntryPoint = "GetCentroid")]
public static extern double GetCentroid(Int64 owlInstance, ref double vertices, ref Int64 indices, out double centroid);

[DllImport(EngineDLL, EntryPoint = "GetCentroid")]
public static extern double GetCentroid(Int64 owlInstance, IntPtr vertices, IntPtr indices, out double centroid);    

Property owlInstance

Size: 64 bit / 8 byte (value)
The handle to the specific instance in the design tree. The instance handle is static within one open model but is most probably different when the same instance is opened in another model. The instance is always exactly of one unique class.

Property vertices

Size: 64 bit / 8 byte (reference)
The array of vertices, this array is allocated by the host application. Depending on SetFormat() the array exists of 32 bit (4 byte) single precision floats or 64 bit (8 byte) double precision floats. Each vertex elements exists of several elemens, i.e. X, Y, Z values, but optionally also nX, nY, nZ, texture coordinates, bitangent / binormal coordinates, colors etc. What is contained is defined by SetFormat() and can be retrieved via GetFormat(). The host application has to make sure enough memory is allocated for the vertices array.

Property indices

Size: 64 bit / 8 byte (reference)
The array of indices, this array is allocated by the host application. Depending on SetFormat() the array exists of 32 bit (4 byte) integers or 64 bit (8 byte) integeres.

Property centroid

Size: 64 bit / 8 byte (reference)
The centroid is expected to be a 3 element double value allocated by the host (i.e. 24 bytes). The function will fill in X, Y, Z as thew centroid coordinate in double precision.

Example

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

using Engine;

...

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

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

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

        //
        //  Instances (creating)
        //
        Int64   instanceBox = Engine.x86_64.CreateInstance(classBox, (string) null);

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

        Engine.x86_64.SetDatatypeProperty(instanceBox, propertyLength, ref length, 1);
        Engine.x86_64.SetDatatypeProperty(instanceBox, propertyWidth, ref width, 1);
        Engine.x86_64.SetDatatypeProperty(instanceBox, propertyHeight, ref height, 1);

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

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

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

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

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