我正在学习Three.js,并建立了一个运行node.js服务器并导入Three.js作为节点模块的基本项目。
其实我的设置可以用,但是如果这是一个好的设置,我有点困惑吗?
我正在考虑的事情基本上是我的node_module的漫长道路。在某些页面上,Three.js仅通过以下方式导入:
import * as THREE from 'three';
但就我而言,我必须写完整路径:
import * as THREE from './node_modules/three/build/three.module.js';
这是正确的实现吗?
这是我的完整代码:
index.html
three.js webglbody {
background-color: #cce0ff;
color: #000;
}
a {
color: #080;
}
index.js
**import * as THREE from './node_modules/three/build/three.module.js';**
const scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var geometry = new THREE.BoxGeometry(1, 1, 1);
var material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
var cube = new THREE.Mesh(geometry, material);
scene.add(cube);
camera.position.z = 5;
var animate = function () {
requestAnimationFrame(animate);
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render(scene, camera);
};
animate();
我需要使用webpack捆绑吗?那可以解决它找不到我的nodemodule路径的问题吗?