Update viewer_ar_ios.js
Browse files- viewer_ar_ios.js +18 -27
viewer_ar_ios.js
CHANGED
|
@@ -292,7 +292,7 @@
|
|
| 292 |
if (USDZ_URL) {
|
| 293 |
ensureQuickLookButton(USDZ_URL);
|
| 294 |
message(
|
| 295 |
-
"Modèle chargé.
|
| 296 |
(PLACE_ON_FLOOR ? "sur le sol." : "sur un mur (faites-le glisser sur la surface).")
|
| 297 |
);
|
| 298 |
} else {
|
|
@@ -379,7 +379,7 @@
|
|
| 379 |
|
| 380 |
// Mode mur / sol
|
| 381 |
var wallMode = !PLACE_ON_FLOOR;
|
| 382 |
-
var wallAxis = new pc.Vec3(1, 0, 0); // axe de rotation =
|
| 383 |
var wallBaseRot = new pc.Quat();
|
| 384 |
var wallAngleDeg = 0;
|
| 385 |
|
|
@@ -451,13 +451,13 @@
|
|
| 451 |
rotVal.textContent = String(Math.round(angleDeg)) + "°";
|
| 452 |
}
|
| 453 |
|
| 454 |
-
// Rotation murale : angle autour de wallAxis (normale
|
| 455 |
function setWallRotationFromSlider(angleDeg) {
|
| 456 |
wallAngleDeg = angleDeg;
|
| 457 |
var qExtra = new pc.Quat();
|
| 458 |
-
qExtra.setFromAxisAngle(wallAxis, angleDeg);
|
| 459 |
var q = new pc.Quat();
|
| 460 |
-
q.mul2(qExtra, wallBaseRot); // rotation autour de l’axe
|
| 461 |
modelRoot.setRotation(q);
|
| 462 |
}
|
| 463 |
|
|
@@ -626,31 +626,22 @@
|
|
| 626 |
applySliderRotation(y0);
|
| 627 |
} else {
|
| 628 |
// --- MODE MUR ---
|
| 629 |
-
// 1) normale du plan
|
| 630 |
var upLocal = new pc.Vec3(0, 1, 0);
|
| 631 |
-
var
|
| 632 |
-
rot.transformVector(upLocal,
|
| 633 |
|
| 634 |
-
// 2)
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
normalWorld.set(0, 0, 1);
|
| 638 |
-
}
|
| 639 |
-
normalWorld.normalize();
|
| 640 |
-
|
| 641 |
-
// 3) orienter l’objet : forward ≈ normale, up ≈ vertical monde
|
| 642 |
-
var worldUp = new pc.Vec3(0, 1, 0);
|
| 643 |
-
var posCopy = pos.clone ? pos.clone() : new pc.Vec3(pos.x, pos.y, pos.z);
|
| 644 |
-
var target = posCopy.clone ? posCopy.clone() : new pc.Vec3(posCopy.x, posCopy.y, posCopy.z);
|
| 645 |
-
target.add(normalWorld); // regarder "vers" la normale
|
| 646 |
-
modelRoot.setPosition(pos);
|
| 647 |
-
modelRoot.lookAt(target, worldUp);
|
| 648 |
|
| 649 |
-
//
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
|
|
|
|
|
|
| 654 |
|
| 655 |
// angle initial = 0
|
| 656 |
applySliderRotation(0);
|
|
|
|
| 292 |
if (USDZ_URL) {
|
| 293 |
ensureQuickLookButton(USDZ_URL);
|
| 294 |
message(
|
| 295 |
+
"Modèle chargé. Appuyez sur « Lancer l’AR » puis placez-le " +
|
| 296 |
(PLACE_ON_FLOOR ? "sur le sol." : "sur un mur (faites-le glisser sur la surface).")
|
| 297 |
);
|
| 298 |
} else {
|
|
|
|
| 379 |
|
| 380 |
// Mode mur / sol
|
| 381 |
var wallMode = !PLACE_ON_FLOOR;
|
| 382 |
+
var wallAxis = new pc.Vec3(1, 0, 0); // axe de rotation = projection horizontale de la normale du mur
|
| 383 |
var wallBaseRot = new pc.Quat();
|
| 384 |
var wallAngleDeg = 0;
|
| 385 |
|
|
|
|
| 451 |
rotVal.textContent = String(Math.round(angleDeg)) + "°";
|
| 452 |
}
|
| 453 |
|
| 454 |
+
// Rotation murale : angle autour de wallAxis (normale projetée à l’horizontale)
|
| 455 |
function setWallRotationFromSlider(angleDeg) {
|
| 456 |
wallAngleDeg = angleDeg;
|
| 457 |
var qExtra = new pc.Quat();
|
| 458 |
+
qExtra.setFromAxisAngle(wallAxis, angleDeg); // angle en degrés dans PlayCanvas
|
| 459 |
var q = new pc.Quat();
|
| 460 |
+
q.mul2(qExtra, wallBaseRot); // rotation supplémentaire autour de l’axe (en espace monde)
|
| 461 |
modelRoot.setRotation(q);
|
| 462 |
}
|
| 463 |
|
|
|
|
| 626 |
applySliderRotation(y0);
|
| 627 |
} else {
|
| 628 |
// --- MODE MUR ---
|
| 629 |
+
// 1) normale complète du plan (en monde) = rot * (0,1,0)
|
| 630 |
var upLocal = new pc.Vec3(0, 1, 0);
|
| 631 |
+
var normalWorldFull = new pc.Vec3();
|
| 632 |
+
rot.transformVector(upLocal, normalWorldFull);
|
| 633 |
|
| 634 |
+
// 2) orienter l’objet exactement comme le plan (comme le cercle)
|
| 635 |
+
modelRoot.setRotation(rot);
|
| 636 |
+
wallBaseRot.copy(rot);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 637 |
|
| 638 |
+
// 3) axe de rotation = projection horizontale de la normale (perpendiculaire au mur, horizontale)
|
| 639 |
+
var axis = new pc.Vec3(normalWorldFull.x, 0, normalWorldFull.z);
|
| 640 |
+
if (axis.lengthSq() < 1e-4) {
|
| 641 |
+
axis.set(0, 0, 1);
|
| 642 |
+
}
|
| 643 |
+
axis.normalize();
|
| 644 |
+
wallAxis.copy(axis);
|
| 645 |
|
| 646 |
// angle initial = 0
|
| 647 |
applySliderRotation(0);
|