@preference-sl/pref-viewer 2.7.0 → 2.8.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 +1 -1
- package/src/index.js +48 -16
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -56,6 +56,8 @@ class PrefViewer extends HTMLElement {
|
|
|
56
56
|
this.camera = null;
|
|
57
57
|
this.hemiLight = null;
|
|
58
58
|
this.dirLight = null;
|
|
59
|
+
this.cameraLight = null;
|
|
60
|
+
this.shadowGen = null;
|
|
59
61
|
this._onWindowResize = null;
|
|
60
62
|
|
|
61
63
|
// Model sources
|
|
@@ -111,7 +113,8 @@ class PrefViewer extends HTMLElement {
|
|
|
111
113
|
}
|
|
112
114
|
|
|
113
115
|
_setupUrlPreprocessing() {
|
|
114
|
-
const transformUrl = (url) =>
|
|
116
|
+
const transformUrl = (url) =>
|
|
117
|
+
url.replace(/^blob:[^/]+\//i, "").replace(/\\/g, "/");
|
|
115
118
|
SceneLoader.OnPluginActivatedObservable.add((plugin) => {
|
|
116
119
|
if (plugin.name === "gltf" || plugin.name === "gltf2") {
|
|
117
120
|
plugin.preprocessUrl = transformUrl;
|
|
@@ -158,23 +161,35 @@ class PrefViewer extends HTMLElement {
|
|
|
158
161
|
}
|
|
159
162
|
|
|
160
163
|
_createLights() {
|
|
161
|
-
//
|
|
162
|
-
this.hemiLight = new HemisphericLight(
|
|
163
|
-
|
|
164
|
+
// 1) Stronger ambient fill
|
|
165
|
+
this.hemiLight = new HemisphericLight(
|
|
166
|
+
"hemiLight",
|
|
167
|
+
new Vector3(0, 1, 0),
|
|
168
|
+
this.scene
|
|
169
|
+
);
|
|
170
|
+
this.hemiLight.intensity = 0.8;
|
|
164
171
|
|
|
165
|
-
//
|
|
166
|
-
this.dirLight = new DirectionalLight(
|
|
172
|
+
// 2) Soft directional “sun” for form
|
|
173
|
+
this.dirLight = new DirectionalLight(
|
|
174
|
+
"dirLight",
|
|
175
|
+
new Vector3(-0.5, -1, -0.5),
|
|
176
|
+
this.scene
|
|
177
|
+
);
|
|
167
178
|
this.dirLight.position = new Vector3(0, 5, 0);
|
|
168
|
-
this.dirLight.intensity = 0.3;
|
|
179
|
+
this.dirLight.intensity = 0.3;
|
|
169
180
|
|
|
170
|
-
//
|
|
171
|
-
|
|
172
|
-
shadowGen.useBlurExponentialShadowMap = true;
|
|
173
|
-
shadowGen.blurKernel = 16;
|
|
174
|
-
shadowGen.darkness = 0.2;
|
|
181
|
+
// 3) Soft blurred shadows
|
|
182
|
+
this.shadowGen = new ShadowGenerator(1024, this.dirLight);
|
|
183
|
+
this.shadowGen.useBlurExponentialShadowMap = true;
|
|
184
|
+
this.shadowGen.blurKernel = 16;
|
|
185
|
+
this.shadowGen.darkness = 0.2;
|
|
175
186
|
|
|
176
|
-
//
|
|
177
|
-
this.cameraLight = new PointLight(
|
|
187
|
+
// 4) Camera‐attached headlight
|
|
188
|
+
this.cameraLight = new PointLight(
|
|
189
|
+
"cameraLight",
|
|
190
|
+
this.camera.position,
|
|
191
|
+
this.scene
|
|
192
|
+
);
|
|
178
193
|
this.cameraLight.parent = this.camera;
|
|
179
194
|
this.cameraLight.intensity = 0.5;
|
|
180
195
|
}
|
|
@@ -205,7 +220,22 @@ class PrefViewer extends HTMLElement {
|
|
|
205
220
|
result = await SceneLoader.ImportMeshAsync(null, "", this.modelUrl, this.scene, undefined, extension);
|
|
206
221
|
}
|
|
207
222
|
|
|
208
|
-
|
|
223
|
+
// Remove any extra lights that the loader might have added
|
|
224
|
+
this.scene.lights
|
|
225
|
+
.filter(
|
|
226
|
+
(light) =>
|
|
227
|
+
!["hemiLight", "dirLight", "cameraLight"].includes(
|
|
228
|
+
light.name
|
|
229
|
+
)
|
|
230
|
+
)
|
|
231
|
+
.forEach((light) => light.dispose());
|
|
232
|
+
|
|
233
|
+
// Hook up our soft shadows to every mesh
|
|
234
|
+
result.meshes.forEach((mesh) => {
|
|
235
|
+
mesh.receiveShadows = true;
|
|
236
|
+
this.shadowGen.addShadowCaster(mesh, true);
|
|
237
|
+
});
|
|
238
|
+
|
|
209
239
|
this.dispatchEvent(
|
|
210
240
|
new CustomEvent("model-loaded", { detail: result, bubbles: true, composed: true })
|
|
211
241
|
);
|
|
@@ -238,7 +268,9 @@ class PrefViewer extends HTMLElement {
|
|
|
238
268
|
_disposeEngine() {
|
|
239
269
|
if (!this.engine) return;
|
|
240
270
|
this.engine.dispose();
|
|
241
|
-
this.engine = this.scene = this.camera =
|
|
271
|
+
this.engine = this.scene = this.camera = null;
|
|
272
|
+
this.hemiLight = this.dirLight = this.cameraLight = null;
|
|
273
|
+
this.shadowGen = null;
|
|
242
274
|
}
|
|
243
275
|
}
|
|
244
276
|
|