我目前正在研究如何从 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:
如果您需要更改模型的透明度,请使用following approach .
关于swift - RealityKit – 更改模型的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67408552/