@openglobus/og 0.22.2 → 0.24.0

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.
Files changed (205) hide show
  1. package/css/og.css +137 -1
  2. package/lib/@openglobus/js/Globe.d.ts +0 -1
  3. package/lib/@openglobus/js/Object3d.d.ts +20 -10
  4. package/lib/@openglobus/js/camera/Camera.d.ts +57 -15
  5. package/lib/@openglobus/js/camera/Frustum.d.ts +3 -0
  6. package/lib/@openglobus/js/camera/PlanetCamera.d.ts +13 -0
  7. package/lib/@openglobus/js/control/CameraLock.d.ts +38 -0
  8. package/lib/@openglobus/js/control/MouseNavigation.d.ts +62 -51
  9. package/lib/@openglobus/js/control/OldMouseNavigation.d.ts +64 -0
  10. package/lib/@openglobus/js/control/SimpleNavigation.d.ts +27 -10
  11. package/lib/@openglobus/js/control/geoObjectEditor/ArrowEntity.d.ts +15 -0
  12. package/lib/@openglobus/js/control/geoObjectEditor/AxisTrackEntity.d.ts +9 -0
  13. package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditor.d.ts +13 -0
  14. package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditorDialog.d.ts +69 -0
  15. package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditorScene.d.ts +78 -9
  16. package/lib/@openglobus/js/control/geoObjectEditor/MoveAxisEntity.d.ts +17 -0
  17. package/lib/@openglobus/js/control/geoObjectEditor/MovePlaneEntity.d.ts +7 -0
  18. package/lib/@openglobus/js/control/geoObjectEditor/RotateEntity.d.ts +9 -0
  19. package/lib/@openglobus/js/control/geoObjectEditor/colors.d.ts +8 -0
  20. package/lib/@openglobus/js/control/index.d.ts +3 -2
  21. package/lib/@openglobus/js/entity/Entity.d.ts +282 -19
  22. package/lib/@openglobus/js/entity/EntityCollection.d.ts +8 -9
  23. package/lib/@openglobus/js/entity/GeoObject.d.ts +135 -39
  24. package/lib/@openglobus/js/entity/GeoObjectHandler.d.ts +39 -63
  25. package/lib/@openglobus/js/entity/InstanceData.d.ts +76 -0
  26. package/lib/@openglobus/js/entity/Polyline.d.ts +19 -6
  27. package/lib/@openglobus/js/entity/PolylineHandler.d.ts +7 -0
  28. package/lib/@openglobus/js/index.d.ts +2 -1
  29. package/lib/@openglobus/js/input/MouseHandler.d.ts +1 -0
  30. package/lib/@openglobus/js/layer/Vector.d.ts +4 -0
  31. package/lib/@openglobus/js/light/LightSource.d.ts +1 -139
  32. package/lib/@openglobus/js/math/Mat3.d.ts +1 -1
  33. package/lib/@openglobus/js/math/Mat4.d.ts +10 -1
  34. package/lib/@openglobus/js/math/Plane.d.ts +3 -1
  35. package/lib/@openglobus/js/math/Quat.d.ts +47 -33
  36. package/lib/@openglobus/js/math/Ray.d.ts +10 -14
  37. package/lib/@openglobus/js/math/Vec2.d.ts +22 -0
  38. package/lib/@openglobus/js/math/Vec3.d.ts +15 -0
  39. package/lib/@openglobus/js/math.d.ts +2 -2
  40. package/lib/@openglobus/js/quadTree/EntityCollectionNode.d.ts +2 -2
  41. package/lib/@openglobus/js/quadTree/Node.d.ts +1 -1
  42. package/lib/@openglobus/js/quadTree/earth/EarthEntityCollectionNodeLonLat.d.ts +1 -1
  43. package/lib/@openglobus/js/quadTree/equi/EquiEntityCollectionNodeLonLat.d.ts +1 -1
  44. package/lib/@openglobus/js/renderer/Renderer.d.ts +63 -44
  45. package/lib/@openglobus/js/renderer/RendererEvents.d.ts +2 -0
  46. package/lib/@openglobus/js/scene/Planet.d.ts +15 -7
  47. package/lib/@openglobus/js/scene/RenderNode.d.ts +10 -25
  48. package/lib/@openglobus/js/shaders/drawnode.d.ts +1 -0
  49. package/lib/@openglobus/js/shaders/geoObject.d.ts +1 -0
  50. package/lib/@openglobus/js/shaders/utils.d.ts +1 -1
  51. package/lib/@openglobus/js/ui/Checkbox.d.ts +31 -0
  52. package/lib/@openglobus/js/ui/Dialog.d.ts +3 -0
  53. package/lib/@openglobus/js/ui/Input.d.ts +32 -0
  54. package/lib/@openglobus/js/ui/View.d.ts +3 -1
  55. package/lib/@openglobus/js/utils/objParser.d.ts +44 -12
  56. package/lib/@openglobus/js/utils/shared.d.ts +22 -0
  57. package/lib/@openglobus/js/webgl/BaseFramebuffer.d.ts +0 -1
  58. package/lib/@openglobus/js/webgl/Framebuffer.d.ts +35 -8
  59. package/lib/@openglobus/js/webgl/Handler.d.ts +22 -12
  60. package/lib/@openglobus/og.css +1 -1
  61. package/lib/@openglobus/og.esm.js +1 -1
  62. package/lib/@openglobus/og.esm.js.map +1 -1
  63. package/lib/@openglobus/og.umd.js +1 -1
  64. package/lib/@openglobus/og.umd.js.map +1 -1
  65. package/lib/js/Globe.d.ts +0 -1
  66. package/lib/js/Globe.js +4 -2
  67. package/lib/js/Object3d.d.ts +20 -10
  68. package/lib/js/Object3d.js +124 -48
  69. package/lib/js/Popup.js +1 -1
  70. package/lib/js/camera/Camera.d.ts +57 -15
  71. package/lib/js/camera/Camera.js +109 -29
  72. package/lib/js/camera/Frustum.d.ts +3 -0
  73. package/lib/js/camera/Frustum.js +7 -0
  74. package/lib/js/camera/PlanetCamera.d.ts +13 -0
  75. package/lib/js/camera/PlanetCamera.js +52 -5
  76. package/lib/js/control/Atmosphere.js +10 -6
  77. package/lib/js/control/CameraLock.d.ts +38 -0
  78. package/lib/js/control/CameraLock.js +216 -0
  79. package/lib/js/control/Control.js +1 -1
  80. package/lib/js/control/DebugInfo.js +38 -8
  81. package/lib/js/control/KeyboardNavigation.js +9 -9
  82. package/lib/js/control/MouseNavigation.d.ts +62 -51
  83. package/lib/js/control/MouseNavigation.js +361 -305
  84. package/lib/js/control/MouseWheelZoomControl.d.ts +0 -44
  85. package/lib/js/control/MouseWheelZoomControl.js +270 -181
  86. package/lib/js/control/OldMouseNavigation.d.ts +64 -0
  87. package/lib/js/control/OldMouseNavigation.js +368 -0
  88. package/lib/js/control/ScaleControl.js +11 -5
  89. package/lib/js/control/SimpleNavigation.d.ts +27 -10
  90. package/lib/js/control/SimpleNavigation.js +149 -49
  91. package/lib/js/control/Sun.js +6 -6
  92. package/lib/js/control/TouchNavigation.js +11 -8
  93. package/lib/js/control/elevationProfile/ElevationProfileScene.js +6 -5
  94. package/lib/js/control/geoObjectEditor/ArrowEntity.d.ts +15 -0
  95. package/lib/js/control/geoObjectEditor/ArrowEntity.js +59 -0
  96. package/lib/js/control/geoObjectEditor/AxisTrackEntity.d.ts +9 -0
  97. package/lib/js/control/geoObjectEditor/AxisTrackEntity.js +93 -0
  98. package/lib/js/control/geoObjectEditor/GeoObjectEditor.d.ts +13 -0
  99. package/lib/js/control/geoObjectEditor/GeoObjectEditor.js +30 -0
  100. package/lib/js/control/geoObjectEditor/GeoObjectEditorDialog.d.ts +69 -0
  101. package/lib/js/control/geoObjectEditor/GeoObjectEditorDialog.js +488 -0
  102. package/lib/js/control/geoObjectEditor/GeoObjectEditorScene.d.ts +78 -9
  103. package/lib/js/control/geoObjectEditor/GeoObjectEditorScene.js +487 -43
  104. package/lib/js/control/geoObjectEditor/MoveAxisEntity.d.ts +17 -0
  105. package/lib/js/control/geoObjectEditor/MoveAxisEntity.js +107 -0
  106. package/lib/js/control/geoObjectEditor/MovePlaneEntity.d.ts +7 -0
  107. package/lib/js/control/geoObjectEditor/MovePlaneEntity.js +31 -0
  108. package/lib/js/control/geoObjectEditor/RotateEntity.d.ts +9 -0
  109. package/lib/js/control/geoObjectEditor/RotateEntity.js +105 -0
  110. package/lib/js/control/geoObjectEditor/colors.d.ts +8 -0
  111. package/lib/js/control/geoObjectEditor/colors.js +8 -0
  112. package/lib/js/control/index.d.ts +3 -2
  113. package/lib/js/control/index.js +3 -2
  114. package/lib/js/control/timeline/TimelineControl.js +2 -0
  115. package/lib/js/control/visibleExtent/Segment.js +4 -4
  116. package/lib/js/entity/Entity.d.ts +282 -19
  117. package/lib/js/entity/Entity.js +497 -62
  118. package/lib/js/entity/EntityCollection.d.ts +8 -9
  119. package/lib/js/entity/EntityCollection.js +48 -45
  120. package/lib/js/entity/GeoObject.d.ts +135 -39
  121. package/lib/js/entity/GeoObject.js +150 -90
  122. package/lib/js/entity/GeoObjectHandler.d.ts +39 -63
  123. package/lib/js/entity/GeoObjectHandler.js +198 -295
  124. package/lib/js/entity/InstanceData.d.ts +76 -0
  125. package/lib/js/entity/InstanceData.js +347 -0
  126. package/lib/js/entity/Polyline.d.ts +19 -6
  127. package/lib/js/entity/Polyline.js +76 -36
  128. package/lib/js/entity/PolylineHandler.d.ts +7 -0
  129. package/lib/js/entity/PolylineHandler.js +26 -1
  130. package/lib/js/index.d.ts +2 -1
  131. package/lib/js/index.js +2 -1
  132. package/lib/js/input/MouseHandler.d.ts +1 -0
  133. package/lib/js/input/MouseHandler.js +12 -1
  134. package/lib/js/layer/Bing.js +2 -2
  135. package/lib/js/layer/Vector.d.ts +4 -0
  136. package/lib/js/layer/Vector.js +16 -0
  137. package/lib/js/light/LightSource.d.ts +1 -139
  138. package/lib/js/light/LightSource.js +21 -227
  139. package/lib/js/math/Mat3.d.ts +1 -1
  140. package/lib/js/math/Mat3.js +1 -1
  141. package/lib/js/math/Mat4.d.ts +10 -1
  142. package/lib/js/math/Mat4.js +17 -1
  143. package/lib/js/math/Plane.d.ts +3 -1
  144. package/lib/js/math/Plane.js +11 -1
  145. package/lib/js/math/Quat.d.ts +47 -33
  146. package/lib/js/math/Quat.js +92 -90
  147. package/lib/js/math/Ray.d.ts +10 -14
  148. package/lib/js/math/Ray.js +56 -33
  149. package/lib/js/math/Vec2.d.ts +22 -0
  150. package/lib/js/math/Vec2.js +32 -0
  151. package/lib/js/math/Vec3.d.ts +15 -0
  152. package/lib/js/math/Vec3.js +30 -1
  153. package/lib/js/math.d.ts +2 -2
  154. package/lib/js/math.js +3 -3
  155. package/lib/js/quadTree/EntityCollectionNode.d.ts +2 -2
  156. package/lib/js/quadTree/EntityCollectionNode.js +8 -8
  157. package/lib/js/quadTree/Node.d.ts +1 -1
  158. package/lib/js/quadTree/Node.js +2 -2
  159. package/lib/js/quadTree/QuadTreeStrategy.js +1 -1
  160. package/lib/js/quadTree/earth/EarthEntityCollectionNodeLonLat.d.ts +1 -1
  161. package/lib/js/quadTree/earth/EarthEntityCollectionNodeLonLat.js +2 -2
  162. package/lib/js/quadTree/equi/EquiEntityCollectionNodeLonLat.d.ts +1 -1
  163. package/lib/js/quadTree/equi/EquiEntityCollectionNodeLonLat.js +2 -2
  164. package/lib/js/renderer/Renderer.d.ts +63 -44
  165. package/lib/js/renderer/Renderer.js +267 -266
  166. package/lib/js/renderer/RendererEvents.d.ts +2 -0
  167. package/lib/js/renderer/RendererEvents.js +5 -2
  168. package/lib/js/scene/Planet.d.ts +15 -7
  169. package/lib/js/scene/Planet.js +133 -90
  170. package/lib/js/scene/RenderNode.d.ts +10 -25
  171. package/lib/js/scene/RenderNode.js +70 -58
  172. package/lib/js/segment/Segment.js +4 -4
  173. package/lib/js/shaders/depth.js +2 -5
  174. package/lib/js/shaders/drawnode.d.ts +1 -0
  175. package/lib/js/shaders/drawnode.js +51 -52
  176. package/lib/js/shaders/geoObject.d.ts +1 -0
  177. package/lib/js/shaders/geoObject.js +154 -91
  178. package/lib/js/shaders/polyline.js +68 -51
  179. package/lib/js/shaders/utils.d.ts +1 -1
  180. package/lib/js/shaders/utils.js +11 -0
  181. package/lib/js/terrain/GlobusTerrain.js +2 -2
  182. package/lib/js/ui/Checkbox.d.ts +31 -0
  183. package/lib/js/ui/Checkbox.js +110 -0
  184. package/lib/js/ui/Color.js +2 -1
  185. package/lib/js/ui/Dialog.d.ts +3 -0
  186. package/lib/js/ui/Dialog.js +20 -0
  187. package/lib/js/ui/Input.d.ts +32 -0
  188. package/lib/js/ui/Input.js +107 -0
  189. package/lib/js/ui/View.d.ts +3 -1
  190. package/lib/js/ui/View.js +6 -0
  191. package/lib/js/utils/objParser.d.ts +44 -12
  192. package/lib/js/utils/objParser.js +241 -149
  193. package/lib/js/utils/shared.d.ts +22 -0
  194. package/lib/js/utils/shared.js +34 -0
  195. package/lib/js/webgl/BaseFramebuffer.d.ts +0 -1
  196. package/lib/js/webgl/Framebuffer.d.ts +35 -8
  197. package/lib/js/webgl/Framebuffer.js +136 -29
  198. package/lib/js/webgl/Handler.d.ts +22 -12
  199. package/lib/js/webgl/Handler.js +53 -34
  200. package/lib/js/webgl/Program.js +0 -8
  201. package/package.json +5 -3
  202. package/lib/@openglobus/js/control/EarthNavigation.d.ts +0 -50
  203. package/lib/@openglobus/js/control/MouseWheelZoomControl.d.ts +0 -44
  204. package/lib/js/control/EarthNavigation.d.ts +0 -50
  205. package/lib/js/control/EarthNavigation.js +0 -202
