sgCObject*   sgFileManager::ObjectFromTriangles(const SG_POINT* vertexes, long vert_count,

                       const SG_INDEX_TRIANGLE* triangles, long tr_count,

                       float smooth_angle_in_radians=30.0*3.14159265/180.0,

                       bool  solids_checking=false)

 

Description:

Creating objects by an array of indexed triangles.

 

Arguments:

vertexes - the array of all vertices in triangles

triangles - the array of structures describing triangles - SG_INDEX_TRIANGLE (Definition in sg3D.h):

typedef struct

{

 long   ver_indexes[3];

} SG_INDEX_TRIANGLE;

this structure is a triple of indexes of vertices in a triangle from the array vertexes

tr_count - number of triangles

smooth_angle_in_radians - the maximal angle (in radians) between the faces of the object, less than which the normal lines of triangles will be automatically smoothed. If the angle between the faces is larger than smooth_angle_in_radians, normal lines will not be smoothed. By default, this argument equals 30 degrees

solids_checking - checking the array of triangles for a closure - that is, whether a solid can be created. If you are sure that the triangles form a solid or a surface, it is better to set this argument to false (the default value) because this check may considerably slow down the function. If triangles are positioned so that a vertex of one triangle belongs to an edge of another triangle and if this argument is set to true, the triangles will be automatically split in such a way that no vertex of one triangle will belong to an edge of another triangle

 

Returned value:

Returns the pointer to the created object. NULL is returned in case of a failure. If the triangles were connected, an object of the sgC3DObject type will be created. If the triangles were split into unconnected groups in space, an object of the sgCGroup type will be created

 

Example (a group out of a cube and a triangle):

 

const SG_POINT vert[] = {

 {0.00000, 0.00000, 0.000000},

 {0.00000, 1.50000, 1.500000},

 {0.00000, 0.00000, 2.000000},

 {0.00000, 2.00000, 0.000000},

 {0.00000, 0.50000, 0.500000},

 {0.00000, 2.00000, 2.000000},

 {2.00000, 0.00000, 0.000000},

 {2.00000, 0.00000, 2.000000},

 {2.00000, 2.00000, 0.000000},

 {2.00000, 2.00000, 2.000000},

 

 {10.0000, 10.0000, 0.0000},

 {10.0000, 11.0000, 0.0000},

 {11.0000, 11.0000, 0.0000},

 {11.0000, 10.0000, 0.0000}

};

 

const SG_INDEX_TRIANGLE  indexes[] = {

 {1, 0, 2},

 {3, 4, 5},

 {1, 2, 5},

 {0, 4, 3},

 {2, 0, 6},

 {2, 6, 7},

 {0, 3, 8},

 {0, 8, 6},

 {2, 7, 9},

 {2, 9, 5},

 {5, 9, 8},

 {5, 8, 3},

 {6, 8, 9},

 {6, 9, 7},

 

 {10, 11, 12},

 {10,12,13}

};

 

sgGetScene()->AttachObject(sgFileManager::ObjectFromTriangles(vert,14,indexes,15));