三.js/OrbitControls 未定义

编程入门 行业动态 更新时间:2024-10-24 23:19:47
本文介绍了三.js/OrbitControls 未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

当我尝试导入 OrbitControls.js 时:

我收到不能在模块外使用导入语句错误

所以,我使用:

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

When i try to import OrbitControls.js the following:

I get the Cannot use import statement outside a module error

So, I use :

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

but this time I get:

ReferenceError: OrbitControls is not defined

HTML body:

<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/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();
...

解决方案

You are mixing ES6 module with non-module code which is not valid. Do it like so:

<script type="module">

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

import { DRACOLoader } from 'https://cdn.jsdelivr/npm/three@0.121.1/examples/jsm/loaders/DRACOLoader.js';
import { OrbitControls } from 'https://cdn.jsdelivr/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>

I suggest you convert your custom geometry_helper.js to a ES6 module, too.

这篇关于三.js/OrbitControls 未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 15:21:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1395712.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:未定义   js   OrbitControls

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!