SCNParticleSystem 仅在几何中

SCNParticleSystem only in Geometry

我只想将粒子系统 rain(来自 X-Code 的模板)添加到几何体(立方体、管状体、圆柱体等)

粒子系统应该只在该几何体中可见。到目前为止我做了什么:

let tube = SCNCylinder(radius: 0.5, height: 2)
tube.firstMaterial?.diffuse.contents = UIColor.white
tube.firstMaterial?.transparency = 0.4
let nodeTube = SCNNode(geometry: tube)
nodeTube.position = SCNVector3(0, 0, -3)

let particleSystem = SCNParticleSystem(named: "FloatingParticleSystem", inDirectory: nil)
particleSystem?.emitterShape = tube
particleSystem?.birthLocation = .volume

nodeTube.addParticleSystem(particleSystem!)
nodeTube.addChildNode(nodeTube)

sceneView.scene.rootNode.addChildNode(nodeTube)

我认为您必须试验实际“ParticleSystem”文件本身的设置,例如出生率等,以使其“适合”几何范围内。

说到这里,我尝试了这些调整,它似乎在一定程度上起作用(无论如何在雨天)。这可能不是您想要的,但我认为它应该为您指明正确的方向:

particleSystem?.isAffectedByGravity = false
particleSystem?.birthLocation = .surface

希望这对您有所帮助...

好的,现在我有一个解决方法:

    let tube = SCNCylinder(radius: 0.5, height: 2)
    tube.firstMaterial?.diffuse.contents = UIColor.white
    tube.firstMaterial?.transparency = 0.4
    let nodeTube = SCNNode(geometry: tube)
    nodeTube.position = SCNVector3(0, 0, -3)
    let bottom = SCNCylinder(radius: 0.6, height: 0.1)
    bottom.firstMaterial?.diffuse.contents = UIColor.red
    let bottomNode = SCNNode(geometry: bottom)
    bottomNode.position = SCNVector3(0, -1, 0)
    nodeTube.addChildNode(bottomNode)


    let particleSystem = SCNParticleSystem(named: "FloatingParticleSystem", inDirectory: nil)
    particleSystem?.birthRate = 100
    particleSystem?.acceleration = SCNVector3(0, 1, 0)
    particleSystem?.emitterShape = tube
    particleSystem?.isAffectedByGravity = false
    particleSystem?.birthLocation = .surface
    particleSystem?.colliderNodes = [bottomNode]
    particleSystem?.particleDiesOnCollision = true

如果有人有更好的解决方案,请在此处post。