我試圖製作像this page一樣的3D地球儀,但失敗了。我在HTML5和CSS/CSS3零知識,我只是將代碼提供到JSFiddle,但我什麼都沒有。製作3D地球儀
window.requestAnimFrame = (function(callback){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback){
window.setTimeout(callback, 1000/60);
};
})();
function animate(lastTime, angularSpeed, three){
// update this frame
var time = new Date().getTime();
var timeDiff = time - lastTime;
var angleChange = angularSpeed * timeDiff * 2 * Math.PI/1000;
three.earth.rotation.y += angleChange;
lastTime = time;
// render this frame
three.renderer.render(three.scene, three.camera);
// next frame
requestAnimFrame(function(){
animate(lastTime, angularSpeed, three);
});
}
window.onload = function(){
var angularSpeed = 0.005;
var lastTime = 0;
// load renderer
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// set a camera
var camera = new THREE.PerspectiveCamera(45, window.innerWidth/ window.innerHeight, 1, 1000);
camera.position.z = 700;
// create a scene
var scene = new THREE.Scene();
// add a texture to a material
var material = new THREE.MeshLambertMaterial({
map: THREE.ImageUtils.loadTexture("https://joshcarllewis.com/static/articles/html5-3d-canvas-tutorial/earth.jpg")
});
// create an earth object
var earth = new THREE.Mesh(new THREE.SphereGeometry(200, 50, 50), material);
earth.overdraw = true;
scene.add(earth);
// add a directional light source
var directionalLight = new THREE.DirectionalLight(0xffffff);
directionalLight.position.set(2, 1, 2).normalize();
scene.add(directionalLight);
// keep everything together to make passing it around easier
var three = {
renderer: renderer,
camera: camera,
scene: scene,
earth: earth
};
// Preload textures before begining animation
var textureImg = new Image();
textureImg.onload = function(){
animate(lastTime, angularSpeed, three, this);
};
textureImg.src = "https://joshcarllewis.com/static/articles/html5-3d-canvas-tutorial/earth.jpg";
};
任何人都可以看到我的代碼有什麼問題嗎? 謝謝。
錯誤?控制檯輸出?我沒有得到什麼意思? http://stackoverflow.com/help/how-to-ask –
你的代碼有什麼問題是它不是你的代碼。 –
堆棧溢出不是調試器的替代品。 「這是所有的代碼,它不起作用,告訴我什麼是錯的」不是一個問題。 – David