RealityKit – How to access the property in a Scene programmatically?(RealityKit-如何以编程方式访问场景中的属性?)
                            本文介绍了RealityKit-如何以编程方式访问场景中的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
                        
                        问题描述
我一直在使用Reality Composer和一个框架实体,是从库中下载的。
我希望访问对象的属性以编程方式提供要在框架中显示的图像。
这里您可以看到有一个配置,我可以从我的图库导入照片。但我想通过编程来实现。 也就是说,我希望访问Frame对象属性并以编程方式提供图像。
但我做不到。
do {
    let boxAnchor = try ImageFrame.loadScene()
        
    guard let imageFrame = boxAnchor.findEntity(named: "imageFrame")
    else { return }
    //how to access the property of imageFrame???
    arView.scene.anchors.append(boxAnchor)
} catch {
    print("error: (error.localizedDescription)")
}
如何以编程方式提供图像?
推荐答案
当然,您需要在模型的hierarchy的深处查找所需的ModelEntity。
使用此SwiftUI解决方案:
struct ARViewContainer: UIViewRepresentable {
    
    func makeUIView(context: Context) -> ARView {
        
        let arView = ARView(frame: .zero)
        let pictureScene = try! Experience.loadPicture()
        pictureScene.children[0].scale *= 4
        
        print(pictureScene)
        
        let edgingModel = pictureScene.masterpiece?.children[0] as! ModelEntity
        edgingModel.model?.materials = [SimpleMaterial(color: .brown,
                                                  isMetallic: true)]
        
        var mat = SimpleMaterial()
        // Here's a great old approach for assigning a texture in iOS 14.5
        mat.baseColor = try! .texture(.load(named: "MonaLisa", in: nil))
        
        let imageModel = pictureScene.masterpiece?.children[0]
                                                  .children[0] as! ModelEntity
        imageModel.model?.materials = [mat]
        
        arView.scene.anchors.append(pictureScene)
        return arView
    }
    func updateUIView(_ uiView: ARView, context: Context) { }
}
                        这篇关于RealityKit-如何以编程方式访问场景中的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
				 沃梦达教程
				
			本文标题为:RealityKit-如何以编程方式访问场景中的属性?
				
        
 
            
        
             猜你喜欢
        
	     - 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
 - Android viewpager检测滑动超出范围 2022-01-01
 - Android - 拆分 Drawable 2022-01-01
 - MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
 - 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
 - android 4中的android RadioButton问题 2022-01-01
 - 用 Swift 实现 UITextFieldDelegate 2022-01-01
 - Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
 - 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
 - 想使用ViewPager,无法识别android.support.*? 2022-01-01
 
				
				
				
				