簡體   English   中英

如何使用 RealityKit 讓 MeshResource.generateText() 錨定到相機以外的東西?

[英]How do I get MeshResource.generateText() to anchor to something other than the camera using RealityKit?

我正在使用 RealityKit 和 SwiftUI 將 3DText 放置在 iOS 上,但我無法將文本錨定到 position。我將項目剝離到下面的基本要素,但它仍然無法正常工作。 當我四處走動時,盒子將固定並停留在一個地方,但無論我移動到哪里,文本都會跟隨在我的設備上方。 這讓我發瘋,因為盒子完全按預期工作,但文本卻沒有。 我嘗試了下面代碼的許多不同迭代都無濟於事。 我想知道是否還有其他人遇到過這個問題,或者是否只是我,這可能是一個錯誤? 還有什么我應該嘗試的嗎?

import SwiftUI
import RealityKit

struct ContentView : View {
    var body: some View {
        return ARViewContainer().edgesIgnoringSafeArea(.all)
    }
}

struct ARViewContainer: UIViewRepresentable {
    
    func makeUIView(context: Context) -> ARView {
        
        let arView = ARView(frame: .zero)
    
        let anchor = AnchorEntity()
        anchor.position = simd_make_float3(0, -0.5, -1)
        let textEntity = ModelEntity(mesh: .generateText("Hello there", extrusionDepth: 0.4, font: .boldSystemFont(ofSize: 8), containerFrame: .zero, alignment: .center, lineBreakMode: .byWordWrapping))
        let boxEntity = ModelEntity(mesh: .generateBox(size: 0.2))
        anchor.addChild(textEntity)
        anchor.addChild(boxEntity)
        arView.scene.anchors.append(anchor)
        
        return arView
        
    }
    
    func updateUIView(_ uiView: ARView, context: Context) {}
    
}

如果有幫助,這里是調試所說的一切:

2022-02-21 17:00:25.428134-0800 testARapp[4776:1686900] Metal GPU Frame Capture Enabled
2022-02-21 17:00:25.428586-0800 testARapp[4776:1686900] Metal API Validation Enabled
2022-02-21 17:00:25.797516-0800 testARapp[4776:1686900] [AssetTypes] Registering library (/System/Library/PrivateFrameworks/CoreRE.framework/default.metallib) that already exists in shader manager. Library will be overwritten.
2022-02-21 17:00:25.919915-0800 testARapp[4776:1686900] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/suFeatheringCreateMergedOcclusionMask.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-02-21 17:00:25.937834-0800 testARapp[4776:1686900] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arKitPassthrough.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-02-21 17:00:25.938393-0800 testARapp[4776:1686900] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/drPostAndComposition.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-02-21 17:00:25.938882-0800 testARapp[4776:1686900] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arSegmentationComposite.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-02-21 17:00:25.939438-0800 testARapp[4776:1686900] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute0.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-02-21 17:00:25.940131-0800 testARapp[4776:1686900] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute1.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-02-21 17:00:25.940383-0800 testARapp[4776:1686900] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute2.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-02-21 17:00:25.947105-0800 testARapp[4776:1686900] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute3.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-02-21 17:00:25.947365-0800 testARapp[4776:1686900] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute4.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-02-21 17:00:25.947601-0800 testARapp[4776:1686900] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute5.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-02-21 17:00:25.947841-0800 testARapp[4776:1686900] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute6.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-02-21 17:00:25.948079-0800 testARapp[4776:1686900] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute7.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-02-21 17:00:25.948513-0800 testARapp[4776:1686900] [Foundation.Serialization] Json Parse Error line 18: Json Deserialization; unknown member 'EnableARProbes' - skipping.
2022-02-21 17:00:25.948533-0800 testARapp[4776:1686900] [Foundation.Serialization] Json Parse Error line 20: Json Deserialization; unknown member 'EnableGuidedFilterOcclusion' - skipping.
2022-02-21 17:00:26.004695-0800 testARapp[4776:1686900] CoreText performance note: Client called CTFontCreateWithName() using name "System Font Semibold" and got font with PostScript name ".SFUI-Semibold". For best performance, only use PostScript names when calling this API.
2022-02-21 17:00:26.004723-0800 testARapp[4776:1686900] CoreText performance note: Set a breakpoint on CTFontLogSuboptimalRequest to debug.
2022-02-21 17:00:26.007971-0800 testARapp[4776:1686900] CoreText performance note: Client called CTFontCreateWithName() using name "System Font Regular" and got font with PostScript name ".SFUI-Regular". For best performance, only use PostScript names when calling this API.
2022-02-21 17:00:26.062646-0800 testARapp[4776:1686900] CoreText performance note: Client called CTFontCreateWithName() using name "System Font Semibold" and got font with PostScript name ".SFUI-Semibold". For best performance, only use PostScript names when calling this API.
2022-02-21 17:00:26.158252-0800 testARapp[4776:1686900] throwing -10878
2022-02-21 17:00:26.159086-0800 testARapp[4776:1686900] throwing -10878
2022-02-21 17:00:26.159123-0800 testARapp[4776:1686900] throwing -10878
2022-02-21 17:00:26.159156-0800 testARapp[4776:1686900] throwing -10878
2022-02-21 17:00:26.159189-0800 testARapp[4776:1686900] throwing -10878
2022-02-21 17:00:26.159344-0800 testARapp[4776:1686900] throwing -10878
2022-02-21 17:00:26.159449-0800 testARapp[4776:1686900] throwing -10878
2022-02-21 17:00:26.159576-0800 testARapp[4776:1686900] throwing -10878
2022-02-21 17:00:26.159643-0800 testARapp[4776:1686900] throwing -10878
2022-02-21 17:00:28.011153-0800 testARapp[4776:1687256] [Technique] ARWorldTrackingTechnique <0x131f0d840>: World tracking performance is being affected by resource constraints [25]

錨定后,嘗試打印出文本實體相對於世界空間的邊界球體,看看它是否有任何變化。 也許在使用屏幕點擊手勢等四處移動時打印幾次。

我懷疑您正在制作的文字 object 比看起來更大,而且距離更遠,由於透視的原因,它看起來好像貼在屏幕上。 我在生成文本和 RealityKit 時遇到了很多問題。 我制作的 package 中有一個小的 class ,它對所有這些與中心、大小等文本相關的怪異現象有很大幫助: RealityUI、RUIText

除此之外,像這樣以 position 在 1x1m 水平面上方 0.5m 的偏移量錨定到地板上會形成更好的錨點:

let anchor = AnchorEntity(.plane(
    [.horizontal], classification: .any, minimumBounds: [1, 1])
)
anchor.position.y = 0.5

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM