IVSmoke 1.0
Loading...
Searching...
No Matches
AIVSmokeVoxelVolume Class Reference

#include <IVSmokeVoxelVolume.h>

Inheritance diagram for AIVSmokeVoxelVolume:
Inheritance graph
Collaboration diagram for AIVSmokeVoxelVolume:
Collaboration graph

Public Member Functions

virtual void Tick (float DeltaTime) override
 
virtual bool ShouldTickIfViewportsOnly () const override
 
virtual void OnConstruction (const FTransform &Transform) override
 
TObjectPtr< UIVSmokeHoleGeneratorComponentGetHoleGeneratorComponent ()
 
TObjectPtr< UIVSmokeCollisionComponentGetCollisionComponent ()
 
void Initialize ()
 
void StartSimulation ()
 
void StopSimulation (bool bImmediate=false)
 
void ResetSimulation ()
 
FORCEINLINE EIVSmokeVoxelVolumeState GetCurrentState () const
 
bool ShouldRender () const
 
FORCEINLINE const TArray< float > & GetVoxelBirthTimes () const
 
FORCEINLINE const TArray< float > & GetVoxelDeathTimes () const
 
FORCEINLINE FIntVector GetGridResolution () const
 
FORCEINLINE FIntVector GetCenterOffset () const
 
FORCEINLINE float GetVoxelSize () const
 
FORCEINLINE EIVSmokeDirtyLevel GetDirtyLevel () const
 
FORCEINLINE bool IsVoxelDataDirty () const
 
FORCEINLINE void ClearVoxelDataDirty ()
 
FORCEINLINE int32 GetVoxelBufferSize () const
 
FORCEINLINE int32 GetActiveVoxelNum () const
 
FORCEINLINE const UIVSmokeSmokePresetGetSmokePresetOverride () const
 
FORCEINLINE FVector GetVoxelWorldAABBMin () const
 
FORCEINLINE FVector GetVoxelWorldAABBMax () const
 
FORCEINLINE bool IsVoxelActive (int32 Index) const
 
FORCEINLINE bool IsVoxelActive (FIntVector GridPos) const
 
FTextureRHIRef GetHoleTexture () const
 
float GetSyncWorldTimeSeconds () const
 
void StartPreviewSimulation ()
 
void StopPreviewSimulation ()
 

Public Attributes

TObjectPtr< UBillboardComponent > BillboardComponent
 
FIntVector VolumeExtent = FIntVector(16, 16, 16)
 
FVector Radii = FVector(1.0f, 1.0f, 1.0f)
 
float VoxelSize = 50.0f
 
int32 MaxVoxelNum = 1000
 
bool bAutoStart = false
 
bool bDestroyOnFinish = false
 
bool bIsInfinite = false
 
TObjectPtr< UIVSmokeSmokePresetSmokePresetOverride
 
float ExpansionDuration = 3.0f
 
float SustainDuration = 5.0f
 
float DissipationDuration = 2.0f
 
float FadeInDuration = 2.0f
 
float FadeOutDuration = 2.0f
 
float ExpansionNoise = 100.0f
 
float DissipationNoise = 100.0f
 
TObjectPtr< UCurveFloat > ExpansionCurve
 
TObjectPtr< UCurveFloat > DissipationCurve
 
bool bEnableSimulationCollision = true
 
TEnumAsByte< ECollisionChannel > VoxelCollisionChannel = ECC_WorldStatic
 
FIVSmokeDebugSettings DebugSettings
 
TObjectPtr< UStaticMesh > DebugVoxelMesh
 
TObjectPtr< UMaterialInterface > DebugVoxelMaterial
 

Protected Member Functions

virtual void BeginPlay () override
 
virtual void EndPlay (const EEndPlayReason::Type EndPlayReason) override
 
virtual void GetLifetimeReplicatedProps (TArray< FLifetimeProperty > &OutLifetimeProps) const override
 

Detailed Description

The core volumetric actor that simulates dynamic smoke expansion using a deterministic voxel-based flood-fill algorithm.

Overview

This actor generates a 3D grid of voxels that expand outward from the center, navigating around obstacles defined by the collision settings. The simulation is deterministic, ensuring the same shape and timing across both Server and Clients without replicating individual voxel data.

Simulation Lifecycle

