@playcanvas/supersplat-viewer 1.3.1 → 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/README.md +2 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/public/index.js +71 -51
- package/public/index.js.map +1 -1
package/package.json
CHANGED
package/public/index.js
CHANGED
|
@@ -94931,6 +94931,10 @@ const migrateAnimTrack = (track) => {
|
|
|
94931
94931
|
times[i] *= defaultFrameRate;
|
|
94932
94932
|
}
|
|
94933
94933
|
}
|
|
94934
|
+
// smoothness property added in v1.4.0
|
|
94935
|
+
if (!track.hasOwnProperty('smoothness')) {
|
|
94936
|
+
track.smoothness = 0;
|
|
94937
|
+
}
|
|
94934
94938
|
};
|
|
94935
94939
|
const migrateSettings = (settings) => {
|
|
94936
94940
|
settings.animTracks?.forEach((track) => {
|
|
@@ -95014,7 +95018,7 @@ class CubicSpline {
|
|
|
95014
95018
|
while (time >= times[seg + 1]) {
|
|
95015
95019
|
seg++;
|
|
95016
95020
|
}
|
|
95017
|
-
|
|
95021
|
+
this.evaluateSegment(seg, (time - times[seg]) / (times[seg + 1] - times[seg]), result);
|
|
95018
95022
|
}
|
|
95019
95023
|
}
|
|
95020
95024
|
getKnot(index, result) {
|
|
@@ -95045,14 +95049,15 @@ class CubicSpline {
|
|
|
95045
95049
|
m1 * (t2 * (t - 1));
|
|
95046
95050
|
}
|
|
95047
95051
|
}
|
|
95048
|
-
//
|
|
95052
|
+
// calculate cubic spline knots from points
|
|
95049
95053
|
// times: time values for each control point
|
|
95050
95054
|
// points: control point values to be interpolated (n dimensional)
|
|
95051
|
-
//
|
|
95052
|
-
static
|
|
95053
|
-
const
|
|
95054
|
-
const
|
|
95055
|
-
|
|
95055
|
+
// smoothness: 0 = linear, 1 = smooth
|
|
95056
|
+
static calcKnots(times, points, smoothness) {
|
|
95057
|
+
const n = times.length;
|
|
95058
|
+
const dim = points.length / n;
|
|
95059
|
+
const knots = new Array(n * dim * 3);
|
|
95060
|
+
for (let i = 0; i < n; i++) {
|
|
95056
95061
|
const t = times[i];
|
|
95057
95062
|
for (let j = 0; j < dim; j++) {
|
|
95058
95063
|
const idx = i * dim + j;
|
|
@@ -95061,28 +95066,29 @@ class CubicSpline {
|
|
|
95061
95066
|
if (i === 0) {
|
|
95062
95067
|
tangent = (points[idx + dim] - p) / (times[i + 1] - t);
|
|
95063
95068
|
}
|
|
95064
|
-
else if (i ===
|
|
95069
|
+
else if (i === n - 1) {
|
|
95065
95070
|
tangent = (p - points[idx - dim]) / (t - times[i - 1]);
|
|
95066
95071
|
}
|
|
95067
95072
|
else {
|
|
95068
|
-
|
|
95069
|
-
tangent = 0.5 * ((points[idx + dim] - p) / (times[i + 1] - t) + (p - points[idx - dim]) / (t - times[i - 1]));
|
|
95070
|
-
// cardinal spline tangents
|
|
95071
|
-
// tangent = (points[idx + dim] - points[idx - dim]) / (times[i + 1] - times[i - 1]);
|
|
95073
|
+
tangent = (points[idx + dim] - points[idx - dim]) / (times[i + 1] - times[i - 1]);
|
|
95072
95074
|
}
|
|
95073
|
-
//
|
|
95074
|
-
|
|
95075
|
-
|
|
95075
|
+
// convert to derivatives w.r.t normalized segment parameter
|
|
95076
|
+
const inScale = i > 0 ? (times[i] - times[i - 1]) : (times[1] - times[0]);
|
|
95077
|
+
const outScale = i < n - 1 ? (times[i + 1] - times[i]) : (times[i] - times[i - 1]);
|
|
95078
|
+
knots[idx * 3] = tangent * inScale * smoothness;
|
|
95076
95079
|
knots[idx * 3 + 1] = p;
|
|
95077
|
-
knots[idx * 3 + 2] = tangent;
|
|
95080
|
+
knots[idx * 3 + 2] = tangent * outScale * smoothness;
|
|
95078
95081
|
}
|
|
95079
95082
|
}
|
|
95080
|
-
return
|
|
95083
|
+
return knots;
|
|
95084
|
+
}
|
|
95085
|
+
static fromPoints(times, points, smoothness = 1) {
|
|
95086
|
+
return new CubicSpline(times, CubicSpline.calcKnots(times, points, smoothness));
|
|
95081
95087
|
}
|
|
95082
95088
|
// create a looping spline by duplicating animation points at the end and beginning
|
|
95083
|
-
static fromPointsLooping(length, times, points,
|
|
95089
|
+
static fromPointsLooping(length, times, points, smoothness = 1) {
|
|
95084
95090
|
if (times.length < 2) {
|
|
95085
|
-
return CubicSpline.fromPoints(times, points
|
|
95091
|
+
return CubicSpline.fromPoints(times, points);
|
|
95086
95092
|
}
|
|
95087
95093
|
const dim = points.length / times.length;
|
|
95088
95094
|
const newTimes = times.slice();
|
|
@@ -95093,7 +95099,7 @@ class CubicSpline {
|
|
|
95093
95099
|
// prepend last two points
|
|
95094
95100
|
newTimes.splice(0, 0, times[times.length - 2] - length, times[times.length - 1] - length);
|
|
95095
95101
|
newPoints.splice(0, 0, ...points.slice(points.length - dim * 2));
|
|
95096
|
-
return CubicSpline.fromPoints(newTimes, newPoints,
|
|
95102
|
+
return CubicSpline.fromPoints(newTimes, newPoints, smoothness);
|
|
95097
95103
|
}
|
|
95098
95104
|
}
|
|
95099
95105
|
|
|
@@ -95174,7 +95180,7 @@ class AnimController extends InputController {
|
|
|
95174
95180
|
}
|
|
95175
95181
|
// construct an animation from a settings track
|
|
95176
95182
|
static fromTrack(track) {
|
|
95177
|
-
const { keyframes, duration, frameRate, loopMode } = track;
|
|
95183
|
+
const { keyframes, duration, frameRate, loopMode, smoothness } = track;
|
|
95178
95184
|
const { times, values } = keyframes;
|
|
95179
95185
|
const { position, target } = values;
|
|
95180
95186
|
// construct the points array containing position and target
|
|
@@ -95184,7 +95190,7 @@ class AnimController extends InputController {
|
|
|
95184
95190
|
points.push(target[i * 3], target[i * 3 + 1], target[i * 3 + 2]);
|
|
95185
95191
|
}
|
|
95186
95192
|
const extra = (duration === times[times.length - 1] / frameRate) ? 1 : 0;
|
|
95187
|
-
const spline = CubicSpline.fromPointsLooping((duration + extra) * frameRate, times, points,
|
|
95193
|
+
const spline = CubicSpline.fromPointsLooping((duration + extra) * frameRate, times, points, smoothness);
|
|
95188
95194
|
return new AnimController(spline, duration, loopMode, frameRate);
|
|
95189
95195
|
}
|
|
95190
95196
|
}
|
|
@@ -95272,7 +95278,6 @@ class AppController {
|
|
|
95272
95278
|
* @param dt - delta time in seconds
|
|
95273
95279
|
* @param state - the current state of the app
|
|
95274
95280
|
* @param state.cameraMode - the current camera mode
|
|
95275
|
-
* @param state.snap - whether the camera is snapped to the target
|
|
95276
95281
|
* @param distance - the distance to the camera target
|
|
95277
95282
|
*/
|
|
95278
95283
|
update(dt, state, distance) {
|
|
@@ -95290,7 +95295,6 @@ class AppController {
|
|
|
95290
95295
|
this._state.shift += key[keyCode.SHIFT];
|
|
95291
95296
|
this._state.ctrl += key[keyCode.CTRL];
|
|
95292
95297
|
if (state.cameraMode !== 'fly' && this._state.axis.length() > 0) {
|
|
95293
|
-
state.snap = true;
|
|
95294
95298
|
state.cameraMode = 'fly';
|
|
95295
95299
|
}
|
|
95296
95300
|
const orbit = +(state.cameraMode === 'orbit');
|
|
@@ -95398,7 +95402,29 @@ class Picker {
|
|
|
95398
95402
|
}
|
|
95399
95403
|
}
|
|
95400
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
|
+
};
|
|
95401
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
|
+
};
|
|
95402
95428
|
/**
|
|
95403
95429
|
* Creates a rotation animation track
|
|
95404
95430
|
*
|
|
@@ -95433,6 +95459,7 @@ const createRotateTrack = (initial, keys = 12, duration = 20) => {
|
|
|
95433
95459
|
target: 'camera',
|
|
95434
95460
|
loopMode: 'repeat',
|
|
95435
95461
|
interpolation: 'spline',
|
|
95462
|
+
smoothness: 1,
|
|
95436
95463
|
keyframes: {
|
|
95437
95464
|
times,
|
|
95438
95465
|
values: {
|
|
@@ -95573,13 +95600,13 @@ class Viewer {
|
|
|
95573
95600
|
if (animCamera) {
|
|
95574
95601
|
state.cameraMode = 'anim';
|
|
95575
95602
|
}
|
|
95576
|
-
// this pose stores the current camera position. it will be blended/smoothed
|
|
95577
|
-
// toward the current active camera
|
|
95578
|
-
const activePose = new Pose();
|
|
95579
95603
|
// create controller
|
|
95580
95604
|
// set move speed based on scene size, within reason
|
|
95581
95605
|
const controller = new AppController(app.graphicsDevice.canvas, entity.camera);
|
|
95582
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();
|
|
95583
95610
|
if (state.cameraMode === 'anim') {
|
|
95584
95611
|
// first frame of the animation
|
|
95585
95612
|
activePose.copy(animCamera.update(controller.frame, 0));
|
|
@@ -95591,11 +95618,7 @@ class Viewer {
|
|
|
95591
95618
|
// place all user cameras at the start position
|
|
95592
95619
|
orbitCamera.attach(activePose, false);
|
|
95593
95620
|
flyCamera.attach(activePose, false);
|
|
95594
|
-
// transition time between cameras
|
|
95595
|
-
let transitionTimer = 0;
|
|
95596
95621
|
// the previous camera we're transitioning away from
|
|
95597
|
-
const prevPose = new Pose();
|
|
95598
|
-
let prevCamera = null;
|
|
95599
95622
|
let prevCameraMode = 'orbit';
|
|
95600
95623
|
// handle input events
|
|
95601
95624
|
events.on('inputEvent', (eventName, event) => {
|
|
@@ -95607,7 +95630,6 @@ class Viewer {
|
|
|
95607
95630
|
}
|
|
95608
95631
|
case 'fly': {
|
|
95609
95632
|
if (state.cameraMode !== 'orbit') {
|
|
95610
|
-
state.snap = true;
|
|
95611
95633
|
state.cameraMode = 'orbit';
|
|
95612
95634
|
}
|
|
95613
95635
|
orbitCamera.attach(pose, true);
|
|
@@ -95634,6 +95656,10 @@ class Viewer {
|
|
|
95634
95656
|
break;
|
|
95635
95657
|
}
|
|
95636
95658
|
});
|
|
95659
|
+
let currCamera = getCamera(state.cameraMode);
|
|
95660
|
+
const prevPose = new Pose();
|
|
95661
|
+
// transition time between cameras
|
|
95662
|
+
let transitionTimer = 1;
|
|
95637
95663
|
// application update
|
|
95638
95664
|
app.on('update', (deltaTime) => {
|
|
95639
95665
|
// in xr mode we leave the camera alone
|
|
@@ -95647,20 +95673,19 @@ class Viewer {
|
|
|
95647
95673
|
events.fire('touchJoystickUpdate', controller.joystick.base, controller.joystick.stick);
|
|
95648
95674
|
}
|
|
95649
95675
|
// use dt of 0 if animation is paused
|
|
95650
|
-
const dt = state.cameraMode === 'anim' ?
|
|
95651
|
-
|
|
95652
|
-
|
|
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);
|
|
95653
95679
|
// update camera
|
|
95654
|
-
pose.copy(
|
|
95655
|
-
// blend camera smoothly during transitions
|
|
95680
|
+
pose.copy(currCamera.update(controller.frame, dt));
|
|
95656
95681
|
if (transitionTimer < 1) {
|
|
95657
|
-
|
|
95658
|
-
|
|
95659
|
-
|
|
95660
|
-
|
|
95682
|
+
// handle lerp away from previous camera
|
|
95683
|
+
lerpPose(activePose, prevPose, pose, easeOut(transitionTimer));
|
|
95684
|
+
}
|
|
95685
|
+
else {
|
|
95686
|
+
activePose.copy(pose);
|
|
95661
95687
|
}
|
|
95662
95688
|
// apply to camera
|
|
95663
|
-
activePose.copy(pose);
|
|
95664
95689
|
entity.setPosition(activePose.position);
|
|
95665
95690
|
entity.setEulerAngles(activePose.angles);
|
|
95666
95691
|
// update animation timeline
|
|
@@ -95672,19 +95697,16 @@ class Viewer {
|
|
|
95672
95697
|
events.on('cameraMode:changed', (value, prev) => {
|
|
95673
95698
|
prevCameraMode = prev;
|
|
95674
95699
|
prevPose.copy(activePose);
|
|
95675
|
-
|
|
95676
|
-
|
|
95700
|
+
getCamera(prev).detach();
|
|
95701
|
+
currCamera = getCamera(value);
|
|
95677
95702
|
switch (value) {
|
|
95678
95703
|
case 'orbit':
|
|
95679
95704
|
case 'fly':
|
|
95680
|
-
|
|
95705
|
+
currCamera.attach(activePose, false);
|
|
95681
95706
|
break;
|
|
95682
95707
|
}
|
|
95683
95708
|
// reset camera transition timer
|
|
95684
|
-
|
|
95685
|
-
transitionTimer = 0;
|
|
95686
|
-
}
|
|
95687
|
-
state.snap = false;
|
|
95709
|
+
transitionTimer = 0;
|
|
95688
95710
|
});
|
|
95689
95711
|
events.on('setAnimationTime', (time) => {
|
|
95690
95712
|
if (animCamera) {
|
|
@@ -95706,7 +95728,6 @@ class Viewer {
|
|
|
95706
95728
|
const result = await picker.pick(event.offsetX, event.offsetY);
|
|
95707
95729
|
if (result) {
|
|
95708
95730
|
if (state.cameraMode !== 'orbit') {
|
|
95709
|
-
state.snap = true;
|
|
95710
95731
|
state.cameraMode = 'orbit';
|
|
95711
95732
|
}
|
|
95712
95733
|
// snap distance of focus to picked point to interpolate rotation only
|
|
@@ -95903,7 +95924,6 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|
|
95903
95924
|
progress: 0,
|
|
95904
95925
|
inputMode: 'desktop', // desktop, touch
|
|
95905
95926
|
cameraMode: 'orbit', // orbit, anim, fly
|
|
95906
|
-
snap: false, // snap to camera target
|
|
95907
95927
|
hasAnimation: false,
|
|
95908
95928
|
animationDuration: 0,
|
|
95909
95929
|
animationTime: 0,
|