3D 对象需要很长时间才能在 RealityKit 中显示

发布于 2025-01-12 13:47:34 字数 9873 浏览 0 评论 0原文

我正在开发 RealityKit 应用程序项目,我有一个问题。 查看 3D 模型时,需要一分钟多的时间才能显示,该应用程序可以快速从 Firebase 加载模型,但需要时间才能在屏幕上显示,我正在使用 iPad 7 代来运行该应用程序。 我尝试了 obj 和 usdz 格式,没有区别

代码

func View3DObject( Name : String){
        
        //start of bring models from firebase
        @ObservedObject var model = Model(name: Name, category: .animals)
        
        //set object on floor
        let anchorEntity = AnchorEntity(plane: .any, classification: .floor)
           
        
        //get object from database
           let resultModel = model.asyncLoadModelEntity(){ result in
            
               
        //enable intraction and movment
            result.generateCollisionShapes(recursive: true)
               self.arView.installGestures([.translation, .rotation, .scale],for: result)
   
            
            anchorEntity.addChild(result)
               
      

        }
        
        
        //add object to secne
            self.arView.scene.anchors.append(anchorEntity)
            print("Model is added to the scene" )


    }
    
}

这是我使用asyncLoadModelEntity 函数的

 func asyncLoadModelEntity(completion: @escaping (_ result: ModelEntity) -> Void) -> ModelEntity{
        var result = ModelEntity()
        FirebaseStorageHelper.asyncDownloadFilesystem(relativePath: "models/\(self.name).obj") { localUrl in
            self.cancellable = ModelEntity.loadModelAsync(contentsOf: localUrl)
                .sink(receiveCompletion: { loadCompletion in
               
                    switch loadCompletion{
                    case .failure(let error): print("Unable to load modelEntity for \(self.name). Error: \(error.localizedDescription)")
                case .finished:
                    break
                }
            }, receiveValue:{ modelEntity in
                result = modelEntity
                self.modelEntity = modelEntity

                // self.modelEntity?.scale *= self.scaleCompensation
                print("modelEntity for \(self.name) has been loaded")
                completion(result)
            })
        }
        return result
    }

:这也是控制台

