在SceneKit中检测触摸 [英] Detecting touch in SceneKit

查看:42
本文介绍了在SceneKit中检测触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于在SceneKit中检测触摸的问题.我已经能够找到有关如何检测何时触摸了某个物体的问题,但是我需要一些更具体的信息.我需要能够分辨出何时触摸了对象的某个部分.为了更好地解释,我有一个3D模型的人,我需要能够说出何时触摸了头部或触摸了腿等.如果需要进一步的说明,我很乐意提供.我只是不太确定如何做到这一点.

I have a question that about detecting touch in SceneKit. I have been able to find questions about how to detect when a certain object is touched but I need something a bit more specific. I need to be able to tell when a certain part of an object is touched. To explain a little better, I have a 3d model of a human and I need to be able to tell when say the head is touched or the leg is touched etc. If any further clarification is needed I would be glad to provide it, I'm just not quite sure how to accomplish this.

推荐答案

扩展NicoS的答案:

To expand on NicoS's answer: hit testing is the way to do this. But you actually have several possible options for identifying model parts in a hit test result, so you can choose the one that best fits your content creation pipeline.

  1. 如其他答案中所述,如果您可以将模型分解为单独的模型,每个模型都具有自己的节点托管在场景中,则可以使用

  1. As noted in other answers, if you can break your model up into separate models, each of which is hosted in the scene with its own node, you can use the SCNHitTestResult.node property to find out which node was clicked/tapped/grabbed.

如果无法完全拆分模型,则可以将其拆分为仍然存在于同一资产/节点中的多个部分.SceneKit调用这些 geometry元素,某些创作工具将其称为 submeshes ,低级渲染代码将其称为具有单独索引缓冲区的单独绘制调用,等等.几何元素(对于在几何的不同部分上用多种材料绘制一个几何所必需的几何元素),您可以使用 answer链接到的HalMueller 中使用了这种方法.)

If you can't split the model completely, you may be able to split it into multiple parts that still live in the same asset/node. SceneKit calls these geometry elements, some authoring tools call them submeshes, low-level rendering code calls it a separate draw call with a separate index buffer, etc. When you have separate geometry elements (which are necessary for drawing one geometry with multiple materials on different parts of the geometry), you can identify them in hit-testing with the SCNHitTestResult.geometryIndex property. (This approach is used in the answer HalMueller linked to.)

如果您控制网格的纹理映射数据,则可以使用

If you control the texture mapping data for the mesh, you can use textureCoordinates(withMappingChannel:) to get texture coordinates for the clicked point, then look them up in a texture image in which you've color-coded the ares of interest. (You can get a general overview for the theory behind this idea in this article, though the implementation isn't specific to SceneKit.)

如果为骨骼动画装配模型,则可以使用 SCNHitTestResult.boneNode 属性以获取在点击位置最负责几何变形的骨骼.

If your model is rigged for skeletal animation, you can use the SCNHitTestResult.boneNode property to get the bone most responsible for geometry deformation at the clicked point.

这篇关于在SceneKit中检测触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