Gltf 2.0 model not loading using ar.js

时间:2018-02-03 10:28:38

标签: javascript gltf ar.js

I am trying to load a gltf2.0 model using ar.js. I have tried it several time but I think I am wrong at something. Here's the code:

    <script src="https://cdn.rawgit.com/jeromeetienne/AR.js/1.5.0/aframe/examples/vendor/aframe/build/aframe.min.js"></script>
<script src="https://cdn.rawgit.com/jeromeetienne/AR.js/1.5.0/aframe/build/aframe-ar.js"></script>
<script src="https://rawgit.com/donmccurdy/aframe-extras/master/dist/aframe-extras.loaders.min.js"></script>
<body style='margin : 0px; overflow: hidden;'>
    <a-scene embedded arjs='trackingMethod: best;'>
      <a-anchor hit-testing-enabled='true'>
      <a-gltf-model-next src="damagedHelmet/damagedHelmet.gltf" scale="0.5 0.5 0.5"></a-gltf-model>
      </a-anchor>
        <a-camera-static/>
    </a-scene>
</body>

The folder of gltf model is in the same folder in which the html code is. Can anyone please help me with this?

1 个答案:

答案 0 :(得分:1)

这是旧aframe版本的已知问题,但您的代码存在其他问题。提高您的aframe版本和aframe-ar版本。删除aframe-extras脚本,在新版本中没有必要。摆脱a-anchor,最后添加一个带有a-marker-camera的标记:

<script src="https://aframe.io/releases/0.8.0/aframe.min.js"></script>
<script src="https://cdn.rawgit.com/jeromeetienne/AR.js/1.5.5/aframe/build/aframe-ar.js"></script>
<body style='margin : 0px; overflow: hidden;'>
    <a-scene embedded arjs='trackingMethod: best;'>
      <a-gltf-model src="https://rawgit.com/KhronosGroup/glTF-Sample-Models/master/2.0/DamagedHelmet/glTF/DamagedHelmet.gltf"></a-gltf-model>
      <a-marker-camera preset='hiro'></a-marker-camera>
      <a-camera-static/>
    </a-scene>
</body>

run code)(download marker

或者,如果您想保留旧的aframe库,可以使用a-assets加载模型,如下所示:

<script src="https://cdn.rawgit.com/jeromeetienne/AR.js/1.5.0/aframe/examples/vendor/aframe/build/aframe.min.js"></script>
<script src="https://cdn.rawgit.com/jeromeetienne/AR.js/1.5.0/aframe/build/aframe-ar.js"></script>
<body style='margin : 0px; overflow: hidden;'>
    <a-scene embedded arjs='trackingMethod: best;'>
    <a-assets>
    <a-asset-item id="model" src="https://rawgit.com/KhronosGroup/glTF-Sample-Models/master/1.0/CesiumMan/glTF/CesiumMan.gltf" crossOrigin="anonymous"></a-asset-item> 
  </a-assets>
  <a-gltf-model src="#model"></a-gltf-model>
  <a-marker-camera preset='hiro'></a-marker-camera>
    <a-camera-static/>
    </a-scene>
</body>

run code)(download marker

但请注意,您只能加载gltf 1.0个型号(头盔为gltf 2.0