summit/frontend/node_modules/three-stdlib/modifiers/TessellateModifier.cjs.map

1 line
12 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"TessellateModifier.cjs","sources":["../../src/modifiers/TessellateModifier.ts"],"sourcesContent":["import { BufferGeometry, Color, Float32BufferAttribute, Vector2, Vector3 } from 'three'\nimport { UV1 } from '../_polyfill/uv1'\n\n/**\n * Break faces with edges longer than maxEdgeLength\n */\n\nclass TessellateModifier {\n public maxEdgeLength: number\n public maxIterations: number\n\n constructor(maxEdgeLength = 0.1, maxIterations = 6) {\n this.maxEdgeLength = maxEdgeLength\n this.maxIterations = maxIterations\n }\n\n public modify = (geometry: BufferGeometry): BufferGeometry => {\n if (geometry.index !== null) {\n geometry = geometry.toNonIndexed()\n }\n\n //\n\n const maxIterations = this.maxIterations\n const maxEdgeLengthSquared = this.maxEdgeLength * this.maxEdgeLength\n\n const va = new Vector3()\n const vb = new Vector3()\n const vc = new Vector3()\n const vm = new Vector3()\n const vs = [va, vb, vc, vm]\n\n const na = new Vector3()\n const nb = new Vector3()\n const nc = new Vector3()\n const nm = new Vector3()\n const ns = [na, nb, nc, nm]\n\n const ca = new Color()\n const cb = new Color()\n const cc = new Color()\n const cm = new Color()\n const cs = [ca, cb, cc, cm]\n\n const ua = new Vector2()\n const ub = new Vector2()\n const uc = new Vector2()\n const um = new Vector2()\n const us = [ua, ub, uc, um]\n\n const u2a = new Vector2()\n const u2b = new Vector2()\n const u2c = new Vector2()\n const u2m = new Vector2()\n const u2s = [u2a, u2b, u2c, u2m]\n\n const attributes = geometry.attributes\n const hasNormals = attributes.normal !== undefined\n const hasColors = attributes.color !== undefined\n const hasUVs = attributes.uv !== undefined\n const hasUV1s = attributes[UV1] !== undefined\n\n let positions = attributes.position.array\n let normals = hasNormals ? attributes.normal.array : null\n let colors = hasColors ? attributes.color.array : null\n let uvs = hasUVs ? attributes.uv.array : null\n let uv1s = hasUV1s ? attributes.uv1.array : null\n\n let positions2 = (positions as unknown) as number[]\n let normals2 = (normals as unknown) as number[]\n let colors2 = (colors as unknown) as number[]\n let uvs2 = (uvs as unknown) as number[]\n let uv1s2 = (uv1s as unknown) as number[]\n\n let iteration = 0\n let tessellating = true\n\n function addTriangle(a: number, b: number, c: number): void {\n const v1 = vs[a]\n const v2 = vs[b]\n const v3 = vs[c]\n\n positions2.push(v1.x, v1.y, v1.z)\n positions2.push(v2.x, v2.y, v2.z)\n positions2.push(v3.x, v3.y, v3.z)\n\n if (hasNormals) {\n const n1 = ns[a]\n const n2 = ns[b]\n const n3 = ns[c]\n\n normals2.push(n1.x, n1.y, n1.z)\n normals2.push(n2.x, n2.y, n2.z)\n normals2.push(n3.x, n3.y, n3.z)\n }\n\n if (hasColors) {\n const c1 = cs[a]\n const c2 = cs[b]\n const c3 = cs[c]\n\n colors2.push(c1.r, c1.g, c1.b)\n colors2.push(c2.r, c2.g, c2.b)\n colors2.push(c3.r, c3.g, c3.b)\n }\n\n if (hasUVs) {\n const u1 = us[a]\n const u2 = us[b]\n const u3 = us[c]\n\n uvs2.push(u1.x, u1.y)\n uvs2.push(u2.x, u2.y)\n uvs2.push(u3.x, u3.y)\n }\n\n if (hasUV1s) {\n const u21 = u2s[a]\n const u22 = u2s[b]\n const u23 = u2s[c]\n\n uv1s2.push(u21.x, u21.y)\n uv1s2.push(u22.x, u22.y)\n uv1s2.push(u23.x, u23.y)\n }\n }\n\n while (tessellating && iteration < maxIterations) {\n iteration++\n tessellating = false\n\n positions = positions2 as any\n positions2 = []\n\n if (hasNormals) {\n normals = normals2 as any\n normals2 = []\n }\n\n if (hasColors) {\n colors = colors2 as any\n colors2 = []\n }\n\n if (hasUVs) {\n uvs = uvs2 as any\n uvs2 = []\n }\n\n if (hasUV1s) {\n uv1s