Newer
Older
AR-project / AR / AR-marker_based.html
@Satou Fumiya Satou Fumiya on 22 Jul 2021 3 KB test
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>AR-marker_based</A-marker_based></title>
<!-- A-Frame ライブラリの読み込み -->
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
<!-- AR.js ライブラリの読み込み -->
<script src="https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar.js"></script>
<style>
#btn{
color: white;
text-align: center;
position: fixed;
left: 45%;
bottom: 5%;
transform: translate(-5%, -50%);
background: rgba(0, 0, 0, 0.2);
border: solid white 2px;
/* border-bottom: black; */
border-radius: 50%;
width: 50px;
height: 50px;
font-size: large;
}

#btn:active{
    color: black;
    background: rgba(255, 255, 255, 0.8);
    border: black;
}

.guide{
    /* display: none; */
    text-align: center ;
    z-index: 1000;
    font-size: 40px;
    color: white;
    /* animation-name: fadeIn; */
    animation: fadeIn 1s ease 1s 1 normal ;
    @keyframes fadeIn {
        0%{
            opacity: 0;
        }
        100%{
            opacity: 1;
        }
    }
}
</style>
</head>
<body style="margin:0px; overflow:hidden;">

<!-- A-Frame の VR空間に AR.js を紐づける(デバッグUIを非表示) -->
<a-scene embedded arjs="debugUIEnabled:false;">

    <!-- マーカーの場所に箱を置く(見やすいようにワイヤーフレーム表示) -->
    <a-entity 
    position="0 0.5 0" 
    animation="property:rotation; dur:10000; from : 0 0 0; to : 0 360 0;loop : -1 ; easing:linear;"
    gltf-model="#mi">
    </a-entity>
    <a-entity  id="myCursor" cursor="fuse: true; fuseTimeout: 1000" position="0 0 -1" geometry="primitive: ring" scale="0.03 0.03 0.03" material="color: blue; shader: flat">
        <a-animation begin="cursor-fusing" easing="ease-in" attribute="scale" fill="none" from="0.03 0.03 0.03" to="0.001 0.001 0.001"></a-animation>
    </a-entity>

    </a-marker>
    <a-marker id="object" preset="custom" type='pattern' url='../material/pattern-AR-marker.patt'>
	    <a-box 
        position="0 0.5 0" 
        wireframe="true" 
        animation="property:rotation; dur:10000; from : 0 0 0; to : 0 360 0;loop : -1 ; easing:linear;">
        </a-box>
    </a-marker>
        <!-- AR用のカメラを置く -->
        <a-entity camera></a-entity>
    <p class="guide">QRコードを写してね</p>
    </a-scene>
    
    <button type="button" id="btn">?</button>


<script>
    const object = document.getElementById('object');
    const btn = document.getElementById('btn');
	let x=0;
	
        btn.addEventListener('click',(e) => {
            if (x === 0 ){
            object.innerHTML = '<a-sphere id="object" radios="1.25" color="#EF2D5E"></a-sphere>';
            x = 1;
            console.log(x);
            } else if (x === 1) {
            object.innerHTML='<a-cylinder radius"0.5" color="#FFC65D" rotation="90 60 0"</a-cylinder>'
            x = 2;
            console.log(x);
            } else if(x === 2){
            object.innerHTML = '<a-box id="object"position="0 0.5 0" wireframe="true" animation="property:rotation; dur:10000; from : 0 0 0; to : 0 360 0;loop : -1 ; easing:linear;"></a-box>'
            x = 0;
            console.log(x);
            } 
        })
</script>
</body>
</html>