@playcanvas/supersplat-viewer 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/public/index.js +42 -29
- package/public/index.js.map +1 -1
package/package.json
CHANGED
package/public/index.js
CHANGED
|
@@ -95278,7 +95278,6 @@ class AppController {
|
|
|
95278
95278
|
* @param dt - delta time in seconds
|
|
95279
95279
|
* @param state - the current state of the app
|
|
95280
95280
|
* @param state.cameraMode - the current camera mode
|
|
95281
|
-
* @param state.snap - whether the camera is snapped to the target
|
|
95282
95281
|
* @param distance - the distance to the camera target
|
|
95283
95282
|
*/
|
|
95284
95283
|
update(dt, state, distance) {
|
|
@@ -95296,7 +95295,6 @@ class AppController {
|
|
|
95296
95295
|
this._state.shift += key[keyCode.SHIFT];
|
|
95297
95296
|
this._state.ctrl += key[keyCode.CTRL];
|
|
95298
95297
|
if (state.cameraMode !== 'fly' && this._state.axis.length() > 0) {
|
|
95299
|
-
state.snap = true;
|
|
95300
95298
|
state.cameraMode = 'fly';
|
|
95301
95299
|
}
|
|
95302
95300
|
const orbit = +(state.cameraMode === 'orbit');
|
|
@@ -95404,7 +95402,29 @@ class Picker {
|
|
|
95404
95402
|
}
|
|
95405
95403
|
}
|
|
95406
95404
|
|
|
95405
|
+
const vecToAngles = (result, vec) => {
|
|
95406
|
+
const radToDeg = 180 / Math.PI;
|
|
95407
|
+
result.x = Math.asin(vec.y) * radToDeg;
|
|
95408
|
+
result.y = Math.atan2(-vec.x, -vec.z) * radToDeg;
|
|
95409
|
+
result.z = 0;
|
|
95410
|
+
return result;
|
|
95411
|
+
};
|
|
95407
95412
|
const pose = new Pose();
|
|
95413
|
+
const avec = new Vec3();
|
|
95414
|
+
const bvec = new Vec3();
|
|
95415
|
+
// lerp between two poses
|
|
95416
|
+
const lerpPose = (result, a, b, t) => {
|
|
95417
|
+
// lerp camera position
|
|
95418
|
+
result.position.lerp(a.position, b.position, t);
|
|
95419
|
+
// lerp focus point and subtract from camera position
|
|
95420
|
+
a.getFocus(avec);
|
|
95421
|
+
b.getFocus(bvec);
|
|
95422
|
+
avec.lerp(avec, bvec, t).sub(result.position);
|
|
95423
|
+
// calculate distance
|
|
95424
|
+
result.distance = avec.length();
|
|
95425
|
+
// set angles
|
|
95426
|
+
vecToAngles(result.angles, avec.mulScalar(1.0 / result.distance));
|
|
95427
|
+
};
|
|
95408
95428
|
/**
|
|
95409
95429
|
* Creates a rotation animation track
|
|
95410
95430
|
*
|
|
@@ -95580,13 +95600,13 @@ class Viewer {
|
|
|
95580
95600
|
if (animCamera) {
|
|
95581
95601
|
state.cameraMode = 'anim';
|
|
95582
95602
|
}
|
|
95583
|
-
// this pose stores the current camera position. it will be blended/smoothed
|
|
95584
|
-
// toward the current active camera
|
|
95585
|
-
const activePose = new Pose();
|
|
95586
95603
|
// create controller
|
|
95587
95604
|
// set move speed based on scene size, within reason
|
|
95588
95605
|
const controller = new AppController(app.graphicsDevice.canvas, entity.camera);
|
|
95589
95606
|
controller.moveSpeed = bbox.halfExtents.length() * 0.1;
|
|
95607
|
+
// this pose stores the current camera position. it will be blended/smoothed
|
|
95608
|
+
// toward the current active camera
|
|
95609
|
+
const activePose = new Pose();
|
|
95590
95610
|
if (state.cameraMode === 'anim') {
|
|
95591
95611
|
// first frame of the animation
|
|
95592
95612
|
activePose.copy(animCamera.update(controller.frame, 0));
|
|
@@ -95598,11 +95618,7 @@ class Viewer {
|
|
|
95598
95618
|
// place all user cameras at the start position
|
|
95599
95619
|
orbitCamera.attach(activePose, false);
|
|
95600
95620
|
flyCamera.attach(activePose, false);
|
|
95601
|
-
// transition time between cameras
|
|
95602
|
-
let transitionTimer = 0;
|
|
95603
95621
|
// the previous camera we're transitioning away from
|
|
95604
|
-
const prevPose = new Pose();
|
|
95605
|
-
let prevCamera = null;
|
|
95606
95622
|
let prevCameraMode = 'orbit';
|
|
95607
95623
|
// handle input events
|
|
95608
95624
|
events.on('inputEvent', (eventName, event) => {
|
|
@@ -95614,7 +95630,6 @@ class Viewer {
|
|
|
95614
95630
|
}
|
|
95615
95631
|
case 'fly': {
|
|
95616
95632
|
if (state.cameraMode !== 'orbit') {
|
|
95617
|
-
state.snap = true;
|
|
95618
95633
|
state.cameraMode = 'orbit';
|
|
95619
95634
|
}
|
|
95620
95635
|
orbitCamera.attach(pose, true);
|
|
@@ -95641,6 +95656,10 @@ class Viewer {
|
|
|
95641
95656
|
break;
|
|
95642
95657
|
}
|
|
95643
95658
|
});
|
|
95659
|
+
let currCamera = getCamera(state.cameraMode);
|
|
95660
|
+
const prevPose = new Pose();
|
|
95661
|
+
// transition time between cameras
|
|
95662
|
+
let transitionTimer = 1;
|
|
95644
95663
|
// application update
|
|
95645
95664
|
app.on('update', (deltaTime) => {
|
|
95646
95665
|
// in xr mode we leave the camera alone
|
|
@@ -95654,20 +95673,19 @@ class Viewer {
|
|
|
95654
95673
|
events.fire('touchJoystickUpdate', controller.joystick.base, controller.joystick.stick);
|
|
95655
95674
|
}
|
|
95656
95675
|
// use dt of 0 if animation is paused
|
|
95657
|
-
const dt = state.cameraMode === 'anim' ?
|
|
95658
|
-
|
|
95659
|
-
|
|
95676
|
+
const dt = state.cameraMode === 'anim' && state.animationPaused ? 0 : deltaTime;
|
|
95677
|
+
// update the camera we're transitioning from
|
|
95678
|
+
transitionTimer = Math.min(1, transitionTimer + deltaTime * 2.0);
|
|
95660
95679
|
// update camera
|
|
95661
|
-
pose.copy(
|
|
95662
|
-
// blend camera smoothly during transitions
|
|
95680
|
+
pose.copy(currCamera.update(controller.frame, dt));
|
|
95663
95681
|
if (transitionTimer < 1) {
|
|
95664
|
-
|
|
95665
|
-
|
|
95666
|
-
|
|
95667
|
-
|
|
95682
|
+
// handle lerp away from previous camera
|
|
95683
|
+
lerpPose(activePose, prevPose, pose, easeOut(transitionTimer));
|
|
95684
|
+
}
|
|
95685
|
+
else {
|
|
95686
|
+
activePose.copy(pose);
|
|
95668
95687
|
}
|
|
95669
95688
|
// apply to camera
|
|
95670
|
-
activePose.copy(pose);
|
|
95671
95689
|
entity.setPosition(activePose.position);
|
|
95672
95690
|
entity.setEulerAngles(activePose.angles);
|
|
95673
95691
|
// update animation timeline
|
|
@@ -95679,19 +95697,16 @@ class Viewer {
|
|
|
95679
95697
|
events.on('cameraMode:changed', (value, prev) => {
|
|
95680
95698
|
prevCameraMode = prev;
|
|
95681
95699
|
prevPose.copy(activePose);
|
|
95682
|
-
|
|
95683
|
-
|
|
95700
|
+
getCamera(prev).detach();
|
|
95701
|
+
currCamera = getCamera(value);
|
|
95684
95702
|
switch (value) {
|
|
95685
95703
|
case 'orbit':
|
|
95686
95704
|
case 'fly':
|
|
95687
|
-
|
|
95705
|
+
currCamera.attach(activePose, false);
|
|
95688
95706
|
break;
|
|
95689
95707
|
}
|
|
95690
95708
|
// reset camera transition timer
|
|
95691
|
-
|
|
95692
|
-
transitionTimer = 0;
|
|
95693
|
-
}
|
|
95694
|
-
state.snap = false;
|
|
95709
|
+
transitionTimer = 0;
|
|
95695
95710
|
});
|
|
95696
95711
|
events.on('setAnimationTime', (time) => {
|
|
95697
95712
|
if (animCamera) {
|
|
@@ -95713,7 +95728,6 @@ class Viewer {
|
|
|
95713
95728
|
const result = await picker.pick(event.offsetX, event.offsetY);
|
|
95714
95729
|
if (result) {
|
|
95715
95730
|
if (state.cameraMode !== 'orbit') {
|
|
95716
|
-
state.snap = true;
|
|
95717
95731
|
state.cameraMode = 'orbit';
|
|
95718
95732
|
}
|
|
95719
95733
|
// snap distance of focus to picked point to interpolate rotation only
|
|
@@ -95910,7 +95924,6 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|
|
95910
95924
|
progress: 0,
|
|
95911
95925
|
inputMode: 'desktop', // desktop, touch
|
|
95912
95926
|
cameraMode: 'orbit', // orbit, anim, fly
|
|
95913
|
-
snap: false, // snap to camera target
|
|
95914
95927
|
hasAnimation: false,
|
|
95915
95928
|
animationDuration: 0,
|
|
95916
95929
|
animationTime: 0,
|