boinor.render.scene =================== .. py:module:: boinor.render.scene Classes ------- .. autoapisummary:: boinor.render.scene.MainWindow Module Contents --------------- .. py:class:: MainWindow(camera='turntable', fov=60, bgcolor='black', size=(800, 600)) Bases: :py:obj:`vispy.scene.SceneCanvas` Main window for rendering 3D models using Vispy. This class provides a graphical interface for rendering 3D models using the Vispy library. It sets up a scene canvas with interactive capabilities, allowing users to visualize and interact with 3D models. The canvas includes a grid layout and a view with a configurable camera for easy manipulation of the 3D scene. :param camera: Camera type for the view. Options are "turntable", "arcball", "fly", "panzoom". Default is "turntable". :type camera: str, optional :param fov: Field of view in degrees. Only applicable for 3D cameras. Default is 60. :type fov: float, optional :param bgcolor: Background color of the view. Can be a color name (e.g., "black", "white") or an RGBA tuple. Default is "black". :type bgcolor: str or tuple, optional :param size: Window size as (width, height). Default is (800, 600). :type size: tuple of int, optional .. py:attribute:: grid .. py:attribute:: view .. py:method:: set_model(vertices, faces, shading='smooth', color='grey') Set the 3D model to be rendered. This method takes arrays of vertices and faces, creates a mesh from them, and adds the mesh to the view for rendering. :param vertices: Array of vertex coordinates. :type vertices: numpy.ndarray :param faces: Array of face indices. :type faces: numpy.ndarray :param shading: Shading mode for the mesh. Options are "smooth", "flat", or None. Default is "smooth". :type shading: str, optional :param color: Color of the mesh. Can be a color name (e.g., "grey", "red") or an RGBA tuple (e.g., (1.0, 0.5, 0.5, 1.0)). Default is "grey". :type color: str or tuple, optional .. py:attribute:: transforms .. py:property:: scene The SubScene object that represents the root node of the scene graph to be displayed. .. py:property:: central_widget Returns the default widget that occupies the entire area of the canvas. .. py:property:: bgcolor .. py:method:: update(node=None) Update the scene :param node: Not used. :type node: instance of Node .. py:method:: on_draw(event) Draw handler :param event: The draw event. :type event: instance of Event .. py:method:: render(region=None, size=None, bgcolor=None, crop=None, alpha=True) Render the scene to an offscreen buffer and return the image array. :param region: Specifies the region of the canvas to render. Format is (x, y, w, h). By default, the entire canvas is rendered. :type region: tuple | None :param size: Specifies the size of the image array to return. If no size is given, then the size of the *region* is used, multiplied by the pixel scaling factor of the canvas (see `pixel_scale`). This argument allows the scene to be rendered at resolutions different from the native canvas resolution. :type size: tuple | None :param bgcolor: The background color to use. :type bgcolor: instance of Color | None :param crop: If specified it determines the pixels read from the framebuffer. In the format (x, y, w, h), relative to the region being rendered. :type crop: array-like | None :param alpha: If True (default) produce an RGBA array (h, w, 4). If False, remove the Alpha channel and return the RGB array (h, w, 3). This may be useful if blending of various elements requires a solid background to produce the expected visualization. :type alpha: bool :returns: **image** -- Numpy array of type ubyte and shape (h, w, 4). Index [0, 0] is the upper-left corner of the rendered region. If ``alpha`` is ``False``, then only 3 channels will be returned (RGB). :rtype: array .. py:method:: draw_visual(visual, event=None) Draw a visual and its children to the canvas or currently active framebuffer. :param visual: The visual to draw :type visual: Visual :param event: Optionally specifies the original canvas draw event that initiated this draw. :type event: None or DrawEvent .. py:method:: visual_at(pos) Return the visual at a given position :param pos: The position in logical coordinates to query. :type pos: tuple :returns: **visual** -- The visual at the position, if it exists. :rtype: instance of Visual | None .. py:method:: visuals_at(pos, radius=10) Return a list of visuals within *radius* pixels of *pos*. Visuals are sorted by their proximity to *pos*. :param pos: (x, y) position at which to find visuals. :type pos: tuple :param radius: Distance away from *pos* to search for visuals. :type radius: int .. py:method:: on_resize(event) Resize handler :param event: The resize event. :type event: instance of Event .. py:method:: on_close(event) Close event handler :param event: The event. :type event: instance of Event .. py:method:: push_viewport(viewport) Push a viewport (x, y, w, h) on the stack. Values must be integers relative to the active framebuffer. :param viewport: The viewport as (x, y, w, h). :type viewport: tuple .. py:method:: pop_viewport() Pop a viewport from the stack. .. py:method:: push_fbo(fbo, offset, csize) Push an FBO on the stack. This activates the framebuffer and causes subsequent rendering to be written to the framebuffer rather than the canvas's back buffer. This will also set the canvas viewport to cover the boundaries of the framebuffer. :param fbo: The framebuffer object . :type fbo: instance of FrameBuffer :param offset: The location of the fbo origin relative to the canvas's framebuffer origin. :type offset: tuple :param csize: The size of the region in the canvas's framebuffer that should be covered by this framebuffer object. :type csize: tuple .. py:method:: pop_fbo() Pop an FBO from the stack. .. py:property:: dpi The physical resolution of the canvas in dots per inch. .. py:attribute:: events .. py:method:: create_native() Create the native widget if not already done so. If the widget is already created, this function does nothing. .. py:property:: context The OpenGL context of the native widget It gives access to OpenGL functions to call on this canvas object, and to the shared context namespace. .. py:property:: app The vispy Application instance on which this Canvas is based. .. py:property:: native The native widget object on which this Canvas is based. .. py:method:: connect(fun) Connect a function to an event The name of the function should be on_X, with X the name of the event (e.g. 'on_draw'). This method is typically used as a decorator on a function definition for an event handler. :param fun: The function. :type fun: callable .. py:property:: size The size of canvas/window. .. py:property:: physical_size The physical size of the canvas/window, which may differ from the size property on backends that expose HiDPI. .. py:property:: pixel_scale The ratio between the number of logical pixels, or 'points', and the physical pixels on the device. In most cases this will be 1.0, but on certain backends this will be greater than 1. This should be used as a scaling factor when writing your own visualisations with gloo (make a copy and multiply all your logical pixel values by it). When writing Visuals or SceneGraph visualisations, this value is exposed as `TransformSystem.px_scale`. .. py:property:: fullscreen .. py:property:: position The position of canvas/window relative to screen. .. py:property:: title The title of canvas/window. .. py:property:: fps The fps of canvas/window, as the rate that events.draw is emitted. .. py:method:: set_current(event=None) Make this the active GL canvas :param event: Not used. :type event: None .. py:method:: swap_buffers(event=None) Swap GL buffers such that the offscreen buffer becomes visible :param event: Not used. :type event: None .. py:method:: show(visible=True, run=False) Show or hide the canvas :param visible: Make the canvas visible. :type visible: bool :param run: Run the backend event loop. :type run: bool .. py:method:: close() Close the canvas .. rubric:: Notes This will usually destroy the GL context. For Qt, the context (and widget) will be destroyed only if the widget is top-level. To avoid having the widget destroyed (more like standard Qt behavior), consider making the widget a sub-widget. .. py:method:: measure_fps(window=1, callback='%1.1f FPS') Measure the current FPS Sets the update window, connects the draw event to update_fps and sets the callback function. :param window: The time-window (in seconds) to calculate FPS. Default 1.0. :type window: float :param callback: The function to call with the float FPS value, or the string to be formatted with the fps value and then printed. The default is ``'%1.1f FPS'``. If callback evaluates to False, the FPS measurement is stopped. :type callback: function | str .. py:method:: __repr__() .. py:method:: __enter__() .. py:method:: __exit__(type, value, traceback) .. py:method:: __setattr__(key, value) .. py:method:: freeze() Freeze the object so that only existing properties can be set .. py:method:: unfreeze() Unfreeze the object so that additional properties can be added