繁体   English   中英

三.js / OrbitControls 未定义

[英]three.js / OrbitControls is not defined

当我尝试导入 OrbitControls.js 时:

我得到了Cannot use import statement outside a module错误

所以,我使用:

<script type="module" src="OrbitControls.js"></script >

但这次我得到:

ReferenceError: OrbitControls is not defined

HTML 正文:

<body>
    <div id="page-wrapper">
        <h1>Open Spaceport Container (.drc):</h1>
        <div>
            <input type="file" id="fileInput">
        </div>
    </div>
    <div>
        <pre id="decoderType"><pre>
    </div>
    <div>
        <pre id="fileDisplayArea"><pre>
    </div>
    <script src="https://cdn.rawgit.com/mrdoob/three.js/dev/build/three.min.js"></script>
    <script src="DRACOLoader.js"></script>
   <script src="geometry_helper.js"></script>
   <script type="module" src="OrbitControls.js"></script>
       <script>
        "use strict"
        


      // Configure decoder and create loader.
          var textureLoader = new THREE.TextureLoader();
          const loadManager = new THREE.LoadingManager();
...

您将 ES6 模块与无效的非模块代码混合在一起。 这样做:

<script type="module">

import * as THREE from 'https://cdn.jsdelivr.net/npm/three@0.121.1/build/three.module.js';

import { DRACOLoader } from 'https://cdn.jsdelivr.net/npm/three@0.121.1/examples/jsm/loaders/DRACOLoader.js';
import { OrbitControls } from 'https://cdn.jsdelivr.net/npm/three@0.121.1/examples/jsm/controls/OrbitControls.js';

// your actual app code

// Configure decoder and create loader.
const manager = new THREE.LoadingManager();
const textureLoader = new THREE.TextureLoader(manager);

</script>

我建议你也将自定义的geometry_helper.js转换为 ES6 模块。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM