首页 > 解决方案 > 更改对象的颜色

问题描述

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

我在文档中发现我可以更改位置、旋转、比例,但是,我无法找到如何更改颜色的方法。

标签: swiftaugmented-realityarkitrealitykitreality-composer

解决方案


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

let boxScene = try! Experience.loadBox()

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

var material = SimpleMaterial()
material.baseColor = .color(.green)
modelEntity.model?.materials = [material]

arView.scene.anchors.append(boxScene)

print(boxScene)

向下转换为 ModelEntity 是访问模型组件所必需的:

在此处输入图像描述


推荐阅读