(A-Frame) local gltf wont load; Cannot read property 'slice' of undefined

谁都会走 提交于 2019-12-23 07:52:08

问题


I took the code from the A-Frame School in which a gltf model is loaded. Then I loaded the Sample Models from Khronos, this box and tried to load it, but I get this error (several times)

GLTFLoader.js:979 Uncaught (in promise) TypeError: Cannot read property 'slice' of undefined
at GLTFLoader.js:979
at i (GLTFLoader.js:570)
at GLTFLoader.js:975
at <anonymous>

I can load .obj models and tried the several versions of the model, but get always the error.
The sample code does work locally, meaning it loads the model correctly, getting it from the aframe cdn.

Heres the code for completion

<!DOCTYPE html>
<html>
  <head>
    <title>glTF Model</title>
    <meta name="description" content="glTF Model">
    <script src="https://rawgit.com/aframevr/aframe/b395ea0/dist/aframe-master.min.js"></script>
  </head>
  <body>
    <a-scene>
      <a-assets>
        <a-asset-item id="boxModel" src="Box.gltf"></a-asset-item>
      </a-assets>          
      <a-gltf-model src="#boxModel"></a-gltf-model>
    </a-scene>
  </body>
</html>  

回答1:


Those models are in the 2.0 folder which means you need glTF v2.0 loader. A-Frame 0.5.0/0.6.0 supports glTF v1. But glTF v2 will be supported in A-Frame 0.7.0, but you can use gltf-model-next from Don McCurdy:

https://github.com/donmccurdy/aframe-extras/blob/master/src/loaders/gltf-model-next.js

Or you can grab different models instead from the 1.0 folder: https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/1.0




回答2:


Replace Aframe version to this:

<script src="https://aframe.io/releases/0.7.1/aframe.min.js"></script>



来源:https://stackoverflow.com/questions/44698203/a-frame-local-gltf-wont-load-cannot-read-property-slice-of-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!