MikaFil commited on
Commit
12e3548
·
verified ·
1 Parent(s): 30e3f83

Update viewer.js

Browse files
Files changed (1) hide show
  1. viewer.js +38 -5
viewer.js CHANGED
@@ -68,8 +68,22 @@ export async function initializeViewer(config, instanceId) {
68
  canvas.style.zIndex = "1";
69
  viewerContainer.insertBefore(canvas, progressDialog);
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  // 4. Wheel listener
72
  canvas.addEventListener('wheel', e => {
 
73
  if (cameraEntity && cameraEntity.script && cameraEntity.script.orbitCamera) {
74
  const orbitCam = cameraEntity.script.orbitCamera;
75
  const sens = (cameraEntity.script.orbitCameraInputMouse?.distanceSensitivity) || 0.4;
@@ -148,13 +162,16 @@ export async function initializeViewer(config, instanceId) {
148
  const assets = {
149
  model: new pc.Asset('gsplat', 'gsplat', { url: plyUrl }),
150
  orbit: new pc.Asset('script', 'script', { url: "https://mikafil-viewer-gs.static.hf.space/orbit-camera.js" }),
151
- galerie: new pc.Asset('galerie', 'container', { url: glbUrl }),
152
  hdr: new pc.Asset('hdr', 'texture', {
153
  url: "https://huggingface.co/datasets/bilca/ply_files/resolve/main/galeries/blanc.png"
154
  }, { type: pc.TEXTURETYPE_RGBP, mipmaps: false })
155
  };
156
 
157
- const loader = new pc.AssetListLoader(Object.values(assets), app.assets);
 
 
 
158
  let lastProg = 0;
159
  assets.model.on('load', () => progressDialog.style.display = 'none');
160
  assets.model.on('error', err => {
@@ -173,6 +190,7 @@ export async function initializeViewer(config, instanceId) {
173
  }, 100);
174
 
175
  loader.load(async () => {
 
176
  app.start();
177
  app.scene.envAtlas = assets.hdr.resource;
178
 
@@ -205,9 +223,11 @@ export async function initializeViewer(config, instanceId) {
205
  dirLight.setLocalEulerAngles(0, 0, 0);
206
  app.root.addChild(dirLight);
207
 
208
- // Gallery GLB
 
209
  if (assets.galerie && assets.galerie.resource && assets.galerie.resource.instantiateRenderEntity) {
210
- const galleryEntity = assets.galerie.resource.instantiateRenderEntity();
 
211
  app.root.addChild(galleryEntity);
212
  }
213
 
@@ -233,6 +253,7 @@ export async function initializeViewer(config, instanceId) {
233
  yawAngleMax: maxAzimuth,
234
  yawAngleMin: minAzimuth,
235
  minPivotY: minPivotY,
 
236
  frameOnStart: false
237
  }
238
  });
@@ -253,6 +274,14 @@ export async function initializeViewer(config, instanceId) {
253
  });
254
  app.root.addChild(cameraEntity);
255
 
 
 
 
 
 
 
 
 
256
  // Reset & constrain updates
257
  app.once('update', () => resetViewerCamera());
258
  app.on('update', dt => {
@@ -267,6 +296,10 @@ export async function initializeViewer(config, instanceId) {
267
  // Final resize
268
  app.resizeCanvas(viewerContainer.clientWidth, viewerContainer.clientHeight);
269
 
 
 
 
 
270
  // Tooltips
271
  try {
272
  const tooltipsModule = await import('./tooltips.js');
@@ -279,7 +312,7 @@ export async function initializeViewer(config, instanceId) {
279
  moveDuration: config.tooltipMoveDuration || 0.6
280
  });
281
  } catch (e) {
282
- // Tooltips are optional
283
  }
284
 
285
  progressDialog.style.display = 'none';
 
68
  canvas.style.zIndex = "1";
69
  viewerContainer.insertBefore(canvas, progressDialog);
70
 
71
+ // --- PATCH: Prevent pinch/double-tap zoom for iOS (in addition to interface.js) ---
72
+ if (isIOS) {
73
+ canvas.style.touchAction = "none";
74
+ canvas.addEventListener('gesturestart', e => e.preventDefault());
75
+ canvas.addEventListener('gesturechange', e => e.preventDefault());
76
+ canvas.addEventListener('gestureend', e => e.preventDefault());
77
+ // Extra: prevent rubber-band scroll on iOS Safari inside canvas
78
+ canvas.addEventListener('touchmove', function(e) {
79
+ if (e.touches.length > 1) e.preventDefault();
80
+ }, { passive: false });
81
+ }
82
+ // --------------------------------------------------------------------------
83
+
84
  // 4. Wheel listener
85
  canvas.addEventListener('wheel', e => {
86
+ // Only prevent default if wheel is over canvas (don't scroll webpage)
87
  if (cameraEntity && cameraEntity.script && cameraEntity.script.orbitCamera) {
88
  const orbitCam = cameraEntity.script.orbitCamera;
89
  const sens = (cameraEntity.script.orbitCameraInputMouse?.distanceSensitivity) || 0.4;
 
162
  const assets = {
163
  model: new pc.Asset('gsplat', 'gsplat', { url: plyUrl }),
164
  orbit: new pc.Asset('script', 'script', { url: "https://mikafil-viewer-gs.static.hf.space/orbit-camera.js" }),
165
+ galerie: glbUrl ? new pc.Asset('galerie', 'container', { url: glbUrl }) : null,
166
  hdr: new pc.Asset('hdr', 'texture', {
167
  url: "https://huggingface.co/datasets/bilca/ply_files/resolve/main/galeries/blanc.png"
168
  }, { type: pc.TEXTURETYPE_RGBP, mipmaps: false })
169
  };
170
 
171
+ // --- PATCH: PlayCanvas bug on iOS: forcibly wait for all assets before first render ---
172
+ let allLoaded = false;
173
+
174
+ const loader = new pc.AssetListLoader(Object.values(assets).filter(Boolean), app.assets);
175
  let lastProg = 0;
176
  assets.model.on('load', () => progressDialog.style.display = 'none');
177
  assets.model.on('error', err => {
 
190
  }, 100);
191
 
192
  loader.load(async () => {
193
+ allLoaded = true;
194
  app.start();
195
  app.scene.envAtlas = assets.hdr.resource;
196
 
 
223
  dirLight.setLocalEulerAngles(0, 0, 0);
224
  app.root.addChild(dirLight);
225
 
226
+ // Gallery GLB (floor)
227
+ let galleryEntity = null;
228
  if (assets.galerie && assets.galerie.resource && assets.galerie.resource.instantiateRenderEntity) {
229
+ galleryEntity = assets.galerie.resource.instantiateRenderEntity();
230
+ galleryEntity.enabled = true; // Ensure enabled at start
231
  app.root.addChild(galleryEntity);
232
  }
233
 
 
253
  yawAngleMax: maxAzimuth,
254
  yawAngleMin: minAzimuth,
255
  minPivotY: minPivotY,
256
+ minY: minY,
257
  frameOnStart: false
258
  }
259
  });
 
274
  });
275
  app.root.addChild(cameraEntity);
276
 
277
+ // --- iOS Black Screen Bug Fix: force at least one frame after all assets are loaded ---
278
+ // Wait for WebGL context to be ready before first render
279
+ app.once('frameupdate', () => {
280
+ if (!canvas.width || !canvas.height) {
281
+ app.resizeCanvas(viewerContainer.clientWidth, viewerContainer.clientHeight);
282
+ }
283
+ });
284
+
285
  // Reset & constrain updates
286
  app.once('update', () => resetViewerCamera());
287
  app.on('update', dt => {
 
296
  // Final resize
297
  app.resizeCanvas(viewerContainer.clientWidth, viewerContainer.clientHeight);
298
 
299
+ // --- Gallery GLB (floor) visibility bug on iPhone ---
300
+ // Defensive: never toggle galerie (floor) visibility on tooltip toggle!
301
+ // If you ever use tooltips code that disables/enables galleryEntity, remove it.
302
+
303
  // Tooltips
304
  try {
305
  const tooltipsModule = await import('./tooltips.js');
 
312
  moveDuration: config.tooltipMoveDuration || 0.6
313
  });
314
  } catch (e) {
315
+ // Tooltips are optional; do nothing if failed
316
  }
317
 
318
  progressDialog.style.display = 'none';