### Vector3D::zip Example Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Vec3D.html Applies a function to corresponding components of two Vector3D instances. Useful for element-wise operations like saturating addition. ```rust use euclid::default::Vector3D; let a: Vector3D = Vector3D::new(50, 200, 10); let b: Vector3D = Vector3D::new(100, 100, 0); assert_eq!(a.zip(b, u8::saturating_add), Vector3D::new(150, 255, 10)); ``` -------------------------------- ### Vector3D::map Example Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Vec3D.html Applies a function to each component of a Vector3D. Useful for custom arithmetic operations on vector components. ```rust use euclid::default::Vector3D; let p = Vector3D::::new(5, 11, 15); assert_eq!(p.map(|coord| coord.saturating_sub(10)), Vector3D::new(0, 1, 5)); ``` -------------------------------- ### Vector2D::zip Example Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Vec2D.html Applies a function to corresponding components of two Vector2Ds. Useful for element-wise operations like addition or multiplication. ```rust use euclid::default::Vector2D; let a: Vector2D = Vector2D::new(50, 200); let b: Vector2D = Vector2D::new(100, 100); assert_eq!(a.zip(b, u8::saturating_add), Vector2D::new(150, 255)); ``` -------------------------------- ### Vector2D::map Example Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Vec2D.html Applies a function to each component of a Vector2D. Useful for custom arithmetic operations not directly supported by methods. ```rust use euclid::default::Vector2D; let p = Vector2D::::new(5, 11); assert_eq!(p.map(|coord| coord.saturating_sub(10)), Vector2D::new(0, 1)); ``` -------------------------------- ### clamp Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Vec3D.html Returns the vector each component of which is clamped by corresponding components of `start` and `end`. Shortcut for `self.max(start).min(end)`. ```APIDOC ## clamp ### Description Returns the vector each component of which is clamped by corresponding components of `start` and `end`. Shortcut for `self.max(start).min(end)`. ### Method `clamp(start: Vector3D, end: Vector3D)` ``` -------------------------------- ### Get Bounds Size Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Bounds2D.html Calculates and returns the full size (width and height) of the bounds. ```rust pub fn size(&self) -> T ``` -------------------------------- ### Create Shader Module Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/shader/struct.Sdf3DShader.html Generates a wgpu::ShaderModule from the Sdf3DShader, requiring a wgpu::Device. ```rust pub fn create_shader_module(&self, device: &Device) -> ShaderModule ``` -------------------------------- ### Get TypeId Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/mesh/struct.VertexList.html Gets the `TypeId` of `self`. This is part of the `Any` trait implementation. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Initialize Rgba32FloatTextureStorage Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/texture.rs.html Creates a new Rgba32FloatTextureStorage with a WGPU texture, view, and buffer. Requires a WGPU device, dimensions, and a binding ID. ```rust pub fn new(device: &wgpu::Device, dims: (u32, u32), binding_id: u32) -> Self { let texture = device.create_texture(&wgpu::TextureDescriptor { label: None, size: wgpu::Extent3d { width: dims.0, height: dims.1, depth_or_array_layers: 1, }, mip_level_count: 1, sample_count: 1, dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Rgba32Float, usage: wgpu::TextureUsages::STORAGE_BINDING | wgpu::TextureUsages::COPY_SRC, view_formats: &[], }); let data = vec![0.0_f32; (dims.0 as usize) * (dims.1 as usize) * 4]; let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); let buffer = device.create_buffer(&wgpu::BufferDescriptor { label: None, size: std::mem::size_of_val(&data[..]) as u64, usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ, mapped_at_creation: false, }); Self { data, dims, texture, view, buffer, binding_id, } } ``` -------------------------------- ### Initialize Built-in Shader Modules Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/shader.rs.html Defines a static HashMap containing WGSL code for built-in SDF modules. These modules are included using `include_str!` and are essential for shader functionality. ```rust lazy_static! { static ref BUILTIN_MODULES: std::collections::HashMap<&'static str, &'static str> = { hash_map! { "sdf::op" => include_str!("sdf_op.wgsl"), "sdf3d::normal" => include_str!("sdf3d_normal.wgsl"), "sdf3d::primitives" => include_str!("sdf3d_primitives.wgsl"), } }; } ``` -------------------------------- ### Get Bounds Center Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Bounds2D.html Calculates and returns the center point of the bounds. ```rust pub fn center(&self) -> T ``` -------------------------------- ### Get Maximum Corner Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Bounds2D.html Returns a reference to the maximum corner point of the bounds. ```rust pub fn max(&self) -> &T ``` -------------------------------- ### Initialize Sdf3DShader with Built-in Modules Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/shader.rs.html Constructs a new `Sdf3DShader` instance and pre-populates its module handlers with built-in WGSL code for SDF operations, primitives, and normals. The shader source is then loaded from a specified path. ```rust impl Sdf3DShader { /// Construct a new `Sdf3DShader` from a path pub fn from_path(path: impl AsRef) -> Self { let mut s = Self { source: String::new(), modules: HashMap::new(), }; s.add_module("sdf::*", |w| write!(w, "{}", BUILTIN_MODULES["sdf::op"])) .add_module("sdf::op", |w| write!(w, "{}", BUILTIN_MODULES["sdf::op"])) .add_module("sdf3d::normal", |w| { write!(w, "{}", BUILTIN_MODULES["sdf3d::normal"]) }) .add_module("sdf3d::primitives", |w| { write!(w, "{}", BUILTIN_MODULES["sdf3d::primitives"]) }) .add_module("sdf3d::*", |w| { write!(w, "{}", BUILTIN_MODULES["sdf3d::primitives"])?; write!(w, "{}", BUILTIN_MODULES["sdf3d::normal"])?; Ok(()) }); s.source = s.shader_source(&path); s } // ... other methods ``` -------------------------------- ### Get Minimum Corner Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Bounds2D.html Returns a reference to the minimum corner point of the bounds. ```rust pub fn min(&self) -> &T ``` -------------------------------- ### Create VertexList with Capacity Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/mesh/struct.VertexList.html Initializes a new VertexList with a specified pre-allocated capacity to optimize memory usage. ```rust pub fn with_capacity(capacity: usize) -> Self ``` -------------------------------- ### Policy 'And' Method Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/shader/struct.Sdf3DShader.html Creates a new `Policy` that returns `Action::Follow` only if both `self` and `other` policies return `Action::Follow`. ```rust fn and(self, other: P) -> And where T: Policy, P: Policy, ``` -------------------------------- ### Get VertexList Length Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/mesh/struct.VertexList.html Returns the number of vertices currently stored in the VertexList. ```rust pub fn len(&self) -> usize ``` -------------------------------- ### Policy 'Or' Method Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/shader/struct.Sdf3DShader.html Creates a new `Policy` that returns `Action::Follow` if either `self` or `other` policies return `Action::Follow`. ```rust fn or(self, other: P) -> Or where T: Policy, P: Policy, ``` -------------------------------- ### Vector2D::clamp Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Vec2D.html Clamps each component of the vector between corresponding components of start and end vectors. ```APIDOC ## Vector2D::clamp ### Description Returns the vector each component of which is clamped by corresponding components of `start` and `end`. Shortcut for `self.max(start).min(end)`. ### Method `clamp(start: Vector2D, end: Vector2D) -> Vector2D` ### Parameters - **start** (Vector2D): The vector defining the lower bounds for clamping. - **end** (Vector2D): The vector defining the upper bounds for clamping. ### Response - `Vector2D`: The clamped vector. ### Example ```rust let v = vec2(5.0, 0.0); let start = vec2(1.0, -1.0); let end = vec2(3.0, 3.0); assert_eq!(v.clamp(start, end), vec2(3.0, 0.0)); ``` ``` -------------------------------- ### Sdf3DShader::create_shader_module Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/shader/struct.Sdf3DShader.html Creates a `wgpu::ShaderModule` from the `Sdf3DShader`. ```APIDOC ## Sdf3DShader::create_shader_module ### Description Creates a `wgpu::ShaderModule` from the `Sdf3DShader`. ### Signature ```rust pub fn create_shader_module(&self, device: &Device) -> ShaderModule ``` ### Parameters * `device`: A reference to the `wgpu::Device` used for creating the shader module. ``` -------------------------------- ### Any Trait Implementation Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/shadertoy/struct.ShaderInfo.html Implements the Any trait for generic types, providing a way to get the TypeId of a value. ```rust impl Any for T where T: 'static + ?Sized, { fn type_id(&self) -> TypeId } ``` -------------------------------- ### STLWriter: New Instance Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/mesh.rs.html Initializes a new STLWriter, writing the 'solid' header to the output stream. Ensure the writer implements `std::io::Write`. ```rust pub fn new(mut w: &'a mut dyn Write) -> Self { writeln!(&mut w, "solid").unwrap(); Self { writer: w } } ``` -------------------------------- ### Vector3D::round Example Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Vec3D.html Rounds each component of a Vector3D to the nearest integer. Preserves behavior for negative values. ```rust enum Mm {} assert_eq!(vec3::<_, Mm>(-0.1, -0.8, 0.4).round(), vec3::<_, Mm>(0.0, -1.0, 0.0)) ``` -------------------------------- ### Fetch and Convert ShaderToy Shader to WGSL Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/shader.rs.html Asynchronously constructs an `Sdf3DShader` by fetching a shader from the ShaderToy API. It converts the fetched shader to WGSL, removes default entry points, and adds a wrapper for the specified SDF function if needed. ```rust pub async fn from_shadertoy_api( shader_id: &str, sdf: &str, ) -> Result { let shader = shadertoy::Shader::from_api(shader_id).await?; log::info!("Shader: {}", shader.info.name); log::info!("Shader author: {}", shader.info.username); let mut wgsl = shader.generate_wgsl_shader_code()?; wgsl.remove_function("fn main_1(")?; wgsl.remove_function("fn main(")?; wgsl.remove_function("fn mainImage(")?; wgsl.remove_line("@fragment"); // Remove fragment entry point if wgsl.has_function(sdf) { if !wgsl.has_function("sdf3d") { // Generate function wrapper wgsl.add_line( format!("fn sdf3d(p: vec3) -> f32 {{ return {}(p); }}", sdf).as_str(), ); } } else { return Err(shadertoy::ShaderProcessingError::MissingSdf(sdf.into())); } Ok(Self { source: wgsl.to_string(), modules: HashMap::new(), }) } ``` -------------------------------- ### PLYWriter: New Instance Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/mesh.rs.html Initializes a new PLYWriter, writing the initial PLY header lines including format and comment. Returns a `std::io::Result`. ```rust pub fn new(mut w: &'a mut dyn Write) -> std::io::Result { writeln!(&mut w, "ply")?; writeln!(&mut w, "format ascii 1.0")?; writeln!(&mut w, "comment written by rust-sdf")?; Ok(Self { writer: w }) } ``` -------------------------------- ### Get Mutable Maximum Corner Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Bounds2D.html Returns a mutable reference to the maximum corner point of the bounds, allowing in-place modification. ```rust pub fn max_mut(&mut self) -> &mut T ``` -------------------------------- ### from_api Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/shadertoy/struct.Shader.html Asynchronously creates a Shader instance from a given shader ID fetched from an API. ```APIDOC ## pub async fn from_api(shader_id: &str) -> Result Asynchronously creates a Shader instance from a given shader ID fetched from an API. Returns a Result containing the Shader or a ShaderProcessingError. ``` -------------------------------- ### Get Mutable Minimum Corner Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Bounds2D.html Returns a mutable reference to the minimum corner point of the bounds, allowing in-place modification. ```rust pub fn min_mut(&mut self) -> &mut T ``` -------------------------------- ### Create wgpu::ShaderModule from source Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/shader.rs.html Creates a `wgpu::ShaderModule` object from the generated WGSL source string, which can then be used by the GPU. ```rust pub fn create_shader_module(&self, device: &wgpu::Device) -> wgpu::ShaderModule { device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(self.source.as_str())), }) } ``` -------------------------------- ### Bounds3D Implementations Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Bounds3D.html Provides various methods for creating and manipulating 3D bounding boxes, such as creating cubes, projecting bounds, and checking for containment. ```rust pub fn centered(size: &Vec3D) -> Self ``` ```rust pub fn projected_z(&self) -> Bounds2D ``` ```rust pub fn cube(a: Scalar, center: &Vec3D) -> Self ``` ```rust pub fn centered_cube(a: Scalar) -> Self ``` ```rust pub fn max_extent(&self) -> Scalar ``` ```rust pub fn union_(a: &Bounds3D, b: &Bounds3D) -> Self ``` ```rust pub fn contains(&self, p: &Vec3D) -> bool ``` -------------------------------- ### Get RGBA pixel data Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/texture.rs.html Retrieves the RGBA color values for a specific pixel from the texture's data. Coordinates are 0-indexed. ```rust pub fn get_rgba(&self, x: u32, y: u32) -> (f32, f32, f32, f32) { let idx = ((y * self.dims.0 + x) * 4) as usize; ( self.data[idx], self.data[idx + 1], self.data[idx + 2], self.data[idx + 3], ) } ``` -------------------------------- ### Vector2D::ceil Example Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Vec2D.html Rounds each component up to the smallest integer greater than or equal to the original value. Preserves behavior for negative values. ```rust enum Mm {} assert_eq!(vec2::<_, Mm>(-0.1, -0.8).ceil(), vec2::<_, Mm>(0.0, 0.0)) ``` -------------------------------- ### Vector3D Constructors Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Vec3D.html Provides methods for creating new Vector3D instances. ```APIDOC ## Constructors ### `zero()` Constructor, setting all components to zero. ### `one()` Constructor, setting all components to one. ### `new(x: T, y: T, z: T)` Constructor taking scalar values directly. ### `splat(v: T)` Constructor setting all components to the same value. ### `from_lengths(x: Length, y: Length, z: Length)` Constructor taking properly Lengths instead of scalar values. ### `from_untyped(p: Vector3D)` Tag a unitless value with units. ``` -------------------------------- ### Vector2D::round Example Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Vec2D.html Rounds each component of the vector to the nearest integer. Preserves behavior for negative values, unlike a simple cast. ```rust enum Mm {} assert_eq!(vec2::<_, Mm>(-0.1, -0.8).round(), vec2::<_, Mm>(0.0, -1.0)) ``` -------------------------------- ### Create Bounds from Min and Max Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Bounds2D.html Constructs a Bounds instance given its minimum and maximum corner points. This is a fundamental way to create bounds. ```rust pub fn min_max(min: T, max: T) -> Self ``` -------------------------------- ### Get Bind Group Entry Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/texture/struct.Rgba32FloatTextureStorage.html Generates a BindGroupEntry for this texture storage. This entry is used to bind the actual texture resource to a bind group. ```rust pub fn bind_group_entry(&self) -> BindGroupEntry<'_> ``` -------------------------------- ### Write shader source to a file Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/shader.rs.html Creates a file at the specified path and writes the generated shader source code into it. ```rust pub fn write_to_file(&self, path: impl AsRef) -> std::io::Result<()> { let mut f = std::io::BufWriter::new(File::create(path)?); write!(f, "{}", self.source) } ``` -------------------------------- ### Vector3D::ceil Example Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Vec3D.html Rounds each component of a Vector3D up to the smallest integer greater than or equal to the original value. Preserves behavior for negative values. ```rust enum Mm {} assert_eq!(vec3::<_, Mm>(-0.1, -0.8, 0.4).ceil(), vec3::<_, Mm>(0.0, 0.0, 1.0)) ``` -------------------------------- ### Initialize PLYWriter Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/mesh/struct.PLYWriter.html Creates a new instance of PLYWriter, taking a mutable reference to a writer. This is the entry point for writing PLY data. ```rust pub fn new(w: &'a mut dyn Write) -> Result ``` -------------------------------- ### Create Bounds from Size and Center Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Bounds2D.html Constructs a Bounds instance given its size (full width/height) and center point. Useful when dimensions are known relative to a center. ```rust pub fn size_center(size: T, center: T) -> Self ``` -------------------------------- ### Get Bind Group Layout Entry Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/texture/struct.Rgba32FloatTextureStorage.html Generates a BindGroupLayoutEntry for this texture storage. This is used to define how the texture resource is laid out in a bind group for the GPU. ```rust pub fn bind_group_layout_entry(&self) -> BindGroupLayoutEntry ``` -------------------------------- ### Vector3D::abs Example Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Vec3D.html Computes the absolute value for each component of a Vector3D. Panics may occur based on the scalar type's `abs` implementation. ```rust enum U {} assert_eq!(vec3::<_, U>(-1, 0, 2).abs(), vec3(1, 0, 2)); let vec = vec3::<_, U>(f32::NAN, 0.0, -f32::MAX).abs(); assert!(vec.x.is_nan()); assert_eq!(vec.y, 0.0); assert_eq!(vec.z, f32::MAX); ``` -------------------------------- ### Get Vertex Index in SDF2Mesh Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/mesh.rs.html Retrieves the index of a vertex at specified coordinates. Returns u32::MAX if the vertex is not found. This is used internally for mesh construction. ```rust fn vertex_index(&self, x: u16, y: u16, z: u16) -> u32 { self.0 .binary_search_by_key(&VertexListItem::compute_index(x, y, z), |item| item.index()) .unwrap_or(u32::MAX as usize) as u32 } ``` -------------------------------- ### Convert GLSL to WgslShaderCode Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/shadertoy/struct.WgslShaderCode.html Creates a WgslShaderCode instance from GLSL source code. Returns an error if processing fails. ```rust pub fn from_glsl(glsl: &str) -> Result ``` -------------------------------- ### VertexList Methods Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/mesh/struct.VertexList.html Provides methods for creating, manipulating, and querying VertexList instances. ```APIDOC ## pub fn with_capacity(capacity: usize) -> Self Creates a new `VertexList` with a pre-allocated capacity. ### Parameters - `capacity` (usize) - The initial capacity for the vertex list. ### Returns - `Self` - A new `VertexList` instance. ``` ```APIDOC ## pub fn insert( &mut self, cell: (u16, u16, u16), sign_changes: (bool, bool, bool, bool), vertex: Vertex, ) Inserts a vertex into the `VertexList` along with its associated cell and sign change information. ### Parameters - `cell` ((u16, u16, u16)) - The cell coordinates. - `sign_changes` ((bool, bool, bool, bool)) - The sign changes associated with the vertex. - `vertex` (Vertex) - The vertex data to insert. ``` ```APIDOC ## pub fn len(&self) -> usize Returns the number of vertices currently in the `VertexList`. ### Returns - `usize` - The number of vertices. ``` ```APIDOC ## pub fn is_empty(&self) -> bool Checks if the `VertexList` is empty. ### Returns - `bool` - `true` if the list is empty, `false` otherwise. ``` ```APIDOC ## pub fn fetch_vertices(&self) -> Vec Retrieves all vertices from the `VertexList` as a `Vec`. ### Returns - `Vec` - A vector containing all vertices. ``` ```APIDOC ## pub fn fetch_triangle_indices(&self) -> Vec> Retrieves the triangle indices from the `VertexList` as a `Vec>`. ### Returns - `Vec>` - A vector containing triangle indices. ``` -------------------------------- ### Vector2D::abs Example Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Vec2D.html Computes the vector with the absolute values of each component. Panics may occur based on the scalar type's `Signed::abs` implementation. ```rust enum U {} assert_eq!(vec2::<_, U>(-1, 2).abs(), vec2(1, 2)); let vec = vec2::<_, U>(f32::NAN, -f32::MAX).abs(); assert!(vec.x.is_nan()); assert_eq!(vec.y, f32::MAX); ``` -------------------------------- ### Get RGBA Pixel Data Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/texture/struct.Rgba32FloatTextureStorage.html Retrieves the RGBA color values for a specific pixel at coordinates (x, y) from the texture storage. Returns values as a tuple of four f32. ```rust pub fn get_rgba(&self, x: u32, y: u32) -> (f32, f32, f32, f32) ``` -------------------------------- ### Quad Methods Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/struct.Quad.html Specific methods for Quad with u32 type. ```APIDOC ## Quad ### is_valid ```rust pub fn is_valid(&self) -> bool ``` Checks if the Quad is valid. ``` -------------------------------- ### Sdf3DShader::from_path Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/shader/struct.Sdf3DShader.html Constructs a new `Sdf3DShader` from a given file path. ```APIDOC ## Sdf3DShader::from_path ### Description Construct a new `Sdf3DShader` from a path. ### Signature ```rust pub fn from_path(path: impl AsRef) -> Self ``` ### Parameters * `path`: A type that can be converted into a reference to a `Path`, representing the shader file location. ``` -------------------------------- ### Check if Function Exists in WGSL Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/shadertoy.rs.html Checks if a function with the given name exists in the WGSL code. It searches for lines starting with 'fn function_name('. Returns an error if the function is not found. ```rust fn wgsl_has_function(wgsl: &str, function_name: &str) -> Result { let lines = wgsl.lines(); let mut function_found = false; for line in lines { let line = line.trim(); if line.starts_with(format!("fn {function_name}(").as_str()) { function_found = true; break; } } if !function_found { return Err(ShaderProcessingError::ShaderError(format!( "Function {} not found in shader", function_name ))); } Ok(true) } ``` -------------------------------- ### Rgba32FloatTextureStorage Methods Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/texture/struct.Rgba32FloatTextureStorage.html Provides methods for creating, accessing, and managing Rgba32FloatTextureStorage instances. ```APIDOC ## pub fn new(device: &Device, dims: (u32, u32), binding_id: u32) -> Self ### Description Creates a new Rgba32FloatTextureStorage. ### Parameters - `device`: A reference to the graphics device. - `dims`: A tuple representing the dimensions (width, height) of the texture. - `binding_id`: The binding ID for the texture. ### Returns A new instance of Rgba32FloatTextureStorage. ``` ```APIDOC ## pub fn get_rgba(&self, x: u32, y: u32) -> (f32, f32, f32, f32) ### Description Retrieves the RGBA color values at the specified coordinates. ### Parameters - `x`: The x-coordinate. - `y`: The y-coordinate. ### Returns A tuple of four f32 values representing the Red, Green, Blue, and Alpha components. ``` ```APIDOC ## pub fn bind_group_layout_entry(&self) -> BindGroupLayoutEntry ### Description Returns the BindGroupLayoutEntry for this texture storage. ### Returns A BindGroupLayoutEntry. ``` ```APIDOC ## pub fn bind_group_entry(&self) -> BindGroupEntry<'_> ### Description Returns the BindGroupEntry for this texture storage. ### Returns A BindGroupEntry. ``` ```APIDOC ## pub fn copy_texture_to_buffer(&self, encoder: &mut CommandEncoder) ### Description Copies the texture data to a buffer using the provided command encoder. ### Parameters - `encoder`: A mutable reference to the CommandEncoder. ``` ```APIDOC ## pub async fn map_buffer(&mut self, device: &Device) ### Description Maps the texture's buffer for CPU access asynchronously. ### Parameters - `device`: A reference to the graphics device. ``` -------------------------------- ### Implement Default for ShaderOutput Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/shadertoy/struct.ShaderOutput.html Provides a Default implementation for ShaderOutput, allowing instances to be created with default values. ```rust impl Default for ShaderOutput Source§ #### fn default() -> ShaderOutput Returns the “default value” for a type. Read more Source§ ``` -------------------------------- ### Quad Methods Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/lib.rs.html Provides methods for creating triangles from a Quad and checking its validity. ```APIDOC ## Quad ### Description Represents a quadrilateral defined by four vertices. ### Methods #### `make_triangles(&self) -> (Triangle, Triangle)` Converts the quadrilateral into two triangles. - **Returns**: A tuple containing two `Triangle` objects. #### `is_valid(&self) -> bool` (for `Quad`) Checks if the quad is valid by ensuring none of its vertices are `u32::MAX`. - **Returns**: `true` if the quad is valid, `false` otherwise. ``` -------------------------------- ### Default TriangleMesh Initialization Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/mesh/struct.TriangleMesh.html Provides a default, empty TriangleMesh instance. This is useful for creating a new mesh without initial data. ```rust fn default() -> TriangleMesh ``` -------------------------------- ### ToPngFile Implementation Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/texture/struct.Rgba32FloatTextureStorage.html Implementation of the ToPngFile trait for Rgba32FloatTextureStorage. ```APIDOC ## fn to_png_file(&self, path: impl AsRef) ### Description Saves the texture data to a PNG file at the specified path. ### Parameters - `path`: A type that can be converted into a Path, specifying the output file location. ``` -------------------------------- ### Process shader source with includes and uses Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/shader.rs.html Reads a shader file, processes `use` and `include` directives, and writes the final shader source to a writer. Handles recursive includes and module lookups. ```rust match read_lines(&path) { Ok(lines) => { for line in lines.flatten() { let trimmed = line.trim(); if trimmed.ends_with(';') { if trimmed.starts_with("use") { let modulename = trimmed .replacen("use", "", 1) .replace(['"', ';'], "") .trim() .to_string(); log::info!(%modulename); if self.modules.contains_key(&modulename) { self.modules.get(&modulename).unwrap()(w)?; } continue; } else if trimmed.starts_with("include") { let filename = std::path::PathBuf::from( trimmed .replacen("include", "", 1) .replace(['"', ';'], "") .trim(), ); if filename != path.as_ref() { self.shader_source_input(filename, w)?; } continue; } } writeln!(w, "{}", line)?; } } Err(err) => { log::error!("Could not include {:?}: {}", path.as_ref(), err); } } Ok(()) } ``` -------------------------------- ### Default and Trait Implementations for Bounds2D Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Bounds2D.html Covers the default value implementation and trait implementations like Clone, Debug, and Copy for Bounds2D. ```APIDOC ### Trait Implementations for Bounds2D #### `impl Default for Bounds2D` ##### `fn default() -> Self` Returns the default value for Bounds2D. #### `impl Clone for Bounds` ##### `fn clone(&self) -> Bounds` Clones the Bounds object. ##### `fn clone_from(&mut self, source: &Self)` Clones from a source Bounds object. #### `impl Debug for Bounds` ##### `fn fmt(&self, f: &mut Formatter<'_>) -> Result` Formats the Bounds object for debugging. #### `impl Copy for Bounds` Indicates that Bounds is a Copy type. ``` -------------------------------- ### Display Implementation for Bounds3D Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Bounds3D.html Enables formatting Bounds3D for display. ```APIDOC ### impl Display for Bounds3D #### fn fmt(&self, f: &mut Formatter<'_>) -> Result Formats the value using the given formatter. ``` -------------------------------- ### Create Rgba32FloatTextureStorage Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/texture/struct.Rgba32FloatTextureStorage.html Constructs a new Rgba32FloatTextureStorage. Requires a graphics device, dimensions (width, height), and a binding ID for resource management. ```rust pub fn new(device: &Device, dims: (u32, u32), binding_id: u32) -> Self ``` -------------------------------- ### Bounds2D Construction and Utility Methods Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Bounds2D.html Provides methods for creating and manipulating Bounds2D objects, such as creating a square, performing unions and intersections, scaling, and checking for containment. ```APIDOC ## Bounds2D ### Type Alias ```rust pub type Bounds2D = Bounds; ``` ### Aliased Type ```rust pub struct Bounds2D(/* private fields */); ``` ### Implementations for Bounds2D #### `pub fn square(a: f32, center: Vec2D) -> Self` Creates a square bounding box. #### `pub fn union_(a: &Bounds2D, b: &Bounds2D) -> Self` Computes the union of two bounding boxes. #### `pub fn intersection(a: &Bounds2D, b: &Bounds2D) -> Self` Computes the intersection of two bounding boxes. #### `pub fn scaled(&self, scale: Scalar) -> Bounds2D` Returns a new Bounds2D scaled by the given factor. #### `pub fn max_extent(&self) -> Scalar` Returns the maximum extent of the bounding box. #### `pub fn contains(&self, p: &Vec2D) -> bool` Checks if a point is contained within the bounding box. ``` -------------------------------- ### Clone Implementation Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/struct.Bounds.html Provides methods for cloning Bounds instances. ```APIDOC ## Clone Implementation ### `clone(&self) -> Bounds` Returns a duplicate of the value. ### `clone_from(&mut self, source: &Self)` Performs copy-assignment from `source`. ``` -------------------------------- ### Create a Square Bounds2D Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/type.Bounds2D.html Creates a square Bounds2D. Requires a side length and a center point. ```rust pub fn square(a: f32, center: Vec2D) -> Self ``` -------------------------------- ### Write Mesh to File (Auto-detect Format) Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/mesh.rs.html Determines the file format (STL or PLY) based on the file extension and calls the appropriate writing function. Logs an error for unknown extensions. ```rust pub fn write_to_file(&self, path: impl AsRef) -> std::io::Result<()> { match path .as_ref() .extension() .unwrap_or_default() .to_ascii_uppercase() .to_str() .unwrap_or_default() { "STL" => self.write_stl_to_file(path)?, "PLY" => self.write_ply_to_file(path)?, ext => log::error!("Unknown file extension: {ext}"), } Ok(()) } ``` -------------------------------- ### Sdf3DShader::from_shadertoy_api Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/shader/struct.Sdf3DShader.html Constructs a new `Sdf3DShader` by fetching a shader from the ShaderToy API. ```APIDOC ## Sdf3DShader::from_shadertoy_api ### Description Construct a new `Sdf3DShader` from the ShaderToy API. ### Signature ```rust pub async fn from_shadertoy_api( shader_id: &str, sdf: &str, ) -> Result ``` ### Parameters * `shader_id`: The ID of the ShaderToy shader to fetch, e.g., `DldfR7`. * `sdf`: Function name of the SDF function within the shader, e.g., `float sdf(vec3)`. ``` -------------------------------- ### Copy Texture to Buffer Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/texture.rs.html Copies the contents of the WGPU texture to a buffer using a command encoder. The buffer layout requires specific byte alignment. ```rust pub fn copy_texture_to_buffer(&self, encoder: &mut wgpu::CommandEncoder) { encoder.copy_texture_to_buffer( wgpu::ImageCopyTexture { texture: &self.texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, aspect: wgpu::TextureAspect::All, }, wgpu::ImageCopyBuffer { buffer: &self.buffer, layout: wgpu::ImageDataLayout { offset: 0, // This needs to be padded to 256. bytes_per_row: Some(self.dims.0 * 16), rows_per_image: Some(self.dims.1), }, }, wgpu::Extent3d { width: self.dims.0, height: self.dims.1, depth_or_array_layers: 1, }, ); } ``` -------------------------------- ### Convert GLSL Fragment Shader to WGSL Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/shader.rs.html Creates an `Sdf3DShader` from a GLSL fragment shader file. It converts the GLSL to WGSL, removes default entry points, adds necessary SDF helper functions, and ensures the specified SDF function exists. ```rust pub fn from_glsl_fragment_shader( path: impl AsRef, sdf: &str, ) -> Result { use shadertoy::*; let mut file = File::open(path).unwrap(); let mut glsl = String::new(); file.read_to_string(&mut glsl).unwrap(); let mut wgsl = WgslShaderCode::from_glsl(&glsl)?; wgsl.remove_function("fn main_1(")?; wgsl.remove_function("fn main(")?; wgsl.remove_line("@fragment"); // Remove fragment entry point wgsl.add_line(include_str!("sdf3d_normal.wgsl")); if wgsl.has_function(sdf) { if !wgsl.has_function("sdf3d") { // Generate function wrapper wgsl.add_line( format!("fn sdf3d(p: vec3) -> f32 {{ return {}(p); }}", sdf).as_str(), ); } } else { return Err(shadertoy::ShaderProcessingError::MissingSdf(sdf.into())); } Ok(Self { source: wgsl.to_string(), modules: HashMap::new(), }) } ``` -------------------------------- ### WGPU BindGroupEntry for Texture Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/texture.rs.html Generates a BindGroupEntry for the texture, linking the binding ID to the texture view. Essential for creating a WGPU BindGroup. ```rust pub fn bind_group_entry(&self) -> wgpu::BindGroupEntry { wgpu::BindGroupEntry { binding: self.binding_id, resource: wgpu::BindingResource::TextureView(&self.view), } } ``` -------------------------------- ### WgslShaderCode::from_glsl Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/shadertoy.rs.html Creates a new WgslShaderCode instance by converting GLSL code to WGSL. It ensures the GLSL code is valid by adding an empty main function if necessary. ```APIDOC ## WgslShaderCode::from_glsl ### Description Converts GLSL shader code into WGSL format. This function is useful for integrating GLSL shaders into environments that require WGSL. ### Signature ```rust pub fn from_glsl(glsl: &str) -> Result ``` ### Parameters * `glsl` (string slice) - The GLSL shader code to convert. ``` -------------------------------- ### With Subscriber Method Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/shader/struct.Sdf3DShader.html Attaches a `Subscriber` to the type, returning a `WithDispatch` wrapper for enhanced telemetry. ```rust fn with_subscriber(self, subscriber: S) -> WithDispatch where S: Into, ``` -------------------------------- ### Construct Sdf3DShader from GLSL Fragment Shader Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/shader/struct.Sdf3DShader.html Constructs an Sdf3DShader from a GLSL fragment shader file. Requires the path to the GLSL file and the name of the SDF function within the shader. ```rust pub fn from_glsl_fragment_shader( path: impl AsRef, sdf: &str, ) -> Result ``` -------------------------------- ### Construct Sdf3DShader from Path Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/shader/struct.Sdf3DShader.html Creates a new Sdf3DShader instance by loading shader code from a specified file path. ```rust pub fn from_path(path: impl AsRef) -> Self ``` -------------------------------- ### Quad Methods Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/struct.Quad.html Methods available for the Quad struct. ```APIDOC ## Quad ### swap ```rust pub fn swap(&self, yes: bool) -> Quad ``` Converts the quad into two triangles, swapping the order of vertices based on the `yes` parameter. ### make_triangles ```rust pub fn make_triangles(&self) -> (Triangle, Triangle) ``` Converts the quad into two triangles. ``` -------------------------------- ### Implement Debug for ShaderOutput Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/shadertoy/struct.ShaderOutput.html Provides a Debug implementation for ShaderOutput, allowing it to be formatted for debugging purposes. ```rust impl Debug for ShaderOutput Source§ #### fn fmt(&self, f: &mut Formatter<'_>) -> Result Formats the value using the given formatter. Read more Source§ ``` -------------------------------- ### Sdf3DShader::from_shadertoy_api Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/shader.rs.html Constructs a new `Sdf3DShader` from the ShaderToy API. It fetches shader code by ID, converts it to WGSL, and prepares it for SDF operations. ```APIDOC ## Sdf3DShader::from_shadertoy_api ### Description Constructs a new `Sdf3DShader` from the ShaderToy API. It fetches shader code by ID, converts it to WGSL, and prepares it for SDF operations. ### Parameters #### Path Parameters - **shader_id** (String) - Required - Id of the ShaderToy shader, e.g. DldfR7. - **sdf** (String) - Required - Function name of the SDF function, e.g. `float sdf(vec3)`. ### Returns - Result - A `Result` containing the `Sdf3DShader` on success, or a `ShaderProcessingError` on failure. ``` -------------------------------- ### Clone Implementation for Vertex Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/struct.Vertex.html Provides methods for cloning Vertex instances. ```APIDOC ### impl Clone for Vertex #### fn clone(&self) -> Vertex Returns a duplicate of the value. ``` ```APIDOC #### fn clone_from(&mut self, source: &Self) Performs copy-assignment from `source`. ``` -------------------------------- ### Generate shader source string Source: https://docs.rs/sdf2mesh/0.1.0/src/sdf2mesh/shader.rs.html Compiles the shader source, including any included modules, into a single string. Errors during inclusion are logged but do not prevent string generation. ```rust fn shader_source(&self, path: impl AsRef) -> String { let mut w = Vec::new(); let _ = self.shader_source_input(path, &mut w); std::str::from_utf8(w.as_slice()).unwrap().to_string() } ``` -------------------------------- ### Implement Clone for Vertex Source: https://docs.rs/sdf2mesh/0.1.0/sdf2mesh/struct.Vertex.html Provides a way to create a duplicate of a Vertex instance. This is useful for copying vertex data. ```rust fn clone(&self) -> Vertex ``` ```rust fn clone_from(&mut self, source: &Self) ```