swift - 更改对象的颜色
问题描述
我目前正在研究如何从 Swift 转换对象颜色的选项。该对象已从 Reality 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 是访问模型组件所必需的:
推荐阅读
- csv - CSV Parser,如何自动发现 col 名称和类型
- css - 如何使用 React Material-UI、fontAwesome 图标和 Tailwind.css 左对齐所有列表项
- javascript - Typescript Angular HTTP请求仅获得最后一个结果
- r - Shiny:全球反应式数据集
- azure - 将 Azure 托管映像从 Azure 商业复制到 Azure 中国
- c# - C# excel 到 datagridview 从 VB 转换
- javascript - React setState 在 es6 中不可变:无法将 undefined 或 null 转换为对象
- selectize.js - selectize.js lockOptgroupOrder 抛出异常
- kendo-ui - Kendo Virtual ComboBox:选中的dataItem为null,不在bar中显示,但在datasource中存在
- ruby-on-rails - 如何在 Rails 应用程序中存储或保存内存加载的图像