私は非常に基本的なフレーム シーンで遊んでいます。実行時にカメラの位置を取得するための情報を探しています。コンポーネントと three.js コードを使用する必要がありますか?
どうすればできますか?
まず、カメラ エンティティを取得します ( 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);
}
});