Col*_*gic 8 augmented-reality swift arkit realitykit reality-composer
model通过在a 的属性上设置材质的颜色ModelEntity,我可以更改对象的不透明度/alpha。但如何将其动画化呢?我的目标是使对象具有完全不透明度的动画,然后让它们淡入设定的不透明度,例如 50%。
有了SCNAction.fadeOpacityin ,这变得特别容易SCNNode。SceneKit
let fade = SCNAction.fadeOpacity(by: 0.5, duration: 0.5)
node.runAction(fade)
Run Code Online (Sandbox Code Playgroud)
AnEntity符合HasTransform,但这仅允许您对比例、位置和方向进行动画处理。与淡入或淡出之类的材质动画无关。如果您创建用于动画隐藏或显示的行为,则效果在 RealityComposer 中,但似乎没有类似的功能来HasTransform提供动画不透明度的功能。
我一直在文档中寻找一些东西,我的下一个想法本质上是创建一个自定义动画来替换这种行为,但它似乎应该可用,但我只是没有找到它。
我使用不同的技术对其进行了测试,并得出了悲伤的结论:您无法在 RealityKit 框架中对材质的不透明度进行动画处理,因为
RealityKit materials don't support animation at runtime(目前我希望如此)。让我们一起等待RealityKit的重大更新吧。
这是您可以用于测试的代码
(arView.alpha属性正常工作):
import UIKit
import RealityKit
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
arView.alpha = 1.0
opacityAnimation()
}
func opacityAnimation() {
UIView.animate(withDuration: 5.0,
animations: {
self.arView.alpha = 0.0
})
}
}
Run Code Online (Sandbox Code Playgroud)
并使用此代码片段以确保动画无法正常工作
(没有动画过程,只是赋值):
import UIKit
import RealityKit
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
let tetheringAnchor = AnchorEntity(world: [0,0,0])
var material = SimpleMaterial()
let mesh: MeshResource = .generateSphere(radius: 0.5)
var sphereComponent: ModelComponent? = nil
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
material.metallic = .float(1.0)
material.roughness = .float(0.0)
material.baseColor = .color(.red)
sphereComponent = ModelComponent(mesh: mesh,
materials: [material])
tetheringAnchor.components.set(sphereComponent!)
arView.scene.anchors.append(tetheringAnchor)
opacityAnimation()
}
func opacityAnimation() {
UIView.animate(withDuration: 5.0,
animations: {
self.material.metallic = .float(1.0)
self.material.roughness = .float(0.0)
self.material.baseColor = .color(.green)
self.sphereComponent = ModelComponent(mesh: self.mesh,
materials: [self.material])
self.tetheringAnchor.components.set(self.sphereComponent!)
self.arView.scene.anchors.append(self.tetheringAnchor)
})
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2437 次 |
| 最近记录: |