Closed tagahei closed 7 months ago
マーカーから距離を得る
// import this on your HTML
window.addEventListener('load', () => {
const camera = document.querySelector('[camera]');
const marker = document.querySelector('a-marker');
let check;
marker.addEventListener('markerFound', () => {
let cameraPosition = camera.object3D.position;
let markerPosition = marker.object3D.position;
let distance = cameraPosition.distanceTo(markerPosition)
check = setInterval(() => {
cameraPosition = camera.object3D.position;
markerPosition = marker.object3D.position;
distance = cameraPosition.distanceTo(markerPosition)
// do what you want with the distance:
console.log(distance);
}, 100);
});
marker.addEventListener('markerLost', () => {
clearInterval(check);
})
})
DPIが大事っぽい,これによって表示するコンテンツのサイズも変更されるっぽい
重要な要素は画像の DPI です。良好な dpi (300 以上) では非常に良好な安定化が得られますが、低い DPI (72 など) ではユーザーは非常に静止して画像の近くに留まる必要があり、そうしないと追跡が遅れます。 。
https://medium.com/@noemi__biro/exclusive-builds-of-tracking-image-based-tracking-ar-js-d92821cae83d
この人のやつめっちゃきれいに場所でとるな,JS何も書いてないけど
この処理めっちゃポジションを真ん中にしている感ある -> THREE.jsっぽい https://discourse.threejs.org/t/way-to-raycast-webar-ar-js/55244
window.addEventListener('arjs-nft-init-data', function(nft) {
console.log(nft);
var msg = nft.detail;
model.position.y = (msg.height / msg.dpi * 2.54 * 10)/2.0; //y axis?
model.position.x = (msg.width / msg.dpi * 2.54 * 10)/2.0; //x axis?
})
解決したい課題
表示位置が安定しない -> 認識した時点で座標軸が展開され,座標の幅が認識した位置によって異なるのでは?
やること