MikaFil commited on
Commit
fd176ec
·
verified ·
1 Parent(s): cb1ca43

Update viewer.js

Browse files
Files changed (1) hide show
  1. viewer.js +20 -91
viewer.js CHANGED
@@ -173,90 +173,44 @@ export async function initializeViewer(config, instanceId) {
173
  app.start();
174
  if (progressDialog) progressDialog.style.display = 'none';
175
 
176
- // Reorder depth layer for transmission
177
- const depthLayer = app.scene.layers.getLayerById(pc.LAYERID_DEPTH);
178
- app.scene.layers.remove(depthLayer);
179
- app.scene.layers.insertOpaque(depthLayer, 2);
180
-
181
- //create texture and render target foro rendering into, including depth buffer
182
  const texture = new pc.Texture(app.graphicsDevice, {
183
  width: 512,
184
  height: 256,
185
- format: pc.PIXELFORMAT_R8_G8_B8_A8,
186
  mipmaps: true,
187
  addressU: pc.ADDRESS_CLAMP_TO_EDGE,
188
- addressV: pc.ADDRESS_CLAMP_TO_EDGE,
189
  });
190
  const renderTarget = new pc.RenderTarget({
191
- name :'RT',
192
  colorBuffer: texture,
193
  depth: true,
194
  flipY: !app.graphicsDevice.isWebGPU,
195
  samples: 2
196
  });
197
 
198
- const excludeLayer = new pc.Layer({name : 'Excluded'});
199
  app.scene.layers.insert(excludeLayer, 1);
200
 
201
- const tubeLayer = new pc.Layer({name : 'TubeLayer'});
202
- app.scene.layers.insert(tubeLayer, 1);
203
-
204
- //get existing layers
205
  const worldLayer = app.scene.layers.getLayerByName('World');
206
  const skyboxLayer = app.scene.layers.getLayerByName('Skybox');
207
  const uiLayer = app.scene.layers.getLayerByName('UI');
208
 
 
 
 
 
 
209
  // Instantiate GLB entities
210
  modelEntity = assets.model.resource.instantiateRenderEntity();
211
  tubeEntity = assets.tube.resource.instantiateRenderEntity();
212
  filtreEntity = assets.filtre.resource.instantiateRenderEntity();
213
-
214
  app.root.addChild(modelEntity);
215
  app.root.addChild(tubeEntity);
216
  app.root.addChild(filtreEntity);
217
 
218
-
219
-
220
-
221
-
222
-
223
-
224
- //precise dans quel layer les tubes sont visibles
225
- traverse(tubeEntity, node => {
226
- if(node.render && node.render.meshInstances){
227
- for(let mi of node.render.meshInstances){
228
- mi.layer = tubeLayer.id;
229
- }
230
- }
231
- });
232
-
233
- //precise dans quel layer les filtres sont visibles
234
- traverse(filtreEntity, node => {
235
- if(node.render && node.render.meshInstances){
236
- for(let mi of node.render.meshInstances){
237
- mi.layer = tubeLayer.id;
238
- }
239
- }
240
- });
241
-
242
-
243
- //test avec modele separe du reste
244
- const modelLayer = new pc.Layer({name : 'ModelLayer'});
245
- app.scene.layers.insert(tubeLayer, 1);
246
- traverse(modelEntity, node => {
247
- if(node.render && node.render.meshInstances){
248
- for(let mi of node.render.meshInstances){
249
- mi.layer = modelLayer.id;
250
- }
251
- }
252
- });
253
-
254
-
255
-
256
-
257
-
258
-
259
-
260
  // ----- Materials Setup -----
261
  // Transparent material (main model)
262
  matTransparent = new pc.StandardMaterial();
@@ -344,11 +298,9 @@ export async function initializeViewer(config, instanceId) {
344
  filtreEntity.setLocalEulerAngles(modelRotationX, modelRotationY, modelRotationZ);
345
 
346
  // ----- Camera + Orbit Controls -----
347
- //test : si je mets pas le skyboxLayer la, j'ai pas besoin de l'enlever apres
348
  cameraEntity = new pc.Entity('camera');
349
  cameraEntity.addComponent('camera', {
350
  clearColor: new pc.Color(0.8, 0.8, 0.8, 1),
351
- layers:[modelLayer.id, skyboxLayer.id, uiLayer.id],
352
  toneMapping: pc.TONEMAP_NEUTRAL
353
  });
354
  cameraEntity.setPosition(chosenCameraX, chosenCameraY, chosenCameraZ);
@@ -375,6 +327,7 @@ export async function initializeViewer(config, instanceId) {
375
  app.root.addChild(cameraEntity);
376
 
377
  // Remove Skybox layer from camera
 
378
  if (skyboxLayer) {
379
  const camLayers = cameraEntity.camera.layers.slice();
380
  const idx = camLayers.indexOf(skyboxLayer.id);
@@ -383,49 +336,25 @@ export async function initializeViewer(config, instanceId) {
383
  cameraEntity.camera.layers = camLayers;
384
  }
385
  }
386
-
387
- const textureCamera = new pc.Entity('TextureCamera');
388
- textureCamera.addComponent('camera', {
389
- layers: [tubeLayer.id],
390
- toneMapping: pc.TONEMAP_NEUTRAL,
391
-
392
- // set the priority of textureCamera to lower number than the priority of the main camera (which is at default 0)
393
- // to make it rendered first each frame
394
- priority: -1,
395
-
396
- // this camera renders into texture target
397
- renderTarget: renderTarget
398
- });
399
- cameraEntity.addChild(textureCamera);
400
-
401
  // ----- Camera-attached background plane -----
402
  const bgPlane = new pc.Entity("Plane");
403
- bgPlane.addComponent("model", {
404
- type: "plane",
405
- layers: excludeLayer
406
- });
407
-
408
  bgPlane.setLocalPosition(0, 0, -10);
409
  bgPlane.setLocalScale(11, 1, 5.5);
410
  bgPlane.setLocalEulerAngles(90, 0, 0);
411
  // Simple material for the banner
412
  const mat = new pc.StandardMaterial();
 
 
413
  mat.emissive = new pc.Color(1, 1, 1);
414
- mat.emissiveMap = texture;
 
415
  mat.useLighting = false;
416
  mat.update();
417
-
418
- traverse(bgPlane, node => {
419
- if (node.render && node.render.meshInstances) {
420
- for (let mi of node.render.meshInstances) {
421
- mi.material = mat;
422
- }
423
- }
424
- });
425
  cameraEntity.addChild(bgPlane);
426
-
427
-
428
-
429
  // ----- Lighting -----
430
  const light = new pc.Entity("mainLight");
431
  light.addComponent('light', {
 
173
  app.start();
174
  if (progressDialog) progressDialog.style.display = 'none';
175
 
 
 
 
 
 
 
176
  const texture = new pc.Texture(app.graphicsDevice, {
177
  width: 512,
178
  height: 256,
179
+ format: pc.PIXELFORMAT_SRGBA8,
180
  mipmaps: true,
181
  addressU: pc.ADDRESS_CLAMP_TO_EDGE,
182
+ addressV: pc.ADDRESS_CLAMP_TO_EDGE
183
  });
184
  const renderTarget = new pc.RenderTarget({
185
+ name: 'RT',
186
  colorBuffer: texture,
187
  depth: true,
188
  flipY: !app.graphicsDevice.isWebGPU,
189
  samples: 2
190
  });
191
 
192
+ const excludeLayer = new pc.Layer({name: 'Excluded'});
193
  app.scene.layers.insert(excludeLayer, 1);
194
 
195
+ // get existing layers
 
 
 
196
  const worldLayer = app.scene.layers.getLayerByName('World');
197
  const skyboxLayer = app.scene.layers.getLayerByName('Skybox');
198
  const uiLayer = app.scene.layers.getLayerByName('UI');
199
 
200
+ // Reorder depth layer for transmission
201
+ const depthLayer = app.scene.layers.getLayerById(pc.LAYERID_DEPTH);
202
+ app.scene.layers.remove(depthLayer);
203
+ app.scene.layers.insertOpaque(depthLayer, 2);
204
+
205
  // Instantiate GLB entities
206
  modelEntity = assets.model.resource.instantiateRenderEntity();
207
  tubeEntity = assets.tube.resource.instantiateRenderEntity();
208
  filtreEntity = assets.filtre.resource.instantiateRenderEntity();
209
+
210
  app.root.addChild(modelEntity);
211
  app.root.addChild(tubeEntity);
212
  app.root.addChild(filtreEntity);
213
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  // ----- Materials Setup -----
215
  // Transparent material (main model)
216
  matTransparent = new pc.StandardMaterial();
 
298
  filtreEntity.setLocalEulerAngles(modelRotationX, modelRotationY, modelRotationZ);
299
 
300
  // ----- Camera + Orbit Controls -----
 
301
  cameraEntity = new pc.Entity('camera');
302
  cameraEntity.addComponent('camera', {
303
  clearColor: new pc.Color(0.8, 0.8, 0.8, 1),
 
304
  toneMapping: pc.TONEMAP_NEUTRAL
305
  });
306
  cameraEntity.setPosition(chosenCameraX, chosenCameraY, chosenCameraZ);
 
327
  app.root.addChild(cameraEntity);
328
 
329
  // Remove Skybox layer from camera
330
+ //const skyboxLayer = app.scene.layers.getLayerByName("Skybox");
331
  if (skyboxLayer) {
332
  const camLayers = cameraEntity.camera.layers.slice();
333
  const idx = camLayers.indexOf(skyboxLayer.id);
 
336
  cameraEntity.camera.layers = camLayers;
337
  }
338
  }
339
+ /*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
340
  // ----- Camera-attached background plane -----
341
  const bgPlane = new pc.Entity("Plane");
342
+ bgPlane.addComponent("model", { type: "plane" });
 
 
 
 
343
  bgPlane.setLocalPosition(0, 0, -10);
344
  bgPlane.setLocalScale(11, 1, 5.5);
345
  bgPlane.setLocalEulerAngles(90, 0, 0);
346
  // Simple material for the banner
347
  const mat = new pc.StandardMaterial();
348
+ mat.diffuse = new pc.Color(1, 1, 1);
349
+ mat.diffuseMap = bgTex;
350
  mat.emissive = new pc.Color(1, 1, 1);
351
+ mat.emissiveMap = bgTex;
352
+ mat.emissiveIntensity = 1;
353
  mat.useLighting = false;
354
  mat.update();
355
+ bgPlane.model.material = mat;
 
 
 
 
 
 
 
356
  cameraEntity.addChild(bgPlane);
357
+ */
 
 
358
  // ----- Lighting -----
359
  const light = new pc.Entity("mainLight");
360
  light.addComponent('light', {