@openglobus/og 0.13.3 → 0.13.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@openglobus/og.esm.js +2 -2
- package/dist/@openglobus/og.esm.js.map +1 -1
- package/dist/@openglobus/og.umd.js +2 -2
- package/dist/@openglobus/og.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/og/Events.js +188 -188
- package/src/og/Globe.js +1 -0
- package/src/og/control/KeyboardNavigation.js +48 -2
- package/src/og/control/TouchNavigation.js +340 -319
- package/src/og/control/ZoomControl.js +1 -1
- package/src/og/ellipsoid/Ellipsoid.js +1 -1
- package/src/og/entity/Billboard.js +165 -165
- package/src/og/entity/BillboardHandler.js +1 -1
- package/src/og/entity/GeoObject.js +4 -0
- package/src/og/entity/GeoObjectHandler.js +22 -33
- package/src/og/entity/Geometry.js +319 -319
- package/src/og/entity/Label.js +348 -346
- package/src/og/entity/LabelHandler.js +44 -37
- package/src/og/input/input.js +7 -1
- package/src/og/layer/KML.js +181 -12
- package/src/og/layer/Layer.js +4 -2
- package/src/og/renderer/RendererEvents.js +1065 -1051
- package/src/og/scene/Planet.js +45 -27
- package/src/og/shaders/billboard.js +8 -0
- package/src/og/shaders/label.js +56 -13
- package/src/og/terrain/EmptyTerrain.js +159 -146
- package/src/og/terrain/Geoid.js +246 -241
- package/src/og/terrain/GlobusTerrain.js +17 -18
- package/src/og/terrain/MapboxTerrain.js +292 -294
- package/src/og/utils/FontAtlas.js +25 -15
- package/src/og/utils/PlainSegmentWorker.js +38 -26
- package/src/og/utils/TextureAtlas.js +291 -280
- package/types/control/KeyboardNavigation.d.ts +3 -0
- package/types/entity/GeoObject.d.ts +1 -0
- package/types/entity/Label.d.ts +1 -0
- package/types/entity/LabelHandler.d.ts +1 -1
- package/types/input/input.d.ts +6 -0
- package/types/layer/KML.d.ts +26 -1
- package/types/renderer/RendererEvents.d.ts +2 -0
- package/types/scene/Planet.d.ts +5 -0
- package/types/terrain/EmptyTerrain.d.ts +3 -1
- package/types/terrain/Geoid.d.ts +1 -10
- package/types/terrain/GlobusTerrain.d.ts +0 -1
- package/types/terrain/MapboxTerrain.d.ts +1 -1
- package/types/utils/TextureAtlas.d.ts +2 -0
|
@@ -49,30 +49,42 @@ class PlainSegmentWorker {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
setGeoid(geoid) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
52
|
+
|
|
53
|
+
let model = null;
|
|
54
|
+
|
|
55
|
+
if (geoid.model) {
|
|
56
|
+
let m = geoid.model;
|
|
57
|
+
model = {
|
|
58
|
+
scale: m.scale,
|
|
59
|
+
offset: m.offset,
|
|
60
|
+
width: m.width,
|
|
61
|
+
height: m.height,
|
|
62
|
+
rlonres: m.rlonres,
|
|
63
|
+
rlatres: m.rlatres,
|
|
64
|
+
i: m.i
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
this._workerQueue.forEach((w) => {
|
|
68
|
+
let rawfile = new Uint8Array(m.rawfile.length);
|
|
69
|
+
rawfile.set(m.rawfile);
|
|
70
|
+
|
|
71
|
+
w.postMessage(
|
|
72
|
+
{
|
|
73
|
+
model: model,
|
|
74
|
+
rawfile: rawfile
|
|
75
|
+
},
|
|
76
|
+
[rawfile.buffer]
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
} else {
|
|
80
|
+
this._workerQueue.forEach((w) => {
|
|
81
|
+
w.postMessage(
|
|
82
|
+
{
|
|
83
|
+
model: null
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
76
88
|
}
|
|
77
89
|
|
|
78
90
|
make(segment) {
|
|
@@ -116,6 +128,8 @@ class PlainSegmentWorker {
|
|
|
116
128
|
|
|
117
129
|
const _programm = `
|
|
118
130
|
'use strict';
|
|
131
|
+
|
|
132
|
+
let model = null;
|
|
119
133
|
|
|
120
134
|
let cached_ix = null;
|
|
121
135
|
let cached_iy = null;
|
|
@@ -185,8 +199,6 @@ const _programm = `
|
|
|
185
199
|
return model.offset + model.scale * h;
|
|
186
200
|
};
|
|
187
201
|
|
|
188
|
-
let model = null;
|
|
189
|
-
|
|
190
202
|
const HALF_PI = Math.PI * 0.5;
|
|
191
203
|
const POLE = 20037508.34;
|
|
192
204
|
const PI_BY_POLE = Math.PI / POLE;
|
|
@@ -1,280 +1,291 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { ImageCanvas } from "../ImageCanvas.js";
|
|
4
|
-
import { Rectangle } from "../Rectangle.js";
|
|
5
|
-
import { ImagesCacheManager } from "./ImagesCacheManager.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Texture atlas stores images in one texture. Each image has its own
|
|
9
|
-
* atlas texture coordinates.
|
|
10
|
-
* @class
|
|
11
|
-
* @param {number} [width] - Texture atlas width, if it hasn't 1024 default.
|
|
12
|
-
* @param {number} [height] - Texture atlas height, if it hasn't 1024 default..
|
|
13
|
-
*/
|
|
14
|
-
class TextureAtlas {
|
|
15
|
-
constructor(width = 1024, height = 1024) {
|
|
16
|
-
/**
|
|
17
|
-
* Atlas nodes where input images store. It can be access by image.__nodeIndex.
|
|
18
|
-
* @public
|
|
19
|
-
* @type {Array.<utils.TextureAtlasNode >}
|
|
20
|
-
*/
|
|
21
|
-
this.nodes =
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Created gl texture.
|
|
25
|
-
* @public
|
|
26
|
-
*/
|
|
27
|
-
this.texture = null;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Atlas canvas.
|
|
31
|
-
* @public
|
|
32
|
-
* @type {canvas}
|
|
33
|
-
*/
|
|
34
|
-
this.canvas = new ImageCanvas(width, height);
|
|
35
|
-
this.clearCanvas();
|
|
36
|
-
|
|
37
|
-
this._handler = null;
|
|
38
|
-
this._images = [];
|
|
39
|
-
this._btree = null;
|
|
40
|
-
this._imagesCacheManager = new ImagesCacheManager();
|
|
41
|
-
this.borderSize = 4;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Returns atlas javascript image object.
|
|
46
|
-
* @public
|
|
47
|
-
* @returns {Object} -
|
|
48
|
-
*/
|
|
49
|
-
getImage() {
|
|
50
|
-
return this.canvas.getImage();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Returns canvas object.
|
|
55
|
-
* @public
|
|
56
|
-
* @returns {Object} -
|
|
57
|
-
*/
|
|
58
|
-
getCanvas() {
|
|
59
|
-
return this.canvas._canvas;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Clear atlas with black.
|
|
64
|
-
* @public
|
|
65
|
-
*/
|
|
66
|
-
clearCanvas() {
|
|
67
|
-
this.canvas.fillEmpty("black");
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Sets openglobus gl handler that creates gl texture.
|
|
72
|
-
* @public
|
|
73
|
-
* @param {Handler} handler - WebGL handler.
|
|
74
|
-
*/
|
|
75
|
-
assignHandler(handler) {
|
|
76
|
-
this._handler = handler;
|
|
77
|
-
this.createTexture();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Returns image diagonal size.
|
|
82
|
-
* @param {Object} image - JavaSript image object.
|
|
83
|
-
* @returns {number} -
|
|
84
|
-
*/
|
|
85
|
-
getDiagonal(image) {
|
|
86
|
-
var w = image.atlasWidth || image.width,
|
|
87
|
-
h = image.atlasHeight || image.height;
|
|
88
|
-
return Math.sqrt(w * w + h * h);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Adds image to the atlas and returns creted node with texture coordinates of the stored image.
|
|
93
|
-
* @public
|
|
94
|
-
* @param {Object} image - Input javascript image object.
|
|
95
|
-
* @param {boolean} [fastInsert] - If it's true atlas doesnt restore all images again
|
|
96
|
-
* and store image in the curent atlas sheme.
|
|
97
|
-
* @returns {utils.TextureAtlasNode} -
|
|
98
|
-
*/
|
|
99
|
-
addImage(image, fastInsert) {
|
|
100
|
-
if (!(image.width && image.height)) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
this._images.push(image);
|
|
105
|
-
|
|
106
|
-
this._makeAtlas(fastInsert);
|
|
107
|
-
|
|
108
|
-
return this.
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
_completeNode(nodes, node) {
|
|
112
|
-
if (node) {
|
|
113
|
-
var w = this.canvas.getWidth(),
|
|
114
|
-
h = this.canvas.getHeight();
|
|
115
|
-
var im = node.image;
|
|
116
|
-
var r = node.rect;
|
|
117
|
-
var bs = Math.round(this.borderSize * 0.5);
|
|
118
|
-
this.canvas.drawImage(im, r.left + bs, r.top + bs, im.atlasWidth, im.atlasHeight);
|
|
119
|
-
var tc = node.texCoords;
|
|
120
|
-
|
|
121
|
-
tc[0] = (r.left + bs) / w;
|
|
122
|
-
tc[1] = (r.top + bs) / h;
|
|
123
|
-
|
|
124
|
-
tc[2] = (r.left + bs) / w;
|
|
125
|
-
tc[3] = (r.bottom - bs) / h;
|
|
126
|
-
|
|
127
|
-
tc[4] = (r.right - bs) / w;
|
|
128
|
-
tc[5] = (r.bottom - bs) / h;
|
|
129
|
-
|
|
130
|
-
tc[6] = (r.right - bs) / w;
|
|
131
|
-
tc[7] = (r.bottom - bs) / h;
|
|
132
|
-
|
|
133
|
-
tc[8] = (r.right - bs) / w;
|
|
134
|
-
tc[9] = (r.top + bs) / h;
|
|
135
|
-
|
|
136
|
-
tc[10] = (r.left + bs) / w;
|
|
137
|
-
tc[11] = (r.top + bs) / h;
|
|
138
|
-
|
|
139
|
-
nodes
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Main atlas making function.
|
|
145
|
-
* @private
|
|
146
|
-
* @param {boolean} [fastInsert] - If it's true atlas doesnt restore all images again
|
|
147
|
-
* and store image in the curent atlas sheme.
|
|
148
|
-
*/
|
|
149
|
-
_makeAtlas(fastInsert) {
|
|
150
|
-
if (fastInsert && this._btree) {
|
|
151
|
-
let im = this._images[this._images.length - 1];
|
|
152
|
-
this._completeNode(this.nodes, this._btree.insert(im));
|
|
153
|
-
} else {
|
|
154
|
-
let im = this._images.slice(0);
|
|
155
|
-
|
|
156
|
-
im.sort(function (b, a) {
|
|
157
|
-
return (
|
|
158
|
-
(a.atlasWidth || a.width) - (b.atlasWidth || b.width) ||
|
|
159
|
-
(a.atlasHeight || a.height) - (b.atlasHeight || b.height)
|
|
160
|
-
);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
this._btree = new TextureAtlasNode(
|
|
164
|
-
new Rectangle(0, 0, this.canvas.getWidth(), this.canvas.getHeight())
|
|
165
|
-
);
|
|
166
|
-
this._btree.atlas = this;
|
|
167
|
-
|
|
168
|
-
this.clearCanvas();
|
|
169
|
-
|
|
170
|
-
var newNodes =
|
|
171
|
-
for (var i = 0; i < im.length; i++) {
|
|
172
|
-
this._completeNode(newNodes, this._btree.insert(im[i]));
|
|
173
|
-
}
|
|
174
|
-
this.nodes =
|
|
175
|
-
this.nodes = newNodes;
|
|
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
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { ImageCanvas } from "../ImageCanvas.js";
|
|
4
|
+
import { Rectangle } from "../Rectangle.js";
|
|
5
|
+
import { ImagesCacheManager } from "./ImagesCacheManager.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Texture atlas stores images in one texture. Each image has its own
|
|
9
|
+
* atlas texture coordinates.
|
|
10
|
+
* @class
|
|
11
|
+
* @param {number} [width] - Texture atlas width, if it hasn't 1024 default.
|
|
12
|
+
* @param {number} [height] - Texture atlas height, if it hasn't 1024 default..
|
|
13
|
+
*/
|
|
14
|
+
class TextureAtlas {
|
|
15
|
+
constructor(width = 1024, height = 1024) {
|
|
16
|
+
/**
|
|
17
|
+
* Atlas nodes where input images store. It can be access by image.__nodeIndex.
|
|
18
|
+
* @public
|
|
19
|
+
* @type {Array.<utils.TextureAtlasNode >}
|
|
20
|
+
*/
|
|
21
|
+
this.nodes = new Map();
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Created gl texture.
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
this.texture = null;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Atlas canvas.
|
|
31
|
+
* @public
|
|
32
|
+
* @type {canvas}
|
|
33
|
+
*/
|
|
34
|
+
this.canvas = new ImageCanvas(width, height);
|
|
35
|
+
this.clearCanvas();
|
|
36
|
+
|
|
37
|
+
this._handler = null;
|
|
38
|
+
this._images = [];
|
|
39
|
+
this._btree = null;
|
|
40
|
+
this._imagesCacheManager = new ImagesCacheManager();
|
|
41
|
+
this.borderSize = 4;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Returns atlas javascript image object.
|
|
46
|
+
* @public
|
|
47
|
+
* @returns {Object} -
|
|
48
|
+
*/
|
|
49
|
+
getImage() {
|
|
50
|
+
return this.canvas.getImage();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Returns canvas object.
|
|
55
|
+
* @public
|
|
56
|
+
* @returns {Object} -
|
|
57
|
+
*/
|
|
58
|
+
getCanvas() {
|
|
59
|
+
return this.canvas._canvas;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Clear atlas with black.
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
clearCanvas() {
|
|
67
|
+
this.canvas.fillEmpty("black");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Sets openglobus gl handler that creates gl texture.
|
|
72
|
+
* @public
|
|
73
|
+
* @param {Handler} handler - WebGL handler.
|
|
74
|
+
*/
|
|
75
|
+
assignHandler(handler) {
|
|
76
|
+
this._handler = handler;
|
|
77
|
+
this.createTexture();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Returns image diagonal size.
|
|
82
|
+
* @param {Object} image - JavaSript image object.
|
|
83
|
+
* @returns {number} -
|
|
84
|
+
*/
|
|
85
|
+
getDiagonal(image) {
|
|
86
|
+
var w = image.atlasWidth || image.width,
|
|
87
|
+
h = image.atlasHeight || image.height;
|
|
88
|
+
return Math.sqrt(w * w + h * h);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Adds image to the atlas and returns creted node with texture coordinates of the stored image.
|
|
93
|
+
* @public
|
|
94
|
+
* @param {Object} image - Input javascript image object.
|
|
95
|
+
* @param {boolean} [fastInsert] - If it's true atlas doesnt restore all images again
|
|
96
|
+
* and store image in the curent atlas sheme.
|
|
97
|
+
* @returns {utils.TextureAtlasNode} -
|
|
98
|
+
*/
|
|
99
|
+
addImage(image, fastInsert) {
|
|
100
|
+
if (!(image.width && image.height)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
this._images.push(image);
|
|
105
|
+
|
|
106
|
+
this._makeAtlas(fastInsert);
|
|
107
|
+
|
|
108
|
+
return this.get(image.__nodeIndex);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
_completeNode(nodes, node) {
|
|
112
|
+
if (node) {
|
|
113
|
+
var w = this.canvas.getWidth(),
|
|
114
|
+
h = this.canvas.getHeight();
|
|
115
|
+
var im = node.image;
|
|
116
|
+
var r = node.rect;
|
|
117
|
+
var bs = Math.round(this.borderSize * 0.5);
|
|
118
|
+
this.canvas.drawImage(im, r.left + bs, r.top + bs, im.atlasWidth, im.atlasHeight);
|
|
119
|
+
var tc = node.texCoords;
|
|
120
|
+
|
|
121
|
+
tc[0] = (r.left + bs) / w;
|
|
122
|
+
tc[1] = (r.top + bs) / h;
|
|
123
|
+
|
|
124
|
+
tc[2] = (r.left + bs) / w;
|
|
125
|
+
tc[3] = (r.bottom - bs) / h;
|
|
126
|
+
|
|
127
|
+
tc[4] = (r.right - bs) / w;
|
|
128
|
+
tc[5] = (r.bottom - bs) / h;
|
|
129
|
+
|
|
130
|
+
tc[6] = (r.right - bs) / w;
|
|
131
|
+
tc[7] = (r.bottom - bs) / h;
|
|
132
|
+
|
|
133
|
+
tc[8] = (r.right - bs) / w;
|
|
134
|
+
tc[9] = (r.top + bs) / h;
|
|
135
|
+
|
|
136
|
+
tc[10] = (r.left + bs) / w;
|
|
137
|
+
tc[11] = (r.top + bs) / h;
|
|
138
|
+
|
|
139
|
+
nodes.set(im.__nodeIndex, node);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Main atlas making function.
|
|
145
|
+
* @private
|
|
146
|
+
* @param {boolean} [fastInsert] - If it's true atlas doesnt restore all images again
|
|
147
|
+
* and store image in the curent atlas sheme.
|
|
148
|
+
*/
|
|
149
|
+
_makeAtlas(fastInsert) {
|
|
150
|
+
if (fastInsert && this._btree) {
|
|
151
|
+
let im = this._images[this._images.length - 1];
|
|
152
|
+
this._completeNode(this.nodes, this._btree.insert(im));
|
|
153
|
+
} else {
|
|
154
|
+
let im = this._images.slice(0);
|
|
155
|
+
|
|
156
|
+
im.sort(function (b, a) {
|
|
157
|
+
return (
|
|
158
|
+
(a.atlasWidth || a.width) - (b.atlasWidth || b.width) ||
|
|
159
|
+
(a.atlasHeight || a.height) - (b.atlasHeight || b.height)
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
this._btree = new TextureAtlasNode(
|
|
164
|
+
new Rectangle(0, 0, this.canvas.getWidth(), this.canvas.getHeight())
|
|
165
|
+
);
|
|
166
|
+
this._btree.atlas = this;
|
|
167
|
+
|
|
168
|
+
this.clearCanvas();
|
|
169
|
+
|
|
170
|
+
var newNodes = new Map();
|
|
171
|
+
for (var i = 0; i < im.length; i++) {
|
|
172
|
+
this._completeNode(newNodes, this._btree.insert(im[i]));
|
|
173
|
+
}
|
|
174
|
+
this.nodes = null;
|
|
175
|
+
this.nodes = newNodes;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
get(key) {
|
|
180
|
+
return this.nodes.get(key);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
set(key, value) {
|
|
184
|
+
this.nodes.set(key, value);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Creates atlas gl texture.
|
|
189
|
+
* @public
|
|
190
|
+
*/
|
|
191
|
+
createTexture(img, internalFormat) {
|
|
192
|
+
if (this._handler) {
|
|
193
|
+
this._handler.gl.deleteTexture(this.texture);
|
|
194
|
+
if (img) {
|
|
195
|
+
this.canvas.resize(img.width, img.height);
|
|
196
|
+
this.canvas.drawImage(img, 0, 0, img.width, img.height);
|
|
197
|
+
}
|
|
198
|
+
this.texture = this._handler.createTexture_l(this.canvas._canvas, internalFormat);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Image handler callback.
|
|
204
|
+
* @callback Object~successCallback
|
|
205
|
+
* @param {Image} img - Loaded image.
|
|
206
|
+
*/
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Asynchronous function that loads and creates image to the image cache, and call success callback when it's done.
|
|
210
|
+
* @public
|
|
211
|
+
* @param {string} src - Image object src string.
|
|
212
|
+
* @param {Object~successCallback} success - The callback that handles the image loads done.
|
|
213
|
+
*/
|
|
214
|
+
loadImage(src, success) {
|
|
215
|
+
this._imagesCacheManager.load(src, success);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
getImageTexCoordinates(img) {
|
|
219
|
+
if (img.__nodeIndex != null) {
|
|
220
|
+
let n = this.get(img.__nodeIndex);
|
|
221
|
+
if (n) {
|
|
222
|
+
return n.texCoords;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Atlas binary tree node.
|
|
230
|
+
* @class
|
|
231
|
+
* @param {Rectangle} rect - Node image rectangle.
|
|
232
|
+
*/
|
|
233
|
+
class TextureAtlasNode {
|
|
234
|
+
constructor(rect, texCoords = []) {
|
|
235
|
+
this.childNodes = null;
|
|
236
|
+
this.image = null;
|
|
237
|
+
this.rect = rect;
|
|
238
|
+
this.texCoords = texCoords;
|
|
239
|
+
this.atlas = null;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
insert(img) {
|
|
243
|
+
if (this.childNodes) {
|
|
244
|
+
var newNode = this.childNodes[0].insert(img);
|
|
245
|
+
|
|
246
|
+
if (newNode != null) {
|
|
247
|
+
return newNode;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return this.childNodes[1].insert(img);
|
|
251
|
+
} else {
|
|
252
|
+
if (this.image != null) {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
var rc = this.rect;
|
|
257
|
+
var w = (img.atlasWidth || img.width) + this.atlas.borderSize;
|
|
258
|
+
var h = (img.atlasHeight || img.height) + this.atlas.borderSize;
|
|
259
|
+
|
|
260
|
+
if (w > rc.getWidth() || h > rc.getHeight()) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (rc.fit(w, h)) {
|
|
265
|
+
this.image = img;
|
|
266
|
+
return this;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
this.childNodes = new Array(2);
|
|
270
|
+
this.childNodes[0] = new TextureAtlasNode();
|
|
271
|
+
this.childNodes[0].atlas = this.atlas;
|
|
272
|
+
this.childNodes[1] = new TextureAtlasNode();
|
|
273
|
+
this.childNodes[1].atlas = this.atlas;
|
|
274
|
+
|
|
275
|
+
var dw = rc.getWidth() - w;
|
|
276
|
+
var dh = rc.getHeight() - h;
|
|
277
|
+
|
|
278
|
+
if (dw > dh) {
|
|
279
|
+
this.childNodes[0].rect = new Rectangle(rc.left, rc.top, rc.left + w, rc.bottom);
|
|
280
|
+
this.childNodes[1].rect = new Rectangle(rc.left + w, rc.top, rc.right, rc.bottom);
|
|
281
|
+
} else {
|
|
282
|
+
this.childNodes[0].rect = new Rectangle(rc.left, rc.top, rc.right, rc.top + h);
|
|
283
|
+
this.childNodes[1].rect = new Rectangle(rc.left, rc.top + h, rc.right, rc.bottom);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return this.childNodes[0].insert(img);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export { TextureAtlas, TextureAtlasNode };
|
|
@@ -13,8 +13,11 @@ export class KeyboardNavigation extends Control {
|
|
|
13
13
|
onCameraStrifeRight(event: any): void;
|
|
14
14
|
onCameraLookUp(event: any): void;
|
|
15
15
|
onCameraLookDown(event: any): void;
|
|
16
|
+
onCameraLookLeft(event: any): void;
|
|
17
|
+
onCameraLookRight(event: any): void;
|
|
16
18
|
onCameraTurnLeft(event: any): void;
|
|
17
19
|
onCameraTurnRight(event: any): void;
|
|
20
|
+
onCameraRollNorth(event: any): void;
|
|
18
21
|
onCameraRollLeft(event: any): void;
|
|
19
22
|
onCameraRollRight(event: any): void;
|
|
20
23
|
}
|