The simulation state machine progresses based on the sum of duration and fade settings:

  1. Idle: Initial state.
  2. Expansion: Spawns voxels. Ends after ExpansionDuration + FadeInDuration.
  3. Sustain: Maintains the shape. Ends after SustainDuration.
  4. Dissipation: Removes voxels. Ends after DissipationDuration + FadeOutDuration.
  5. Finished: Simulation complete.

Network & Execution

The simulation logic executes deterministically on both the Server and Client.

  • The Server manages the authoritative state (State, Seed, StartTime) and replicates it to Clients.
  • Clients execute the exact same flood-fill algorithm locally based on the replicated Seed and Time.

Definition at line 167 of file IVSmokeVoxelVolume.h.

Constructor & Destructor Documentation

◆ AIVSmokeVoxelVolume()

AIVSmokeVoxelVolume::AIVSmokeVoxelVolume ( )

Definition at line 140 of file IVSmokeVoxelVolume.cpp.

Member Function Documentation

◆ BeginPlay()

void AIVSmokeVoxelVolume::BeginPlay ( )
overrideprotectedvirtual

Definition at line 171 of file IVSmokeVoxelVolume.cpp.

◆ ClearVoxelDataDirty()

FORCEINLINE void AIVSmokeVoxelVolume::ClearVoxelDataDirty ( )
inline

Marks the voxel data as clean after a successful GPU upload.

Note
Should only be called by the IVSmokeRenderer.

Definition at line 680 of file IVSmokeVoxelVolume.h.

◆ EndPlay()

void AIVSmokeVoxelVolume::EndPlay ( const EEndPlayReason::Type  EndPlayReason)
overrideprotectedvirtual

Definition at line 203 of file IVSmokeVoxelVolume.cpp.

◆ GetActiveVoxelNum()

FORCEINLINE int32 AIVSmokeVoxelVolume::GetActiveVoxelNum ( ) const
inline

Returns the number of active (non-zero density) voxels.

Definition at line 686 of file IVSmokeVoxelVolume.h.

◆ GetCenterOffset()

FORCEINLINE FIntVector AIVSmokeVoxelVolume::GetCenterOffset ( ) const
inline

Returns the center offset for grid-to-local coordinate conversion.

Definition at line 665 of file IVSmokeVoxelVolume.h.

◆ GetCollisionComponent()

TObjectPtr< UIVSmokeCollisionComponent > AIVSmokeVoxelVolume::GetCollisionComponent ( )

Returns the component responsible for handling physical interactions and collision queries. Caches the result to avoid repeated lookups. Returns nullptr if the component is missing.

Definition at line 1229 of file IVSmokeVoxelVolume.cpp.

◆ GetCurrentState()

FORCEINLINE EIVSmokeVoxelVolumeState AIVSmokeVoxelVolume::GetCurrentState ( ) const
inline

Returns the current phase of the simulation state machine.

Definition at line 640 of file IVSmokeVoxelVolume.h.

◆ GetDirtyLevel()

FORCEINLINE EIVSmokeDirtyLevel AIVSmokeVoxelVolume::GetDirtyLevel ( ) const
inline

Returns the current dirty level for GPU buffer synchronization.

Definition at line 671 of file IVSmokeVoxelVolume.h.

◆ GetGridResolution()

FORCEINLINE FIntVector AIVSmokeVoxelVolume::GetGridResolution ( ) const
inline

Returns the grid resolution (dimensions of the voxel grid).

Definition at line 655 of file IVSmokeVoxelVolume.h.

◆ GetHoleGeneratorComponent()

TObjectPtr< UIVSmokeHoleGeneratorComponent > AIVSmokeVoxelVolume::GetHoleGeneratorComponent ( )

Returns the component responsible for generating holes (negative space) in the smoke. Caches the result to avoid repeated lookups. Returns nullptr if the component is missing.

Definition at line 1219 of file IVSmokeVoxelVolume.cpp.

◆ GetHoleTexture()

FTextureRHIRef AIVSmokeVoxelVolume::GetHoleTexture ( ) const

Returns the RHI texture resource from the HoleGeneratorComponent, if available.

Definition at line 1239 of file IVSmokeVoxelVolume.cpp.

◆ GetLifetimeReplicatedProps()

void AIVSmokeVoxelVolume::GetLifetimeReplicatedProps ( TArray< FLifetimeProperty > &  OutLifetimeProps) const
overrideprotectedvirtual

Definition at line 211 of file IVSmokeVoxelVolume.cpp.

◆ GetSmokePresetOverride()

