@houstonp/rubiks-cube 1.5.0 → 1.5.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/index.js +21 -7
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -19,7 +19,7 @@ const defaultSettings = {
|
|
|
19
19
|
};
|
|
20
20
|
const minGap = 1;
|
|
21
21
|
const minRadius = 4;
|
|
22
|
-
const minFieldOfView =
|
|
22
|
+
const minFieldOfView = 30;
|
|
23
23
|
const maxFieldOfView = 100;
|
|
24
24
|
const maxAzimuthAngle = (5 * Math.PI) / 16;
|
|
25
25
|
const polarAngleOffset = Math.PI / 2;
|
|
@@ -76,27 +76,36 @@ class RubiksCube extends HTMLElement {
|
|
|
76
76
|
if (name === 'camera-radius') {
|
|
77
77
|
var radius = Number(newVal);
|
|
78
78
|
this.settings.cameraRadius = radius < minRadius ? minRadius : radius;
|
|
79
|
-
|
|
79
|
+
if (oldVal !== newVal && oldVal !== null) {
|
|
80
|
+
this.dispatchEvent(new CustomEvent('cameraSettingsChanged'));
|
|
81
|
+
}
|
|
80
82
|
}
|
|
81
83
|
if (name === 'camera-peek-angle-horizontal') {
|
|
82
84
|
var angle = Number(newVal);
|
|
83
85
|
angle = angle > 0 ? angle : 0;
|
|
84
86
|
angle = angle < 1 ? angle : 1;
|
|
85
87
|
this.settings.cameraPeekAngleHorizontal = angle > 0 ? angle : 0;
|
|
86
|
-
|
|
88
|
+
if (oldVal !== newVal && oldVal !== null) {
|
|
89
|
+
this.dispatchEvent(new CustomEvent('cameraSettingsChanged'));
|
|
90
|
+
}
|
|
87
91
|
}
|
|
88
92
|
if (name === 'camera-peek-angle-vertical') {
|
|
89
93
|
var angle = Number(newVal);
|
|
90
94
|
angle = angle > 0 ? angle : 0;
|
|
91
95
|
angle = angle < 1 ? angle : 1;
|
|
92
96
|
this.settings.cameraPeekAngleVertical = angle;
|
|
93
|
-
|
|
97
|
+
if (oldVal !== newVal && oldVal !== null) {
|
|
98
|
+
this.dispatchEvent(new CustomEvent('cameraSettingsChanged'));
|
|
99
|
+
}
|
|
94
100
|
}
|
|
95
101
|
if (name == 'camera-field-of-view') {
|
|
96
102
|
var fov = Number(newVal);
|
|
97
103
|
fov = fov > minFieldOfView ? fov : minFieldOfView;
|
|
98
104
|
fov = fov < maxFieldOfView ? fov : maxFieldOfView;
|
|
99
105
|
this.settings.cameraFieldOfView = fov;
|
|
106
|
+
if (oldVal !== newVal && oldVal !== null) {
|
|
107
|
+
this.dispatchEvent(new CustomEvent('cameraFieldOfViewChanged'));
|
|
108
|
+
}
|
|
100
109
|
}
|
|
101
110
|
}
|
|
102
111
|
|
|
@@ -128,8 +137,8 @@ class RubiksCube extends HTMLElement {
|
|
|
128
137
|
).observe(this);
|
|
129
138
|
|
|
130
139
|
// add camera
|
|
131
|
-
const camera = new PerspectiveCamera(this.settings.cameraFieldOfView, this.clientWidth / this.clientHeight,
|
|
132
|
-
const cameraSpherical = new Spherical(
|
|
140
|
+
const camera = new PerspectiveCamera(this.settings.cameraFieldOfView, this.clientWidth / this.clientHeight, 1, 2000);
|
|
141
|
+
const cameraSpherical = new Spherical(50, (3 * Math.PI) / 8, -Math.PI / 4);
|
|
133
142
|
camera.position.setFromSpherical(cameraSpherical);
|
|
134
143
|
/** @type {{ Up: boolean, Right: boolean }} */
|
|
135
144
|
const cameraState = { Up: true, Right: true };
|
|
@@ -254,7 +263,12 @@ class RubiksCube extends HTMLElement {
|
|
|
254
263
|
updateCameraPosition(); // animate settings changes
|
|
255
264
|
});
|
|
256
265
|
|
|
257
|
-
|
|
266
|
+
this.addEventListener('cameraFieldOfViewChanged', () => {
|
|
267
|
+
camera.fov = this.settings.cameraFieldOfView;
|
|
268
|
+
camera.updateProjectionMatrix();
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
updateCameraPosition(1000, 'none'); // initial animation
|
|
258
272
|
}
|
|
259
273
|
}
|
|
260
274
|
customElements.define('rubiks-cube', RubiksCube);
|