skip to Main Content

I am trying to load multiple Mixamo 3d animations on one USDZ model. All the exported animations are USDZ animation files and the main USDZ model file have the same exact rig. All animations were exported at the same time but stored in separate USDZ files. The animation works if I play the animation that comes with the created "modelEntity" but when I try to update the animation from another USDZ file I get this error:

Cannot find a BindPoint for any bind path: "", "", "Bboy_Uprock.mixamorig_Hips", "Bboy_Uprock.mixamorig_Hips.SkeletalPose.SkeletalPoses[0]"

Running out of ideas.

import SwiftUI
import RealityKit
import ARKit
import Combine
import Foundation

struct ContentView: View {
    @State private var animationTrigger = false
    @StateObject private var arViewModel = ARViewModel()

    var body: some View {
        VStack {
            ARViewContainer(animationTrigger: $animationTrigger, viewModel: arViewModel)
                .edgesIgnoringSafeArea(.all)

            Button("Change Animation") {
                animationTrigger.toggle()
            }
            .padding()
            .background(Color.blue)
            .foregroundColor(.white)
            .cornerRadius(10)
        }
    }
}

struct ARViewContainer: UIViewRepresentable {
    @Binding var animationTrigger: Bool
    @ObservedObject var viewModel: ARViewModel 
    @State var mainModelEntity: ModelEntity?
    
    func makeUIView(context: Context) -> ARView {
        let arView = ARView(frame: .zero)
        setupARView(arView)
        return arView
    }
    
    func updateUIView(_ uiView: ARView, context: Context) {
           if animationTrigger, let mainModelEntity = viewModel.mainModelEntity {
               print("Applying new animation!")
               applyRandomAnimation(to: mainModelEntity, in: uiView)
           }
       }
    
    
    private func setupARView(_ arView: ARView) {
        let config = ARWorldTrackingConfiguration()
        config.planeDetection = [.horizontal, .vertical]
        arView.session.run(config)
        
        let mainModelName = "BboyUprock.usdz"
       
        if let modelEntity = try? ModelEntity.loadModel(named: mainModelName) {
            modelEntity.scale = SIMD3<Float>(0.01, 0.01, 0.01)

            DispatchQueue.main.async {
                self.viewModel.mainModelEntity = modelEntity
            }
            
            if let animation = modelEntity.availableAnimations.first {
                modelEntity.playAnimation(animation.repeat())
                print("Playing first animation")
            } else {
                print("No animations found in the model")
            }
            
            let anchor = AnchorEntity(plane: .horizontal)
            anchor.addChild(modelEntity)
            arView.scene.addAnchor(anchor)
        } else {
            fatalError("Failed to load main model")
        }
    }
    
    
    private func applyRandomAnimation(to entity: ModelEntity, in arView: ARView) {
        
        let animationModelNames = ["BboyUprock.usdz", "HipHopDancing1.usdz", "HipHopDancing2.usdz", "HipHopDancing3.usdz"]
        
        var animations = [AnimationResource]()
        
        for animModelName in animationModelNames {
            if let animationEntity = try? Entity.load(named: animModelName) {
                if let animation = animationEntity.availableAnimations.first {
                    animations.append(animation)
                } else {
                    print("No animations found in (animModelName)")
                }
            } else {
                print("Failed to load entity from (animModelName)")
            }
        }
        
        if let randomAnimation = animations.randomElement() {
            print("Attempting to play animation with bind paths:")
                      
            entity.playAnimation(randomAnimation.repeat(duration: .infinity), transitionDuration: 1.25, startsPaused: false)
            
            print("Playing animation from (animations.count) loaded animations")
        } else {
            print("No animations available to play")
        }
    }
}

class ARViewModel: ObservableObject {
    @Published var mainModelEntity: ModelEntity?
}

2

Answers


  1. I believe RealityKit Composer Pro will get you there.

    Login or Signup to reply.
  2. Having this issue right now, did you come around the solution?

    Thanks a lot

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search