Finally I was able to figure out how to save custom components and load them from file system. The solution is save it as reality file and not usdz. This is kinda a round about way as Reality Composer pro doesn't support exporting files directly to reality file. It would be great if this functionality is added to Reality Composer pro.
Post
Replies
Boosts
Views
Activity
@Vision Pro Engineer would like to know if there are any updates on this.
An Overview of RealityKit Codable Components:
Since "git.rwth-aachen.de" is not in the permitted domain list, I used the inline codes for links.
Source Repo link : https://git.rwth-aachen.de/apple-realitykit-usdz/usdz_files
The repository explores the inconsistencies with custom components when loading a scene exported as usdz from file system(here after refered as exported file) and loading the scene directly from the bundle(here after refered as internal file). The expected behaviour is that after parsing both the external file and internal file both should have the same values for the custom components.
Reality Composer Pro supports a small set of primitive data types which provides the functionality to create and modifying the Scenes with no explicit coding requirments. The following code block shows the all possible primitive codable compontents.
public struct TestComponentBool : Component, Codable {
public var someBool : Bool = false
public init() {}
}
public struct TestComponentFloat : Component, Codable {
public var someFloatNumber : Float = 0
public init() {}
}
public struct TestComponentInt : Component, Codable {
public var someIntNumber : Int = 0
public init() {}
}
public struct TestComponentUint : Component, Codable {
public var someIntNumber : UInt = 0
public init() {}
}
public struct TestComponentString : Component, Codable {
public var someString : String = "Hello world !"
public init() {}
}
public struct TestComponentSimdFloat : Component, Codable {
public var someFloatArray : SIMD3<Float> = [0,0,0]
public init() {}
}
public struct TestComponentChoice : Component, Codable {
public enum SomeChoice : String, Codable{
case choice1, choice2, choice3
}
public var someChoice : SomeChoice = .choice1
public init() {}
}
To see the implementation of the above components, check the RealityKitContent package in CustomComponentsParser available in https://git.rwth-aachen.de/apple-realitykit-usdz/customcomponentsparser/-/tree/main/Packages/RealityKitContent.
When exporting a scene with the all above components to a seperate .usdz file, and then loading it in an app has custom components registered, the values stored in these components those match the value when it was exported, leading to inconsistencies and EXC_BAD_ACCESS in the worst case when the component contains a String type.
To reproduce the error,
Export Scene.usda in to RealityKitContent package with Reality Composer Pro and share to the simulator. Alternatively the usdz file in the source repository https://git.rwth-aachen.de/apple-realitykit-usdz/usdz_files can be directly shared to the simulator.
Build and install the app in the link https://git.rwth-aachen.de/apple-realitykit-usdz/customcomponentsparser/.
Open the CustomComponentsParser app
Click on Load from internal storage to load the Scene entity.
Click on Import usdz file and select the exported file shared to the simulator.