From b2cc734e39cf59fd311e66f8888f23ccbf107c55 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 21 Nov 2022 20:32:41 +0200 Subject: [OKG/HWK2] Implemented system for easy animation management and creation --- .../Homework 2/mannequin.html | 33 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html b/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html index f2a6986..c81921f 100644 --- a/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html +++ b/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html @@ -92,8 +92,9 @@ var jotaro = newJotaro(); //jotaro.rotation.x = Math.PI / 2; - jotaro.position.x = 50; - jotaro.position.z = -120; + jotaro.position.x = 120; + jotaro.position.z = 60; + jotaro.rotation.y = Math.PI / 2; scene.add(jotaro); // scene.add(newKira()); @@ -161,9 +162,35 @@ ** Анимация **/ + var animationData = { + 0: [ + [jotaro, 10, {"version":6,"data":[3.8,[0,-90,0],[0,0,-2],[0,0,5],[6,0,0],[0],[-6,-6,-0.6],[-6,0,0],[0],[6,6,-0.6],[7,-0.6,-5],[15],[-15,0,0],[10,10],[-7,0.6,-5],[15],[15,0,0],[10,10]]}, {"version":6,"data":[3.8,[0,-90,0],[-1.3,0,-2],[0,0,5],[6,0,0],[0],[-6,-6,-0.6],[-6,0,0],[0],[6,6,-0.6],[7,-0.6,-5],[15],[-15,0,0],[10,10],[-86.8,50.3,65.1],[15],[15,0,0],[10,10]]}] + ] + }; + + var executeHooks = []; function animate(t) { - //tailorShop.rotation.y += 0.005; + t = Math.floor(t) / 100; + if (animationData.hasOwnProperty(t)) { + for (var instr of animationData[t]) { + executeHooks.push({ + start: t, + end: t + instr[1], + mannequin: instr[0], + A: instr[2], + B: instr[3] + }); + } + } + + const executeLength = executeHooks.length; + for (var i = 0; i < executeLength; i++) { + var mo = executeHooks.shift(); + mo.mannequin.posture = Mannequin.blend(mo.A, mo.B, (t - mo.start) / mo.end); + if (t <= mo.end) + executeHooks.push(mo); + } } /** -- cgit v1.3.1-26-gb76a