| 45 | } |
| 46 | |
| 47 | function slerpQuaternion(q1, q2, t) { |
| 48 | let dot = q1[0] * q2[0] + q1[1] * q2[1] + q1[2] * q2[2] + q1[3] * q2[3]; |
| 49 | if (dot < 0) { |
| 50 | q2 = [-q2[0], -q2[1], -q2[2], -q2[3]]; |
| 51 | dot = -dot; |
| 52 | } |
| 53 | if (dot > 0.9995) { |
| 54 | const result = [ |
| 55 | q1[0] + t * (q2[0] - q1[0]), |
| 56 | q1[1] + t * (q2[1] - q1[1]), |
| 57 | q1[2] + t * (q2[2] - q1[2]), |
| 58 | q1[3] + t * (q2[3] - q1[3]) |
| 59 | ]; |
| 60 | const len = Math.sqrt(result[0] * result[0] + result[1] * result[1] + result[2] * result[2] + result[3] * result[3]); |
| 61 | return [result[0] / len, result[1] / len, result[2] / len, result[3] / len]; |
| 62 | } |
| 63 | const theta0 = Math.acos(dot); |
| 64 | const theta = theta0 * t; |
| 65 | const sinTheta = Math.sin(theta); |
| 66 | const sinTheta0 = Math.sin(theta0); |
| 67 | const s0 = Math.cos(theta) - dot * sinTheta / sinTheta0; |
| 68 | const s1 = sinTheta / sinTheta0; |
| 69 | return [ |
| 70 | s0 * q1[0] + s1 * q2[0], |
| 71 | s0 * q1[1] + s1 * q2[1], |
| 72 | s0 * q1[2] + s1 * q2[2], |
| 73 | s0 * q1[3] + s1 * q2[3] |
| 74 | ]; |
| 75 | } |
| 76 | |
| 77 | function sampleSampler(sampler, time, path) { |
| 78 | const input = sampler.input; |