virtucamera.VCServer - shycats/PyVirtuCamera GitHub Wiki

class virtucamera.VCServer

This class is the core of PyVirtuCamera.

It takes care of asyncronously calling your virtucamera.VCBase code when needed, it captures the viewport, encodes it, and handles network communication with the app.

Provides methods to start and stop the server, generate a QR Code for easy app connections, and to setup how the viewport is captured.

Creating virtucamera.VCServer object

virtucamera.VCServer( platform, plugin_version, vcbase, event_mode, main_thread_func=None, python_executable=None )
Returns
-------
    instance of virtucamera.VCServer
platform : str
    Name of the DCC software where this code is running (e.g. 'Blender')
plugin_version : tuple of 3 int
    Version of the plug-in making use of this API
    as (major, minor, patch).
vcbase : virtucamera.VCBase object
    Instance of a class overloading virtucamera.VCBase,
    this is the way to provide code which carries out especific
    tasks in your DCC software, like setting the camera transform
    or getting the current frame. Methods of this class will be
    called asyncronously when needed.

Related: virtucamera.VCBase

event_mode : int
    Two modes are provided for calling the methods of
    virtucamera.VCBase asyncronously:

    * VCServer.EVENTMODE_PUSH - It just calls virtucamera.VCBase
        methods from a separate thread. This can be a problem if
        the DCC API methods are not thread-safe, leading to crashes
        and hangs. Some DCCs like Maya provide a function to safely
        execute code from a separate thread in the main thread.
        see the 'main_thread_func' parameter.

    * VCServer.EVENTMODE_PULL - You will be responsible to call
        VCServer.execute_pending_events() regularly from
        the main thread. This is usefull when the DCC software
        provides a way to register a timer that will call a function
        at regular intervals. You have to set the interval really low,
        less than 0.016 seconds (60FPS) or even zero if it's allowed
        without blocking, as setting a value too high will lead to
        low framerates and high latency.

Related: virtucamera.VCBase ||| 'main_thread_func' parameter ||| VCServer.execute_pending_events()

main_thread_func : function, optional
    If you are using 'event_mode' VCServer.EVENTMODE_PUSH and the
    DCC API functions being used in your implementation of
    virtucamera.VCBase are not thread-safe, you can provide a function
    that safely executes code in the main thread when called from a
    separate thread. This function must take a Python callable object
    such as a function as the first argument, and extra arguments
    that are passed on to the callable object when it is run.
    An example of such a function would be Maya's
    maya.utils.executeInMainThreadWithResult()

Related: virtucamera.VCBase ||| 'event_mode' parameter ||| maya.utils.executeInMainThreadWithResult()

python_executable : str, optional
    Only on Windows. Absolute path to the Python executable file of
    the DCC software. This is needed to capture and encode the viewport
    image stream in a parallel process. It will try to guess the path if
    it's not provided, but this may not always work and it's better to
    provide it explicitly. This is usually a python.exe
    file in the /bin or /python/bin folder under the DCC software
    installation path, but there are other variants
    like mayapy.exe in the case of Maya. A system Python installation
    can also be used as far as it's the same major and minor Python 
    version as the one used in the DCC software.