@preference-sl/pref-viewer 2.1.4 → 2.1.5
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 +19 -44
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -40,16 +40,7 @@
|
|
|
40
40
|
* -----------------------------------------------------------------------------
|
|
41
41
|
*/
|
|
42
42
|
|
|
43
|
-
import {
|
|
44
|
-
Engine,
|
|
45
|
-
Scene,
|
|
46
|
-
ArcRotateCamera,
|
|
47
|
-
Vector3,
|
|
48
|
-
SceneLoader,
|
|
49
|
-
Color4,
|
|
50
|
-
HemisphericLight,
|
|
51
|
-
DirectionalLight
|
|
52
|
-
} from "@babylonjs/core";
|
|
43
|
+
import { Engine, Scene, ArcRotateCamera, Vector3, SceneLoader, Color4, HemisphericLight, DirectionalLight } from "@babylonjs/core";
|
|
53
44
|
import "@babylonjs/loaders";
|
|
54
45
|
|
|
55
46
|
class PrefViewer extends HTMLElement {
|
|
@@ -147,47 +138,16 @@ class PrefViewer extends HTMLElement {
|
|
|
147
138
|
this.scene = new Scene(this.engine);
|
|
148
139
|
this.scene.clearColor = new Color4(1, 1, 1, 1);
|
|
149
140
|
|
|
150
|
-
// 2)
|
|
151
|
-
// get stripped off before we check for an absolute "https://".
|
|
152
|
-
console.log("PrefViewer: Adding preprocessUrl hook");
|
|
153
|
-
SceneLoader.OnPluginActivatedObservable.add((plugin) => {
|
|
154
|
-
console.log(`PrefViewer: Plugin activated - ${plugin.name}`);
|
|
155
|
-
if (plugin.name === "gltf" || plugin.name === "gltf2") {
|
|
156
|
-
plugin.preprocessUrl = (url) => {
|
|
157
|
-
// a) If the loader already prepended "blob:…", strip it out.
|
|
158
|
-
// Regex explanation: ^blob:(?:file|https?|ftp):\/\/[^\/]+\/(.*)
|
|
159
|
-
// basically removes the entire "blob:http://localhost:3000/" prefix.
|
|
160
|
-
const stripped = url.replace(
|
|
161
|
-
/^blob:(?:http|https|file):\/\/[^\/]+\/(.+)/i,
|
|
162
|
-
"$1"
|
|
163
|
-
);
|
|
164
|
-
// b) Normalize backslashes "\" → forward slashes "/"
|
|
165
|
-
const fixedSlashes = stripped.replace(/\\/g, "/");
|
|
166
|
-
console.log(
|
|
167
|
-
`PrefViewer: preprocessUrl received "${url}", stripped to "${stripped}", normalized to "${fixedSlashes}"`
|
|
168
|
-
);
|
|
169
|
-
// c) If it now starts with "http://" or "https://", return it as an absolute URL:
|
|
170
|
-
if (/^https?:\/\//i.test(fixedSlashes)) {
|
|
171
|
-
console.log(`PrefViewer: preprocessUrl returning absolute URL "${fixedSlashes}"`);
|
|
172
|
-
return fixedSlashes;
|
|
173
|
-
}
|
|
174
|
-
// d) Otherwise, return the relative path (Babylon will resolve it relative to the blob if needed)
|
|
175
|
-
console.log(`PrefViewer: preprocessUrl returning relative URL "${fixedSlashes}"`);
|
|
176
|
-
return fixedSlashes;
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
// 3) Create camera and lights
|
|
141
|
+
// 2) Create camera and lights
|
|
182
142
|
console.log("PrefViewer: _createCamera and _createLights");
|
|
183
143
|
this._createCamera();
|
|
184
144
|
this._createLights();
|
|
185
145
|
|
|
186
|
-
//
|
|
146
|
+
// 3) Hook up input/event handlers (e.g. wheel-to-zoom)
|
|
187
147
|
console.log("PrefViewer: _setupEventListeners");
|
|
188
148
|
this._setupEventListeners();
|
|
189
149
|
|
|
190
|
-
//
|
|
150
|
+
// 4) Start Babylon’s render loop
|
|
191
151
|
console.log("PrefViewer: Starting render loop");
|
|
192
152
|
this.engine.runRenderLoop(() => {
|
|
193
153
|
if (this.scene) {
|
|
@@ -263,6 +223,21 @@ class PrefViewer extends HTMLElement {
|
|
|
263
223
|
// Dispose previous meshes so we don’t accumulate them
|
|
264
224
|
this._disposePreviousMeshes();
|
|
265
225
|
|
|
226
|
+
SceneLoader.OnPluginActivatedObservable.addOnce((plugin) => {
|
|
227
|
+
if (plugin.name === "gltf") {
|
|
228
|
+
plugin.preprocessUrlAsync = async (url) => {
|
|
229
|
+
try {
|
|
230
|
+
const parsed = new URL(url);
|
|
231
|
+
return parsed.href; // Absolute URL: use as-is
|
|
232
|
+
} catch {
|
|
233
|
+
// If relative, optionally fix or log
|
|
234
|
+
console.warn("Relative texture URL, resolving manually:", url);
|
|
235
|
+
return url; // or prepend your desired base path here
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
266
241
|
try {
|
|
267
242
|
console.log(`PrefViewer: ImportMeshAsync("${this.modelUrl}")`);
|
|
268
243
|
const result = await SceneLoader.ImportMeshAsync(
|