022-03-06 01:43:27.800057+0300 MarsamApp[689:48039] Metal GPU Frame Capture Enabled
2022-03-06 01:43:27.801598+0300 MarsamApp[689:48039] Metal API Validation Enabled
2022-03-06 01:43:28.325928+0300 MarsamApp[689:48039] [AssetTypes] Registering library (/System/Library/PrivateFrameworks/CoreRE.framework/default.metallib) that already exists in shader manager. Library will be overwritten.
2022-03-06 01:43:28.413704+0300 MarsamApp[689:48242] 6.34.0 - [Firebase/Core][I-COR000008] The project's Bundle ID is inconsistent with either the Bundle ID in 'GoogleService-Info.plist', or the Bundle ID in the options if you are using a customized options. To ensure that everything can be configured correctly, you may need to make the Bundle IDs consistent. To continue with this plist file, you may change your app's bundle identifier to 'com.MarsamApp'. Or you can download a new configuration file that matches your bundle identifier from https://console.firebase.google.com/ and replace the current one.
2022-03-06 01:43:28.455746+0300 MarsamApp[689:48246] [general] *** -[NSKeyedUnarchiver validateAllowedClass:forKey:] allowed unarchiving safe plist type ''NSString' (0x1f345e358) [/System/Library/Frameworks/Foundation.framework]' for key 'NS.keys', even though it was not explicitly included in the client allowed classes set: '{(
    "'NSDate' (0x1f34536c0) [/System/Library/Frameworks/CoreFoundation.framework]",
    "'NSDictionary' (0x1f3453828) [/System/Library/Frameworks/CoreFoundation.framework]"
)}'. This will be disallowed in the future.
2022-03-06 01:43:28.477648+0300 MarsamApp[689:48246] 6.34.0 - [Firebase/Analytics][I-ACS023007] Analytics v.60900000 started
2022-03-06 01:43:28.478318+0300 MarsamApp[689:48246] 6.34.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see)
2022-03-06 01:43:28.491851+0300 MarsamApp[689:48246] 6.34.0 - [Firebase/Analytics][I-ACS800023] No pending snapshot to activate. SDK name: app_measurement
2022-03-06 01:43:28.498980+0300 MarsamApp[689:48242] 6.34.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled
2022-03-06 01:43:28.499730+0300 MarsamApp[689:48242] 6.34.0 - [Firebase/Analytics][I-ACS023220] Analytics screen reporting is enabled. Call +[FIRAnalytics logEventWithName:FIREventScreenView parameters:] to log a screen view event. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO (boolean) in the Info.plist
2022-03-06 01:43:28.634100+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/suFeatheringCreateMergedOcclusionMask.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.718313+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arKitPassthrough.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.720479+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/drPostAndComposition.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.722138+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arSegmentationComposite.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.724000+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute0.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.726142+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute1.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.727083+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute2.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.741687+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute3.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.742755+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute4.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.743783+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute5.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.744806+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute6.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.745873+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute7.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.747365+0300 MarsamApp[689:48039] [Foundation.Serialization] Json Parse Error line 18: Json Deserialization; unknown member 'EnableARProbes' - skipping.
2022-03-06 01:43:28.747443+0300 MarsamApp[689:48039] [Foundation.Serialization] Json Parse Error line 20: Json Deserialization; unknown member 'EnableGuidedFilterOcclusion' - skipping.
2022-03-06 01:43:29.018288+0300 MarsamApp[689:48039] throwing -10878
2022-03-06 01:43:29.020976+0300 MarsamApp[689:48039] throwing -10878
2022-03-06 01:43:29.021108+0300 MarsamApp[689:48039] throwing -10878
2022-03-06 01:43:29.021210+0300 MarsamApp[689:48039] throwing -10878
2022-03-06 01:43:29.021303+0300 MarsamApp[689:48039] throwing -10878
2022-03-06 01:43:29.021756+0300 MarsamApp[689:48039] throwing -10878
2022-03-06 01:43:29.021864+0300 MarsamApp[689:48039] throwing -10878
2022-03-06 01:43:29.021971+0300 MarsamApp[689:48039] throwing -10878
2022-03-06 01:43:29.022073+0300 MarsamApp[689:48039] throwing -10878
2022-03-06 01:43:29.222669+0300 MarsamApp[689:48250] [general] *** -[NSKeyedUnarchiver validateAllowedClass:forKey:] allowed unarchiving safe plist type ''NSString' (0x1f345e358) [/System/Library/Frameworks/Foundation.framework]' for key 'NS.keys', even though it was not explicitly included in the client allowed classes set: '{(
    "'NSDate' (0x1f34536c0) [/System/Library/Frameworks/CoreFoundation.framework]",
    "'NSDictionary' (0x1f3453828) [/System/Library/Frameworks/CoreFoundation.framework]"
)}'. This will be disallowed in the future.

Model is added to the scene
Warning (secondary thread): in AppendProperty at line 859 of sdf/path.cpp -- Can only append a property 'preliminary:anchoring:type' to a prim path (/)
Warning (secondary thread): in AppendProperty at line 859 of sdf/path.cpp -- Can only append a property 'triggers' to a prim path (/)
Warning (secondary thread): in AppendProperty at line 859 of sdf/path.cpp -- Can only append a property 'preliminary:anchoring:type' to a prim path (/)
modelEntity for Banana has been loaded

,这些是一些用于统计的场景截图 绵羊对象 青蛙对象

I am working on RealityKit app project and I have a question.
when viewing a 3d model it takes more than one minute to show up, the app loads the models from firebase fast but it takes time to show on the screen and I am using iPad 7 generation to run the app.
I tried obj and usdz format and there is no difference

This is the code I use

