From 11bd428c0721f9d80b31a371d01ebf371884ed75 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Sun, 3 Mar 2024 10:46:59 -0500 Subject: [PATCH 01/36] fix(types): stub TextureEncoding (#347) --- src/objects/Reflector.d.ts | 3 ++- src/objects/Refractor.d.ts | 3 ++- src/objects/Water2.d.ts | 3 ++- src/types/shared.ts | 7 +++++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/objects/Reflector.d.ts b/src/objects/Reflector.d.ts index bdae2e9e..491e75c5 100644 --- a/src/objects/Reflector.d.ts +++ b/src/objects/Reflector.d.ts @@ -1,4 +1,5 @@ -import { Mesh, BufferGeometry, Color, TextureEncoding, WebGLRenderTarget, PerspectiveCamera } from 'three' +import { Mesh, BufferGeometry, Color, WebGLRenderTarget, PerspectiveCamera } from 'three' +import { TextureEncoding } from '../types/shared' export interface ReflectorOptions { color?: Color | string | number diff --git a/src/objects/Refractor.d.ts b/src/objects/Refractor.d.ts index 37b5bb7f..83ed8e1f 100644 --- a/src/objects/Refractor.d.ts +++ b/src/objects/Refractor.d.ts @@ -1,4 +1,5 @@ -import { Mesh, BufferGeometry, Color, TextureEncoding, WebGLRenderTarget, PerspectiveCamera } from 'three' +import { Mesh, BufferGeometry, Color, WebGLRenderTarget, PerspectiveCamera } from 'three' +import { TextureEncoding } from '../types/shared' export interface RefractorOptions { color?: Color | string | number diff --git a/src/objects/Water2.d.ts b/src/objects/Water2.d.ts index 23a53e91..2bfdc53d 100644 --- a/src/objects/Water2.d.ts +++ b/src/objects/Water2.d.ts @@ -1,4 +1,5 @@ -import { BufferGeometry, Color, Mesh, ShaderMaterial, Texture, TextureEncoding, Vector2 } from 'three' +import { BufferGeometry, Color, Mesh, ShaderMaterial, Texture, Vector2 } from 'three' +import { TextureEncoding } from '../types/shared' export interface Water2Options { color?: Color | string | number diff --git a/src/types/shared.ts b/src/types/shared.ts index f13fe65b..c8edf4be 100644 --- a/src/types/shared.ts +++ b/src/types/shared.ts @@ -19,3 +19,10 @@ export type TypedArrayConstructors = | Uint32Array['constructor'] | Float32Array['constructor'] | Float64Array['constructor'] + +type LinearEncoding = 3000 +type sRGBEncoding = 3001 +/** + * Stub for `TextureEncoding` type since it was removed in r162. + */ +export type TextureEncoding = LinearEncoding | sRGBEncoding From ba6a58d46e2c8d24f574da4b3537ada54a37dce3 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Sun, 3 Mar 2024 10:47:21 -0500 Subject: [PATCH 02/36] fix(types): Remove usages of ambient THREE namespace (#346) --- src/animation/MMDPhysics.d.ts | 8 ++++---- src/controls/OrbitControls.ts | 7 ++----- src/utils/RoughnessMipmapper.d.ts | 4 ++-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/animation/MMDPhysics.d.ts b/src/animation/MMDPhysics.d.ts index eb3f20e2..fcdf615c 100644 --- a/src/animation/MMDPhysics.d.ts +++ b/src/animation/MMDPhysics.d.ts @@ -1,4 +1,4 @@ -import { Bone, Euler, Matrix4, Object3D, Quaternion, SkinnedMesh, Vector3 } from 'three' +import { Bone, Euler, Matrix4, MeshBasicMaterial, Object3D, Quaternion, SkinnedMesh, Vector3 } from 'three' export interface MMDPhysicsParameter { unitStep?: number | undefined @@ -110,10 +110,10 @@ export class Constraint { } export class MMDPhysicsHelper extends Object3D { - mesh: THREE.SkinnedMesh + mesh: SkinnedMesh physics: MMDPhysics - materials: [THREE.MeshBasicMaterial, THREE.MeshBasicMaterial, THREE.MeshBasicMaterial] + materials: [MeshBasicMaterial, MeshBasicMaterial, MeshBasicMaterial] - constructor(mesh: THREE.SkinnedMesh, physics: MMDPhysics) + constructor(mesh: SkinnedMesh, physics: MMDPhysics) dispose(): void } diff --git a/src/controls/OrbitControls.ts b/src/controls/OrbitControls.ts index c2341e9b..c25da9b9 100644 --- a/src/controls/OrbitControls.ts +++ b/src/controls/OrbitControls.ts @@ -274,10 +274,7 @@ class OrbitControls extends EventDispatcher { // adjust the camera position based on zoom only if we're not zooming to the cursor or if it's an ortho camera // we adjust zoom later in these cases - if ( - (scope.zoomToCursor && performCursorZoom) || - (scope.object as THREE.OrthographicCamera).isOrthographicCamera - ) { + if ((scope.zoomToCursor && performCursorZoom) || (scope.object as OrthographicCamera).isOrthographicCamera) { spherical.radius = clampDistance(spherical.radius) } else { spherical.radius = clampDistance(spherical.radius * scale) @@ -317,7 +314,7 @@ class OrbitControls extends EventDispatcher { const radiusDelta = prevRadius - newRadius scope.object.position.addScaledVector(dollyDirection, radiusDelta) scope.object.updateMatrixWorld() - } else if ((scope.object as THREE.OrthographicCamera).isOrthographicCamera) { + } else if ((scope.object as OrthographicCamera).isOrthographicCamera) { // adjust the ortho camera position based on zoom changes const mouseBefore = new Vector3(mouse.x, mouse.y, 0) mouseBefore.unproject(scope.object) diff --git a/src/utils/RoughnessMipmapper.d.ts b/src/utils/RoughnessMipmapper.d.ts index 80c0f292..f51fe9e4 100644 --- a/src/utils/RoughnessMipmapper.d.ts +++ b/src/utils/RoughnessMipmapper.d.ts @@ -1,8 +1,8 @@ -import { WebGLRenderer } from 'three' +import { Material, WebGLRenderer } from 'three' export class RoughnessMipmapper { constructor(renderer: WebGLRenderer) - generateMipmaps(material: THREE.Material): void + generateMipmaps(material: Material): void dispose(): void } From 017639d81eb65b3a69b334ec1792efcf6f4a2215 Mon Sep 17 00:00:00 2001 From: Jesse Date: Tue, 19 Mar 2024 18:32:11 -0400 Subject: [PATCH 03/36] fix(KTX2Loader): remove parse overload from types --- src/loaders/KTX2Loader.d.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/loaders/KTX2Loader.d.ts b/src/loaders/KTX2Loader.d.ts index 9fb50dba..5bc8c66e 100644 --- a/src/loaders/KTX2Loader.d.ts +++ b/src/loaders/KTX2Loader.d.ts @@ -7,10 +7,4 @@ export class KTX2Loader extends CompressedTextureLoader { setWorkerLimit(limit: number): KTX2Loader detectSupport(renderer: WebGLRenderer): KTX2Loader dispose(): KTX2Loader - - parse( - buffer: ArrayBuffer, - onLoad: (texture: CompressedTexture) => void, - onError?: (event: ErrorEvent) => void, - ): KTX2Loader } From c61652b2915951b7c0206e6ff586a95dfd34e4ad Mon Sep 17 00:00:00 2001 From: Scott Vorthmann Date: Sat, 27 Apr 2024 01:08:26 -0700 Subject: [PATCH 04/36] Fixed rotation defect in VRMLLoader.js (#355) --- src/loaders/VRMLLoader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/loaders/VRMLLoader.js b/src/loaders/VRMLLoader.js index 7b693b91..cb820d64 100644 --- a/src/loaders/VRMLLoader.js +++ b/src/loaders/VRMLLoader.js @@ -719,7 +719,7 @@ class VRMLLoader extends Loader { break case 'rotation': - const axis = new Vector3(fieldValues[0], fieldValues[1], fieldValues[2]) + const axis = new Vector3(fieldValues[0], fieldValues[1], fieldValues[2]).normalize() const angle = fieldValues[3] object.quaternion.setFromAxisAngle(axis, angle) break From e1f6d3e9fb3d49e53924a09bd00ba59a93c422b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ankit=20Kumar=20=28=E0=A4=85=E0=A4=82=E0=A4=95=E0=A4=BF?= =?UTF-8?q?=E0=A4=A4=20=E0=A4=95=E0=A5=81=E0=A4=AE=E0=A4=BE=E0=A4=B0=29?= Date: Sat, 27 Apr 2024 21:11:16 +0900 Subject: [PATCH 05/36] fix(OrbitControls): restore touchAction on dispose --- src/controls/OrbitControls.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/controls/OrbitControls.ts b/src/controls/OrbitControls.ts index c25da9b9..87af957d 100644 --- a/src/controls/OrbitControls.ts +++ b/src/controls/OrbitControls.ts @@ -413,6 +413,10 @@ class OrbitControls extends EventDispatcher { } this.dispose = (): void => { + // Enabling touch scroll + if(scope.domElement) { + scope.domElement.style.touchAction = 'auto' + } scope.domElement?.removeEventListener('contextmenu', onContextMenu) scope.domElement?.removeEventListener('pointerdown', onPointerDown) scope.domElement?.removeEventListener('pointercancel', onPointerCancel) From fb716b0a814f0db0b37e7b8f22894520e7d58218 Mon Sep 17 00:00:00 2001 From: Cody Bennett Date: Sat, 27 Apr 2024 18:51:20 -0500 Subject: [PATCH 06/36] fix(RGBELoader): upstream fixes (#358) --- src/loaders/RGBELoader.js | 114 +++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 64 deletions(-) diff --git a/src/loaders/RGBELoader.js b/src/loaders/RGBELoader.js index cc05475c..6c5fc8d6 100644 --- a/src/loaders/RGBELoader.js +++ b/src/loaders/RGBELoader.js @@ -13,10 +13,7 @@ class RGBELoader extends DataTextureLoader { // adapted from http://www.graphics.cornell.edu/~bjw/rgbe.html parse(buffer) { - const /* return codes for rgbe routines */ - //RGBE_RETURN_SUCCESS = 0, - RGBE_RETURN_FAILURE = -1, - /* default error routine. change this to change error handling */ + const /* default error routine. change this to change error handling */ rgbe_read_error = 1, rgbe_write_error = 2, rgbe_format_error = 3, @@ -24,20 +21,15 @@ class RGBELoader extends DataTextureLoader { rgbe_error = function (rgbe_error_code, msg) { switch (rgbe_error_code) { case rgbe_read_error: - console.error('THREE.RGBELoader Read Error: ' + (msg || '')) - break + throw new Error('THREE.RGBELoader: Read Error: ' + (msg || '')) case rgbe_write_error: - console.error('THREE.RGBELoader Write Error: ' + (msg || '')) - break + throw new Error('THREE.RGBELoader: Write Error: ' + (msg || '')) case rgbe_format_error: - console.error('THREE.RGBELoader Bad File Format: ' + (msg || '')) - break + throw new Error('THREE.RGBELoader: Bad File Format: ' + (msg || '')) default: case rgbe_memory_error: - console.error('THREE.RGBELoader: Error: ' + (msg || '')) + throw new Error('THREE.RGBELoader: Memory Error: ' + (msg || '')) } - - return RGBE_RETURN_FAILURE }, /* offsets to red, green, and blue components in a data (float) pixel */ //RGBE_DATA_RED = 0, @@ -113,12 +105,12 @@ class RGBELoader extends DataTextureLoader { let line, match if (buffer.pos >= buffer.byteLength || !(line = fgets(buffer))) { - return rgbe_error(rgbe_read_error, 'no header found') + rgbe_error(rgbe_read_error, 'no header found') } /* if you want to require the magic token then uncomment the next line */ if (!(match = line.match(magic_token_re))) { - return rgbe_error(rgbe_format_error, 'bad initial token') + rgbe_error(rgbe_format_error, 'bad initial token') } header.valid |= RGBE_VALID_PROGRAMTYPE @@ -158,11 +150,11 @@ class RGBELoader extends DataTextureLoader { } if (!(header.valid & RGBE_VALID_FORMAT)) { - return rgbe_error(rgbe_format_error, 'missing format specifier') + rgbe_error(rgbe_format_error, 'missing format specifier') } if (!(header.valid & RGBE_VALID_DIMENSIONS)) { - return rgbe_error(rgbe_format_error, 'missing image size specifier') + rgbe_error(rgbe_format_error, 'missing image size specifier') } return header @@ -184,13 +176,13 @@ class RGBELoader extends DataTextureLoader { } if (scanline_width !== ((buffer[2] << 8) | buffer[3])) { - return rgbe_error(rgbe_format_error, 'wrong scanline width') + rgbe_error(rgbe_format_error, 'wrong scanline width') } const data_rgba = new Uint8Array(4 * w * h) if (!data_rgba.length) { - return rgbe_error(rgbe_memory_error, 'unable to allocate buffer space') + rgbe_error(rgbe_memory_error, 'unable to allocate buffer space') } let offset = 0, @@ -204,7 +196,7 @@ class RGBELoader extends DataTextureLoader { // read in each successive scanline while (num_scanlines > 0 && pos < buffer.byteLength) { if (pos + 4 > buffer.byteLength) { - return rgbe_error(rgbe_read_error) + rgbe_error(rgbe_read_error) } rgbeStart[0] = buffer[pos++] @@ -213,7 +205,7 @@ class RGBELoader extends DataTextureLoader { rgbeStart[3] = buffer[pos++] if (2 != rgbeStart[0] || 2 != rgbeStart[1] || ((rgbeStart[2] << 8) | rgbeStart[3]) != scanline_width) { - return rgbe_error(rgbe_format_error, 'bad rgbe scanline format') + rgbe_error(rgbe_format_error, 'bad rgbe scanline format') } // read each of the four channels for the scanline into the buffer @@ -227,7 +219,7 @@ class RGBELoader extends DataTextureLoader { if (isEncodedRun) count -= 128 if (0 === count || ptr + count > ptr_end) { - return rgbe_error(rgbe_format_error, 'bad scanline data') + rgbe_error(rgbe_format_error, 'bad scanline data') } if (isEncodedRun) { @@ -291,58 +283,52 @@ class RGBELoader extends DataTextureLoader { byteArray.pos = 0 const rgbe_header_info = RGBE_ReadHeader(byteArray) - if (RGBE_RETURN_FAILURE !== rgbe_header_info) { - const w = rgbe_header_info.width, - h = rgbe_header_info.height, - image_rgba_data = RGBE_ReadPixels_RLE(byteArray.subarray(byteArray.pos), w, h) - - if (RGBE_RETURN_FAILURE !== image_rgba_data) { - let data, type - let numElements - - switch (this.type) { - case FloatType: - numElements = image_rgba_data.length / 4 - const floatArray = new Float32Array(numElements * 4) + const w = rgbe_header_info.width, + h = rgbe_header_info.height, + image_rgba_data = RGBE_ReadPixels_RLE(byteArray.subarray(byteArray.pos), w, h) - for (let j = 0; j < numElements; j++) { - RGBEByteToRGBFloat(image_rgba_data, j * 4, floatArray, j * 4) - } + let data, type + let numElements - data = floatArray - type = FloatType - break + switch (this.type) { + case FloatType: + numElements = image_rgba_data.length / 4 + const floatArray = new Float32Array(numElements * 4) - case HalfFloatType: - numElements = image_rgba_data.length / 4 - const halfArray = new Uint16Array(numElements * 4) + for (let j = 0; j < numElements; j++) { + RGBEByteToRGBFloat(image_rgba_data, j * 4, floatArray, j * 4) + } - for (let j = 0; j < numElements; j++) { - RGBEByteToRGBHalf(image_rgba_data, j * 4, halfArray, j * 4) - } + data = floatArray + type = FloatType + break - data = halfArray - type = HalfFloatType - break + case HalfFloatType: + numElements = image_rgba_data.length / 4 + const halfArray = new Uint16Array(numElements * 4) - default: - console.error('THREE.RGBELoader: unsupported type: ', this.type) - break + for (let j = 0; j < numElements; j++) { + RGBEByteToRGBHalf(image_rgba_data, j * 4, halfArray, j * 4) } - return { - width: w, - height: h, - data: data, - header: rgbe_header_info.string, - gamma: rgbe_header_info.gamma, - exposure: rgbe_header_info.exposure, - type: type, - } - } + data = halfArray + type = HalfFloatType + break + + default: + throw new Error('THREE.RGBELoader: Unsupported type: ' + this.type) + break } - return null + return { + width: w, + height: h, + data: data, + header: rgbe_header_info.string, + gamma: rgbe_header_info.gamma, + exposure: rgbe_header_info.exposure, + type: type, + } } setDataType(value) { From ea1e4bfeb69f802068c39b8a5cf6348ce48903d6 Mon Sep 17 00:00:00 2001 From: Cody Bennett Date: Sat, 27 Apr 2024 19:12:33 -0500 Subject: [PATCH 07/36] fix(SVGLoader): upstream fixes (#359) --- src/loaders/SVGLoader.js | 278 ++++++++++++++++++++++++++++++++------- 1 file changed, 229 insertions(+), 49 deletions(-) diff --git a/src/loaders/SVGLoader.js b/src/loaders/SVGLoader.js index 7f1e1bac..b8879e62 100644 --- a/src/loaders/SVGLoader.js +++ b/src/loaders/SVGLoader.js @@ -13,6 +13,8 @@ import { Vector3, } from 'three' +const COLOR_SPACE_SVG = 'srgb' + class SVGLoader extends Loader { constructor(manager) { super(manager) @@ -59,12 +61,13 @@ class SVGLoader extends Loader { const transform = getNodeTransform(node) - let traverseChildNodes = true + let isDefsNode = false let path = null switch (node.nodeName) { case 'svg': + style = parseStyle(node, style) break case 'style': @@ -111,16 +114,14 @@ class SVGLoader extends Loader { break case 'defs': - traverseChildNodes = false - break - - case 'mask': - traverseChildNodes = false + isDefsNode = true break case 'use': style = parseStyle(node, style) - const usedNodeId = node.href.baseVal.substring(1) + + const href = node.getAttributeNS('http://www.w3.org/1999/xlink', 'href') || '' + const usedNodeId = href.substring(1) const usedNode = node.viewportElement.getElementById(usedNodeId) if (usedNode) { parseNode(usedNode, style) @@ -136,7 +137,7 @@ class SVGLoader extends Loader { if (path) { if (style.fill !== undefined && style.fill !== 'none') { - path.color.setStyle(style.fill) + path.color.setStyle(style.fill, COLOR_SPACE_SVG) } transformPath(path, currentTransform) @@ -146,12 +147,19 @@ class SVGLoader extends Loader { path.userData = { node: node, style: style } } - if (traverseChildNodes) { - const nodes = node.childNodes + const childNodes = node.childNodes - for (let i = 0; i < nodes.length; i++) { - parseNode(nodes[i], style) + for (let i = 0; i < childNodes.length; i++) { + const node = childNodes[i] + + if (isDefsNode && node.nodeName !== 'style' && node.nodeName !== 'defs') { + // Ignore everything in defs except CSS style definitions + // and nested defs, because it is OK by the standard to have + //