FORCEINLINE const UIVSmokeSmokePreset * AIVSmokeVoxelVolume::GetSmokePresetOverride ( ) const
inline

Returns the smoke preset override for this volume, or nullptr to use default.

Definition at line 689 of file IVSmokeVoxelVolume.h.

◆ GetSyncWorldTimeSeconds()

float AIVSmokeVoxelVolume::GetSyncWorldTimeSeconds ( ) const

Returns the synchronized world time in seconds. Handles network time offsets to ensure clients see the simulation at the same progress as the server.

Definition at line 1248 of file IVSmokeVoxelVolume.cpp.

◆ GetVoxelBirthTimes()

FORCEINLINE const TArray< float > & AIVSmokeVoxelVolume::GetVoxelBirthTimes ( ) const
inline

Returns the raw array of timestamps indicating when each voxel was created (Server Time).

Definition at line 649 of file IVSmokeVoxelVolume.h.

◆ GetVoxelBufferSize()

FORCEINLINE int32 AIVSmokeVoxelVolume::GetVoxelBufferSize ( ) const
inline

Returns the current buffer size (for detecting resize).

Definition at line 683 of file IVSmokeVoxelVolume.h.

◆ GetVoxelDeathTimes()

FORCEINLINE const TArray< float > & AIVSmokeVoxelVolume::GetVoxelDeathTimes ( ) const
inline

Returns the raw array of timestamps indicating when each voxel was removed (Server Time).

Definition at line 652 of file IVSmokeVoxelVolume.h.

◆ GetVoxelSize()

FORCEINLINE float AIVSmokeVoxelVolume::GetVoxelSize ( ) const
inline

Returns the world-space size of each voxel.

Definition at line 668 of file IVSmokeVoxelVolume.h.

◆ GetVoxelWorldAABBMax()

FORCEINLINE FVector AIVSmokeVoxelVolume::GetVoxelWorldAABBMax ( ) const
inline

Returns the AABBMax of voxels.

Definition at line 695 of file IVSmokeVoxelVolume.h.

◆ GetVoxelWorldAABBMin()

FORCEINLINE FVector AIVSmokeVoxelVolume::GetVoxelWorldAABBMin ( ) const
inline

Returns the AABBMin of voxels.

Definition at line 692 of file IVSmokeVoxelVolume.h.

◆ Initialize()

void AIVSmokeVoxelVolume::Initialize ( )

Allocates memory for the voxel grid based on VolumeExtent. Automatically called on BeginPlay. Can be called manually to resize the grid at runtime,

Definition at line 386 of file IVSmokeVoxelVolume.cpp.

◆ IsVoxelActive() [1/2]

FORCEINLINE bool AIVSmokeVoxelVolume::IsVoxelActive ( FIntVector  GridPos) const
inline

Checks if a voxel at the given grid coordinate is currently active.

Parameters
GridPos3D grid coordinate of the voxel.
Returns
True if the voxel is active.

Definition at line 715 of file IVSmokeVoxelVolume.h.

◆ IsVoxelActive() [2/2]

FORCEINLINE bool AIVSmokeVoxelVolume::IsVoxelActive ( int32  Index) const
inline

Checks if a voxel at the given linear index is currently active.

Parameters
IndexLinear index of the voxel.
Returns
True if the voxel is active (bit set).

Definition at line 703 of file IVSmokeVoxelVolume.h.

◆ IsVoxelDataDirty()

FORCEINLINE bool AIVSmokeVoxelVolume::IsVoxelDataDirty ( ) const
inline

Returns true if voxel data has been modified since last GPU upload.

Definition at line 674 of file IVSmokeVoxelVolume.h.

◆ OnConstruction()

void AIVSmokeVoxelVolume::OnConstruction ( const FTransform &  Transform)
overridevirtual

Definition at line 278 of file IVSmokeVoxelVolume.cpp.

◆ ResetSimulation()

void AIVSmokeVoxelVolume::ResetSimulation ( )

Resets the simulation state to Idle and clears all voxel data. (Server Only) Increments the Generation counter to force all clients to reset and resync.

◆ ShouldRender()

bool AIVSmokeVoxelVolume::ShouldRender ( ) const

Returns true if this volume should be rendered. Used by SceneViewExtension to filter active volumes without explicit registration.

Definition at line 1173 of file IVSmokeVoxelVolume.cpp.

◆ ShouldTickIfViewportsOnly()

bool AIVSmokeVoxelVolume::ShouldTickIfViewportsOnly ( ) const
overridevirtual

