SCNParticleSystem仅在几何中

时间:2018-03-06 11:41:17

标签: ios swift scenekit arkit

我想将粒子系统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)

2 个答案:

答案 0 :(得分:1)

我认为你必须在实际的'ParticleSystem'文件中试验设置,例如出生率等,以使其“适应”在几何的范围内。

说了这些之后,我尝试了这些调整,它似乎在某种程度上起作用(无论如何都在Rain'上)。它可能不完全是您的追求,但我认为它应该指向正确的方向:

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

希望这可以帮助你...

答案 1 :(得分:1)

好了,我现在得到了一个解决方法:

    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

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