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.
174 lines
4.3 KiB
174 lines
4.3 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>three.js webgl - materials - cube reflection / refraction [Walt]</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 {
|
|
font-family: Monospace;
|
|
margin: 0px;
|
|
overflow: hidden;
|
|
}
|
|
#info {
|
|
color: #fff;
|
|
position: absolute;
|
|
top: 10px;
|
|
width: 100%;
|
|
text-align: center;
|
|
z-index: 100;
|
|
display:block;
|
|
}
|
|
#info a {
|
|
color: #ff0080;
|
|
font-weight: bold;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="container"></div>
|
|
<div id="info">
|
|
<a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - cube mapping demo.<br />
|
|
Texture by <a href="http://www.humus.name/index.php?page=Textures" target="_blank" rel="noopener">Humus</a> Walt Disney head by <a href="http://davidoreilly.com/post/18087489343/disneyhead" target="_blank" rel="noopener">David OReilly</a>
|
|
</div>
|
|
|
|
<script src="../build/three.js"></script>
|
|
|
|
<script src="js/controls/OrbitControls.js"></script>
|
|
|
|
<script src="js/loaders/OBJLoader.js"></script>
|
|
|
|
<script src="js/WebGL.js"></script>
|
|
<script src="js/libs/stats.min.js"></script>
|
|
|
|
<script>
|
|
|
|
if ( WEBGL.isWebGLAvailable() === false ) {
|
|
|
|
document.body.appendChild( WEBGL.getWebGLErrorMessage() );
|
|
|
|
}
|
|
|
|
var container, stats;
|
|
|
|
var camera, scene, renderer;
|
|
|
|
var pointLight;
|
|
|
|
init();
|
|
animate();
|
|
|
|
function init() {
|
|
|
|
container = document.createElement( 'div' );
|
|
document.body.appendChild( container );
|
|
|
|
camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 5000 );
|
|
camera.position.z = 2000;
|
|
|
|
//controls
|
|
var controls = new THREE.OrbitControls( camera );
|
|
controls.enableZoom = false;
|
|
controls.enablePan = false;
|
|
controls.minPolarAngle = Math.PI / 4;
|
|
controls.maxPolarAngle = Math.PI / 1.5;
|
|
|
|
//cubemap
|
|
var path = "textures/cube/SwedishRoyalCastle/";
|
|
var format = '.jpg';
|
|
var urls = [
|
|
path + 'px' + format, path + 'nx' + format,
|
|
path + 'py' + format, path + 'ny' + format,
|
|
path + 'pz' + format, path + 'nz' + format
|
|
];
|
|
|
|
var reflectionCube = new THREE.CubeTextureLoader().load( urls );
|
|
reflectionCube.format = THREE.RGBFormat;
|
|
|
|
var refractionCube = new THREE.CubeTextureLoader().load( urls );
|
|
refractionCube.mapping = THREE.CubeRefractionMapping;
|
|
refractionCube.format = THREE.RGBFormat;
|
|
|
|
scene = new THREE.Scene();
|
|
scene.background = reflectionCube;
|
|
|
|
//lights
|
|
var ambient = new THREE.AmbientLight( 0xffffff );
|
|
scene.add( ambient );
|
|
|
|
pointLight = new THREE.PointLight( 0xffffff, 2 );
|
|
scene.add( pointLight );
|
|
|
|
//materials
|
|
var cubeMaterial3 = new THREE.MeshLambertMaterial( { color: 0xff6600, envMap: reflectionCube, combine: THREE.MixOperation, reflectivity: 0.3 } );
|
|
var cubeMaterial2 = new THREE.MeshLambertMaterial( { color: 0xffee00, envMap: refractionCube, refractionRatio: 0.95 } );
|
|
var cubeMaterial1 = new THREE.MeshLambertMaterial( { color: 0xffffff, envMap: reflectionCube } );
|
|
|
|
//models
|
|
var objLoader = new THREE.OBJLoader();
|
|
|
|
objLoader.setPath( 'models/obj/walt/' );
|
|
objLoader.load( 'WaltHead.obj', function ( object ) {
|
|
|
|
var head = object.children[ 0 ];
|
|
|
|
head.scale.multiplyScalar( 15 );
|
|
head.position.y = - 500;
|
|
head.material = cubeMaterial1;
|
|
|
|
var head2 = head.clone();
|
|
head2.position.x = - 900;
|
|
head2.material = cubeMaterial2;
|
|
|
|
var head3 = head.clone();
|
|
head3.position.x = 900;
|
|
head3.material = cubeMaterial3;
|
|
|
|
scene.add( head, head2, head3 );
|
|
|
|
} );
|
|
|
|
//renderer
|
|
renderer = new THREE.WebGLRenderer();
|
|
renderer.setPixelRatio( window.devicePixelRatio );
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
container.appendChild( renderer.domElement );
|
|
|
|
//stats
|
|
stats = new Stats();
|
|
container.appendChild( stats.dom );
|
|
|
|
window.addEventListener( 'resize', onWindowResize, false );
|
|
|
|
}
|
|
|
|
function onWindowResize() {
|
|
|
|
camera.aspect = window.innerWidth / window.innerHeight;
|
|
camera.updateProjectionMatrix();
|
|
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
|
}
|
|
|
|
function animate() {
|
|
|
|
requestAnimationFrame( animate );
|
|
render();
|
|
|
|
}
|
|
|
|
function render() {
|
|
|
|
renderer.render( scene, camera );
|
|
stats.update();
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|