<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D地球</title>
<style>
body {
margin: 0;
}
canvas {
width: 100%;
height: 100%
}
</style>
</head>
<body>
<script src="three.js"></script>
<script src="TrackballControls.js"></script>
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 5;
var controls = new THREE.TrackballControls(camera);
var render = new THREE.WebGLRenderer();
render.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(render.domElement);
var textureLoader = new THREE.TextureLoader();
var texture = textureLoader.load('earth.jpg');
var material = new THREE.MeshBasicMaterial({map: texture});
var sphere = new THREE.SphereGeometry(1, 32, 32);
var mesh = new THREE.Mesh(sphere, material);
scene.add(mesh);
function animate() {
requestAnimationFrame(animate);
mesh.rotation.y += 0.005;
controls.update();
render.render(scene, camera);
}
animate();
</script>
</body>
</html>
地球纹理下载地址: https://pan.baidu.com/s/1hrQErCo