[英]Why my Three.js code isn't working when i test it?
我正在尝试Three.js,我一步一步地按照教程。 在我正在使用的代码编辑器(Visual Studio Code 2019)中,一切看起来都很正常,但是当我测试它时,页面上没有任何内容。
我正在使用的编辑器,使用桌面作为查找我的代码的地方,因为它是一个.html文件,我可以运行它。 当我这样做时,唯一出现的是我编程的导航栏,没有别的
This is the entire three.js code:
<script src="three.js-dev/build/three.min.js"> </script>
<script>
var scene = new THREE.scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight);
var renderer = new THREE.WebGLRenderer({antialias = true});
renderer.setSize( window.innerWidth, window.innerHeight);
$('body').append( renderer.domElement);
var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshBasicMaterial ( { color = 0xff0000 });
var cube = new THREE.Mesh( geometry, material) ;
scene.add( cube );
cube.position.z = -5;
var animate = function () {
cube.rotation.x += 0.01;
renderer.render(scene, camera);
requestAnimationFrame( animate );
};
animate();
这个代码在它之前:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script
src="https://code.jquery.com/jquery-2.1.4.js"
integrity="sha256-siFczlgw4jULnUICcdm9gjQPZkw/YPDqhQ9+nAOScE4="
crossorigin="anonymous"></script>
</head>
<body>
<div id="navbar"><span>Three.js Tut</span></div>
我期待一个红色立方体旋转,但没有出现。 ¿有什么我做错了吗?
您的代码中有一些错误:
THREE.scene
应该是THREE.Scene
{antialias = true}
应为{antialias: true}
{ color = 0xff0000 }
应为{ color: 0xff0000 }
使用您的代码进行现场演示: https : //jsfiddle.net/so736vxj/
BTW:如果你正在使用VSCode,我有点恼火,没有突出显示任何错误。 特别是应该报告最后两个语法错误,因为它不是有效的JavaScript。
three.js R105
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.