我不知道有什么人可以帮助我吗? 当我尝试在chrome上加载它时它只是白色屏幕,代码用于它自己的文件中,当我发现什么是错的时候它只是加载一个白页我试图让一个立方体加载帮助来自jquery和three.js
<!DOCTYPE HTML>
<html>
<head>
<title>THREE</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="js/three.js"></script>
<style>
body{
margins:0;
overflow:hidden;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
$(document).ready(function(){}
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(45, window.innerWidth/window.innerHeight, .1, 500);
var renderer = new THREE.WebGLRenderer();
renderer.setColor(0xdddddd);
renderer.setSize(window.innerWidth, window.innerHeight);
var axis = new THREE.AxisHelper(10);
scene.add(axis);
var grid = new THREE.GridHelper(50, 5);
var color = new Color("rgb(255, 0, 0)");
grid.setColors(color, 0x000000);
//scene.add(grid);
var cubeGeo = new THREE.BoxGeometry(5, 5, 5);
var cubeMat = new THREE.MeshBasicMaterial({color:0xdddddd, wireframe:true});
var cube = new THREE.Mesh(cubeGeo, cubeMat);
cube.position.x = 0;
cube.position.y = 0;
cube.position.z = 0;
scene.add(cube);
camera.position.x = 40;
camera.position.y = 40;
camera.position.z = 40;
camera.lookAt(scene.position);
$("#container").append(renderer.domElement);
renderer.render(scene,camera);
});
</script>
</body>
</html>
答案 0 :(得分:1)
从中删除右括号:
$(document).ready(function(){
删除此行,setColor似乎不是THREE.WebGLRenderer的方法:
renderer.setColor(0xdddddd);
变化:
var color = new Color("rgb(255, 0, 0)");
为:
var color = new THREE.Color("rgb(255, 0, 0)");
答案 1 :(得分:0)
您似乎立即打开并关闭了$(document).ready(function(){}
。因此需要删除右括号$(document).ready(function(){}
,因此整个脚本都包含在其中,并且底部有适当的结束标记。我没有三个.js,但我认为以下内容应该有效。
<!DOCTYPE HTML>
<html>
<head>
<title>THREE</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="js/three.js"></script>
<style>
body{
margins:0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
$(document).ready(function(){
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(45, window.innerWidth/window.innerHeight, .1, 500);
var renderer = new THREE.WebGLRenderer();
renderer.setColor(0xdddddd);
renderer.setSize(window.innerWidth, window.innerHeight);
var axis = new THREE.AxisHelper(10);
scene.add(axis);
var grid = new THREE.GridHelper(50, 5);
var color = new Color("rgb(255, 0, 0)");
grid.setColors(color, 0x000000);
//scene.add(grid);
var cubeGeo = new THREE.BoxGeometry(5, 5, 5);
var cubeMat = new THREE.MeshBasicMaterial({color:0xdddddd, wireframe:true});
var cube = new THREE.Mesh(cubeGeo, cubeMat);
cube.position.x = 0;
cube.position.y = 0;
cube.position.z = 0;
scene.add(cube);
camera.position.x = 40;
camera.position.y = 40;
camera.position.z = 40;
camera.lookAt(scene.position);
$("#container").append(renderer.domElement);
renderer.render(scene,camera);
});
</script>
</body>
</html>