Skip to content

Commit db63302

Browse files
committed
Fix hit-test logic on model-viewer example
1 parent 4874a62 commit db63302

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

examples/showcase/model-viewer/model-viewer.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ AFRAME.registerComponent('model-viewer', {
3535

3636
this.onOrientationChange = this.onOrientationChange.bind(this);
3737

38+
this.initCameraRig();
3839
this.initEntities();
3940
this.initBackground();
40-
this.initCameraRig();
4141

4242
if (this.data.uploadUIEnabled) { this.initUploadInput(); }
4343

@@ -212,6 +212,8 @@ AFRAME.registerComponent('model-viewer', {
212212
intensity: 1
213213
});
214214

215+
modelPivotEl.id = 'modelPivot';
216+
215217
this.el.appendChild(sceneLightEl);
216218

217219
reticleEl.setAttribute('gltf-model', '#reticle');
@@ -258,6 +260,7 @@ AFRAME.registerComponent('model-viewer', {
258260

259261
this.containerEl.appendChild(titleEl);
260262

263+
lightEl.id = 'light';
261264
lightEl.setAttribute('position', '-2 4 2');
262265
lightEl.setAttribute('light', {
263266
type: 'directional',
@@ -276,6 +279,7 @@ AFRAME.registerComponent('model-viewer', {
276279
this.containerEl.appendChild(modelPivotEl);
277280

278281
this.el.appendChild(containerEl);
282+
this.el.appendChild(reticleEl);
279283
},
280284

281285
onThumbstickMoved: function (evt) {
@@ -354,15 +358,20 @@ AFRAME.registerComponent('model-viewer', {
354358
this.cameraRigPosition = cameraRigEl.object3D.position.clone();
355359
this.cameraRigRotation = cameraRigEl.object3D.rotation.clone();
356360

357-
cameraRigEl.object3D.rotation.set(0, 0, 0);
358-
cameraRigEl.object3D.position.set(0, 0, 2);
361+
if (!this.el.sceneEl.is('ar-mode')) {
362+
cameraRigEl.object3D.position.set(0, 0, 2);
363+
} else {
364+
cameraRigEl.object3D.position.set(0, 0, 0);
365+
}
359366
},
360367

361368
onExitVR: function () {
362369
var cameraRigEl = this.cameraRigEl;
363370

364371
cameraRigEl.object3D.position.copy(this.cameraRigPosition);
365372
cameraRigEl.object3D.rotation.copy(this.cameraRigRotation);
373+
374+
cameraRigEl.object3D.rotation.set(0, 0, 0);
366375
},
367376

368377
onTouchMove: function (evt) {

0 commit comments

Comments
 (0)