Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Initialize and Freeze All Particles

Add the script to Simulation Flow (Ctrl/Cmd + F2) > SimulationPre.

The script freezes a particle volume at the beginning of the simulation (only works with standard particle fluids only):

Code Block
languagepy
# Initialize the emitter by freezing its particles before the simulation starts
# Get the standard particle emitter "Circle01" and its particles
emitter   = scene.get_PB_Emitter("Circle01")
particles = emitter.getParticles()

# Loop through all particles and freeze their motion
for particle in particles:
	particle.freeze()

...

Unfreeze Particles

Add the script to Simulation Flow (Ctrl/Cmd + F2) > FramesPre or StepsPre.

The script unfreezes a particle (only works with standard particle fluids) when an animated object (here: "Sphere01") is 0.75 m or less away from the particle:

Code Block
languagepy
# Get the standard particle emitter "Circle01" and its particles
# Define a "melting" object ("Sphere01") and a threshold
emitter        = scene.get_PB_Emitter("Circle01")
particles      = emitter.getParticles()
unfreezeObject = scene.getObject("Sphere01")

...


distThreshold  = 0.75

# Loop through all particles
for particle in particles:
 
	# Get the distance between the current particle and "Sphere01"
	particlePosition = particle.getPosition()
	objectPosition = unfreezeObject.getParameter("Position")
	particleObjectDistance = particlePosition.distance(objectPosition)
 
	# If the distance is smaller than or equal to "distThreshold" the particle will be released
	if (particleObjectDistance <= 

...

distThreshold):
		particle.unfreeze()