我正在制作一个增强现实应用程序,我需要在运行时加载3d动画(在.fbx文件中)。是否可以使用arcore来加载这个动画并显示给用户?
你的fbx文件应该有动画,你可以检查。sfb文件动画数组。当您渲染3d模型时,您可以使用该动画并播放。
val modelData = it.getAnimationData(0)
val modelAnimator = ModelAnimator(modelData, it)
modelAnimator?.start()
完整代码:
ModelRenderable.builder()
.setSource(fragment.context, model)
.build()
.thenAccept {
val anchorNode = AnchorNode(anchor)
val skeletonNode = SkeletonNode()
skeletonNode.localScale = Vector3(0.2f, 0.2f, 0.2f)
skeletonNode.setParent(anchorNode)
skeletonNode.renderable = it
skeletonNode.setOnTapListener { hitTestResult: HitTestResult, motionEvent: MotionEvent ->
listener.onClick()
}
anchorNode.setOnTapListener { hitTestResult: HitTestResult, motionEvent: MotionEvent ->
listener.onClick()
}
it.material.setTexture("baseColor", texture)
fragment.arSceneView.scene.addChild(anchorNode)
val count: Int = it.animationDataCount
if (count > 0) {
val modelData = it.getAnimationData(0)
val modelAnimator = ModelAnimator(modelData, it)
modelAnimator?.start()
}
}
.exceptionally {
return@exceptionally null
}