@preference-sl/pref-viewer 2.9.0-beta.6 → 2.9.0-beta.7
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 +6 -2
- package/src/index.js +20 -30
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preference-sl/pref-viewer",
|
|
3
|
-
"version": "2.9.0-beta.
|
|
3
|
+
"version": "2.9.0-beta.7",
|
|
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
7
|
"release": "standard-version --releaseCommitMessageFormat \"chore(release): {{currentTag}} [skip ci]\"",
|
|
8
|
-
"release:beta": "standard-version --prerelease beta --releaseCommitMessageFormat \"chore(release): {{currentTag}} [skip ci]\""
|
|
8
|
+
"release:beta": "standard-version --prerelease beta --releaseCommitMessageFormat \"chore(release): {{currentTag}} [skip ci]\"",
|
|
9
|
+
"build": "esbuild src/index.js --bundle --outfile=dist/bundle.js --sourcemap",
|
|
10
|
+
"start": "npm run build && http-server dist -c-1 -p 8080"
|
|
9
11
|
},
|
|
10
12
|
"repository": {
|
|
11
13
|
"type": "git",
|
|
@@ -36,6 +38,8 @@
|
|
|
36
38
|
"@babylonjs/loaders": "^8.0.0"
|
|
37
39
|
},
|
|
38
40
|
"devDependencies": {
|
|
41
|
+
"esbuild": "^0.25.5",
|
|
42
|
+
"http-server": "^14.1.1",
|
|
39
43
|
"standard-version": "^9.5.0"
|
|
40
44
|
}
|
|
41
45
|
}
|
package/src/index.js
CHANGED
|
@@ -29,26 +29,26 @@
|
|
|
29
29
|
* </pref-viewer>
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
|
-
import {
|
|
33
|
-
Engine,
|
|
34
|
-
Scene,
|
|
35
|
-
ArcRotateCamera,
|
|
36
|
-
Vector3,
|
|
37
|
-
SceneLoader,
|
|
38
|
-
Color4,
|
|
39
|
-
HemisphericLight,
|
|
40
|
-
DirectionalLight,
|
|
41
|
-
PointLight,
|
|
42
|
-
ShadowGenerator
|
|
43
|
-
} from "@babylonjs/core";
|
|
32
|
+
import { Engine, Scene, ArcRotateCamera, Vector3, SceneLoader, Color4, HemisphericLight, DirectionalLight, PointLight, ShadowGenerator } from "@babylonjs/core";
|
|
44
33
|
import "@babylonjs/loaders";
|
|
45
|
-
|
|
34
|
+
import "@babylonjs/loaders/glTF/2.0/Extensions/KHR_draco_mesh_compression";
|
|
35
|
+
import { DracoCompression } from "@babylonjs/core/Meshes/Compression/dracoCompression";
|
|
46
36
|
class PrefViewer extends HTMLElement {
|
|
47
37
|
constructor() {
|
|
48
38
|
super();
|
|
49
39
|
this.attachShadow({ mode: "open" });
|
|
50
40
|
this._createCanvas();
|
|
51
41
|
this._wrapCanvas();
|
|
42
|
+
// Point to whichever version you packaged or want to use:
|
|
43
|
+
const DRACO_BASE = "https://www.gstatic.com/draco/versioned/decoders/1.5.7";
|
|
44
|
+
DracoCompression.Configuration.decoder = {
|
|
45
|
+
// loader for the “wrapper” that pulls in the real WASM
|
|
46
|
+
wasmUrl: `${DRACO_BASE}/draco_wasm_wrapper_gltf.js`,
|
|
47
|
+
// the raw WebAssembly binary
|
|
48
|
+
wasmBinaryUrl: `${DRACO_BASE}/draco_decoder_gltf.wasm`,
|
|
49
|
+
// JS fallback if WASM isn’t available
|
|
50
|
+
fallbackUrl: `${DRACO_BASE}/draco_decoder_gltf.js`,
|
|
51
|
+
};
|
|
52
52
|
|
|
53
53
|
// Babylon.js core objects
|
|
54
54
|
this.engine = null;
|
|
@@ -164,7 +164,7 @@ class PrefViewer extends HTMLElement {
|
|
|
164
164
|
// 1) Stronger ambient fill
|
|
165
165
|
this.hemiLight = new HemisphericLight(
|
|
166
166
|
"hemiLight",
|
|
167
|
-
new Vector3(
|
|
167
|
+
new Vector3(-10, 10, -10),
|
|
168
168
|
this.scene
|
|
169
169
|
);
|
|
170
170
|
this.hemiLight.intensity = 0.6;
|
|
@@ -172,17 +172,17 @@ class PrefViewer extends HTMLElement {
|
|
|
172
172
|
// 2) Directional light from the front-right, angled slightly down
|
|
173
173
|
this.dirLight = new DirectionalLight(
|
|
174
174
|
"dirLight",
|
|
175
|
-
new Vector3(-
|
|
175
|
+
new Vector3(-10, 10, -10),
|
|
176
176
|
this.scene
|
|
177
177
|
);
|
|
178
178
|
this.dirLight.position = new Vector3(5, 4, 5); // light is IN FRONT + ABOVE + to the RIGHT
|
|
179
179
|
this.dirLight.intensity = 0.6;
|
|
180
180
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
181
|
+
// 3) Soft shadows
|
|
182
|
+
this.shadowGen = new ShadowGenerator(1024, this.dirLight);
|
|
183
|
+
this.shadowGen.useBlurExponentialShadowMap = true;
|
|
184
|
+
this.shadowGen.blurKernel = 16;
|
|
185
|
+
this.shadowGen.darkness = 0.5;
|
|
186
186
|
|
|
187
187
|
// 4) Camera‐attached headlight
|
|
188
188
|
this.cameraLight = new PointLight(
|
|
@@ -222,16 +222,6 @@ class PrefViewer extends HTMLElement {
|
|
|
222
222
|
|
|
223
223
|
this.scene.createDefaultCamera(true, true, true);
|
|
224
224
|
|
|
225
|
-
// Remove any extra lights that the loader might have added
|
|
226
|
-
this.scene.lights
|
|
227
|
-
.filter(
|
|
228
|
-
(light) =>
|
|
229
|
-
!["hemiLight", "dirLight", "cameraLight"].includes(
|
|
230
|
-
light.name
|
|
231
|
-
)
|
|
232
|
-
)
|
|
233
|
-
.forEach((light) => light.dispose());
|
|
234
|
-
|
|
235
225
|
// Hook up our soft shadows to every mesh
|
|
236
226
|
result.meshes.forEach((mesh) => {
|
|
237
227
|
mesh.receiveShadows = true;
|