Definition at line 269 of file IVSmokeVoxelVolume.cpp.

◆ StartPreviewSimulation()

void AIVSmokeVoxelVolume::StartPreviewSimulation ( )

Runs a preview of the simulation directly in the Editor viewport without starting a Play In Editor (PIE) session. Use this to quickly iterate on parameters like ExpansionDuration, Noise, and Curves.

Note
This resets the current simulation state.

Definition at line 1273 of file IVSmokeVoxelVolume.cpp.

◆ StartSimulation()

void AIVSmokeVoxelVolume::StartSimulation ( )

Begins the simulation. (Server Only) Sets the state to Expansion and synchronizes the start time and random seed to clients. Has no effect if the simulation is already running.

◆ StopPreviewSimulation()

void AIVSmokeVoxelVolume::StopPreviewSimulation ( )

Stops the current editor preview simulation and clears all generated voxel data. Returns the actor to an Idle state.

Definition at line 1287 of file IVSmokeVoxelVolume.cpp.

◆ StopSimulation()

void AIVSmokeVoxelVolume::StopSimulation ( bool  bImmediate = false)

Stops the simulation and triggers the dissipation phase. (Server Only)

Parameters
bImmediateIf true, skips the dissipation phase and instantly transitions to Finished, clearing all voxels.

◆ Tick()

void AIVSmokeVoxelVolume::Tick ( float  DeltaTime)
overridevirtual

Definition at line 218 of file IVSmokeVoxelVolume.cpp.

Member Data Documentation

◆ bAutoStart

bool AIVSmokeVoxelVolume::bAutoStart = false

If true, the simulation starts automatically on BeginPlay.

Definition at line 283 of file IVSmokeVoxelVolume.h.

◆ bDestroyOnFinish

bool AIVSmokeVoxelVolume::bDestroyOnFinish = false

If true, the actor is automatically destroyed when the simulation reaches the Finished state.

Definition at line 287 of file IVSmokeVoxelVolume.h.

◆ bEnableSimulationCollision

bool AIVSmokeVoxelVolume::bEnableSimulationCollision = true

If true, voxels perform collision checks against the world before spawning. Disable this to allow smoke to pass through walls, significantly reducing CPU cost.

Definition at line 407 of file IVSmokeVoxelVolume.h.

◆ BillboardComponent

TObjectPtr<UBillboardComponent> AIVSmokeVoxelVolume::BillboardComponent

Editor visualization sprite. Used as the RootComponent.

Definition at line 216 of file IVSmokeVoxelVolume.h.

◆ bIsInfinite

bool AIVSmokeVoxelVolume::bIsInfinite = false

If true, the smoke stays in the Sustain phase indefinitely.

Definition at line 291 of file IVSmokeVoxelVolume.h.

◆ DebugSettings

FIVSmokeDebugSettings AIVSmokeVoxelVolume::DebugSettings

Configuration settings for visual debugging tools.

Definition at line 758 of file IVSmokeVoxelVolume.h.

◆ DebugVoxelMaterial

TObjectPtr<UMaterialInterface> AIVSmokeVoxelVolume::DebugVoxelMaterial

Optional material to apply to the debug voxel mesh.

Definition at line 766 of file IVSmokeVoxelVolume.h.

◆ DebugVoxelMesh

TObjectPtr<UStaticMesh> AIVSmokeVoxelVolume::DebugVoxelMesh

Optional static mesh to use for voxel visualization when bShowVoxelMesh is enabled in settings.

Definition at line 762 of file IVSmokeVoxelVolume.h.

◆ DissipationCurve

TObjectPtr<UCurveFloat> AIVSmokeVoxelVolume::DissipationCurve

Defines the normalized rate of voxel survival over DissipationDuration.

  • X-axis (Time): 0.0 to 1.0 (Normalized Duration)
  • Y-axis (Value): 1.0 to 0.0 (Fraction of voxels remaining)
    Note
    The curve should be monotonically decreasing (start at 1.0, end at 0.0).

Definition at line 400 of file IVSmokeVoxelVolume.h.

◆ DissipationDuration

float AIVSmokeVoxelVolume::DissipationDuration = 2.0f

The duration (in seconds) of the voxel removal phase. The actual Dissipation state lasts for DissipationDuration + FadeOutDuration.

Definition at line 356 of file IVSmokeVoxelVolume.h.

◆ DissipationNoise

