Skip to content

Commit e536080

Browse files
Enhance PlacementBox with stable interaction and improved visuals (#5082)
* enhance placementbox creation * remove flickering * address performance comments * fix the sclaing damper
1 parent 914fdaf commit e536080

File tree

2 files changed

+395
-66
lines changed

2 files changed

+395
-66
lines changed

packages/model-viewer/src/three-components/ARRenderer.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,18 @@ export class ARRenderer extends EventDispatcher<
328328
this.yawDamper.setDecayTime(DECAY);
329329
this.pitchDamper.setDecayTime(DECAY);
330330
this.rollDamper.setDecayTime(DECAY);
331+
this.scaleDamper.setDecayTime(DECAY);
331332
}
332333

333334
this.currentSession = currentSession;
334335
this.placementBox =
335336
new PlacementBox(scene, this.placeOnWall ? 'back' : 'bottom');
337+
338+
// Set screen space mode for proper positioning
339+
if (this.placementBox) {
340+
this.placementBox.setScreenSpaceMode(this.xrMode === XRMode.SCREEN_SPACE);
341+
}
342+
336343
this.placementComplete = false;
337344

338345
if (this.xrMode !== XRMode.SCREEN_SPACE) {
@@ -561,9 +568,11 @@ export class ARRenderer extends EventDispatcher<
561568

562569
onUpdateScene = () => {
563570
if (this.placementBox != null && this.isPresenting) {
564-
this.placementBox!.dispose();
565-
this.placementBox = new PlacementBox(
566-
this.presentedScene!, this.placeOnWall ? 'back' : 'bottom');
571+
// Update the existing placement box with new model dimensions instead of recreating
572+
this.placementBox!.updateFromModelChanges();
573+
574+
// Ensure screen space mode is maintained
575+
this.placementBox!.setScreenSpaceMode(this.xrMode === XRMode.SCREEN_SPACE);
567576
}
568577
if (this.xrMode !== XRMode.SCREEN_SPACE) {
569578
if (this.menuPanel) {
@@ -1162,7 +1171,17 @@ export class ARRenderer extends EventDispatcher<
11621171
}
11631172

11641173
private updatePlacementBoxOpacity(box: PlacementBox, delta: number) {
1165-
box.updateOpacity(delta);
1174+
// Use the new enhanced update method that includes distance scaling and visual state
1175+
const camera = this.presentedScene!.getCamera();
1176+
box.update(delta, camera.position);
1177+
1178+
// Update interaction state based on hover
1179+
const over1 = this.hover(this.xrController1!);
1180+
const over2 = this.hover(this.xrController2!);
1181+
const isHovered = (over1 || over2) && !this.isTwoHandInteraction;
1182+
1183+
// Set interaction state for visual feedback
1184+
box.setInteractionState(this.isTranslating || this.isRotating, isHovered);
11661185
}
11671186

11681187
private updateTwoHandInteractionState() {
@@ -1186,7 +1205,13 @@ export class ARRenderer extends EventDispatcher<
11861205
private updateXRControllerHover() {
11871206
const over1 = this.hover(this.xrController1!);
11881207
const over2 = this.hover(this.xrController2!);
1189-
this.placementBox!.show = (over1 || over2) && !this.isTwoHandInteraction;
1208+
const isHovered = (over1 || over2) && !this.isTwoHandInteraction;
1209+
1210+
// Use the new interaction state system
1211+
if (this.placementBox) {
1212+
this.placementBox.setInteractionState(this.isTranslating || this.isRotating, isHovered);
1213+
this.placementBox.show = isHovered;
1214+
}
11901215
}
11911216

11921217

0 commit comments

Comments
 (0)