three-stdlib 2.31.0 → 2.32.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/_polyfill/uv1.cjs +6 -0
  2. package/_polyfill/uv1.cjs.map +1 -0
  3. package/_polyfill/uv1.d.ts +5 -0
  4. package/_polyfill/uv1.js +6 -0
  5. package/_polyfill/uv1.js.map +1 -0
  6. package/controls/ArcballControls.cjs.map +1 -1
  7. package/controls/ArcballControls.d.ts +2 -2
  8. package/controls/ArcballControls.js.map +1 -1
  9. package/controls/FirstPersonControls.cjs.map +1 -1
  10. package/controls/FirstPersonControls.d.ts +1 -1
  11. package/controls/FirstPersonControls.js.map +1 -1
  12. package/exporters/ColladaExporter.cjs +3 -2
  13. package/exporters/ColladaExporter.cjs.map +1 -1
  14. package/exporters/ColladaExporter.js +3 -2
  15. package/exporters/ColladaExporter.js.map +1 -1
  16. package/lines/LineSegments2.cjs +3 -2
  17. package/lines/LineSegments2.cjs.map +1 -1
  18. package/lines/LineSegments2.js +3 -2
  19. package/lines/LineSegments2.js.map +1 -1
  20. package/loaders/ColladaLoader.cjs +7 -6
  21. package/loaders/ColladaLoader.cjs.map +1 -1
  22. package/loaders/ColladaLoader.js +7 -6
  23. package/loaders/ColladaLoader.js.map +1 -1
  24. package/loaders/FBXLoader.cjs +4 -4
  25. package/loaders/FBXLoader.cjs.map +1 -1
  26. package/loaders/FBXLoader.js +4 -4
  27. package/loaders/FBXLoader.js.map +1 -1
  28. package/loaders/LWOLoader.cjs +3 -1
  29. package/loaders/LWOLoader.cjs.map +1 -1
  30. package/loaders/LWOLoader.js +3 -1
  31. package/loaders/LWOLoader.js.map +1 -1
  32. package/misc/ProgressiveLightmap.cjs +12 -10
  33. package/misc/ProgressiveLightmap.cjs.map +1 -1
  34. package/misc/ProgressiveLightmap.js +12 -10
  35. package/misc/ProgressiveLightmap.js.map +1 -1
  36. package/modifiers/TessellateModifier.cjs +20 -19
  37. package/modifiers/TessellateModifier.cjs.map +1 -1
  38. package/modifiers/TessellateModifier.js +20 -19
  39. package/modifiers/TessellateModifier.js.map +1 -1
  40. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"ProgressiveLightmap.js","sources":["../../src/misc/ProgressiveLightmap.js"],"sourcesContent":["import {\n Scene,\n WebGLRenderTarget,\n FloatType,\n MeshBasicMaterial,\n MeshPhongMaterial,\n DoubleSide,\n PlaneGeometry,\n Mesh,\n} from 'three'\nimport potpack from 'potpack'\n\n/**\n * Progressive Light Map Accumulator, by [zalo](https://github.com/zalo/)\n *\n * To use, simply construct a `ProgressiveLightMap` object,\n * `plmap.addObjectsToLightMap(object)` an array of semi-static\n * objects and lights to the class once, and then call\n * `plmap.update(camera)` every frame to begin accumulating\n * lighting samples.\n *\n * This should begin accumulating lightmaps which apply to\n * your objects, so you can start jittering lighting to achieve\n * the texture-space effect you're looking for.\n *\n * @param {WebGLRenderer} renderer A WebGL Rendering Context\n * @param {number} res The side-long dimension of you total lightmap\n */\nclass ProgressiveLightMap {\n constructor(renderer, res = 1024) {\n this.renderer = renderer\n this.res = res\n this.lightMapContainers = []\n this.compiled = false\n this.scene = new Scene()\n this.scene.background = null\n this.tinyTarget = new WebGLRenderTarget(1, 1)\n this.buffer1Active = false\n this.firstUpdate = true\n this.warned = false\n\n // Create the Progressive LightMap Texture\n const format = /(Android|iPad|iPhone|iPod)/g.test(navigator.userAgent) ? alfFloatType : FloatType\n this.progressiveLightMap1 = new WebGLRenderTarget(this.res, this.res, { type: format })\n this.progressiveLightMap2 = new WebGLRenderTarget(this.res, this.res, { type: format })\n\n // Inject some spicy new logic into a standard phong material\n this.uvMat = new MeshPhongMaterial()\n this.uvMat.uniforms = {}\n this.uvMat.onBeforeCompile = (shader) => {\n // Vertex Shader: Set Vertex Positions to the Unwrapped UV Positions\n shader.vertexShader =\n '#define USE_LIGHTMAP\\n' +\n shader.vertexShader.slice(0, -1) +\n '\tgl_Position = vec4((uv2 - 0.5) * 2.0, 1.0, 1.0); }'\n\n // Fragment Shader: Set Pixels to average in the Previous frame's Shadows\n const bodyStart = shader.fragmentShader.indexOf('void main() {')\n shader.fragmentShader =\n 'varying vec2 vUv2;\\n' +\n shader.fragmentShader.slice(0, bodyStart) +\n '\tuniform sampler2D previousShadowMap;\\n\tuniform float averagingWindow;\\n' +\n shader.fragmentShader.slice(bodyStart - 1, -1) +\n `\\nvec3 texelOld = texture2D(previousShadowMap, vUv2).rgb;\n\t\t\t\tgl_FragColor.rgb = mix(texelOld, gl_FragColor.rgb, 1.0/averagingWindow);\n\t\t\t}`\n\n // Set the Previous Frame's Texture Buffer and Averaging Window\n shader.uniforms.previousShadowMap = { value: this.progressiveLightMap1.texture }\n shader.uniforms.averagingWindow = { value: 100 }\n\n this.uvMat.uniforms = shader.uniforms\n\n // Set the new Shader to this\n this.uvMat.userData.shader = shader\n\n this.compiled = true\n }\n }\n\n /**\n * Sets these objects' materials' lightmaps and modifies their uv2's.\n * @param {Object3D} objects An array of objects and lights to set up your lightmap.\n */\n addObjectsToLightMap(objects) {\n // Prepare list of UV bounding boxes for packing later...\n this.uv_boxes = []\n const padding = 3 / this.res\n\n for (let ob = 0; ob < objects.length; ob++) {\n const object = objects[ob]\n\n // If this object is a light, simply add it to the internal scene\n if (object.isLight) {\n this.scene.attach(object)\n continue\n }\n\n if (!object.geometry.hasAttribute('uv')) {\n console.warn('All lightmap objects need UVs!')\n continue\n }\n\n if (this.blurringPlane == null) {\n this._initializeBlurPlane(this.res, this.progressiveLightMap1)\n }\n\n // Apply the lightmap to the object\n object.material.lightMap = this.progressiveLightMap2.texture\n object.material.dithering = true\n object.castShadow = true\n object.receiveShadow = true\n object.renderOrder = 1000 + ob\n\n // Prepare UV boxes for potpack\n // TODO: Size these by object surface area\n this.uv_boxes.push({ w: 1 + padding * 2, h: 1 + padding * 2, index: ob })\n\n this.lightMapContainers.push({ basicMat: object.material, object: object })\n\n this.compiled = false\n }\n\n // Pack the objects' lightmap UVs into the same global space\n const dimensions = potpack(this.uv_boxes)\n this.uv_boxes.forEach((box) => {\n const uv2 = objects[box.index].geometry.getAttribute('uv').clone()\n for (let i = 0; i < uv2.array.length; i += uv2.itemSize) {\n uv2.array[i] = (uv2.array[i] + box.x + padding) / dimensions.w\n uv2.array[i + 1] = (uv2.array[i + 1] + box.y + padding) / dimensions.h\n }\n\n objects[box.index].geometry.setAttribute('uv2', uv2)\n objects[box.index].geometry.getAttribute('uv2').needsUpdate = true\n })\n }\n\n /**\n * This function renders each mesh one at a time into their respective surface maps\n * @param {Camera} camera Standard Rendering Camera\n * @param {number} blendWindow When >1, samples will accumulate over time.\n * @param {boolean} blurEdges Whether to fix UV Edges via blurring\n */\n update(camera, blendWindow = 100, blurEdges = true) {\n if (this.blurringPlane == null) {\n return\n }\n\n // Store the original Render Target\n const oldTarget = this.renderer.getRenderTarget()\n\n // The blurring plane applies blur to the seams of the lightmap\n this.blurringPlane.visible = blurEdges\n\n // Steal the Object3D from the real world to our special dimension\n for (let l = 0; l < this.lightMapContainers.length; l++) {\n this.lightMapContainers[l].object.oldScene = this.lightMapContainers[l].object.parent\n this.scene.attach(this.lightMapContainers[l].object)\n }\n\n // Render once normally to initialize everything\n if (this.firstUpdate) {\n this.renderer.setRenderTarget(this.tinyTarget) // Tiny for Speed\n this.renderer.render(this.scene, camera)\n this.firstUpdate = false\n }\n\n // Set each object's material to the UV Unwrapped Surface Mapping Version\n for (let l = 0; l < this.lightMapContainers.length; l++) {\n this.uvMat.uniforms.averagingWindow = { value: blendWindow }\n this.lightMapContainers[l].object.material = this.uvMat\n this.lightMapContainers[l].object.oldFrustumCulled = this.lightMapContainers[l].object.frustumCulled\n this.lightMapContainers[l].object.frustumCulled = false\n }\n\n // Ping-pong two surface buffers for reading/writing\n const activeMap = this.buffer1Active ? this.progressiveLightMap1 : this.progressiveLightMap2\n const inactiveMap = this.buffer1Active ? this.progressiveLightMap2 : this.progressiveLightMap1\n\n // Render the object's surface maps\n this.renderer.setRenderTarget(activeMap)\n this.uvMat.uniforms.previousShadowMap = { value: inactiveMap.texture }\n this.blurringPlane.material.uniforms.previousShadowMap = { value: inactiveMap.texture }\n this.buffer1Active = !this.buffer1Active\n this.renderer.render(this.scene, camera)\n\n // Restore the object's Real-time Material and add it back to the original world\n for (let l = 0; l < this.lightMapContainers.length; l++) {\n this.lightMapContainers[l].object.frustumCulled = this.lightMapContainers[l].object.oldFrustumCulled\n this.lightMapContainers[l].object.material = this.lightMapContainers[l].basicMat\n this.lightMapContainers[l].object.oldScene.attach(this.lightMapContainers[l].object)\n }\n\n // Restore the original Render Target\n this.renderer.setRenderTarget(oldTarget)\n }\n\n /** DEBUG\n * Draw the lightmap in the main scene. Call this after adding the objects to it.\n * @param {boolean} visible Whether the debug plane should be visible\n * @param {Vector3} position Where the debug plane should be drawn\n */\n showDebugLightmap(visible, position = undefined) {\n if (this.lightMapContainers.length == 0) {\n if (!this.warned) {\n console.warn('Call this after adding the objects!')\n this.warned = true\n }\n\n return\n }\n\n if (this.labelMesh == null) {\n this.labelMaterial = new MeshBasicMaterial({\n map: this.progressiveLightMap1.texture,\n side: DoubleSide,\n })\n this.labelPlane = new PlaneGeometry(100, 100)\n this.labelMesh = new Mesh(this.labelPlane, this.labelMaterial)\n this.labelMesh.position.y = 250\n this.lightMapContainers[0].object.parent.add(this.labelMesh)\n }\n\n if (position != undefined) {\n this.labelMesh.position.copy(position)\n }\n\n this.labelMesh.visible = visible\n }\n\n /**\n * INTERNAL Creates the Blurring Plane\n * @param {number} res The square resolution of this object's lightMap.\n * @param {WebGLRenderTexture} lightMap The lightmap to initialize the plane with.\n */\n _initializeBlurPlane(res, lightMap = null) {\n const blurMaterial = new MeshBasicMaterial()\n blurMaterial.uniforms = {\n previousShadowMap: { value: null },\n pixelOffset: { value: 1.0 / res },\n polygonOffset: true,\n polygonOffsetFactor: -1,\n polygonOffsetUnits: 3.0,\n }\n blurMaterial.onBeforeCompile = (shader) => {\n // Vertex Shader: Set Vertex Positions to the Unwrapped UV Positions\n shader.vertexShader =\n '#define USE_UV\\n' + shader.vertexShader.slice(0, -1) + '\tgl_Position = vec4((uv - 0.5) * 2.0, 1.0, 1.0); }'\n\n // Fragment Shader: Set Pixels to 9-tap box blur the current frame's Shadows\n const bodyStart = shader.fragmentShader.indexOf('void main() {')\n shader.fragmentShader =\n '#define USE_UV\\n' +\n shader.fragmentShader.slice(0, bodyStart) +\n '\tuniform sampler2D previousShadowMap;\\n\tuniform float pixelOffset;\\n' +\n shader.fragmentShader.slice(bodyStart - 1, -1) +\n `\tgl_FragColor.rgb = (\n\t\t\t texture2D(previousShadowMap, vUv + vec2( pixelOffset, 0.0 )).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2( 0.0 , pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2( 0.0 , -pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2(-pixelOffset, 0.0 )).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2( pixelOffset, pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2(-pixelOffset, pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2( pixelOffset, -pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2(-pixelOffset, -pixelOffset)).rgb)/8.0;\n\t\t}`\n\n // Set the LightMap Accumulation Buffer\n shader.uniforms.previousShadowMap = { value: lightMap.texture }\n shader.uniforms.pixelOffset = { value: 0.5 / res }\n blurMaterial.uniforms = shader.uniforms\n\n // Set the new Shader to this\n blurMaterial.userData.shader = shader\n\n this.compiled = true\n }\n\n this.blurringPlane = new Mesh(new PlaneGeometry(1, 1), blurMaterial)\n this.blurringPlane.name = 'Blurring Plane'\n this.blurringPlane.frustumCulled = false\n this.blurringPlane.renderOrder = 0\n this.blurringPlane.material.depthWrite = false\n this.scene.add(this.blurringPlane)\n }\n}\n\nexport { ProgressiveLightMap }\n"],"names":[],"mappings":";;AA4BA,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eAAe,QAAQ,eAAe;AAC/D,aAAO,iBACL,qBACA,OAAO,eAAe,MAAM,GAAG,SAAS,IACxC,yEACA,OAAO,eAAe,MAAM,YAAY,GAAG,EAAE,IAC7C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYF,aAAO,SAAS,oBAAoB,EAAE,OAAO,SAAS,QAAS;AAC/D,aAAO,SAAS,cAAc,EAAE,OAAO,MAAM,IAAK;AAClD,mBAAa,WAAW,OAAO;AAG/B,mBAAa,SAAS,SAAS;AAE/B,WAAK,WAAW;AAAA,IACjB;AAED,SAAK,gBAAgB,IAAI,KAAK,IAAI,cAAc,GAAG,CAAC,GAAG,YAAY;AACnE,SAAK,cAAc,OAAO;AAC1B,SAAK,cAAc,gBAAgB;AACnC,SAAK,cAAc,cAAc;AACjC,SAAK,cAAc,SAAS,aAAa;AACzC,SAAK,MAAM,IAAI,KAAK,aAAa;AAAA,EAClC;AACH;"}
