将 3D SceneKit 节点位置映射到 2D 坐标 - projectPoint 不起作用 [英] Mapping 3D SceneKit Node-Position to 2D Coordinate - projectPoint doesn't work

查看:74
本文介绍了将 3D SceneKit 节点位置映射到 2D 坐标 - projectPoint 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在显示由 SceneKit 中的几个 SNNode 组成的 3d 模型.

I am displaying a 3d model consisting of several SNNodes in SceneKit.

我正在场景视图叠加视图上显示一个 2D SpriteKit 节点.2D 节点位置应始终位于特定 3D SCNNode 的前面.

I am displaying a 2D SpriteKit node on the sceneview-overlay view. The 2D-node position should always be in front of a particular 3D SCNNode.

如何将 3D 位置映射到 SpriteKit 2D 位置?

How can I map the 3D position to the SpriteKit 2D position?

我尝试了 let screenPoint = sceneView.projectPoint(my3dNode),但这不起作用:即使 my3dNode 位于屏幕中央,该函数也会返回非常奇怪的值(例如负数)值或超过 1000).

I tried let screenPoint = sceneView.projectPoint(my3dNode), but this doesn't work: even when the my3dNode is in the center of the screen, the function returns very weird values (e.g. negative values or over 1000).

你有什么想法吗?

推荐答案

可能是它从未平移、未修改的节点位置投影,或者该节点是另一个节点的子节点,从而改变了它的参考系.尝试使用 myNode.presentation.worldPosition 作为 projectPoint 的输入.

It could be that it's projecting from the untranslated, unmodified node position, or that the node is a child of another node, thus changing its frame of reference. Try using myNode.presentation.worldPosition as the input for projectPoint.

仔细阅读,创建精灵的平面纹理,将其附加到相关节点,给它一个广告牌"约束并设置其 Z 顺序,使其始终出现在前面不是更好吗?

Reading a bit closer, would you not be better off creating a flat texture of your sprite, attach it to the node in question, give it a 'billboard' constraint and set its Z order so that it always appears in front?

这篇关于将 3D SceneKit 节点位置映射到 2D 坐标 - projectPoint 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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