### Example Usage of ToWgslString Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/trait.ToWgslString.html Demonstrates how to use the `to_wgsl_string` method to format a floating-point literal for WGSL. This ensures correct WGSL syntax for constants. ```rust let x = 2.0_f32; assert_eq!("let x = 2.;", format!("let x = {{}};", x.to_wgsl_string())); ``` -------------------------------- ### Basic WriterExpr Addition Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/expr/struct.WriterExpr.html Demonstrates creating literal values and adding them using WriterExpr. This is a fundamental example of combining expressions. ```rust let mut w = ExprWriter::new(); let x = w.lit(-3.5); let y = w.lit(78.); let z = x + y; // == 74.5 ``` -------------------------------- ### Vec3 Constructor Example Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/expr/enum.TernaryOperator.html Constructs a 3-element vector from three scalar elements. ```rust (x, y, z) ``` -------------------------------- ### Create a new empty Gradient Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.Gradient.html Initializes an empty gradient. Use this when starting with no predefined key points. ```rust let g: Gradient = Gradient::new(); assert!(g.is_empty()); ``` -------------------------------- ### DynamicBundle for C Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.EffectParent.html Enables a component `C` to be dynamically handled as a bundle, with methods for getting and applying components. ```APIDOC ## impl DynamicBundle for C where C: Component, ### type Effect = () An operation on the entity that happens _after_ inserting this bundle. ### unsafe fn get_components( ptr: MovingPtr<'_, C>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> ::Effect Moves the components out of the bundle. ### unsafe fn apply_effect( _ptr: MovingPtr<'_, MaybeUninit>, _entity: &mut EntityWorldMut<'_>, ) Applies the after-effects of spawning this bundle. ``` -------------------------------- ### Example Usage of OrientModifier Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/output/struct.OrientModifier.html Demonstrates how to initialize and use OrientModifier within an EffectAsset, setting particle orientation and rotation. ```rust let writer = ExprWriter::new(); let init_rotation = (writer.rand(ScalarType::Float) * writer.lit(std::f32::consts::TAU)).expr(); let init_rotation = SetAttributeModifier::new(Attribute::F32_0, init_rotation); let rotation = writer.attr(Attribute::F32_0).expr(); let lifetime = writer.lit(1.).expr(); let init_lifetime = SetAttributeModifier::new(Attribute::LIFETIME, lifetime); let age = writer.lit(0.).expr(); let init_age = SetAttributeModifier::new(Attribute::AGE, age); let asset = EffectAsset::new(256, SpawnerSettings::default(), writer.finish()) .with_name("orient") .init(init_age) .init(init_lifetime) .init(init_rotation) .render(OrientModifier::new(OrientMode::ParallelCameraDepthPlane).with_rotation(rotation)); ``` -------------------------------- ### Get Value Type Example Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/enum.Value.html Demonstrates how to get the type of a Value variant. Use this to determine if a value is a Scalar, Vector, or Matrix before casting. ```rust let value = graph::Value::Scalar(3_f32.into()); assert_eq!(ValueType::Scalar(ScalarType::Float), value.value_type()); ``` -------------------------------- ### Example: Configuring Debug Captures on Startup Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.DebugSettings.html Configures DebugSettings in a Bevy startup system to capture 2 frames each time a new effect is spawned. ```rust fn startup(mut debug_settings: ResMut) { // Each time a new effect is spawned, capture 2 frames debug_settings.start_capture_on_new_effect = true; debug_settings.capture_frame_count = 2; } ``` -------------------------------- ### starts_active Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.SpawnerSettings.html Gets whether the spawner starts active when the effect is instantiated. This value is transferred to the active state of the EffectSpawner. Inactive spawners do not spawn any particles. ```APIDOC ## starts_active ### Description Get whether the spawner starts active when the effect is instantiated. This value will be transfered to the active state of the `EffectSpawner` once it’s instantiated. Inactive spawners do not spawn any particle. ### Method GET ### Endpoint `/spawner/starts_active` ### Returns - **bool** - Whether the spawner starts active. ``` -------------------------------- ### Create PropertyLayout with Properties Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/properties/struct.PropertyLayout.html Demonstrates creating a PropertyLayout with two properties: one Vec3 and one f32. It also shows how to assert the expected CPU size. ```rust let layout = PropertyLayout::new(&[ Property::new("my_property", Vec3::ZERO), Property::new("other_property", 3.4_f32), ]); assert_eq!(layout.cpu_size(), 16); ``` -------------------------------- ### Using EffectSimulation in a System Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.EffectSimulation.html Demonstrates how to use the EffectSimulation resource within a Bevy system to control effect timing. This includes pausing, unpausing, and setting the relative speed of effects. ```rust fn my_system(mut time: ResMut>) { // Pause the effects time.pause(); // Unpause the effects time.unpause(); // Set the speed to 2.0 time.set_relative_speed(2.0); } ``` -------------------------------- ### Get GPU Alignment of PropertyLayout Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/properties/struct.PropertyLayout.html Retrieves the GPU alignment in bytes for the PropertyLayout, based on WGSL rules. The example asserts the alignment for a layout containing a Vec3 and an f32. ```rust let layout = PropertyLayout::new(&[ Property::new("my_property", Vec3::ZERO), Property::new("other_property", 3.4_f32), ]); assert_eq!(layout.align(), 16); ``` -------------------------------- ### SpawnerSettings::with_emit_on_start Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.SpawnerSettings.html Sets whether the `EffectSpawner` immediately starts emitting particles when the `ParticleEffect` is spawned. If false, the spawner needs to be reset before emitting. ```APIDOC ## SpawnerSettings::with_emit_on_start ### Description Set whether the `EffectSpawner` immediately starts to emit particle when the `ParticleEffect` is spawned into the ECS world. If set to `false`, then `EffectSpawner::has_completed()` will return `true` after spawning the component, and the spawner needs to be `EffectSpawner::reset()` before it can spawn particles. This is useful to spawn a particle effect instance immediately, but only start emitting particles when an event occurs (collision, user input, any other game logic…). Because a spawner repeating forever never completes, this has no effect if `is_forever()` is `true`. To start/stop spawning with those effects, use `EffectSpawner::active` instead. ### Method `with_emit_on_start(self, emit_on_start: bool) -> Self` ``` -------------------------------- ### Gradient::linear Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.Gradient.html Creates a linear gradient between a start and end value. The start value is at ratio 0.0 and the end value is at ratio 1.0. ```APIDOC ## Gradient::linear ### Description Create a linear gradient between two values. The gradient contains the `start` value at key 0.0 and the `end` value at key 1.0. ### Method `fn linear(start: T, end: T) -> Self` ### Example ```rust let g = Gradient::linear(Vec3::ZERO, Vec3::Y); assert_eq!(g.sample(0.3), Vec3::new(0., 0.3, 0.)); ``` ``` -------------------------------- ### Create SpawnerSettings from individual values Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.SpawnerSettings.html Use this raw constructor to create SpawnerSettings. It's generally recommended to use utility constructors like `once()`, `burst()`, or `rate()` for consistent control parameter setup. ```rust let spawner = SpawnerSettings::new(32.0.into(), 3.0.into(), 10.0.into(), 5); ``` -------------------------------- ### Create a linear Gradient Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.Gradient.html Generates a gradient that interpolates linearly between a start and end value. The start value is at ratio 0.0 and the end value is at ratio 1.0. ```rust let g = Gradient::linear(Vec3::ZERO, Vec3::Y); assert_eq!(g.sample(0.3), Vec3::new(0., 0.3, 0.)); ``` -------------------------------- ### SpawnerSettings::count Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.SpawnerSettings.html Gets the number of particles that are spawned in each cycle. ```APIDOC ## SpawnerSettings::count ### Description Get the number of particles that are spawned each cycle. ### Method `count(&self) -> CpuValue` ``` -------------------------------- ### SpawnerSettings::new Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.SpawnerSettings.html Creates new SpawnerSettings from individual values. It's recommended to use utility constructors like `once()`, `burst()`, or `rate()` for consistent parameter settings. ```APIDOC ## SpawnerSettings::new ### Description Create settings from individual values. This is the _raw_ constructor. In general you should prefer using one of the utility constructors `once()`, `burst()`, or `rate()`, which will ensure the control parameters are set consistently relative to each other. ### Method `new(count: CpuValue, spawn_duration: CpuValue, period: CpuValue, cycle_count: u32) -> Self` ### Panics - Panics if `period` can produce a negative number (the sample range lower bound is negative), unless the cycle count is exactly 1, in which case `period` is ignored. - Panics if `period` can only produce 0 (the sample range upper bound is not strictly positive), unless the cycle count is exactly 1, in which case `period` is ignored. - Panics if any value is infinite. ### Example ``` // Spawn 32 particles over 3 seconds, then pause for 7 seconds (10 - 3), doing that 5 times in total. let spawner = SpawnerSettings::new(32.0.into(), 3.0.into(), 10.0.into(), 5); ``` ``` -------------------------------- ### impl Any for T Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.EffectVisibilityClass.html Provides the `type_id` method to get the `TypeId` of an object. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method `type_id` ### Parameters None ### Returns - `TypeId`: The unique identifier for the type of `self`. ``` -------------------------------- ### Box::new_uninit Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/type.BoxedModifier.html Constructs a new box with uninitialized contents on the heap. ```APIDOC ## Box::new_uninit ### Description Constructs a new box with uninitialized contents. ### Method Associated function ### Returns - Box> - A new box with uninitialized contents. ### Example ```rust let mut five = Box::::new_uninit(); // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5) ``` ``` -------------------------------- ### Any for T Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/node/struct.Graph.html Provides the `type_id` method to get the unique identifier of a type. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method `type_id` ### Parameters None ### Returns - `TypeId`: The unique identifier of the type. ``` -------------------------------- ### Create an Empty PropertyLayout Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/properties/struct.PropertyLayout.html Shows how to create an empty PropertyLayout, which is useful as a placeholder when no properties are needed. Asserts that the layout is indeed empty. ```rust let layout = PropertyLayout::empty(); assert!(layout.is_empty()); ``` -------------------------------- ### Get Slot ID Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/node/struct.Slot.html Retrieves the unique SlotId for this slot. ```rust pub fn id(&self) -> SlotId ``` -------------------------------- ### Manually Construct Box from Scratch with System Allocator Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/type.BoxedModifier.html Manually creates a Box from scratch using the system allocator. This involves allocating memory, writing the value, and then constructing the Box. Requires careful handling of memory layout and initialization. ```rust #![feature(allocator_api, slice_ptr_get)] use std::alloc::{Allocator, Layout, System}; unsafe { let ptr = System.allocate(Layout::new::())?.as_mut_ptr() as *mut i32; // In general .write is required to avoid attempting to destruct // the (uninitialized) previous contents of `ptr`, though for this // simple example `*ptr = 5` would have worked as well. ptr.write(5); let x = Box::from_raw_in(ptr, System); } ``` -------------------------------- ### Box::new_uninit_in Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/type.BoxedModifier.html Constructs a new Box with uninitialized contents using the provided allocator. This is an experimental API and requires the 'allocator_api' feature. ```APIDOC ## Box::new_uninit_in ### Description Constructs a new box with uninitialized contents in the provided allocator. ### Method Associated Function ### Parameters - **alloc** (A) - The allocator to use. ### Returns - **Box, A>** - A new Box with uninitialized contents. ### Examples ```rust #![feature(allocator_api)] use std::alloc::System; let mut five = Box::::new_uninit_in(System); // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5) ``` ``` -------------------------------- ### Get ScalarValue type Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/enum.ScalarValue.html Returns the ScalarType associated with the ScalarValue. ```rust pub fn scalar_type(&self) -> ScalarType ``` -------------------------------- ### Manually Create Box from NonNull and Allocator Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/type.BoxedModifier.html Demonstrates manual Box creation from a NonNull pointer obtained via the global allocator. This is a nightly-only experimental API and requires unsafe operations. ```rust #![feature(box_vec_non_null)] use std::alloc::{alloc, Layout}; use std::ptr::NonNull; unsafe { let non_null = NonNull::new(alloc(Layout::new::()).cast::()) .expect("allocation failed"); // In general .write is required to avoid attempting to destruct // the (uninitialized) previous contents of `non_null`. non_null.write(5); let x = Box::from_non_null(non_null); } ``` -------------------------------- ### Get Second Component (y) Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/expr/struct.WriterExpr.html Retrieves the second component of a vector expression. ```rust // A literal expression `v = vec3(1., 1., 1.);`. let v = w.lit(Vec3::ONE); // f = v.y; let f = v.y(); ``` -------------------------------- ### SetAttributeModifier Example Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/attr/struct.SetAttributeModifier.html Demonstrates how to use SetAttributeModifier to set a particle's position on spawn and its velocity each frame using module expressions and properties. ```rust let mut module = Module::default(); // Set the position of the particle to (0,0,0) on spawn. let pos = module.lit(Vec3::ZERO); let init_pos = SetAttributeModifier::new(Attribute::POSITION, pos); // Each frame, assign the value of the "my_velocity" property to the velocity // of the particle. The property is assigned from CPU, and uploaded to GPU // automatically when its value changed. let my_velocity = module.add_property("my_velocity", Vec3::ZERO.into()); let vel = module.prop(my_velocity); let update_vel = SetAttributeModifier::new(Attribute::VELOCITY, vel); ``` -------------------------------- ### Create ParticleLayout with Builder Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/attributes/struct.ParticleLayout.html Use ParticleLayout::new() to get a builder and append attributes. Call build() to finalize the immutable layout. ```rust let layout = ParticleLayout::new() .append(Attribute::POSITION) .append(Attribute::AGE) .append(Attribute::LIFETIME) .build(); ``` -------------------------------- ### Get Modifier Context for AccelModifier Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/accel/struct.AccelModifier.html Retrieves the ModifierContext that this AccelModifier applies to. ```rust fn context(&self) -> ModifierContext ``` -------------------------------- ### Box LocalSpawn Implementation Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/type.BoxedModifier.html Documentation for the LocalSpawn implementation on Box, providing methods for spawning local futures. ```APIDOC ## impl LocalSpawn for Box ### spawn_local_obj Spawns a future that will be run to completion. ### status_local Determines whether the executor is able to spawn new tasks. ``` -------------------------------- ### Get MatrixType of MatrixValue Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/struct.MatrixValue.html Retrieves the MatrixType of the MatrixValue, indicating its dimensions. ```rust assert_eq!(m.matrix_type().cols(), 3); assert_eq!(m.matrix_type().rows(), 2); ``` -------------------------------- ### Create SpawnerSettings for a continuous rate Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.SpawnerSettings.html Use this constructor to spawn particles at a continuous rate per second. Fractional values are accumulated each frame. This configuration repeats indefinitely. ```rust let spawner = SpawnerSettings::rate(10.0.into()); ``` -------------------------------- ### Get Slot Name Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/node/struct.SlotDef.html Retrieves the name of the slot as a string slice. ```rust pub fn name(&self) -> &str ``` -------------------------------- ### Box::try_new_uninit Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/type.BoxedModifier.html Constructs a new box with uninitialized contents on the heap, returning an error if allocation fails. This is a nightly-only experimental API. ```APIDOC ## Box::try_new_uninit ### Description Constructs a new box with uninitialized contents on the heap, returning an error if allocation fails. This is a nightly-only experimental API. ### Method Associated function ### Returns - Result>, AllocError> - A `Result` containing the new box or an allocation error. ### Example ```rust #![feature(allocator_api)] let mut five = Box::::try_new_uninit()?; // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5); ``` ``` -------------------------------- ### Get Property by Name Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/expr/struct.Module.html Retrieves the PropertyHandle for an existing property by its name. ```rust pub fn get_property_by_name(&self, name: &str) -> Option ``` -------------------------------- ### ColorBlendMask Initialization Methods Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/output/struct.ColorBlendMask.html Provides methods to create ColorBlendMask instances from bit values or by setting all bits. ```rust pub const fn empty() -> Self ``` ```rust pub const fn all() -> Self ``` ```rust pub const fn from_bits(bits: u8) -> Option ``` ```rust pub const fn from_bits_truncate(bits: u8) -> Self ``` ```rust pub const fn from_bits_retain(bits: u8) -> Self ``` ```rust pub fn from_name(name: &str) -> Option ``` -------------------------------- ### Manually Create Box from Allocator Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/type.BoxedModifier.html Illustrates manual Box creation using the global allocator. This requires unsafe operations and careful memory management. ```rust use std::alloc::{alloc, Layout}; unsafe { let ptr = alloc(Layout::new::()) as *mut i32; // In general .write is required to avoid attempting to destruct // the (uninitialized) previous contents of `ptr`, though for this // simple example `*ptr = 5` would have worked as well. ptr.write(5); let x = Box::from_raw(ptr); } ``` -------------------------------- ### Get Component Count of VectorType Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/attributes/struct.VectorType.html Returns the number of components in a VectorType. ```rust pub const fn count(&self) -> usize ``` -------------------------------- ### Get Number of Rows Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/attributes/struct.MatrixType.html Returns the number of rows in the matrix type. ```rust pub const fn rows(&self) -> usize ``` -------------------------------- ### Get Number of Columns Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/attributes/struct.MatrixType.html Returns the number of columns in the matrix type. ```rust pub const fn cols(&self) -> usize ``` -------------------------------- ### Box::try_new_uninit_in Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/type.BoxedModifier.html Constructs a new Box with uninitialized contents using the provided allocator, returning an error if the allocation fails. This is an experimental API and requires the 'allocator_api' feature. ```APIDOC ## Box::try_new_uninit_in ### Description Constructs a new box with uninitialized contents in the provided allocator, returning an error if the allocation fails. ### Method Associated Function ### Parameters - **alloc** (A) - The allocator to use. ### Returns - **Result, A>, AllocError>** - A Result containing the new Box or an AllocError if allocation failed. ### Examples ```rust #![feature(allocator_api)] use std::alloc::System; let mut five = Box::::try_new_uninit_in(System)?; // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5); ``` ``` -------------------------------- ### Create a new empty Graph Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/node/struct.Graph.html Initializes a new, empty graph. Remember to add and link nodes to form a valid effect. ```rust let mut graph = Graph::new(); ``` -------------------------------- ### SpawnerSettings::spawn_duration Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.SpawnerSettings.html Gets the duration, in seconds, over which particles are spawned within each cycle. ```APIDOC ## SpawnerSettings::spawn_duration ### Description Get the duration, in seconds, of the spawn part each cycle. ### Method `spawn_duration(&self) -> CpuValue` ``` -------------------------------- ### Create New ExprWriter Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/expr/struct.ExprWriter.html Initializes a new ExprWriter with an internal Module. This is the standard way to begin writing expressions. ```rust let mut w = ExprWriter::new(); ``` -------------------------------- ### GetTupleStructField Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/output/struct.ColorBlendMask.html Provides methods to get references to fields within a tuple struct. ```APIDOC ## fn get_field(&self, index: usize) -> Option<&T> ### Description Returns a reference to the value of the field with index `index`, downcast to `T`. ### Method `get_field` ### Parameters #### Path Parameters - **index** (usize) - Required - The index of the field to retrieve. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (Option<&T>) - **T** (Type) - A reference to the field's value, downcast to type `T`. #### Response Example None ``` ```APIDOC ## fn get_field_mut(&mut self, index: usize) -> Option<&mut T> ### Description Returns a mutable reference to the value of the field with index `index`, downcast to `T`. ### Method `get_field_mut` ### Parameters #### Path Parameters - **index** (usize) - Required - The index of the field to retrieve. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (Option<&mut T>) - **T** (Type) - A mutable reference to the field's value, downcast to type `T`. #### Response Example None ``` -------------------------------- ### Get Fourth Component (w) Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/expr/struct.WriterExpr.html Retrieves the fourth component of a vector expression. ```rust // A literal expression `v = vec3(1., 1., 1.);`. let v = w.lit(Vec3::ONE); // f = v.w; let f = v.w(); ``` -------------------------------- ### Trying to Create an Uninitialized Box with a Specific Allocator Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/type.BoxedModifier.html Attempts to construct a new Box with uninitialized contents using the provided allocator, returning an error if the allocation fails. Deferred initialization is required. This is a nightly-only experimental API. ```rust #![feature(allocator_api)] use std::alloc::System; let mut five = Box::::try_new_uninit_in(System)?; // Deferred initialization: five.write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5); ``` -------------------------------- ### Get Third Component (z) Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/expr/struct.WriterExpr.html Retrieves the third component of a vector expression. ```rust // A literal expression `v = vec3(1., 1., 1.);`. let v = w.lit(Vec3::ONE); // f = v.z; let f = v.z(); ``` -------------------------------- ### Create and Write Literal Expression Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/expr/index.html Demonstrates how to create a literal expression and write it into a `Module` using the `lit` method. ```rust let mut module = Module::default(); // Build and write a literal expression into the module. let expr = module.lit(3.42); ``` -------------------------------- ### Get All Properties Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/expr/struct.Module.html Returns a slice containing all properties currently added to the module. ```rust pub fn properties(&self) -> &[Property] ``` -------------------------------- ### EffectSpawner::new Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.EffectSpawner.html Creates a new EffectSpawner instance with the provided spawner settings. ```APIDOC ## EffectSpawner::new ### Description Create a new spawner. ### Method ``` pub fn new(settings: &SpawnerSettings) -> Self ``` ### Parameters * **settings** (*SpawnerSettings*) - The settings to configure the new spawner. ``` -------------------------------- ### Get Property by Handle Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/expr/struct.Module.html Retrieves an existing property from the module using its PropertyHandle. ```rust pub fn get_property(&self, property: PropertyHandle) -> Option<&Property> ``` -------------------------------- ### Equivalent manual cleanup using Box::from_non_null Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/type.BoxedModifier.html Shows an alternative manual cleanup method that leverages `Box::from_non_null` within a `drop` call, effectively achieving the same result as explicit deallocation but relying on the `Box` destructor for cleanup. ```rust #![feature(box_vec_non_null)] let x = Box::new(String::from("Hello")); let non_null = Box::into_non_null(x); unsafe { drop(Box::from_non_null(non_null)); } ``` -------------------------------- ### SpawnerSettings::once Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.SpawnerSettings.html Creates settings to spawn a burst of particles once. The particles are spawned all at once, and the spawner then idles until manually reset. ```APIDOC ## SpawnerSettings::once ### Description Create settings to spawn a burst of particles once. The burst of particles is spawned all at once in the same frame. After that, the spawner idles, waiting to be manually reset via `EffectSpawner::reset()`. This is a convenience for: ``` SpawnerSettings::new(count, 0.0.into(), 0.0.into(), 1); ``` ### Method `once(count: CpuValue) -> Self` ### Example ``` // Spawn 32 particles in a burst once immediately on creation. let spawner = SpawnerSettings::once(32.0.into()); ``` ``` -------------------------------- ### Get the Value Type of LiteralExpr Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/expr/struct.LiteralExpr.html Retrieves the ValueType associated with the literal expression. ```rust pub fn value_type(&self) -> ValueType ``` -------------------------------- ### try_new_zeroed_in Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/type.BoxedModifier.html Constructs a new Box with uninitialized contents, filling the memory with 0 bytes using the provided allocator. Returns an error if the allocation fails. This is a nightly-only experimental API. ```APIDOC ## try_new_zeroed_in ### Description Constructs a new `Box` with uninitialized contents, with the memory being filled with `0` bytes in the provided allocator, returning an error if the allocation fails. ### Method `pub fn try_new_zeroed_in(alloc: A) -> Result, A>, AllocError>` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **Box, A>** - A new Box with zeroed memory. #### Response Example None ### Notes This is a nightly-only experimental API. (`allocator_api`) ``` -------------------------------- ### Get Element Type of VectorType Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/attributes/struct.VectorType.html Returns the ScalarType of the individual components of a VectorType. ```rust pub const fn elem_type(&self) -> ScalarType ``` -------------------------------- ### Create and Use ExprWriter Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/expr/struct.ExprWriter.html Demonstrates how to create an ExprWriter, define a complex expression involving literals, attributes, and properties, finalize the expression, and use it to initialize a modifier for an EffectAsset. This pattern is useful for building complex visual effects with Bevy Hanabi. ```rust use bevy_hanabi::prelude::*; use bevy::prelude::*; // Create a writer let w = ExprWriter::new(); // Create a new expression: max(5. + particle.position, properties.my_prop) let prop = w.add_property("my_property", Vec3::ONE.into()); let expr = (w.lit(5.) + w.attr(Attribute::POSITION)).max(w.prop(prop)); // Finalize the expression and write it down into the `Module` as an `Expr` let expr: ExprHandle = expr.expr(); // Create a modifier and assign the expression to one of its input(s) let init_modifier = SetAttributeModifier::new(Attribute::LIFETIME, expr); // Create an EffectAsset with the modifier and the Module from the writer let effect = EffectAsset::new(1024, SpawnerSettings::rate(32_f32.into()), w.finish()) .init(init_modifier); ``` -------------------------------- ### Get Property Default Value Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/properties/struct.Property.html Returns the default value of the property, used for initialization. ```rust pub fn default_value(&self) -> &Value ``` -------------------------------- ### impl BundleFromComponents for C Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.EffectVisibilityClass.html Provides a way to create a bundle from components. ```APIDOC ## unsafe fn from_components(ctx: &mut T, func: &mut F) -> C ### Description Creates a bundle from components using a context and a function. ### Method `from_components` ### Parameters - `ctx` (`&mut T`): A mutable reference to the context. - `func` (`&mut F`): A mutable reference to a function that provides components. ### Returns - `C`: The created bundle. ``` -------------------------------- ### Get First Component (x) Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/expr/struct.WriterExpr.html Retrieves the first component of a scalar or vector expression. ```rust // A literal expression `v = vec3(1., 1., 1.);`. let v = w.lit(Vec3::ONE); // f = v.x; let f = v.x(); ``` -------------------------------- ### Box::clone_from_ref Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/type.BoxedModifier.html Allocates memory on the heap then clones a source value into it. This is a nightly-only experimental API. ```APIDOC ## Box::clone_from_ref ### Description Allocates memory on the heap then clones `src` into it. This is a nightly-only experimental API. ### Method Associated function ### Parameters - **src** (&T) - The reference to the value to clone. ### Returns - Box - A new box containing a clone of `src`. ### Example ```rust #![feature(clone_from_ref)] let hello: Box = Box::clone_from_ref("hello"); ``` ### Notes This doesn’t actually allocate if `src` is zero-sized. ``` -------------------------------- ### Clone Implementation for PropertyHandle Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/expr/struct.PropertyHandle.html Demonstrates the `clone` and `clone_from` methods for the PropertyHandle struct, allowing for duplication and copy-assignment. ```rust fn clone(&self) -> PropertyHandle ``` ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### Get Required Attributes for AccelModifier Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/accel/struct.AccelModifier.html Returns the list of particle attributes required for this AccelModifier. ```rust fn attributes(&self) -> &[Attribute] ``` -------------------------------- ### impl Bundle for C Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.EffectVisibilityClass.html Defines how a component can be used as a bundle. ```APIDOC ## fn component_ids( components: &mut ComponentsRegistrator<'_>, ) -> impl Iterator ### Description Returns an iterator over this `Bundle`’s component IDs. ### Method `component_ids` ### Parameters - `components` (`&mut ComponentsRegistrator<'_>`): A mutable reference to the components registrator. ### Returns - `impl Iterator`: An iterator yielding component IDs. ``` ```APIDOC ## fn get_component_ids( components: &Components, ) -> impl Iterator> ### Description Returns a iterator over this `Bundle`’s component ids. This will be `None` if the component has not been registered. ### Method `get_component_ids` ### Parameters - `components` (`&Components`): A reference to the components. ### Returns - `impl Iterator>`: An iterator yielding optional component IDs. ``` -------------------------------- ### Get All Slots for a Node Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/node/struct.Graph.html Retrieves a vector containing all SlotIds associated with a specific node. ```rust let slots = graph.slots(node_id); ``` -------------------------------- ### Get Slot Direction Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/node/struct.Slot.html Returns the SlotDir, indicating whether the slot is an input or output. ```rust pub fn dir(&self) -> SlotDir ``` -------------------------------- ### SpawnerSettings Serialization Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.SpawnerSettings.html Allows SpawnerSettings to be serialized into various formats using the Serde library. ```APIDOC ## SpawnerSettings Serialization ### Description Allows SpawnerSettings to be serialized into various formats using the Serde library. ### Method - `serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>` where `__S: Serializer`: Serialize this value into the given Serde serializer. ``` -------------------------------- ### Get Slot Value Type Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/node/struct.SlotDef.html Retrieves the optional value type associated with the slot. ```rust pub fn value_type(&self) -> Option ``` -------------------------------- ### Box::try_new_zeroed Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/type.BoxedModifier.html Constructs a new box with uninitialized contents, with the memory being filled with `0` bytes on the heap. This is a nightly-only experimental API. ```APIDOC ## Box::try_new_zeroed ### Description Constructs a new `Box` with uninitialized contents, with the memory being filled with `0` bytes on the heap. This is a nightly-only experimental API. ### Method Associated function ### Returns - Result>, AllocError> - A `Result` containing the new box or an allocation error. ### Example ```rust #![feature(allocator_api)] let zero = Box::::try_new_zeroed()?; let zero = unsafe { zero.assume_init() }; assert_eq!(*zero, 0); ``` ``` -------------------------------- ### Get Slot Definition Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/node/struct.Slot.html Returns a reference to the SlotDef, which contains the definition details of the slot. ```rust pub fn def(&self) -> &SlotDef ``` -------------------------------- ### Setting up FlipbookModifier Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/output/struct.FlipbookModifier.html This snippet demonstrates how to create and configure a FlipbookModifier as part of an EffectAsset. It initializes attributes like age and lifetime, updates the sprite index, and sets up the rendering with FlipbookModifier and ParticleTextureModifier. ```rust let mut writer = ExprWriter::new(); let lifetime = writer.lit(5.).expr(); let init_lifetime = SetAttributeModifier::new(Attribute::LIFETIME, lifetime); // Age goes from 0 to LIFETIME=5s let age = writer.lit(0.).expr(); let init_age = SetAttributeModifier::new(Attribute::AGE, age); // sprite_index = i32(particle.age) % 4; let sprite_index = writer .attr(Attribute::AGE) .cast(ScalarType::Int) .rem(writer.lit(4i32)) .expr(); let update_sprite_index = SetAttributeModifier::new(Attribute::SPRITE_INDEX, sprite_index); let texture_slot = writer.lit(0u32).expr(); let asset = EffectAsset::new(32768, SpawnerSettings::once(32.0.into()), writer.finish()) .with_name("flipbook") .init(init_age) .init(init_lifetime) .update(update_sprite_index) .render(ParticleTextureModifier { texture_slot, sample_mapping: ImageSampleMapping::ModulateOpacityFromR, }) .render(FlipbookModifier { sprite_grid_size: UVec2::new(2, 2), // 4 frames }); ``` -------------------------------- ### Get Node ID of Slot Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/node/struct.Slot.html Retrieves the NodeId associated with the node to which this slot belongs. ```rust pub fn node_id(&self) -> NodeId ``` -------------------------------- ### Extension Information Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/type.BoxedModifier.html Methods for prefetching and retrieving information about X11 extensions. ```APIDOC ## prefetch_extension_information ### Description Prefetches information about an extension. ### Method `prefetch_extension_information` ### Parameters - `extension_name`: &'static str - The name of the extension. ### Returns `Result<(), ConnectionError>` - An empty result on success, or a connection error. ## extension_information ### Description Get information about an extension. ### Method `extension_information` ### Parameters - `extension_name`: &'static str - The name of the extension. ### Returns `Result, ConnectionError>` - An optional extension information, or a connection error. ``` -------------------------------- ### sample function Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/enum.CpuValue.html Samples a value from the CpuValue. For `CpuValue::Single`, it returns the constant value. For `CpuValue::Uniform`, it generates a random sample using the provided pseudo-random number generator. ```APIDOC ## pub fn sample(&self, rng: &mut Pcg32) -> T ### Description Sample the value. For `CpuValue::Single`, always return the same single value. For `CpuValue::Uniform`, use the given pseudo-random number generator to generate a random sample. ### Parameters #### Path Parameters - `rng` (Pcg32) - A mutable reference to a pseudo-random number generator. ``` -------------------------------- ### GetTypeRegistration Implementation Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/expr/struct.BuiltInExpr.html Defines how to get the default TypeRegistration for BuiltInExpr and register its type dependencies. ```rust fn get_type_registration() -> TypeRegistration ``` ```rust fn register_type_dependencies(registry: &mut TypeRegistry) ``` -------------------------------- ### Get ScalarValue as bytes Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/enum.ScalarValue.html Retrieves the ScalarValue as a byte slice, suitable for GPU upload. ```rust pub fn as_bytes(&self) -> &[u8] ``` -------------------------------- ### Gradient::sample Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.Gradient.html Samples the gradient at a given ratio. Linearly interpolates between keys if the ratio falls between them. Returns the first key's value for ratios before the first key, and the last key's value for ratios after the last key. Panics if the gradient is empty. ```APIDOC ## Gradient::sample ### Description Sample the gradient at the given ratio. If the ratio is exactly equal to those of one or more keys, sample the first key in the collection. If the ratio falls between two keys, return a linear interpolation of their values. If the ratio is before the first key or after the last one, return the first and last value, respectively. ### Method `fn sample(&self, ratio: f32) -> T` ### Panics This method panics if the gradient is empty (has no key point). ``` -------------------------------- ### RenderContext Methods Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/struct.RenderContext.html Provides methods for creating and configuring a RenderContext. ```APIDOC ## impl<'a> RenderContext<'a> ### `new(property_layout: &'a PropertyLayout, particle_layout: &'a ParticleLayout, texture_layout: &'a TextureLayout) -> Self` Create a new update context. ### `set_needs_uv(&mut self)` Mark the rendering shader as needing UVs. ### `set_needs_normal(&mut self)` Mark the rendering shader as needing normals. ### `set_needs_particle_fragment(&mut self)` Mark the rendering shader as needing particle data in the fragment shader. ### `with_attribute_pointer(self) -> Self` Mark the attribute struct as being available through a pointer. ``` -------------------------------- ### Get &dyn Any from &Trait Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/node/struct.NormalizeNode.html Converts a `&Trait` reference to a `&Any` reference. Necessary for dynamic dispatch involving `Any`. ```rust fn as_any(&self) -> &(dyn Any + 'static) ``` -------------------------------- ### SimulationSpace Core Reflection Methods Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/enum.SimulationSpace.html Core reflection methods for SimulationSpace, enabling conversion to and from `Any` and `Reflect` types. ```APIDOC ## SimulationSpace Core Reflection This section covers the fundamental reflection methods for `SimulationSpace`. ### `into_any()` - **Description**: Returns the `SimulationSpace` value as a `Box`. - **Source**: `fn into_any(self: Box) -> Box` ### `as_any()` - **Description**: Returns the `SimulationSpace` value as a `&dyn Any`. - **Source**: `fn as_any(&self) -> &dyn Any` ### `as_any_mut()` - **Description**: Returns the `SimulationSpace` value as a `&mut dyn Any`. - **Source**: `fn as_any_mut(&mut self) -> &mut dyn Any` ### `into_reflect()` - **Description**: Casts this `SimulationSpace` type to a boxed, fully-reflected value. - **Source**: `fn into_reflect(self: Box) -> Box` ### `as_reflect()` - **Description**: Casts this `SimulationSpace` type to a fully-reflected value. - **Source**: `fn as_reflect(&self) -> &dyn Reflect` ### `as_reflect_mut()` - **Description**: Casts this `SimulationSpace` type to a mutable, fully-reflected value. - **Source**: `fn as_reflect_mut(&mut self) -> &mut dyn Reflect` ### `set()` - **Description**: Performs a type-checked assignment of a reflected value to this `SimulationSpace` value. - **Source**: `fn set(&mut self, value: Box) -> Result<(), Box>` ``` -------------------------------- ### Get One-Based Slot Index Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/node/struct.SlotId.html Retrieves the one-based slot index from a SlotId. Returns a NonZeroU32. ```rust pub fn id(&self) -> NonZeroU32> ``` -------------------------------- ### Manually Construct Box from Scratch with NonNull and System Allocator Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/type.BoxedModifier.html Manually creates a Box from scratch using the system allocator and a NonNull pointer. This involves allocating memory, casting it, writing the value, and then constructing the Box. ```rust #![feature(allocator_api, box_vec_non_null, slice_ptr_get)] use std::alloc::{Allocator, Layout, System}; unsafe { let non_null = System.allocate(Layout::new::())?.cast::(); // In general .write is required to avoid attempting to destruct // the (uninitialized) previous contents of `non_null`. non_null.write(5); let x = Box::from_non_null_in(non_null, System); } ``` -------------------------------- ### Create Attribute Expression Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/expr/struct.ExprWriter.html Creates an expression from a particle attribute. For example, accessing particle position. ```rust let x = w.attr(Attribute::POSITION); ``` -------------------------------- ### Clamp Operator Example Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/expr/enum.TernaryOperator.html Clamps a value to a specified range. Supports vector operands of the same rank. ```rust min(max(x, low), high) ``` -------------------------------- ### Into Implementation Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/expr/struct.BuiltInExpr.html Provides a conversion from one type to another if the target type implements `From`. ```APIDOC #### fn into(self) -> U ### Description Calls `U::from(self)`. That is, this conversion is whatever the implementation of `From for U` chooses to do. ### Method (Implicitly CONVERT-like) ### Endpoint (N/A - SDK method) ### Response #### Success Response - **U** - The converted value of type U. ``` -------------------------------- ### GetPath Trait Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.EffectSimulation.html Provides methods to get references to values within a structure using a reflective path. ```APIDOC ## reflect_path ### Description Returns a reference to the value specified by `path`. ### Method `reflect_path` ### Parameters - `path`: A type implementing `ReflectPath`. ### Returns `Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>` - A reference to the reflected value or an error. ## reflect_path_mut ### Description Returns a mutable reference to the value specified by `path`. ### Method `reflect_path_mut` ### Parameters - `path`: A type implementing `ReflectPath`. ### Returns `Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>` - A mutable reference to the reflected value or an error. ## path ### Description Returns a statically typed reference to the value specified by `path`. ### Method `path` ### Parameters - `path`: A type implementing `ReflectPath`. ### Returns `Result<&T, ReflectPathError<'p>>` - A statically typed reference to the value or an error. ## path_mut ### Description Returns a statically typed mutable reference to the value specified by `path`. ### Method `path_mut` ### Parameters - `path`: A type implementing `ReflectPath`. ### Returns `Result<&mut T, ReflectPathError<'p>>` - A statically typed mutable reference to the value or an error. ``` -------------------------------- ### Create SpawnerSettings for a single burst Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/struct.SpawnerSettings.html Use this constructor to spawn a burst of particles all at once. The spawner will then idle until manually reset. ```rust let spawner = SpawnerSettings::once(32.0.into()); ``` -------------------------------- ### Create New TextureSampleExpr Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/expr/struct.TextureSampleExpr.html Constructor for creating a new texture sample expression. Requires handles for the image and sampling coordinates. ```rust pub fn new(image: ExprHandle, coordinates: ExprHandle) -> Self ``` -------------------------------- ### Box::try_clone_from_ref Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/modifier/type.BoxedModifier.html Allocates memory on the heap then clones a source value into it, returning an error if allocation fails. This is a nightly-only experimental API. ```APIDOC ## Box::try_clone_from_ref ### Description Allocates memory on the heap then clones `src` into it, returning an error if allocation fails. This is a nightly-only experimental API. ### Method Associated function ### Parameters - **src** (&T) - The reference to the value to clone. ### Returns - Result, AllocError> - A `Result` containing the new box or an allocation error. ### Example ```rust #![feature(clone_from_ref)] #![feature(allocator_api)] let hello: Box = Box::try_clone_from_ref("hello")?; ``` ### Notes This doesn’t actually allocate if `src` is zero-sized. ``` -------------------------------- ### Get mutable reference to Matrix Element Source: https://docs.rs/bevy_hanabi/latest/bevy_hanabi/graph/struct.MatrixValue.html Provides a mutable reference to a matrix element, allowing modification. ```rust pub fn value_mut(&mut self, row: usize, col: usize) -> &mut f32 ```