@@ -4,6 +4,7 @@ import { createRendererEvents } from "./RendererEvents";
4
4
  import { depth } from "../shaders/depth";
5
5
  import { Framebuffer, Multisample } from "../webgl/index";
6
6
  import { FontAtlas } from "../utils/FontAtlas";
7
+ import { Handler } from "../webgl/Handler";
7
8
  import { input } from "../input/input";
8
9
  import { isEmpty } from "../utils/shared";
9
10
  import { LabelWorker } from "../entity/LabelWorker";
@@ -13,10 +14,11 @@ import { toneMapping } from "../shaders/toneMapping";
13
14
  import { TextureAtlas } from "../utils/TextureAtlas";
14
15
  import { Vec2 } from "../math/Vec2";
15
16
  import { Vec3 } from "../math/Vec3";
17
+ import { Vec4 } from "../math/Vec4";
16
18
  const MSAA_DEFAULT = 0;
17
19
  let __pickingCallbackCounter__ = 0;
18
20
  let __depthCallbackCounter__ = 0;
19
- let __distanceCallbackCounter__ = 0;
21
+ let _tempDepth_ = new Float32Array(2);
20
22
  function clientWaitAsync(gl, sync, flags) {
21
23
  return new Promise((resolve, reject) => {
22
24
  function check() {
@@ -34,109 +36,27 @@ function clientWaitAsync(gl, sync, flags) {
34
36
  check();
35
37
  });
36
38
  }
37
- /**
38
- * Represents high level WebGL context interface that starts WebGL handler working in real time.
39
- * @class
40
- * @param {Handler} handler - WebGL handler context.
41
- * @param {Object} [params] - Renderer parameters:
42
- * @fires EventsHandler<RendererEventsType>#draw
43
- * @fires EventsHandler<RendererEventsType>#resize
44
- * @fires EventsHandler<RendererEventsType>#mousemove
45
- * @fires EventsHandler<RendererEventsType>#mousestop
46
- * @fires EventsHandler<RendererEventsType>#lclick
47
- * @fires EventsHandler<RendererEventsType>#rclick
48
- * @fires EventsHandler<RendererEventsType>#mclick
49
- * @fires EventsHandler<RendererEventsType>#ldblclick
50
- * @fires EventsHandler<RendererEventsType>#rdblclick
51
- * @fires EventsHandler<RendererEventsType>#mdblclick
52
- * @fires EventsHandler<RendererEventsType>#lup
53
- * @fires EventsHandler<RendererEventsType>#rup
54
- * @fires EventsHandler<RendererEventsType>#mup
55
- * @fires EventsHandler<RendererEventsType>#ldown
56
- * @fires EventsHandler<RendererEventsType>#rdown
57
- * @fires EventsHandler<RendererEventsType>#mdown
58
- * @fires EventsHandler<RendererEventsType>#lhold
59
- * @fires EventsHandler<RendererEventsType>#rhold
60
- * @fires EventsHandler<RendererEventsType>#mhold
61
- * @fires EventsHandler<RendererEventsType>#mousewheel
62
- * @fires EventsHandler<RendererEventsType>#touchstart
63
- * @fires EventsHandler<RendererEventsType>#touchend
64
- * @fires EventsHandler<RendererEventsType>#touchcancel
65
- * @fires EventsHandler<RendererEventsType>#touchmove
66
- * @fires EventsHandler<RendererEventsType>#doubletouch
67
- * @fires EventsHandler<RendererEventsType>#touchleave
68
- * @fires EventsHandler<RendererEventsType>#touchenter
69
- */
70
- let __resizeTimeout;
71
39
  class Renderer {
72
40
  constructor(handler, params = {}) {
73
- this._readPickingBuffer_webgl1 = () => {
74
- this.pickingFramebuffer.activate();
75
- this.pickingFramebuffer.readAllPixels(this._tempPickingPix_);
76
- this.pickingFramebuffer.deactivate();
77
- };
78
- this._readPickingBuffer_webgl2 = () => {
79
- const gl = this.handler.gl;
80
- const buf = this._pickingPixelBuffer;
81
- if (!this._skipPickingFrame) {
82
- this._skipPickingFrame = true;
83
- let dest = this._tempPickingPix_;
84
- let w = this.pickingFramebuffer.width, h = this.pickingFramebuffer.height;
85
- this.pickingFramebuffer.activate();
86
- gl.bindBuffer(gl.PIXEL_PACK_BUFFER, buf);
87
- gl.bufferData(gl.PIXEL_PACK_BUFFER, dest.byteLength, gl.STREAM_READ);
88
- gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, 0);
89
- gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
90
- this.pickingFramebuffer.deactivate();
91
- const sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0);
92
- gl.flush();
93
- clientWaitAsync(gl, sync, 0).then(() => {
94
- this._skipPickingFrame = false;
95
- gl.deleteSync(sync);
96
- gl.bindBuffer(gl.PIXEL_PACK_BUFFER, buf);
97
- gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 0, dest);
98
- gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
99
- });
100
- }
101
- };
102
- this._readDistanceBuffer_webgl1 = () => {
103
- this.distanceFramebuffer.activate();
104
- this.distanceFramebuffer.readAllPixels(this._tempDistancePix_);
105
- this.distanceFramebuffer.deactivate();
106
- };
107
- this._readDistanceBuffer_webgl2 = () => {
108
- const gl = this.handler.gl;
109
- const buf = this._distancePixelBuffer;
110
- if (!this._skipDistanceFrame) {
111
- this._skipDistanceFrame = true;
112
- let dest = this._tempDistancePix_;
113
- let w = this.distanceFramebuffer.width, h = this.distanceFramebuffer.height;
114
- this.distanceFramebuffer.activate();
115
- gl.bindBuffer(gl.PIXEL_PACK_BUFFER, buf);
116
- gl.bufferData(gl.PIXEL_PACK_BUFFER, dest.byteLength, gl.STREAM_READ);
117
- gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, 0);
118
- gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
119
- this.distanceFramebuffer.deactivate();
120
- const sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0);
121
- gl.flush();
122
- clientWaitAsync(gl, sync, 0).then(() => {
123
- this._skipDistanceFrame = false;
124
- gl.deleteSync(sync);
125
- gl.bindBuffer(gl.PIXEL_PACK_BUFFER, buf);
126
- gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 0, dest);
127
- gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
128
- });
129
- }
130
- };
131
41
  this.div = null;
