-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·295 lines (239 loc) · 7.4 KB
/
index.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<!doctype html>
<html lang="en">
<head>
<title>Massification</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link rel=stylesheet href="css/base.css"/>
</head>
<body>
<script src="js/three.min.js"></script>
<script src="js/Detector.js"></script>
<script src="js/Stats.js"></script>
<script src="js/OrbitControls.js"></script>
<script src="js/THREEx.KeyboardState.js"></script>
<script src="js/THREEx.FullScreen.js"></script>
<script src="js/THREEx.WindowResize.js"></script>
<script src="OBJLoader.js"></script>
<script src="js/shaders/FresnelShader.js"></script>
This three.js demo is part of a collection at
<a href="http://stemkoski.github.io/Three.js/">http://stemkoski.github.io/Three.js/</a>
</div>
<!-- ------------------------------------------------------------ -->
<div id="ThreeJS" style="position: absolute; left:0px; top:0px"></div>
<script>
/*
Three.js "tutorials by example"
Author: Lee Stemkoski
Date: July 2013 (three.js v59dev)
*/
// MAIN
// standard global variables
var container, scene, camera, renderer, controls, stats;
var keyboard = new THREEx.KeyboardState();
var clock = new THREE.Clock();
// custom global variables
var cube;
var fresnelUniforms;
var center;
init();
animate();
// FUNCTIONS
function init()
{
// SCENE
scene = new THREE.Scene();
// CAMERA
var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight;
var VIEW_ANGLE = 45, ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT, NEAR = 0.1, FAR = 20000;
camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR);
scene.add(camera);
camera.position.set(60,50,60);
camera.up = new THREE.Vector3(0,1,0);
center = new THREE.Vector3(
20,
20,
20
)
// RENDERER
if ( Detector.webgl )
renderer = new THREE.WebGLRenderer( {antialias:true} );
else
renderer = new THREE.CanvasRenderer();
renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
container = document.getElementById( 'ThreeJS' );
container.appendChild( renderer.domElement );
// EVENTS
THREEx.WindowResize(renderer, camera);
THREEx.FullScreen.bindKey({ charCode : 'm'.charCodeAt(0) });
// CONTROLS
controls = new THREE.OrbitControls( camera, renderer.domElement );
controls.autoRotate = true;
controls.center = center;
// STATS
/*
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.bottom = '0px';
stats.domElement.style.zIndex = 100;
container.appendChild( stats.domElement );
*/
var c = document.getElementById('canvas');
function on_fullscreen_change() {
if(document.mozFullScreen || document.webkitIsFullScreen) {
var rect = c.getBoundingClientRect();
c.width = rect.width;
c.height = rect.height;
}
else {
c.width = 500;
c.height = 400;
}
}
document.addEventListener('mozfullscreenchange', on_fullscreen_change);
document.addEventListener('webkitfullscreenchange', on_fullscreen_change);
// LIGHT
var light = new THREE.PointLight(0xffffff);
light.position.set(0,250,0);
scene.add(light);
camera.lookAt(center);
createStarfield();
// FLOOR
/*
var floorTexture = new THREE.ImageUtils.loadTexture( 'images/checkerboard.jpg' );
floorTexture.wrapS = floorTexture.wrapT = THREE.RepeatWrapping;
floorTexture.repeat.set( 10, 10 );
var floorMaterial = new THREE.MeshBasicMaterial( { map: floorTexture, side: THREE.DoubleSide } );
var floorGeometry = new THREE.PlaneGeometry(1000, 1000, 10, 10);
var floor = new THREE.Mesh(floorGeometry, floorMaterial);
floor.position.y = -50.5;
floor.rotation.x = Math.PI / 2;
scene.add(floor);
*/
// SKYBOX
/*var imagePrefix = "images/dawnmountain-";
var directions = ["xpos", "xneg", "ypos", "yneg", "zpos", "zneg"];
var imageSuffix = ".png";
var skyGeometry = new THREE.CubeGeometry( 5000, 5000, 5000 );
var urls = [];
for (var i = 0; i < 6; i++)
urls.push( imagePrefix + directions[i] + imageSuffix );
var materialArray = [];
for (var i = 0; i < 6; i++)
materialArray.push( new THREE.MeshBasicMaterial({
map: THREE.ImageUtils.loadTexture( 'images/ubican.jpg' ),
side: THREE.BackSide
}));
var skyMaterial = new THREE.MeshFaceMaterial( materialArray );
var skyBox = new THREE.Mesh( skyGeometry, skyMaterial );
*/
//scene.add( skyBox );
////////////
// CUSTOM //
////////////
this.refractSphereCamera = new THREE.CubeCamera( 0.1, 5000, 512 );
scene.add( refractSphereCamera );
var fShader = THREE.FresnelShader;
fresnelUniforms =
{
"mRefractionRatio": { type: "f", value: 1.02 },
"mFresnelBias": { type: "f", value: 2.1 },
"mFresnelPower": { type: "f", value: 1.0 },
"mFresnelScale": { type: "f", value: 1.0 },
"tCube": { type: "t", value: refractSphereCamera.renderTarget } // textureCube }
};
// create custom material for the shader
var customMaterial = new THREE.ShaderMaterial(
{
uniforms: fresnelUniforms,
vertexShader: fShader.vertexShader,
fragmentShader: fShader.fragmentShader
} );
var sphereGeometry = new THREE.SphereGeometry( 100, 64, 32 );
this.sphere = new THREE.Mesh( sphereGeometry, customMaterial );
sphere.position.set(0, 50, 100);
//scene.add(sphere);
refractSphereCamera.position = sphere.position;
omin(customMaterial);
}
function omin(material)
{
/*it π
var material = new THREE.MeshPhongMaterial( {
specular: 0x222222,
shininess: 35
} );
*/
var x = 5, y=5, z=5, offset = 9
var positions = []
for(var xi = 0; xi < x; xi++ ){
for(var yi=0; yi < y; yi++){
for(var zi=0; zi < z; zi++){
positions.push({
x: xi * offset,
y: yi * offset,
z: zi * offset
})
}
}
}
loader = new THREE.OBJLoader();
loader.load('gonzo3.obj', function(object) {
positions.forEach(function(pos){
var obj = object.clone()
obj.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) {
child.material = material;
child.position.y = pos.y;
child.position.x = pos.x;
child.position.z = pos.z;
}
});
scene.add(obj);
})
/*
object.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) {
child.material = material;
child.position.y -= 1 ;
}
})
scene.add(object);*/
})
//
}
function createStarfield() {
// create the geometry sphere
var envGeometry = new THREE.SphereGeometry(120, 132, 132);
// create the material, using a texture of startfield
var envTexture = new THREE.Texture();
var loader = new THREE.ImageLoader();
loader.load('images/total5.jpg', function(image){
envTexture.image = image;
envTexture.needsUpdate = true;
});
var envMaterial = new THREE.MeshBasicMaterial();
envMaterial.map = envTexture;
envMaterial.side = THREE.BackSide;
var mesh = new THREE.Mesh(envGeometry, envMaterial)
scene.add(mesh);
}
function animate()
{
requestAnimationFrame( animate );
render();
controls.update();
}
var i = 0
function normalize(min, max, val){
return (val-min)/(max-min)
}
function render()
{
refractSphereCamera.updateCubeMap( renderer, scene );
renderer.render( scene, camera );
fresnelUniforms.mFresnelBias.value = normalize(-Math.PI/2, Math.PI/2, camera.rotation.y)
}
</script>
</body>
</html>