MikaFil commited on
Commit
857088f
·
verified ·
1 Parent(s): 041fcae

Update viewer_ar.js

Browse files
Files changed (1) hide show
  1. viewer_ar.js +36 -20
viewer_ar.js CHANGED
@@ -223,19 +223,19 @@
223
  var BLOB_SIZE = 0.7;
224
  var BLOB_OFFSET_Y = 0.005;
225
 
226
- function makeBlobTexture(app, size) {
227
- size = size || 256;
228
- var cvs = document.createElement('canvas');
229
  cvs.width = cvs.height = size;
230
- var ctx = cvs.getContext('2d');
231
- var r = size * 0.45;
232
- var grd = ctx.createRadialGradient(size / 2, size / 2, r * 0.2, size / 2, size / 2, r);
233
- grd.addColorStop(0, 'rgba(0,0,0,0.35)');
234
- grd.addColorStop(1, 'rgba(0,0,0,0.0)');
 
235
  ctx.fillStyle = grd;
236
  ctx.fillRect(0, 0, size, size);
237
-
238
- var tex = new pc.Texture(app.graphicsDevice, {
239
  width: size,
240
  height: size,
241
  format: pc.PIXELFORMAT_R8_G8_B8_A8,
@@ -247,28 +247,44 @@
247
  return tex;
248
  }
249
 
 
250
  function createBlobShadowAt(pos, rot) {
251
- var tex = makeBlobTexture(app, 256);
252
- var blobMat = new pc.StandardMaterial();
253
- blobMat.diffuse = new pc.Color(0, 0, 0);
 
 
 
 
254
  blobMat.opacity = 1.0;
255
- blobMat.blendType = pc.BLEND_PREMULTIPLIED;
 
 
 
 
 
 
 
256
  blobMat.depthWrite = false;
257
- blobMat.diffuseMap = tex;
 
 
258
  blobMat.update();
259
-
260
- var e = new pc.Entity("BlobShadow");
261
  e.addComponent("render", { type: "plane", castShadows: false, receiveShadows: false });
262
  e.render.material = blobMat;
263
-
 
264
  e.setPosition(pos.x, pos.y + BLOB_OFFSET_Y, pos.z);
265
- e.setRotation(rot);
266
  e.setLocalScale(BLOB_SIZE, 1, BLOB_SIZE);
267
-
268
  app.root.addChild(e);
269
  return e;
270
  }
271
 
 
272
  // Euler base
273
  var baseEulerX = 0, baseEulerZ = 0;
274
 
 
223
  var BLOB_SIZE = 0.7;
224
  var BLOB_OFFSET_Y = 0.005;
225
 
226
+ function makeBlobTexture(app, size = 256) {
227
+ const cvs = document.createElement('canvas');
 
228
  cvs.width = cvs.height = size;
229
+ const ctx = cvs.getContext('2d');
230
+
231
+ const r = size * 0.45;
232
+ const grd = ctx.createRadialGradient(size/2, size/2, r*0.2, size/2, size/2, r);
233
+ grd.addColorStop(0, 'rgba(0,0,0,0.35)'); // centre sombre
234
+ grd.addColorStop(1, 'rgba(0,0,0,0.0)'); // bords transparents
235
  ctx.fillStyle = grd;
236
  ctx.fillRect(0, 0, size, size);
237
+
238
+ const tex = new pc.Texture(app.graphicsDevice, {
239
  width: size,
240
  height: size,
241
  format: pc.PIXELFORMAT_R8_G8_B8_A8,
 
247
  return tex;
248
  }
249
 
250
+
251
  function createBlobShadowAt(pos, rot) {
252
+ const tex = makeBlobTexture(app, 256);
253
+
254
+ const blobMat = new pc.StandardMaterial();
255
+ // Couleur noire (ombre)
256
+ blobMat.diffuse.set(0, 0, 0);
257
+
258
+ // >>> CLÉ : utiliser l’alpha de la texture pour la transparence
259
  blobMat.opacity = 1.0;
260
+ blobMat.opacityMap = tex; // on se sert du canal A
261
+ blobMat.opacityMapChannel = 'a';
262
+
263
+ // Pas besoin d’éclairage sur une “ombre peinte”
264
+ blobMat.useLighting = false;
265
+
266
+ // Mélange standard + pas d’écriture dans le depth (évite de masquer le modèle)
267
+ blobMat.blendType = pc.BLEND_NORMAL; // (si halos bizarres, essayer PREMULTIPLIED)
268
  blobMat.depthWrite = false;
269
+
270
+ // Optionnel: adoucir un poil le tri/transpa
271
+ blobMat.alphaTest = 0; // on ne découpe pas “dur”, on laisse le gradient
272
  blobMat.update();
273
+
274
+ const e = new pc.Entity("BlobShadow");
275
  e.addComponent("render", { type: "plane", castShadows: false, receiveShadows: false });
276
  e.render.material = blobMat;
277
+
278
+ // Place légèrement au-dessus du sol pour éviter le z-fighting
279
  e.setPosition(pos.x, pos.y + BLOB_OFFSET_Y, pos.z);
280
+ e.setRotation(rot); // suit le plan horizontal détecté
281
  e.setLocalScale(BLOB_SIZE, 1, BLOB_SIZE);
282
+
283
  app.root.addChild(e);
284
  return e;
285
  }
286
 
287
+
288
  // Euler base
289
  var baseEulerX = 0, baseEulerZ = 0;
290