再來添加一些方法讓虛擬場景更符合需求和效能
func suspendPlaneDetection() {
let config = sceneView.session.configuration as!
ARWorldTrackingConfiguration
config.planeDetection = []
sceneView.session.run(config)
}
這裡獲得當前AR tracking 的配置(configuration) 從 scene view session,
再來清除planeDetection, 最後重新run, 則不會再去偵測額外的平面而節省效能
func hidePlaneNodes() {
for anchor in (self.sceneView.session.currentFrame?.anchors)! {
if let node = self.sceneView.node(for: anchor) {
for child in node.childNodes {
let material = child.geometry?.materials.first!
material?.colorBufferWriteMask = []
}
} }
}
這裏遍訪每一個anchor, 然後找到對應的node, 一但找到了就隱藏它和他的子類