From 7da36542204ac7c5a99fbc9f111af450044fea25 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 28 Nov 2022 15:52:07 +0200 Subject: [OKG/HWK2] Reworked animationData parsing to allow higher robustness and faster framerates --- .../Homework 2/mannequin.html | 64 ++++++++++++---------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html b/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html index c903818..456620a 100644 --- a/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html +++ b/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html @@ -169,52 +169,58 @@ // или // [<времетраене в сек.>, <отместване на камера>, <отместване на гледане>, <не е отместване?>] - var executeHooks = []; - function animate(t) - { - t = Math.floor(t) / 100; - - var propInd = approxProp(animationData, t); - if (propInd) { - for (var instr of animationData[propInd]) { - if (instr[1].constructor === Array) { - executeHooks.push({ - start : t, - end : t+instr[0], + var executeBacklog = []; + function fillBacklog() { + for (var time in animationData) { + for (var instruction of animationData[time]) { + if (instruction[1].constructor === Array) { + executeBacklog.push({ + start : time, + end : time + instruction[0], iscamera : true, camposold : vecToArr(camera.position), - campos : (instr[3] || !instr[1]) ? instr[1] : arrSum(vecToArr(camera.position), instr[1]), + campos : (instruction[3] || !instruction[1]) ? instruction[1] : arrSum(vecToArr(camera.position), instruction[1]), camwatold : camLookAt.clone(), - camwatch : arrToVec(((instr[3] || !instr[2]) ? instr[2] : arrSum(vecToArr(camLookAt), instr[2]))), - isabsol : instr[3], + camwatch : arrToVec(((instruction[3] || !instruction[2]) ? instruction[2] : arrSum(vecToArr(camLookAt), instruction[2]))), + isabsol : instruction[3], }); } else { - executeHooks.push({ - start : t, - end : t + instr[0], + executeBacklog.push({ + start : time, + end : time + instruction[0], iscamera : false, - mannequin : instr[1], - A : (instr[2]) ? instr[2] : fixPostureY(instr[1].posture), - B : fixPostureY(instr[3]), - cpos : instr[1].position.clone(), - npos : (instr.length < 5 || !instr[4]) ? null : vecSum(instr[1].position, arrToVec(instr[4])), - crot : instr[1].rotation.clone(), - nrot : (instr.length < 6 || !instr[5]) ? null : vecMultScal(arrToVec(instr[5]), Math.PI / 2), + mannequin : instruction[1], + A : instruction[2], + B : fixPostureY(instruction[3]), + cpos : instruction[1].position.clone(), + npos : (instruction.length < 5 || !instruction[4]) ? null : vecSum(instruction[1].position, arrToVec(instruction[4])), + crot : instruction[1].rotation.clone(), + nrot : (instruction.length < 6 || !instruction[5]) ? null : vecMultScal(arrToVec(instruction[5]), Math.PI / 2), }); } } - delete animationData[propInd]; + } + } + + var executeHooks = []; + function animate(t) + { + t = Math.floor(t) / 100; + + while (executeBacklog.length > 0 && executeBacklog[0].start <= t) { + executeHooks.push(executeBacklog.shift()); } const executeLength = executeHooks.length; for (var i = 0; i < executeLength; i++) { var mo = executeHooks.shift(); - var blendPer = (t - mo.start) / mo.end; + var blendPer = (mo.start === mo.end) ? 1 : (t - mo.start) / mo.end; if (!mo.iscamera) { + if (!mo.A) mo.A = fixPostureY(mo.mannequin.posture); if (mo.B) mo.mannequin.posture = Mannequin.blend(mo.A, mo.B, blendPer); if (mo.npos) @@ -263,7 +269,6 @@ camera.position.z + vec[2]); } - /* * За анимация */ @@ -709,12 +714,13 @@ ], 5: [ [ - 3, jotaro, + 0, jotaro, null, {"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],[-38.1,-66.6,-62],[15],[-15,0,0],[10,10],[89.2,85,-124.8],[15],[15,0,0],[10,10]]} ] ], }; + fillBacklog(); -- cgit v1.3.1-26-gb76a