Last active
August 2, 2024 19:27
-
-
Save eospi/ff37e4fa2e1333544b46054f98ca43cf to your computer and use it in GitHub Desktop.
RealityKit Asynchronous Loading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
func loadEntityAsync() { | |
// Create an world anchor at the origin and add it to the scene | |
let anchor = AnchorEntity(world: [0,0,0]) | |
arView.scene.addAnchor(anchor) | |
let usdzPath = "path/to/usdz/asset" | |
// Load the asset asynchronously | |
var cancellable: AnyCancellable? = nil | |
cancellable = ModelEntity.loadModelAsync(named: usdzPath) | |
.sink(receiveCompletion: { error in | |
print("Unexpected error: \(error)") | |
cancellable?.cancel() | |
}, receiveValue: { entity in | |
anchor.addChild(entity) | |
cancellable?.cancel() | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pretty nice 👍 It helped me a lot!!