-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
157 lines (125 loc) · 5.94 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
<html>
<head>
<title>Three.js </title>
<style>
body {margin: 0;}
canvas {width: 100%; height: 100%};
</style>
</head>
<body>
<script src="js/three.js"></script>
<script src="js/OrbitControls.js"></script>
<script src="js/ObjectLoader.js"></script>
<script src="js/AnaglyphEffect.js"></script>
<script>
// add frame plugin
(function(){
var script=document.createElement('script');
script.onload=function(){
var stats=new Stats();document.body.appendChild(stats.dom);
requestAnimationFrame(function loop(){stats.update();
requestAnimationFrame(loop)})
;
};
script.src='//rawgit.com/mrdoob/stats.js/master/build/stats.min.js';document.head.appendChild(script);})()
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 90, window.innerWidth / window.innerHeight, 0.1, 1000);
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth , window.innerHeight );
document.body.appendChild(renderer.domElement);
// resize the viewpoint
window.addEventListener( 'resize', function() {
var width = window.innerWidth;
var height = window.innerHeight;
renderer.setSize(width, height);
camera.aspect = width / height ;
//Updates the camera projection matrix. Must be called after any change of parameters.
camera.updateProjectionMatrix();
});
// add anaglyph effect
var effect = new THREE.AnaglyphEffect( renderer);
effect.setSize(window.innerWidth, window.innerHeight);
// add skybox
var geometry = new THREE.CubeGeometry(10000, 1000, 1000);
var cubeMaterials = [
new THREE.MeshBasicMaterial( {map: new THREE.TextureLoader().load( 'imgs/Skybox/right.png'), side: THREE.DoubleSide} ),
new THREE.MeshBasicMaterial( {map: new THREE.TextureLoader().load( 'imgs/Skybox/left.png'), side: THREE.DoubleSide} ),
new THREE.MeshBasicMaterial( {map: new THREE.TextureLoader().load( 'imgs/Skybox/up.png'), side: THREE.DoubleSide} ),
new THREE.MeshBasicMaterial( {map: new THREE.TextureLoader().load( 'imgs/Skybox/down.png'), side: THREE.DoubleSide} ),
new THREE.MeshBasicMaterial( {map: new THREE.TextureLoader().load( 'imgs/Skybox/front.png'), side: THREE.DoubleSide} ),
new THREE.MeshBasicMaterial( {map: new THREE.TextureLoader().load( 'imgs/Skybox/back.png'), side: THREE.DoubleSide} ),
];
var cubeMaterial = new THREE.MeshFaceMaterial( cubeMaterials);
var cube = new THREE.Mesh(geometry, cubeMaterial);
scene.add( cube );
// add orbit control
controls = new THREE.OrbitControls( camera, renderer.domElement );
// load files
// var loader = new THREE.ObjectLoader( );
//
// loader.load(
// 'models/skull.json',
// function ( object ) {
// scene.add(object)
// }
// );
// create the shape
// var geometry = new THREE.BoxGeometry( 1, 1, 1);
// var cubeMaterials = [
//
// new THREE.MeshBasicMaterial( {color: 'white', side: THREE.DoubleSide } ) , // RIGHT
// new THREE.MeshPhongMaterial( {color: 'black', side: THREE.DoubleSide } ) , // LEFT
// new THREE.MeshLambertMaterial( {color: 'blue', side: THREE.DoubleSide } ) , // TOP
// new THREE.MeshPhongMaterial( {color: 'orange', side: THREE.DoubleSide } ) , // BOTTOM
// new THREE.MeshLambertMaterial( {color: 'yellow', side: THREE.DoubleSide } ) , // FRONT
// new THREE.MeshBasicMaterial( {color: 'white',side: THREE.DoubleSide } ) , // BACK
// ];
// create a material, color or image texture
// var material = new THREE.MeshFaceMaterial( cubeMaterials );
// var cube = new THREE.Mesh( geometry, material);
// scene.add(cube);
camera.position.z = 7;
var ambientLight = new THREE.AmbientLight( 0xFFFFFF, 0.5);
scene.add( ambientLight );
var light1 = new THREE.PointLight( 0xFF0040, 4, 50);
scene.add(light1);
var light2 = new THREE.PointLight( 0x0040FF, 3, 50);
scene.add(light2);
var light3 = new THREE.PointLight( 0x80FF80, 4, 50);
scene.add(light3);
var directionalLight = new THREE.DirectionalLight( 0xFFFFFF ,1 );
directionalLight.position.set( 0, 1, 0);
scene.add( directionalLight );
var spotLight = new THREE.SpotLight( 0xFF45F6, 25);
spotLight.position.set( 0, 3, 0);
scene.add( spotLight );
// game logic
var update = function() {
// cube.rotation.x += 0.01;
// cube.rotation.y += 0.01;
// change point light position
var time = Date.now( ) * 0.0005;
light1.position.x = Math.sin(time * 0.7) * 30;
light1.position.y = Math.cos(time * 0.5) * 40;
light1.position.z = Math.cos(time * 0.3) * 30;
light2.position.x = Math.cos(time * 0.3) * 30;
light2.position.y = Math.sin(time * 0.5) * 40;
light2.position.z = Math.sin(time * 0.7) * 30;
light3.position.x = Math.sin(time * 0.7) * 30;
light3.position.y = Math.cos(time * 0.3) * 40;
light3.position.z = Math.sin(time * 0.5) * 30;
};
//draw Scene
var render = function() {
renderer.render(scene, camera);
};
// run game loop (update, render, repeat)
var GameLoop = function () {
requestAnimationFrame(GameLoop);
update();
render();
};
GameLoop( );
</script>
</body>
</html>