我已经编写了代码来初始化 3 个 Reality Composer 场景中的一个,当按下按钮时,具体取决于一个月中的哪一天。
这一切都很好。
Reality Composer 场景使用图像检测将对象放置在环境中,但目前只要图像离开相机视图,对象就会消失。
我想将场景锚定在第一次检测到图像的根节点,这样用户就可以环顾场景,即使图像触发器不在相机视图中,也可以维护对象。
我尝试在下面传递一个 func 渲染器代码,但我收到错误说视图控制器类没有 .planeNode
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
guard let imageAnchor = anchor as? ARImageAnchor else { return }
let referenceImage = imageAnchor.referenceImage
// Create a plane to visualize the initial position of the detected image.
let plane = SCNPlane(width: referenceImage.physicalSize.width,
height: referenceImage.physicalSize.height)
plane.materials.first?.diffuse.contents = UIColor.blue.withAlphaComponent(0.20)
self.planeNode = SCNNode(geometry: plane)
self.planeNode?.opacity = 1
/*
`SCNPlane` is vertically oriented in its local coordinate space, but
`ARImageAnchor` assumes the image is horizontal in its local space, so
rotate the plane to match.
*/
self.planeNode?.eulerAngles.x = -.pi / 2
/*
Image anchors are not tracked after initial detection, so create an
animation that limits the duration for which the plane visualization appears.
*/
// Add the plane visualization to the scene.
if let planeNode = self.planeNode {
node.addChildNode(planeNode)
}
if let imageName = referenceImage.name {
plane.materials = [SCNMaterial()]
plane.materials[0].diffuse.contents = UIImage(named: imageName)
}
这是我的代码
import UIKit
import RealityKit
import ARKit
import SceneKit
class ViewController: UIViewController {
@IBOutlet var move: ARView!
@IBOutlet var arView: ARView!
var ARBorealAnchor3: ARboreal.ArBoreal3!
var ARBorealAnchor2: ARboreal.ArBoreal2!
var ARBorealAnchor: ARboreal.ArBoreal!
var Date1 = 1
override func viewDidLoad() {
super.viewDidLoad()
func getSingle() {
let date = Date()
let calendar = Calendar.current
let day = calendar.component(.day, from: date)
Date1 = day
}
getSingle()
ARBorealAnchor = try! ARboreal.loadArBoreal()
ARBorealAnchor2 = try!
ARboreal.loadArBoreal2()
ARBorealAnchor3 = try!
ARboreal.loadArBoreal3()
if Date1 == 24 {
arView.scene.anchors.append(ARBorealAnchor)
}
if Date1 == 25 {
arView.scene.anchors.append(ARBorealAnchor2)
}
if Date1 == 26 {
arView.scene.anchors.append(ARBorealAnchor3)
}
}
}
任何帮助将不胜感激。
干杯,丹尼尔萨维奇