float AIVSmokeVoxelVolume::DissipationNoise = 100.0f

Randomness added to the voxel removal order. Higher values cause the smoke to break apart more randomly during dissipation.

Definition at line 382 of file IVSmokeVoxelVolume.h.

◆ ExpansionCurve

TObjectPtr<UCurveFloat> AIVSmokeVoxelVolume::ExpansionCurve

Defines the normalized rate of voxel spawning over ExpansionDuration.

  • X-axis (Time): 0.0 to 1.0 (Normalized Duration)
  • Y-axis (Value): 0.0 to 1.0 (Fraction of MaxVoxelNum to spawn)
    Note
    The curve should be monotonically increasing.

Definition at line 391 of file IVSmokeVoxelVolume.h.

◆ ExpansionDuration

float AIVSmokeVoxelVolume::ExpansionDuration = 3.0f

The duration (in seconds) of the active expansion phase where voxels are spawned. The actual Expansion state lasts for ExpansionDuration + FadeInDuration.

Definition at line 342 of file IVSmokeVoxelVolume.h.

◆ ExpansionNoise

float AIVSmokeVoxelVolume::ExpansionNoise = 100.0f

Randomness added to the flood-fill pathfinding cost. Higher values create more irregular, jagged shapes instead of a perfect sphere.

Definition at line 375 of file IVSmokeVoxelVolume.h.

◆ FadeInDuration

float AIVSmokeVoxelVolume::FadeInDuration = 2.0f

Additional time added to the Expansion phase to allow for opacity fade-in.

Definition at line 362 of file IVSmokeVoxelVolume.h.

◆ FadeOutDuration

float AIVSmokeVoxelVolume::FadeOutDuration = 2.0f

Additional time added to the Dissipation phase to allow for opacity fade-out.

Definition at line 368 of file IVSmokeVoxelVolume.h.

◆ MaxVoxelNum

int32 AIVSmokeVoxelVolume::MaxVoxelNum = 1000

The hard limit on the number of active voxels. Simulation will stop spawning new voxels once this limit is reached. Use this to guarantee a fixed performance budget for this actor.

Definition at line 279 of file IVSmokeVoxelVolume.h.

◆ Radii

FVector AIVSmokeVoxelVolume::Radii = FVector(1.0f, 1.0f, 1.0f)

Defines the relative aspect ratio of the smoke's expansion shape per axis. These values act as ratios, not absolute units.

  • Example: (1.0, 1.0, 1.0) creates a spherical shape.
  • Example: (2.0, 1.0, 1.0) creates an ellipsoid that stretches twice as far along the X-axis.

Definition at line 263 of file IVSmokeVoxelVolume.h.

◆ SmokePresetOverride

TObjectPtr<UIVSmokeSmokePreset> AIVSmokeVoxelVolume::SmokePresetOverride

Optional Data Asset to override visual properties such as Smoke Color, Absorption, and Density. If set, the visual settings in this preset take precedence over the actor's local settings.

See also
UIVSmokeSmokePreset

Definition at line 299 of file IVSmokeVoxelVolume.h.

◆ SustainDuration

float AIVSmokeVoxelVolume::SustainDuration = 5.0f

The duration (in seconds) the smoke maintains its shape after expansion. Ignored if bIsInfinite is true.

Definition at line 349 of file IVSmokeVoxelVolume.h.

◆ VolumeExtent

FIntVector AIVSmokeVoxelVolume::VolumeExtent = FIntVector(16, 16, 16)

Half-size of the voxel grid in index units. The actual grid resolution will be (Extent * 2) - 1 per axis.

Note
Increasing this value exponentially increases memory usage. Keep it as low as possible.

Definition at line 254 of file IVSmokeVoxelVolume.h.

◆ VoxelCollisionChannel

TEnumAsByte<ECollisionChannel> AIVSmokeVoxelVolume::VoxelCollisionChannel = ECC_WorldStatic

The collision channel used for obstacle detection during expansion.

Definition at line 411 of file IVSmokeVoxelVolume.h.

◆ VoxelSize

float AIVSmokeVoxelVolume::VoxelSize = 50.0f

World space size of a single voxel in centimeters.

Note
Larger values cover more area with the same performance cost but reduce visual detail. Smaller values require more voxels (higher VolumeExtent or MaxVoxelNum) to cover the same area.

Definition at line 271 of file IVSmokeVoxelVolume.h.


The documentation for this class was generated from the following files: