| 7 | const { |
| 8 | PREVIEW_3MF_TARGET_TRIANGLES, |
| 9 | extractAllMeshesFast, |
| 10 | simplifyForPreview, |
| 11 | shouldUseFastPath, |
| 12 | modelHasPlacementTransforms |
| 13 | } = require('./threemf-mesh-extract.js'); |
| 14 | |
| 15 | /** Identity 4x4 matrix, column-major (THREE.Matrix4 layout). */ |
| 16 | function mat4Identity() { |
| 17 | return new Float32Array([ |
| 18 | 1, 0, 0, 0, |
| 19 | 0, 1, 0, 0, |
| 20 | 0, 0, 1, 0, |
| 21 | 0, 0, 0, 1 |
| 22 | ]); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Parse 3MF transform="a b c d e f g h i tx ty tz" into a column-major 4x4 |
| 27 | * matching THREE.3MFLoader / the 3MF spec. |
| 28 | */ |
| 29 | function parseTransformAttr(transform) { |
| 30 | if (!transform || typeof transform !== 'string') return null; |
| 31 | const t = transform.trim().split(/\s+/).map(parseFloat); |
| 32 | if (t.length < 12 || t.some(n => Number.isNaN(n))) return null; |
| 33 | // THREE.Matrix4.set(n11,n12,n13,n14, n21,...) then .elements is column-major |
| 34 | return new Float32Array([ |
| 35 | t[0], t[1], t[2], 0, |
| 36 | t[3], t[4], t[5], 0, |
| 37 | t[6], t[7], t[8], 0, |
| 38 | t[9], t[10], t[11], 1 |
| 39 | ]); |
| 40 | } |
| 41 | |
| 42 | function mat4Multiply(a, b) { |
| 43 | const out = new Float32Array(16); |
| 44 | for (let col = 0; col < 4; col++) { |
| 45 | for (let row = 0; row < 4; row++) { |
| 46 | out[col * 4 + row] = |
| 47 | a[0 * 4 + row] * b[col * 4 + 0] + |
| 48 | a[1 * 4 + row] * b[col * 4 + 1] + |
| 49 | a[2 * 4 + row] * b[col * 4 + 2] + |
| 50 | a[3 * 4 + row] * b[col * 4 + 3]; |
| 51 | } |
| 52 | } |
| 53 | return out; |
| 54 | } |
| 55 | |
| 56 | function mat4ApplyPoint(m, x, y, z) { |
| 57 | return { |
| 58 | x: m[0] * x + m[4] * y + m[8] * z + m[12], |
| 59 | y: m[1] * x + m[5] * y + m[9] * z + m[13], |
| 60 | z: m[2] * x + m[6] * y + m[10] * z + m[14] |
| 61 | }; |
| 62 | } |
| 63 | |
| 64 | function isIdentityMatrix(m) { |
| 65 | if (!m) return true; |
| 66 | const id = mat4Identity(); |
nothing calls this directly
no outgoing calls
no test coverage detected