最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

animation - RealityKit scene doesn't call System update() unless I move the volume - Stack Overflow

programmeradmin11浏览0评论

Okay, I'm missing something fundamental here. I want to create a scene for visionOS with a continuously rotating cube. I set up my scene and register a System to do the rotation updates.

When I run on the simulator or headset, the first 20 updates happen pretty quickly, then slow to a stop, and the cube stops rotating. If I grab the volume handle and move the volume around, the scene updates and the cube rotates as long as I'm moving it.

How do I get the cube to rotate continuously without interacting with the volume?

import SwiftUI
import RealityKit

struct ContentView: View {
    var body: some View {
        VStack {
            RealityView { content in
                // Create a shiny red cube entity
                let cube = MeshResource.generateBox(size: [0.3, 0.3, 0.3])
                let matl = SimpleMaterial(color: .red, isMetallic: false)
                let cubeEntity = ModelEntity(mesh: cube, materials: [matl])
                cubeEntity.name = "cube"
                content.add(cubeEntity)

                // Register the "SpinSystem" system to rotate it
                SpinSystem.registerSystem()
            }
        }
    }
}

// A System to incrementally spin the cube every frame
class SpinSystem : System {
    var theta: Float = 0
    var count: Int = 0
    
    required init(scene: RealityFoundation.Scene) {}

    func update(context: SceneUpdateContext) {
        count += 1
        print("update \(count)")
        if let cubeEntity = context.scene.findEntity(named: "cube") {
            theta += 0.01
            cubeEntity.transform.rotation = simd_quatf(angle: theta, axis: simd_float3(1, 0, 0))
        }
    }
}

update 1
update 2
cannot add handler to 0 from 1 - dropping
update 3
update 4
update 5
update 6
update 7
cannot add handler to 0 from 1 - dropping
update 8
update 9
...
update 21
update 22
update 23
发布评论

评论列表(0)

  1. 暂无评论