如何在函数渲染器(SCNSceneRenisher,nodeFor:ARAnchor)中旋转SCNNode?>SCNNode?&Quot;

How do I rotate a SCNNode in quot;func renderer(SCNSceneRenderer, nodeFor: ARAnchor) -gt; SCNNode?quot;(如何在函数渲染器(SCNSceneRenisher,nodeFor:ARAnchor)中旋转SCNNode?gt;SCNNode?Quot;)
本文介绍了如何在函数渲染器(SCNSceneRenisher,nodeFor:ARAnchor)中旋转SCNNode?>SCNNode?&Quot;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我能够在锚点位置放置一个长方体节点。 现在,如何在场景中旋转SCNNode?

我正在尝试修改节点的转换&;eulerAngles,但它们没有效果:

func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
    print("nodeFor anchor (anchor)")

    guard anchor.name == "card" else { return nil }

    let colors = [
        UIColor.yellow, // front
        UIColor.red, // right
        UIColor.blue, // back
        UIColor.green, // left
        UIColor.purple, // top
        UIColor.gray] // bottom

    let sideMaterials = colors.map { color -> SCNMaterial in
        let material = SCNMaterial()
        material.diffuse.contents = color
        material.locksAmbientWithDiffuse = true
        return material
    }

    let boxGeometry = SCNBox(width: 0.12, height: 0.01, length: 0.07, chamferRadius: 0)
    boxGeometry.materials = sideMaterials

    let node = SCNNode(geometry: boxGeometry)
    node.transform = SCNMatrix4MakeRotation(-Float.pi / 2, 1, 0, 0)
    node.eulerAngles.x = .pi / 2

    return node
}

我还试着在函数渲染器中进行旋转(_renender:SCNSceneRenender,didAdd node:SCNNode,For Anchor:ARAnchor)

func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
    node.eulerAngles.x = .pi / 2
}

但这也没有帮助。

我使用下面的代码成功地制作了旋转动画。

    let spin = CABasicAnimation(keyPath: "rotation")
    // Use from-to to explicitly make a full rotation around z
    spin.fromValue = NSValue(scnVector4: SCNVector4(x: 0, y: 0, z: 1, w: 0))
    spin.toValue = NSValue(scnVector4: SCNVector4(x: 0, y: 0, z: 1, w: Float(2 * Double.pi)))
    spin.duration = 3
    spin.repeatCount = 1
    node.addAnimation(spin, forKey: "rotation")

基于那次成功,我也尝试了(但失败了)

    node.rotation = SCNVector4(x: 5, y: 4, z: 3, w: 0)

有人知道如何在ARSCNViewDelegate的委托方法中旋转节点吗?

推荐答案

ARSession将定位您提供给它的节点。最好是对子节点执行轮换操作,将其转换为已分配的子节点。因此在func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode?

在返回之前,您可以说:

let node = SCNNode(geometry: boxGeometry)
node.eulerAngles = SCNVector3(x: -Float.pi / 2, y: 0, z: 0)

let rootNode = SCNNode()
rootNode.addChildNode(node)
return rootNode

这篇关于如何在函数渲染器(SCNSceneRenisher,nodeFor:ARAnchor)中旋转SCNNode?>SCNNode?&Quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
Dropbox Files.download does not start when number of files in folder is gt; 1000(当文件夹中的文件数为1000时,Dropbox Files.Download不会启动)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)