MikaFil commited on
Commit
4f02694
·
verified ·
1 Parent(s): d9a3e89

Update viewer.js

Browse files
Files changed (1) hide show
  1. viewer.js +6 -17
viewer.js CHANGED
@@ -80,7 +80,7 @@ export async function initializeViewer(config, instanceId) {
80
  window.pc = pc;
81
  }
82
 
83
- // Create app *before* creating assets!
84
  const device = await pc.createGraphicsDevice(canvas, {
85
  deviceTypes: ["webgl2"],
86
  glslangUrl: "https://playcanvas.vercel.app/static/lib/glslang/glslang.js",
@@ -123,31 +123,18 @@ export async function initializeViewer(config, instanceId) {
123
  window.addEventListener('resize', () => app.resizeCanvas(viewerContainer.clientWidth, viewerContainer.clientHeight));
124
  app.on('destroy', () => resizeObserver.disconnect());
125
 
126
- // Now create and register assets (with app.assets ready)
127
  const assets = {
128
  model: new pc.Asset('gsplat', 'gsplat', { url: plyUrl }),
129
  orbit: new pc.Asset('script', 'script', { url: "https://mikafil-viewer-gs.static.hf.space/orbit-camera.js" }),
130
- hdr: new pc.Asset(
131
- 'hdr', 'texture',
132
- { url: "https://huggingface.co/datasets/bilca/ply_files/resolve/main/galeries/blanc.png" },
133
- { type: pc.TEXTURETYPE_RGBP, mipmaps: false }
134
- ),
135
  };
136
- // Register all assets to app.assets
137
- for (const key in assets) {
138
- app.assets.add(assets[key]);
139
- }
140
 
141
  const loader = new pc.AssetListLoader(Object.values(assets), app.assets);
142
  loader.load(() => {
143
  app.start();
144
  progressDialog.style.display = 'none';
145
 
146
- // Apply HDR environment if available
147
- if (assets.hdr && assets.hdr.resource) {
148
- app.scene.envAtlas = assets.hdr.resource;
149
- }
150
-
151
  modelEntity = new pc.Entity('model');
152
  modelEntity.addComponent('gsplat', { asset: assets.model });
153
  modelEntity.setLocalPosition(modelX, modelY, modelZ);
@@ -156,7 +143,8 @@ export async function initializeViewer(config, instanceId) {
156
  app.root.addChild(modelEntity);
157
 
158
  cameraEntity = new pc.Entity('camera');
159
- cameraEntity.addComponent('camera', { clearColor: new pc.Color(0.2, 0.2, 0.2, 1) });
 
160
  cameraEntity.setPosition(chosenCameraX, chosenCameraY, chosenCameraZ);
161
  cameraEntity.lookAt(modelEntity.getPosition());
162
  cameraEntity.addComponent('script');
@@ -174,6 +162,7 @@ export async function initializeViewer(config, instanceId) {
174
 
175
  app.once('update', () => resetViewerCamera());
176
 
 
177
  try {
178
  if (config.tooltips_url) {
179
  import('./tooltips.js').then(tooltipsModule => {
 
80
  window.pc = pc;
81
  }
82
 
83
+ // Create app first
84
  const device = await pc.createGraphicsDevice(canvas, {
85
  deviceTypes: ["webgl2"],
86
  glslangUrl: "https://playcanvas.vercel.app/static/lib/glslang/glslang.js",
 
123
  window.addEventListener('resize', () => app.resizeCanvas(viewerContainer.clientWidth, viewerContainer.clientHeight));
124
  app.on('destroy', () => resizeObserver.disconnect());
125
 
126
+ // Assets after app exists
127
  const assets = {
128
  model: new pc.Asset('gsplat', 'gsplat', { url: plyUrl }),
129
  orbit: new pc.Asset('script', 'script', { url: "https://mikafil-viewer-gs.static.hf.space/orbit-camera.js" }),
 
 
 
 
 
130
  };
131
+ for (const key in assets) app.assets.add(assets[key]);
 
 
 
132
 
133
  const loader = new pc.AssetListLoader(Object.values(assets), app.assets);
134
  loader.load(() => {
135
  app.start();
136
  progressDialog.style.display = 'none';
137
 
 
 
 
 
 
138
  modelEntity = new pc.Entity('model');
139
  modelEntity.addComponent('gsplat', { asset: assets.model });
140
  modelEntity.setLocalPosition(modelX, modelY, modelZ);
 
143
  app.root.addChild(modelEntity);
144
 
145
  cameraEntity = new pc.Entity('camera');
146
+ // --- PURE WHITE BACKGROUND ---
147
+ cameraEntity.addComponent('camera', { clearColor: new pc.Color(1, 1, 1, 1) }); // White RGBA
148
  cameraEntity.setPosition(chosenCameraX, chosenCameraY, chosenCameraZ);
149
  cameraEntity.lookAt(modelEntity.getPosition());
150
  cameraEntity.addComponent('script');
 
162
 
163
  app.once('update', () => resetViewerCamera());
164
 
165
+ // Tooltips supported if tooltips_url set
166
  try {
167
  if (config.tooltips_url) {
168
  import('./tooltips.js').then(tooltipsModule => {