首页 > 解决方案 > 我无法在 A-frame 中加载 .glb 文件!我该如何解决?

问题描述

我是 a-frame 的新手,我尝试在 A-frame 中加载 .glb 文件,但在场景中看不到它!我该如何解决?我在下面有代码,还注意到它与 .obj 文件完美配合。

{% load static %}

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    {% block threedtitle %}{% endblock %}

    <style>
        body {
            margin: 0;
        }

        canvas {
            width: 100%;
            height: 100%;
        }
    </style>

    <script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
    <script src="https://unpkg.com/aframe-event-set-component@^4.0.0/dist/aframe-event-set-component.min.js"></script>
    <script src="https://unpkg.com/aframe-environment-component/dist/aframe-environment-component.min.js"></script>
</head>

<body>
    <a-scene background="color: #EAEAEA">

        <a-asset>
            <a-asset-item id="toilet-glb" src="{% static '3d_file/toilet.glb' %}"></a-asset-item>
        </a-asset>

        <!-- Camera -->
        <a-entity position="0 100 100">
            <a-camera></a-camera>
        </a-entity>

        <!-- toilet -->
        <a-entity gltf-model="#toilet-glb" position="0 0 10" scale="0.08 0.08 0.08"
            animation="property: rotation; to: 0 360 0; dur: 14000; easing: linear; loop: true">
        </a-entity>

    </a-scene>

</body>

</html>

标签: javascripthtml5-canvasaframe

解决方案


Not sure what seems wrong but try this:

<a-entity gltf-model="src: url({% static '3d_file/toilet.glb' %})" ...></a-entity>

also check:

  1. Are you sure about the position not at 0 0 0?
  2. The scale is so small!
  3. Is {% static '3d_file/toilet.glb' %} return correct URL?
  4. Maybe the animation= part cause some error?

推荐阅读