MikaFil commited on
Commit
82241f6
·
verified ·
1 Parent(s): 2cb73f7

Update viewer_ar_ios.js

Browse files
Files changed (1) hide show
  1. viewer_ar_ios.js +24 -13
viewer_ar_ios.js CHANGED
@@ -3,7 +3,7 @@
3
  - sol = true → plans horizontaux (sol) + rotation autour de l’axe local Y (haut)
4
  - sol = false → plans verticaux (mur) + rotation autour de l’axe local Y aligné à la normale du mur
5
  - iOS : AR Quick Look (USDZ) — l’utilisateur place l’objet sur sol/mur
6
- - Android/Desktop : WebXR AR + bouton "Lancer l’AR" + slider de rotation + ombre blob (sol uniquement)
7
  */
8
 
9
  (function () {
@@ -467,9 +467,9 @@
467
  } else {
468
  wallAngleDeg = y;
469
  var qLocal = new pc.Quat();
470
- qLocal.setFromAxisAngle(new pc.Vec3(0, 1, 0), y); // rotation locale autour de Y
471
  var qFinal = new pc.Quat();
472
- qFinal.mul2(wallBaseRot, qLocal); // base (mur) puis rotation locale Y
473
  modelRoot.setRotation(qFinal);
474
  }
475
 
@@ -596,7 +596,7 @@
596
 
597
  app.keyboard.on("keydown", function (evt) { if (evt.key === pc.KEY_ESCAPE && app.xr.active) app.xr.end(); });
598
 
599
- // Hit-test (sol vs mur)
600
  app.xr.hitTest.on("available", function () {
601
  app.xr.hitTest.start({
602
  entityTypes: [pc.XRTRACKABLE_POINT, pc.XRTRACKABLE_PLANE],
@@ -616,25 +616,22 @@
616
  if (!wallMode) {
617
  // --- MODE SOL ---
618
  blob = createBlobShadowAt(pos, rot);
619
-
620
  var e = new pc.Vec3();
621
  rot.getEulerAngles(e);
622
  var y0 = ((e.y % 360) + 360) % 360;
623
  applyRotationY(y0);
624
  } else {
625
- // --- MODE MUR ---
626
- // on aligne directement l’objet sur la rotation du hit-test
627
- // (axe local Y du modèle = normale du mur)
628
- modelRoot.setRotation(rot);
629
  wallBaseRot.copy(rot);
630
- applyRotationY(0); // angle initial = 0
631
  }
632
 
633
  placedOnce = true;
634
  rotInput.disabled = false;
635
  message(
636
  wallMode
637
- ? "Objet placé contre le mur. Glissez pour déplacer sur le mur, tournez-le avec le slider →"
638
  : "Objet placé. Glissez pour déplacer, tournez-le avec le slider →"
639
  );
640
  }
@@ -643,7 +640,7 @@
643
  });
644
  });
645
 
646
- // Drag XR continu
647
  var isDragging = false;
648
  app.xr.input.on("add", function (inputSource) {
649
  inputSource.on("selectstart", function () {
@@ -659,8 +656,22 @@
659
  transientSource.on("result", function (pos, rot) {
660
  if (!isDragging) return;
661
  if (!planeMatchesMode(rot)) return;
 
662
  modelRoot.setPosition(pos);
663
- if (!wallMode) updateBlobPositionUnder(pos, rot);
 
 
 
 
 
 
 
 
 
 
 
 
 
664
  });
665
 
666
  transientSource.once("remove", function () { isDragging = false; });
 
3
  - sol = true → plans horizontaux (sol) + rotation autour de l’axe local Y (haut)
4
  - sol = false → plans verticaux (mur) + rotation autour de l’axe local Y aligné à la normale du mur
5
  - iOS : AR Quick Look (USDZ) — l’utilisateur place l’objet sur sol/mur
6
+ - Android/Desktop : WebXR AR + bouton "Lancer l’AR" + slider de rotation
7
  */
8
 
9
  (function () {
 
467
  } else {
468
  wallAngleDeg = y;
469
  var qLocal = new pc.Quat();
470
+ qLocal.setFromAxisAngle(pc.Vec3.UP, y); // rotation locale autour de Y
471
  var qFinal = new pc.Quat();
472
+ qFinal.mul2(wallBaseRot, qLocal); // base (mur) puis rotation locale Y
473
  modelRoot.setRotation(qFinal);
474
  }
475
 
 
596
 
597
  app.keyboard.on("keydown", function (evt) { if (evt.key === pc.KEY_ESCAPE && app.xr.active) app.xr.end(); });
598
 
599
+ // Hit-test principal (pour le reticle + premier placement)
600
  app.xr.hitTest.on("available", function () {
601
  app.xr.hitTest.start({
602
  entityTypes: [pc.XRTRACKABLE_POINT, pc.XRTRACKABLE_PLANE],
 
616
  if (!wallMode) {
617
  // --- MODE SOL ---
618
  blob = createBlobShadowAt(pos, rot);
 
619
  var e = new pc.Vec3();
620
  rot.getEulerAngles(e);
621
  var y0 = ((e.y % 360) + 360) % 360;
622
  applyRotationY(y0);
623
  } else {
624
+ // --- MODE MUR (première pose) ---
625
+ modelRoot.setRotation(rot); // Y local = normale du mur
 
 
626
  wallBaseRot.copy(rot);
627
+ applyRotationY(0); // angle initial = 0
628
  }
629
 
630
  placedOnce = true;
631
  rotInput.disabled = false;
632
  message(
633
  wallMode
634
+ ? "Objet placé contre le mur. Glissez pour déplacer sur un autre mur, tournez-le avec le slider →"
635
  : "Objet placé. Glissez pour déplacer, tournez-le avec le slider →"
636
  );
637
  }
 
640
  });
641
  });
642
 
643
+ // Drag XR continu (déplacement après placement)
644
  var isDragging = false;
645
  app.xr.input.on("add", function (inputSource) {
646
  inputSource.on("selectstart", function () {
 
656
  transientSource.on("result", function (pos, rot) {
657
  if (!isDragging) return;
658
  if (!planeMatchesMode(rot)) return;
659
+
660
  modelRoot.setPosition(pos);
661
+
662
+ if (!wallMode) {
663
+ // sol : on ne change que la position, l'orientation reste pilotée par le slider
664
+ updateBlobPositionUnder(pos, rot);
665
+ } else {
666
+ // mur : à CHAQUE déplacement on ré-aligne la base sur le plan courant,
667
+ // puis on ré-applique l'angle du slider autour de Y
668
+ wallBaseRot.copy(rot); // Y local = normale du mur courant
669
+ var qLocal = new pc.Quat();
670
+ qLocal.setFromAxisAngle(pc.Vec3.UP, wallAngleDeg);
671
+ var qFinal = new pc.Quat();
672
+ qFinal.mul2(wallBaseRot, qLocal);
673
+ modelRoot.setRotation(qFinal);
674
+ }
675
  });
676
 
677
  transientSource.once("remove", function () { isDragging = false; });