### Create Window with Setup (Rust) Source: https://docs.rs/kiss3d/latest/kiss3d/window/struct.Window_search= Creates a new window with custom setup options, including VSync and anti-aliasing. This provides fine-grained control over window creation. ```rust use kiss3d::canvas::CanvasSetup; let setup = CanvasSetup { vsync: true, samples: Some(4), // Anti-aliasing samples ..Default::default() }; let mut window = Window::new_with_setup("Custom Setup Window", 800, 600, setup).await; ``` -------------------------------- ### Handle Start of a Rendering Pass (wgpu) Source: https://docs.rs/kiss3d/latest/src/kiss3d/camera/first_person_stereo3d.rs This function is intended to handle the setup for each rendering pass. However, it's noted that in wgpu, viewport and scissor configurations are handled per render pass, so this function's implementation would need to be adapted, possibly by managing viewport information for materials. ```rust // Note: In wgpu, viewport/scissor are set per render pass, not globally. // The stereo camera's start_pass and render_complete functionality would need // to be handled differently in wgpu (e.g., through separate render passes // or by storing viewport info for materials to use). fn start_pass(&self, _pass: usize, _canvas: &Canvas) { // TODO: Viewport handling needs to be done at render pass creation in wgpu } ``` -------------------------------- ### Start Rendering Pass (Rust) Source: https://docs.rs/kiss3d/latest/kiss3d/camera/struct.FirstPersonCamera3d_search= Called at the start of each rendering pass. This function can be used for any setup required before a rendering pass begins. ```rust fn start_pass(&self, _pass: usize, _canvas: &Canvas) Called at the start of each rendering pass. Read more ``` -------------------------------- ### Create Window with Custom Setup (Rust) Source: https://docs.rs/kiss3d/latest/kiss3d/window/struct.Window_search=u32+-%3E+bool Creates a new Kiss3D window with custom setup options, including dimensions and `CanvasSetup` for VSync and anti-aliasing. This provides fine-grained control over window creation. Returns a new `Window` instance. ```rust use kiss3d::canvas::CanvasSetup; let setup = CanvasSetup { vsync: true, samples: 4, ..Default::default() }; let mut window = kiss3d::window::Window::new_with_setup("Custom Setup Window", 800, 600, setup).await; ``` -------------------------------- ### Rust Search Query Examples Source: https://docs.rs/kiss3d/latest/src/kiss3d/post_processing/oculus_stereo.rs_search= These are example search queries for a Rust documentation or code search tool. They illustrate how to search for specific types, type conversions, and generic function signatures. These examples help users understand the search syntax for finding relevant Rust code or documentation. ```text std::vec ``` ```text u32 -> bool ``` ```text Option, (T -> U) -> Option ``` -------------------------------- ### Unproject Example Source: https://docs.rs/kiss3d/latest/kiss3d/camera/trait.Camera3d_search= An example demonstrating how to use the `unproject` method to obtain a 3D ray from a mouse position on the screen. This ray can then be used for interacting with objects in the 3D scene. ```Rust let mouse_pos = Vec2::new(400.0, 300.0); let screen_size = Vec2::new(800.0, 600.0); let (ray_origin, ray_dir) = camera.unproject(mouse_pos, screen_size); // Now you can use the ray for picking objects in the scene ``` -------------------------------- ### Start Rendering Pass in Rust Source: https://docs.rs/kiss3d/latest/kiss3d/camera/trait.Camera3d_search= The `start_pass` method is called at the beginning of each rendering pass. It can be overridden to perform setup tasks specific to each pass, such as setting the viewport for stereo rendering. ```rust fn start_pass(&self, _pass: usize, _canvas: &Canvas) { ... } ``` -------------------------------- ### Handle wgpu Start Pass in Rust Source: https://docs.rs/kiss3d/latest/src/kiss3d/camera/first_person_stereo3d.rs_search=std%3A%3Avec This function is a placeholder for handling the start of a rendering pass in wgpu. The comment indicates that viewport handling in wgpu is managed differently, typically at render pass creation, and requires specific implementation. ```rust fn start_pass(&self, _pass: usize, _canvas: &Canvas) { // TODO: Viewport handling needs to be done at render pass creation in wgpu } ``` -------------------------------- ### Create a new window with custom setup options (Rust) Source: https://docs.rs/kiss3d/latest/src/kiss3d/window/window.rs Creates a new window with custom dimensions and advanced setup options defined by a `CanvasSetup` struct. This provides fine-grained control over VSync, anti-aliasing, and other window properties. ```Rust pub async fn new_with_setup( title: &str, width: u32, height: u32, setup: CanvasSetup, ) -> Window { Window::do_new(title, false, width, height, Some(setup)).await } ``` -------------------------------- ### Rust Search Example: Option and Function Mapping Source: https://docs.rs/kiss3d/latest/kiss3d/prelude/struct.RefCell_search=std%3A%3Avec An example search query for common Rust patterns involving `Option` and function mapping. It shows how to find operations that transform an `Option` using a function `T -> U` into an `Option`, often using methods like `map`. ```text Option, (T -> U) -> Option ``` -------------------------------- ### Initialize and Get wgpu Context (Rust) Source: https://docs.rs/kiss3d/latest/src/kiss3d/context/context.rs_search=u32+-%3E+bool Initializes or reinitializes the global wgpu context with provided instance, device, queue, adapter, and surface format. The `get` function retrieves a clone of the initialized context, panicking if it hasn't been set up yet. This is crucial for managing GPU resources across window creations. ```rust pub fn init( instance: wgpu::Instance, device: wgpu::Device, queue: wgpu::Queue, adapter: wgpu::Adapter, surface_format: wgpu::TextureFormat, ) { CONTEXT_SINGLETON.with(|cell| { *cell.borrow_mut() = Some(Context { instance: Arc::new(instance), device: Arc::new(device), queue: Arc::new(queue), adapter: Arc::new(adapter), surface_format, }); }); } pub fn get() -> Context { CONTEXT_SINGLETON.with(|cell| { cell.borrow() .as_ref() .expect("wgpu context not initialized. Call Context::init() first.") .clone() }) } ``` -------------------------------- ### Get X11 Server Setup Information Source: https://docs.rs/kiss3d/latest/kiss3d/prelude/struct.Rc_search= Retrieves the setup information provided by the X11 server upon connection. This data typically includes details about the server's capabilities and configuration. The function returns a reference to the `Setup` object. ```rust fn setup(&self) -> &Setup ``` -------------------------------- ### Get Raw Pointer to Rc Data Source: https://docs.rs/kiss3d/latest/kiss3d/prelude/struct.Rc_search= Illustrates how to get a raw pointer to the data contained within an Rc without consuming the Rc itself, using `Rc::as_ptr`. This pointer is valid as long as there are strong references. The example shows that pointers from cloned Rcs are identical. ```rust use std::rc::Rc; let x = Rc::new(0); let y = Rc::clone(&x); let x_ptr = Rc::as_ptr(&x); assert_eq!(x_ptr, Rc::as_ptr(&y)); assert_eq!(unsafe { *x_ptr }, 0); ``` -------------------------------- ### Example Usage of kiss3d Lights in Rust Source: https://docs.rs/kiss3d/latest/src/kiss3d/light.rs_search= Demonstrates how to create and configure different types of lights (point, directional, spot) in kiss3d using Rust. It shows how to set their colors and intensities using chained method calls. ```Rust # use kiss3d::prelude::* # use glamx::Vec3; # use kiss3d::color::Color; # use kiss3d::light::Light; // Create a white point light let point_light = Light::point(100.0) .with_color(WHITE) .with_intensity(5.0); // Create a directional "sun" light let sun = Light::directional(Vec3::new(-1.0, -1.0, 0.0)) .with_color(Color::new(1.0, 0.95, 0.8, 1.0)) .with_intensity(2.0); // Create a spot light (flashlight) let spot = Light::spot(0.3, 0.5, 50.0) .with_color(WHITE) .with_intensity(10.0); ``` -------------------------------- ### Create and Configure kiss3d Lights in Rust Source: https://docs.rs/kiss3d/latest/kiss3d/light/struct.Light_search= Provides examples of creating different types of light sources (point, directional, spot) using the kiss3d library. It demonstrates how to initialize lights and customize their properties such as color and intensity. ```Rust // Create a white point light let point_light = Light::point(100.0) .with_color(WHITE) .with_intensity(5.0); // Create a directional "sun" light let sun = Light::directional(Vec3::new(-1.0, -1.0, 0.0)) .with_color(Color::new(1.0, 0.95, 0.8, 1.0)) .with_intensity(2.0); // Create a spot light (flashlight) let spot = Light::spot(0.3, 0.5, 50.0) .with_color(WHITE) .with_intensity(10.0); ``` -------------------------------- ### Get Allocator from Rc (Nightly) Source: https://docs.rs/kiss3d/latest/kiss3d/prelude/struct.Rc_search= Shows how to retrieve a reference to the allocator used by an Rc instance. This is an experimental, nightly-only API. The example calls the associated function `Rc::allocator`. ```rust #![feature(allocator_api)] use std::rc::Rc; use std::alloc::System; let x = Rc::new_in("hello".to_owned(), System); let alloc_ref = Rc::allocator(&x); // Use alloc_ref... ``` -------------------------------- ### Example Usage of kiss3d Lights in Rust Source: https://docs.rs/kiss3d/latest/src/kiss3d/light.rs_search=u32+-%3E+bool Demonstrates how to create and configure different types of lights (point, directional, spot) in kiss3d using Rust. It shows setting colors and intensities for various lighting scenarios. ```Rust # use kiss3d::prelude::*; # use glamx::Vec3; // Create a white point light let point_light = Light::point(100.0) .with_color(WHITE) .with_intensity(5.0); // Create a directional "sun" light let sun = Light::directional(Vec3::new(-1.0, -1.0, 0.0)) .with_color(Color::new(1.0, 0.95, 0.8, 1.0)) .with_intensity(2.0); // Create a spot light (flashlight) let spot = Light::spot(0.3, 0.5, 50.0) .with_color(WHITE) .with_intensity(10.0); ``` -------------------------------- ### XInput Get Device Key Mapping Source: https://docs.rs/kiss3d/latest/kiss3d/prelude/struct.Rc_search=u32+-%3E+bool Retrieves the key mapping for a device, starting from a specific keycode and count. It requires device_id, first_keycode, and count. Returns a Cookie containing GetDeviceKeyMappingReply or a ConnectionError. ```rust fn xinput_get_device_key_mapping( &self, device_id: u8, first_keycode: u8, count: u8, ) -> Result, ConnectionError> ``` -------------------------------- ### Rendering and Scene Setup Source: https://docs.rs/kiss3d/latest/kiss3d/window/struct.Window_search=std%3A%3Avec APIs for setting the background color, managing textures, and controlling scene lighting. ```APIDOC ## Rendering and Scene Setup API ### `set_background_color(&mut self, color: Color)` Sets the background color for the window. #### Parameters * `r` (f32) - Red component (0.0 to 1.0) * `g` (f32) - Green component (0.0 to 1.0) * `b` (f32) - Blue component (0.0 to 1.0) #### Example ```rust use kiss3d::color::DARK_BLUE; let mut window = Window::new("Example").await; window.set_background_color(DARK_BLUE); ``` ### `add_texture(&mut self, path: &Path, name: &str) -> Arc` Loads a texture from a file and returns a reference to it. The texture is managed by the global texture manager and will be reused if loaded again with the same name. #### Parameters * `path` (&Path) - Path to the texture file * `name` (&str) - A unique name to identify this texture #### Returns * A reference-counted texture that can be applied to scene objects ### `set_ambient(&mut self, ambient: f32)` Sets the ambient light intensity for the scene. #### Parameters * `ambient` (f32) - The ambient light intensity #### Example ```rust // Set global ambient lighting intensity window.set_ambient(0.3); ``` *Note: Individual lights should be added to the scene tree using `SceneNode3d::add_point_light()`, `add_directional_light()`, or `add_spot_light()`.* ### `ambient(&self) -> f32` Returns the current ambient lighting intensity. ``` -------------------------------- ### Get Number of Rendering Passes Source: https://docs.rs/kiss3d/latest/src/kiss3d/camera/first_person_stereo3d.rs_search= Returns the total number of rendering passes required for the current camera setup. This is typically used to control iteration over rendering stages. ```rust fn num_passes(&self) -> usize { 2usize } ``` -------------------------------- ### WGPU Context Initialization (First Window) Source: https://docs.rs/kiss3d/latest/src/kiss3d/window/wgpu_canvas.rs_search=std%3A%3Avec This snippet demonstrates the initialization of the WGPU graphics context for the first window being created. It sets up the WGPU instance, creates a surface for rendering, and requests an adapter from the instance. This is typically executed when no context has been previously initialized. ```rust // First window - create the full wgpu context let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor { backends: wgpu::Backends::all(), ..Default::default() }); // Create surface let surface = instance .create_surface(window.clone()) .expect("Failed to create surface"); // Request adapter (async on all platforms) let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { power_preference: wgpu::PowerPreference::default(), ``` -------------------------------- ### Canvas Setup and Creation Source: https://docs.rs/kiss3d/latest/src/kiss3d/window/canvas.rs_search=u32+-%3E+bool This section details the `CanvasSetup` enum for configuring multisample anti-aliasing and the `Canvas::open` function for initializing a new window or canvas. ```APIDOC ## Enum: NumSamples ### Description Represents the possible number of samples for multisample anti-aliasing (MSAA). ### Variants - **Zero**: Multisampling disabled. - **One**: One sample. - **Two**: Two samples. - **Four**: Four samples. - **Eight**: Eight samples. - **Sixteen**: Sixteen samples. ### Methods - **from_u32(i: u32) -> Option** Creates a `NumSamples` enum variant from a `u32` value. Returns `None` if the input `i` is invalid. ## Struct: CanvasSetup ### Description Configuration options for the canvas. ### Fields - **vsync** (bool) - Indicates whether VSync is enabled. - **samples** (NumSamples) - The number of samples to use for anti-aliasing. ## Method: Canvas::open ### Description Opens a new window and initializes the WGPU context. This function is asynchronous. ### Method `async fn open( title: &str, hide: bool, width: u32, height: u32, canvas_setup: Option, out_events: Sender, ) -> Self` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust // Example usage (requires async context) // let event_sender = std::sync::mpsc::channel::().0; // let canvas = Canvas::open("My Window", false, 800, 600, None, event_sender).await; ``` ### Response #### Success Response (Self) - **Self** (Canvas) - An initialized `Canvas` instance. #### Response Example ```rust // let canvas: Canvas = ...; ``` ``` -------------------------------- ### Pose2 Default Implementation in Rust Source: https://docs.rs/kiss3d/latest/kiss3d/prelude/struct.Pose2_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the `Default` trait implementation for Pose2, allowing for the creation of a default Pose2 instance. This typically corresponds to the identity pose, offering a convenient way to get a standard starting pose. ```rust fn default() -> Pose2 ``` -------------------------------- ### WgpuCanvas Initialization and Management Source: https://docs.rs/kiss3d/latest/kiss3d/window/struct.WgpuCanvas This section details the methods for opening, closing, and managing the WgpuCanvas window, including event polling and basic window properties. ```APIDOC ## WgpuCanvas ### Description A unified canvas based on wgpu that works on both native and web platforms. ### Methods #### `open` * **Description**: Opens a new window and initializes the wgpu context. * **Method**: `pub async fn open(&str title, bool hide, u32 width, u32 height, Option canvas_setup, Sender out_events) -> Self` #### `poll_events` * **Description**: Polls events from the window system. * **Method**: `pub fn poll_events(&mut self)` #### `set_title` * **Description**: Set the window title. * **Method**: `pub fn set_title(&mut self, title: &str)` #### `set_icon` * **Description**: Set the window icon. * **Method**: `pub fn set_icon(&mut self, icon: impl GenericImage>)` #### `hide` * **Description**: Hide the window. * **Method**: `pub fn hide(&mut self)` #### `show` * **Description**: Show the window. * **Method**: `pub fn show(&mut self)` #### `size` * **Description**: The size of the render surface. This returns the configured surface size, which matches the depth texture and is guaranteed to be consistent with the render targets. * **Method**: `pub fn size(&self) -> (u32, u32)` #### `scale_factor` * **Description**: The scale factor. * **Method**: `pub fn scale_factor(&self) -> f64 ``` -------------------------------- ### XInput: Get Device Motion Events Source: https://docs.rs/kiss3d/latest/kiss3d/prelude/struct.Rc_search= Retrieves motion events for a device within a specified time range. This function requires start and stop times, and the device ID. It returns a Cookie containing GetDeviceMotionEventsReply on success or a ConnectionError. ```rust fn xinput_get_device_motion_events( &self, start: u32, stop: A, device_id: u8, ) -> Result, ConnectionError> where A: Into ``` -------------------------------- ### Get Raw Pointer from Rc (String) Source: https://docs.rs/kiss3d/latest/kiss3d/prelude/struct.Rc_search= Shows how to obtain a raw pointer to the data inside an Rc using Rc::into_raw. The example demonstrates that the pointer is valid as long as the Rc exists and can be dereferenced to access the string data. ```rust use std::rc::Rc; let x = Rc::new("hello".to_owned()); let x_ptr = Rc::into_raw(x); assert_eq!(unsafe { &*x_ptr }, "hello"); ``` -------------------------------- ### Initialize wgpu Context and Surface - Rust Source: https://docs.rs/kiss3d/latest/src/kiss3d/window/wgpu_canvas.rs_search=u32+-%3E+bool This snippet demonstrates the initialization of the wgpu graphics context and surface. It checks if a context is already initialized (for multi-window scenarios) and reuses it, or creates a new instance, requests an adapter, and creates a surface. It also configures the surface format based on capabilities. ```rust // Check if we already have a context initialized (multi-window case) let (surface, surface_format) = if Context::is_initialized() { // Reuse the existing context - create a new surface using the shared instance let ctxt = Context::get(); let surface = ctxt .instance .create_surface(window.clone()) .expect("Failed to create surface"); // Configure surface with existing device let surface_caps = surface.get_capabilities(&ctxt.adapter); let surface_format = surface_caps .formats .iter() .find(|f| !f.is_srgb()) .copied() .unwrap_or(surface_caps.formats[0]); (surface, surface_format) } else { // First window - create the full wgpu context let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor { backends: wgpu::Backends::all(), ..Default::default() }); // Create surface let surface = instance .create_surface(window.clone()) .expect("Failed to create surface"); // Request adapter (async on all platforms) let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { power_preference: wgpu::PowerPreference::default(), ``` -------------------------------- ### Create Visible Window in Kiss3D Source: https://docs.rs/kiss3d/latest/src/kiss3d/window/window.rs Creates a new, visible Kiss3D window with default settings (800x600 pixels). This function is intended for use with the `#[kiss3d::main]` macro for cross-platform compatibility. The example shows basic setup with a camera and scene node. ```rust /// Creates a new visible window with default settings. /// /// The window is created and immediately visible with a default size of 800x600 pixels. /// Use this in combination with the `#[kiss3d::main]` macro for cross-platform rendering. /// /// # Arguments /// * `title` - The window title /// /// # Returns /// A new `Window` instance /// /// # Example /// ```no_run /// use kiss3d::prelude::*; /// /// #[kiss3d::main] /// async fn main() { /// let mut window = Window::new("My Application").await; /// let mut camera = OrbitCamera3d::default(); /// let mut scene = SceneNode3d::empty(); /// /// } ``` ``` -------------------------------- ### XInput: Get Device Motion Events Source: https://docs.rs/kiss3d/latest/kiss3d/prelude/struct.Rc_search=u32+-%3E+bool Retrieves motion events for a device within a specified time range. This function requires a start time, stop time (which can be converted to u32), and the device ID, returning a Cookie containing the GetDeviceMotionEventsReply on success or a ConnectionError. ```rust fn xinput_get_device_motion_events( &self, start: u32, stop: A, device_id: u8, ) -> Result, ConnectionError> where A: Into, ``` -------------------------------- ### TryFrom and TryInto Implementations Source: https://docs.rs/kiss3d/latest/kiss3d/scene/struct.SceneNode2d_search=std%3A%3Avec Details the implementations for attempting conversions between types. ```APIDOC ### impl TryFrom for T #### type Error = Infallible ### Description The type returned in the event of a conversion error. #### fn try_from(value: U) -> Result>::Error> ### Description Performs the conversion. ### Method fn ### Endpoint N/A ### Parameters #### Path Parameters - **value** (U) - Required - The value to convert. ### Response #### Success Response (200) - **Result** - The converted value or an error. ### impl TryInto for T #### type Error = >::Error ### Description The type returned in the event of a conversion error. #### fn try_into(self) -> Result>::Error> ### Description Performs the conversion. ### Method fn ### Endpoint N/A ### Parameters None ### Response #### Success Response (200) - **Result** - The converted value or an error. ``` -------------------------------- ### Window Initialization and Basic Properties (Rust) Source: https://docs.rs/kiss3d/latest/src/kiss3d/window/window.rs Demonstrates how to create a new window and access its basic properties like dimensions and the underlying canvas. The `Window::new` function is typically used for initialization. ```rust impl Window { /// Indicates whether this window should be closed. #[inline] pub fn should_close(&self) -> bool { self.should_close } /// The window width. #[inline] pub fn width(&self) -> u32 { self.canvas.size().0 } /// The window height. #[inline] pub fn height(&self) -> u32 { self.canvas.size().1 } /// The size of the window. #[inline] pub fn size(&self) -> UVec2 { let (w, h) = self.canvas.size(); UVec2::new(w, h) } /// Gets a reference to the underlying canvas. /// /// This provides access to low-level rendering features like: /// - Getting the current surface texture for custom rendering /// - Getting the depth texture view /// - Presenting frames manually #[inline] pub fn canvas(&self) -> &Canvas { &self.canvas } /// Gets a mutable reference to the underlying canvas. #[inline] pub fn canvas_mut(&mut self) -> &mut Canvas { &mut self.canvas } } ``` -------------------------------- ### Install Colormap using install_colormap Source: https://docs.rs/kiss3d/latest/kiss3d/prelude/struct.Rc_search= Installs a colormap for a window. Requires the colormap ID. ```rust fn install_colormap( &self, cmap: u32, ) -> Result, ConnectionError> ``` -------------------------------- ### XInput XI Focus and Get Focus Source: https://docs.rs/kiss3d/latest/kiss3d/prelude/struct.Rc_search= Functions for setting and getting the input focus for XInput devices. ```APIDOC ## POST /xinput/xi_set_focus ### Description Sets the input focus for a window and device. ### Method POST ### Endpoint /xinput/xi_set_focus ### Parameters #### Path Parameters None #### Query Parameters - **window** (u32) - Required - The ID of the window. - **time** (A: Into) - Required - The time at which to set the focus. - **deviceid** (B: Into) - Required - The ID of the input device. ### Request Body None ### Response #### Success Response (200) - **cookie** (VoidCookie<'_, Self>) - A cookie representing the asynchronous operation. #### Response Example ```json { "cookie": "" } ``` ## GET /xinput/xi_get_focus ### Description Retrieves the input focus for a specified XInput device. ### Method GET ### Endpoint /xinput/xi_get_focus ### Parameters #### Path Parameters None #### Query Parameters - **deviceid** (A: Into) - Required - The ID of the input device. ### Request Body None ### Response #### Success Response (200) - **cookie** (Cookie<'_, Self, XIGetFocusReply>) - A cookie containing the focus information. #### Response Example ```json { "cookie ``` -------------------------------- ### Implement kiss3d Light Constructors (Rust) Source: https://docs.rs/kiss3d/latest/kiss3d/light/struct.Light Shows the implementation of constructor functions for creating point, directional, and spot lights. These functions initialize the `Light` struct with specific parameters. ```rust /// Creates a point light with the given attenuation radius. /// /// # Arguments /// * `attenuation_radius` - Maximum distance the light affects pub fn point(attenuation_radius: f32) -> Self { // ... implementation details ... } /// Creates a directional light (like the sun). /// The direction is determined by the scene node’s rotation. pub fn directional(dir: Vec3) -> Self { // ... implementation details ... } /// Creates a spot light with the given cone angles and attenuation radius. /// /// # Arguments /// * `inner_cone_angle` - Inner cone angle in radians (full intensity) /// * `outer_cone_angle` - Outer cone angle in radians (fades to zero) /// * `attenuation_radius` - Maximum distance the light affects pub fn spot( inner_cone_angle: f32, outer_cone_angle: f32, attenuation_radius: f32, ) -> Self { // ... implementation details ... } ``` -------------------------------- ### ulps_eq Method Examples Source: https://docs.rs/kiss3d/latest/kiss3d/procedural/enum.IndexBuffer_search=u32+-%3E+bool Examples of the `ulps_eq` method used for approximate equality checks with a given tolerance. ```APIDOC ## ulps_eq ### Description Checks for approximate equality between two values using Units in the Last Place (ULPs). ### Method Signatures: - `kiss3d::prelude::Rot2::ulps_eq(&Rot2, &Rot2, u32) -> bool` - `kiss3d::prelude::Mat3::ulps_eq(&Mat3, &Mat3, u32) -> bool` - `kiss3d::prelude::Vec2::ulps_eq(&Vec2, &Vec2, u32) -> bool` - `kiss3d::prelude::Vec3::ulps_eq(&Vec3, &Vec3, u32) -> bool` - `kiss3d::prelude::Mat2::ulps_eq(&Mat2, &Mat2, u32) -> bool` - `kiss3d::prelude::Quat::ulps_eq(&Quat, &Quat, u32) -> bool` - `kiss3d::prelude::RefCell::ulps_eq(&RefCell, &RefCell, u32) -> bool` ``` -------------------------------- ### Light Configuration Methods Source: https://docs.rs/kiss3d/latest/kiss3d/light/struct.Light_search=u32+-%3E+bool Methods for configuring the properties of a Light instance. ```APIDOC ## Light Configuration Methods ### `with_color(self, color: Color) -> Self` Sets the light color. ##### Arguments - **color** (Color) - RGBA color (each component 0.0-1.0) ### `with_intensity(self, intensity: f32) -> Self` Sets the light intensity. ##### Arguments - **intensity** (f32) - Intensity multiplier (default: 3.0) ### `with_enabled(self, enabled: bool) -> Self` Sets whether the light is enabled. ##### Arguments - **enabled** (bool) - Whether the light is enabled. ``` -------------------------------- ### TryFrom and TryInto Interfaces Source: https://docs.rs/kiss3d/latest/kiss3d/scene/struct.SceneNode2d_search=u32+-%3E+bool Documentation for fallible type conversions. ```APIDOC ### impl TryFrom for T #### type Error = Infallible ### Description The type returned in the event of a conversion error. ### Method `type` ### Endpoint N/A (Type alias) #### fn try_from(value: U) -> Result>::Error> ### Description Performs the conversion from `U` to `T`. ### Method `fn` ### Endpoint N/A (Internal function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) `Result` #### Response Example None ### impl TryInto for T #### type Error = >::Error ### Description The type returned in the event of a conversion error. ### Method `type` ### Endpoint N/A (Type alias) #### fn try_into(self) -> Result>::Error> ### Description Performs the conversion from `T` to `U`. ### Method `fn` ### Endpoint N/A (Internal function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) `Result` #### Response Example None ``` -------------------------------- ### List Installed Colormaps using list_installed_colormaps Source: https://docs.rs/kiss3d/latest/kiss3d/prelude/struct.Rc_search= Lists all colormaps currently installed for a given window. Requires the window ID. ```rust fn list_installed_colormaps( &self, window: u32, ) -> Result, ConnectionError> ``` -------------------------------- ### Context Initialization and Management Source: https://docs.rs/kiss3d/latest/kiss3d/context/struct.Context_search=std%3A%3Avec Functions for initializing, getting, checking status, and resetting the global wgpu context. ```APIDOC ## Context Initialization and Management ### `init` #### Description Initializes or reinitializes the global wgpu context. This function is called when creating a window. For multi-window support, this will replace the existing context with a new one. #### Method `pub fn init(instance: Instance, device: Device, queue: Queue, adapter: Adapter, surface_format: TextureFormat)` #### Arguments - **instance** (Instance) - The wgpu instance - **device** (Device) - The wgpu device - **queue** (Queue) - The wgpu queue - **adapter** (Adapter) - The wgpu adapter - **surface_format** (TextureFormat) - The preferred surface texture format ### `get` #### Description Gets a clone of the global wgpu context. #### Method `pub fn get() -> Context` #### Panics Panics if the context has not been initialized via `init()`. ### `is_initialized` #### Description Checks if the context has been initialized. #### Method `pub fn is_initialized() -> bool` ### `reset` #### Description Resets the global wgpu context, dropping all GPU resources. This should be called before thread-local storage destruction begins to avoid TLS access order issues with wgpu internals. After calling this, `is_initialized()` will return `false` and `get()` will panic until `init()` is called again. #### Method `pub fn reset()` ``` -------------------------------- ### Get Depth Texture Format Source: https://docs.rs/kiss3d/latest/src/kiss3d/context/context.rs_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets the depth texture format used for depth attachments. This is a static method that returns the predefined depth format. ```APIDOC ## GET /websites/rs_kiss3d/depth_format ### Description Gets the depth texture format used for depth attachments. ### Method GET ### Endpoint /websites/rs_kiss3d/depth_format ### Parameters None ### Request Example (No request body) ### Response #### Success Response (200) - **format** (wgpu::TextureFormat) - The depth texture format. #### Response Example ```json { "format": "Depth32Float" } ``` ``` -------------------------------- ### Window Configuration and Rendering Source: https://docs.rs/kiss3d/latest/kiss3d/window/struct.Window_search=u32+-%3E+bool APIs for setting the background color, loading textures, and retrieving screen scale factor. ```APIDOC ## PUT /window/{window_id}/background_color ### Description Sets the background color for the window. ### Method PUT ### Endpoint /window/{window_id}/background_color ### Parameters #### Path Parameters - **window_id** (string) - Required - The ID of the window #### Request Body - **color** (object) - Required - The background color - **r** (number) - Required - Red component (0.0 to 1.0) - **g** (number) - Required - Green component (0.0 to 1.0) - **b** (number) - Required - Blue component (0.0 to 1.0) ### Request Example ```json { "color": { "r": 0.1, "g": 0.2, "b": 0.5 } } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message #### Response Example ```json { "message": "Background color set." } ``` ## POST /window/{window_id}/textures ### Description Loads a texture from a file and returns a reference to it. The texture is managed by the global texture manager and will be reused if loaded again with the same name. ### Method POST ### Endpoint /window/{window_id}/textures ### Parameters #### Path Parameters - **window_id** (string) - Required - The ID of the window #### Request Body - **path** (string) - Required - Path to the texture file - **name** (string) - Required - A unique name to identify this texture ### Request Example ```json { "path": "/path/to/texture.png", "name": "my_texture" } ``` ### Response #### Success Response (200) - **texture_id** (string) - A unique identifier for the loaded texture #### Response Example ```json { "texture_id": "tex_abc123" } ``` ## GET /window/{window_id}/scale_factor ### Description Returns the DPI scale factor of the screen. This is the ratio between physical pixels and logical pixels. On high-DPI displays (like Retina displays), this will be greater than 1.0. ### Method GET ### Endpoint /window/{window_id}/scale_factor ### Parameters #### Path Parameters - **window_id** (string) - Required - The ID of the window ### Response #### Success Response (200) - **scale_factor** (number) - The scale factor (e.g., 1.0 for standard displays, 2.0 for Retina displays) #### Response Example ```json { "scale_factor": 1.5 } ``` ``` -------------------------------- ### RandR: Get Monitors Source: https://docs.rs/kiss3d/latest/kiss3d/prelude/struct.Rc_search= Retrieves a list of connected monitors for a given window. Allows specifying whether to get only active monitors. ```rust fn randr_get_monitors( &self, window: u32, get_active: bool, ) -> Result, ConnectionError> ``` -------------------------------- ### RandR Get CRTC Gamma Size Function Source: https://docs.rs/kiss3d/latest/kiss3d/prelude/struct.Rc_search= Gets the size of the gamma ramp supported by a CRTC. Returns a Cookie for the GetCrtcGammaSizeReply or a ConnectionError. ```rust fn randr_get_crtc_gamma_size( &self, crtc: u32, ) -> Result, ConnectionError> ``` -------------------------------- ### Example: Create Unit Hemisphere Mesh (Rust) Source: https://docs.rs/kiss3d/latest/kiss3d/procedural/fn.unit_hemisphere_search=u32+-%3E+bool An example demonstrating how to create a hemisphere mesh using the `unit_hemisphere` function with specified subdivision counts. ```Rust // Create a hemisphere with 32 longitude and 16 latitude subdivisions let hemisphere_mesh = unit_hemisphere(32, 16); ``` -------------------------------- ### Initialize wgpu Adapter and Device Source: https://docs.rs/kiss3d/latest/src/kiss3d/window/wgpu_canvas.rs_search=std%3A%3Avec This snippet demonstrates how to find a compatible wgpu adapter and request a device. It includes platform-specific limit defaults for WebGL2 compatibility on WASM. The process involves creating a wgpu instance, finding an adapter, and then requesting a device and queue. ```rust let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { compatible_surface: Some(&surface), force_fallback_adapter: false, }) .await .expect("Failed to find an appropriate adapter"); #[cfg(target_arch = "wasm32")] let limits = wgpu::Limits::downlevel_webgl2_defaults(); #[cfg(not(target_arch = "wasm32"))] let limits = wgpu::Limits::default(); let (device, queue) = adapter .request_device(&wgpu::DeviceDescriptor { label: Some("kiss3d device"), required_features: wgpu::Features::empty(), required_limits: limits, memory_hints: wgpu::MemoryHints::default(), trace: wgpu::Trace::Off, experimental_features: ExperimentalFeatures::default(), }) .await .expect("Failed to create device"); ``` -------------------------------- ### Configure FirstPersonCamera3d Input Buttons (Rust) Source: https://docs.rs/kiss3d/latest/kiss3d/camera/struct.FirstPersonCamera3d Explains how to get and set the mouse buttons and keyboard keys used for controlling the `FirstPersonCamera3d`. This allows for customization of the camera's interaction scheme. ```rust let mut camera = FirstPersonCamera3d::new(Vec3::new(0.0, 1.0, 5.0), Vec3::ZERO); // Get current buttons/keys let rotate_button = camera.rotate_button(); let drag_button = camera.drag_button(); let up_key = camera.up_key(); // Rebind buttons/keys camera.rebind_rotate_button(Some(MouseButton::Right)); camera.rebind_drag_button(Some(MouseButton::Left)); camera.rebind_up_key(Some(Key::W)); camera.rebind_down_key(Some(Key::S)); camera.rebind_left_key(Some(Key::A)); camera.rebind_right_key(Some(Key::D)); // Disable a movement key camera.rebind_up_key(None); ``` -------------------------------- ### Get and Set Camera Drag Button (Rust) Source: https://docs.rs/kiss3d/latest/src/kiss3d/camera/first_person3d.rs Provides methods to get and set the mouse button used for dragging the camera. Setting it to `None` disables dragging. ```Rust /// The button used to drag the FirstPersonCamera3d camera. pub fn drag_button(&self) -> Option { self.drag_button } /// Set the button used to drag the FirstPersonCamera3d camera. /// Use None to disable dragging. pub fn rebind_drag_button(&mut self, new_button: Option) { self.drag_button = new_button; } ``` -------------------------------- ### Get and Set Camera Rotation Button (Rust) Source: https://docs.rs/kiss3d/latest/src/kiss3d/camera/first_person3d.rs Provides methods to get and set the mouse button used for rotating the camera. Setting it to `None` disables rotation. ```Rust /// The button used to rotate the FirstPersonCamera3d camera. pub fn rotate_button(&self) -> Option { self.rotate_button } /// Set the button used to rotate the FirstPersonCamera3d camera. /// Use None to disable rotation. pub fn rebind_rotate_button(&mut self, new_button: Option) { self.rotate_button = new_button; } ``` -------------------------------- ### Create FirstPersonCamera3d with Custom Frustum (Rust) Source: https://docs.rs/kiss3d/latest/kiss3d/camera/struct.FirstPersonCamera3d Shows how to initialize a `FirstPersonCamera3d` with custom frustum parameters, including field of view (FOV), near and far clipping planes, and initial camera position and orientation. ```rust let camera = FirstPersonCamera3d::new_with_frustum( f32::consts::PI / 4.0, // 45 degrees FOV in radians 0.1, // Near clipping plane 1024.0, // Far clipping plane Vec3::new(0.0, 5.0, 10.0), // Eye position Vec3::ZERO // Looking at origin ); ``` -------------------------------- ### Get Type ID of Any Type Source: https://docs.rs/kiss3d/latest/kiss3d/event/struct.Modifiers_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Implements the `Any` trait for generic types, providing a method to get the `TypeId` of an instance. This is useful for runtime type identification. ```rust fn type_id(&self) -> TypeId; ```