SubEmitter

Struct SubEmitter 

Source
pub struct SubEmitter {
    pub parent_type: u32,
    pub child_type: u32,
    pub count: u32,
    pub speed_min: f32,
    pub speed_max: f32,
    pub spread: f32,
    pub inherit_velocity: f32,
    pub child_lifetime: Option<f32>,
    pub child_color: Option<Vec3>,
    pub spawn_radius: f32,
    pub trigger: SpawnTrigger,
}
Expand description

Configuration for a sub-emitter that spawns children when triggered.

§Example

SubEmitter::new(ParentType, ChildType)
    .count(20)                    // Spawn 20 children per death
    .speed(1.0..2.0)              // Random speed in range
    .spread(PI / 4.0)             // 45-degree cone
    .inherit_velocity(0.5)        // 50% of parent velocity
    .child_lifetime(1.5)          // Children live 1.5 seconds
    .child_color(Vec3::new(1.0, 0.5, 0.0))  // Orange children

Fields§

§parent_type: u32

Parent particle type that triggers sub-emission.

§child_type: u32

Child particle type to spawn.

§count: u32

Number of children to spawn per trigger event.

§speed_min: f32

Speed range for children (random within range).

§speed_max: f32§spread: f32

Spread angle in radians (0 = laser, PI = hemisphere, TAU = full sphere).

§inherit_velocity: f32

How much of parent’s velocity children inherit (0.0 - 1.0).

§child_lifetime: Option<f32>

Optional fixed lifetime for children (overrides any lifecycle rules).

§child_color: Option<Vec3>

Optional fixed color for children.

§spawn_radius: f32

Spawn radius around parent position.

§trigger: SpawnTrigger

What triggers this sub-emitter (death, condition, etc.).

Implementations§

Source§

impl SubEmitter

Source

pub fn new(parent_type: u32, child_type: u32) -> Self

Create a new sub-emitter configuration.

By default, triggers on parent death. Use .on_condition() to trigger on a custom WGSL condition instead.

§Arguments
  • parent_type - Type of particle that triggers sub-emission
  • child_type - Type of particle to spawn as children
§Example
// Classic death-triggered spawning (fireworks)
SubEmitter::new(Firework::Rocket.into(), Firework::Spark.into())

// Condition-triggered spawning (cell division)
SubEmitter::new(Cell::Parent.into(), Cell::Child.into())
    .on_condition("p.energy > 1.5")
    .count(2)
Source

pub fn on_condition(self, condition: impl Into<String>) -> Self

Set the trigger to a custom WGSL condition.

The condition is a WGSL boolean expression with access to:

  • p - The current particle
  • uniforms.time - Total elapsed time
  • uniforms.delta_time - Frame delta time

When the condition evaluates to true, spawn events are recorded and children are spawned in a secondary pass.

§Example
// Spawn when energy exceeds threshold
SubEmitter::new(Parent, Child)
    .on_condition("p.energy > 0.9")
    .count(3)

// Periodic spawning (approximately every second)
SubEmitter::new(Parent, Child)
    .on_condition("fract(p.age) < uniforms.delta_time")
    .count(1)

// Spawn near the origin
SubEmitter::new(Parent, Child)
    .on_condition("length(p.position) < 0.2")
    .count(2)
Source

pub fn trigger(self, trigger: SpawnTrigger) -> Self

Set the trigger type explicitly.

§Example
SubEmitter::new(Parent, Child)
    .trigger(SpawnTrigger::OnDeath)
Source

pub fn count(self, n: u32) -> Self

Set the number of children to spawn per parent death.

§Example
SubEmitter::new(Rocket, Spark).count(50)
Source

pub fn speed(self, range: Range<f32>) -> Self

Set the speed range for children.

Children will have a random speed within this range.

§Example
SubEmitter::new(Rocket, Spark).speed(1.0..3.0)
Source

pub fn spread(self, radians: f32) -> Self

Set the spread angle in radians.

  • 0 = All children move in same direction (laser)
  • PI/4 = 45-degree cone
  • PI/2 = 90-degree cone (hemisphere)
  • PI = Full hemisphere
  • TAU = Full sphere (all directions)
§Example
SubEmitter::new(Rocket, Spark).spread(std::f32::consts::PI)
Source

pub fn inherit_velocity(self, factor: f32) -> Self

Set how much of parent’s velocity children inherit.

  • 0.0 = Children ignore parent velocity
  • 0.5 = Children inherit half of parent velocity
  • 1.0 = Children inherit full parent velocity
§Example
SubEmitter::new(Rocket, Spark).inherit_velocity(0.5)
Source

pub fn child_lifetime(self, seconds: f32) -> Self

Set a fixed lifetime for children.

This overrides any Rule::Lifetime for child particles. If not set, children follow normal lifecycle rules.

§Example
SubEmitter::new(Rocket, Spark).child_lifetime(1.5)
Source

pub fn child_color(self, color: Vec3) -> Self

Set a fixed color for children.

If not set, children inherit parent’s color.

§Example
SubEmitter::new(Rocket, Spark).child_color(Vec3::new(1.0, 0.8, 0.0))
Source

pub fn spawn_radius(self, radius: f32) -> Self

Set spawn radius around parent position.

Children spawn at random positions within this radius of the parent.

§Example
SubEmitter::new(Rocket, Spark).spawn_radius(0.1)

Trait Implementations§

Source§

impl Clone for SubEmitter

Source§

fn clone(&self) -> SubEmitter

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SubEmitter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,