Created
July 25, 2013 13:34
-
-
Save Xanmia/6079690 to your computer and use it in GitHub Desktop.
A CodePen by Xanmia. Dynamic Plane Adjusting in threejs - Random adjusting the heights on the plane object. Refresh page for new plane layout.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vertexHeight = 500; | |
var planeDefinition = 20; | |
var planeSize = 15000; | |
var container = document.createElement('div'); | |
document.body.appendChild( container ); | |
var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight,1, 20000) | |
camera.position.z = 6000; | |
var scene = new THREE.Scene(); | |
var material = new THREE.MeshBasicMaterial({ color: 0xFFFFFF, wireframe:true }); | |
var plane = new THREE.Mesh( new THREE.PlaneGeometry( planeSize, planeSize, planeDefinition, planeDefinition ), new THREE.MeshBasicMaterial( { color: 0x555555, wireframe: true } ) ); | |
plane.rotation.x -=1; | |
scene.add( plane ); | |
var renderer = new THREE.WebGLRenderer(); | |
renderer.setSize(window.innerWidth, window.innerHeight); | |
container.appendChild( renderer.domElement ); | |
updatePlane(); | |
function updatePlane() { | |
for (var i = 0; i < plane.geometry.vertices.length; i++) | |
{ | |
plane.geometry.vertices[i].z += Math.random()*vertexHeight -vertexHeight; | |
} | |
}; | |
render(); | |
function render() { | |
requestAnimationFrame( render ); | |
renderer.render( scene, camera ); | |
} | |
window.addEventListener( 'resize', onWindowResize, false ); | |
function onWindowResize() { | |
camera.aspect = window.innerWidth / window.innerHeight; | |
camera.updateProjectionMatrix(); | |
renderer.setSize( window.innerWidth, window.innerHeight ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body{ | |
background-color: #000000; | |
margin: 0px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment