Setting gravity for SceneKit ParticleEngine particles

我与影子孤独终老i 提交于 2021-02-11 12:47:28

问题


I'm just experimenting with SceneKit as a continuing migration through methods of 3D rendering. I have played with SceneKit and it is generally as advertised. One troublesome aspect (for me) is that while I can create ParticleEngines via the UI or code, I can't figure out how to set the gravitational field for particles created via code.

The working code is here: https://github.com/rkwright/ParticleTest. Works with XCode 12.3 and iOS 15.3

Here is the function that sets up the ParticleEngine via code.

func createTrailCode( color: UIColor ) -> SCNParticleSystem {

    let particleSystem = SCNParticleSystem()
    particleSystem.birthRate = 5000
    particleSystem.particleLifeSpan = 1
    particleSystem.warmupDuration = 1
    particleSystem.emissionDuration = 500.0
    particleSystem.loops = false
    particleSystem.particleColor = color
    particleSystem.particleSize = 0.25
    particleSystem.birthDirection = .random
    particleSystem.speedFactor = 7
    particleSystem.emittingDirection = SCNVector3(0,1,1)
    particleSystem.emitterShape = .some(SCNSphere(radius: 2.0))
    particleSystem.spreadingAngle = 30
    particleSystem.particleImage = "star"
    particleSystem.isAffectedByGravity = true
    particleSystem.acceleration = SCNVector3(0.0,-1.8,0.0)
    
    return particleSystem

If you run the demo you'll see the ParticleEngine created from the scnp file works fine and the particles slowly drop as they are pulled by gravity. But for the engine created with code (above) the particles immediately zoom off the scene, no matter what the gravity or acceleraton is set to.

Still poking at this, but any suggestions would be appreciated. TIA

来源:https://stackoverflow.com/questions/65833809/setting-gravity-for-scenekit-particleengine-particles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!