From 681f3591bf2f3e38c70d4eda4ac9cc9b428de7f0 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 21 Nov 2022 20:59:48 +0200 Subject: [OKG/HWK2] Added the ability to change position in animation frame --- .../Homework 2/mannequin.html | 43 ++++++++++++++++++---- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html b/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html index c81921f..5213bad 100644 --- a/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html +++ b/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html @@ -164,7 +164,12 @@ 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]]}] + [ + 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]]}, + { x: 100, y: -10, z: 0 } + ] ] }; @@ -172,14 +177,17 @@ function animate(t) { 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] + start : t, + end : t + instr[1], + mannequin : instr[0], + A : instr[2], + B : instr[3], + cpos : instr[0].position.clone(), + npos : (instr.length === 4) ? null : coordSum(instr[0].position, instr[4]), }); } } @@ -187,7 +195,12 @@ 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); + var blendPer = (t - mo.start) / mo.end; + if (mo.A && mo.B) + mo.mannequin.posture = Mannequin.blend(mo.A, mo.B, blendPer); + if (mo.cpos) + mo.mannequin.position.set(...coordBlend(mo.cpos, mo.npos, blendPer)); + if (t <= mo.end) executeHooks.push(mo); } @@ -197,6 +210,22 @@ ** Помощни функции **/ + function coordSum(a, b) { + return { + x: a.x + b.x, + y: a.y + b.y, + z: a.z + b.z, + }; + } + + function coordBlend(a, b, per) { + return [ + a.x * (1.0 - per) + b.x * per, + a.y * (1.0 - per) + b.y * per, + a.z * (1.0 - per) + b.z * per, + ]; + } + function thc(value) { return new THREE.Color(value); } -- cgit v1.3.1-23-gd82d