← Commit history

Proper key/fill/rim rig via stolen constructor; instrument the stalled init

John Lauer ·091b2259d6 ·2mo ago ·parent e89852d
1 file changed +59−9
viewer/index.html+59−9
@@ -1376,6 +1376,26 @@ async function initViewer() {       environmentUrl: 'js/environmentSpecular.env',     });     window.viewer = viewer;  // expose for eval/ bridge+    // Diagnostics for the sandbox failure. Adom3DViewer.init() is NOT awaited:+    // it hands back the API object and finishes setup in the background+    // (SceneBuilder.init creates the light rig, then scene.executeWhenReady+    // starts the render loop). Under the wiki CSP that background step never+    // completes, so both are missing with no error anywhere. Read+    // window.__initDiag to see how far it got.+    window.__initDiag = { t0: Date.now(), checks: [] };+    for (const ms of [200, 1000, 3000, 8000, 15000]) setTimeout(() => {+      try {+        const sc = viewer.getScene(), en = viewer.getEngine();+        window.__initDiag.checks.push({+          ms, lights: sc.lights.length, env: !!sc.environmentTexture,+          loops: en.activeRenderLoops.length, meshes: sc.meshes.length,+          ready: sc.isReady ? sc.isReady() : null,+        });+      } catch (e) { window.__initDiag.checks.push({ ms, err: String(e).slice(0, 120) }); }+    }, ms);+    addEventListener('unhandledrejection', (e) => {+      window.__initDiag.rejection = String(e.reason).slice(0, 200);+    });     // ── Rotation-center sphere: only show on user-initiated orbit ──     // The adom-3d-viewer draws an `arcRotateIndicatorSphere` at the     // camera target whenever `detectAndShowRotationSphere()` (called@@ -1525,19 +1545,49 @@ async function loadCurrentGlb(force) {       }        if (scene.lights.length === 0 && !scene.environmentTexture && scene.createDefaultLight) {+        // A single hemispheric light leaves PBR looking flat and washed out,+        // because with no environmentTexture there is nothing driving the+        // specular lobe. Adom3DViewer.BABYLON exports no light class, but the+        // stolen-constructor trick from the adom-tsci skill works here too:+        // take the class off the instance createDefaultLight gives us and+        // build a real key / fill / rim rig.         scene.createDefaultLight(true);-        const l = scene.lights[0];-        if (l) {-          l.direction = new B.Vector3(-0.3, -0.5, 1);-          l.intensity = 2.2;-          l.diffuse = new B.Color3(1, 1, 1);-          l.groundColor = new B.Color3(0.45, 0.47, 0.5);-          l.specular = new B.Color3(0.6, 0.6, 0.6);+        const hemi = scene.lights[0];+        if (hemi) {+          hemi.direction = new B.Vector3(-0.25, -0.45, 1);+          hemi.intensity = 0.85;+          hemi.diffuse = new B.Color3(1, 1, 1);+          hemi.groundColor = new B.Color3(0.30, 0.32, 0.36);+          hemi.specular = new B.Color3(0.25, 0.25, 0.28);++          const Hemi = hemi.constructor;+          const add = (name, dir, intensity, diffuse, ground, spec) => {+            try {+              const l = new Hemi(name, dir, scene);+              l.intensity = intensity;+              l.diffuse = diffuse;+              l.groundColor = ground;+              l.specular = spec;+              return l;+            } catch (e) { return null; }+          };+          // Key from the upper front-left, warm; fill from the opposite side,+          // cool and dim; rim from behind to pick out the component edges.+          add('rescueKey',  new B.Vector3(-0.55, -0.65, 0.85), 1.15,+              new B.Color3(1.00, 0.97, 0.92), new B.Color3(0.12, 0.13, 0.16),+              new B.Color3(0.85, 0.85, 0.85));+          add('rescueFill', new B.Vector3(0.70, 0.35, 0.55), 0.55,+              new B.Color3(0.80, 0.86, 1.00), new B.Color3(0.10, 0.11, 0.13),+              new B.Color3(0.30, 0.32, 0.38));+          add('rescueRim',  new B.Vector3(0.20, 0.85, 0.35), 0.45,+              new B.Color3(0.92, 0.95, 1.00), new B.Color3(0.08, 0.08, 0.10),+              new B.Color3(0.55, 0.58, 0.65));         }-        scene.ambientColor = new B.Color3(0.35, 0.35, 0.35);+        scene.ambientColor = new B.Color3(0.22, 0.22, 0.24);         for (const m of scene.materials) {           if (m.ambientColor) m.ambientColor = new B.Color3(1, 1, 1);-          if (m.environmentIntensity !== undefined) m.environmentIntensity = 0;+          // Do NOT zero environmentIntensity: if a future bundle manages to+          // load the .env, that would silently throw the IBL away again.         }       }