132
- this.handler = handler;
42
+ if (handler instanceof Handler) {
43
+ this.handler = handler;
44
+ }
45
+ else {
46
+ this.handler = new Handler(handler, {
47
+ pixelRatio: params.dpi || (window.devicePixelRatio + 0.15),
48
+ autoActivate: true
49
+ });
50
+ }
133
51
  this.exposure = params.exposure || 3.01;
134
52
  this.gamma = params.gamma || 0.47;
135
53
  this.whitepoint = 1.0;
136
54
  this.brightThreshold = 0.9;
137
55
  this._renderNodesArr = [];
138
56
  this.renderNodes = {};
139
- this.activeCamera = null;
57
+ this.activeCamera = new Camera(this, {
58
+ eye: new Vec3(0, 0, 0), look: new Vec3(0, 0, -1), up: new Vec3(0, 1, 0)
59
+ });
140
60
  this.events = createRendererEvents(this);
141
61
  this.controls = {};
142
62
  if (params.controls) {
@@ -148,10 +68,6 @@ class Renderer {
148
68
  this.colorObjects = new Map();
149
69
  this._pickingCallbacks = [];
150
70
  this.pickingFramebuffer = null;
151
- this._tempPickingPix_ = new Uint8Array([]);
152
- this.distanceFramebuffer = null;
153
- this._distanceCallbacks = [];
154
- this._tempDistancePix_ = new Uint8Array([]);
155
71
  this._depthCallbacks = [];
156
72
  this.depthFramebuffer = null;
157
73
  let urlParams = new URLSearchParams(location.search);
@@ -187,20 +103,14 @@ class Renderer {
187
103
  * @type {FontAtlas}
188
104
  */
189
105
  this.fontAtlas = new FontAtlas(params.fontsSrc);
190
- this._entityCollections = [];
106
+ this._entityCollections = [[]];
191
107
  this._currentOutput = "screen";
192
108
  this._fnScreenFrame = null;
193
109
  this.labelWorker = new LabelWorker(4);
194
- this.__useDistanceFramebuffer__ = true;
195
110
  this.screenDepthFramebuffer = null;
196
111
  this.screenFramePositionBuffer = null;
197
112
  this.screenTexture = {};
198
113
  this.outputTexture = null;
199
- this._skipDistanceFrame = false;
200
- this._distancePixelBuffer = null;
201
- this._skipPickingFrame = false;
202
- this._pickingPixelBuffer = null;
203
- this._readDistanceBuffer = this._readDistanceBuffer_webgl2;
204
114
  this._readPickingBuffer = this._readPickingBuffer_webgl2;
205
115
  if (params.autoActivate || isEmpty(params.autoActivate)) {
206
116
  this.start();
@@ -218,6 +128,9 @@ class Renderer {
218
128
  gl.blendEquation(gl.FUNC_ADD);
219
129
  gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE);
220
130
  }
131
+ setRelativeCenter(c) {
132
+ this.events.dispatch(this.events.changerelativecenter, c || this.activeCamera.eye);
133
+ }
221
134
  /**
222
135
  * Sets renderer events activity.
223
136
  * @param {Boolean} activity - Events activity.
@@ -240,21 +153,6 @@ class Renderer {
240
153
  }
241
154
  }
242
155
  }
243
- addDistanceCallback(sender, callback) {
244
- let id = __distanceCallbackCounter__++;
245
- this._distanceCallbacks.push({
246
- id: id, callback: callback, sender: sender
247
- });
248
- return id;
249
- }
250
- removeDistanceCallback(id) {
251
- for (let i = 0; i < this._distanceCallbacks.length; i++) {
252
- if (id === this._distanceCallbacks[i].id) {
253
- this._distanceCallbacks.splice(i, 1);
254
- break;
255
- }
256
- }
257
- }
258
156
  /**
259
157
  * Adds picking rendering callback function.
260
158
  * @param {object} sender - Callback context.
@@ -406,9 +304,6 @@ class Renderer {
406
304
  this.handler.setFrameCallback(() => {
407
305
  this.draw();
408
306
  });
409
- this.activeCamera = new Camera(this, {
410
- eye: new Vec3(0, 0, 0), look: new Vec3(0, 0, -1), up: new Vec3(0, 1, 0)
411
- });
412
307
  this.events.initialize();
413
308
  // Bind console key
414
309
  this.events.on("charkeypress", input.KEY_APOSTROPHE, function () {
@@ -416,23 +311,28 @@ class Renderer {
416
311
  });
417
312
  this.handler.addProgram(screenFrame());
418
313
  this.pickingFramebuffer = new Framebuffer(this.handler, {
419
- width: 640, height: 480
314
+ width: 640,
315
+ height: 480,
316
+ targets: [{
317
+ readAsync: true
318
+ }]
420
319
  });
421
320
  this.pickingFramebuffer.init();
422
- this._tempPickingPix_ = new Uint8Array(this.pickingFramebuffer.width * this.pickingFramebuffer.height * 4);
423
- this.distanceFramebuffer = new Framebuffer(this.handler, {
424
- width: 320, height: 240
425
- });
426
- this.distanceFramebuffer.init();
427
- this._tempDistancePix_ = new Uint8Array(this.distanceFramebuffer.width * this.distanceFramebuffer.height * 4);
428
- //this._tempDistancePix_ = new Uint8Array(4);
429
321
  this.depthFramebuffer = new Framebuffer(this.handler, {
430
- size: 2,
431
- internalFormat: ["RGBA", "DEPTH_COMPONENT24"],
432
- format: ["RGBA", "DEPTH_COMPONENT"],
433
- type: ["UNSIGNED_BYTE", "UNSIGNED_INT"],
434
- attachment: ["COLOR_ATTACHMENT", "DEPTH_ATTACHMENT"],
435
- useDepth: false
322
+ width: 640,
323
+ height: 480,
324
+ targets: [{
325
+ internalFormat: "RGBA",
326
+ type: "UNSIGNED_BYTE",
327
+ attachment: "COLOR_ATTACHMENT",
328
+ readAsync: true
329
+ }, {
330
+ internalFormat: "RGBA16F",
331
+ type: "FLOAT",
332
+ attachment: "COLOR_ATTACHMENT",
333
+ readAsync: true
334
+ }],
335
+ useDepth: true
436
336
  });
437
337
  this.depthFramebuffer.init();
438
338
  this.screenDepthFramebuffer = new Framebuffer(this.handler, {
@@ -440,7 +340,6 @@ class Renderer {
440
340
  });
441
341
  this.screenDepthFramebuffer.init();
442
342
  if (this.handler.gl.type === "webgl") {
443
- this._readDistanceBuffer = this._readDistanceBuffer_webgl1;
444
343
  this._readPickingBuffer = this._readPickingBuffer_webgl1;
445
344
  this.sceneFramebuffer = new Framebuffer(this.handler);
446
345
  this.sceneFramebuffer.init();
@@ -448,7 +347,6 @@ class Renderer {
448
347
  this.screenTexture = {
449
348
  screen: this.sceneFramebuffer.textures[0],
450
349
  picking: this.pickingFramebuffer.textures[0],
451
- distance: this.distanceFramebuffer.textures[0],
452
350
  depth: this.screenDepthFramebuffer.textures[0]
453
351
  };
454
352
  }
@@ -469,10 +367,12 @@ class Renderer {
469
367
  this.blitFramebuffer = new Framebuffer(this.handler, {
470
368
  size: 1,
471
369
  useDepth: false,
472
- internalFormat: this._internalFormat,
473
- format: this._format,
474
- type: this._type,
475
- filter: "NEAREST"
370
+ targets: [{
371
+ internalFormat: this._internalFormat,
372
+ format: this._format,
373
+ type: this._type,
374
+ filter: "NEAREST"
375
+ }]
476
376
  });
477
377
  this.blitFramebuffer.init();
478
378
  this.toneMappingFramebuffer = new Framebuffer(this.handler, {
@@ -483,11 +383,9 @@ class Renderer {
483
383
  this.screenTexture = {
484
384
  screen: this.toneMappingFramebuffer.textures[0],
485
385
  picking: this.pickingFramebuffer.textures[0],
486
- distance: this.distanceFramebuffer.textures[0],
487
386
  depth: this.screenDepthFramebuffer.textures[0],
488
387
  frustum: this.depthFramebuffer.textures[0]
489
388
  };
490
- this._initReadPixelsBuffers();
491
389
  }
492
390
  this.handler.ONCANVASRESIZE = () => {
493
391
  this._resizeStart();
@@ -505,17 +403,6 @@ class Renderer {
505
403
  this._initializeRenderNodes();
506
404
  this._initializeControls();
507
405
  }
508
- _initReadPixelsBuffers() {
509
- let gl = this.handler.gl;
510
- this._distancePixelBuffer = gl.createBuffer();
511
- gl.bindBuffer(gl.PIXEL_PACK_BUFFER, this._distancePixelBuffer);
512
- gl.bufferData(gl.PIXEL_PACK_BUFFER, this.distanceFramebuffer.width * this.distanceFramebuffer.height * 4, gl.STREAM_READ);
513
- gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
514
- this._pickingPixelBuffer = gl.createBuffer();
515
- gl.bindBuffer(gl.PIXEL_PACK_BUFFER, this._pickingPixelBuffer);
516
- gl.bufferData(gl.PIXEL_PACK_BUFFER, this.pickingFramebuffer.width * this.pickingFramebuffer.height * 4, gl.STREAM_READ);
517
- gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
518
- }
519
406
  _initializeControls() {
520
407
  let temp = this.controls;
521
408
  this.controls = {};
@@ -544,19 +431,17 @@ class Renderer {
544
431
  this.sceneFramebuffer.setSize(c.width, c.height);
545
432
  this.blitFramebuffer && this.blitFramebuffer.setSize(c.width, c.height, true);
546
433
  this.toneMappingFramebuffer && this.toneMappingFramebuffer.setSize(c.width, c.height, true);
547
- this.depthFramebuffer && this.depthFramebuffer.setSize(c.clientWidth, c.clientHeight, true);
548
434
  this.screenDepthFramebuffer && this.screenDepthFramebuffer.setSize(c.clientWidth, c.clientHeight, true);
435
+ //this.depthFramebuffer && this.depthFramebuffer.setSize(c.clientWidth, c.clientHeight, true);
549
436
  if (this.handler.gl.type === "webgl") {
550
437
  this.screenTexture.screen = this.sceneFramebuffer.textures[0];
551
438
  this.screenTexture.picking = this.pickingFramebuffer.textures[0];
552
- this.screenTexture.distance = this.distanceFramebuffer.textures[0];
553
439
  this.screenTexture.depth = this.screenDepthFramebuffer.textures[0];
554
440
  this.screenTexture.frustum = this.depthFramebuffer.textures[0];
555
441
  }
556
442
  else {
557
443
  this.screenTexture.screen = this.toneMappingFramebuffer.textures[0];
558
444
  this.screenTexture.picking = this.pickingFramebuffer.textures[0];
559
- this.screenTexture.distance = this.distanceFramebuffer.textures[0];
560
445
  this.screenTexture.depth = this.screenDepthFramebuffer.textures[0];
561
446
  this.screenTexture.frustum = this.depthFramebuffer.textures[0];
562
447
  }
@@ -629,35 +514,27 @@ class Renderer {
629
514
  /**
630
515
  * TODO: replace with cache friendly linked list by BillboardHandler, LabelHandler etc.
631
516
  */
632
- enqueueEntityCollectionsToDraw(ecArr) {
633
- this._entityCollections.push.apply(this._entityCollections, ecArr);
517
+ enqueueEntityCollectionsToDraw(ecArr, depthOrder = 0) {
518
+ if (!this._entityCollections[depthOrder]) {
519
+ this._entityCollections[depthOrder] = [];
520
+ }
521
+ this._entityCollections[depthOrder].push(...ecArr);
634
522
  }
635
523
  /**
636
- * Draws opaque items entity collections.
637
524
  * @protected
638
525
  */
639
- _drawOpaqueEntityCollections() {
640
- let ec = this._entityCollections;
526
+ _drawEntityCollections(depthOrder) {
527
+ let ec = this._entityCollections[depthOrder];
641
528
  if (ec.length) {
529
+ let gl = this.handler.gl;
642
530
  this.enableBlendDefault();
643
- // pointClouds pass
531
+ // Point Clouds
644
532
  let i = ec.length;
645
533
  while (i--) {
646
534
  ec[i]._fadingOpacity && ec[i].pointCloudHandler.draw();
647
535
  }
648
- }
649
- }
650
- /**
651
- * Draws transparent items entity collections.
652
- * @protected
653
- */
654
- _drawTransparentEntityCollections() {
655
- let ec = this._entityCollections;
656
- if (ec.length) {
657
- let gl = this.handler.gl;
658
- this.enableBlendDefault();
659
536
  // GeoObjects
660
- let i = ec.length;
537
+ i = ec.length;
661
538
  while (i--) {
662
539
  let eci = ec[i];
663
540
  if (ec[i]._fadingOpacity) {
@@ -700,9 +577,75 @@ class Renderer {
700
577
  }
701
578
  }
702
579
  }
703
- _clearEntityCollectionQueue() {
704
- this._entityCollections.length = 0;
705
- this._entityCollections = [];
580
+ _drawPickingEntityCollections(depthOrder) {
581
+ let ec = this._entityCollections[depthOrder];
582
+ if (ec.length) {
583
+ // billboard pass
584
+ let i = ec.length;
585
+ while (i--) {
586
+ ec[i]._fadingOpacity && ec[i].billboardHandler.drawPicking();
587
+ }
588
+ // geoObject pass
589
+ i = ec.length;
590
+ while (i--) {
591
+ ec[i]._fadingOpacity && ec[i].geoObjectHandler.drawPicking();
592
+ }
593
+ // label pass
594
+ i = ec.length;
595
+ while (i--) {
596
+ ec[i]._fadingOpacity && ec[i].labelHandler.drawPicking();
597
+ }
598
+ // ray pass
599
+ i = ec.length;
600
+ while (i--) {
601
+ ec[i]._fadingOpacity && ec[i].rayHandler.drawPicking();
602
+ }
603
+ // polyline pass
604
+ i = ec.length;
605
+ while (i--) {
606
+ ec[i]._visibility && ec[i].polylineHandler.drawPicking();
607
+ }
608
+ //Strip pass
609
+ i = ec.length;
610
+ while (i--) {
611
+ ec[i]._visibility && ec[i].stripHandler.drawPicking();
612
+ }
613
+ // //pointClouds pass
614
+ // i = ec.length;
615
+ // while (i--) {
616
+ // ec[i]._visibility && ec[i].pointCloudHandler.drawPicking();
617
+ // }
618
+ }
619
+ }
620
+ _drawDepthEntityCollections(depthOrder) {
621
+ let ec = this._entityCollections[depthOrder];
622
+ if (ec.length) {
623
+ // geoObject pass
624
+ let i = ec.length;
625
+ while (i--) {
626
+ ec[i]._fadingOpacity && ec[i].geoObjectHandler.drawDepth();
627
+ }
628
+ // i = ec.length;
629
+ // while (i--) {
630
+ // ec[i]._fadingOpacity && ec[i].rayHandler.drawDepth();
631
+ // }
632
+ //
633
+ // // polyline pass
634
+ // i = ec.length;
635
+ // while (i--) {
636
+ // ec[i]._visibility && ec[i].polylineHandler.drawDepth();
637
+ // }
638
+ //
639
+ // //Strip pass
640
+ // i = ec.length;
641
+ // while (i--) {
642
+ // ec[i]._visibility && ec[i].stripHandler.drawDepth();
643
+ // }
644
+ }
645
+ }
646
+ _clearEntityCollectionQueue(depthOrder) {
647
+ this._entityCollections[depthOrder].length = 0;
648
+ this._entityCollections[depthOrder] = [];
706
649
  }
707
650
  /**
708
651
  * Draw nodes.
@@ -721,10 +664,13 @@ class Renderer {
721
664
  e.dispatch(e.draw, this);
722
665
  let frustums = this.activeCamera.frustums;
723
666
  let pointerEvent = e.pointerEvent();
724
- let mouseHold = e.mouseState.leftButtonDown || e.mouseState.rightButtonDown;
667
+ let mouseFree = !e.mouseState.leftButtonDown && !e.mouseState.rightButtonDown;
725
668
  // Rendering scene nodes and entityCollections
726
669
  let rn = this._renderNodesArr;
727
670
  let k = frustums.length;
671
+ //
672
+ // RenderNodes PASS
673
+ //
728
674
  while (k--) {
729
675
  this.activeCamera.setCurrentFrustum(k);
730
676
  gl.clear(gl.DEPTH_BUFFER_BIT);
@@ -732,30 +678,43 @@ class Renderer {
732
678
  while (i--) {
733
679
  rn[i].preDrawNode();
734
680
  }
735
- this._drawOpaqueEntityCollections();
736
681
  i = rn.length;
737
682
  while (i--) {
738
683
  this.enableBlendDefault();
739
684
  rn[i].drawNode();
740
685
  }
741
- this._drawTransparentEntityCollections();
742
- this._clearEntityCollectionQueue();
686
+ this._drawEntityCollections(0);
743
687
  e.dispatch(e.drawtransparent, this);
744
- if (pointerEvent && !mouseHold) {
745
- this._drawPickingBuffer();
688
+ if (pointerEvent && mouseFree) {
689
+ this._drawPickingBuffer(0);
690
+ }
691
+ this._drawDepthBuffer(0);
692
+ this._clearEntityCollectionQueue(0);
693
+ }
694
+ //
695
+ // EntityCollections PASS
696
+ //
697
+ for (let i = 1; i < this._entityCollections.length; i++) {
698
+ gl.clear(gl.DEPTH_BUFFER_BIT);
699
+ let k = frustums.length;
700
+ while (k--) {
701
+ this.activeCamera.setCurrentFrustum(k);
702
+ this._drawEntityCollections(i);
703
+ if (pointerEvent && mouseFree) {
704
+ this._drawPickingBuffer(i);
705
+ }
706
+ this._drawDepthBuffer(i);
746
707
  }
747
- this.__useDistanceFramebuffer__ && this._drawDistanceBuffer();
708
+ this._clearEntityCollectionQueue(i);
748
709
  }
749
710
  sceneFramebuffer.deactivate();
750
711
  this.blitFramebuffer && sceneFramebuffer.blitTo(this.blitFramebuffer, 0);
751
- if (pointerEvent) {
752
- if (h.isWebGl2()) {
753
- // It works ONLY for 0 (closest) frustum
754
- this._drawDepthBuffer();
755
- }
712
+ if (pointerEvent && mouseFree) {
756
713
  this._readPickingBuffer();
757
714
  }
758
- this.__useDistanceFramebuffer__ && this._readDistanceBuffer();
715
+ if (mouseFree) {
716
+ this._readDepthBuffer();
717
+ }
759
718
  // Tone mapping followed by rendering on the screen
760
719
  this._fnScreenFrame();
761
720
  e.dispatch(e.postdraw, this);
@@ -812,87 +771,86 @@ class Renderer {
812
771
  * Draw picking objects framebuffer.
813
772
  * @private
814
773
  */
815
- _drawPickingBuffer() {
774
+ _drawPickingBuffer(depthOrder) {
816
775
  this.pickingFramebuffer.activate();
817
776
  let h = this.handler;
818
777
  let gl = h.gl;
819
- if (this.activeCamera.isFirstPass) {
778
+ if (this.activeCamera.isFirstPass && depthOrder === 0) {
820
779
  gl.clearColor(0.0, 0.0, 0.0, 1.0);
821
780
  gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
822
781
  }
823
782
  else {
824
783
  gl.clear(gl.DEPTH_BUFFER_BIT);
825
784
  }
826
- let dp = this._pickingCallbacks;
827
- for (let i = 0, len = dp.length; i < len; i++) {
828
- //
829
- // draw picking scenes, usually we don't need blending,
830
- // but sometimes set it manually in the callbacks
831
- //
832
- gl.disable(gl.BLEND);
833
- /**
834
- * This callback renders picking frame.
835
- */
836
- dp[i].callback.call(dp[i].sender);
837
- gl.enable(gl.BLEND);
785
+ //
786
+ // draw picking scenes, usually we don't need blending,
787
+ // but sometimes set it manually in the callbacks
788
+ //
789
+ gl.disable(gl.BLEND);
790
+ if (depthOrder === 0) {
791
+ let dp = this._pickingCallbacks;
792
+ for (let i = 0, len = dp.length; i < len; i++) {
793
+ /**
794
+ * This callback renders picking frame.
795
+ */
796
+ dp[i].callback.call(dp[i].sender);
797
+ }
838
798
  }
799
+ this._drawPickingEntityCollections(depthOrder);
800
+ gl.enable(gl.BLEND);
839
801
  this.pickingFramebuffer.deactivate();
840
802
  }
841
- /**
842
- * Draw picking objects framebuffer.
843
- * @protected
844
- */
845
- _drawDistanceBuffer() {
846
- this.distanceFramebuffer.activate();
803
+ _drawDepthBuffer(depthOrder) {
804
+ this.depthFramebuffer.activate();
847
805
  let h = this.handler;
848
806
  let gl = h.gl;
849
- if (this.activeCamera.isFirstPass) {
807
+ gl.disable(gl.BLEND);
808
+ if (this.activeCamera.isFirstPass && depthOrder === 0) {
850
809
  gl.clearColor(0.0, 0.0, 0.0, 1.0);
851
810
  gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
852
811
  }
853
812
  else {
854
813
  gl.clear(gl.DEPTH_BUFFER_BIT);
855
814
  }
856
- gl.disable(gl.BLEND);
857
- let dp = this._distanceCallbacks;
858
- let i = dp.length;
859
- while (i--) {
860
- /**
861
- * This callback renders distance frame.
862
- */
863
- dp[i].callback.call(dp[i].sender);
864
- }
865
- gl.enable(gl.BLEND);
866
- this.distanceFramebuffer.deactivate();
867
- }
868
- _drawDepthBuffer() {
869
- this.depthFramebuffer.activate();
870
- let h = this.handler;
871
- let gl = h.gl;
872
- gl.clearColor(0.0, 0.0, 0.0, 1.0);
873
- gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
874
- gl.enable(gl.DEPTH_TEST);
875
- let dp = this._depthCallbacks;
876
- let i = dp.length;
877
- while (i--) {
878
- /**
879
- * This callback renders depth frame.
880
- */
881
- dp[i].callback.call(dp[i].sender);
815
+ if (depthOrder === 0) {
816
+ let dp = this._depthCallbacks;
817
+ let i = dp.length;
818
+ while (i--) {
819
+ /**
820
+ * This callback renders depth frame.
821
+ */
822
+ dp[i].callback.call(dp[i].sender);
823
+ }
882
824
  }
825
+ this._drawDepthEntityCollections(depthOrder);
883
826
  this.depthFramebuffer.deactivate();
884
827
  //
885
- // PASS to depth visualization
886
- this.screenDepthFramebuffer.activate();
887
- let sh = h.programs.depth, p = sh._program;
888
- gl.bindBuffer(gl.ARRAY_BUFFER, this.screenFramePositionBuffer);
889
- gl.vertexAttribPointer(p.attributes.corners, 2, gl.FLOAT, false, 0, 0);
890
- sh.activate();
891
- gl.activeTexture(gl.TEXTURE0);
892
- gl.bindTexture(gl.TEXTURE_2D, this.depthFramebuffer.textures[1]);
893
- gl.uniform1i(p.uniforms.depthTexture, 0);
894
- gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
895
- this.screenDepthFramebuffer.deactivate();
828
+ // DEBUG SCREEN OUTPUTS
829
+ //
830
+ if (this._currentOutput === "depth" || this._currentOutput === "frustum") {
831
+ //
832
+ // PASS to depth visualization
833
+ this.screenDepthFramebuffer.activate();
834
+ let sh = h.programs.depth, p = sh._program;
835
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.screenFramePositionBuffer);
836
+ gl.vertexAttribPointer(p.attributes.corners, 2, gl.FLOAT, false, 0, 0);
837
+ sh.activate();
838
+ gl.activeTexture(gl.TEXTURE0);
839
+ gl.bindTexture(gl.TEXTURE_2D, this.depthFramebuffer.textures[1]);
840
+ gl.uniform1i(p.uniforms.depthTexture, 0);
841
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
842
+ this.screenDepthFramebuffer.deactivate();
843
+ gl.enable(gl.BLEND);
844
+ }
845
+ }
846
+ _readDepthBuffer() {
847
+ this.depthFramebuffer.readPixelBuffersAsync();
848
+ }
849
+ _readPickingBuffer_webgl1() {
850
+ this.pickingFramebuffer.readPixelBuffersAsync();
851
+ }
852
+ _readPickingBuffer_webgl2() {
853
+ this.pickingFramebuffer.readPixelBuffersAsync();
896
854
  }
897
855
  readPickingColor(x, y, outColor) {
898
856
  let w = this.pickingFramebuffer.width;
@@ -900,19 +858,65 @@ class Renderer {
900
858
  x = Math.round(x * w);
901
859
  y = Math.round(y * h);
902
860
  let ind = (y * w + x) * 4;
903
- outColor[0] = this._tempPickingPix_[ind];
904
- outColor[1] = this._tempPickingPix_[ind + 1];
905
- outColor[2] = this._tempPickingPix_[ind + 2];
861
+ let _tempPickingPix_ = this.pickingFramebuffer?.pixelBuffers[0].data;
862
+ if (_tempPickingPix_) {
863
+ outColor[0] = _tempPickingPix_[ind];
864
+ outColor[1] = _tempPickingPix_[ind + 1];
865
+ outColor[2] = _tempPickingPix_[ind + 2];
866
+ }
906
867
  }
907
- readDistanceColor(x, y, outColor) {
908
- let w = this.distanceFramebuffer.width;
909
- let h = this.distanceFramebuffer.height;
868
+ readDepth(x, y, outDepth) {
869
+ let w = this.depthFramebuffer.width;
870
+ let h = this.depthFramebuffer.height;
910
871
  x = Math.round(x * w);
911
872
  y = Math.round(y * h);
912
873
  let ind = (y * w + x) * 4;
913
- outColor[0] = this._tempDistancePix_[ind];
914
- outColor[1] = this._tempDistancePix_[ind + 1];
915
- outColor[2] = this._tempDistancePix_[ind + 2];
874
+ let _tempDepthPix_ = this.depthFramebuffer?.pixelBuffers[1].data;
875
+ let _tempFrustumPix_ = this.depthFramebuffer?.pixelBuffers[0].data;
876
+ if (_tempDepthPix_) {
877
+ outDepth[0] = _tempDepthPix_[ind];
878
+ outDepth[1] = Math.round(_tempFrustumPix_[ind] / 10.0) - 1.0; // See Camera.frustumColorIndex
879
+ }
880
+ }
881
+ /**
882
+ * Returns the distance from the active (screen) camera to the 3d-surface using the defined screen coordinates
883
+ * @public
884
+ * @param {Vec2 | IBaseInputState} px - Screen coordinates.
885
+ * @returns {number | undefined} -
886
+ */
887
+ getDistanceFromPixel(px, camera) {
888
+ camera = camera || this.activeCamera;
889
+ let r = this;
890
+ let cnv = r.handler.canvas;
891
+ let spx = px.x / cnv.width;
892
+ let spy = (cnv.height - px.y) / cnv.height;
893
+ _tempDepth_[0] = _tempDepth_[1] = 0.0;
894
+ let dist = 0;
895
+ r.readDepth(spx, spy, _tempDepth_);
896
+ if (_tempDepth_[1] === -1) {
897
+ return;
898
+ }
899
+ let depth = _tempDepth_[0], frustum = camera.frustums[_tempDepth_[1]];
900
+ if (!frustum)
901
+ return;
902
+ let screenPos = new Vec4(spx * 2.0 - 1.0, spy * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0 * 2.0 - 1.0);
903
+ let viewPosition = frustum.inverseProjectionMatrix.mulVec4(screenPos);
904
+ let dir = px.direction || r.activeCamera.unproject(px.x, px.y);
905
+ dist = -(viewPosition.z / viewPosition.w) / dir.dot(r.activeCamera.getForward());
906
+ return dist;
907
+ }
908
+ /**
909
+ * Returns 3d coordinates from screen coordinates
910
+ * @public
911
+ * @param {Vec2 | IBaseInputState} px - Screen coordinates.
912
+ * @returns {Vec3 | undefined} -
913
+ */
914
+ getCartesianFromPixel(px) {
915
+ let distance = this.getDistanceFromPixel(px);
916
+ if (distance) {
917
+ let direction = px.direction || this.activeCamera.unproject(px.x, px.y);
918
+ return direction.scaleTo(distance).addA(this.activeCamera.eye);
919
+ }
916
920
  }
917
921
  /**
918
922
  * Function starts renderer
@@ -934,6 +938,7 @@ class Renderer {
934
938
  this.div = null;
935
939
  this._renderNodesArr = [];
936
940
  this.renderNodes = {};
941
+ //@ts-ignore
937
942
  this.activeCamera = null;
938
943
  this.controls = {};
939
944
  this.controlsBag = {};
@@ -944,10 +949,6 @@ class Renderer {
944
949
  this.pickingFramebuffer = null;
945
950
  //@ts-ignore
946
951
  this._tempPickingPix_ = null;
947
- this.distanceFramebuffer = null;
948
- this._distanceCallbacks = [];
949
- //@ts-ignore
950
- this._tempDistancePix_ = null;
951
952
  this._depthCallbacks = [];
952
953
  this.depthFramebuffer = null;
953
954
  this.sceneFramebuffer = null;
@@ -957,7 +958,7 @@ class Renderer {
957
958
  //this.billboardsTextureAtlas.clear();
958
959
  //this.geoObjectsTextureAtlas.clear()
959
960
  //this.fontAtlas.clear();
960
- this._entityCollections = [];
961
+ this._entityCollections = [[]];
961
962
  this.handler.ONCANVASRESIZE = null;
962
963
  this.handler.destroy();
963
964
  // @ts-ignore