我在 RC 中有一个复杂的对象,我无法选择子对象用作按钮。所以我想尝试添加隐形的“点击框”来捕获点击。但我找不到任何方法来创建一个看不见的对象。我已经在 Blender 中尝试了多种材质调整(然后导出到 GTLF,然后使用 Reality Converter 转换为 USDZ),但无论生成的立方体具有反射率并且并不是真正不可见。
如果我无法选择模型中我想要充当触发器的部分,我该怎么做才能实现这一目标?
注意:交付成果是一个
.reality
文件,而不是应用程序。
您无法在 Reality Composer 1.5 中使任何模型不可见。
但是,您可以将盒子导出为
.usdz
或 .reality
文件,将其加载到 Xcode 项目中,在场景中找到一个盒子基元,然后使用 UnlitMaterial(color: .clear)
应用新的不可见着色器。这是代码:
import SwiftUI
import RealityKit
struct ContentView: View {
@State var arView = ARView(frame: .zero)
@State var boolean = true
var body: some View {
ARContainer(arView: arView)
.ignoresSafeArea()
.onTapGesture { location in
let hit = arView.entity(at: location) as? ModelEntity
boolean.toggle()
print(hit?.id as Any)
if boolean {
hit?.model?.materials = [UnlitMaterial(color: .clear)]
} else {
hit?.model?.materials = [UnlitMaterial(color: .init(white: 1,
alpha: 0.1))]
}
}
}
}
struct ARContainer: UIViewRepresentable {
var arView: ARView
func makeUIView(context: Context) -> ARView {
let scene = try! Entity.load(named: "HitBox")
print(scene)
let box = scene.findEntity(named: "Mesh0") as! ModelEntity
box.scale *= 5
box.model?.materials = [UnlitMaterial(color: .clear)]
box.generateCollisionShapes(recursive: false)
let anchor = AnchorEntity()
anchor.addChild(box)
arView.scene.anchors.append(anchor)
return arView
}
func updateUIView(_ view: ARView, context: Context) { }
}