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

ESM Scripts #5764

Closed
wants to merge 146 commits into from
Closed
Show file tree
Hide file tree
Changes from 117 commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
f520c67
Preliminary support for ES Modules
marklundin Oct 18, 2023
40c664c
Fixed linting issues
marklundin Oct 18, 2023
fe3efec
Modified the ES Script format API. Added swap method
marklundin Oct 23, 2023
9d24a07
Added HMR 'swap' to ES Modules
marklundin Oct 26, 2023
274309d
Adding ASSET_BASE_URL to support module importing
marklundin Oct 26, 2023
4841323
Added CORS flag to `npm run serve`
marklundin Oct 26, 2023
e768312
Added _ASSET_BASE_URL fix for dev time
marklundin Oct 26, 2023
2a96c0c
Updated ESModule* naming convention to ScriptESM*
marklundin Oct 26, 2023
762d18d
Fixed missing imports
marklundin Oct 27, 2023
f1696af
removed uneccessary cache
marklundin Oct 27, 2023
6ef4dd1
Cleaned up module specifier import
marklundin Oct 27, 2023
d51230a
Added custom module import script + linting
marklundin Oct 30, 2023
52c3471
Fixed issue with swapped modules being destroyed. Linting issues
marklundin Oct 30, 2023
cb05191
Added module import as template literal. See https://github.com/playc…
marklundin Oct 30, 2023
02fb662
Added correct attributes assignment logic
marklundin Oct 31, 2023
6c4c68b
Prevent module component iterating over all modules
marklundin Oct 31, 2023
e3b9d1e
Script ESM Modules can now be re-ordered in a component
marklundin Nov 1, 2023
9f3ff07
Better documentation. Fixed few edge cases with default values
marklundin Nov 3, 2023
4e6b960
Added examples
marklundin Nov 3, 2023
3dc7ae3
added todo flag to cloning
marklundin Nov 3, 2023
7f0955c
changed naming to EsmScript
marklundin Nov 3, 2023
762caa1
Merge branch 'main' into esmodules
marklundin Nov 3, 2023
1a30002
Fix linting
marklundin Nov 3, 2023
a66fe79
Nested attributes now copy over to modules with same hierarchy
marklundin Nov 6, 2023
9e2da68
Merge branch 'main' into esmodules
marklundin Nov 6, 2023
bd3e347
removed dead code
marklundin Nov 7, 2023
35c93e6
Fixed the ESM Script Component Systems 'clone' method
marklundin Nov 7, 2023
1d45873
Fixed issue that now normalizes module path
marklundin Nov 8, 2023
a659d03
Removed render component on earthtile example
marklundin Nov 8, 2023
a56c825
updated component iteration to use for of loop
marklundin Nov 8, 2023
99c5b1f
documentation update
marklundin Nov 9, 2023
b9f3eee
Merge branch 'main' into esmodules
marklundin Nov 9, 2023
ddd4199
added better documentation for `isValidAttributeDefinition`
marklundin Nov 9, 2023
24a646f
Merge branch 'main' into esmodules
marklundin Nov 9, 2023
fafd773
Fixed types error
marklundin Nov 9, 2023
ecc3e3d
Addresses PR comments
marklundin Nov 10, 2023
eafe253
Merge branch 'main' into esmodules
marklundin Nov 10, 2023
ee0bd96
Updated example
marklundin Nov 10, 2023
61990a4
Adding ignore to documentation
marklundin Nov 10, 2023
2cd077e
added ignore
marklundin Nov 10, 2023
893e2bf
Removed dynamic import and HMR swapping
marklundin Nov 15, 2023
96e3272
Providing new Esm Script Type base class
marklundin Nov 17, 2023
ad9dd97
Fixed linting/types issues
marklundin Nov 17, 2023
673aa2c
Confetti now extends base class
marklundin Nov 21, 2023
177de66
Implemented PR feedback
marklundin Nov 21, 2023
806201f
Added appEntity shorthand
marklundin Nov 21, 2023
8fa2b26
Prevent redundant object creation in update methods
marklundin Nov 21, 2023
d429201
Implemented clone method
marklundin Nov 21, 2023
0b76ad7
Removed Earthatile ESM example
marklundin Nov 21, 2023
1392a62
fixed clone issue
marklundin Nov 21, 2023
22eacf3
Testing nested scripts
marklundin Nov 21, 2023
97649b3
correct imports
marklundin Nov 21, 2023
8244e2b
Fixed issue with late initialized entities
marklundin Nov 21, 2023
d6db607
Added base test classes
marklundin Nov 23, 2023
c4049e1
test fixes
marklundin Nov 23, 2023
e0aa409
additional test
marklundin Nov 23, 2023
443304a
Attributes now correctly resolve arrays and nested props
marklundin Nov 28, 2023
b047e98
merged esmscript test json
marklundin Nov 28, 2023
99cca3f
included esm script tests
marklundin Nov 28, 2023
e34ca79
linting fixes
marklundin Nov 28, 2023
3639e17
Added iniitialize
marklundin Nov 29, 2023
ef57d6c
Adding more tests
marklundin Nov 30, 2023
9e011cb
Merge branch 'main' into esmodules
marklundin Nov 30, 2023
9a02061
Raise an error if a module with the same name is added
marklundin Nov 30, 2023
fe34450
Ensured esm modules are added in correct order
marklundin Dec 1, 2023
633533e
More tests
marklundin Dec 1, 2023
0c0b8cc
Consistent 'ESM Script' naming
marklundin Dec 1, 2023
500e6cd
removed redundant scene
marklundin Dec 1, 2023
22db44d
Moving tests to ESM
marklundin Dec 1, 2023
ef4f2be
Removed redundant NAME field from examples. Sorted imports.
marklundin Dec 1, 2023
0429a3c
documentation improvement.
marklundin Dec 1, 2023
d1ce21f
fixed casing issues
marklundin Dec 1, 2023
9186e18
doc updates. removed some redundant code
marklundin Dec 1, 2023
dad139d
updated docs
marklundin Dec 1, 2023
e1cd169
Merge branch 'esmodules' into esmscript-tests
marklundin Dec 1, 2023
6dd758f
Adding initialize tests
marklundin Dec 1, 2023
b76978d
Fix for undefined attributes in class def
marklundin Dec 4, 2023
381caa5
Merge branch 'esmodules' into esmscript-tests
marklundin Dec 4, 2023
291ba3a
Merge branch 'main' into esmodules
marklundin Dec 4, 2023
230e412
Merge branch 'esmodules' into esmscript-tests
marklundin Dec 4, 2023
0710453
Ported more test over to ES6
marklundin Dec 4, 2023
bff3bb0
Moving tests to ESM
marklundin Dec 1, 2023
009ced3
Adding initialize tests
marklundin Dec 1, 2023
9b5f29a
Ported more test over to ES6
marklundin Dec 4, 2023
a1b8672
Merge branch 'esmscript-tests' into esmodules
marklundin Dec 4, 2023
b2559d3
Add new ESM scripts and update EsmScriptComponent
marklundin Dec 5, 2023
0c04a7f
remove esm test from es5 tests dir
marklundin Dec 5, 2023
444d967
Added scene initialization tests
marklundin Dec 5, 2023
24d1866
Tests: Attribute checks
marklundin Dec 5, 2023
944a020
Added better warning/messaging w/ tests
marklundin Dec 5, 2023
f48643a
Simplified attribute population
marklundin Dec 6, 2023
4c5321b
Enabled attributes test
marklundin Dec 6, 2023
db59d0f
linting fixes
marklundin Dec 6, 2023
c032b26
shimming console.error in tests to remove noise
marklundin Dec 6, 2023
cae0aea
Merge branch 'main' into esmodules
marklundin Dec 6, 2023
daeace9
Add experiemental api warning
marklundin Dec 6, 2023
47ca448
Restrict to `warnOnce`
marklundin Dec 6, 2023
0522633
Doc fixes
marklundin Dec 6, 2023
4fe02bb
doc updates
marklundin Dec 6, 2023
c05ed1a
Jsdoc fixes as per @kungfooman feedbabackl
marklundin Dec 7, 2023
d0982e1
Added OrbitCamera ES Modules example. Removed Hello script Modules ex…
marklundin Dec 7, 2023
6e8bc0c
Added clamping without events
marklundin Dec 7, 2023
5789b07
removed redundant scripts from rollup
marklundin Dec 7, 2023
407903a
removed legacy code from karma tests
marklundin Dec 7, 2023
118e376
Fixed types issues
marklundin Dec 7, 2023
8ea742b
docs + destroy test
marklundin Dec 7, 2023
84c5c67
Attribute definition now a static class member
marklundin Dec 8, 2023
aa2688b
removed redundant attribute Map
marklundin Dec 8, 2023
9a70f07
linting fix
marklundin Dec 8, 2023
bba2a7d
Adde enable/disable tests
marklundin Dec 8, 2023
902d533
Updated orbit example with new static member attribute definition
marklundin Dec 9, 2023
9937fa4
lint fixes
marklundin Dec 11, 2023
7c6e1cc
Added script cache in preload
marklundin Dec 11, 2023
36cbd0f
Removed redundant addComponent
marklundin Dec 11, 2023
6f55849
removed redundant tests
marklundin Dec 11, 2023
880579a
fix lint
marklundin Dec 11, 2023
8f67918
removed unnecessary attr export
marklundin Dec 11, 2023
3da4293
removed redundant exports
marklundin Dec 11, 2023
3953e8d
removed unnecessary export. jsdoc fixes
marklundin Dec 12, 2023
440a145
updated tests to use synchronous calls
marklundin Dec 12, 2023
de693ae
Changed compile time asset lookup to use runtime path
marklundin Dec 12, 2023
1731a4b
removed dead code in tests
marklundin Dec 12, 2023
a083eab
Merge branch 'main' into esmodules
marklundin Dec 12, 2023
89eb9b5
script cache is now scoped to the app
marklundin Dec 12, 2023
97740a3
removed redundant export
marklundin Dec 12, 2023
4bd907d
Update scripts/camera/orbit/orbit-camera-input-mouse.mjs
marklundin Dec 14, 2023
af90e32
Update scripts/camera/orbit/orbit-camera-input-mouse.mjs
marklundin Dec 14, 2023
271b76c
Update scripts/camera/orbit/orbit-camera-input-touch.mjs
marklundin Dec 14, 2023
333606f
Update scripts/camera/orbit/orbit-camera.mjs
marklundin Dec 14, 2023
aff2085
Update scripts/camera/orbit/orbit-camera.mjs
marklundin Dec 14, 2023
fdcf4d0
Update scripts/camera/orbit/orbit-camera.mjs
marklundin Dec 14, 2023
70c9b88
Update scripts/camera/orbit/orbit-camera.mjs
marklundin Dec 14, 2023
ec3af91
Update scripts/camera/orbit/orbit-camera.mjs
marklundin Dec 15, 2023
8e4918f
Update src/framework/components/esmscript/system.js
marklundin Dec 15, 2023
1810d22
Update src/framework/components/esmscript/system.js
marklundin Dec 15, 2023
f12188b
Update scripts/camera/orbit/orbit-camera.mjs
marklundin Dec 15, 2023
9042dae
Update scripts/camera/orbit/orbit-camera.mjs
marklundin Dec 15, 2023
0099dc8
Update scripts/camera/orbit/orbit-camera.mjs
marklundin Dec 15, 2023
3f83c35
Update scripts/camera/orbit/orbit-camera.mjs
marklundin Dec 15, 2023
cee0c70
Update scripts/camera/orbit/orbit-camera.mjs
marklundin Dec 15, 2023
22cf09f
Update scripts/camera/orbit/orbit-camera.mjs
marklundin Dec 15, 2023
972e7c4
Update scripts/camera/orbit/orbit-camera.mjs
marklundin Dec 15, 2023
c4153dd
lint fix
marklundin Dec 15, 2023
c552ee8
attributes are now correctly cloned, not assigned
marklundin Jan 2, 2024
79ca774
ensure deep equal test
marklundin Jan 2, 2024
026f33f
Scripts now have their own `enabled` prop. Removed component level co…
marklundin Jan 10, 2024
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
21 changes: 12 additions & 9 deletions examples/src/examples/camera/orbit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ import * as pc from 'playcanvas';
* @returns {Promise<pc.AppBase>} The example application.
*/
async function example({ canvas, assetPath, scriptsPath }) {

// We currently need to dynamically import the OrbitCamera script
const OrbitCamera = await import(`${scriptsPath}camera/orbit/orbit-camera.mjs`);
const OrbitCameraInputMouse = await import(`${scriptsPath}camera/orbit/orbit-camera-input-mouse.mjs`);
const OrbitCameraInputTouch = await import(`${scriptsPath}camera/orbit/orbit-camera-input-touch.mjs`);

// Create the app and start the update loop
const app = new pc.Application(canvas, {
mouse: new pc.Mouse(document.body),
touch: new pc.TouchDevice(document.body)
});

const assets = {
statue: new pc.Asset('statue', 'container', { url: assetPath + 'models/statue.glb' }),
script: new pc.Asset('script', 'script', { url: scriptsPath + 'camera/orbit-camera.js' })
statue: new pc.Asset('statue', 'container', { url: assetPath + 'models/statue.glb' })
};

// Set the canvas to fill the window and automatically change resolution to be the same as the canvas size
Expand Down Expand Up @@ -51,14 +56,12 @@ async function example({ canvas, assetPath, scriptsPath }) {
camera.addComponent("camera", {
clearColor: new pc.Color(0.4, 0.45, 0.5)
});
camera.addComponent("script");
camera.script.create("orbitCamera", {
attributes: {
inertiaFactor: 0.2 // Override default of 0 (no inertia)
}
camera.addComponent("esmscript");
camera.esmscript.add(OrbitCamera.default, {
inertiaFactor: 0.2 // Override default of 0 (no inertia)
});
camera.script.create("orbitCameraInputMouse");
camera.script.create("orbitCameraInputTouch");
camera.esmscript.add(OrbitCameraInputMouse.default);
camera.esmscript.add(OrbitCameraInputTouch.default);
app.root.addChild(camera);

// Create a directional light
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"docs": "jsdoc -c conf-api.json",
"typedocs": "typedoc",
"lint": "eslint --ext .js,.mjs extras scripts src test utils rollup.config.mjs",
"serve": "serve build -l 51000",
"serve": "serve build -l 51000 -C",
"test": "mocha --recursive --require test/fixtures.mjs",
"test:coverage": "c8 npm test",
"test:karma": "karma start tests/karma.conf.cjs -- --single-run --release",
Expand Down
129 changes: 129 additions & 0 deletions scripts/camera/orbit/orbit-camera-input-mouse.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
////////////////////////////////////////////////////////////////////////////////
// Orbit Camera Mouse Input Script //
////////////////////////////////////////////////////////////////////////////////

const attributes = {
orbitSensitivity: {
type: 'number',
default: 0.3,
title: 'Orbit Sensitivity',
description: 'How fast the camera moves around the orbit. Higher is faster'
},
distanceSensitivity: {
type: 'number',
default: 0.15,
title: 'Distance Sensitivity',
description: 'How fast the camera moves in and out. Higher is faster'
}
};

export default class OrbitCameraInputMouse {
static attributes = attributes;

// initialize code called once per entity
initialize() {
this.orbitCamera = this.entity.esmscript.get('OrbitCamera');

if (this.orbitCamera) {

this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onMouseDown, this);
this.app.mouse.on(pc.EVENT_MOUSEUP, this.onMouseUp, this);
this.app.mouse.on(pc.EVENT_MOUSEMOVE, this.onMouseMove, this);
this.app.mouse.on(pc.EVENT_MOUSEWHEEL, this.onMouseWheel, this);

// Listen to when the mouse travels out of the window
window.addEventListener('mouseout', this.onMouseOut, false);

}

// Disabling the context menu stops the browser displaying a menu when
// you right-click the page
this.app.mouse.disableContextMenu();

this.lookButtonDown = false;
this.panButtonDown = false;
this.lastPoint = new pc.Vec2();
}

// Remove the listeners so if this entity is destroyed
destroy() {
this.app.mouse.off(pc.EVENT_MOUSEDOWN, this.onMouseDown, this);
this.app.mouse.off(pc.EVENT_MOUSEUP, this.onMouseUp, this);
this.app.mouse.off(pc.EVENT_MOUSEMOVE, this.onMouseMove, this);
this.app.mouse.off(pc.EVENT_MOUSEWHEEL, this.onMouseWheel, this);

window.removeEventListener('mouseout', this.onMouseOut, false);
}


static fromWorldPoint = new pc.Vec3();

static toWorldPoint = new pc.Vec3();

static worldDiff = new pc.Vec3();


pan(screenPoint) {
var fromWorldPoint = OrbitCameraInputMouse.fromWorldPoint;
var toWorldPoint = OrbitCameraInputMouse.toWorldPoint;
var worldDiff = OrbitCameraInputMouse.worldDiff;
marklundin marked this conversation as resolved.
Show resolved Hide resolved

// For panning to work at any zoom level, we use screen point to world projection
// to work out how far we need to pan the pivotEntity in world space
var camera = this.entity.camera;
var distance = this.orbitCamera.distance;
marklundin marked this conversation as resolved.
Show resolved Hide resolved

camera.screenToWorld(screenPoint.x, screenPoint.y, distance, fromWorldPoint);
camera.screenToWorld(this.lastPoint.x, this.lastPoint.y, distance, toWorldPoint);

worldDiff.sub2(toWorldPoint, fromWorldPoint);

this.orbitCamera.pivotPoint.add(worldDiff);
}

onMouseDown(event) {
switch (event.button) {
case pc.MOUSEBUTTON_LEFT:
this.lookButtonDown = true;
break;
case pc.MOUSEBUTTON_MIDDLE:
case pc.MOUSEBUTTON_RIGHT:
this.panButtonDown = true;
break;
}
}

onMouseUp(event) {
switch (event.button) {
case pc.MOUSEBUTTON_LEFT:
this.lookButtonDown = false;
break;
case pc.MOUSEBUTTON_MIDDLE:
case pc.MOUSEBUTTON_RIGHT:
this.panButtonDown = false;
break;
}
}

onMouseMove(event) {
if (this.lookButtonDown) {
this.orbitCamera.pitch -= event.dy * this.orbitSensitivity;
this.orbitCamera.yaw -= event.dx * this.orbitSensitivity;

} else if (this.panButtonDown) {
this.pan(event);
}

this.lastPoint.set(event.x, event.y);
}

onMouseWheel(event) {
this.orbitCamera.distance -= event.wheel * this.distanceSensitivity * (this.orbitCamera.distance * 0.1);
event.event.preventDefault();
}

onMouseOut(event) {
this.lookButtonDown = false;
this.panButtonDown = false;
}
}
137 changes: 137 additions & 0 deletions scripts/camera/orbit/orbit-camera-input-touch.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
////////////////////////////////////////////////////////////////////////////////
// Orbit Camera Touch Input Script //
////////////////////////////////////////////////////////////////////////////////

const attributes = {
orbitSensitivity: {
type: 'number',
default: 0.3,
title: 'Orbit Sensitivity',
description: 'How fast the camera moves around the orbit. Higher is faster'
},
distanceSensitivity: {
type: 'number',
default: 0.15,
title: 'Distance Sensitivity',
description: 'How fast the camera moves in and out. Higher is faster'
}
};

export default class OrbitCameraInputTouch {
static attributes = attributes;

// initialize code called once per entity
initialize() {
this.orbitCamera = this.entity.esmscript.get('OrbitCamera');

// Store the position of the touch so we can calculate the distance moved
this.lastTouchPoint = new pc.Vec2();
this.lastPinchMidPoint = new pc.Vec2();
this.lastPinchDistance = 0;

if (this.orbitCamera && this.app.touch) {
// Use the same callback for the touchStart, touchEnd and touchCancel events as they
// all do the same thing which is to deal the possible multiple touches to the screen
this.app.touch.on(pc.EVENT_TOUCHSTART, this.onTouchStartEndCancel, this);
this.app.touch.on(pc.EVENT_TOUCHEND, this.onTouchStartEndCancel, this);
this.app.touch.on(pc.EVENT_TOUCHCANCEL, this.onTouchStartEndCancel, this);

this.app.touch.on(pc.EVENT_TOUCHMOVE, this.onTouchMove, this);

}
}

destroy() {
this.app.touch.off(pc.EVENT_TOUCHSTART, this.onTouchStartEndCancel, this);
this.app.touch.off(pc.EVENT_TOUCHEND, this.onTouchStartEndCancel, this);
this.app.touch.off(pc.EVENT_TOUCHCANCEL, this.onTouchStartEndCancel, this);

this.app.touch.off(pc.EVENT_TOUCHMOVE, this.onTouchMove, this);
}

getPinchDistance(pointA, pointB) {
// Return the distance between the two points
var dx = pointA.x - pointB.x;
var dy = pointA.y - pointB.y;
Comment on lines +54 to +55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var dx = pointA.x - pointB.x;
var dy = pointA.y - pointB.y;
const dx = pointA.x - pointB.x;
const dy = pointA.y - pointB.y;


return Math.sqrt((dx * dx) + (dy * dy));
}

calcMidPoint(pointA, pointB, result) {
result.set(pointB.x - pointA.x, pointB.y - pointA.y);
result.mulScalar(0.5);
result.x += pointA.x;
result.y += pointA.y;
}

onTouchStartEndCancel(event) {
// We only care about the first touch for camera rotation. As the user touches the screen,
// we stored the current touch position
var touches = event.touches;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var touches = event.touches;
const touches = event.touches;

if (touches.length === 1) {
this.lastTouchPoint.set(touches[0].x, touches[0].y);

} else if (touches.length === 2) {
// If there are 2 touches on the screen, then set the pinch distance
this.lastPinchDistance = this.getPinchDistance(touches[0], touches[1]);
this.calcMidPoint(touches[0], touches[1], this.lastPinchMidPoint);
}
}

static fromWorldPoint = new pc.Vec3();

static toWorldPoint = new pc.Vec3();

static worldDiff = new pc.Vec3();


pan(midPoint) {
var fromWorldPoint = OrbitCameraInputTouch.fromWorldPoint;
var toWorldPoint = OrbitCameraInputTouch.toWorldPoint;
var worldDiff = OrbitCameraInputTouch.worldDiff;
Comment on lines +89 to +91
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var fromWorldPoint = OrbitCameraInputTouch.fromWorldPoint;
var toWorldPoint = OrbitCameraInputTouch.toWorldPoint;
var worldDiff = OrbitCameraInputTouch.worldDiff;
const fromWorldPoint = OrbitCameraInputTouch.fromWorldPoint;
const toWorldPoint = OrbitCameraInputTouch.toWorldPoint;
const worldDiff = OrbitCameraInputTouch.worldDiff;


// For panning to work at any zoom level, we use screen point to world projection
// to work out how far we need to pan the pivotEntity in world space
var camera = this.entity.camera;
var distance = this.orbitCamera.distance;
marklundin marked this conversation as resolved.
Show resolved Hide resolved

camera.screenToWorld(midPoint.x, midPoint.y, distance, fromWorldPoint);
camera.screenToWorld(this.lastPinchMidPoint.x, this.lastPinchMidPoint.y, distance, toWorldPoint);

worldDiff.sub2(toWorldPoint, fromWorldPoint);

this.orbitCamera.pivotPoint.add(worldDiff);
}


static pinchMidPoint = new pc.Vec2();

onTouchMove(event) {
var pinchMidPoint = OrbitCameraInputTouch.pinchMidPoint;

// We only care about the first touch for camera rotation. Work out the difference moved since the last event
// and use that to update the camera target position
var touches = event.touches;
if (touches.length === 1) {
var touch = touches[0];
Comment on lines +114 to +116
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var touches = event.touches;
if (touches.length === 1) {
var touch = touches[0];
const touches = event.touches;
if (touches.length === 1) {
const touch = touches[0];


this.orbitCamera.pitch -= (touch.y - this.lastTouchPoint.y) * this.orbitSensitivity;
this.orbitCamera.yaw -= (touch.x - this.lastTouchPoint.x) * this.orbitSensitivity;

this.lastTouchPoint.set(touch.x, touch.y);

} else if (touches.length === 2) {
// Calculate the difference in pinch distance since the last event
var currentPinchDistance = this.getPinchDistance(touches[0], touches[1]);
var diffInPinchDistance = currentPinchDistance - this.lastPinchDistance;
this.lastPinchDistance = currentPinchDistance;

this.orbitCamera.distance -= (diffInPinchDistance * this.distanceSensitivity * 0.1) * (this.orbitCamera.distance * 0.1);

// Calculate pan difference
this.calcMidPoint(touches[0], touches[1], pinchMidPoint);
this.pan(pinchMidPoint);
this.lastPinchMidPoint.copy(pinchMidPoint);
}
}
}
Loading