MikaFil commited on
Commit
6cf750d
·
verified ·
1 Parent(s): 0d17afa

Update viewer.js

Browse files
Files changed (1) hide show
  1. viewer.js +19 -2
viewer.js CHANGED
@@ -36,7 +36,6 @@ function hexToRgbaArray(hex) {
36
  }
37
  }
38
 
39
-
40
  // ----- Utility: Recursive scene traversal -----
41
  function traverse(entity, callback) {
42
  callback(entity);
@@ -45,6 +44,24 @@ function traverse(entity, callback) {
45
  }
46
  }
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  let pc;
49
  export let app = null;
50
  let cameraEntity = null;
@@ -219,7 +236,7 @@ export async function initializeViewer(config, instanceId) {
219
  app.root.addChild(presentoirEntity);
220
 
221
  if(!espace_expo_bool){
222
- //const grilleTex = await loadImageAsTexture('https://huggingface.co/datasets/MikaFil/viewer_gs/resolve/main/ressources/textures/grille_cadrillee_4k.jpg', app);
223
  let matSol = new pc.StandardMaterial();
224
  matSol.blendType = pc.BLEND_NONE;
225
  matSol.emissive = new pc.Color(color_bg);
 
36
  }
37
  }
38
 
 
39
  // ----- Utility: Recursive scene traversal -----
40
  function traverse(entity, callback) {
41
  callback(entity);
 
44
  }
45
  }
46
 
47
+ async function loadImageAsTexture(url, app) {
48
+ return new Promise((resolve, reject) => {
49
+ const img = new window.Image();
50
+ img.crossOrigin = "anonymous";
51
+ img.onload = function() {
52
+ const tex = new pc.Texture(app.graphicsDevice, {
53
+ width: img.width,
54
+ height: img.height,
55
+ format: pc.PIXELFORMAT_R8_G8_B8_A8,
56
+ });
57
+ tex.setSource(img);
58
+ resolve(tex);
59
+ };
60
+ img.onerror = reject;
61
+ img.src = url;
62
+ });
63
+ }
64
+
65
  let pc;
66
  export let app = null;
67
  let cameraEntity = null;
 
236
  app.root.addChild(presentoirEntity);
237
 
238
  if(!espace_expo_bool){
239
+ const grilleTex = await loadImageAsTexture('https://huggingface.co/datasets/MikaFil/viewer_gs/resolve/main/ressources/textures/grille_cadrillee_4k.jpg', app);
240
  let matSol = new pc.StandardMaterial();
241
  matSol.blendType = pc.BLEND_NONE;
242
  matSol.emissive = new pc.Color(color_bg);