forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaterials_cubemap_balls_refraction.html
149 lines (107 loc) · 3.91 KB
/
materials_cubemap_balls_refraction.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>three.js - webgl cube refraction [balls]</title>
<meta charset="utf-8">
<style type="text/css">
body {
background:#fff;
padding:0;
margin:0;
font-weight: bold;
overflow:hidden;
}
#info {
position: absolute;
top: 0px; width: 100%;
color: #ffffff;
padding: 5px;
font-family:Monospace;
font-size:13px;
text-align:center;
z-index:1000;
}
a {
color: #ffffff;
}
</style>
</head>
<body>
<div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - webgl cube refraction demo. skybox by <a href="http://www.zfight.com/" target="_blank">Jochum Skoglund</a></div>
<script type="text/javascript" src="../build/ThreeExtras.js"></script>
<script type="text/javascript" src="js/Stats.js"></script>
<script type="text/javascript">
var statsEnabled = false;
var container, stats;
var camera, scene, webglRenderer;
var cameraCube, sceneCube;
var mesh, zmesh, lightMesh, geometry;
var directionalLight, pointLight;
var mouseX = 0;
var mouseY = 0;
var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
init();
setInterval( loop, 1000 / 60 );
function init() {
container = document.createElement('div');
document.body.appendChild(container);
camera = new THREE.Camera( 60, window.innerWidth / window.innerHeight, 1, 100000 );
camera.position.z = 3200;
cameraCube = new THREE.Camera( 60, window.innerWidth / window.innerHeight, 1, 100000 );
scene = new THREE.Scene();
sceneCube = new THREE.Scene();
var geometry = new Sphere( 100, 32, 16 );
geometry.sortFacesByMaterial();
var path = "textures/cube/skybox/";
var format = '.jpg';
var urls = [
path + 'px' + format, path + 'nx' + format,
path + 'py' + format, path + 'ny' + format,
path + 'pz' + format, path + 'nz' + format
];
var images = ImageUtils.loadArray( urls );
var textureCube = new THREE.Texture( images, new THREE.CubeRefractionMapping() );
var material = new THREE.MeshBasicMaterial( { color: 0xffffff, env_map: textureCube, refraction_ratio: 0.95 } );
for ( var i = 0; i < 200; i ++ ) {
var mesh = new THREE.Mesh( geometry, material );
mesh.position.x = Math.random() * 10000 - 5000;
mesh.position.y = Math.random() * 10000 - 5000;
mesh.position.z = Math.random() * 10000 - 5000;
mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 4 + 1;
scene.addObject( mesh );
}
//SceneUtils.addPanoramaCubePlanes( sceneCube, 100000, images );
//SceneUtils.addPanoramaCube( sceneCube, 100000, images );
SceneUtils.addPanoramaCubeWebGL( sceneCube, 100000, textureCube );
webglRenderer = new THREE.WebGLRenderer();
webglRenderer.setSize( window.innerWidth, window.innerHeight );
webglRenderer.autoClear = false;
container.appendChild( webglRenderer.domElement );
if ( statsEnabled ) {
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
stats.domElement.style.zIndex = 100;
container.appendChild( stats.domElement );
}
}
function onDocumentMouseMove(event) {
mouseX = ( event.clientX - windowHalfX ) * 10;
mouseY = ( event.clientY - windowHalfY ) * 10;
}
function loop() {
camera.position.x += ( mouseX - camera.position.x ) * .05;
camera.position.y += ( - mouseY - camera.position.y ) * .05;
cameraCube.target.position.x = - camera.position.x;
cameraCube.target.position.y = - camera.position.y;
cameraCube.target.position.z = - camera.position.z;
webglRenderer.clear();
webglRenderer.render( sceneCube, cameraCube );
webglRenderer.render( scene, camera );
if ( statsEnabled ) stats.update();
}
</script>
</body>
</html>