1

私は非常に基本的なフレーム シーンで遊んでいます。実行時にカメラの位置を取得するための情報を探しています。コンポーネントと three.js コードを使用する必要がありますか?

どうすればできますか?

4

2 に答える 2

1

まず、カメラ エンティティを取得します ( https://aframe.io/docs/core/entity.html#Retrifying-an-Entity )。カメラ エンティティには、cameraコンポーネントが HTML 属性として添付されます。

document.querySelector('[camera]')またdocument.querySelector('a-scene').camera.el

次に、 を使用getAttributeして位置をつかみます。これは {X, Y, Z} オブジェクトを返します。

document.querySelector('[camera]').getAttribute('position')

カメラがその位置を更新するたびに通知を受けるには、componentchangedイベント ( https://aframe.io/docs/core/entity.html#Listening-for-Component-Changes )を使用できます。

document.querySelector('[camera]').addEventListener('componentchanged', function (evt) {
  if (evt.detail.name === 'position') {
    console.log('Camera position went from', evt.detail.oldData, 'to', evt.detail.newData);
  }
});
于 2016-03-29T20:15:47.690 に答える