-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
199 lines (161 loc) · 5.6 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
<!DOCTYPE html><html><head><title>The Ponies</title>
<style type="text/css">
html, body {
background:
url(images/src/transparent_background.png);
width: 100%; height: 100%;
margin: 0; padding: 0;
overflow: hidden;
}
</style>
<script type="text/javascript">
/**
* Ensure scritps are loaded in order!
*
* @param String url Optional, if specified the queue script for laoding.
*
* @return void
*/
window.include = function(url) {
self = this.include
if (undefined === self.included) {
self.included = []
}
if (url !== undefined) {
script = document.createElement('script')
script.src = url
script.onload = function() {window.include()}
if (undefined === self.includes) {
self.includes = Array()
document.head.appendChild(script)
self.included.push(script)
} else {
self.includes.push(script)
}
} else {
if (0 === self.includes.length) {
self.includes = undefined
} else {
script = self.includes.shift()
document.head.appendChild(script)
self.included.push(script)
}
}
}
window.onload = function() {this.main()};
include('js/json.js')
include('js/log.js')
include('js/uuid.js')
include('js/ajax.js')
include('js/three-js/three.min.js')
// include('js/svg.js')
// include('js/equestria.js')
include('js/three-js/OrbitControls.js')
include('js/three-js/BasicShader.js')
include('js/three-js/stats.min.js')
include('js/three-js/hilbert2D.js')
// include('js/three-js/CSS3DRenderer.js')
include('js/the-ponies/settings.js')
include('js/the-ponies/texture.js')
include('js/the-ponies/tile-engine.js')
var camera, renderer;
var objects = [];
window.main = function () {
texture.init();
// Stats
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
document.body.appendChild( stats.domElement );
// Viewing Window
var scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(
settings.fov, window.innerWidth / window.innerHeight,
settings.clipNear, 10000
);
controls = new THREE.OrbitControls( camera );
controls.addEventListener( 'change', render );
renderer = new THREE.WebGLRenderer({ alpha: true });
renderer.setSize(
settings.renderResolutionWidth,
settings.renderResolutionHeight
);
document.body.appendChild( renderer.domElement );
// Game Geometry
// Tiles
hilbert_index = [].concat(
hilbert2D(
new THREE.Vector3(0, 0.2, 0),
1600,
3
)
);
grid_segment = hilbert_index[0].distanceTo(hilbert_index[1])
grid_segment_half = grid_segment / 2
tiles = [];
for (var i = hilbert_index.length - 1; i >= 0; i--) {
hilbert_index[i].vertex = hilbert_index[i];
hilbert_index[i].geometry = new THREE.PlaneGeometry(grid_segment, grid_segment);
// Grid Lines
var gridline_material = new THREE.LineBasicMaterial({ color: 0x0000ff });
var gridline_geometry = new THREE.Geometry();
// Note, lines not optimized! basically every line that isn't on the edge is overlaping another line.
gridline_geometry.vertices.push(new THREE.Vector3(hilbert_index[i].vertex.x - grid_segment_half, 2, hilbert_index[i].vertex.z + grid_segment_half));
gridline_geometry.vertices.push(new THREE.Vector3(hilbert_index[i].vertex.x + grid_segment_half, 2, hilbert_index[i].vertex.z + grid_segment_half));
gridline_geometry.vertices.push(new THREE.Vector3(hilbert_index[i].vertex.x + grid_segment_half, 2, hilbert_index[i].vertex.z - grid_segment_half));
gridline_geometry.vertices.push(new THREE.Vector3(hilbert_index[i].vertex.x - grid_segment_half, 2, hilbert_index[i].vertex.z - grid_segment_half));
gridline_geometry.vertices.push(gridline_geometry.vertices[0]);
var gridline = new THREE.Line(gridline_geometry, gridline_material);
scene.add(gridline);
// Grid Lines End
// I for got what this for loop was supposed to do, it can probably go.
for (a in texture.textures) break;
hilbert_index[i].material = texture[texture.textures['BonesWolbach Dry Summer Grass']].material;
hilbert_index[i].mesh = new THREE.Mesh(
hilbert_index[i].geometry,
hilbert_index[i].material
);
hilbert_index[i].mesh.position.x = hilbert_index[i].vertex.x;
hilbert_index[i].mesh.position.z = hilbert_index[i].vertex.z;
hilbert_index[i].mesh.lookAt(new THREE.Vector3(hilbert_index[i].mesh.position.x, 1, hilbert_index[i].mesh.position.z));
scene.add(hilbert_index[i].mesh);
};
// Camera
camera.position.y = 100;
camera.position.x = 100;
camera.position.z = 100;
// camera.rotation.y += 0.01;
// SKYBOX
// var axes = new THREE.AxisHelper((settings.clipFar - 10) / 1.414);
var axes = new THREE.AxisHelper(5000);
axes.rotation.y = Math.PI/4;
scene.add( axes );
var imagePrefix = "images/src/skybox-ponyville-by-boneswolbach-512/";
var directions = ["RIGHT", "LEFT", "TOP", "BOTTOM", "FRONT", "BACK"];
var imageSuffix = ".png";
var skyGeometry = new THREE.CubeGeometry( 5000, 5000, 5000 );
var materialArray = [];
for (var i = 0; i < 6; i++)
materialArray.push( new THREE.MeshBasicMaterial({
map: THREE.ImageUtils.loadTexture( imagePrefix + directions[i] + imageSuffix ),
side: THREE.BackSide
}));
var skyMaterial = new THREE.MeshFaceMaterial( materialArray );
var skyBox = new THREE.Mesh( skyGeometry, skyMaterial );
skyBox.rotation.y = Math.PI/4;
skyBox.position.y = 200
scene.add( skyBox );
// Render Loop
function animate() {
requestAnimationFrame( animate );
render();
stats.update();
}
function render() {
var timer = Date.now() * 0.0001;
camera.lookAt( scene.position );
renderer.render( scene, camera );
}
animate()
}
</script></head><body></body></html>