Three.js 三是没有界定;我该如何解决这个问题?
我目前正在试用Three.js,但我似乎无法修复这个错误,我已经尝试并搜索了很多答案,但我无法修复它 我已经包括了threejs库 在我的剧本里,一切都写得很好 这是我的html索引文件Three.js 三是没有界定;我该如何解决这个问题?,three.js,Three.js,我目前正在试用Three.js,但我似乎无法修复这个错误,我已经尝试并搜索了很多答案,但我无法修复它 我已经包括了threejs库 在我的剧本里,一切都写得很好 这是我的html索引文件 <body> <script src="script.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r79/three.
<body>
<script src="script.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r79/three.min.js"></script>
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/242637/TrackballProjectorDetector.js"></script>
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/242637/AsciiEffect.js"></script>
</body>
我想订单在这里可能很重要。如果在加载script.js
(a)时运行init
函数,三个
尚未定义,因为这将发生在下一行
在这种情况下,解决方案是在脚本文件之前加载three.js
(a) 这通常在
js
文件的末尾完成,但在这种情况下我们不能确定,因为我们没有完整的文件。因此,我会查看该文件,看看它是否类似于:
函数init(){
blahBlahBlah();
}
init();
我猜您在加载three.min.js
之前正在执行script.js
。更改
标记的顺序,以便首先加载所有依赖项,然后将代码放在后面。另外,我建议您使用,因为r79
大约3-4岁。天哪,这对我来说很有用。我甚至不知道这是件事。非常感谢。
function init() {
var width = window.innerWidth || 2;
var height = window.innerHeight || 2;
container = document.createElement('div');
document.body.appendChild(container);
var info = document.createElement('div');
info.style.position = 'absolute';
info.style.top = '20px';
info.style.width = '100%';
info.style.textAlign = 'center';
info.innerHTML = 'Drag to change the view';
container.appendChild(info);
** camera = new THREE.PerspectiveCamera(70, width / height, 1, 1000);
camera.position.y = 150;
camera.position.z = 500;
controls = new THREE.TrackballControls(camera);
scene = new THREE.Scene();
var light = new THREE.PointLight(0xffffff);
light.position.set(500, 500, 500);
scene.add(light);
var light = new THREE.PointLight(0xffffff, 0.25);
light.position.set(-500, -500, -500);
scene.add(light);
sphere = new THREE.Mesh(new THREE.SphereGeometry(200, 20, 10), new THREE.MeshLambertMaterial());
scene.add(sphere);
``