CalculateInstance

This function prepares the content to be ready so the buffers can be filled.
It returns the minimum size the buffers should be. This is only the case when the pointer is given, all arguments are allowed to be nullptr.

Note: This function needs to be called directly before UpdateVertexBuffer(),
    UpdateIndexBuffer() and UpdateTransformationBuffer().

Syntax

public const string EngineDLL = @"engine.dll";[DllImport(EngineDLL, EntryPoint = "CalculateInstance")]
public static extern Int64 CalculateInstance(Int64 owlInstance, out Int64 vertexBufferSize, out Int64 indexBufferSize, out Int64 transformationBufferSize);

[DllImport(EngineDLL, EntryPoint = "CalculateInstance")]
public static extern Int64 CalculateInstance(Int64 owlInstance, out Int64 vertexBufferSize, out Int64 indexBufferSize, IntPtr transformationBufferSize);

[DllImport(EngineDLL, EntryPoint = "CalculateInstance")]
public static extern Int64 CalculateInstance(Int64 owlInstance, out Int64 vertexBufferSize, IntPtr indexBufferSize, IntPtr transformationBufferSize);

[DllImport(EngineDLL, EntryPoint = "CalculateInstance")]
public static extern Int64 CalculateInstance(Int64 owlInstance, IntPtr vertexBufferSize, IntPtr indexBufferSize, IntPtr transformationBufferSize);    

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 vertexBufferSize

Size: 32 bit / 4 byte (reference)
The calculated size that is required for the vertex buffer (vertices). This only returns a value if it has a non-zero input value.

Property indexBufferSize

Size: 32 bit / 4 byte (reference)
The calculated size that is required for the index buffer (indices). The host will require to allocate the index array, depending on SetFormat(), this will be 4 bytes * indexBufferSize (32 bit integer) or 8 bytes * indexBufferSize (64 bit integer).

Property transformationBufferSize

Size: 32 bit / 4 byte (reference)
the calculated size that is required for the transformation buffer

Example

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

using Engine;

const Int64 flagbit0 = 1;                           // 2^^0                          0000.0000..0000.0001
const Int64 flagbit1 = 2;                           // 2^^1                          0000.0000..0000.0010
const Int64 flagbit2 = 4;                           // 2^^2                          0000.0000..0000.0100
const Int64 flagbit3 = 8;                           // 2^^3                          0000.0000..0000.1000

const Int64 flagbit4 = 16;                          // 2^^4                          0000.0000..0001.0000
const Int64 flagbit5 = 32;                          // 2^^5                          0000.0000..0010.0000
const Int64 flagbit6 = 64;                          // 2^^6                          0000.0000..0100.0000
const Int64 flagbit7 = 128;                         // 2^^7                          0000.0000..1000.0000

const Int64 flagbit8 = 256;                         // 2^^8                          0000.0001..0000.0000
const Int64 flagbit9 = 512;                         // 2^^9                          0000.0010..0000.0000
const Int64 flagbit10 = 1024;                       // 2^^10                         0000.0100..0000.0000
const Int64 flagbit11 = 2048;                       // 2^^11                         0000.1000..0000.0000

