尝试导入 OrbitControls.js 时 Three.js 中断 [英] Three.js breaks when trying to import OrbitControls.js

查看:59
本文介绍了尝试导入 OrbitControls.js 时 Three.js 中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我想说我对 javascript 和使用库非常陌生.我试图让一些基本的three.js 代码工作,但它不起作用,我不知道为什么.我已经使用 Threejs.org 文档设置了一个基本场景,我正在尝试设置一些基本的轨道控制.一切正常,直到我尝试将轨道控件导入到我的主脚本文件中.然后我收到一个错误:

First I want to say that I'm very new to javascript and working with libraries. I'm trying to get some basic three.js code to work but it's not working and I'm not sure why. I have set up a basic scene using the Threejs.org documentation and I'm trying to get some basic orbit controls set up. Everything works fine until I try to import the orbit controls into my main script file. I then get an error:

未捕获的类型错误:无法解析模块说明符三".相对引用必须以/"、./"或../"开头.

Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../".

我没有尝试太多来解决我的问题,因为我什至不知道从哪里开始.我检查了我的拼写并确保我有正确的导入相对路径.

I haven't tried much to solve my problem because I'm not even sure where to start. I've checked my spelling and made sure I had the correct relative path for my imports.

这是有效的代码:

import * as THREE from '/node_modules/three/build/three.module.js';

// import { OrbitControls } from '/node_modules/three/examples/jsm/controls/OrbitControls.js';

// Construct basic scene elements
const camera = new THREE.PerspectiveCamera(
    75,
    window.innerWidth / window.innerHeight,
    1,
    1000
);
const renderer = new THREE.WebGLRenderer();
const scene = new THREE.Scene();
// const controls = new OrbitControls(camera, renderer.domElement);

// Set parameters for scene elements
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

当我取消注释轨道控件的第二个导入时,它会中断并给我上面的错误.导致错误的原因是什么,我该如何解决?

When I uncomment the second import for the orbit controls it breaks and gives me the error above. What is causing the error and how do I fix it?

提前致谢.

推荐答案

欢迎使用 Stack Overflow.您的问题似乎缺少一些信息,因此我将根据您提供的信息做出一些假设.如果我的任何假设不正确,请更新您的问题以提供更多详细信息.

Welcome to Stack Overflow. You question seems to be missing some information, so I'm going to make some assumptions based on what you have provided. If any of my assumptions are incorrect, please update your question to provide further details.

我的主要假设是您在 HTML 中使用

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