-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
147 lines (123 loc) · 4.32 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
<!DOCTYPE html>
<html lang="en-gb">
<head>
<style>
body {
font-family: Arial, sans;
font-size: 10pt;
}
</style>
<title>Demo - Steppe</title>
</head>
<body onload="Demo.run()">
<h1>Steppe</h1>
<h2>Demo</h2>
<h3>JavaScript (HTML5 Canvas)</h3>
<canvas id="canvas" style="height: 400px; width: 640px" height="200"
width="320">
<p>
Your Web browser does not support the canvas element.
</p>
</canvas>
<script>
document.writeln('<' + 'script src="js/Steppe/Compositor.js?' +
Number(new Date()) + '" type="text/javascript">' + '<' + '/script>');
document.writeln('<' + 'script src="js/Steppe/Renderer.js?' +
Number(new Date()) + '" type="text/javascript">' + '<' + '/script>');
</script>
<script type="text/javascript">
const Demo = (function(undefined) {
const _WATER_HEIGHT = 88;
return {
run: function() {
const canvas = document.getElementById('canvas');
const offscreenCanvas = document.createElement('canvas');
offscreenCanvas.width = 320;
offscreenCanvas.height = 200;
const context = canvas.getContext('2d');
const offscreenContext = offscreenCanvas.getContext('2d');
context.fillStyle = '#000';
context.fillRect(0, 0, canvas.width, canvas.height);
const renderer = Steppe.Renderer(offscreenCanvas);
const compositor = Steppe.Compositor();
const images = {
sky: '/images/sky.png',
heightmap: '/images/heightmap.png',
texturemap: '/images/texturemap.png',
sprite: '/images/sprite.png'
};
let image = new Image();
image.onload = _ => {
images.sky = image;
image = new Image();
image.onload = _ => {
images.heightmap = image;
image = new Image();
image.onload = _ => {
images.texturemap = image;
image = new Image();
image.onload = _ => {
images.sprite = image;
draw();
};
image.src = images.sprite;
};
image.src = images.texturemap;
};
image.src = images.heightmap;
};
image.src = images.sky;
const draw = function() {
const skyCanvas = document.createElement('canvas');
skyCanvas.width = 1920;
skyCanvas.height = 100;
const skyContext = skyCanvas.getContext('2d');
skyContext.drawImage(images['sky'], 0, 0);
const heightmapCanvas = document.createElement('canvas');
heightmapCanvas.width = 1024;
heightmapCanvas.height = 1024;
const heightmapContext = heightmapCanvas.getContext('2d');
heightmapContext.drawImage(images['heightmap'], 0, 0, 1024, 1024);
compositor.setHeightmap(heightmapCanvas);
const texturemapCanvas = document.createElement('canvas');
texturemapCanvas.width = 1024;
texturemapCanvas.height = 1024;
texturemapContext = texturemapCanvas.getContext('2d');
texturemapContext.drawImage(images['texturemap'], 0, 0, 1024, 1024);
renderer.setTexturemap(texturemapCanvas)
.setOutOfBoundsTexturemap(heightmapCanvas)
.setQuality('high')
.setSky(skyCanvas)
.setHeightmap(compositor.getHeightmap())
.setOutOfBoundsHeightmap(
compositor.getOutOfBoundsHeightmap())
.enable('fog')
.setFogColor('#9f8f7f')
.enable('smooth')
.enable('reflection-map')
.setWaterHeight(82)
;
renderer.addSprite(images['sprite'], 1024 + 512 - 128,
renderer.getHeight(1024 + 512 - 128, 1024 + 512 + 32),
1024 + 512 + 32);
/*renderer.addSprite(images['sprite'], 1024 + 512 - 32,
renderer.getHeight(1024 + 512 - 32, 1024 + 512 + 128 + 32),
1024 + 512 + 128 + 32);*/
renderer.addSprite(images['sprite'], 1024 + 512 + 32,
renderer.getHeight(1024 + 512 + 32, 1024 + 512 + 256),
1024 + 512 + 256);
renderer.setCamera({
angle: 255,
x: 1024 + 768 - 128 - 96,
y: renderer.getHeight(1024 + 768 - 128 - 96, 1024 + 768 + 128),
z: 1024 + 768 + 128
});
renderer.render();
context.drawImage(offscreenCanvas, 0, 0, canvas.width, canvas.height);
};
}
};
})();
</script>
</body>
</html>