mirror of
https://github.com/wahyd4/three.js.git
synced 2026-08-10 13:35:56 +10:00
* THREE.Rectangle: `_x1`, ` _x2`, `_y1`, `_y2` ⟶ `_left`, `_right`, `_top`, `_bottom`
140 lines
2.9 KiB
HTML
140 lines
2.9 KiB
HTML
<!DOCTYPE HTML>
|
|
<html lang="en">
|
|
<head>
|
|
<title>three.js - geometry - earth</title>
|
|
<meta charset="utf-8">
|
|
<style type="text/css">
|
|
body {
|
|
color: #808080;
|
|
font-family:Monospace;
|
|
font-size:13px;
|
|
text-align:center;
|
|
|
|
background-color: #ffffff;
|
|
margin: 0px;
|
|
overflow: hidden;
|
|
}
|
|
|
|
#info {
|
|
position: absolute;
|
|
top: 0px; width: 100%;
|
|
padding: 5px;
|
|
}
|
|
|
|
a {
|
|
|
|
color: #0080ff;
|
|
}
|
|
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div id="container"></div>
|
|
<div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - earth demo</div>
|
|
|
|
<script type="text/javascript" src="js/Stats.js"></script>
|
|
|
|
<script type="text/javascript" src="../build/Three.js"></script>
|
|
<script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
|
|
<script type="text/javascript" src="../src/extras/primitives/Sphere.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight;
|
|
|
|
var container, stats;
|
|
|
|
var camera, scene, renderer;
|
|
|
|
var mesh;
|
|
|
|
var mouseX = 0;
|
|
var mouseY = 0;
|
|
|
|
var windowHalfX = window.innerWidth / 2;
|
|
var windowHalfY = window.innerHeight / 2;
|
|
|
|
|
|
init();
|
|
setInterval( loop, 1000 / 60 );
|
|
|
|
|
|
function init() {
|
|
|
|
container = document.getElementById( 'container' );
|
|
|
|
camera = new THREE.Camera( 60, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 10000 );
|
|
camera.position.z = 500;
|
|
|
|
scene = new THREE.Scene();
|
|
|
|
mesh = new THREE.Mesh( new Plane( 300, 300, 3, 3 ), loadImage( 'textures/shadow.png' ) );
|
|
mesh.position.y = - 250;
|
|
mesh.rotation.x = - 90 * Math.PI / 180;
|
|
scene.addObject(mesh);
|
|
|
|
mesh = new THREE.Mesh( new Sphere( 200, 20, 20 ), loadImage( 'textures/land_ocean_ice_cloud_2048.jpg' ) );
|
|
scene.addObject(mesh);
|
|
|
|
renderer = new THREE.CanvasRenderer();
|
|
renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
|
|
|
|
container.appendChild( renderer.domElement );
|
|
|
|
stats = new Stats();
|
|
stats.domElement.style.position = 'absolute';
|
|
stats.domElement.style.top = '0px';
|
|
container.appendChild( stats.domElement );
|
|
|
|
document.addEventListener('mousemove', onDocumentMouseMove, false);
|
|
|
|
}
|
|
|
|
function loadImage( path ) {
|
|
|
|
var canvas = document.createElement( 'canvas' );
|
|
canvas.width = 32;
|
|
canvas.height = 32;
|
|
|
|
var material = new THREE.MeshBitmapMaterial( canvas );
|
|
|
|
var image = new Image();
|
|
|
|
image.onload = function () {
|
|
|
|
material.bitmap = this;
|
|
|
|
};
|
|
|
|
image.src = path;
|
|
|
|
return material;
|
|
|
|
}
|
|
|
|
function onDocumentMouseMove( event ) {
|
|
|
|
mouseX = ( event.clientX - windowHalfX );
|
|
mouseY = ( event.clientY - windowHalfY );
|
|
|
|
}
|
|
|
|
function loop() {
|
|
|
|
camera.position.x += (mouseX - camera.position.x) * 0.05;
|
|
camera.position.y += (-mouseY - camera.position.y) * 0.05;
|
|
|
|
mesh.rotation.y -= 0.005;
|
|
|
|
renderer.render(scene, camera);
|
|
stats.update();
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|