MikaFil commited on
Commit
21f3fb8
·
verified ·
1 Parent(s): 898c748

Update viewer.js

Browse files
Files changed (1) hide show
  1. viewer.js +19 -1
viewer.js CHANGED
@@ -18,6 +18,16 @@
18
  };
19
  })();
20
 
 
 
 
 
 
 
 
 
 
 
21
  let pc;
22
  export let app = null;
23
  let cameraEntity = null;
@@ -32,6 +42,7 @@ let modelX, modelY, modelZ, modelScale, modelRotationX, modelRotationY, modelRot
32
  let presentoirScaleX, presentoirScaleY, presentoirScaleZ;
33
 
34
  let sogsUrl, glbUrl, presentoirUrl;
 
35
 
36
  // --- Log user agent and page location ---
37
  console.log("%c[VIEWER DEBUG] User Agent:", "color: #0074D9;", navigator.userAgent);
@@ -43,6 +54,7 @@ export async function initializeViewer(config, instanceId) {
43
  const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
44
  const isMobile = isIOS || /Android/i.test(navigator.userAgent);
45
 
 
46
  sogsUrl = config.sogs_json_url;
47
  glbUrl = (config.glb_url !== undefined) ? config.glb_url : "https://huggingface.co/datasets/MikaFil/viewer_gs/resolve/main/ressources/espace_expo/sol_blanc.glb";
48
  presentoirUrl = (config.presentoir_url !== undefined) ? config.presentoir_url : "https://huggingface.co/datasets/MikaFil/viewer_gs/resolve/main/ressources/espace_expo/sol_blanc.glb";
@@ -67,6 +79,11 @@ export async function initializeViewer(config, instanceId) {
67
  presentoirScaleY = (config.presentoirScaleY !== undefined) ? parseFloat(config.presentoirScaleY) : 0;
68
  presentoirScaleZ = (config.presentoirScaleZ !== undefined) ? parseFloat(config.presentoirScaleZ) : 0;
69
 
 
 
 
 
 
70
  const cameraX = (config.cameraX !== undefined) ? parseFloat(config.cameraX) : 0;
71
  const cameraY = (config.cameraY !== undefined) ? parseFloat(config.cameraY) : 2;
72
  const cameraZ = (config.cameraZ !== undefined) ? parseFloat(config.cameraZ) : 5;
@@ -78,6 +95,7 @@ export async function initializeViewer(config, instanceId) {
78
  chosenCameraY = isMobile ? cameraYPhone : cameraY;
79
  chosenCameraZ = isMobile ? cameraZPhone : cameraZ;
80
 
 
81
  const canvasId = 'canvas-' + instanceId;
82
  const progressDialog = document.getElementById('progress-dialog-' + instanceId);
83
  const progressIndicator = document.getElementById('progress-indicator-' + instanceId);
@@ -207,7 +225,7 @@ export async function initializeViewer(config, instanceId) {
207
  app.root.addChild(presentoirEntity);
208
 
209
  cameraEntity = new pc.Entity('camera');
210
- cameraEntity.addComponent('camera', { clearColor: new pc.Color(1, 1, 1, 1) });
211
  cameraEntity.setPosition(chosenCameraX, chosenCameraY, chosenCameraZ);
212
  cameraEntity.lookAt(modelEntity.getPosition());
213
  cameraEntity.addComponent('script');
 
18
  };
19
  })();
20
 
21
+ //convertie les hex en vec rgb
22
+ function hexToRgb(hex) {
23
+ var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
24
+ return result ? {
25
+ r: parseInt(result[1], 16),
26
+ g: parseInt(result[2], 16),
27
+ b: parseInt(result[3], 16)
28
+ } : null;
29
+ }
30
+
31
  let pc;
32
  export let app = null;
33
  let cameraEntity = null;
 
42
  let presentoirScaleX, presentoirScaleY, presentoirScaleZ;
43
 
44
  let sogsUrl, glbUrl, presentoirUrl;
45
+ let color_bg_hex, color_bg;
46
 
47
  // --- Log user agent and page location ---
48
  console.log("%c[VIEWER DEBUG] User Agent:", "color: #0074D9;", navigator.userAgent);
 
54
  const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
55
  const isMobile = isIOS || /Android/i.test(navigator.userAgent);
56
 
57
+ //prends les differents arguments de config.json
58
  sogsUrl = config.sogs_json_url;
59
  glbUrl = (config.glb_url !== undefined) ? config.glb_url : "https://huggingface.co/datasets/MikaFil/viewer_gs/resolve/main/ressources/espace_expo/sol_blanc.glb";
60
  presentoirUrl = (config.presentoir_url !== undefined) ? config.presentoir_url : "https://huggingface.co/datasets/MikaFil/viewer_gs/resolve/main/ressources/espace_expo/sol_blanc.glb";
 
79
  presentoirScaleY = (config.presentoirScaleY !== undefined) ? parseFloat(config.presentoirScaleY) : 0;
80
  presentoirScaleZ = (config.presentoirScaleZ !== undefined) ? parseFloat(config.presentoirScaleZ) : 0;
81
 
82
+ color_bg_hex = (config.canvas_background !== undefined) ? config.canvas_background : "#DDD4D5";
83
+ color_bg = new pc.Color(hexToRgb(color_bg_hex));
84
+ console.log(color_bg);
85
+
86
+
87
  const cameraX = (config.cameraX !== undefined) ? parseFloat(config.cameraX) : 0;
88
  const cameraY = (config.cameraY !== undefined) ? parseFloat(config.cameraY) : 2;
89
  const cameraZ = (config.cameraZ !== undefined) ? parseFloat(config.cameraZ) : 5;
 
95
  chosenCameraY = isMobile ? cameraYPhone : cameraY;
96
  chosenCameraZ = isMobile ? cameraZPhone : cameraZ;
97
 
98
+ //cree le nouveau canva (instanceId est une valeur aléatoire pour gérer plusieurs canvas sur la meme page)
99
  const canvasId = 'canvas-' + instanceId;
100
  const progressDialog = document.getElementById('progress-dialog-' + instanceId);
101
  const progressIndicator = document.getElementById('progress-indicator-' + instanceId);
 
225
  app.root.addChild(presentoirEntity);
226
 
227
  cameraEntity = new pc.Entity('camera');
228
+ //cameraEntity.addComponent('camera', { clearColor: new pc.Color(1, 1, 1, 1) });
229
  cameraEntity.setPosition(chosenCameraX, chosenCameraY, chosenCameraZ);
230
  cameraEntity.lookAt(modelEntity.getPosition());
231
  cameraEntity.addComponent('script');