const Int64 flagbit12 = 4096;                       // 2^^12                         0001.0000..0000.0000
const Int64 flagbit13 = 8192;                       // 2^^13                         0010.0000..0000.0000
const Int64 flagbit14 = 16384;                      // 2^^14                         0100.0000..0000.0000
const Int64 flagbit15 = 32768;                      // 2^^15                         1000.0000..0000.0000

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

    if (model != 0)
    {
        //
        //  Classes
        //
        Int64   classCollection = Engine.x86_64.GetClassByName(model, "Collection"),
                classCylinder = Engine.x86_64.GetClassByName(model, "Cylinder"),
                classLine3D = Engine.x86_64.GetClassByName(model, "Line3D"),
                classPoint3D = Engine.x86_64.GetClassByName(model, "Point3D");

        //
        //  Object Properties (relations)
        //
        Int64   propertyObjects = Engine.x86_64.GetPropertyByName(model, "objects");

        //
        //  Datatype Properties (attributes)
        //
        Int64   propertyCoordinates = Engine.x86_64.GetPropertyByName(model, "coordinates"),
                propertyLength = Engine.x86_64.GetPropertyByName(model, "length"),
                propertyPoints = Engine.x86_64.GetPropertyByName(model, "points"),
                propertyRadius = Engine.x86_64.GetPropertyByName(model, "radius"),
                propertySegmentationParts = Engine.x86_64.GetPropertyByName(model, "segmentationParts");

        //
        //  Instances (creating)
        //
        Int64   instanceCollection = Engine.x86_64.CreateInstance(classCollection, (string) null),
                instanceCylinder = Engine.x86_64.CreateInstance(classCylinder, (string) null),
                instanceLine3D = Engine.x86_64.CreateInstance(classLine3D, (string) null),
                instancePoint3D_I = Engine.x86_64.CreateInstance(classPoint3D, (string) null),
                instancePoint3D_II = Engine.x86_64.CreateInstance(classPoint3D, (string) null);

        Int64[] objects = { instancePoint3D_I, instanceLine3D, instanceLine3D, instancePoint3D_II, instanceCylinder, instancePoint3D_I };
        Engine.x86_64.SetObjectProperty(instanceCollection, propertyObjects, ref objects[0], 6);

        double[]    coordinates_I = { 1.0, 2.0, 3.0 },
                    coordinates_II = { 4.0, 5.0, 6.0 },
                    points = { 0.0, 0.0, -1.0, 5.0, 3.0, 0.0 };
        double      length = 4.0,
                    radius = 2.0;
        Int64       segmentationParts = 36;

        Engine.x86_64.SetDatatypeProperty(instanceCylinder, propertyLength, ref length, 1);
        Engine.x86_64.SetDatatypeProperty(instanceCylinder, propertyRadius, ref radius, 1);
        Engine.x86_64.SetDatatypeProperty(instanceCylinder, propertySegmentationParts, ref segmentationParts, 1);
        Engine.x86_64.SetDatatypeProperty(instanceLine3D, propertyPoints, ref points[0], 6);
        Engine.x86_64.SetDatatypeProperty(instancePoint3D_I, propertyCoordinates, ref coordinates_I[0], 3);
        Engine.x86_64.SetDatatypeProperty(instancePoint3D_II, propertyCoordinates, ref coordinates_II[0], 3);

        Int64   myInstance = instanceCollection;

        ...
        ...     //  create, load or edit myInstance, in this case a simple Collection is used as input
        ...

        //
        //  Initializing the mask with all possible options
        //
        Int64   setting = 0,
                mask = Engine.x86_64.GetFormat(0, 0);

        setting += 0 * flagbit2;        //    SINGLE / DOUBLE PRECISION (float / double)
        setting += 0 * flagbit3;        //    32 / 63 BIT INDEX ARRAY (int32_t / int64_t)

        setting += 1 * flagbit4;        //    OFF / ON VECTORS (x, y, z) 
        setting += 1 * flagbit5;        //    OFF / ON NORMALS (Nx, Ny, Nz)

        setting += 1 * flagbit8;        //    OFF / ON TRIANGLES
        setting += 1 * flagbit9;        //    OFF / ON LINES
        setting += 1 * flagbit10;       //    OFF / ON POINTS

        setting += 0 * flagbit12;       //    OFF / ON WIREFRAME FACES
        setting += 0 * flagbit13;       //    OFF / ON WIREFRAME CONCEPTUAL FACES

        Int64   vertexElementSizeInBytes = Engine.x86_64.SetFormat(model, setting, mask);
        System.Diagnostics.Debug.Assert(vertexElementSizeInBytes == (3 + 3) * sizeof(float));

        ...

        Int64   vertexBufferSize = 0, indexBufferSize = 0;
        Engine.x86_64.CalculateInstance(myInstance, out vertexBufferSize, out indexBufferSize, (IntPtr) 0);

        if (vertexBufferSize != 0 && indexBufferSize != 0)
        {
            float[] vertices = new float[vertexBufferSize * (vertexElementSizeInBytes / sizeof(float))];
            Int32[] indices = new Int32[indexBufferSize];

            Engine.x86_64.UpdateInstanceVertexBuffer(myInstance, ref vertices[0]);
            Engine.x86_64.UpdateInstanceIndexBuffer(myInstance, ref indices[0]);

            Int64   triangleCnt = 0, lineCnt = 0, pointCnt = 0,
                    conceptualFaceCnt = Engine.x86_64.GetConceptualFaceCnt(myInstance);
            for (Int64 index = 0; index < conceptualFaceCnt; index++)
            {
                Int64   startIndexTriangles = 0, noIndicesTrangles = 0,
                        startIndexLines = 0, noIndicesLines = 0,
                        startIndexPoints = 0, noIndicesPoints = 0;

                Engine.x86_64.GetConceptualFaceEx(
                        myInstance, index,
                        out startIndexTriangles, out noIndicesTrangles,
                        out startIndexLines, out noIndicesLines,
                        out startIndexPoints, out noIndicesPoints,
                        (IntPtr) 0, (IntPtr) 0,
                        (IntPtr) 0, (IntPtr) 0
                    );

                //  
                //  Calculate space required for arrays
                //
                triangleCnt += noIndicesTrangles / 3;
                lineCnt += noIndicesLines / 2;
                pointCnt += noIndicesPoints;
            }

            Int32[] triangleIndices = (triangleCnt != 0) ? new Int32[3 * triangleCnt] : null,
                    lineIndices = (lineCnt != 0) ? new Int32[2 * lineCnt] : null,
                    pointIndices = (pointCnt != 0) ? new Int32[pointCnt] : null;

            Int64   triangleIndicesOffset = 0, lineIndicesOffset = 0, pointIndicesOffset = 0;
            for (Int64 index = 0; index < conceptualFaceCnt; index++)
            {
                Int64   startIndexTriangles = 0, noIndicesTrangles = 0,
                        startIndexLines = 0, noIndicesLines = 0,
                        startIndexPoints = 0, noIndicesPoints = 0;

                Engine.x86_64.GetConceptualFaceEx(
                        myInstance, index,
                        out startIndexTriangles, out noIndicesTrangles,
                        out startIndexLines, out noIndicesLines,
                        out startIndexPoints, out noIndicesPoints,
                        (IntPtr) 0, (IntPtr) 0,
                        (IntPtr) 0, (IntPtr) 0
                    );

                if (noIndicesTrangles != 0)
                {
                    Array.Copy(indices, startIndexTriangles, triangleIndices, triangleIndicesOffset, noIndicesTrangles);
                    triangleIndicesOffset += noIndicesTrangles;
                }

                if (noIndicesLines != 0)
                {
                    Array.Copy(indices, startIndexLines, lineIndices, lineIndicesOffset, noIndicesLines);
                    lineIndicesOffset += noIndicesLines;
                }

                if (noIndicesPoints != 0)
                {
                    Array.Copy(indices, startIndexPoints, pointIndices, pointIndicesOffset, noIndicesPoints);
                    pointIndicesOffset += noIndicesPoints;
                }
            }
            System.Diagnostics.Debug.Assert(triangleIndicesOffset == triangleCnt * 3 && lineIndicesOffset == lineCnt * 2 && pointIndicesOffset == pointCnt);

            //
            //  Now the index arrays for triagles, lines and points are ready
            //      triangleIndices
            //      lineIndices
            //      pointIndices
            //  all three are using the same vertex array
            //      vertices
            //

            //
            //  Based on the Collection we should find
            //      
            //
            System.Diagnostics.Debug.Assert(triangleCnt == 36 * 2 + 2 * (36 - 2));  //  The collection contained 1 cylinder (with segmentation parts 36)
            System.Diagnostics.Debug.Assert(lineCnt == 2);                          //  The collection contained 2 lines
            System.Diagnostics.Debug.Assert(pointCnt == 3);                         //  The collection contained 3 points

            ...
            ...     //  use the vertex and index array for visualization, QTO, conversion etc.
            ...
        }

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