将SceneKit平面与立方体的面对齐

时间:2019-04-02 22:28:38

标签: ios swift scenekit

我在SceneKit中创建了一个scnbox,并试图在用户触摸的面部上添加一个圆形平面。

我可以使用hittest将SCNPlane添加为接触点上的子节点,但是我正在努力使平面朝向被触摸的脸部。

作为命中测试的一部分提供的局部法线向量似乎是我所需要的,但我不确定如何使用它。通常我会使用EulerAngles属性进行定向,但是localnormal看起来是一个向量。我尝试了使用vector3的Look(at :),但似乎不起作用。 任何建议将不胜感激。下面的代码示例摘自touchesBegan。 “结果”是SCNHitTestResult:

//Draw circular plane, double sided
let circle =  SCNPlane(width: 0.1, height: 0.1) //SCNSphere(radius: 0.1)
circle.cornerRadius = 0.5
circle.materials.first?.diffuse.contents = UIColor.black
circle.materials.first?.isDoubleSided = true
let circleNode = SCNNode(geometry: circle)

//Set position to hit test
circleNode.position = result.localCoordinates
let lookAtPoint = SCNVector3(result.localNormal.x * 100, result.localNormal.y * 100, result.localNormal.z * 100)

//Align to far point on normal
circleNode.look(at: lookAtPoint)
//Add to touched node
result.node.addChildNode(circleNode)

0 个答案:

没有答案
相关问题