func View3DObject( Name : String){
        
        //start of bring models from firebase
        @ObservedObject var model = Model(name: Name, category: .animals)
        
        //set object on floor
        let anchorEntity = AnchorEntity(plane: .any, classification: .floor)
           
        
        //get object from database
           let resultModel = model.asyncLoadModelEntity(){ result in
            
               
        //enable intraction and movment
            result.generateCollisionShapes(recursive: true)
               self.arView.installGestures([.translation, .rotation, .scale],for: result)
   
            
            anchorEntity.addChild(result)
               
      

        }
        
        
        //add object to secne
            self.arView.scene.anchors.append(anchorEntity)
            print("Model is added to the scene" )


    }
    
}

asyncLoadModelEntity function:

 func asyncLoadModelEntity(completion: @escaping (_ result: ModelEntity) -> Void) -> ModelEntity{
        var result = ModelEntity()
        FirebaseStorageHelper.asyncDownloadFilesystem(relativePath: "models/\(self.name).obj") { localUrl in
            self.cancellable = ModelEntity.loadModelAsync(contentsOf: localUrl)
                .sink(receiveCompletion: { loadCompletion in
               
                    switch loadCompletion{
                    case .failure(let error): print("Unable to load modelEntity for \(self.name). Error: \(error.localizedDescription)")
                case .finished:
                    break
                }
            }, receiveValue:{ modelEntity in
                result = modelEntity
                self.modelEntity = modelEntity

                // self.modelEntity?.scale *= self.scaleCompensation
                print("modelEntity for \(self.name) has been loaded")
                completion(result)
            })
        }
        return result
    }

And this is the console

