|
| 1 | +// Lightweight mock of THREE.js for unit tests. |
| 2 | +// Only stubs the APIs actually used by src/lib/ modules. |
| 3 | +// Grow this file incrementally as more tests need additional THREE APIs. |
| 4 | + |
| 5 | +class Vector3 { |
| 6 | + constructor(x = 0, y = 0, z = 0) { |
| 7 | + this.x = x; |
| 8 | + this.y = y; |
| 9 | + this.z = z; |
| 10 | + } |
| 11 | + set(x, y, z) { this.x = x; this.y = y; this.z = z; return this; } |
| 12 | + clone() { return new Vector3(this.x, this.y, this.z); } |
| 13 | + add(v) { this.x += v.x; this.y += v.y; this.z += v.z; return this; } |
| 14 | + sub(v) { this.x -= v.x; this.y -= v.y; this.z -= v.z; return this; } |
| 15 | + normalize() { |
| 16 | + const len = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); |
| 17 | + if (len > 0) { this.x /= len; this.y /= len; this.z /= len; } |
| 18 | + return this; |
| 19 | + } |
| 20 | + multiplyScalar(s) { this.x *= s; this.y *= s; this.z *= s; return this; } |
| 21 | + lerp(v, t) { |
| 22 | + this.x += (v.x - this.x) * t; |
| 23 | + this.y += (v.y - this.y) * t; |
| 24 | + this.z += (v.z - this.z) * t; |
| 25 | + return this; |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +class Vector2 { |
| 30 | + constructor(x = 0, y = 0) { |
| 31 | + this.x = x; |
| 32 | + this.y = y; |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +const MathUtils = { |
| 37 | + lerp: (x, y, t) => x + (y - x) * t, |
| 38 | +}; |
| 39 | + |
| 40 | +class Color { |
| 41 | + constructor(color) { |
| 42 | + this.value = color; |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +class AnimationMixer { |
| 47 | + constructor() { |
| 48 | + this.time = 0; |
| 49 | + } |
| 50 | + clipAction() { |
| 51 | + return { |
| 52 | + reset: function() { return this; }, |
| 53 | + setLoop: function() { return this; }, |
| 54 | + setEffectiveTimeScale: function() { return this; }, |
| 55 | + setEffectiveWeight: function() { return this; }, |
| 56 | + play: function() {}, |
| 57 | + stop: function() {}, |
| 58 | + fadeIn: function() { return this; }, |
| 59 | + fadeOut: function() { return this; }, |
| 60 | + isRunning: function() { return false; }, |
| 61 | + time: 0, |
| 62 | + }; |
| 63 | + } |
| 64 | + stopAllAction() {} |
| 65 | + addEventListener() {} |
| 66 | + update() {} |
| 67 | +} |
| 68 | + |
| 69 | +class AnimationClip { |
| 70 | + static findByName(clips, name) { |
| 71 | + return clips.find(c => c.name === name); |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +class EventDispatcher { |
| 76 | + constructor() { |
| 77 | + this._listeners = {}; |
| 78 | + } |
| 79 | + addEventListener(type, listener) { |
| 80 | + if (!this._listeners[type]) this._listeners[type] = []; |
| 81 | + this._listeners[type].push(listener); |
| 82 | + } |
| 83 | + removeEventListener(type, listener) { |
| 84 | + if (this._listeners[type]) { |
| 85 | + this._listeners[type] = this._listeners[type].filter(l => l !== listener); |
| 86 | + } |
| 87 | + } |
| 88 | + dispatchEvent(event) { |
| 89 | + if (this._listeners[event.type]) { |
| 90 | + this._listeners[event.type].forEach(l => l(event)); |
| 91 | + } |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +class Quaternion { |
| 96 | + constructor(x = 0, y = 0, z = 0, w = 1) { |
| 97 | + this.x = x; this.y = y; this.z = z; this.w = w; |
| 98 | + } |
| 99 | + identity() { this.x = 0; this.y = 0; this.z = 0; this.w = 1; return this; } |
| 100 | + copy(q) { this.x = q.x; this.y = q.y; this.z = q.z; this.w = q.w; return this; } |
| 101 | + clone() { return new Quaternion(this.x, this.y, this.z, this.w); } |
| 102 | +} |
| 103 | + |
| 104 | +class Euler { |
| 105 | + constructor(x = 0, y = 0, z = 0, order = "XYZ") { |
| 106 | + this.x = x; this.y = y; this.z = z; this.order = order; |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +class Matrix4 { |
| 111 | + constructor() { |
| 112 | + this.elements = [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1]; |
| 113 | + } |
| 114 | + identity() { this.elements = [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1]; return this; } |
| 115 | + getInverse() { return this; } |
| 116 | + multiplyMatrices() { return this; } |
| 117 | + setFromMatrixScale() { return this; } |
| 118 | +} |
| 119 | + |
| 120 | +// Material stubs |
| 121 | +class MeshBasicMaterial { constructor(opts) { Object.assign(this, opts); } } |
| 122 | +class MeshLambertMaterial { constructor(opts) { Object.assign(this, opts); } } |
| 123 | +class MeshPhongMaterial { constructor(opts) { Object.assign(this, opts); } } |
| 124 | +class MeshDepthMaterial { constructor(opts) { Object.assign(this, opts); } } |
| 125 | +class MeshStandardMaterial { constructor(opts) { Object.assign(this, opts); } } |
| 126 | +class MeshToonMaterial { constructor(opts) { Object.assign(this, opts); } } |
| 127 | + |
| 128 | +// Encoding constants |
| 129 | +const LinearEncoding = 3000; |
| 130 | +const sRGBEncoding = 3001; |
| 131 | +const GammaEncoding = 3007; |
| 132 | +const RGBEEncoding = 3002; |
| 133 | +const RGBM7Encoding = 3004; |
| 134 | +const RGBM16Encoding = 3005; |
| 135 | +const RGBDEncoding = 3006; |
| 136 | +const BasicDepthPacking = 3200; |
| 137 | +const RGBADepthPacking = 3201; |
| 138 | + |
| 139 | +// Side constants |
| 140 | +const FrontSide = 0; |
| 141 | +const BackSide = 1; |
| 142 | +const DoubleSide = 2; |
| 143 | + |
| 144 | +const LoopRepeat = 2201; |
| 145 | +const LoopOnce = 2200; |
| 146 | + |
| 147 | +module.exports = { |
| 148 | + Vector3, |
| 149 | + Vector2, |
| 150 | + Quaternion, |
| 151 | + Euler, |
| 152 | + Matrix4, |
| 153 | + MathUtils, |
| 154 | + Color, |
| 155 | + AnimationMixer, |
| 156 | + AnimationClip, |
| 157 | + EventDispatcher, |
| 158 | + MeshBasicMaterial, |
| 159 | + MeshLambertMaterial, |
| 160 | + MeshPhongMaterial, |
| 161 | + MeshDepthMaterial, |
| 162 | + MeshStandardMaterial, |
| 163 | + MeshToonMaterial, |
| 164 | + LinearEncoding, |
| 165 | + sRGBEncoding, |
| 166 | + GammaEncoding, |
| 167 | + RGBEEncoding, |
| 168 | + RGBM7Encoding, |
| 169 | + RGBM16Encoding, |
| 170 | + RGBDEncoding, |
| 171 | + BasicDepthPacking, |
| 172 | + RGBADepthPacking, |
| 173 | + FrontSide, |
| 174 | + BackSide, |
| 175 | + DoubleSide, |
| 176 | + LoopRepeat, |
| 177 | + LoopOnce, |
| 178 | +}; |
0 commit comments