1

我想在 AR 投影时隐藏对象的背面。你看,这个物体在墙上有点加深了。我可以制作某种蒙版对象以使该对象不可见吗?

import UIKit
import RealityKit

class ViewController: UIViewController {

    @IBOutlet var arView: ARView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Load the "Box" scene from the "Experience" Reality File
        let ARscene1 = try! Experience.load_1()
        let ARscene2 = try! Experience.load_2()
        let ARscene3 = try! Experience.load_3() //that scene, object named "mask"          

        // Add the box anchor to the scene
        arView.scene.anchors.append(ARscene1)
        arView.scene.anchors.append(ARscene2)
        arView.scene.anchors.append(ARscene3)
    }
}

在这里你可以看到我的模型是什么样子的

4

1 回答 1

0

这是一个小的 macOS 项目,向您展示如何Occlusion Material在 RealityKit 中进行设置:

import Cocoa
import RealityKit

class GameViewController: NSViewController {

    @IBOutlet var arView: ARView!
    let anchor = try! TwoCubes.loadTwoObjects()

    override func awakeFromNib() {
        arView.environment.background = .color(.black)

        let boxEntity1: Entity = anchor.invisible!.children[0]
        var boxComponent1: ModelComponent = boxEntity1.components[ModelComponent]!.self

        let boxEntity2: Entity = anchor.visible!.children[0]
        var boxComponent2: ModelComponent = boxEntity2.components[ModelComponent]!.self

        let material1 = OcclusionMaterial()  // Material hiding other objects behind it
        var material2 = SimpleMaterial()
        material2.baseColor = .color(.orange)

        boxComponent1.materials = [material1]
        boxComponent2.materials = [material2]

        anchor.invisible!.components.set(boxComponent1)
        anchor.visible!.components.set(boxComponent2)

        arView.scene.anchors.append(anchor)
    }
}

在此处输入图像描述

于 2020-01-07T09:37:57.450 回答