简体   繁体   English

在SpriteKit(或SceneKit)中更新几何

[英]Updating geometry in SpriteKit (or SceneKit)

We are porting a game to SpriteKit and I've run in to a bit of a problem. 我们正在将游戏移植到SpriteKit,我遇到了一个问题。 Some objects in our game have triangle-strip trails attached to them. 我们游戏中的某些对象附有三角形条纹轨迹。 The vertex buffers of the trails are continuously updated as the objects move in the world to create a seamless and flowing effect (there are constraints on how many vertices are in the buffer and how often we emit new vertices). 路径的顶点缓冲区会随着对象在世界中移动而不断更新,以创建无缝流畅的效果(缓冲区中有多少个顶点以及我们发出新顶点的频率受到限制)。

In the previous implementation we simply updated the affected vertices in the corresponding buffer whenever we emitted new vertices. 在以前的实现中,只要我们发出新的顶点,我们就只需在相应的缓冲区中更新受影响的顶点。 In SceneKit it seems I am unable to update geometry sources, unless I use geometrySourceWithBuffer:vertexFormat:semantic:vertexCount:dataOffset:dataStride: . 在SceneKit中,除非我使用geometrySourceWithBuffer:vertexFormat:semantic:vertexCount:dataOffset:dataStride: :,否则似乎无法更新几何源。 To do this however, it seems I need a Metal device, command queue and encoder, to be able to submit commands to update my buffer before it renders. 但是,要执行此操作,似乎我需要一个Metal设备,命令队列和编码器,以便能够提交命令以在渲染缓冲区之前更新我的缓冲区。

Is there any way I can do this with a normal SCNView , or do I have to do everything manually with a CAMetalLayer , creating my own metal device etc? 有什么办法可以使用普通的SCNView来完成此SCNView ,还是必须使用CAMetalLayer手动完成所有操作,创建自己的金属设备等?

In essence, everything we need, bar this trail geometry is available in SpriteKit, so I was hoping there was some way I could get a hold of the metal device and command queue used by the SKView and simply use that to upload my geometry. 从本质上讲,我们需要的所有东西都可以在SpriteKit中使用,但可以在SpriteKit中使用此几何图形,因此我希望可以通过某种方式掌握SKView使用的金属设备和命令队列,并简单地使用它来上传几何图形。 This would make things a lot simpler. 这将使事情变得更简单。

I've used a particle system to get a similar effect. 我使用了粒子系统来获得类似的效果。 The particle emitter is attached to the moving object, with particles set to fade out and eventually die. 粒子发射器附着在运动物体上,粒子设置为淡出并最终死亡。 You might need to set the emitter's targetNode to your scene, depending on the effect you want. 根据您想要的效果,您可能需要将发射器的targetNode设置为场景。

    emitter = SKEmitterNode()
    emitter.name = marbleNodeNames.trail.rawValue
    emitter.particleTexture = SKTexture(imageNamed: "spark")
    emitter.particleAlphaSpeed = -1.0
    emitter.particleLifetime = 2
    emitter.particleScale = 0.2
    marbleSprite.addChild(emitter)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM