swift - RealityKit – 更改模型的颜色

标签 swift augmented-reality arkit realitykit reality-composer

我目前正在研究如何从 Swift 转换对象颜色的选项。该对象已从 Reality Composer 添加到场景中。

我在 documentation 中找到我可以改变位置、旋转、缩放,但是,我无法找到改变颜色的方法。

最佳答案

Xcode 14.2、RealityKit 2.0、目标 iOS 16.2

使用以下代码更改盒模型的颜色(可在 Xcode RealityKit 模板中找到):

let boxScene = try! Experience.loadBox()     // Reality Composer scene

let modelEntity = boxScene.steelBox!.children[0] as! ModelEntity

var material = SimpleMaterial()
material.color = .init(tint: .green)
modelEntity.model?.materials[0] = material

arView.scene.anchors.append(boxScene)

print(boxScene)

访问模型的组件需要向下转换为 ModelEntity:

enter image description here

如果您需要更改模型的透明度,请使用following approach .

关于swift - RealityKit – 更改模型的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67408552/

相关文章:

swift - 如何使 UILabel 在未跟踪图像时出现在屏幕上,并在跟踪图像时消失

swift - 如何在 RealityKit 中使用 Raycast 方法?

ios - ios中相应标记的标记检测和3d模型显示(使用ARkit)

ios - 多次调用 deleteRowsAtIndexPaths

swift - 选择后的osx NSPopUpButton通知

swift - 如何在相机 ARKit 顶部添加半透明背景

ios - 在 ARKit session 中左右移动对象

swift - 在 swift 中转换和强制指针有什么区别?

ios - SwiftUI:通过 View 组合实现代码重用

swift - SceneKit AR 游戏 fps 越来越低,设备随着使用而变热