TimLee9024 / MCglTF

glTF library for Minecraft Modding
MIT License
7 stars 12 forks source link

How to use multiple animations #2

Closed linglong233 closed 2 years ago

TimLee9024 commented 2 years ago

In example code, it play all animation clips simultaneously in the glTF file.

for(Animation animation : animations) {
    animation.update(net.minecraftforge.client.model.animation.Animation.getWorldTime(mc.level, net.minecraftforge.client.model.animation.Animation.getPartialTickTime()) % animation.getEndTimeS());
}

You can determine which animation clip need to play based on various condition.

You can also add name or extras in each animation clip and get these properties (object from getExtras() need to deserialize by Gson) via getAnimationModels() during onModelLoaded(RenderedGltfModel renderedModel). This give you a concept of ID or filter/categorizer for animation clips, if the order and count of animation clips is unspecifed for a glTF model.


Chinese translation: 在範例程式碼中,預設是同時撥放所有的動畫片段:

for(Animation animation : animations) {
    animation.update(net.minecraftforge.client.model.animation.Animation.getWorldTime(mc.level, net.minecraftforge.client.model.animation.Animation.getPartialTickTime()) % animation.getEndTimeS());
}

你可以根據一些條件(例如物品的NBT、實體或方塊實體的成員變數),來決定需要撥放的動畫片段。

假如你的glTF模型的動畫片段的數量和排序是不固定的,你可以在glTF模型檔的每個動畫片段中加入nameextras等額外資料,並在onModelLoaded(RenderedGltfModel renderedModel)時透過getAnimationModels()來存取並反序列化其中的資料(從getExtras()取得的物件要透過Gson反序列化),這些資料即可成為該動畫片段能撥放的附加條件之一。

linglong233 commented 2 years ago

OK Thanks