@preference-sl/pref-viewer 2.8.1 → 2.9.0-beta.0
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/package.json +3 -2
- package/src/index.js +27 -5
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preference-sl/pref-viewer",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0-beta.0",
|
|
4
4
|
"description": "Web Component to preview GLTF models with Babylon.js",
|
|
5
5
|
"author": "Alex Moreno Palacio <amoreno@preference.es>",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"release": "standard-version --releaseCommitMessageFormat \"chore(release): {{currentTag}} [skip ci]\""
|
|
7
|
+
"release": "standard-version --releaseCommitMessageFormat \"chore(release): {{currentTag}} [skip ci]\"",
|
|
8
|
+
"release:beta": "standard-version --prerelease beta --releaseCommitMessageFormat \"chore(release): {{currentTag}} [skip ci]\""
|
|
8
9
|
},
|
|
9
10
|
"repository": {
|
|
10
11
|
"type": "git",
|
package/src/index.js
CHANGED
|
@@ -39,7 +39,8 @@ import {
|
|
|
39
39
|
HemisphericLight,
|
|
40
40
|
DirectionalLight,
|
|
41
41
|
PointLight,
|
|
42
|
-
ShadowGenerator
|
|
42
|
+
ShadowGenerator,
|
|
43
|
+
PointerEventTypes
|
|
43
44
|
} from "@babylonjs/core";
|
|
44
45
|
import "@babylonjs/loaders";
|
|
45
46
|
|
|
@@ -158,6 +159,8 @@ class PrefViewer extends HTMLElement {
|
|
|
158
159
|
this.scene
|
|
159
160
|
);
|
|
160
161
|
this.camera.attachControl(this.canvas, true);
|
|
162
|
+
// remove default wheel behavior
|
|
163
|
+
this.camera.inputs.removeByType("ArcRotateCameraMouseWheelInput");
|
|
161
164
|
}
|
|
162
165
|
|
|
163
166
|
_createLights() {
|
|
@@ -195,11 +198,30 @@ class PrefViewer extends HTMLElement {
|
|
|
195
198
|
}
|
|
196
199
|
|
|
197
200
|
_setupInteraction() {
|
|
198
|
-
|
|
199
|
-
|
|
201
|
+
// custom wheel zoom: zoom toward the point under mouse
|
|
202
|
+
this.scene.onPointerObservable.add((pointerInfo) => {
|
|
203
|
+
if (pointerInfo.type !== PointerEventTypes.POINTERWHEEL) return;
|
|
204
|
+
const evt = pointerInfo.event;
|
|
200
205
|
const pick = this.scene.pick(this.scene.pointerX, this.scene.pointerY);
|
|
201
|
-
|
|
202
|
-
|
|
206
|
+
if (!pick.hit) return;
|
|
207
|
+
const zoomPoint = pick.pickedPoint;
|
|
208
|
+
|
|
209
|
+
// compute new radius
|
|
210
|
+
const delta = evt.deltaY * this.camera.wheelDeltaPercentage;
|
|
211
|
+
let newRadius = this.camera.radius + delta;
|
|
212
|
+
if (this.camera.lowerRadiusLimit) newRadius = Math.max(newRadius, this.camera.lowerRadiusLimit);
|
|
213
|
+
if (this.camera.upperRadiusLimit) newRadius = Math.min(newRadius, this.camera.upperRadiusLimit);
|
|
214
|
+
|
|
215
|
+
// compute direction from target to camera
|
|
216
|
+
const fromTarget = this.camera.position.subtract(this.camera.target);
|
|
217
|
+
const ratio = newRadius / this.camera.radius;
|
|
218
|
+
const newFromTarget = fromTarget.scale(ratio);
|
|
219
|
+
|
|
220
|
+
// update camera
|
|
221
|
+
this.camera.target = zoomPoint;
|
|
222
|
+
this.camera.radius = newRadius;
|
|
223
|
+
this.camera.position = zoomPoint.add(newFromTarget);
|
|
224
|
+
|
|
203
225
|
evt.preventDefault();
|
|
204
226
|
});
|
|
205
227
|
}
|