022-03-06 01:43:27.800057+0300 MarsamApp[689:48039] Metal GPU Frame Capture Enabled
2022-03-06 01:43:27.801598+0300 MarsamApp[689:48039] Metal API Validation Enabled
2022-03-06 01:43:28.325928+0300 MarsamApp[689:48039] [AssetTypes] Registering library (/System/Library/PrivateFrameworks/CoreRE.framework/default.metallib) that already exists in shader manager. Library will be overwritten.
2022-03-06 01:43:28.413704+0300 MarsamApp[689:48242] 6.34.0 - [Firebase/Core][I-COR000008] The project's Bundle ID is inconsistent with either the Bundle ID in 'GoogleService-Info.plist', or the Bundle ID in the options if you are using a customized options. To ensure that everything can be configured correctly, you may need to make the Bundle IDs consistent. To continue with this plist file, you may change your app's bundle identifier to 'com.MarsamApp'. Or you can download a new configuration file that matches your bundle identifier from https://console.firebase.google.com/ and replace the current one.
2022-03-06 01:43:28.455746+0300 MarsamApp[689:48246] [general] *** -[NSKeyedUnarchiver validateAllowedClass:forKey:] allowed unarchiving safe plist type ''NSString' (0x1f345e358) [/System/Library/Frameworks/Foundation.framework]' for key 'NS.keys', even though it was not explicitly included in the client allowed classes set: '{(
    "'NSDate' (0x1f34536c0) [/System/Library/Frameworks/CoreFoundation.framework]",
    "'NSDictionary' (0x1f3453828) [/System/Library/Frameworks/CoreFoundation.framework]"
)}'. This will be disallowed in the future.
2022-03-06 01:43:28.477648+0300 MarsamApp[689:48246] 6.34.0 - [Firebase/Analytics][I-ACS023007] Analytics v.60900000 started
2022-03-06 01:43:28.478318+0300 MarsamApp[689:48246] 6.34.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see)
2022-03-06 01:43:28.491851+0300 MarsamApp[689:48246] 6.34.0 - [Firebase/Analytics][I-ACS800023] No pending snapshot to activate. SDK name: app_measurement
2022-03-06 01:43:28.498980+0300 MarsamApp[689:48242] 6.34.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled
2022-03-06 01:43:28.499730+0300 MarsamApp[689:48242] 6.34.0 - [Firebase/Analytics][I-ACS023220] Analytics screen reporting is enabled. Call +[FIRAnalytics logEventWithName:FIREventScreenView parameters:] to log a screen view event. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO (boolean) in the Info.plist
2022-03-06 01:43:28.634100+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/suFeatheringCreateMergedOcclusionMask.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.718313+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arKitPassthrough.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.720479+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/drPostAndComposition.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.722138+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arSegmentationComposite.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.724000+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute0.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.726142+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute1.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.727083+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute2.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.741687+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute3.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.742755+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute4.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.743783+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute5.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.744806+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute6.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.745873+0300 MarsamApp[689:48039] [Assets] Resolving material name 'engine:BuiltinRenderGraphResources/AR/arInPlacePostProcessCombinedPermute7.rematerial' as an asset path -- this usage is deprecated; instead provide a valid bundle
2022-03-06 01:43:28.747365+0300 MarsamApp[689:48039] [Foundation.Serialization] Json Parse Error line 18: Json Deserialization; unknown member 'EnableARProbes' - skipping.
2022-03-06 01:43:28.747443+0300 MarsamApp[689:48039] [Foundation.Serialization] Json Parse Error line 20: Json Deserialization; unknown member 'EnableGuidedFilterOcclusion' - skipping.
2022-03-06 01:43:29.018288+0300 MarsamApp[689:48039] throwing -10878
2022-03-06 01:43:29.020976+0300 MarsamApp[689:48039] throwing -10878
2022-03-06 01:43:29.021108+0300 MarsamApp[689:48039] throwing -10878
2022-03-06 01:43:29.021210+0300 MarsamApp[689:48039] throwing -10878
2022-03-06 01:43:29.021303+0300 MarsamApp[689:48039] throwing -10878
2022-03-06 01:43:29.021756+0300 MarsamApp[689:48039] throwing -10878
2022-03-06 01:43:29.021864+0300 MarsamApp[689:48039] throwing -10878
2022-03-06 01:43:29.021971+0300 MarsamApp[689:48039] throwing -10878
2022-03-06 01:43:29.022073+0300 MarsamApp[689:48039] throwing -10878
2022-03-06 01:43:29.222669+0300 MarsamApp[689:48250] [general] *** -[NSKeyedUnarchiver validateAllowedClass:forKey:] allowed unarchiving safe plist type ''NSString' (0x1f345e358) [/System/Library/Frameworks/Foundation.framework]' for key 'NS.keys', even though it was not explicitly included in the client allowed classes set: '{(
    "'NSDate' (0x1f34536c0) [/System/Library/Frameworks/CoreFoundation.framework]",
    "'NSDictionary' (0x1f3453828) [/System/Library/Frameworks/CoreFoundation.framework]"
)}'. This will be disallowed in the future.

Model is added to the scene
Warning (secondary thread): in AppendProperty at line 859 of sdf/path.cpp -- Can only append a property 'preliminary:anchoring:type' to a prim path (/)
Warning (secondary thread): in AppendProperty at line 859 of sdf/path.cpp -- Can only append a property 'triggers' to a prim path (/)
Warning (secondary thread): in AppendProperty at line 859 of sdf/path.cpp -- Can only append a property 'preliminary:anchoring:type' to a prim path (/)
modelEntity for Banana has been loaded

also, these are some sceneshots for the statistics
sheep object
frog object

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

前事休说 2025-01-19 13:47:34

为了快速加载和渲染,请使用最大多边形数为 100K 的 AR 模型(模型具有 20K 到 50K 多边形的纹理要“快得多”),并且纹理最大 2K rez(但是,1K质感更好)。大量的PBR材料也阻碍了快速加载。

For fast loading and rendering, use AR models with a max polygon count of 100K (models with 20K to 50K polygons are considerably "faster"), and textures of max 2K rez (however, 1K textures are better). A large amount of PBR materials also prevents fast loading.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文