MikaFil commited on
Commit
e7ca7b5
·
verified ·
1 Parent(s): b4e5b01

Update viewer.js

Browse files
Files changed (1) hide show
  1. viewer.js +13 -7
viewer.js CHANGED
@@ -3,6 +3,8 @@
3
 
4
  /* -------------------------------------------
5
  Utils
 
 
6
  -------------------------------------------- */
7
 
8
  async function loadImageAsTexture(url, app) {
@@ -23,7 +25,7 @@ async function loadImageAsTexture(url, app) {
23
  });
24
  }
25
 
26
- // Patch global Image -> force CORS
27
  (function () {
28
  const OriginalImage = window.Image;
29
  window.Image = function (...args) {
@@ -104,7 +106,7 @@ let chosenCameraX, chosenCameraY, chosenCameraZ;
104
  let minZoom, maxZoom, minAngle, maxAngle, minAzimuth, maxAzimuth, minY;
105
  let modelX, modelY, modelZ, modelScale, modelRotationX, modelRotationY, modelRotationZ;
106
  let presentoirScaleX, presentoirScaleY, presentoirScaleZ;
107
- let sogsUrl, glbUrl, presentoirUrl;
108
  let color_bg_hex, color_bg, espace_expo_bool;
109
 
110
  /* -------------------------------------------
@@ -119,7 +121,9 @@ export async function initializeViewer(config, instanceId) {
119
  const isMobile = isIOS || /Android/i.test(navigator.userAgent);
120
 
121
  // --- Configuration ---
122
- sogsUrl = config.sogs_json_url;
 
 
123
 
124
  glbUrl =
125
  config.glb_url !== undefined
@@ -287,6 +291,7 @@ export async function initializeViewer(config, instanceId) {
287
  pc.CollisionComponentSystem,
288
  pc.RigidbodyComponentSystem
289
  ];
 
290
  opts.resourceHandlers = [pc.TextureHandler, pc.ContainerHandler, pc.ScriptHandler, pc.GSplatHandler];
291
 
292
  app = new pc.Application(canvas, opts);
@@ -322,9 +327,10 @@ export async function initializeViewer(config, instanceId) {
322
  canvas.removeEventListener("blur", onCanvasBlur);
323
  });
324
 
325
- // --- Enregistre les assets (SAUF orbit script : chargé globalement) ---
 
326
  const assets = {
327
- sogs: new pc.Asset("gsplat", "gsplat", { url: sogsUrl }),
328
  glb: new pc.Asset("glb", "container", { url: glbUrl }),
329
  presentoir: new pc.Asset("presentoir", "container", { url: presentoirUrl })
330
  };
@@ -339,9 +345,9 @@ export async function initializeViewer(config, instanceId) {
339
  app.start();
340
  progressDialog.style.display = "none";
341
 
342
- // --- Modèle principal (gsplat) ---
343
  modelEntity = new pc.Entity("model");
344
- modelEntity.addComponent("gsplat", { asset: assets.sogs });
345
  modelEntity.setLocalPosition(modelX, modelY, modelZ);
346
  modelEntity.setLocalEulerAngles(modelRotationX, modelRotationY, modelRotationZ);
347
  modelEntity.setLocalScale(modelScale, modelScale, modelScale);
 
3
 
4
  /* -------------------------------------------
5
  Utils
6
+ (les helpers image ne sont plus nécessaires pour .sog,
7
+ mais on les garde sans effet de bord pour compat ascendante)
8
  -------------------------------------------- */
9
 
10
  async function loadImageAsTexture(url, app) {
 
25
  });
26
  }
27
 
28
+ // Patch global Image -> force CORS (sans incidence pour .sog)
29
  (function () {
30
  const OriginalImage = window.Image;
31
  window.Image = function (...args) {
 
106
  let minZoom, maxZoom, minAngle, maxAngle, minAzimuth, maxAzimuth, minY;
107
  let modelX, modelY, modelZ, modelScale, modelRotationX, modelRotationY, modelRotationZ;
108
  let presentoirScaleX, presentoirScaleY, presentoirScaleZ;
109
+ let sogUrl, glbUrl, presentoirUrl;
110
  let color_bg_hex, color_bg, espace_expo_bool;
111
 
112
  /* -------------------------------------------
 
121
  const isMobile = isIOS || /Android/i.test(navigator.userAgent);
122
 
123
  // --- Configuration ---
124
+ // Nouveau : utiliser un .sog "bundled" (format SOG PlayCanvas)
125
+ // Compat ascendante : on accepte encore sogs_json_url si sog_url absent
126
+ sogUrl = config.sog_url || config.sogs_json_url;
127
 
128
  glbUrl =
129
  config.glb_url !== undefined
 
291
  pc.CollisionComponentSystem,
292
  pc.RigidbodyComponentSystem
293
  ];
294
+ // GSplatHandler gère nativement les .sog (bundled SOG)
295
  opts.resourceHandlers = [pc.TextureHandler, pc.ContainerHandler, pc.ScriptHandler, pc.GSplatHandler];
296
 
297
  app = new pc.Application(canvas, opts);
 
327
  canvas.removeEventListener("blur", onCanvasBlur);
328
  });
329
 
330
+ // --- Enregistre les assets ---
331
+ // IMPORTANT : pour .sog on déclare un asset de type "gsplat" avec l'URL .sog
332
  const assets = {
333
+ sog: new pc.Asset("gsplat", "gsplat", { url: sogUrl }),
334
  glb: new pc.Asset("glb", "container", { url: glbUrl }),
335
  presentoir: new pc.Asset("presentoir", "container", { url: presentoirUrl })
336
  };
 
345
  app.start();
346
  progressDialog.style.display = "none";
347
 
348
+ // --- Modèle principal (GSplat via .sog) ---
349
  modelEntity = new pc.Entity("model");
350
+ modelEntity.addComponent("gsplat", { asset: assets.sog });
351
  modelEntity.setLocalPosition(modelX, modelY, modelZ);
352
  modelEntity.setLocalEulerAngles(modelRotationX, modelRotationY, modelRotationZ);
353
  modelEntity.setLocalScale(modelScale, modelScale, modelScale);