Spaces:
Running
Running
Update viewer.js
Browse files
viewer.js
CHANGED
|
@@ -1,6 +1,23 @@
|
|
| 1 |
// viewer.js
|
| 2 |
// ==============================
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
let pc;
|
| 5 |
export let app = null;
|
| 6 |
let cameraEntity = null;
|
|
@@ -17,56 +34,6 @@ let sogsUrl, glbUrl;
|
|
| 17 |
console.log("%c[VIEWER DEBUG] User Agent:", "color: #0074D9;", navigator.userAgent);
|
| 18 |
console.log("%c[VIEWER DEBUG] Page:", "color: #0074D9;", location.href);
|
| 19 |
|
| 20 |
-
// --- Monkeypatch Image to log src and crossOrigin ---
|
| 21 |
-
(function() {
|
| 22 |
-
const OriginalImage = window.Image;
|
| 23 |
-
window.Image = function(...args) {
|
| 24 |
-
const img = new OriginalImage(...args);
|
| 25 |
-
const origSetAttribute = img.setAttribute;
|
| 26 |
-
img.setAttribute = function(name, value) {
|
| 27 |
-
if (name === "crossOrigin") {
|
| 28 |
-
console.log("%c[VIEWER DEBUG] setAttribute crossOrigin:", "color: orange;", value, img.src);
|
| 29 |
-
}
|
| 30 |
-
return origSetAttribute.apply(this, arguments);
|
| 31 |
-
};
|
| 32 |
-
Object.defineProperty(img, "src", {
|
| 33 |
-
set(value) {
|
| 34 |
-
console.log("%c[VIEWER DEBUG] Setting img.src:", "color: orange;", value, "crossOrigin:", img.crossOrigin);
|
| 35 |
-
origSetAttribute.call(img, "src", value);
|
| 36 |
-
}
|
| 37 |
-
});
|
| 38 |
-
img.onload = function() {
|
| 39 |
-
console.log("%c[VIEWER DEBUG] Image loaded:", "color: orange;", img.src, "crossOrigin:", img.crossOrigin);
|
| 40 |
-
};
|
| 41 |
-
img.onerror = function(e) {
|
| 42 |
-
console.error("%c[VIEWER DEBUG] Image load error:", "color: orange;", img.src, e);
|
| 43 |
-
};
|
| 44 |
-
return img;
|
| 45 |
-
};
|
| 46 |
-
})();
|
| 47 |
-
|
| 48 |
-
// --- Monkeypatch WebGL texImage2D for detailed logging ---
|
| 49 |
-
(function() {
|
| 50 |
-
const orig = WebGLRenderingContext.prototype.texImage2D;
|
| 51 |
-
WebGLRenderingContext.prototype.texImage2D = function() {
|
| 52 |
-
try {
|
| 53 |
-
console.log("%c[VIEWER DEBUG] texImage2D called with:", "color: #FF4136;", arguments);
|
| 54 |
-
return orig.apply(this, arguments);
|
| 55 |
-
} catch (e) {
|
| 56 |
-
console.error("%c[VIEWER DEBUG] texImage2D ERROR:", "color: #FF4136;", e, arguments);
|
| 57 |
-
throw e;
|
| 58 |
-
}
|
| 59 |
-
};
|
| 60 |
-
})();
|
| 61 |
-
|
| 62 |
-
// --- Global error logging ---
|
| 63 |
-
window.addEventListener("error", function(e) {
|
| 64 |
-
if (e.message && /insecure|taint|cross-origin/i.test(e.message)) {
|
| 65 |
-
alert("[VIEWER] WebGL/CORS error: " + e.message);
|
| 66 |
-
console.error("%c[VIEWER DEBUG] Global error:", "color: #FF4136;", e);
|
| 67 |
-
}
|
| 68 |
-
});
|
| 69 |
-
|
| 70 |
export async function initializeViewer(config, instanceId) {
|
| 71 |
if (viewerInitialized) return;
|
| 72 |
|
|
@@ -135,23 +102,6 @@ export async function initializeViewer(config, instanceId) {
|
|
| 135 |
window.pc = pc;
|
| 136 |
}
|
| 137 |
|
| 138 |
-
if (pc && pc.TextureHandler) {
|
| 139 |
-
const origLoad = pc.TextureHandler.prototype.load;
|
| 140 |
-
pc.TextureHandler.prototype.load = function(url, callback, asset) {
|
| 141 |
-
// Use our own image loader
|
| 142 |
-
const img = new window.Image();
|
| 143 |
-
img.crossOrigin = "anonymous";
|
| 144 |
-
img.onload = function() {
|
| 145 |
-
callback(null, img);
|
| 146 |
-
};
|
| 147 |
-
img.onerror = function(err) {
|
| 148 |
-
callback(err || new Error("Image load failed"), null);
|
| 149 |
-
};
|
| 150 |
-
img.src = url;
|
| 151 |
-
};
|
| 152 |
-
console.log("[VIEWER DEBUG] Patched pc.TextureHandler to force crossOrigin=anonymous on all images");
|
| 153 |
-
}
|
| 154 |
-
|
| 155 |
// Create app first
|
| 156 |
const device = await pc.createGraphicsDevice(canvas, {
|
| 157 |
deviceTypes: ["webgl2"],
|
|
|
|
| 1 |
// viewer.js
|
| 2 |
// ==============================
|
| 3 |
|
| 4 |
+
// --- Patch all window.Image to force crossOrigin="anonymous" ---
|
| 5 |
+
(function() {
|
| 6 |
+
const OriginalImage = window.Image;
|
| 7 |
+
window.Image = function(...args) {
|
| 8 |
+
const img = new OriginalImage(...args);
|
| 9 |
+
img.crossOrigin = "anonymous";
|
| 10 |
+
// Optionally log image loading for debugging
|
| 11 |
+
img.onload = function() {
|
| 12 |
+
console.log("[VIEWER DEBUG] Image loaded:", img.src, "crossOrigin:", img.crossOrigin);
|
| 13 |
+
};
|
| 14 |
+
img.onerror = function(e) {
|
| 15 |
+
console.error("[VIEWER DEBUG] Image load error:", img.src, e);
|
| 16 |
+
};
|
| 17 |
+
return img;
|
| 18 |
+
};
|
| 19 |
+
})();
|
| 20 |
+
|
| 21 |
let pc;
|
| 22 |
export let app = null;
|
| 23 |
let cameraEntity = null;
|
|
|
|
| 34 |
console.log("%c[VIEWER DEBUG] User Agent:", "color: #0074D9;", navigator.userAgent);
|
| 35 |
console.log("%c[VIEWER DEBUG] Page:", "color: #0074D9;", location.href);
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
export async function initializeViewer(config, instanceId) {
|
| 38 |
if (viewerInitialized) return;
|
| 39 |
|
|
|
|
| 102 |
window.pc = pc;
|
| 103 |
}
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
// Create app first
|
| 106 |
const device = await pc.createGraphicsDevice(canvas, {
|
| 107 |
deviceTypes: ["webgl2"],
|