animation - RealityKit:更改 ModelEntity 的比例而不改变其位置

标签 animation augmented-reality realitykit ios-animations

我有一个从 A 点移动到 B 点的 ModelEntity 动画,需要一段时间才能完成。当用户点击 ModelEntity 时,我也想向 ModelEntity 添加收缩动画。

我尝试将缩放动画直接添加到 ModelEntity View .move 但问题是我当前的模型转换是模型预计结束的位置。导致 ModelEnity 跳转到动画末尾。

var transform = modelEntity.transform 
transform.scale *= factor
modelEntity.move(to: transform, relativeTo: modelEntity.parent, duration: duration) // will not work because the translation of the transform is already at the end of the animation

有没有办法将缩放动画添加到已经位于不同动画中间的 ModelEntity 并使它们一起工作?

最佳答案

使用 Xcode 14.2 进行测试。 :

import RealityKit
import CoreGraphics

extension Entity {
    
    func scaleAnimated(with value: SIMD3<Float>, duration: CGFloat) {
        
        var scaleTransform: Transform = Transform()
        scaleTransform.scale = value
        self.move(to: self.transform, relativeTo: self.parent)
        self.move(to: scaleTransform, relativeTo: self.parent, duration: duration)
        
    }
    
}

用法:

var scaleTransform: Transform = Transform()
        
if exampleEntity.scale.x == 1.0 {
   exampleEntity.scaleAnimated(with: [0.012, 0.012, 0.012], duration: 1.0)
} else {
    exampleEntity.scaleAnimated(with: [1.0, 1.0, 1.0], duration: 1.0)
}
        

关于animation - RealityKit:更改 ModelEntity 的比例而不改变其位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71144866/

相关文章:

javascript - 在 Web Audio API 中精确播放/暂停/搜索大型音频文件的最佳方式

iphone - 用于通过标记获取相机角度的库

python - 使用 OpenCV Python 计算相机世界位置

swift - RealityKit – 如何使实体及其 PBR Material 透明?

swift - 如何在 ARKit 的重建网格中获取顶点位置?

javascript - jQuery 无尽-动画

animation - Flutter 反向动画完整监听器

java - 添加组件到JPanel,屏幕上没有变化

ios - 如何在 ARKit 应用程序运行时加载 SCN 或 glTF 模型?

swift - RealityKit - 异步模型加载不起作用