Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tree-shaking #395

Merged
merged 4 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions src/_polyfill/CapsuleGeometry.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import { Path, LatheGeometry } from 'three'

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

super(path.getPoints(capSegments), radialSegments)
super(path.getPoints(capSegments), radialSegments)

this.type = 'CapsuleGeometry'
this.type = 'CapsuleGeometry'

this.parameters = {
radius: radius,
height: length,
capSegments: capSegments,
radialSegments: radialSegments,
this.parameters = {
radius: radius,
height: length,
capSegments: capSegments,
radialSegments: radialSegments,
}
}
}

static fromJSON(data) {
return new CapsuleGeometry(data.radius, data.length, data.capSegments, data.radialSegments)
static fromJSON(data) {
return new CapsuleGeometry(data.radius, data.length, data.capSegments, data.radialSegments)
}
}
}

return CapsuleGeometry
})()

export { CapsuleGeometry }
2 changes: 1 addition & 1 deletion src/_polyfill/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { REVISION } from 'three'

export const version = parseInt(REVISION.replace(/\D+/g, ''))
export const version = /* @__PURE__ */ (() => parseInt(REVISION.replace(/\D+/g, '')))()
26 changes: 13 additions & 13 deletions src/animation/AnimationClipCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
VectorKeyframeTrack,
} from 'three'

