在我的 iOS 应用程序中,我想使用新的 Reality Composer 来介绍 AR 的一部分。
在我的项目中,我使用以下代码加载场景:
let arView = ARView.init(frame: frame)
// Configure the AR session for horizontal plane tracking.
let arConfiguration = ARWorldTrackingConfiguration()
arConfiguration.planeDetection = .horizontal
arView.session.run(arConfiguration)
arView.session.delegate = self
self.view.addSubview(arView)
Experience.loadSceneAsync{ [weak self] scene, error in
print("Error \(String(describing: error))")
guard let scene = scene else { return }
arView.scene.addAnchor(scene)
// THIS IS THE entity that i want to edit programmatically
scene.Label
The “场景.标签”是我的场景中的文本对象,我想以编程方式设置文本。
我怎样才能做到这一点?
这是可能的?
提前致谢
在 RealityKit 框架中,使用以下内容类型方法 https://developer.apple.com/documentation/realitykit/meshresource用于生成 3D 文本:
static func generateText(_ string: String,
extrusionDepth: Float,
font: MeshResource.Font,
containerFrame: CGRect,
alignment: CTTextAlignment,
lineBreakMode: CTLineBreakMode) -> MeshResource
让我们看看真实的代码是什么样子的:
let textAnchor = try! SomeText.loadTextScene()
let textEntity: Entity = textAnchor.vacation!.children[0].children[0]
var textModelComponent = (textEntity.components[ModelComponent])!
textModelComponent.mesh = .generateText("Hello, World!",
extrusionDepth: 0.01,
font: .systemFont(ofSize: 0.25),
containerFrame: CGRect.zero,
alignment: .center,
lineBreakMode: .byCharWrapping)
textAnchor.vacation!.children[0].children[0].components.set(textModelComponent)
arView.scene.anchors.append(textAnchor)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)