gpt4 book ai didi

javascript - 三.js/OrbitControls 未定义

转载 作者:行者123 更新时间:2023-12-04 12:36:36 25 4
gpt4 key购买 nike

当我尝试导入 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 模块,也是。

关于javascript - 三.js/OrbitControls 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64155393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com