Animations guide #2
Replies: 2 comments
-
|
First, you should use a format supports animation like glTF. After you got the data, use the format's ModelFileLoader (or just use ModelFileLoaders if you don't know which loader to use, and it will probe the correct one for you). Loaded data will be in ModelFileLoader.LoadResult. val result = ModelFileLoaders.probeAndLoad(path) ?: error("No loader probed")
val model = result.model ?: error("No model")
val rawAnimation = result.animations?.firstOrNull() ?: error("No animation")However, you can't use the raw animation data and raw model data directly. You should pass the Model to ModelLoader, and pass Animation object to AnimationLoader to load them. val scene = ModelLoader().loadModel(model)
val animation = AnimationLoader.load(scene, rawAnimation)Once you have animation data, you should apply it on a ModelInstance. Model instance stores data for each instance of model, so they can have different state. If your model is static (like the example ball_block), you can share one instance, otherwise you should manage ModelInstance yourself for each item to be rendered (such as entities). Create a model instance: val instance = ModelInstance(scene, ModelBufferManager.getEntry(scene))Now you have model instance and animation data, you can apply the animation to model instance. // On every frame
val time = 3f // seconds
animation.apply(instance, time)
// Before rendering, you should call update() if you changed the instance
instance.update()
instance.render(matrix, light)Take care of reference counting! Many class implements RefCount interface, and you should call increaseReferenceCount() and decreaseReferenceCount() to maintain the reference count. You can pass JVM arguments |
Beta Was this translation helpful? Give feedback.
-
|
It works perfectly. I just had to make a few adjustments to get it to work properly in Java, but it works great. Thank you very much. I will make incredible use of the API. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
How would the API be used to reproduce the model's animations?
Beta Was this translation helpful? Give feedback.
All reactions