Search code examples
scenekitparticle-system

SceneKit: stop animation of particle system


I am using a SCNPArticleSystem to create a haze around an object. Once the haze has been created, I don't want it it change further.

I'm noticing that the particle system animation is continuing after the emissionDuration has been reached. This causes the app to use a lot of CPU.

Is there a way to freeze the particle system as it exists after the emissionDuration and not have any further animation hit?

I have tried calling:

particleSyste.removeAllAnimations()

But that doesn't help. Here is how I set up the particle system

    let particleSystem = SCNParticleSystem()

    particleSystem.particleImage = UIImage(named: "smoke")
    particleSystem.particleColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.005)
    particleSystem.birthRate = 10000;
    particleSystem.birthDirection = .random
    particleSystem.birthLocation = .volume
    particleSystem.particleLifeSpan = CGFloat.greatestFiniteMagnitude
    particleSystem.particleSize = 2
    particleSystem.particleSizeVariation = 0.2
    particleSystem.particleAngleVariation = 360
    particleSystem.blendMode = .additive
    particleSystem.orientationMode = .free
    particleSystem.emissionDuration = 1
    particleSystem.loops = false
    particleSystem.warmupDuration = 2
    particleSystem.isLocal = true
    particleSystem.stretchFactor = 1.5

    let particleSystemGeometry = SCNCylinder(radius: 0.85 * GAL_IMAGE_WIDTH_IN_LIGHT_YEARS * sceneScale / 2, height: 100 * sceneScale)
    particleSystem.emitterShape = particleSystemGeometry
    particleSystemNode = SCNNode(geometry: particleSystemGeometry)
    particleSystemNode.addParticleSystem(particleSystem)
    particleSystemNode.pivot = SCNMatrix4MakeRotation(Float.pi / 2, 1, 0, 0)
    particleSystemNode.name = "ParticleNode"

    scene.rootNode.addChildNode(particleSystemNode)

I would appreciate any suggestions.


Solution

  • I did finally contact Apple DTS about this issue. They confirmed that there is no way to prevent this. When you add a particle system to the Scene, it turns on continuous rendering. They suggested submitting a bug on it (which I will).