Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Assuming 'content' contains the parsed animation data
- local parsed = {
- format_version = "1.8.0",
- animations = {
- ["animation.template"] = {
- animation_length = 10,
- bones = {
- head = {
- rotation= {
- ["0.0"] = {0, 0, 0},
- ["1.0"] = {0, -40, 0},
- ["2.0"] = {0, -130, 0},
- ["3.0"] = {0, -180, 0},
- ["4.0"] = {0, 160, 0},
- ["5.0"] = {0, 70, 0},
- ["6.0"] = {0, 50, 0},
- ["7.0"] = {0, -50, 0},
- ["8.0"] = {0, -10, 0},
- ["9.0"] = {0, 0, 0},
- ["10.0"] = {0, 0, 0}
- }
- }
- }
- }
- }
- }
- -- Create a table to hold the baked animations
- local animations = {}
- -- Loop through each animation entry in parsed data
- for name, data in pairs(parsed.animations) do
- local baked = {} -- Create a table to hold the baked animation data for this entry
- -- Loop through each bone in the animation data
- for part, rots in pairs(data.bones) do
- baked[part] = {} -- Create a table to hold the baked bone rotation data
- -- Check if the rotation data is a single set of rotations or a series
- if type(rots.rotation[1]) == "number" then
- baked[part][1] = rots.rotation -- If single, add it as-is
- else
- local indexes = {}
- -- Collect and sort the frame indexes
- for index, rot in pairs(rots.rotation) do
- table.insert(indexes, index)
- end
- table.sort(indexes, function(a, b) return tonumber(a) < tonumber(b) end)
- -- Reorganize the rotation data using the sorted indexes
- for new_index, real_index in ipairs(indexes) do
- baked[part][new_index] = rots.rotation[real_index]
- end
- end
- end
- -- Add the baked animation data to the animations table
- animations[name] = baked
- end
- -- Obtenir l'accès à l'animatronique connecté
- local animatronic = peripheral.wrap("top") -- Changez "top" si le périphérique est ailleurs
- -- Vérifier si le périphérique est bien un animatronique
- if not animatronic or not animatronic.setHeadRot then
- error("Aucun animatronique détecté sur le port 'top'. Vérifiez la connexion.")
- end
- -- Fonction pour jouer une animation
- function playAnimation(animName, animations, frameTime)
- local anim = animations[animName]
- if not anim then
- error("Animation non trouvée : " .. animName)
- end
- -- Obtenir la durée de l'animation et les os concernés
- local bones = anim
- local maxFrames = 0
- for _, frames in pairs(bones) do
- maxFrames = math.max(maxFrames, #frames)
- end
- -- Jouer les frames de l'animation
- for frame = 1, maxFrames do
- -- Appliquer les rotations pour chaque os
- for part, frames in pairs(bones) do
- local rotation = frames[frame]
- if rotation then
- if part == "head" then
- animatronic.setHeadRot(rotation[1], rotation[2], rotation[3])
- elseif part == "body" then
- animatronic.setBodyRot(rotation[1], rotation[2], rotation[3])
- elseif part == "left_arm" then
- animatronic.setLeftArmRot(rotation[1], rotation[2], rotation[3])
- elseif part == "right_arm" then
- animatronic.setRightArmRot(rotation[1], rotation[2], rotation[3])
- end
- end
- end
- -- Pousser les rotations vers l'animatronique
- animatronic.push()
- -- Attendre jusqu'à la prochaine frame
- sleep(frameTime)
- end
- end
- -- Exemple d'utilisation
- local frameTime = 0.5 -- 0.5 secondes par frame
- playAnimation("animation.template", animations, frameTime)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement