本文介绍了Three.js - 未捕获的ReferenceError:未定义THREE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我运行我的javascript代码时。我收到以下错误Uncaught ReferenceError:THREE未定义。
提到的行是:
When I run my javascript code. I get the following error "Uncaught ReferenceError: THREE is not defined".The line mentioned is:
var renderer = new THREE.WebGLRenderer();
// I have attached the three.js library in the script tag. I don't know what seems to be problem.
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(45, window.innerWidth/window.innerHeight, 0.1, 1000);
camera.position.set = (0, 0, 10);
camera.lookAt(camera.position);
scene.add(camera);
var geometry = new THREE.Geometry();
geometry.vertices.push(new THREE.Vector3(0.0, 1.0, 0.0));
geometry.vertices.push(new THREE.Vector3(-1.0, -1.0, 0.0));
geometry.vertices.push(new THREE.Vector3(1.0, -1.0, 0.0));
geometry.faces.push(new THREE.Face3(0, 1, 2));
var material = new THREE.BasicMeshMaterial({
color: 0xFFFFFF,
side: THREE.DoubleSide
});
var mesh = new THREE.Mesh(geometry, material);
mesh.position.set(-1.5, 0.0, 4.0);
scene.add(mesh);
function render() {
renderer.render(scene, camera);
}
render();
推荐答案
你需要在
You need to include three.js before
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r79/three.min.js"></script>
这篇关于Three.js - 未捕获的ReferenceError:未定义THREE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!