【问题标题】:How do I make the back of an object invisible with a mask object?如何使用蒙版对象使对象的背面不可见?
【发布时间】:2019-12-26 10:12:25
【问题描述】:

我想在 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)
    }
}

这里你可以看到my model looks like

【问题讨论】:

    标签: swift augmented-reality arkit realitykit reality-composer


    【解决方案1】:

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

    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)
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-29
      • 1970-01-01
      相关资源
      最近更新 更多