1
+ {"version":3,"file":"ProgressiveLightmap.js","sources":["../../src/misc/ProgressiveLightmap.js"],"sourcesContent":["import {\n Scene,\n WebGLRenderTarget,\n FloatType,\n MeshBasicMaterial,\n MeshPhongMaterial,\n DoubleSide,\n PlaneGeometry,\n Mesh,\n} from 'three'\nimport potpack from 'potpack'\nimport { UV1 } from '../_polyfill/uv1'\n\n/**\n * Progressive Light Map Accumulator, by [zalo](https://github.com/zalo/)\n *\n * To use, simply construct a `ProgressiveLightMap` object,\n * `plmap.addObjectsToLightMap(object)` an array of semi-static\n * objects and lights to the class once, and then call\n * `plmap.update(camera)` every frame to begin accumulating\n * lighting samples.\n *\n * This should begin accumulating lightmaps which apply to\n * your objects, so you can start jittering lighting to achieve\n * the texture-space effect you're looking for.\n *\n * @param {WebGLRenderer} renderer A WebGL Rendering Context\n * @param {number} res The side-long dimension of you total lightmap\n */\nclass ProgressiveLightMap {\n constructor(renderer, res = 1024) {\n this.renderer = renderer\n this.res = res\n this.lightMapContainers = []\n this.compiled = false\n this.scene = new Scene()\n this.scene.background = null\n this.tinyTarget = new WebGLRenderTarget(1, 1)\n this.buffer1Active = false\n this.firstUpdate = true\n this.warned = false\n\n // Create the Progressive LightMap Texture\n const format = /(Android|iPad|iPhone|iPod)/g.test(navigator.userAgent) ? alfFloatType : FloatType\n this.progressiveLightMap1 = new WebGLRenderTarget(this.res, this.res, { type: format })\n this.progressiveLightMap2 = new WebGLRenderTarget(this.res, this.res, { type: format })\n\n // Inject some spicy new logic into a standard phong material\n this.uvMat = new MeshPhongMaterial()\n this.uvMat.uniforms = {}\n this.uvMat.onBeforeCompile = (shader) => {\n // Vertex Shader: Set Vertex Positions to the Unwrapped UV Positions\n shader.vertexShader =\n '#define USE_LIGHTMAP\\n' +\n shader.vertexShader.slice(0, -1) +\n `\tgl_Position = vec4((${UV1} - 0.5) * 2.0, 1.0, 1.0); }`\n\n // Fragment Shader: Set Pixels to average in the Previous frame's Shadows\n const bodyStart = shader.fragmentShader.indexOf('void main() {')\n shader.fragmentShader =\n `varying vec2 v${UV1 === 'uv1' ? UV1 : 'Uv2'};\\n` +\n shader.fragmentShader.slice(0, bodyStart) +\n '\tuniform sampler2D previousShadowMap;\\n\tuniform float averagingWindow;\\n' +\n shader.fragmentShader.slice(bodyStart - 1, -1) +\n `\\nvec3 texelOld = texture2D(previousShadowMap, v${UV1 === 'uv1' ? UV1 : 'Uv2'}).rgb;\n\t\t\t\tgl_FragColor.rgb = mix(texelOld, gl_FragColor.rgb, 1.0/averagingWindow);\n\t\t\t}`\n\n // Set the Previous Frame's Texture Buffer and Averaging Window\n shader.uniforms.previousShadowMap = { value: this.progressiveLightMap1.texture }\n shader.uniforms.averagingWindow = { value: 100 }\n\n this.uvMat.uniforms = shader.uniforms\n\n // Set the new Shader to this\n this.uvMat.userData.shader = shader\n\n this.compiled = true\n }\n }\n\n /**\n * Sets these objects' materials' lightmaps and modifies their uv1's.\n * @param {Object3D} objects An array of objects and lights to set up your lightmap.\n */\n addObjectsToLightMap(objects) {\n // Prepare list of UV bounding boxes for packing later...\n this.uv_boxes = []\n const padding = 3 / this.res\n\n for (let ob = 0; ob < objects.length; ob++) {\n const object = objects[ob]\n\n // If this object is a light, simply add it to the internal scene\n if (object.isLight) {\n this.scene.attach(object)\n continue\n }\n\n if (!object.geometry.hasAttribute('uv')) {\n console.warn('All lightmap objects need UVs!')\n continue\n }\n\n if (this.blurringPlane == null) {\n this._initializeBlurPlane(this.res, this.progressiveLightMap1)\n }\n\n // Apply the lightmap to the object\n object.material.lightMap = this.progressiveLightMap2.texture\n object.material.dithering = true\n object.castShadow = true\n object.receiveShadow = true\n object.renderOrder = 1000 + ob\n\n // Prepare UV boxes for potpack\n // TODO: Size these by object surface area\n this.uv_boxes.push({ w: 1 + padding * 2, h: 1 + padding * 2, index: ob })\n\n this.lightMapContainers.push({ basicMat: object.material, object: object })\n\n this.compiled = false\n }\n\n // Pack the objects' lightmap UVs into the same global space\n const dimensions = potpack(this.uv_boxes)\n this.uv_boxes.forEach((box) => {\n const uv1 = objects[box.index].geometry.getAttribute('uv').clone()\n for (let i = 0; i < uv1.array.length; i += uv1.itemSize) {\n uv1.array[i] = (uv1.array[i] + box.x + padding) / dimensions.w\n uv1.array[i + 1] = (uv1.array[i + 1] + box.y + padding) / dimensions.h\n }\n\n objects[box.index].geometry.setAttribute(UV1, uv1)\n objects[box.index].geometry.getAttribute(UV1).needsUpdate = true\n })\n }\n\n /**\n * This function renders each mesh one at a time into their respective surface maps\n * @param {Camera} camera Standard Rendering Camera\n * @param {number} blendWindow When >1, samples will accumulate over time.\n * @param {boolean} blurEdges Whether to fix UV Edges via blurring\n */\n update(camera, blendWindow = 100, blurEdges = true) {\n if (this.blurringPlane == null) {\n return\n }\n\n // Store the original Render Target\n const oldTarget = this.renderer.getRenderTarget()\n\n // The blurring plane applies blur to the seams of the lightmap\n this.blurringPlane.visible = blurEdges\n\n // Steal the Object3D from the real world to our special dimension\n for (let l = 0; l < this.lightMapContainers.length; l++) {\n this.lightMapContainers[l].object.oldScene = this.lightMapContainers[l].object.parent\n this.scene.attach(this.lightMapContainers[l].object)\n }\n\n // Render once normally to initialize everything\n if (this.firstUpdate) {\n this.renderer.setRenderTarget(this.tinyTarget) // Tiny for Speed\n this.renderer.render(this.scene, camera)\n this.firstUpdate = false\n }\n\n // Set each object's material to the UV Unwrapped Surface Mapping Version\n for (let l = 0; l < this.lightMapContainers.length; l++) {\n this.uvMat.uniforms.averagingWindow = { value: blendWindow }\n this.lightMapContainers[l].object.material = this.uvMat\n this.lightMapContainers[l].object.oldFrustumCulled = this.lightMapContainers[l].object.frustumCulled\n this.lightMapContainers[l].object.frustumCulled = false\n }\n\n // Ping-pong two surface buffers for reading/writing\n const activeMap = this.buffer1Active ? this.progressiveLightMap1 : this.progressiveLightMap2\n const inactiveMap = this.buffer1Active ? this.progressiveLightMap2 : this.progressiveLightMap1\n\n // Render the object's surface maps\n this.renderer.setRenderTarget(activeMap)\n this.uvMat.uniforms.previousShadowMap = { value: inactiveMap.texture }\n this.blurringPlane.material.uniforms.previousShadowMap = { value: inactiveMap.texture }\n this.buffer1Active = !this.buffer1Active\n this.renderer.render(this.scene, camera)\n\n // Restore the object's Real-time Material and add it back to the original world\n for (let l = 0; l < this.lightMapContainers.length; l++) {\n this.lightMapContainers[l].object.frustumCulled = this.lightMapContainers[l].object.oldFrustumCulled\n this.lightMapContainers[l].object.material = this.lightMapContainers[l].basicMat\n this.lightMapContainers[l].object.oldScene.attach(this.lightMapContainers[l].object)\n }\n\n // Restore the original Render Target\n this.renderer.setRenderTarget(oldTarget)\n }\n\n /** DEBUG\n * Draw the lightmap in the main scene. Call this after adding the objects to it.\n * @param {boolean} visible Whether the debug plane should be visible\n * @param {Vector3} position Where the debug plane should be drawn\n */\n showDebugLightmap(visible, position = undefined) {\n if (this.lightMapContainers.length == 0) {\n if (!this.warned) {\n console.warn('Call this after adding the objects!')\n this.warned = true\n }\n\n return\n }\n\n if (this.labelMesh == null) {\n this.labelMaterial = new MeshBasicMaterial({\n map: this.progressiveLightMap1.texture,\n side: DoubleSide,\n })\n this.labelPlane = new PlaneGeometry(100, 100)\n this.labelMesh = new Mesh(this.labelPlane, this.labelMaterial)\n this.labelMesh.position.y = 250\n this.lightMapContainers[0].object.parent.add(this.labelMesh)\n }\n\n if (position != undefined) {\n this.labelMesh.position.copy(position)\n }\n\n this.labelMesh.visible = visible\n }\n\n /**\n * INTERNAL Creates the Blurring Plane\n * @param {number} res The square resolution of this object's lightMap.\n * @param {WebGLRenderTexture} lightMap The lightmap to initialize the plane with.\n */\n _initializeBlurPlane(res, lightMap = null) {\n const blurMaterial = new MeshBasicMaterial()\n blurMaterial.uniforms = {\n previousShadowMap: { value: null },\n pixelOffset: { value: 1.0 / res },\n polygonOffset: true,\n polygonOffsetFactor: -1,\n polygonOffsetUnits: 3.0,\n }\n blurMaterial.onBeforeCompile = (shader) => {\n // Vertex Shader: Set Vertex Positions to the Unwrapped UV Positions\n shader.vertexShader =\n '#define USE_UV\\n' + shader.vertexShader.slice(0, -1) + '\tgl_Position = vec4((uv - 0.5) * 2.0, 1.0, 1.0); }'\n\n // Fragment Shader: Set Pixels to 9-tap box blur the current frame's Shadows\n const bodyStart = shader.fragmentShader.indexOf('void main() {')\n shader.fragmentShader =\n '#define USE_UV\\n' +\n shader.fragmentShader.slice(0, bodyStart) +\n '\tuniform sampler2D previousShadowMap;\\n\tuniform float pixelOffset;\\n' +\n shader.fragmentShader.slice(bodyStart - 1, -1) +\n `\tgl_FragColor.rgb = (\n\t\t\t texture2D(previousShadowMap, vUv + vec2( pixelOffset, 0.0 )).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2( 0.0 , pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2( 0.0 , -pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2(-pixelOffset, 0.0 )).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2( pixelOffset, pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2(-pixelOffset, pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2( pixelOffset, -pixelOffset)).rgb +\n\t\t\t texture2D(previousShadowMap, vUv + vec2(-pixelOffset, -pixelOffset)).rgb)/8.0;\n\t\t}`\n\n // Set the LightMap Accumulation Buffer\n shader.uniforms.previousShadowMap = { value: lightMap.texture }\n shader.uniforms.pixelOffset = { value: 0.5 / res }\n blurMaterial.uniforms = shader.uniforms\n\n // Set the new Shader to this\n blurMaterial.userData.shader = shader\n\n this.compiled = true\n }\n\n this.blurringPlane = new Mesh(new PlaneGeometry(1, 1), blurMaterial)\n this.blurringPlane.name = 'Blurring Plane'\n this.blurringPlane.frustumCulled = false\n this.blurringPlane.renderOrder = 0\n this.blurringPlane.material.depthWrite = false\n this.scene.add(this.blurringPlane)\n }\n}\n\nexport { ProgressiveLightMap }\n"],"names":[],"mappings":";;;AA6BA,MAAM,oBAAoB;AAAA,EACxB,YAAY,UAAU,MAAM,MAAM;AAChC,SAAK,WAAW;AAChB,SAAK,MAAM;AACX,SAAK,qBAAqB,CAAE;AAC5B,SAAK,WAAW;AAChB,SAAK,QAAQ,IAAI,MAAO;AACxB,SAAK,MAAM,aAAa;AACxB,SAAK,aAAa,IAAI,kBAAkB,GAAG,CAAC;AAC5C,SAAK,gBAAgB;AACrB,SAAK,cAAc;AACnB,SAAK,SAAS;AAGd,UAAM,SAAS,8BAA8B,KAAK,UAAU,SAAS,IAAI,eAAe;AACxF,SAAK,uBAAuB,IAAI,kBAAkB,KAAK,KAAK,KAAK,KAAK,EAAE,MAAM,QAAQ;AACtF,SAAK,uBAAuB,IAAI,kBAAkB,KAAK,KAAK,KAAK,KAAK,EAAE,MAAM,QAAQ;AAGtF,SAAK,QAAQ,IAAI,kBAAmB;AACpC,SAAK,MAAM,WAAW,CAAE;AACxB,SAAK,MAAM,kBAAkB,CAAC,WAAW;AAEvC,aAAO,eACL,2BACA,OAAO,aAAa,MAAM,GAAG,EAAE,IAC/B,wBAAwB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 -7,6 +7,7 @@ var __publicField = (obj, key, value) => {
7
7
  };
