Skip to content

Conversation

abernier
Copy link
Collaborator

@abernier abernier commented Jul 26, 2025

when subclassing, due to :

const VERSION = '__VERSION'; // will be replaced with `version` in package.json during the build process.
const TOUCH_DOLLY_FACTOR = 1 / 8;
const isMac = /Mac/.test( globalThis?.navigator?.platform );
let THREE: THREESubset;
let _ORIGIN: _THREE.Vector3;
let _AXIS_Y: _THREE.Vector3;
let _AXIS_Z: _THREE.Vector3;
let _v2: _THREE.Vector2;
let _v3A: _THREE.Vector3;
let _v3B: _THREE.Vector3;
let _v3C: _THREE.Vector3;
let _cameraDirection: _THREE.Vector3;
let _xColumn: _THREE.Vector3;
let _yColumn: _THREE.Vector3;
let _zColumn: _THREE.Vector3;
let _deltaTarget: _THREE.Vector3;
let _deltaOffset: _THREE.Vector3;
let _sphericalA: _THREE.Spherical;
let _sphericalB: _THREE.Spherical;
let _box3A: _THREE.Box3;
let _box3B: _THREE.Box3;
let _sphere: _THREE.Sphere;
let _quaternionA: _THREE.Quaternion;
let _quaternionB: _THREE.Quaternion;
let _rotationMatrix: _THREE.Matrix4;
let _raycaster: _THREE.Raycaster;

it becomes difficult to override any method that uses thoses module closured vars

import * as _THREE from "three";

const _box3A = new _THREE.Box3(); // ⚠️ we should redeclare any closure-var

class MyCameraControls extends CameraControls {
  fitToBox() {
    // ...
    const aabb = (box3OrObject as _THREE.Box3).isBox3
      ? _box3A.copy(box3OrObject as _THREE.Box3)
      : _box3A.setFromObject(box3OrObject as _THREE.Object3D);
    // ...
  }
}

with this PR, all closure vars are now consumed as eg: this. so more portable

@abernier
Copy link
Collaborator Author

in bb73162

i'm exporting more so, when subclassing, we can easily reuse without re-declaring utilities like approxEquals or anything

@abernier abernier self-assigned this Jul 26, 2025
@abernier abernier requested a review from yomotsu July 26, 2025 09:15
@abernier abernier closed this Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant