@openglobus/og 0.13.2 → 0.13.5

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.
@@ -1,165 +1,165 @@
1
- /**
2
- * @module og/entity/Billboard
3
- */
4
-
5
- "use strict";
6
-
7
- import { BaseBillboard } from "./BaseBillboard.js";
8
-
9
- /**
10
- * Represents basic quad billboard image.
11
- * @class
12
- * @extends {BaseBillboard}
13
- * @param {Object} [options] - Options:
14
- * @param {Vec3|Array.<number>} [options.position] - Billboard spatial position.
15
- * @param {number} [options.rotation] - Screen angle rotaion.
16
- * @param {Vec4|string|Array.<number>} [options.color] - Billboard color.
17
- * @param {Vec3|Array.<number>} [options.alignedAxis] - Billboard aligned vector.
18
- * @param {Vec3|Array.<number>} [options.offset] - Billboard center screen offset.
19
- * @param {boolean} [options.visibility] - Visibility.
20
- * @param {string} [options.src] - Billboard image url source.
21
- * @param {Image} [options.image] - Billboard image object.
22
- * @param {number} [options.width] - Screen width.
23
- * @param {number} [options.height] - Screen height.
24
- * @param {number} [options.scale] - Billboard scale.
25
- */
26
- class Billboard extends BaseBillboard {
27
- constructor(options) {
28
- super(options);
29
-
30
- options = options || {};
31
-
32
- /**
33
- * Image src.
34
- * @protected
35
- * @type {string}
36
- */
37
- this._src = options.src || null;
38
-
39
- /**
40
- * Image object.
41
- * @protected
42
- * @type {Object}
43
- */
44
- this._image = options.image || null;
45
-
46
- this._scale = 1.0;
47
-
48
- /**
49
- * Billboard screen width.
50
- * @protected
51
- * @type {number}
52
- */
53
- this._width = options.width || (options.size ? options.size[0] : 30);
54
-
55
- /**
56
- * Billboard screen height.
57
- * @protected
58
- * @type {number}
59
- */
60
- this._height = options.height || (options.size ? options.size[1] : 30);
61
- }
62
-
63
- /**
64
- * Sets billboard image url source.
65
- * @public
66
- * @param {string} src - Image url.
67
- */
68
- setSrc(src) {
69
- this._src = src;
70
- var bh = this._handler;
71
- if (bh && src) {
72
- var rn = bh._entityCollection.renderNode;
73
- if (rn) {
74
- var ta = rn.renderer.billboardsTextureAtlas;
75
- var that = this;
76
- ta.loadImage(src, function (img) {
77
- if (ta.nodes[img.__nodeIndex]) {
78
- that._image = img;
79
- bh.setTexCoordArr(
80
- that._handlerIndex,
81
- ta.nodes[that._image.__nodeIndex].texCoords
82
- );
83
- } else {
84
- ta.addImage(img);
85
- ta.createTexture();
86
- that._image = img;
87
- rn.updateBillboardsTexCoords();
88
- }
89
- });
90
- }
91
- }
92
- }
93
-
94
- /**
95
- * Sets image object.
96
- * @public
97
- * @param {Object} image - JavaScript image object.
98
- */
99
- setImage(image) {
100
- this.setSrc(image.src);
101
- }
102
-
103
- /**
104
- * Sets billboard screen size in pixels.
105
- * @public
106
- * @param {number} width - Billboard width.
107
- * @param {number} height - Billboard height.
108
- */
109
- setSize(width, height) {
110
- this._width = width;
111
- this._height = height;
112
- this._handler &&
113
- this._handler.setSizeArr(this._handlerIndex, width * this._scale, height * this._scale);
114
- }
115
-
116
- /**
117
- * Returns billboard screen size.
118
- * @public
119
- * @returns {Object}
120
- */
121
- getSize() {
122
- return {
123
- width: this._width,
124
- height: this._height
125
- };
126
- }
127
-
128
- /**
129
- * Sets billboard screen width.
130
- * @public
131
- * @param {number} width - Width.
132
- */
133
- setWidth(width) {
134
- this.setSize(width, this._height);
135
- }
136
-
137
- /**
138
- * Gets billboard screen width.
139
- * @public
140
- * @returns {number}
141
- */
142
- getWidth() {
143
- return this._width;
144
- }
145
-
146
- /**
147
- * Sets billboard screen heigh.
148
- * @public
149
- * @param {number} height - Height.
150
- */
151
- setHeight(height) {
152
- this.setSize(this._width, height);
153
- }
154
-
155
- /**
156
- * Gets billboard screen height.
157
- * @public
158
- * @returns {number}
159
- */
160
- getHeight() {
161
- return this._height;
162
- }
163
- }
164
-
165
- export { Billboard };
1
+ /**
2
+ * @module og/entity/Billboard
3
+ */
4
+
5
+ "use strict";
6
+
7
+ import { BaseBillboard } from "./BaseBillboard.js";
8
+
9
+ /**
10
+ * Represents basic quad billboard image.
11
+ * @class
12
+ * @extends {BaseBillboard}
13
+ * @param {Object} [options] - Options:
14
+ * @param {Vec3|Array.<number>} [options.position] - Billboard spatial position.
15
+ * @param {number} [options.rotation] - Screen angle rotaion.
16
+ * @param {Vec4|string|Array.<number>} [options.color] - Billboard color.
17
+ * @param {Vec3|Array.<number>} [options.alignedAxis] - Billboard aligned vector.
18
+ * @param {Vec3|Array.<number>} [options.offset] - Billboard center screen offset.
19
+ * @param {boolean} [options.visibility] - Visibility.
20
+ * @param {string} [options.src] - Billboard image url source.
21
+ * @param {Image} [options.image] - Billboard image object.
22
+ * @param {number} [options.width] - Screen width.
23
+ * @param {number} [options.height] - Screen height.
24
+ * @param {number} [options.scale] - Billboard scale.
25
+ */
26
+ class Billboard extends BaseBillboard {
27
+ constructor(options) {
28
+ super(options);
29
+
30
+ options = options || {};
31
+
32
+ /**
33
+ * Image src.
34
+ * @protected
35
+ * @type {string}
36
+ */
37
+ this._src = options.src || null;
38
+
39
+ /**
40
+ * Image object.
41
+ * @protected
42
+ * @type {Object}
43
+ */
44
+ this._image = options.image || null;
45
+
46
+ this._scale = 1.0;
47
+
48
+ /**
49
+ * Billboard screen width.
50
+ * @protected
51
+ * @type {number}
52
+ */
53
+ this._width = options.width || (options.size ? options.size[0] : 30);
54
+
55
+ /**
56
+ * Billboard screen height.
57
+ * @protected
58
+ * @type {number}
59
+ */
60
+ this._height = options.height || (options.size ? options.size[1] : 30);
61
+ }
62
+
63
+ /**
64
+ * Sets billboard image url source.
65
+ * @public
66
+ * @param {string} src - Image url.
67
+ */
68
+ setSrc(src) {
69
+ this._src = src;
70
+ var bh = this._handler;
71
+ if (bh && src) {
72
+ var rn = bh._entityCollection.renderNode;
73
+ if (rn) {
74
+ var ta = rn.renderer.billboardsTextureAtlas;
75
+ var that = this;
76
+ ta.loadImage(src, function (img) {
77
+ if (ta.get(img.__nodeIndex)) {
78
+ that._image = img;
79
+ bh.setTexCoordArr(
80
+ that._handlerIndex,
81
+ ta.get(that._image.__nodeIndex).texCoords
82
+ );
83
+ } else {
84
+ ta.addImage(img);
85
+ ta.createTexture();
86
+ that._image = img;
87
+ rn.updateBillboardsTexCoords();
88
+ }
89
+ });
90
+ }
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Sets image object.
96
+ * @public
97
+ * @param {Object} image - JavaScript image object.
98
+ */
99
+ setImage(image) {
100
+ this.setSrc(image.src);
101
+ }
102
+
103
+ /**
104
+ * Sets billboard screen size in pixels.
105
+ * @public
106
+ * @param {number} width - Billboard width.
107
+ * @param {number} height - Billboard height.
108
+ */
109
+ setSize(width, height) {
110
+ this._width = width;
111
+ this._height = height;
112
+ this._handler &&
113
+ this._handler.setSizeArr(this._handlerIndex, width * this._scale, height * this._scale);
114
+ }
115
+
116
+ /**
117
+ * Returns billboard screen size.
118
+ * @public
119
+ * @returns {Object}
120
+ */
121
+ getSize() {
122
+ return {
123
+ width: this._width,
124
+ height: this._height
125
+ };
126
+ }
127
+
128
+ /**
129
+ * Sets billboard screen width.
130
+ * @public
131
+ * @param {number} width - Width.
132
+ */
133
+ setWidth(width) {
134
+ this.setSize(width, this._height);
135
+ }
136
+
137
+ /**
138
+ * Gets billboard screen width.
139
+ * @public
140
+ * @returns {number}
141
+ */
142
+ getWidth() {
143
+ return this._width;
144
+ }
145
+
146
+ /**
147
+ * Sets billboard screen heigh.
148
+ * @public
149
+ * @param {number} height - Height.
150
+ */
151
+ setHeight(height) {
152
+ this.setSize(this._width, height);
153
+ }
154
+
155
+ /**
156
+ * Gets billboard screen height.
157
+ * @public
158
+ * @returns {number}
159
+ */
160
+ getHeight() {
161
+ return this._height;
162
+ }
163
+ }
164
+
165
+ export { Billboard };
@@ -866,7 +866,7 @@ class BillboardHandler {
866
866
  var bi = this._billboards[i];
867
867
  var img = bi._image;
868
868
  if (img) {
869
- var imageNode = ta.nodes[bi._image.__nodeIndex];
869
+ var imageNode = ta.get(bi._image.__nodeIndex);
870
870
  if (imageNode) {
871
871
  this.setTexCoordArr(bi._handlerIndex, imageNode.texCoords);
872
872
  }
@@ -193,6 +193,10 @@ class GeoObject {
193
193
  this._handler && this._handler.setScaleArr(this._handlerIndex, scale);
194
194
  }
195
195
 
196
+ getScale() {
197
+ return this.scale;
198
+ }
199
+
196
200
  /**
197
201
  * Removes geo object from handler.
198
202
  * @public
@@ -90,8 +90,7 @@ class GeoObjectHandler {
90
90
  const h = this._renderer.handler;
91
91
  for (let i = 0, len = this._vertexArr.length; i < len; i++) {
92
92
  this._vertexBuffer && h.gl.deleteBuffer(this._vertexBuffer[i]);
93
- this._vertexArr[i] = makeArrayTyped(this._vertexArr[i]);
94
- this._vertexBuffer[i] = h.createArrayBuffer(this._vertexArr[i], 3, this._vertexArr[i].length / 3);
93
+ this._vertexBuffer[i] = h.createArrayBuffer(new Float32Array(this._vertexArr[i]), 3, this._vertexArr[i].length / 3);
95
94
  }
96
95
  }
97
96
 
@@ -99,8 +98,7 @@ class GeoObjectHandler {
99
98
  const h = this._renderer.handler;
100
99
  for (let i = 0, len = this._pitchRollArr.length; i < len; i++) {
101
100
  this._pitchRollBuffer && h.gl.deleteBuffer(this._pitchRollBuffer[i]);
102
- this._pitchRollArr[i] = makeArrayTyped(this._pitchRollArr[i]);
103
- this._pitchRollBuffer[i] = h.createArrayBuffer(this._pitchRollArr[i], 2, this._pitchRollArr[i].length / 2);
101
+ this._pitchRollBuffer[i] = h.createArrayBuffer(new Float32Array(this._pitchRollArr[i]), 2, this._pitchRollArr[i].length / 2);
104
102
  }
105
103
  }
106
104
 
@@ -108,8 +106,7 @@ class GeoObjectHandler {
108
106
  const h = this._renderer.handler;
109
107
  for (let i = 0, len = this._vehicleVisibleArr.length; i < len; i++) {
110
108
  this._vehicleVisibleBuffer && h.gl.deleteBuffer(this._vehicleVisibleBuffer[i]);
111
- this._vehicleVisibleArr[i] = makeArrayTyped(this._vehicleVisibleArr[i]);
112
- this._vehicleVisibleBuffer[i] = h.createArrayBuffer(this._vehicleVisibleArr[i], 1, this._vehicleVisibleArr[i].length);
109
+ this._vehicleVisibleBuffer[i] = h.createArrayBuffer(new Float32Array(this._vehicleVisibleArr[i]), 1, this._vehicleVisibleArr[i].length);
113
110
  }
114
111
  }
115
112
 
@@ -117,8 +114,7 @@ class GeoObjectHandler {
117
114
  const h = this._renderer.handler;
118
115
  for (let i = 0, len = this._sizeArr.length; i < len; i++) {
119
116
  this._sizeBuffer && h.gl.deleteBuffer(this._sizeBuffer[i]);
120
- this._sizeArr[i] = makeArrayTyped(this._sizeArr[i]);
121
- this._sizeBuffer[i] = h.createArrayBuffer(this._sizeArr[i], 1, this._sizeArr[i].length);
117
+ this._sizeBuffer[i] = h.createArrayBuffer(new Float32Array(this._sizeArr[i]), 1, this._sizeArr[i].length);
122
118
  }
123
119
  }
124
120
 
@@ -126,11 +122,9 @@ class GeoObjectHandler {
126
122
  let h = this._renderer.handler;
127
123
  for (let i = 0, len = this._positionHighArr.length; i < len; i++) {
128
124
  this._positionHighBuffer && h.gl.deleteBuffer(this._positionHighBuffer[i]);
129
- this._positionHighArr[i] = makeArrayTyped(this._positionHighArr[i]);
130
- this._positionHighBuffer[i] = h.createArrayBuffer(this._positionHighArr[i], 3, this._positionHighArr[i].length / 3);
125
+ this._positionHighBuffer[i] = h.createArrayBuffer(new Float32Array(this._positionHighArr[i]), 3, this._positionHighArr[i].length / 3);
131
126
  this._positionLowBuffer && h.gl.deleteBuffer(this._positionLowBuffer[i]);
132
- this._positionLowArr[i] = makeArrayTyped(this._positionLowArr[i]);
133
- this._positionLowBuffer[i] = h.createArrayBuffer(this._positionLowArr[i], 3, this._positionLowArr[i].length / 3);
127
+ this._positionLowBuffer[i] = h.createArrayBuffer(new Float32Array(this._positionLowArr[i]), 3, this._positionLowArr[i].length / 3);
134
128
  }
135
129
  }
136
130
 
@@ -138,8 +132,7 @@ class GeoObjectHandler {
138
132
  const h = this._renderer.handler;
139
133
  for (let i = 0, len = this._rgbaArr.length; i < len; i++) {
140
134
  this._rgbaBuffer && h.gl.deleteBuffer(this._rgbaBuffer[i]);
141
- this._rgbaArr[i] = makeArrayTyped(this._rgbaArr[i]);
142
- this._rgbaBuffer[i] = h.createArrayBuffer(this._rgbaArr[i], 4, this._rgbaArr[i].length / 4);
135
+ this._rgbaBuffer[i] = h.createArrayBuffer(new Float32Array(this._rgbaArr[i]), 4, this._rgbaArr[i].length / 4);
143
136
  }
144
137
  }
145
138
 
@@ -147,8 +140,7 @@ class GeoObjectHandler {
147
140
  const h = this._renderer.handler;
148
141
  for (let i = 0, len = this._directionArr.length; i < len; i++) {
149
142
  this._directionBuffer && h.gl.deleteBuffer(this._directionBuffer[i]);
150
- this._directionArr[i] = makeArrayTyped(this._directionArr[i]);
151
- this._directionBuffer[i] = h.createArrayBuffer(this._directionArr[i], 3, this._directionArr[i].length / 3);
143
+ this._directionBuffer[i] = h.createArrayBuffer(new Float32Array(this._directionArr[i]), 3, this._directionArr[i].length / 3);
152
144
  }
153
145
  }
154
146
 
@@ -156,8 +148,7 @@ class GeoObjectHandler {
156
148
  const h = this._renderer.handler;
157
149
  for (let i = 0, len = this._normalsArr.length; i < len; i++) {
158
150
  this._normalsBuffer && h.gl.deleteBuffer(this._normalsBuffer[i]);
159
- this._normalsArr[i] = makeArrayTyped(this._normalsArr[i]);
160
- this._normalsBuffer[i] = h.createArrayBuffer(this._normalsArr[i], 3, this._normalsArr[i].length / 3);
151
+ this._normalsBuffer[i] = h.createArrayBuffer(new Float32Array(this._normalsArr[i]), 3, this._normalsArr[i].length / 3);
161
152
  }
162
153
  }
163
154
 
@@ -165,8 +156,7 @@ class GeoObjectHandler {
165
156
  const h = this._renderer.handler;
166
157
  for (let i = 0, len = this._indicesArr.length; i < len; i++) {
167
158
  this._indicesBuffer && h.gl.deleteBuffer(this._indicesBuffer[i]);
168
- this._indicesArr[i] = makeArrayTyped(this._indicesArr[i], Uint16Array);
169
- this._indicesBuffer[i] = h.createElementArrayBuffer(this._indicesArr[i], 1, this._indicesArr[i].length);
159
+ this._indicesBuffer[i] = h.createElementArrayBuffer(new Uint16Array(this._indicesArr[i]), 1, this._indicesArr[i].length);
170
160
  }
171
161
  }
172
162
 
@@ -174,8 +164,7 @@ class GeoObjectHandler {
174
164
  const h = this._renderer.handler;
175
165
  for (let i = 0, len = this._pickingColorArr.length; i < len; i++) {
176
166
  this._pickingColorBuffer && h.gl.deleteBuffer(this._pickingColorBuffer[i]);
177
- this._pickingColorArr[i] = makeArrayTyped(this._pickingColorArr[i]);
178
- this._pickingColorBuffer[i] = h.createArrayBuffer(this._pickingColorArr[i], 3, this._pickingColorArr[i].length / 3);
167
+ this._pickingColorBuffer[i] = h.createArrayBuffer(new Float32Array(this._pickingColorArr[i]), 3, this._pickingColorArr[i].length / 3);
179
168
  }
180
169
  }
181
170
 
@@ -771,17 +760,17 @@ class GeoObjectHandler {
771
760
  this._pickingColorArr = null;
772
761
  this._vehicleVisibleArr = null;
773
762
 
774
- this._pitchRollArr = [new Float32Array()];
775
- this._sizeArr = [new Float32Array()];
776
- this._vertexArr = [new Float32Array()];
777
- this._positionHighArr = [new Float32Array()];
778
- this._positionLowArr = [new Float32Array()];
779
- this._rgbaArr = [new Float32Array()];
780
- this._directionArr = [new Float32Array()];
781
- this._normalsArr = [new Float32Array()];
782
- this._indicesArr = [new Uint16Array()];
783
- this._pickingColorArr = [new Float32Array()];
784
- this._vehicleVisibleArr = [new Int8Array()];
763
+ this._pitchRollArr = [];
764
+ this._sizeArr = [];
765
+ this._vertexArr = [];
766
+ this._positionHighArr = [];
767
+ this._positionLowArr = [];
768
+ this._rgbaArr = [];
769
+ this._directionArr = [];
770
+ this._normalsArr = [];
771
+ this._indicesArr = [];
772
+ this._pickingColorArr = [];
773
+ this._vehicleVisibleArr = [];
785
774
 
786
775
  this._removeGeoObjects();
787
776
  this._deleteBuffers();