Update viewer_ar_ios.js
Browse files- viewer_ar_ios.js +45 -9
viewer_ar_ios.js
CHANGED
|
@@ -379,7 +379,7 @@
|
|
| 379 |
|
| 380 |
// Mode mur / sol
|
| 381 |
var wallMode = !PLACE_ON_FLOOR;
|
| 382 |
-
var wallBaseRot = new pc.Quat(); // orientation de base alignée
|
| 383 |
var wallAngleDeg = 0; // angle autour de l’axe local Y
|
| 384 |
|
| 385 |
// Ombre blob (uniquement pour le sol)
|
|
@@ -450,13 +450,13 @@
|
|
| 450 |
rotVal.textContent = String(Math.round(angleDeg)) + "°";
|
| 451 |
}
|
| 452 |
|
| 453 |
-
// Rotation murale : angle autour de l’axe local Y (
|
| 454 |
function setWallRotationFromSlider(angleDeg) {
|
| 455 |
wallAngleDeg = angleDeg;
|
| 456 |
var qLocal = new pc.Quat();
|
| 457 |
-
qLocal.setFromAxisAngle(pc.Vec3
|
| 458 |
var q = new pc.Quat();
|
| 459 |
-
//
|
| 460 |
q.mul2(wallBaseRot, qLocal);
|
| 461 |
modelRoot.setRotation(q);
|
| 462 |
}
|
|
@@ -626,11 +626,47 @@
|
|
| 626 |
applySliderRotation(y0);
|
| 627 |
} else {
|
| 628 |
// --- MODE MUR ---
|
| 629 |
-
//
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 634 |
}
|
| 635 |
|
| 636 |
placedOnce = true;
|
|
|
|
| 379 |
|
| 380 |
// Mode mur / sol
|
| 381 |
var wallMode = !PLACE_ON_FLOOR;
|
| 382 |
+
var wallBaseRot = new pc.Quat(); // orientation de base alignée à la normale du mur
|
| 383 |
var wallAngleDeg = 0; // angle autour de l’axe local Y
|
| 384 |
|
| 385 |
// Ombre blob (uniquement pour le sol)
|
|
|
|
| 450 |
rotVal.textContent = String(Math.round(angleDeg)) + "°";
|
| 451 |
}
|
| 452 |
|
| 453 |
+
// Rotation murale : angle autour de l’axe local Y (pointe ↔ base)
|
| 454 |
function setWallRotationFromSlider(angleDeg) {
|
| 455 |
wallAngleDeg = angleDeg;
|
| 456 |
var qLocal = new pc.Quat();
|
| 457 |
+
qLocal.setFromAxisAngle(new pc.Vec3(0, 1, 0), angleDeg);
|
| 458 |
var q = new pc.Quat();
|
| 459 |
+
// finale : base * rotation_locale_Y
|
| 460 |
q.mul2(wallBaseRot, qLocal);
|
| 461 |
modelRoot.setRotation(q);
|
| 462 |
}
|
|
|
|
| 626 |
applySliderRotation(y0);
|
| 627 |
} else {
|
| 628 |
// --- MODE MUR ---
|
| 629 |
+
// 1) normale du plan en monde
|
| 630 |
+
var planeNormal = new pc.Vec3();
|
| 631 |
+
rot.transformVector(new pc.Vec3(0, 1, 0), planeNormal);
|
| 632 |
+
planeNormal.normalize();
|
| 633 |
+
|
| 634 |
+
// 2) on force la normale à pointer vers la caméra
|
| 635 |
+
var camPos = camera.getPosition();
|
| 636 |
+
var toCam = new pc.Vec3();
|
| 637 |
+
toCam.sub2(camPos, pos);
|
| 638 |
+
toCam.normalize();
|
| 639 |
+
if (planeNormal.dot(toCam) < 0) {
|
| 640 |
+
planeNormal.scale(-1); // on flip la normale pour qu’elle sorte vers la caméra
|
| 641 |
+
}
|
| 642 |
+
|
| 643 |
+
// 3) construire un repère orthonormé : Y = normale, X/Z quelconques mais ⟂
|
| 644 |
+
var ref = new pc.Vec3(0, 1, 0);
|
| 645 |
+
if (Math.abs(planeNormal.y) > 0.9) {
|
| 646 |
+
ref.set(1, 0, 0); // si la normale est trop verticale, on change le ref
|
| 647 |
+
}
|
| 648 |
+
|
| 649 |
+
var xAxis = new pc.Vec3();
|
| 650 |
+
xAxis.cross(ref, planeNormal).normalize(); // X ⟂ normale
|
| 651 |
+
var zAxis = new pc.Vec3();
|
| 652 |
+
zAxis.cross(xAxis, planeNormal).normalize(); // Z = X × Y
|
| 653 |
+
|
| 654 |
+
// 4) construire la matrice (colonnes = X, Y, Z) puis le quaternion
|
| 655 |
+
var m = new pc.Mat4();
|
| 656 |
+
m.set(
|
| 657 |
+
xAxis.x, planeNormal.x, zAxis.x, 0,
|
| 658 |
+
xAxis.y, planeNormal.y, zAxis.y, 0,
|
| 659 |
+
xAxis.z, planeNormal.z, zAxis.z, 0,
|
| 660 |
+
0, 0, 0, 1
|
| 661 |
+
);
|
| 662 |
+
var baseQ = new pc.Quat();
|
| 663 |
+
baseQ.setFromMat4(m);
|
| 664 |
+
|
| 665 |
+
modelRoot.setRotation(baseQ);
|
| 666 |
+
wallBaseRot.copy(baseQ);
|
| 667 |
+
|
| 668 |
+
// angle initial = 0 → pointe toujours "vers dehors"
|
| 669 |
+
applySliderRotation(0);
|
| 670 |
}
|
| 671 |
|
| 672 |
placedOnce = true;
|