8
8
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
9
9
  const THREE = require("three");
10
+ const uv1 = require("../_polyfill/uv1.cjs");
10
11
  class TessellateModifier {
11
12
  constructor(maxEdgeLength = 0.1, maxIterations = 6) {
12
13
  __publicField(this, "maxEdgeLength");
@@ -46,17 +47,17 @@ class TessellateModifier {
46
47
  const hasNormals = attributes.normal !== void 0;
47
48
  const hasColors = attributes.color !== void 0;
48
49
  const hasUVs = attributes.uv !== void 0;
49
- const hasUV2s = attributes.uv2 !== void 0;
50
+ const hasUV1s = attributes[uv1.UV1] !== void 0;
50
51
  let positions = attributes.position.array;
51
52
  let normals = hasNormals ? attributes.normal.array : null;
52
53
  let colors = hasColors ? attributes.color.array : null;
53
54
  let uvs = hasUVs ? attributes.uv.array : null;
54
- let uv2s = hasUV2s ? attributes.uv2.array : null;
55
+ let uv1s = hasUV1s ? attributes.uv1.array : null;
55
56
  let positions2 = positions;
56
57
  let normals2 = normals;
57
58
  let colors2 = colors;
58
59
  let uvs2 = uvs;
59
- let uv2s2 = uv2s;
60
+ let uv1s2 = uv1s;
60
61
  let iteration = 0;
61
62
  let tessellating = true;
62
63
  function addTriangle(a, b, c) {
@@ -90,13 +91,13 @@ class TessellateModifier {
90
91
  uvs2.push(u2.x, u2.y);
91
92
  uvs2.push(u3.x, u3.y);
92
93
  }
93
- if (hasUV2s) {
94
+ if (hasUV1s) {
94
95
  const u21 = u2s[a];
95
96
  const u22 = u2s[b];
96
97
  const u23 = u2s[c];
97
- uv2s2.push(u21.x, u21.y);
98
- uv2s2.push(u22.x, u22.y);
99
- uv2s2.push(u23.x, u23.y);
98
+ uv1s2.push(u21.x, u21.y);
99
+ uv1s2.push(u22.x, u22.y);
100
+ uv1s2.push(u23.x, u23.y);
100
101
  }
101
102
  }
102
103
  while (tessellating && iteration < maxIterations) {
@@ -116,9 +117,9 @@ class TessellateModifier {
116
117
  uvs = uvs2;
117
118
  uvs2 = [];
118
119
  }
119
- if (hasUV2s) {
120
- uv2s = uv2s2;
121
- uv2s2 = [];
120
+ if (hasUV1s) {
121
+ uv1s = uv1s2;
122
+ uv1s2 = [];
122
123
  }
123
124
  for (let i = 0, i2 = 0, il = positions.length; i < il; i += 9, i2 += 6) {
124
125
  va.fromArray(positions, i + 0);
@@ -139,10 +140,10 @@ class TessellateModifier {
139
140
  ub.fromArray(uvs, i2 + 2);
140
141
  uc.fromArray(uvs, i2 + 4);
141
142
  }
142
- if (hasUV2s && uv2s) {
143
- u2a.fromArray(uv2s, i2 + 0);
144
- u2b.fromArray(uv2s, i2 + 2);
145
- u2c.fromArray(uv2s, i2 + 4);
143
+ if (hasUV1s && uv1s) {
144
+ u2a.fromArray(uv1s, i2 + 0);
145
+ u2b.fromArray(uv1s, i2 + 2);
146
+ u2c.fromArray(uv1s, i2 + 4);
146
147
  }
147
148
  const dab = va.distanceToSquared(vb);
148
149
  const dbc = vb.distanceToSquared(vc);
@@ -157,7 +158,7 @@ class TessellateModifier {
157
158
  cm.lerpColors(ca, cb, 0.5);
158
159
  if (hasUVs)
159
160
  um.lerpVectors(ua, ub, 0.5);
160
- if (hasUV2s)
161
+ if (hasUV1s)
161
162
  u2m.lerpVectors(u2a, u2b, 0.5);
162
163
  addTriangle(0, 3, 2);
163
164
  addTriangle(3, 1, 2);
@@ -169,7 +170,7 @@ class TessellateModifier {
169
170
  cm.lerpColors(cb, cc, 0.5);
170
171
  if (hasUVs)
171
172
  um.lerpVectors(ub, uc, 0.5);
172
- if (hasUV2s)
173
+ if (hasUV1s)
173
174
  u2m.lerpVectors(u2b, u2c, 0.5);
174
175
  addTriangle(0, 1, 3);
175
176
  addTriangle(3, 2, 0);
@@ -181,7 +182,7 @@ class TessellateModifier {
181
182
  cm.lerpColors(ca, cc, 0.5);
182
183
  if (hasUVs)
183
184
  um.lerpVectors(ua, uc, 0.5);
184
- if (hasUV2s)
185
+ if (hasUV1s)
185
186
  u2m.lerpVectors(u2a, u2c, 0.5);
186
187
  addTriangle(0, 1, 3);
187
188
  addTriangle(3, 1, 2);
@@ -202,8 +203,8 @@ class TessellateModifier {
202
203
  if (hasUVs) {
203
204
  geometry2.setAttribute("uv", new THREE.Float32BufferAttribute(uvs2, 2));
204
205
  }
205
- if (hasUV2s) {
206
- geometry2.setAttribute("uv2", new THREE.Float32BufferAttribute(uv2s2, 2));
206
+ if (hasUV1s) {
207
+ geometry2.setAttribute(uv1.UV1, new THREE.Float32BufferAttribute(uv1s2, 2));
207
208
  }
208
209
  return geometry2;
209
210
  });
@@ -1 +1 @@
1
- {"version":3,"file":"TessellateModifier.cjs","sources":["../../src/modifiers/TessellateModifier.ts"],"sourcesContent":["import { BufferGeometry, Color, Float32BufferAttribute, Vector2, Vector3 } from 'three'\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 hasUV2s = attributes.uv2 !== 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 uv2s = hasUV2s ? attributes.uv2.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 uv2s2 = (uv2s 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 (hasUV2s) {\n const u21 = u2s[a]\n const u22 = u2s[b]\n const u23 = u2s[c]\n\n uv2s2.push(u21.x, u21.y)\n uv2s2.push(u22.x, u22.y)\n uv2s2.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 (hasUV2s) {\n uv2s = uv2s2 as any\n uv2s2 = []\n }\n\n for (let i = 0, i2 = 0, il = positions.length; i < il; i += 9, i2 += 6) {\n va.fromArray(positions, i + 0)\n vb.fromArray(positions, i + 3)\n vc.fromArray(positions, i + 6)\n\n if (hasNormals && normals) {\n na.fromArray(normals, i + 0)\n nb.fromArray(normals, i + 3)\n nc.fromArray(normals, i + 6)\n }\n\n if (hasColors && colors) {\n ca.fromArray(colors, i + 0)\n cb.fromArray(colors, i + 3)\n cc.fromArray(colors, i + 6)\n }\n\n if (hasUVs && uvs) {\n ua.fromArray(uvs, i2 + 0)\n ub.fromArray(uvs, i2 + 2)\n uc.fromArray(uvs, i2 + 4)\n }\n\n if (hasUV2s && uv2s) {\n u2a.fromArray(uv2s, i2 + 0)\n u2b.fromArray(uv2s, i2 + 2)\n u2c.fromArray(uv2s, i2 + 4)\n }\n\n const dab = va.distanceToSquared(vb)\n const dbc = vb.distanceToSquared(vc)\n const dac = va.distanceToSquared(vc)\n\n if (dab > maxEdgeLengthSquared || dbc > maxEdgeLengthSquared || dac > maxEdgeLengthSquared) {\n tessellating = true\n\n if (dab >= dbc && dab >= dac) {\n vm.lerpVectors(va, vb, 0.5)\n if (hasNormals) nm.lerpVectors(na, nb, 0.5)\n if (hasColors) cm.lerpColors(ca, cb, 0.5)\n if (hasUVs) um.lerpVectors(ua, ub, 0.5)\n if (hasUV2s) u2m.lerpVectors(u2a, u2b, 0.5)\n\n addTriangle(0, 3, 2)\n addTriangle(3, 1, 2)\n } else if (dbc >= dab && dbc >= dac) {\n vm.lerpVectors(vb, vc, 0.5)\n if (hasNormals) nm.lerpVectors(nb, nc, 0.5)\n if (hasColors) cm.lerpColors(cb, cc, 0.5)\n if (hasUVs) um.lerpVectors(ub, uc, 0.5)\n if (hasUV2s) u2m.lerpVectors(u2b, u2c, 0.5)\n\n addTriangle(0, 1, 3)\n addTriangle(3, 2, 0)\n } else {\n vm.lerpVectors(va, vc, 0.5)\n if (hasNormals) nm.lerpVectors(na, nc, 0.5)\n if (hasColors) cm.lerpColors(ca, cc, 0.5)\n if (hasUVs) um.lerpVectors(ua, uc, 0.5)\n if (hasUV2s) u2m.lerpVectors(u2a, u2c, 0.5)\n\n addTriangle(0, 1, 3)\n addTriangle(3, 1, 2)\n }\n } else {\n addTriangle(0, 1, 2)\n }\n }\n }\n\n const geometry2 = new BufferGeometry()\n\n geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3))\n\n if (hasNormals) {\n geometry2.setAttribute('normal', new Float32BufferAttribute(normals2 as any, 3))\n }\n\n if (hasColors) {\n geometry2.setAttribute('color', new Float32BufferAttribute(colors2 as any, 3))\n }\n\n if (hasUVs) {\n geometry2.setAttribute('uv', new Float32BufferAttribute(uvs2 as any, 2))\n }\n\n if (hasUV2s) {\n geometry2.setAttribute('uv2', new Float32BufferAttribute(uv2s2 as any, 2))\n }\n\n return geometry2\n }\n}\n\nexport { TessellateModifier }\n"],"names":["Vector3","Color","Vector2","BufferGeometry","Float32BufferAttribute"],"mappings":";;;;;;;;;AAMA,MAAM,mBAAmB;AAAA,EAIvB,YAAY,gBAAgB,KAAK,gBAAgB,GAAG;AAH7C;AACA;AAOA,kCAAS,CAAC,aAA6C;AACxD,UAAA,SAAS,UAAU,MAAM;AAC3B,mBAAW,SAAS;MACtB;AAIA,YAAM,gBAAgB,KAAK;AACrB,YAAA,uBAAuB,KAAK,gBAAgB,KAAK;AAEjD,YAAA,KAAK,IAAIA,MAAAA;AACT,YAAA,KAAK,IAAIA,MAAAA;AACT,YAAA,KAAK,IAAIA,MAAAA;AACT,YAAA,KAAK,IAAIA,MAAAA;AACf,YAAM,KAAK,CAAC,IAAI,IAAI,IAAI,EAAE;AAEpB,YAAA,KAAK,IAAIA,MAAAA;AACT,YAAA,KAAK,IAAIA,MAAAA;AACT,YAAA,KAAK,IAAIA,MAAAA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YAAY,IAAIC,MAAuB,uBAAA,YAAY,CAAC,CAAC;AAE5E,UAAI,YAAY;AACd,kBAAU,aAAa,UAAU,IAAIA,MAAuB,uBAAA,UAAiB,CAAC,CAAC;AAAA,MACjF;AAEA,UAAI,WAAW;AACb,kBAAU,aAAa,SAAS,IAAIA,MAAuB,uBAAA,SAAgB,CAAC,CAAC;AAAA,MAC/E;AAEA,UAAI,QAAQ;AACV,kBAAU,aAAa,MAAM,IAAIA,MAAuB,uBAAA,MAAa,CAAC,CAAC;AAAA,MACzE;AAEA,UAAI,SAAS;AACX,kBAAU,aAAa,OAAO,IAAIA,MAAuB,uBAAA,OAAc,CAAC,CAAC;AAAA,MAC3E;AAEO,aAAA;AAAA,IAAA;AAxOP,SAAK,gBAAgB;AACrB,SAAK,gBAAgB;AAAA,EACvB;AAwOF;;"}
1
+ {"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 = uv1s2 as any\n uv1s2 = []\n }\n\n for (let i = 0, i2 = 0, il = positions.length; i < il; i += 9, i2 += 6) {\n va.fromArray(positions, i + 0)\n vb.fromArray(positions, i + 3)\n vc.fromArray(positions, i + 6)\n\n if (hasNormals && normals) {\n na.fromArray(normals, i + 0)\n nb.fromArray(normals, i + 3)\n nc.fromArray(normals, i + 6)\n }\n\n if (hasColors && colors) {\n ca.fromArray(colors, i + 0)\n cb.fromArray(colors, i + 3)\n cc.fromArray(colors, i + 6)\n }\n\n if (hasUVs && uvs) {\n ua.fromArray(uvs, i2 + 0)\n ub.fromArray(uvs, i2 + 2)\n uc.fromArray(uvs, i2 + 4)\n }\n\n if (hasUV1s && uv1s) {\n u2a.fromArray(uv1s, i2 + 0)\n u2b.fromArray(uv1s, i2 + 2)\n u2c.fromArray(uv1s, i2 + 4)\n }\n\n const dab = va.distanceToSquared(vb)\n const dbc = vb.distanceToSquared(vc)\n const dac = va.distanceToSquared(vc)\n\n if (dab > maxEdgeLengthSquared || dbc > maxEdgeLengthSquared || dac > maxEdgeLengthSquared) {\n tessellating = true\n\n if (dab >= dbc && dab >= dac) {\n vm.lerpVectors(va, vb, 0.5)\n if (hasNormals) nm.lerpVectors(na, nb, 0.5)\n if (hasColors) cm.lerpColors(ca, cb, 0.5)\n if (hasUVs) um.lerpVectors(ua, ub, 0.5)\n if (hasUV1s) u2m.lerpVectors(u2a, u2b, 0.5)\n\n addTriangle(0, 3, 2)\n addTriangle(3, 1, 2)\n } else if (dbc >= dab && dbc >= dac) {\n vm.lerpVectors(vb, vc, 0.5)\n if (hasNormals) nm.lerpVectors(nb, nc, 0.5)\n if (hasColors) cm.lerpColors(cb, cc, 0.5)\n if (hasUVs) um.lerpVectors(ub, uc, 0.5)\n if (hasUV1s) u2m.lerpVectors(u2b, u2c, 0.5)\n\n addTriangle(0, 1, 3)\n addTriangle(3, 2, 0)\n } else {\n vm.lerpVectors(va, vc, 0.5)\n if (hasNormals) nm.lerpVectors(na, nc, 0.5)\n if (hasColors) cm.lerpColors(ca, cc, 0.5)\n if (hasUVs) um.lerpVectors(ua, uc, 0.5)\n if (hasUV1s) u2m.lerpVectors(u2a, u2c, 0.5)\n\n addTriangle(0, 1, 3)\n addTriangle(3, 1, 2)\n }\n } else {\n addTriangle(0, 1, 2)\n }\n }\n }\n\n const geometry2 = new BufferGeometry()\n\n geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3))\n\n if (hasNormals) {\n geometry2.setAttribute('normal', new Float32BufferAttribute(normals2 as any, 3))\n }\n\n if (hasColors) {\n geometry2.setAttribute('color', new Float32BufferAttribute(colors2 as any, 3))\n }\n\n if (hasUVs) {\n geometry2.setAttribute('uv', new Float32BufferAttribute(uvs2 as any, 2))\n }\n\n if (hasUV1s) {\n geometry2.setAttribute(UV1, new Float32BufferAttribute(uv1s2 as any, 2))\n }\n\n return geometry2\n }\n}\n\nexport { TessellateModifier }\n"],"names":["Vector3","Color","Vector2","UV1","BufferGeometry","Float32BufferAttribute"],"mappings":";;;;;;;;;;AAOA,MAAM,mBAAmB;AAAA,EAIvB,YAAY,gBAAgB,KAAK,gBAAgB,GAAG;AAH7C;AACA;AAOA,kCAAS,CAAC,aAA6C;AACxD,UAAA,SAAS,UAAU,MAAM;AAC3B,mBAAW,SAAS;MACtB;AAIA,YAAM,gBAAgB,KAAK;AACrB,YAAA,uBAAuB,KAAK,gBAAgB,KAAK;AAEjD,YAAA,KAAK,IAAIA,MAAAA;AACT,YAAA,KAAK,IAAIA,MAAAA;AACT,YAAA,KAAK,IAAI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,GAAG,CAAC;AACP,0BAAA,GAAG,GAAG,CAAC;AAAA,YACrB;AAAA,UAAA,OACK;AACO,wBAAA,GAAG,GAAG,CAAC;AAAA,UACrB;AAAA,QACF;AAAA,MACF;AAEM,YAAA,YAAY,IAAIC,MAAAA;AAEtB,gBAAU,aAAa,YAAY,IAAIC,MAAuB,uBAAA,YAAY,CAAC,CAAC;AAE5E,UAAI,YAAY;AACd,kBAAU,aAAa,UAAU,IAAIA,MAAuB,uBAAA,UAAiB,CAAC,CAAC;AAAA,MACjF;AAEA,UAAI,WAAW;AACb,kBAAU,aAAa,SAAS,IAAIA,MAAuB,uBAAA,SAAgB,CAAC,CAAC;AAAA,MAC/E;AAEA,UAAI,QAAQ;AACV,kBAAU,aAAa,MAAM,IAAIA,MAAuB,uBAAA,MAAa,CAAC,CAAC;AAAA,MACzE;AAEA,UAAI,SAAS;AACX,kBAAU,aAAaF,SAAK,IAAIE,MAAuB,uBAAA,OAAc,CAAC,CAAC;AAAA,MACzE;AAEO,aAAA;AAAA,IAAA;AAxOP,SAAK,gBAAgB;AACrB,SAAK,gBAAgB;AAAA,EACvB;AAwOF;;"}
@@ -5,6 +5,7 @@ var __publicField = (obj, key, value) => {
5
5
  return value;
6
6
  };
7
7
  import { Vector3, Color, Vector2, BufferGeometry, Float32BufferAttribute } from "three";
8
+ import { UV1 } from "../_polyfill/uv1.js";
8
9
  class TessellateModifier {
9
10
  constructor(maxEdgeLength = 0.1, maxIterations = 6) {
10
11
  __publicField(this, "maxEdgeLength");
@@ -44,17 +45,17 @@ class TessellateModifier {
44
45
  const hasNormals = attributes.normal !== void 0;
45
46
  const hasColors = attributes.color !== void 0;
46
47
  const hasUVs = attributes.uv !== void 0;
47
- const hasUV2s = attributes.uv2 !== void 0;
48
+ const hasUV1s = attributes[UV1] !== void 0;
48
49
  let positions = attributes.position.array;
49
50
  let normals = hasNormals ? attributes.normal.array : null;
50
51
  let colors = hasColors ? attributes.color.array : null;
51
52
  let uvs = hasUVs ? attributes.uv.array : null;
52
- let uv2s = hasUV2s ? attributes.uv2.array : null;
53
+ let uv1s = hasUV1s ? attributes.uv1.array : null;
53
54
  let positions2 = positions;
54
55
  let normals2 = normals;
55
56
  let colors2 = colors;
56
57
  let uvs2 = uvs;
57
- let uv2s2 = uv2s;
58
+ let uv1s2 = uv1s;
58
59
  let iteration = 0;
59
60
  let tessellating = true;
60
61
  function addTriangle(a, b, c) {
@@ -88,13 +89,13 @@ class TessellateModifier {
88
89
  uvs2.push(u2.x, u2.y);
89
90
  uvs2.push(u3.x, u3.y);
90
91
  }
91
- if (hasUV2s) {
92
+ if (hasUV1s) {
92
93
  const u21 = u2s[a];
93
94
  const u22 = u2s[b];
94
95
  const u23 = u2s[c];
95
- uv2s2.push(u21.x, u21.y);
96
- uv2s2.push(u22.x, u22.y);
97
- uv2s2.push(u23.x, u23.y);
96
+ uv1s2.push(u21.x, u21.y);
97
+ uv1s2.push(u22.x, u22.y);
98
+ uv1s2.push(u23.x, u23.y);
98
99
  }
99
100
  }
100
101
  while (tessellating && iteration < maxIterations) {
@@ -114,9 +115,9 @@ class TessellateModifier {
114
115
  uvs = uvs2;
115
116
  uvs2 = [];
116
117
  }
117
- if (hasUV2s) {
118
- uv2s = uv2s2;
119
- uv2s2 = [];
118
+ if (hasUV1s) {
119
+ uv1s = uv1s2;
120
+ uv1s2 = [];
120
121
  }
121
122
  for (let i = 0, i2 = 0, il = positions.length; i < il; i += 9, i2 += 6) {
122
123
  va.fromArray(positions, i + 0);
@@ -137,10 +138,10 @@ class TessellateModifier {
137
138
  ub.fromArray(uvs, i2 + 2);
138
139
  uc.fromArray(uvs, i2 + 4);
139
140
  }
140
- if (hasUV2s && uv2s) {
141
- u2a.fromArray(uv2s, i2 + 0);
142
- u2b.fromArray(uv2s, i2 + 2);
143
- u2c.fromArray(uv2s, i2 + 4);
141
+ if (hasUV1s && uv1s) {
142
+ u2a.fromArray(uv1s, i2 + 0);
143
+ u2b.fromArray(uv1s, i2 + 2);
144
+ u2c.fromArray(uv1s, i2 + 4);
144
145
  }
145
146
  const dab = va.distanceToSquared(vb);
146
147
  const dbc = vb.distanceToSquared(vc);
@@ -155,7 +156,7 @@ class TessellateModifier {
155
156
  cm.lerpColors(ca, cb, 0.5);
156
157
  if (hasUVs)
157
158
  um.lerpVectors(ua, ub, 0.5);
158
- if (hasUV2s)
159
+ if (hasUV1s)
159
160
  u2m.lerpVectors(u2a, u2b, 0.5);
160
161
  addTriangle(0, 3, 2);
161
162
  addTriangle(3, 1, 2);
@@ -167,7 +168,7 @@ class TessellateModifier {
167
168
  cm.lerpColors(cb, cc, 0.5);
168
169
  if (hasUVs)
169
170
  um.lerpVectors(ub, uc, 0.5);
170
- if (hasUV2s)
171
+ if (hasUV1s)
171
172
  u2m.lerpVectors(u2b, u2c, 0.5);
172
173
  addTriangle(0, 1, 3);
173
174
  addTriangle(3, 2, 0);
@@ -179,7 +180,7 @@ class TessellateModifier {
179
180
  cm.lerpColors(ca, cc, 0.5);
180
181
  if (hasUVs)
181
182
  um.lerpVectors(ua, uc, 0.5);
182
- if (hasUV2s)
183
+ if (hasUV1s)
183
184
  u2m.lerpVectors(u2a, u2c, 0.5);
184
185
  addTriangle(0, 1, 3);
185
186
  addTriangle(3, 1, 2);
@@ -200,8 +201,8 @@ class TessellateModifier {
200
201
  if (hasUVs) {
201
202
  geometry2.setAttribute("uv", new Float32BufferAttribute(uvs2, 2));
202
203
  }
203
- if (hasUV2s) {
204
- geometry2.setAttribute("uv2", new Float32BufferAttribute(uv2s2, 2));
204
+ if (hasUV1s) {
205
+ geometry2.setAttribute(UV1, new Float32BufferAttribute(uv1s2, 2));
205
206
  }
206
207
  return geometry2;
207
208
  });
@@ -1 +1 @@
1
- {"version":3,"file":"TessellateModifier.js","sources":["../../src/modifiers/TessellateModifier.ts"],"sourcesContent":["import { BufferGeometry, Color, Float32BufferAttribute, Vector2, Vector3 } from 'three'\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 hasUV2s = attributes.uv2 !== 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 uv2s = hasUV2s ? attributes.uv2.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 uv2s2 = (uv2s 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 (hasUV2s) {\n const u21 = u2s[a]\n const u22 = u2s[b]\n const u23 = u2s[c]\n\n uv2s2.push(u21.x, u21.y)\n uv2s2.push(u22.x, u22.y)\n uv2s2.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 (hasUV2s) {\n uv2s = uv2s2 as any\n uv2s2 = []\n }\n\n for (let i = 0, i2 = 0, il = positions.length; i < il; i += 9, i2 += 6) {\n va.fromArray(positions, i + 0)\n vb.fromArray(positions, i + 3)\n vc.fromArray(positions, i + 6)\n\n if (hasNormals && normals) {\n na.fromArray(normals, i + 0)\n nb.fromArray(normals, i + 3)\n nc.fromArray(normals, i + 6)\n }\n\n if (hasColors && colors) {\n ca.fromArray(colors, i + 0)\n cb.fromArray(colors, i + 3)\n cc.fromArray(colors, i + 6)\n }\n\n if (hasUVs && uvs) {\n ua.fromArray(uvs, i2 + 0)\n ub.fromArray(uvs, i2 + 2)\n uc.fromArray(uvs, i2 + 4)\n }\n\n if (hasUV2s && uv2s) {\n u2a.fromArray(uv2s, i2 + 0)\n u2b.fromArray(uv2s, i2 + 2)\n u2c.fromArray(uv2s, i2 + 4)\n }\n\n const dab = va.distanceToSquared(vb)\n const dbc = vb.distanceToSquared(vc)\n const dac = va.distanceToSquared(vc)\n\n if (dab > maxEdgeLengthSquared || dbc > maxEdgeLengthSquared || dac > maxEdgeLengthSquared) {\n tessellating = true\n\n if (dab >= dbc && dab >= dac) {\n vm.lerpVectors(va, vb, 0.5)\n if (hasNormals) nm.lerpVectors(na, nb, 0.5)\n if (hasColors) cm.lerpColors(ca, cb, 0.5)\n if (hasUVs) um.lerpVectors(ua, ub, 0.5)\n if (hasUV2s) u2m.lerpVectors(u2a, u2b, 0.5)\n\n addTriangle(0, 3, 2)\n addTriangle(3, 1, 2)\n } else if (dbc >= dab && dbc >= dac) {\n vm.lerpVectors(vb, vc, 0.5)\n if (hasNormals) nm.lerpVectors(nb, nc, 0.5)\n if (hasColors) cm.lerpColors(cb, cc, 0.5)\n if (hasUVs) um.lerpVectors(ub, uc, 0.5)\n if (hasUV2s) u2m.lerpVectors(u2b, u2c, 0.5)\n\n addTriangle(0, 1, 3)\n addTriangle(3, 2, 0)\n } else {\n vm.lerpVectors(va, vc, 0.5)\n if (hasNormals) nm.lerpVectors(na, nc, 0.5)\n if (hasColors) cm.lerpColors(ca, cc, 0.5)\n if (hasUVs) um.lerpVectors(ua, uc, 0.5)\n if (hasUV2s) u2m.lerpVectors(u2a, u2c, 0.5)\n\n addTriangle(0, 1, 3)\n addTriangle(3, 1, 2)\n }\n } else {\n addTriangle(0, 1, 2)\n }\n }\n }\n\n const geometry2 = new BufferGeometry()\n\n geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3))\n\n if (hasNormals) {\n geometry2.setAttribute('normal', new Float32BufferAttribute(normals2 as any, 3))\n }\n\n if (hasColors) {\n geometry2.setAttribute('color', new Float32BufferAttribute(colors2 as any, 3))\n }\n\n if (hasUVs) {\n geometry2.setAttribute('uv', new Float32BufferAttribute(uvs2 as any, 2))\n }\n\n if (hasUV2s) {\n geometry2.setAttribute('uv2', new Float32BufferAttribute(uv2s2 as any, 2))\n }\n\n return geometry2\n }\n}\n\nexport { TessellateModifier }\n"],"names":[],"mappings":";;;;;;;AAMA,MAAM,mBAAmB;AAAA,EAIvB,YAAY,gBAAgB,KAAK,gBAAgB,GAAG;AAH7C;AACA;AAOA,kCAAS,CAAC,aAA6C;AACxD,UAAA,SAAS,UAAU,MAAM;AAC3B,mBAAW,SAAS;MACtB;AAIA,YAAM,gBAAgB,KAAK;AACrB,YAAA,uBAAuB,KAAK,gBAAgB,KAAK;AAEjD,YAAA,KAAK,IAAI;AACT,YAAA,KAAK,IAAI;AACT,YAAA,KAAK,IAAI;AACT,YAAA,KAAK,IAAI;AACf,YAAM,KAAK,CAAC,IAAI,IAAI,IAAI,EAAE;AAEpB,YAAA,KAAK,IAAI;AACT,YAAA,KAAK,IAAI;AACT,YAAA,KAAK,IAAI;AACT,YAAA,KAAK,IAAI;AACf,YAAM,KAAK,CAAC,IAAI,IAAI,IAAI,EAAE;AAEpB,YAAA,KAAK,IAAI;AACT,YAAA,KAAK,IAAI;AACT,YAAA,KAAK,IAAI;AACT,YAAA,KAAK,IAAI;AACf,YAAM,KAAK,CAAC,IAAI,IAAI,IAAI,EAAE;AAEpB,YAAA,KAAK,IAAI;AACT,YAAA,KAAK,IAAI;AACT,YAAA,KAAK,IAAI;AACT,YAAA,KAAK,IAAI;AACf,YAAM,KAAK,CAAC,IAAI,IAAI,IAAI,EAAE;AAEpB,YAAA,MAAM,IAAI;AACV,YAAA,MAAM,IAAI;AACV,YAAA,MAAM,IAAI;AACV,YAAA,MAAM,IAAI;AAChB,YAAM,MAAM,CAAC,KAAK,KAAK,KAAK,GAAG;AAE/B,YAAM,aAAa,SAAS;AACtB,YAAA,aAAa,WAAW,WAAW;AACnC,YAAA,YAAY,WAAW,UAAU;AACjC,YAAA,SAAS,WAAW,OAAO;AAC3B,YAAA,UAAU,WAAW,QAAQ;AAE/B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AAG,CAAC;AAAA,YAAA,OACd;AACF,iBAAA,YAAY,IAAI,IAAI,GAAG;AACtB,kBAAA;AAAe,mBAAA,YAAY,IAAI,IAAI,GAAG;AACtC,kBAAA;AAAc,mBAAA,WAAW,IAAI,IAAI,GAAG;AACpC,kBAAA;AAAW,mBAAA,YAAY,IAAI,IAAI,GAAG;AAClC,kBAAA;AAAa,oBAAA,YAAY,KAAK,KAAK,GAAG;AAE9B,0BAAA,GAAG,GAAG,CAAC;AACP,0BAAA,GAAG,GAAG,CAAC;AAAA,YACrB;AAAA,UAAA,OACK;AACO,wBAAA,GAAG,GAAG,CAAC;AAAA,UACrB;AAAA,QACF;AAAA,MACF;AAEM,YAAA,YAAY,IAAI;AAEtB,gBAAU,aAAa,YAAY,IAAI,uBAAuB,YAAY,CAAC,CAAC;AAE5E,UAAI,YAAY;AACd,kBAAU,aAAa,UAAU,IAAI,uBAAuB,UAAiB,CAAC,CAAC;AAAA,MACjF;AAEA,UAAI,WAAW;AACb,kBAAU,aAAa,SAAS,IAAI,uBAAuB,SAAgB,CAAC,CAAC;AAAA,MAC/E;AAEA,UAAI,QAAQ;AACV,kBAAU,aAAa,MAAM,IAAI,uBAAuB,MAAa,CAAC,CAAC;AAAA,MACzE;AAEA,UAAI,SAAS;AACX,kBAAU,aAAa,OAAO,IAAI,uBAAuB,OAAc,CAAC,CAAC;AAAA,MAC3E;AAEO,aAAA;AAAA,IAAA;AAxOP,SAAK,gBAAgB;AACrB,SAAK,gBAAgB;AAAA,EACvB;AAwOF;"}
1
+ {"version":3,"file":"TessellateModifier.js","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 = uv1s2 as any\n uv1s2 = []\n }\n\n for (let i = 0, i2 = 0, il = positions.length; i < il; i += 9, i2 += 6) {\n va.fromArray(positions, i + 0)\n vb.fromArray(positions, i + 3)\n vc.fromArray(positions, i + 6)\n\n if (hasNormals && normals) {\n na.fromArray(normals, i + 0)\n nb.fromArray(normals, i + 3)\n nc.fromArray(normals, i + 6)\n }\n\n if (hasColors && colors) {\n ca.fromArray(colors, i + 0)\n cb.fromArray(colors, i + 3)\n cc.fromArray(colors, i + 6)\n }\n\n if (hasUVs && uvs) {\n ua.fromArray(uvs, i2 + 0)\n ub.fromArray(uvs, i2 + 2)\n uc.fromArray(uvs, i2 + 4)\n }\n\n if (hasUV1s && uv1s) {\n u2a.fromArray(uv1s, i2 + 0)\n u2b.fromArray(uv1s, i2 + 2)\n u2c.fromArray(uv1s, i2 + 4)\n }\n\n const dab = va.distanceToSquared(vb)\n const dbc = vb.distanceToSquared(vc)\n const dac = va.distanceToSquared(vc)\n\n if (dab > maxEdgeLengthSquared || dbc > maxEdgeLengthSquared || dac > maxEdgeLengthSquared) {\n tessellating = true\n\n if (dab >= dbc && dab >= dac) {\n vm.lerpVectors(va, vb, 0.5)\n if (hasNormals) nm.lerpVectors(na, nb, 0.5)\n if (hasColors) cm.lerpColors(ca, cb, 0.5)\n if (hasUVs) um.lerpVectors(ua, ub, 0.5)\n if (hasUV1s) u2m.lerpVectors(u2a, u2b, 0.5)\n\n addTriangle(0, 3, 2)\n addTriangle(3, 1, 2)\n } else if (dbc >= dab && dbc >= dac) {\n vm.lerpVectors(vb, vc, 0.5)\n if (hasNormals) nm.lerpVectors(nb, nc, 0.5)\n if (hasColors) cm.lerpColors(cb, cc, 0.5)\n if (hasUVs) um.lerpVectors(ub, uc, 0.5)\n if (hasUV1s) u2m.lerpVectors(u2b, u2c, 0.5)\n\n addTriangle(0, 1, 3)\n addTriangle(3, 2, 0)\n } else {\n vm.lerpVectors(va, vc, 0.5)\n if (hasNormals) nm.lerpVectors(na, nc, 0.5)\n if (hasColors) cm.lerpColors(ca, cc, 0.5)\n if (hasUVs) um.lerpVectors(ua, uc, 0.5)\n if (hasUV1s) u2m.lerpVectors(u2a, u2c, 0.5)\n\n addTriangle(0, 1, 3)\n addTriangle(3, 1, 2)\n }\n } else {\n addTriangle(0, 1, 2)\n }\n }\n }\n\n const geometry2 = new BufferGeometry()\n\n geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3))\n\n if (hasNormals) {\n geometry2.setAttribute('normal', new Float32BufferAttribute(normals2 as any, 3))\n }\n\n if (hasColors) {\n geometry2.setAttribute('color', new Float32BufferAttribute(colors2 as any, 3))\n }\n\n if (hasUVs) {\n geometry2.setAttribute('uv', new Float32BufferAttribute(uvs2 as any, 2))\n }\n\n if (hasUV1s) {\n geometry2.setAttribute(UV1, new Float32BufferAttribute(uv1s2 as any, 2))\n }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A;AAAe,mBAAA,YAAY,IAAI,IAAI,GAAG;AACtC,kBAAA;AAAc,mBAAA,WAAW,IAAI,IAAI,GAAG;AACpC,kBAAA;AAAW,mBAAA,YAAY,IAAI,IAAI,GAAG;AAClC,kBAAA;AAAa,oBAAA,YAAY,KAAK,KAAK,GAAG;AAE9B,0BAAA,GAAG,GAAG,CAAC;AACP,0BAAA,GAAG,GAAG,CAAC;AAAA,YACrB;AAAA,UAAA,OACK;AACO,wBAAA,GAAG,GAAG,CAAC;AAAA,UACrB;AAAA,QACF;AAAA,MACF;AAEM,YAAA,YAAY,IAAI;AAEtB,gBAAU,aAAa,YAAY,IAAI,uBAAuB,YAAY,CAAC,CAAC;AAE5E,UAAI,YAAY;AACd,kBAAU,aAAa,UAAU,IAAI,uBAAuB,UAAiB,CAAC,CAAC;AAAA,MACjF;AAEA,UAAI,WAAW;AACb,kBAAU,aAAa,SAAS,IAAI,uBAAuB,SAAgB,CAAC,CAAC;AAAA,MAC/E;AAEA,UAAI,QAAQ;AACV,kBAAU,aAAa,MAAM,IAAI,uBAAuB,MAAa,CAAC,CAAC;AAAA,MACzE;AAEA,UAAI,SAAS;AACX,kBAAU,aAAa,KAAK,IAAI,uBAAuB,OAAc,CAAC,CAAC;AAAA,MACzE;AAEO,aAAA;AAAA,IAAA;AAxOP,SAAK,gBAAgB;AACrB,SAAK,gBAAgB;AAAA,EACvB;AAwOF;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-stdlib",
3
- "version": "2.31.0",
3
+ "version": "2.32.1",
4
4
  "description": "stand-alone library of threejs examples",
5
5
  "keywords": [
6
6
  "three",