我试图在放置3D对象(在我的情况下为.sfb)时播放动画(如掉落或反弹),但我不知道该怎么做。
我尝试使用ValueAnimator来更改其颜色值,但效果很好,但这不是我想要的。
val alphaAnimator = ValueAnimator.ofFloat(0.0f, 1.0f, 0.0f)
alphaAnimator.addUpdateListener { animation ->
val animatedAlpha = animation.animatedValue as Float
modelRenderable.material.setFloat4(
MaterialFactory.MATERIAL_COLOR,
Color(0.0f, 0.0f, 1.0f * animatedAlpha, animatedAlpha)
)
}
alphaAnimator.repeatCount = ValueAnimator.INFINITE
alphaAnimator.duration = 1000
alphaAnimator.start()
val animatorSet = AnimatorSet()
animatorSet.playSequentially(
ObjectAnimator.ofFloat(modelRenderable, "translationY", 0.0f)
ObjectAnimator.ofFloat(modelRenderable, "translationY", 1.5f)
ObjectAnimator.ofFloat(modelRenderable, "translationY", 0.0f)
)
animatorSet.duration = 600
animatorSet.start()
但这给我一个错误“在com.google.ar.sceneform.rendering.ModelRenderable上找不到属性设置器方法setTranslationY
”。
答案 0 :(得分:0)
您应该为可渲染对象附加到的节点(而不是模型本身)设置动画。该节点具有setLocalPosition(Vector3)方法,可将其用于ObjectAnimator。因此,例如要对模型的位置进行动画处理,应执行以下操作:
ObjectAnimator nodeAnimator = ObjectAnimator.ofObject(
yourNode,
"localPosition",
new Vector3Evaluator(),
Vector3.zero(), new Vector3(0f, 1f, 0f));
然后,您可以设置持续时间,重复计数,模式等。您还可以在动画上缩放和旋转模型。