Skip to content

Commit e925563

Browse files
fix: tree-shaking
Re-release of #395 with necessary workarounds for TypeScript class inference
1 parent bc97e08 commit e925563

File tree

133 files changed

+11725
-11544
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+11725
-11544
lines changed

Diff for: src/_polyfill/CapsuleGeometry.js

+20-16
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
import { Path, LatheGeometry } from 'three'
22

3-
class CapsuleGeometry extends LatheGeometry {
4-
constructor(radius = 1, length = 1, capSegments = 4, radialSegments = 8) {
5-
const path = new Path()
6-
path.absarc(0, -length / 2, radius, Math.PI * 1.5, 0)
7-
path.absarc(0, length / 2, radius, 0, Math.PI * 0.5)
3+
const CapsuleGeometry = /* @__PURE__ */ (() => {
4+
class CapsuleGeometry extends LatheGeometry {
5+
constructor(radius = 1, length = 1, capSegments = 4, radialSegments = 8) {
6+
const path = new Path()
7+
path.absarc(0, -length / 2, radius, Math.PI * 1.5, 0)
8+
path.absarc(0, length / 2, radius, 0, Math.PI * 0.5)
89

9-
super(path.getPoints(capSegments), radialSegments)
10+
super(path.getPoints(capSegments), radialSegments)
1011

11-
this.type = 'CapsuleGeometry'
12+
this.type = 'CapsuleGeometry'
1213

13-
this.parameters = {
14-
radius: radius,
15-
height: length,
16-
capSegments: capSegments,
17-
radialSegments: radialSegments,
14+
this.parameters = {
15+
radius: radius,
16+
height: length,
17+
capSegments: capSegments,
18+
radialSegments: radialSegments,
19+
}
1820
}
19-
}
2021

21-
static fromJSON(data) {
22-
return new CapsuleGeometry(data.radius, data.length, data.capSegments, data.radialSegments)
22+
static fromJSON(data) {
23+
return new CapsuleGeometry(data.radius, data.length, data.capSegments, data.radialSegments)
24+
}
2325
}
24-
}
26+
27+
return CapsuleGeometry
28+
})()
2529

2630
export { CapsuleGeometry }

Diff for: src/_polyfill/constants.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import { REVISION } from 'three'
22

3-
export const version = parseInt(REVISION.replace(/\D+/g, ''))
3+
export const version = /* @__PURE__ */ (() => parseInt(REVISION.replace(/\D+/g, '')))()

Diff for: src/animation/AnimationClipCreator.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
VectorKeyframeTrack,
88
} from 'three'
99

10-
class AnimationClipCreator {
11-
static CreateRotationAnimation(period, axis = 'x') {
10+
const AnimationClipCreator = {
11+
CreateRotationAnimation(period, axis = 'x') {
1212
const times = [0, period],
1313
values = [0, 360]
1414

@@ -17,9 +17,9 @@ class AnimationClipCreator {
1717
const track = new NumberKeyframeTrack(trackName, times, values)
1818

1919
return new AnimationClip(null, period, [track])
20-
}
20+
},
2121

22-
static CreateScaleAxisAnimation(period, axis = 'x') {
22+
CreateScaleAxisAnimation(period, axis = 'x') {
2323
const times = [0, period],
2424
values = [0, 1]
2525

@@ -28,9 +28,9 @@ class AnimationClipCreator {
2828
const track = new NumberKeyframeTrack(trackName, times, values)
2929

3030
return new AnimationClip(null, period, [track])
31-
}
31+
},
3232

33-
static CreateShakeAnimation(duration, shakeScale) {
33+
CreateShakeAnimation(duration, shakeScale) {
3434
const times = [],
3535
values = [],
3636
tmp = new Vector3()
@@ -49,9 +49,9 @@ class AnimationClipCreator {
4949
const track = new VectorKeyframeTrack(trackName, times, values)
5050

5151
return new AnimationClip(null, duration, [track])
52-
}
52+
},
5353

54-
static CreatePulsationAnimation(duration, pulseScale) {
54+
CreatePulsationAnimation(duration, pulseScale) {
5555
const times = [],
5656
values = [],
5757
tmp = new Vector3()
@@ -68,9 +68,9 @@ class AnimationClipCreator {
6868
const track = new VectorKeyframeTrack(trackName, times, values)
6969

7070
return new AnimationClip(null, duration, [track])
71-
}
71+
},
7272

73-
static CreateVisibilityAnimation(duration) {
73+
CreateVisibilityAnimation(duration) {
7474
const times = [0, duration / 2, duration],
7575
values = [true, false, true]
7676

@@ -79,9 +79,9 @@ class AnimationClipCreator {
7979
const track = new BooleanKeyframeTrack(trackName, times, values)
8080

8181
return new AnimationClip(null, duration, [track])
82-
}
82+
},
8383

84-
static CreateMaterialColorAnimation(duration, colors) {
84+
CreateMaterialColorAnimation(duration, colors) {
8585
const times = [],
8686
values = [],
8787
timeStep = duration / colors.length
@@ -98,7 +98,7 @@ class AnimationClipCreator {
9898
const track = new ColorKeyframeTrack(trackName, times, values)
9999

100100
return new AnimationClip(null, duration, [track])
101-
}
101+
},
102102
}
103103

104104
export { AnimationClipCreator }

Diff for: src/animation/CCDIKSolver.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ import {
1313
Vector3,
1414
} from 'three'
1515

16-
const _q = new Quaternion()
17-
const _targetPos = new Vector3()
18-
const _targetVec = new Vector3()
19-
const _effectorPos = new Vector3()
20-
const _effectorVec = new Vector3()
21-
const _linkPos = new Vector3()
22-
const _invLinkQ = new Quaternion()
23-
const _linkScale = new Vector3()
24-
const _axis = new Vector3()
25-
const _vector = new Vector3()
26-
const _matrix = new Matrix4()
16+
const _q = /* @__PURE__ */ new Quaternion()
17+
const _targetPos = /* @__PURE__ */ new Vector3()
18+
const _targetVec = /* @__PURE__ */ new Vector3()
19+
const _effectorPos = /* @__PURE__ */ new Vector3()
20+
const _effectorVec = /* @__PURE__ */ new Vector3()
21+
const _linkPos = /* @__PURE__ */ new Vector3()
22+
const _invLinkQ = /* @__PURE__ */ new Quaternion()
23+
const _linkScale = /* @__PURE__ */ new Vector3()
24+
const _axis = /* @__PURE__ */ new Vector3()
25+
const _vector = /* @__PURE__ */ new Vector3()
26+
const _matrix = /* @__PURE__ */ new Matrix4()
2727

2828
/**
2929
* CCD Algorithm

Diff for: src/animation/MMDAnimationHelper.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ class AudioManager {
861861
}
862862
}
863863

864-
const _q = new Quaternion()
864+
const _q = /* @__PURE__ */ new Quaternion()
865865

866866
/**
867867
* Solver for Grant (Fuyo in Japanese. I just google translated because

Diff for: src/animation/MMDPhysics.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1001,10 +1001,10 @@ class Constraint {
10011001
}
10021002
}
10031003

1004-
const _position = new Vector3()
1005-
const _quaternion = new Quaternion()
1006-
const _scale = new Vector3()
1007-
const _matrixWorldInv = new Matrix4()
1004+
const _position = /* @__PURE__ */ new Vector3()
1005+
const _quaternion = /* @__PURE__ */ new Quaternion()
1006+
const _scale = /* @__PURE__ */ new Vector3()
1007+
const _matrixWorldInv = /* @__PURE__ */ new Matrix4()
10081008

10091009
class MMDPhysicsHelper extends Object3D {
10101010
/**

Diff for: src/controls/ArcballControls.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ const _center = {
6868

6969
//transformation matrices for gizmos and camera
7070
const _transformation: Transformation = {
71-
camera: new Matrix4(),
72-
gizmos: new Matrix4(),
71+
camera: /* @__PURE__ */ new Matrix4(),
72+
gizmos: /* @__PURE__ */ new Matrix4(),
7373
}
7474

7575
//events

Diff for: src/controls/FirstPersonControls.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { MathUtils, Spherical, Vector3, Camera } from 'three'
22
import { EventDispatcher } from './EventDispatcher'
33
import { StandardControlsEventMap } from './StandardControlsEventMap'
44

5-
const targetPosition = new Vector3()
5+
const targetPosition = /* @__PURE__ */ new Vector3()
66

77
export class FirstPersonControls extends EventDispatcher<{}> {
88
public object: Camera

Diff for: src/controls/OrbitControls.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import {
1414
import { EventDispatcher } from './EventDispatcher'
1515
import { StandardControlsEventMap } from './StandardControlsEventMap'
1616

17-
const _ray = new Ray()
18-
const _plane = new Plane()
17+
const _ray = /* @__PURE__ */ new Ray()
18+
const _plane = /* @__PURE__ */ new Plane()
1919
const TILT_LIMIT = Math.cos(70 * (Math.PI / 180))
2020

2121
// This set of controls performs orbiting, dollying (zooming), and panning.
@@ -119,7 +119,6 @@ class OrbitControls extends EventDispatcher<StandardControlsEventMap> {
119119
getScale: () => number
120120
// Set the current scale (these are not used in most scenarios, however they can be useful for specific use cases)
121121
setScale: (newScale: number) => void
122-
123122

124123
constructor(object: PerspectiveCamera | OrthographicCamera, domElement?: HTMLElement) {
125124
super()
@@ -1096,21 +1095,21 @@ class OrbitControls extends EventDispatcher<StandardControlsEventMap> {
10961095
}
10971096

10981097
this.dollyOut = (dollyScale = getZoomScale()) => {
1099-
dollyOut(dollyScale)
1100-
scope.update()
1098+
dollyOut(dollyScale)
1099+
scope.update()
11011100
}
11021101

11031102
this.getScale = () => {
1104-
return scale;
1103+
return scale
11051104
}
11061105

11071106
this.setScale = (newScale) => {
1108-
setScale(newScale)
1109-
scope.update()
1107+
setScale(newScale)
1108+
scope.update()
11101109
}
11111110

11121111
this.getZoomScale = () => {
1113-
return getZoomScale();
1112+
return getZoomScale()
11141113
}
11151114

11161115
// connect events

Diff for: src/controls/PointerLockControls.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Euler, Camera, Vector3 } from 'three'
22
import { EventDispatcher } from './EventDispatcher'
33

4-
const _euler = new Euler(0, 0, 0, 'YXZ')
5-
const _vector = new Vector3()
4+
const _euler = /* @__PURE__ */ new Euler(0, 0, 0, 'YXZ')
5+
const _vector = /* @__PURE__ */ new Vector3()
66
const _changeEvent = { type: 'change' }
77
const _lockEvent = { type: 'lock' }
88
const _unlockEvent = { type: 'unlock' }
@@ -12,17 +12,17 @@ export interface PointerLockControlsEventMap {
1212
/**
1313
* Fires when the user moves the mouse.
1414
*/
15-
change: {};
15+
change: {}
1616

1717
/**
1818
* Fires when the pointer lock status is "locked" (in other words: the mouse is captured).
1919
*/
20-
lock: {};
20+
lock: {}
2121

2222
/**
2323
* Fires when the pointer lock status is "unlocked" (in other words: the mouse is not captured anymore).
2424
*/
25-
unlock: {};
25+
unlock: {}
2626
}
2727

2828
class PointerLockControls extends EventDispatcher<PointerLockControlsEventMap> {

Diff for: src/csm/CSM.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { Vector2, Vector3, DirectionalLight, MathUtils, ShaderChunk, Matrix4, Bo
22
import { CSMFrustum } from './CSMFrustum'
33
import { CSMShader } from './CSMShader'
44

5-
const _cameraToLightMatrix = new Matrix4()
6-
const _lightSpaceFrustum = new CSMFrustum()
7-
const _center = new Vector3()
8-
const _bbox = new Box3()
5+
const _cameraToLightMatrix = /* @__PURE__ */ new Matrix4()
6+
const _lightSpaceFrustum = /* @__PURE__ */ new CSMFrustum()
7+
const _center = /* @__PURE__ */ new Vector3()
8+
const _bbox = /* @__PURE__ */ new Box3()
99
const _uniformArray = []
1010
const _logArray = []
1111

Diff for: src/csm/CSMFrustum.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Vector3, Matrix4 } from 'three'
22

3-
const inverseProjectionMatrix = new Matrix4()
3+
const inverseProjectionMatrix = /* @__PURE__ */ new Matrix4()
44

55
class CSMFrustum {
66
constructor(data) {

0 commit comments

Comments
 (0)