gpt4 book ai didi

javascript - Three.js - 未捕获的 ReferenceError : THREE is not defined

转载 作者:搜寻专家 更新时间:2023-11-01 05:28:46 25 4
gpt4 key购买 nike

当我运行我的 javascript 代码时。我收到以下错误“Uncaught ReferenceError: THREE is not defined”。提到的行是:

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

最佳答案

之前需要包含three.js

<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r79/three.min.js"></script>

关于javascript - Three.js - 未捕获的 ReferenceError : THREE is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41089475/

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