.. role:: ts-api-decorator

####################
MeshIndexedTriangles
####################

.. js:module:: cee.geo
   :noindex:

.. container:: ts-api-section

   .. js:class:: MeshIndexedTriangles

      This class implements a ``Mesh`` for indexed triangles.

      Rather than defining each triangle directly as an array of vertices, an array containing x, y and z values for each
      unique vertex in the part is defined. Then triangles are defined by arrays of indices that refer to
      elements of this vertex array. This allows triangles to share vertices, thus reducing the number of
      vertices, and enabling the computation of smooth shade normals.

      Note that while the vertices array contains 3 elements per point (x, y and z), the elements in the indices array are
      interpreted as vertex indices. For example, if vertices contains 3 vertices A, B and C:


      .. code-block::

         `
         vertices = [Ax, Ay, Az, Bx, By, Bz, Cx, Cy, Cz];
         `



      Then vertex A is at index 0, vertex B and 1 and vertex C at 2. So the triangle containing these vertices would be defined
      with


      .. code-block::

         `
         indices = [0, 1, 2];
         `




.. container:: api-index-section

   .. rubric:: Constructors

   .. rst-class:: api-index-list-item api-kind-constructor api-parent-kind-class

   * :js:meth:`~cee.geo.MeshIndexedTriangles.constructor`



.. container:: api-index-section

   .. rubric:: Accessors

   .. rst-class:: api-index-list-item api-kind-accessor api-parent-kind-class

   * :js:attr:`~cee.geo.MeshIndexedTriangles.boundingBox`
   * :js:attr:`~cee.geo.MeshIndexedTriangles.indexArray`
   * :js:attr:`~cee.geo.MeshIndexedTriangles.primitiveCount`
   * :js:attr:`~cee.geo.MeshIndexedTriangles.primitiveType`
   * :js:attr:`~cee.geo.MeshIndexedTriangles.textureCoordinates`
   * :js:attr:`~cee.geo.MeshIndexedTriangles.vertexArray`
   * :js:attr:`~cee.geo.MeshIndexedTriangles.vertexCount`



.. container:: api-index-section

   .. rubric:: Methods

   .. rst-class:: api-index-list-item api-kind-method api-parent-kind-class

   * :js:meth:`~cee.geo.MeshIndexedTriangles.getPrimitiveVertices`
   * :js:meth:`~cee.geo.MeshIndexedTriangles.rayIntersect`
   * :js:meth:`~cee.geo.MeshIndexedTriangles.constructPreserveSharpEdges`





------------

Constructors
============

.. container:: ts-api-section

   .. js:function:: MeshIndexedTriangles.constructor( vertices, indices[, optionalVertexData])

      :param vertices: None
      :type vertices: ArrayLike <number>
      :param indices: None
      :type indices: ArrayLike <number>
      :param optionalVertexData: :ts-api-decorator:`optional` None
      :type optionalVertexData: OptionalIndexedTriangleVertexData


      Creates an indexed triangle mesh with the given vertices and indices.


      :rtype: MeshIndexedTriangles



Accessors
=========

.. container:: ts-api-section

   .. js:function:: MeshIndexedTriangles.boundingBox()



      Returns a copy of the ``BoundingBox`` of the mesh


      :rtype: BoundingBox



.. container:: ts-api-section

   .. js:function:: MeshIndexedTriangles.indexArray()



      A readonly array containing the indices of the mesh


      :rtype: ArrayLike <number>



.. container:: ts-api-section

   .. js:function:: MeshIndexedTriangles.primitiveCount()



      The number of primitives in the mesh.


      :rtype: number



.. container:: ts-api-section

   .. js:function:: MeshIndexedTriangles.primitiveType()



      The type of primitives that are used in the mesh.


      :rtype: MeshPrimitiveType



.. container:: ts-api-section

   .. js:function:: MeshIndexedTriangles.textureCoordinates()



      A readonly array containing the 2d texture coordinates of the mesh


      :rtype: ArrayLike <number>



.. container:: ts-api-section

   .. js:function:: MeshIndexedTriangles.vertexArray()



      A readonly array containing the vertices of the mesh


      :rtype: ArrayLike <number>



.. container:: ts-api-section

   .. js:function:: MeshIndexedTriangles.vertexCount()



      The number of vertices in the mesh.


      :rtype: number



Methods
=======

.. rst-class:: ts-api-section

getPrimitiveVertices
--------------------

.. js:method:: MeshIndexedTriangles.getPrimitiveVertices( primitiveIndex)

   :param primitiveIndex: None
   :type primitiveIndex: number


   Returns a copy of the vertex indices of a given primitive.


   :rtype: [Vec3]

.. rst-class:: ts-api-section

rayIntersect
------------

.. js:method:: MeshIndexedTriangles.rayIntersect( ray[, hitItem])

   :param ray: None
   :type ray: Ray
   :param hitItem: :ts-api-decorator:`optional` None
   :type hitItem: MeshHitItem


   Performs picking on the mesh.

   If a primitive was hit, the function returns true and populates the passed hitItem object with
   information about this primitive. It nothing was hit, returns false.


   :rtype: boolean

.. rst-class:: ts-api-section

:ts-api-decorator:`static` constructPreserveSharpEdges
------------------------------------------------------

.. js:method:: MeshIndexedTriangles.constructPreserveSharpEdges( creaseAngleDegrees, vertices, indices[, optionalVertexData])

   :param creaseAngleDegrees: None
   :type creaseAngleDegrees: number
   :param vertices: None
   :type vertices: ArrayLike <number>
   :param indices: None
   :type indices: ArrayLike <number>
   :param optionalVertexData: :ts-api-decorator:`optional` None
   :type optionalVertexData: OptionalIndexedTriangleVertexData


   Creates an indexed triangle mesh with the given vertices and indices. 

   Preserve sharp edges by splitting vertices on edges where the surface normal of the two triangles
   sharing the edge is more than the given angle (in degrees).


   :rtype: MeshIndexedTriangles

