Swift 如何使用遮罩对象使对象的背面不可见?
我想在投影时隐藏对象的背面。你看,物体在墙上加深了。我可以制作某种遮罩对象使其不可见吗Swift 如何使用遮罩对象使对象的背面不可见?,swift,augmented-reality,arkit,realitykit,reality-composer,Swift,Augmented Reality,Arkit,Realitykit,Reality Composer,我想在投影时隐藏对象的背面。你看,物体在墙上加深了。我可以制作某种遮罩对象使其不可见吗 import UIKit import RealityKit class ViewController: UIViewController { @IBOutlet var arView: ARView! override func viewDidLoad() { super.viewDidLoad() // Load the "Box" scene fr
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)
}
}
在这里您可以看到如何操作。这里有一个小macOS项目,向您展示如何在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)
}
}
这里有一个小macOS项目,向您展示如何在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)
}
}