You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
3.8 KiB
163 lines
3.8 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>three.js webgl - map controls</title>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
|
<style>
|
|
body {
|
|
color: #000;
|
|
font-family:Monospace;
|
|
font-size:13px;
|
|
text-align:center;
|
|
font-weight: bold;
|
|
|
|
background-color: #fff;
|
|
margin: 0px;
|
|
overflow: hidden;
|
|
}
|
|
|
|
#info {
|
|
color:#000;
|
|
position: absolute;
|
|
top: 0px; width: 100%;
|
|
padding: 5px;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
a {
|
|
color: red;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div id="info">
|
|
<a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - map controls example
|
|
</div>
|
|
|
|
<script src="../build/three.js"></script>
|
|
<script src="js/controls/MapControls.js"></script>
|
|
<script src="js/WebGL.js"></script>
|
|
|
|
<script src='js/libs/dat.gui.min.js'></script>
|
|
|
|
<script>
|
|
|
|
if ( WEBGL.isWebGLAvailable() === false ) {
|
|
|
|
document.body.appendChild( WEBGL.getWebGLErrorMessage() );
|
|
|
|
}
|
|
|
|
var camera, controls, scene, renderer;
|
|
|
|
init();
|
|
//render(); // remove when using next line for animation loop (requestAnimationFrame)
|
|
animate();
|
|
|
|
function init() {
|
|
|
|
scene = new THREE.Scene();
|
|
scene.background = new THREE.Color( 0xcccccc );
|
|
scene.fog = new THREE.FogExp2( 0xcccccc, 0.002 );
|
|
|
|
renderer = new THREE.WebGLRenderer( { antialias: true } );
|
|
renderer.setPixelRatio( window.devicePixelRatio );
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
document.body.appendChild( renderer.domElement );
|
|
|
|
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 1000 );
|
|
camera.position.set( 400, 200, 0 );
|
|
|
|
// controls
|
|
|
|
controls = new THREE.MapControls( camera, renderer.domElement );
|
|
|
|
//controls.addEventListener( 'change', render ); // call this only in static scenes (i.e., if there is no animation loop)
|
|
|
|
controls.enableDamping = true; // an animation loop is required when either damping or auto-rotation are enabled
|
|
controls.dampingFactor = 0.25;
|
|
|
|
controls.screenSpacePanning = false;
|
|
|
|
controls.minDistance = 100;
|
|
controls.maxDistance = 500;
|
|
|
|
controls.maxPolarAngle = Math.PI / 2;
|
|
|
|
// world
|
|
|
|
var geometry = new THREE.BoxBufferGeometry( 1, 1, 1 );
|
|
geometry.translate( 0, 0.5, 0 );
|
|
var material = new THREE.MeshPhongMaterial( { color: 0xffffff, flatShading: true } );
|
|
|
|
for ( var i = 0; i < 500; i ++ ) {
|
|
|
|
var mesh = new THREE.Mesh( geometry, material );
|
|
mesh.position.x = Math.random() * 1600 - 800;
|
|
mesh.position.y = 0;
|
|
mesh.position.z = Math.random() * 1600 - 800;
|
|
mesh.scale.x = 20;
|
|
mesh.scale.y = Math.random() * 80 + 10;
|
|
mesh.scale.z = 20;
|
|
mesh.updateMatrix();
|
|
mesh.matrixAutoUpdate = false;
|
|
scene.add( mesh );
|
|
|
|
}
|
|
|
|
// lights
|
|
|
|
var light = new THREE.DirectionalLight( 0xffffff );
|
|
light.position.set( 1, 1, 1 );
|
|
scene.add( light );
|
|
|
|
var light = new THREE.DirectionalLight( 0x002288 );
|
|
light.position.set( - 1, - 1, - 1 );
|
|
scene.add( light );
|
|
|
|
var light = new THREE.AmbientLight( 0x222222 );
|
|
scene.add( light );
|
|
|
|
//
|
|
|
|
window.addEventListener( 'resize', onWindowResize, false );
|
|
|
|
|
|
var gui = new dat.GUI();
|
|
|
|
gui.add( controls, 'screenSpacePanning' );
|
|
|
|
}
|
|
|
|
function onWindowResize() {
|
|
|
|
camera.aspect = window.innerWidth / window.innerHeight;
|
|
camera.updateProjectionMatrix();
|
|
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
|
}
|
|
|
|
function animate() {
|
|
|
|
requestAnimationFrame( animate );
|
|
|
|
controls.update(); // only required if controls.enableDamping = true, or if controls.autoRotate = true
|
|
|
|
render();
|
|
|
|
}
|
|
|
|
function render() {
|
|
|
|
renderer.render( scene, camera );
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|