Replace model static entity onto animated model without losing animations / Multiple animations for dynamic assets

Is it possible to replace the model from one ModelEntity onto another ModelEntity without breaking the animations?

I have a ModelEntity object that I would like to apply animations to, but this ModelEntity is dynamically generated without animations. (baseEntity)

So for each animation, I load an individual usdz with using ModelEntity.loadModel (animEntity). I add the animEntity as a child to their parentEntity. Then I add the materials from the baseEntity onto the animEntity.

animEntity.model?.materials = baseMaterials

parentEntity.addChild(animEntity, preservingWorldTransform: false)

This does work, but causes texture / model issues, due to the baseEntity having a completely different mesh than the animEntity.

Is there a better way to accomplish this?

Other implementations I have tried:

  1. animEntity.model?.mesh = MeshResource.generate(from: baseModel.mesh.contents)
  2. animEntity.model!.mesh.replace(with: baseEntity.model!.mesh.contents)
  3. animEntity.model?.mesh.replaceAsync(with: baseModel.mesh.contents)
  4. animEntity.components[ModelComponent.self] = baseEntity.components[ModelComponent.self]
Post not yet marked as solved Up vote post of HunterHarris Down vote post of HunterHarris
719 views

Replies

Is it possible to use animations from one model to play on a different model with same skeleton? I know this is possible in SceneKit AR implementation, but I am having a lot of problems doing this in RealityKit. Thanks for any advice.