Recursively searching the realityKitContentBundle

Hi

Hopefully someone can share some ideas on how to accomplish this.

I know we can load models from realityKitContentBundle like

let model = try? await Entity(named: “testModel”, in: realityKitContentBundle)

But this is in the root of RealityKitContent.rkassets , if I have the models in some subfolder then I have to add the complete path like

let model = try? await Entity(named: “/superModels/testModel”, in: realityKitContentBundle)

What I want is to be able to search recursively in all folders for that file as I have several subfolders with different models.

Any suggestion ?

Thanks in advance.

Guillermo

Answered by DTS Engineer in 818325022

Good news. You don’t need to combine all your USDA files into one.

The recommended approach is adding a Reality Composer Pro project, containing your USDA files, to your Xcode project.

This creates a Swift package (.reality file) from which you can find and create Entities (possibly described by multiple USDA files). In other words, take advantage of Reality Composer Pro to package your USDA assets so they can be used in your Xcode project as Entities.

For more details check out Meet Reality Composer Pro.

If you prefer to instantiate Entities directly from USDA both init and load functions can handle a USDA file composed of other USDA files by reference. Note: an asset reference must exist within the app's sandbox.

For more information about USD composition and references watch this section of Understand USD fundamentals.

Hi,

init(named:in:) doesn't seem flexible enough for what you're trying to do.

named: is a "scene name if loading from a .reality file." and that's a fixed value / reference / handle.

What you seek is more like findEntity(named:) but for loading an Entity versus recursively searching a previously loaded Entity's hierarchy.

So that's an option to consider if you have available resources:

  1. init(named:in:) the root Entity (main scene) and all of its subfolders
  2. Recursively search for Entities at runtime as needed with findEntity(named:)

... and if you're resource constrained, instead of lazy loading in 2, create all required Entities upfront and discard the Entity from 1.

Right now I have a bunch of .usda files in different folders, in order to use findEntity(named:) I would need to reorganize the assets and put all the models into a single .usda right ?. That's the only way ?

Good news. You don’t need to combine all your USDA files into one.

The recommended approach is adding a Reality Composer Pro project, containing your USDA files, to your Xcode project.

This creates a Swift package (.reality file) from which you can find and create Entities (possibly described by multiple USDA files). In other words, take advantage of Reality Composer Pro to package your USDA assets so they can be used in your Xcode project as Entities.

For more details check out Meet Reality Composer Pro.

If you prefer to instantiate Entities directly from USDA both init and load functions can handle a USDA file composed of other USDA files by reference. Note: an asset reference must exist within the app's sandbox.

For more information about USD composition and references watch this section of Understand USD fundamentals.

Recursively searching the realityKitContentBundle
 
 
Q