.. role:: ts-api-decorator

###########
StreamModel
###########

.. js:module:: cee.vs
   :noindex:

.. container:: ts-api-section

   .. js:class:: StreamModel

      A remote Visualization Streamer (VizStreamer) model that can be displayed in the Viewer.

      The ``StreamModel`` class supports an efficient streaming and rendering of 3D data. The data to this model is sent from 
      the VizStreamer Service, to which data is sent using GRPC or a C++ interface.  

      To create a new instance of the ``StreamModel``, the ``ServerSession`` object needs to be created first. Afterwards, 
      use the ``ServerSession.createStreamModel`` method to create a model linked to the stream. By default, the model 
      starts streaming immediately. 

      The streaming to this model is controlled with the ``startStreaming`` and ``stopStreaming`` methods. 
      You can also check whether streaming is active with the ``isStreamingActive`` method. 

      The current frame of the StreamModel can be set with the ``currentFrameIndex`` property.

      **Example:** 

       Create a StreamModel and add it to the view.


      .. code-block:: typescript

         // create a cloud session first, viewer and a view
         const cloudSession = new cee.CloudSession();
         const viewer = cloudSession.addViewer(htmlCanvasElement, { useOperators: false });
         const view = viewer.addView()

         // Connect to the server session at the given url. 
         const serverSession = await cee.vs.ServerSession.createInstance_async("http://localhost:8080");
         // Get the available streams
         const streams = await serverSession.getAvailableStreams_async();

         // grab the first stream in the server
         if (streams[0]) {
             const streamName = streams[0].streamName;
             const streamModel = serverSession.createStreamModel(streamName);

             // Add the model to the cee.View
             view.addModel(streamModel);
             // Start the streaming if not already started.
             if (!streamModel.isStreamingActive()) {
                 streamModel.startStreaming();
             }            
         }




.. container:: api-index-section

   .. rubric:: Accessors

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

   * :js:attr:`~cee.vs.StreamModel.currentFrameIndex`
   * :js:attr:`~cee.vs.StreamModel.frameCount`
   * :js:attr:`~cee.vs.StreamModel.name`
   * :js:attr:`~cee.vs.StreamModel.streamName`



.. container:: api-index-section

   .. rubric:: Methods

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

   * :js:meth:`~cee.vs.StreamModel.getBoundingBox`
   * :js:meth:`~cee.vs.StreamModel.getDefaultCameraConfig`
   * :js:meth:`~cee.vs.StreamModel.isStreamingActive`
   * :js:meth:`~cee.vs.StreamModel.pollForStreamConfig_async`
   * :js:meth:`~cee.vs.StreamModel.rayIntersect`
   * :js:meth:`~cee.vs.StreamModel.setGuidingCamera`
   * :js:meth:`~cee.vs.StreamModel.startStreaming`
   * :js:meth:`~cee.vs.StreamModel.stopStreaming`





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

Accessors
=========

.. container:: ts-api-section

   .. js:function:: StreamModel.currentFrameIndex()



      Gets/sets the current frame index displayed in this model.


      :rtype: number

   .. js:function:: StreamModel.currentFrameIndex( frameIndex)

      :param frameIndex: None
      :type frameIndex: number


      :rtype: void



.. container:: ts-api-section

   .. js:function:: StreamModel.frameCount()



      Gets the number of frames in this model.


      :rtype: number



.. container:: ts-api-section

   .. js:function:: StreamModel.name()



      Name of the model, primarily used for debugging.


      :rtype: string

   .. js:function:: StreamModel.name( name)

      :param name: None
      :type name: string


      Name of the model. 

      Mainly used for debugging.


      :rtype: void



.. container:: ts-api-section

   .. js:function:: StreamModel.streamName()



      Name of the stream being consumed by this model


      :rtype: string



Methods
=======

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

getBoundingBox
--------------

.. js:method:: StreamModel.getBoundingBox([ _options])

   :param _options: :ts-api-decorator:`optional` None
   :type _options: ModelBoundingBoxOptions


   Returns the ``BoundingBox`` (in world coordinates) of the current contents of the model

   Note that this method does not support any ``ModelBoundingBoxOptions``


   :rtype: BoundingBox

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

getDefaultCameraConfig
----------------------

.. js:method:: StreamModel.getDefaultCameraConfig()



   Returns default camera configuration, which is always null for this model.


   :rtype: unknown

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

isStreamingActive
-----------------

.. js:method:: StreamModel.isStreamingActive()



   Checks whether the streaming to the model is enabled or not.


   :rtype: boolean

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

pollForStreamConfig_async
-------------------------

.. js:method:: StreamModel.pollForStreamConfig_async()



   Polls for new data for this model.


   :rtype: Promise <void>

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

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

.. js:method:: StreamModel.rayIntersect( ray)

   :param ray: None
   :type ray: Ray


   Performs picking on the model using the current frame. Returns null when nothing is hit.


   :rtype: HitItem

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

setGuidingCamera
----------------

.. js:method:: StreamModel.setGuidingCamera( camera)

   :param camera: None
   :type camera: Camera


   Sets the guiding camera by watching its changes and using it to guide the streaming.


   :rtype: void

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

startStreaming
--------------

.. js:method:: StreamModel.startStreaming()



   Starts the streaming from the VizStreamer Service.


   :rtype: void

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

stopStreaming
-------------

.. js:method:: StreamModel.stopStreaming()



   Stops the streaming from the VizStreamer Service.


   :rtype: void

