-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.js
244 lines (156 loc) · 6.07 KB
/
init.js
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
if (!Detector.webgl)
Detector.addGetWebGLMessage();
var SCREEN_WIDTH = window.innerWidth;
var SCREEN_HEIGHT = window.innerHeight;
var container, stats;
var camera, scene, renderer, geometry, terrain, meterial_g;
var PointLight;
var scan, bibutats;
var num = 0;
var mouseX = 0, mouseY = 0;
var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
var controls, time = Date.now();
var clock = new THREE.Clock();
var composer, effectFXAA;
init();
animate();
function init() {
this.init = true;
container = document.createElement('div');
document.body.appendChild(container);
renderer = new THREE.WebGLRenderer({antialias: true});
camera = new THREE.PerspectiveCamera(35, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 2500);
scene = new THREE.Scene();
scene = new THREE.Scene();
PointLight = new pointlight(scene);
scene.add( camera );
scene.fog = new THREE.FogExp2( 0x050510, 0.0025 );
//scene.fog = new THREE.Fog( 'rgb( 50, 50, 50 )', 1, 700 );
//scene.fog.color = new THREE.Color( 20, 20, 20 );
scene.add(camera);
scene.fog = new THREE.FogExp2(0x050510, 0.0025);
scene.add(new THREE.AmbientLight('rgb(5,5,20)'));
directionalLight = new THREE.DirectionalLight(0xffffff, 1.15);
directionalLight.position.set(500, 2000, 0);
scene.add(directionalLight);
var maxAnisotropy = renderer.getMaxAnisotropy();
if (maxAnisotropy > 0) {
document.getElementById("val_left").innerHTML = maxAnisotropy;
} else {
document.getElementById("val_left").innerHTML = "not supported";
document.getElementById("val_right").innerHTML = "not supported";
}
terrain = new terrain(scene, maxAnisotropy);
terrain.MakeBiburats();
terrain.energyLines=[];
var mat = new THREE.MeshLambertMaterial({color: 0xffffff, shading: THREE.FlatShading, overdraw: true});
sphere = new THREE.Mesh(new THREE.SphereGeometry(20, 20, 10), mat);
sphere.position.z = -150;
sphere.position.x = -50;
sphere.updateMatrix();
sphere.name = "factory";
scene.add(sphere);
stats = new Stats();
container.appendChild( stats.domElement );
loader = new THREE.JSONLoader();
loader.load('model/fabric.json', function(geometry) {
// sphere.num = UTILS.addLineColor(scene,1,15)-1;
// terrain.energyLines.push(sphere);
for (var i = 0; i < 20; i++) {
meterial_g = new THREE.MeshLambertMaterial({color: 0xffffff, shading: THREE.FlatShading, overdraw: true});
mesh1 = new THREE.Mesh(geometry, meterial_g);
mesh1.position.x = Math.random() * 1000 - 500;
mesh1.position.z = Math.random() * 1000 - 500;
// mesh1.geometry.boundingSphere.radius = 10;
mesh1.updateMatrix();
mesh1.name = "sphere";
mesh1.num = UTILS.addLineColor(scene,1,15)-1;
UTILS.lines[mesh1.num].position.copy(mesh1.position);
UTILS.lines[mesh1.num].updateMatrix();
terrain.energyLines.push(mesh1);
scene.add( mesh1 );
}
terrain.InitEnergyLines();
});
// RENDERER
renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
renderer.setClearColor(scene.fog.color, 1);
renderer.autoClear = false;
renderer.domElement.style.position = "relative";
container.appendChild(renderer.domElement);
// STATS1
stats = new Stats();
container.appendChild(stats.domElement);
controls = new THREE.PointerLockControls(camera);
scene.add(controls.getObject());
controls.enabled = true;
var renderModel = new THREE.RenderPass(scene, camera);
var effectBloom = new THREE.BloomPass(1.2);
var effectCopy = new THREE.ShaderPass(THREE.CopyShader);
effectFXAA = new THREE.ShaderPass(THREE.FXAAShader);
var width = window.innerWidth || 2;
var height = window.innerHeight || 2;
effectFXAA.uniforms[ 'resolution' ].value.set(1 / width, 1 / height);
effectCopy.renderToScreen = true;
composer = new THREE.EffectComposer(renderer);
composer.addPass(renderModel);
//composer.addPass( effectFXAA );
//composer.addPass( effectBloom );
composer.addPass(effectCopy);
scene.fireLaser = laser;
// UTILS.addLine(scene);//DEBUG
// UTILS.addLineColor(scene);//DEBUG
// UTILS.addLineColor(scene);//DEBUG
// UTILS.addLine(scene);//DEBUG
scan = new scaner(container, scene, controls.getObject(), SCREEN_HEIGHT / 2, SCREEN_HEIGHT / 2);
}
function animate() {
requestAnimationFrame(animate);
render();
stats.update();
}
// document.getElementById( "val_right" ).innerHTML = vv;
function render() {
var delta_time = clock.getDelta();
controls.update( delta_time * 10);
terrain.update(controls.getObject());
mouseX = 0;
var collision = false;
for (var index in scene.children) {
mouseX += 1;
var object = scene.children[index];
if (true === controls.CheckCollisionWithCamera(object)) {
collision = true;
}
if ("update" in object) {
object.update(delta_time);
}
}
if (collision === false) {
controls.controlSet(true);
}
scan.update(delta_time);
if (document.getElementById( "val_left" )){
document.getElementById( "val_left" ).innerHTML = controls.vv;
}
renderer.clear();
composer.render();
time = Date.now();
}
var onKeyDownMain = function(event) {
if (event.keyCode === 32) { // Пробел
scene.fireLaser(controls.getObject());
}
};
document.addEventListener( 'keydown', onKeyDownMain, false );
function onWindowResize() {
SCREEN_WIDTH = window.innerWidth;
SCREEN_HEIGHT = window.innerHeight;
camera.aspect = SCREEN_WIDTH / SCREEN_HEIGHT;
camera.updateProjectionMatrix();
renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
scan.remove();
scan = new scaner(container, scene, controls.getObject(), SCREEN_HEIGHT / 2, SCREEN_HEIGHT / 2);
}
window.addEventListener( 'resize', onWindowResize, false );