class AnimationClipCreator {
static CreateRotationAnimation(period, axis = 'x') {
const AnimationClipCreator = {
CreateRotationAnimation(period, axis = 'x') {
const times = [0, period],
values = [0, 360]

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

return new AnimationClip(null, period, [track])
}
},

static CreateScaleAxisAnimation(period, axis = 'x') {
CreateScaleAxisAnimation(period, axis = 'x') {
const times = [0, period],
values = [0, 1]

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

return new AnimationClip(null, period, [track])
}
},

static CreateShakeAnimation(duration, shakeScale) {
CreateShakeAnimation(duration, shakeScale) {
const times = [],
values = [],
tmp = new Vector3()
Expand All @@ -49,9 +49,9 @@ class AnimationClipCreator {
const track = new VectorKeyframeTrack(trackName, times, values)

return new AnimationClip(null, duration, [track])
}
},

static CreatePulsationAnimation(duration, pulseScale) {
CreatePulsationAnimation(duration, pulseScale) {
const times = [],
values = [],
tmp = new Vector3()
Expand All @@ -68,9 +68,9 @@ class AnimationClipCreator {
const track = new VectorKeyframeTrack(trackName, times, values)

return new AnimationClip(null, duration, [track])
}
},

static CreateVisibilityAnimation(duration) {
CreateVisibilityAnimation(duration) {
const times = [0, duration / 2, duration],
values = [true, false, true]

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

return new AnimationClip(null, duration, [track])
}
},

static CreateMaterialColorAnimation(duration, colors) {
CreateMaterialColorAnimation(duration, colors) {
const times = [],
values = [],
timeStep = duration / colors.length
Expand All @@ -98,7 +98,7 @@ class AnimationClipCreator {
const track = new ColorKeyframeTrack(trackName, times, values)

return new AnimationClip(null, duration, [track])
}
},
}

export { AnimationClipCreator }
22 changes: 11 additions & 11 deletions src/animation/CCDIKSolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import {
Vector3,
} from 'three'

const _q = new Quaternion()
const _targetPos = new Vector3()
const _targetVec = new Vector3()
const _effectorPos = new Vector3()
const _effectorVec = new Vector3()
const _linkPos = new Vector3()
const _invLinkQ = new Quaternion()
const _linkScale = new Vector3()
const _axis = new Vector3()
const _vector = new Vector3()
const _matrix = new Matrix4()
const _q = /* @__PURE__ */ new Quaternion()
const _targetPos = /* @__PURE__ */ new Vector3()
const _targetVec = /* @__PURE__ */ new Vector3()
const _effectorPos = /* @__PURE__ */ new Vector3()
const _effectorVec = /* @__PURE__ */ new Vector3()
const _linkPos = /* @__PURE__ */ new Vector3()
const _invLinkQ = /* @__PURE__ */ new Quaternion()
const _linkScale = /* @__PURE__ */ new Vector3()
const _axis = /* @__PURE__ */ new Vector3()
const _vector = /* @__PURE__ */ new Vector3()
const _matrix = /* @__PURE__ */ new Matrix4()

/**
* CCD Algorithm
Expand Down
2 changes: 1 addition & 1 deletion src/animation/MMDAnimationHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ class AudioManager {
}
}

const _q = new Quaternion()
const _q = /* @__PURE__ */ new Quaternion()

/**
* Solver for Grant (Fuyo in Japanese. I just google translated because
Expand Down
8 changes: 4 additions & 4 deletions src/animation/MMDPhysics.js
Original file line number Diff line number Diff line change
Expand Up @@ -1001,10 +1001,10 @@ class Constraint {
}
}

const _position = new Vector3()
const _quaternion = new Quaternion()
const _scale = new Vector3()
const _matrixWorldInv = new Matrix4()
const _position = /* @__PURE__ */ new Vector3()
const _quaternion = /* @__PURE__ */ new Quaternion()
const _scale = /* @__PURE__ */ new Vector3()
const _matrixWorldInv = /* @__PURE__ */ new Matrix4()

class MMDPhysicsHelper extends Object3D {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/controls/ArcballControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ const _center = {

//transformation matrices for gizmos and camera
const _transformation: Transformation = {
camera: new Matrix4(),
gizmos: new Matrix4(),
camera: /* @__PURE__ */ new Matrix4(),
gizmos: /* @__PURE__ */ new Matrix4(),
}

//events
Expand Down
2 changes: 1 addition & 1 deletion src/controls/FirstPersonControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MathUtils, Spherical, Vector3, Camera } from 'three'
import { EventDispatcher } from './EventDispatcher'
import { StandardControlsEventMap } from './StandardControlsEventMap'

const targetPosition = new Vector3()
const targetPosition = /* @__PURE__ */ new Vector3()

export class FirstPersonControls extends EventDispatcher<{}> {
public object: Camera
Expand Down
17 changes: 8 additions & 9 deletions src/controls/OrbitControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
import { EventDispatcher } from './EventDispatcher'
import { StandardControlsEventMap } from './StandardControlsEventMap'

const _ray = new Ray()
const _plane = new Plane()
const _ray = /* @__PURE__ */ new Ray()
const _plane = /* @__PURE__ */ new Plane()
const TILT_LIMIT = Math.cos(70 * (Math.PI / 180))

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


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

this.dollyOut = (dollyScale = getZoomScale()) => {
dollyOut(dollyScale)
scope.update()
dollyOut(dollyScale)
scope.update()
}

this.getScale = () => {
return scale;
return scale
}

this.setScale = (newScale) => {
setScale(newScale)
scope.update()
setScale(newScale)
scope.update()
}

this.getZoomScale = () => {
return getZoomScale();
return getZoomScale()
}

// connect events
Expand Down
10 changes: 5 additions & 5 deletions src/controls/PointerLockControls.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Euler, Camera, Vector3 } from 'three'
import { EventDispatcher } from './EventDispatcher'

const _euler = new Euler(0, 0, 0, 'YXZ')
const _vector = new Vector3()
const _euler = /* @__PURE__ */ new Euler(0, 0, 0, 'YXZ')
const _vector = /* @__PURE__ */ new Vector3()
const _changeEvent = { type: 'change' }
const _lockEvent = { type: 'lock' }
const _unlockEvent = { type: 'unlock' }
Expand All @@ -12,17 +12,17 @@ export interface PointerLockControlsEventMap {
/**
* Fires when the user moves the mouse.
*/
change: {};
change: {}

/**
* Fires when the pointer lock status is "locked" (in other words: the mouse is captured).
*/
lock: {};
lock: {}

/**
* Fires when the pointer lock status is "unlocked" (in other words: the mouse is not captured anymore).
*/
unlock: {};
unlock: {}
}

class PointerLockControls extends EventDispatcher<PointerLockControlsEventMap> {
Expand Down
8 changes: 4 additions & 4 deletions src/csm/CSM.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Vector2, Vector3, DirectionalLight, MathUtils, ShaderChunk, Matrix4, Bo
import { CSMFrustum } from './CSMFrustum'
import { CSMShader } from './CSMShader'

const _cameraToLightMatrix = new Matrix4()
const _lightSpaceFrustum = new CSMFrustum()
const _center = new Vector3()
const _bbox = new Box3()
const _cameraToLightMatrix = /* @__PURE__ */ new Matrix4()
const _lightSpaceFrustum = /* @__PURE__ */ new CSMFrustum()
const _center = /* @__PURE__ */ new Vector3()
const _bbox = /* @__PURE__ */ new Box3()
const _uniformArray = []
const _logArray = []

Expand Down
2 changes: 1 addition & 1 deletion src/csm/CSMFrustum.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Vector3, Matrix4 } from 'three'

const inverseProjectionMatrix = new Matrix4()
const inverseProjectionMatrix = /* @__PURE__ */ new Matrix4()

class CSMFrustum {
constructor(data) {
Expand Down
Loading
Loading