Swift 如何在RealityKit中设置变换动画
在我的工作中,我已经找到了如何在一个对象的一个轴上进行旋转变换,现在我希望这是动画 在RealityKit中有没有办法做到这一点?带动画的旋转: 复制长方体的当前变换 将长方体设置为在z轴上旋转90度 将长方体移动到新变换超过10秒 动画翻译: 使用动画缩放: 带动画的旋转: 复制长方体的当前变换 将长方体设置为在z轴上旋转90度 将长方体移动到新变换超过10秒 动画翻译: 使用动画缩放: 以下是如何在RealityKit中设置对象动画为简单起见,我使用macOS应用程序制作: 或者,您可以使用animationPlaybackController播放3D应用程序中制作的现成动画: 以下是如何在RealityKit中设置对象动画为简单起见,我使用macOS应用程序制作: 或者,您可以使用animationPlaybackController播放3D应用程序中制作的现成动画:Swift 如何在RealityKit中设置变换动画,swift,xcode,animation,augmented-reality,realitykit,Swift,Xcode,Animation,Augmented Reality,Realitykit,在我的工作中,我已经找到了如何在一个对象的一个轴上进行旋转变换,现在我希望这是动画 在RealityKit中有没有办法做到这一点?带动画的旋转: 复制长方体的当前变换 将长方体设置为在z轴上旋转90度 将长方体移动到新变换超过10秒 动画翻译: 使用动画缩放: 带动画的旋转: 复制长方体的当前变换 将长方体设置为在z轴上旋转90度 将长方体移动到新变换超过10秒 动画翻译: 使用动画缩放: 以下是如何在RealityKit中设置对象动画为简单起见,我使用macOS应用程序制作: 或者,您可以使用
var rotationTransform = boxAnchor.steelBox?.transform
rotationTransform?.rotation = simd_quatf(angle: .pi/2, axis: [0,0,1])
boxAnchor.steelBox?.move(to: rotationTransform!, relativeTo: boxAnchor.steelBox?.parent, duration: 10, timingFunction: .easeInOut)
var translationTransform = boxAnchor.steelBox?.transform
translationTransform?.translation = SIMD3<Float>(x: 5, y: 0, z: 0)
boxAnchor.steelBox?.move(to: translationTransform!, relativeTo: boxAnchor.steelBox?.parent, duration: 10, timingFunction: .easeInOut)
var scaleTransform = boxAnchor.steelBox?.transform
scaleTransform?.scale = SIMD3<Float>(x: 1, y: 1, z: 1)
boxAnchor.steelBox?.move(to: scaleTransform!, relativeTo: boxAnchor.steelBox?.parent, duration: 10, timingFunction: .easeInOut)
import RealityKit
class ViewController: NSViewController {
@IBOutlet var arView: ARView!
let boxAnchor = try! Experience.loadBox()
override func awakeFromNib() {
boxAnchor.steelBox?.scale = [10, 10, 10]
let rotation = Transform(pitch: 0, yaw: 0, roll: .pi)
boxAnchor.steelBox?.orientation = rotation.rotation
arView.scene.anchors.append(boxAnchor)
boxAnchor.steelBox?.move(to: rotation,
relativeTo: boxAnchor.steelBox,
duration: 5.0,
timingFunction: .linear)
}
}
import RealityKit
class ViewController: NSViewController {
@IBOutlet var arView: ARView!
override func awakeFromNib() {
do {
let robot = try ModelEntity.load(named: "drummer")
let anchor = AnchorEntity(world: [0, -0.7, 0])
anchor.transform.rotation = simd_quatf(angle: .pi/4,
axis: [0, 1, 0])
arView.scene.anchors.append(anchor)
robot.scale = [1, 1, 1] * 0.1
anchor.children.append(robot)
robot.playAnimation(robot.availableAnimations[0].repeat(),
transitionDuration: 0.5,
startsPaused: false)
} catch {
fatalError("Cannot load USDZ asset.")
}
}
}