Нужно веб-решение AR без маркеров - PullRequest
0 голосов
/ 04 июля 2019

Пожалуйста, помогите мне разобраться.Мне нужно создать дополненную реальность без маркеров для Интернета.Какую технологию лучше использовать для этого. В моем решении я могу добавить 3d-модель, но когда я перемещаю камеру, модель меняет положение. Так что в моем примере я использую aframe и aframe-ar.js. Вот код

<head>
    <script src="https://aframe.io/releases/0.8.0/aframe.min.js"></script>
    <script src="https://cdn.rawgit.com/jeromeetienne/AR.js/1.6.0/aframe/build/aframe-ar.js"></script>
    <script src="https://cdn.rawgit.com/donmccurdy/aframe-extras/cfe5f316/dist/aframe-extras.js"></script>
</head>
    <script>
      // Component that places trees where the ground is clicked
      AFRAME.registerComponent('tap-place', {
        init: function() {
          const ground = document.getElementById('ground')
          ground.addEventListener('click', event => {
            console.log('event registered');
            const newElement = document.createElement('a-entity')
            const touchPoint = event.detail.intersection.point;
            console.log('touchPoint', touchPoint);
            newElement.setAttribute('position', touchPoint)
            newElement.setAttribute('id', 'dino')
            const randomYRotation = Math.random() * 360
            newElement.setAttribute('rotation', '0 ' + randomYRotation + ' 0')
           // newElement.setAttribute('visible', 'false')
          //  newElement.setAttribute('scale', '0.0001 0.0001 0.0001')
            newElement.setAttribute('gltf-model', '#dino-model')
            this.el.sceneEl.appendChild(newElement)
            newElement.addEventListener('model-loaded', () => {
              // Once the model is loaded, we are ready to show it popping in using an animation
              newElement.setAttribute('visible', 'true')
              newElement.setAttribute('animation', {
                property: 'scale',
                to: '0.01 0.01 0.01',
                easing: 'easeOutElastic',
                dur: 800,
              })
            })
          })
        },
      })
    </script>
  </head>
<body>
    <a-scene embedded arjs='sourceType: webcam;' id='canvas' tap-place>
        <!-- <a-camera ar-raycaster raycaster cursor="fuse:false"> </a-camera> -->
        <a-camera 
         position="0 8 0"
         raycaster="objects: .cantap"
         cursor="
          fuse: false;
          rayOrigin: mouse;">
        </a-camera>
         <a-entity
        light="type: directional;
               intensity: 0.8;"
        position="1 4.3 2.5">
      </a-entity>

      <a-light type="ambient" intensity="1"></a-light>
        <a-assets>
            <a-asset id="dino-model" src="dino.glb"></a-asset>
        </a-assets>
       <a-entity
        id="ground"
        class="cantap"
        geometry="primitive: box"
        material="color: #ffffff; transparent: true; opacity: 0.0"
        scale="1000 2 1000"
        position="0 -1 0">
      </a-entity>
    </a-scene>
</body>

</html>
...