-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
249 lines (187 loc) · 6.93 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
<!DOCTYPE html>
<html>
<head>
<title>Example 10.05 - Env map</title>
<script type="text/javascript" src="libs/three.js"></script>
<script type="text/javascript" src="libs/jquery-1.9.0.js"></script>
<script type="text/javascript" src="libs/stats.js"></script>
<script type="text/javascript" src="libs/dat.gui.js"></script>
<style>
body {
/* set margin to 0 and overflow to hidden, to go fullscreen */
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<div id="Stats-output">
</div>
<div id="WebGL-output">
</div>
<script type="text/javascript">
$(function () {
//var stats = initStats();
var scene = new THREE.Scene();
var sceneCube = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
var cameraCube = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 1000);
var webGLRenderer = new THREE.WebGLRenderer();
webGLRenderer.setClearColorHex(0xEEEEEE, 1.0);
webGLRenderer.setSize(window.innerWidth, window.innerHeight);
webGLRenderer.shadowMapEnabled = false;
webGLRenderer.autoClear = false;
var textureCube = createCubeMap();
var shader = THREE.ShaderLib[ "cube" ];
shader.uniforms[ "tCube" ].value = textureCube;
var material = new THREE.ShaderMaterial({
fragmentShader: shader.fragmentShader,
vertexShader: shader.vertexShader,
uniforms: shader.uniforms,
depthWrite: false,
side: THREE.BackSide
});
cubeMesh = new THREE.Mesh(new THREE.CubeGeometry(100, 100, 100), material);
sceneCube.add(cubeMesh);
var sphere1 = createMesh(new THREE.SphereGeometry(10, 15, 15), "plaster.jpg");
sphere1.material.envMap = textureCube;
sphere1.rotation.y = -0.5;
sphere1.position.x = 12;
sphere1.position.y = 5;
scene.add(sphere1);
/*
var sphereGeom = new THREE.SphereGeometry( 10, 15, 15 );
var refractSphereCamera = new THREE.CubeCamera( 0.1, 5000, 512 );
scene.add( refractSphereCamera );
refractSphereCamera.renderTarget.mapping = new THREE.CubeRefractionMapping();
var refractMaterial = new THREE.MeshBasicMaterial( {
color: 0xccccff,
envMap: refractSphereCamera.renderTarget,
refractionRatio: 0.985,
reflectivity: 0.9
} );
refractSphere = new THREE.Mesh( sphereGeom, refractMaterial );
refractSphere.position.set(0,50,0);
refractSphereCamera.position = refractSphere.position;
scene.add(refractSphere);
*/
// position and point the camera to the center of the scene
camera.position.x = 00;
camera.position.y = 12;
camera.position.z = 68;
camera.lookAt(new THREE.Vector3(0, 0, 0));
var ambiLight = new THREE.AmbientLight(0xffffff)
scene.add(ambiLight);
var light = new THREE.SpotLight();
light.position.set(0, 30, 30);
light.intensity = 1.2;
scene.add(light);
// var pointColor = "#ff5808";
var pointColor = "#ff5808";
var directionalLight = new THREE.PointLight(pointColor);
directionalLight.intensity = 4.5;
// directionalLight.distance = 0;
// directionalLight.intensity = 0.5;
scene.add(directionalLight);
var sphereLight = new THREE.SphereGeometry(0.2);
var sphereLightMaterial = new THREE.MeshBasicMaterial({color: 0xac6c25});
var sphereLightMesh = new THREE.Mesh(sphereLight, sphereLightMaterial);
sphereLightMesh.castShadow = true;
sphereLightMesh.position = new THREE.Vector3(3, 3, 3);
scene.add(sphereLightMesh);
$("#WebGL-output").append(webGLRenderer.domElement);
var step = 0;
render();
function createMesh(geom, texture, normal) {
//geom.computeVertexNormals();
if (normal) {
var t = THREE.ImageUtils.loadTexture("assets/" + texture);
var m = THREE.ImageUtils.loadTexture("assets/" + normal);
var mat2 = new THREE.MeshPhongMaterial({
map: t,
normalMap: m
});
var mesh = new THREE.Mesh(geom, mat2);
return mesh;
} else {
var t = THREE.ImageUtils.loadTexture("assets/" + texture);
var mat1 = new THREE.MeshPhongMaterial({
})
var mesh = new THREE.Mesh(geom, mat1);
return mesh;
}
return mesh;
}
function createCubeMap() {
var path = "assets/";
var format = '.jpg';
var urls = [
path + 'posx' + format, path + 'negx' + format,
path + 'posy' + format, path + 'negy' + format,
path + 'posz' + format, path + 'negz' + format
];
// var textureCube = THREE.ImageUtils.loadTextureCube( urls );
var textureCube = THREE.ImageUtils.loadTextureCube(urls, new THREE.CubeReflectionMapping());
return textureCube;
}
var invert = 1;
var phase = 0;
var mouseX = 0;
var mouseY = 0;
document.addEventListener('mousemove', onDocumentMouseMove, false);
function onDocumentMouseMove(event) {
mouseX = ( event.clientX - window.innerWidth / 2 ) * 10;
mouseY = ( event.clientY - window.innerHeight / 2 ) * 10;
}
function render() {
step += 0.1;
/*if (controls.rotate) {
sphere1.rotation.y -= 0.01;
sphere2.rotation.y += 0.01;
}*/
if (phase > 2 * Math.PI) {
invert = invert * -1;
phase -= 2 * Math.PI;
} else {
phase += 0.03;
}
sphereLightMesh.position.z = +(21 * (Math.sin(phase)));
sphereLightMesh.position.x = -14 + (14 * (Math.cos(phase)));
if (invert < 0) {
var pivot = 0;
sphereLightMesh.position.x = (invert * (sphereLightMesh.position.x - pivot)) + pivot;
}
directionalLight.position = sphereLightMesh.position;
camera.position.x = (mouseX * .018);
camera.position.y = 6 + (mouseY * .018);
// camera.position.y += ( - mouseY - camera.position.y ) * .005;
// console.log(mouseX + "," + mouseY);
camera.lookAt(scene.position);
cameraCube.rotation = camera.rotation;
// sphere1.rotation.y=step+=0.01;
// sphere1.rotation.x=step;
// sphere2.rotation.y=step;
// sphere2.rotation.x=step;
// render using requestAnimationFrame
requestAnimationFrame(render);
webGLRenderer.render(sceneCube, cameraCube);
webGLRenderer.render(scene, camera);
//
<!---->
}
/*
function initStats() {
var stats = new Stats();
stats.setMode(0); // 0: fps, 1: ms
// Align top-left
stats.domElement.style.position = 'absolute';
stats.domElement.style.left = '0px';
stats.domElement.style.top = '0px';
$("#Stats-output").append(stats.domElement);
return stats;
}
*/
});
</script>
</body>
</html>