@openglobus/og 0.22.1 → 0.23.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.
- package/css/og.css +137 -1
- package/lib/@openglobus/js/Object3d.d.ts +20 -10
- package/lib/@openglobus/js/camera/Camera.d.ts +9 -0
- package/lib/@openglobus/js/camera/Frustum.d.ts +3 -0
- package/lib/@openglobus/js/control/CameraLock.d.ts +38 -0
- package/lib/@openglobus/js/control/SimpleNavigation.d.ts +27 -10
- package/lib/@openglobus/js/control/geoObjectEditor/ArrowEntity.d.ts +15 -0
- package/lib/@openglobus/js/control/geoObjectEditor/AxisTrackEntity.d.ts +9 -0
- package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditor.d.ts +13 -0
- package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditorDialog.d.ts +69 -0
- package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditorScene.d.ts +78 -9
- package/lib/@openglobus/js/control/geoObjectEditor/MoveAxisEntity.d.ts +17 -0
- package/lib/@openglobus/js/control/geoObjectEditor/MovePlaneEntity.d.ts +7 -0
- package/lib/@openglobus/js/control/geoObjectEditor/RotateEntity.d.ts +9 -0
- package/lib/@openglobus/js/control/geoObjectEditor/colors.d.ts +8 -0
- package/lib/@openglobus/js/control/index.d.ts +2 -0
- package/lib/@openglobus/js/entity/Entity.d.ts +278 -19
- package/lib/@openglobus/js/entity/EntityCollection.d.ts +8 -9
- package/lib/@openglobus/js/entity/GeoObject.d.ts +141 -36
- package/lib/@openglobus/js/entity/GeoObjectHandler.d.ts +39 -63
- package/lib/@openglobus/js/entity/InstanceData.d.ts +76 -0
- package/lib/@openglobus/js/entity/Polyline.d.ts +19 -6
- package/lib/@openglobus/js/entity/PolylineHandler.d.ts +7 -0
- package/lib/@openglobus/js/index.d.ts +2 -1
- package/lib/@openglobus/js/layer/Vector.d.ts +4 -0
- package/lib/@openglobus/js/light/LightSource.d.ts +1 -139
- package/lib/@openglobus/js/math/Quat.d.ts +46 -33
- package/lib/@openglobus/js/math/Ray.d.ts +10 -4
- package/lib/@openglobus/js/math/Vec3.d.ts +15 -0
- package/lib/@openglobus/js/math.d.ts +2 -2
- package/lib/@openglobus/js/quadTree/EntityCollectionNode.d.ts +2 -2
- package/lib/@openglobus/js/quadTree/Node.d.ts +1 -1
- package/lib/@openglobus/js/quadTree/earth/EarthEntityCollectionNodeLonLat.d.ts +1 -1
- package/lib/@openglobus/js/quadTree/equi/EquiEntityCollectionNodeLonLat.d.ts +1 -1
- package/lib/@openglobus/js/renderer/Renderer.d.ts +64 -44
- package/lib/@openglobus/js/renderer/RendererEvents.d.ts +1 -0
- package/lib/@openglobus/js/scene/Planet.d.ts +11 -7
- package/lib/@openglobus/js/scene/RenderNode.d.ts +10 -25
- package/lib/@openglobus/js/shaders/drawnode.d.ts +1 -0
- package/lib/@openglobus/js/shaders/geoObject.d.ts +1 -0
- package/lib/@openglobus/js/shaders/utils.d.ts +1 -1
- package/lib/@openglobus/js/ui/Checkbox.d.ts +31 -0
- package/lib/@openglobus/js/ui/Dialog.d.ts +3 -0
- package/lib/@openglobus/js/ui/Input.d.ts +32 -0
- package/lib/@openglobus/js/ui/View.d.ts +3 -1
- package/lib/@openglobus/js/utils/objParser.d.ts +44 -12
- package/lib/@openglobus/js/utils/shared.d.ts +22 -0
- package/lib/@openglobus/js/webgl/BaseFramebuffer.d.ts +0 -1
- package/lib/@openglobus/js/webgl/Framebuffer.d.ts +35 -8
- package/lib/@openglobus/js/webgl/Handler.d.ts +3 -0
- package/lib/@openglobus/og.css +1 -1
- package/lib/@openglobus/og.esm.js +1 -1
- package/lib/@openglobus/og.esm.js.map +1 -1
- package/lib/@openglobus/og.umd.js +1 -1
- package/lib/@openglobus/og.umd.js.map +1 -1
- package/lib/js/Globe.js +2 -1
- package/lib/js/Object3d.d.ts +20 -10
- package/lib/js/Object3d.js +124 -48
- package/lib/js/camera/Camera.d.ts +9 -0
- package/lib/js/camera/Camera.js +27 -1
- package/lib/js/camera/Frustum.d.ts +3 -0
- package/lib/js/camera/Frustum.js +7 -0
- package/lib/js/control/Atmosphere.js +10 -6
- package/lib/js/control/CameraLock.d.ts +38 -0
- package/lib/js/control/CameraLock.js +216 -0
- package/lib/js/control/Control.js +1 -1
- package/lib/js/control/DebugInfo.js +13 -3
- package/lib/js/control/KeyboardNavigation.js +1 -1
- package/lib/js/control/ScaleControl.js +9 -3
- package/lib/js/control/SimpleNavigation.d.ts +27 -10
- package/lib/js/control/SimpleNavigation.js +148 -49
- package/lib/js/control/Sun.js +1 -1
- package/lib/js/control/elevationProfile/ElevationProfileScene.js +4 -4
- package/lib/js/control/geoObjectEditor/ArrowEntity.d.ts +15 -0
- package/lib/js/control/geoObjectEditor/ArrowEntity.js +59 -0
- package/lib/js/control/geoObjectEditor/AxisTrackEntity.d.ts +9 -0
- package/lib/js/control/geoObjectEditor/AxisTrackEntity.js +93 -0
- package/lib/js/control/geoObjectEditor/GeoObjectEditor.d.ts +13 -0
- package/lib/js/control/geoObjectEditor/GeoObjectEditor.js +30 -0
- package/lib/js/control/geoObjectEditor/GeoObjectEditorDialog.d.ts +69 -0
- package/lib/js/control/geoObjectEditor/GeoObjectEditorDialog.js +502 -0
- package/lib/js/control/geoObjectEditor/GeoObjectEditorScene.d.ts +78 -9
- package/lib/js/control/geoObjectEditor/GeoObjectEditorScene.js +487 -43
- package/lib/js/control/geoObjectEditor/MoveAxisEntity.d.ts +17 -0
- package/lib/js/control/geoObjectEditor/MoveAxisEntity.js +106 -0
- package/lib/js/control/geoObjectEditor/MovePlaneEntity.d.ts +7 -0
- package/lib/js/control/geoObjectEditor/MovePlaneEntity.js +34 -0
- package/lib/js/control/geoObjectEditor/RotateEntity.d.ts +9 -0
- package/lib/js/control/geoObjectEditor/RotateEntity.js +105 -0
- package/lib/js/control/geoObjectEditor/colors.d.ts +8 -0
- package/lib/js/control/geoObjectEditor/colors.js +8 -0
- package/lib/js/control/index.d.ts +2 -0
- package/lib/js/control/index.js +2 -0
- package/lib/js/control/timeline/TimelineControl.js +2 -0
- package/lib/js/entity/Entity.d.ts +278 -19
- package/lib/js/entity/Entity.js +483 -63
- package/lib/js/entity/EntityCollection.d.ts +8 -9
- package/lib/js/entity/EntityCollection.js +48 -45
- package/lib/js/entity/GeoObject.d.ts +141 -36
- package/lib/js/entity/GeoObject.js +153 -90
- package/lib/js/entity/GeoObjectHandler.d.ts +39 -63
- package/lib/js/entity/GeoObjectHandler.js +198 -295
- package/lib/js/entity/InstanceData.d.ts +76 -0
- package/lib/js/entity/InstanceData.js +344 -0
- package/lib/js/entity/Polyline.d.ts +19 -6
- package/lib/js/entity/Polyline.js +76 -36
- package/lib/js/entity/PolylineHandler.d.ts +7 -0
- package/lib/js/entity/PolylineHandler.js +26 -1
- package/lib/js/index.d.ts +2 -1
- package/lib/js/index.js +2 -1
- package/lib/js/layer/Bing.js +2 -2
- package/lib/js/layer/Vector.d.ts +4 -0
- package/lib/js/layer/Vector.js +16 -0
- package/lib/js/light/LightSource.d.ts +1 -139
- package/lib/js/light/LightSource.js +21 -227
- package/lib/js/math/Quat.d.ts +46 -33
- package/lib/js/math/Quat.js +91 -90
- package/lib/js/math/Ray.d.ts +10 -4
- package/lib/js/math/Ray.js +20 -4
- package/lib/js/math/Vec3.d.ts +15 -0
- package/lib/js/math/Vec3.js +30 -1
- package/lib/js/math.d.ts +2 -2
- package/lib/js/math.js +3 -3
- package/lib/js/quadTree/EntityCollectionNode.d.ts +2 -2
- package/lib/js/quadTree/EntityCollectionNode.js +8 -8
- package/lib/js/quadTree/Node.d.ts +1 -1
- package/lib/js/quadTree/Node.js +2 -2
- package/lib/js/quadTree/QuadTreeStrategy.js +1 -1
- package/lib/js/quadTree/earth/EarthEntityCollectionNodeLonLat.d.ts +1 -1
- package/lib/js/quadTree/earth/EarthEntityCollectionNodeLonLat.js +2 -2
- package/lib/js/quadTree/equi/EquiEntityCollectionNodeLonLat.d.ts +1 -1
- package/lib/js/quadTree/equi/EquiEntityCollectionNodeLonLat.js +2 -2
- package/lib/js/renderer/Renderer.d.ts +64 -44
- package/lib/js/renderer/Renderer.js +264 -263
- package/lib/js/renderer/RendererEvents.d.ts +1 -0
- package/lib/js/renderer/RendererEvents.js +2 -1
- package/lib/js/scene/Planet.d.ts +11 -7
- package/lib/js/scene/Planet.js +109 -87
- package/lib/js/scene/RenderNode.d.ts +10 -25
- package/lib/js/scene/RenderNode.js +70 -58
- package/lib/js/shaders/depth.js +2 -5
- package/lib/js/shaders/drawnode.d.ts +1 -0
- package/lib/js/shaders/drawnode.js +51 -52
- package/lib/js/shaders/geoObject.d.ts +1 -0
- package/lib/js/shaders/geoObject.js +154 -91
- package/lib/js/shaders/polyline.js +68 -51
- package/lib/js/shaders/utils.d.ts +1 -1
- package/lib/js/shaders/utils.js +11 -0
- package/lib/js/ui/Checkbox.d.ts +31 -0
- package/lib/js/ui/Checkbox.js +110 -0
- package/lib/js/ui/Color.js +2 -1
- package/lib/js/ui/Dialog.d.ts +3 -0
- package/lib/js/ui/Dialog.js +20 -0
- package/lib/js/ui/Input.d.ts +32 -0
- package/lib/js/ui/Input.js +107 -0
- package/lib/js/ui/View.d.ts +3 -1
- package/lib/js/ui/View.js +6 -0
- package/lib/js/utils/objParser.d.ts +44 -12
- package/lib/js/utils/objParser.js +241 -149
- package/lib/js/utils/shared.d.ts +22 -0
- package/lib/js/utils/shared.js +34 -0
- package/lib/js/webgl/BaseFramebuffer.d.ts +0 -1
- package/lib/js/webgl/Framebuffer.d.ts +35 -8
- package/lib/js/webgl/Framebuffer.js +136 -29
- package/lib/js/webgl/Handler.d.ts +3 -0
- package/lib/js/webgl/Handler.js +11 -1
- package/lib/js/webgl/Program.js +0 -8
- package/package.json +4 -2
|
@@ -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
|
|
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
|
-
|
|
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 =
|
|
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,26 @@ class Renderer {
|
|
|
416
311
|
});
|
|
417
312
|
this.handler.addProgram(screenFrame());
|
|
418
313
|
this.pickingFramebuffer = new Framebuffer(this.handler, {
|
|
419
|
-
width: 640,
|
|
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
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
322
|
+
targets: [{
|
|
323
|
+
internalFormat: "RGBA",
|
|
324
|
+
type: "UNSIGNED_BYTE",
|
|
325
|
+
attachment: "COLOR_ATTACHMENT",
|
|
326
|
+
readAsync: true
|
|
327
|
+
}, {
|
|
328
|
+
internalFormat: "RGBA16F",
|
|
329
|
+
type: "FLOAT",
|
|
330
|
+
attachment: "COLOR_ATTACHMENT",
|
|
331
|
+
readAsync: true
|
|
332
|
+
}],
|
|
333
|
+
useDepth: true
|
|
436
334
|
});
|
|
437
335
|
this.depthFramebuffer.init();
|
|
438
336
|
this.screenDepthFramebuffer = new Framebuffer(this.handler, {
|
|
@@ -440,7 +338,6 @@ class Renderer {
|
|
|
440
338
|
});
|
|
441
339
|
this.screenDepthFramebuffer.init();
|
|
442
340
|
if (this.handler.gl.type === "webgl") {
|
|
443
|
-
this._readDistanceBuffer = this._readDistanceBuffer_webgl1;
|
|
444
341
|
this._readPickingBuffer = this._readPickingBuffer_webgl1;
|
|
445
342
|
this.sceneFramebuffer = new Framebuffer(this.handler);
|
|
446
343
|
this.sceneFramebuffer.init();
|
|
@@ -448,7 +345,6 @@ class Renderer {
|
|
|
448
345
|
this.screenTexture = {
|
|
449
346
|
screen: this.sceneFramebuffer.textures[0],
|
|
450
347
|
picking: this.pickingFramebuffer.textures[0],
|
|
451
|
-
distance: this.distanceFramebuffer.textures[0],
|
|
452
348
|
depth: this.screenDepthFramebuffer.textures[0]
|
|
453
349
|
};
|
|
454
350
|
}
|
|
@@ -469,10 +365,12 @@ class Renderer {
|
|
|
469
365
|
this.blitFramebuffer = new Framebuffer(this.handler, {
|
|
470
366
|
size: 1,
|
|
471
367
|
useDepth: false,
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
368
|
+
targets: [{
|
|
369
|
+
internalFormat: this._internalFormat,
|
|
370
|
+
format: this._format,
|
|
371
|
+
type: this._type,
|
|
372
|
+
filter: "NEAREST"
|
|
373
|
+
}]
|
|
476
374
|
});
|
|
477
375
|
this.blitFramebuffer.init();
|
|
478
376
|
this.toneMappingFramebuffer = new Framebuffer(this.handler, {
|
|
@@ -483,11 +381,9 @@ class Renderer {
|
|
|
483
381
|
this.screenTexture = {
|
|
484
382
|
screen: this.toneMappingFramebuffer.textures[0],
|
|
485
383
|
picking: this.pickingFramebuffer.textures[0],
|
|
486
|
-
distance: this.distanceFramebuffer.textures[0],
|
|
487
384
|
depth: this.screenDepthFramebuffer.textures[0],
|
|
488
385
|
frustum: this.depthFramebuffer.textures[0]
|
|
489
386
|
};
|
|
490
|
-
this._initReadPixelsBuffers();
|
|
491
387
|
}
|
|
492
388
|
this.handler.ONCANVASRESIZE = () => {
|
|
493
389
|
this._resizeStart();
|
|
@@ -505,17 +401,6 @@ class Renderer {
|
|
|
505
401
|
this._initializeRenderNodes();
|
|
506
402
|
this._initializeControls();
|
|
507
403
|
}
|
|
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
404
|
_initializeControls() {
|
|
520
405
|
let temp = this.controls;
|
|
521
406
|
this.controls = {};
|
|
@@ -544,19 +429,17 @@ class Renderer {
|
|
|
544
429
|
this.sceneFramebuffer.setSize(c.width, c.height);
|
|
545
430
|
this.blitFramebuffer && this.blitFramebuffer.setSize(c.width, c.height, true);
|
|
546
431
|
this.toneMappingFramebuffer && this.toneMappingFramebuffer.setSize(c.width, c.height, true);
|
|
547
|
-
this.depthFramebuffer && this.depthFramebuffer.setSize(c.clientWidth, c.clientHeight, true);
|
|
548
432
|
this.screenDepthFramebuffer && this.screenDepthFramebuffer.setSize(c.clientWidth, c.clientHeight, true);
|
|
433
|
+
this.depthFramebuffer && this.depthFramebuffer.setSize(c.clientWidth, c.clientHeight, true);
|
|
549
434
|
if (this.handler.gl.type === "webgl") {
|
|
550
435
|
this.screenTexture.screen = this.sceneFramebuffer.textures[0];
|
|
551
436
|
this.screenTexture.picking = this.pickingFramebuffer.textures[0];
|
|
552
|
-
this.screenTexture.distance = this.distanceFramebuffer.textures[0];
|
|
553
437
|
this.screenTexture.depth = this.screenDepthFramebuffer.textures[0];
|
|
554
438
|
this.screenTexture.frustum = this.depthFramebuffer.textures[0];
|
|
555
439
|
}
|
|
556
440
|
else {
|
|
557
441
|
this.screenTexture.screen = this.toneMappingFramebuffer.textures[0];
|
|
558
442
|
this.screenTexture.picking = this.pickingFramebuffer.textures[0];
|
|
559
|
-
this.screenTexture.distance = this.distanceFramebuffer.textures[0];
|
|
560
443
|
this.screenTexture.depth = this.screenDepthFramebuffer.textures[0];
|
|
561
444
|
this.screenTexture.frustum = this.depthFramebuffer.textures[0];
|
|
562
445
|
}
|
|
@@ -629,35 +512,27 @@ class Renderer {
|
|
|
629
512
|
/**
|
|
630
513
|
* TODO: replace with cache friendly linked list by BillboardHandler, LabelHandler etc.
|
|
631
514
|
*/
|
|
632
|
-
enqueueEntityCollectionsToDraw(ecArr) {
|
|
633
|
-
|
|
515
|
+
enqueueEntityCollectionsToDraw(ecArr, depthOrder = 0) {
|
|
516
|
+
if (!this._entityCollections[depthOrder]) {
|
|
517
|
+
this._entityCollections[depthOrder] = [];
|
|
518
|
+
}
|
|
519
|
+
this._entityCollections[depthOrder].push(...ecArr);
|
|
634
520
|
}
|
|
635
521
|
/**
|
|
636
|
-
* Draws opaque items entity collections.
|
|
637
522
|
* @protected
|
|
638
523
|
*/
|
|
639
|
-
|
|
640
|
-
let ec = this._entityCollections;
|
|
524
|
+
_drawEntityCollections(depthOrder) {
|
|
525
|
+
let ec = this._entityCollections[depthOrder];
|
|
641
526
|
if (ec.length) {
|
|
527
|
+
let gl = this.handler.gl;
|
|
642
528
|
this.enableBlendDefault();
|
|
643
|
-
//
|
|
529
|
+
// Point Clouds
|
|
644
530
|
let i = ec.length;
|
|
645
531
|
while (i--) {
|
|
646
532
|
ec[i]._fadingOpacity && ec[i].pointCloudHandler.draw();
|
|
647
533
|
}
|
|
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
534
|
// GeoObjects
|
|
660
|
-
|
|
535
|
+
i = ec.length;
|
|
661
536
|
while (i--) {
|
|
662
537
|
let eci = ec[i];
|
|
663
538
|
if (ec[i]._fadingOpacity) {
|
|
@@ -700,9 +575,75 @@ class Renderer {
|
|
|
700
575
|
}
|
|
701
576
|
}
|
|
702
577
|
}
|
|
703
|
-
|
|
704
|
-
this._entityCollections
|
|
705
|
-
|
|
578
|
+
_drawPickingEntityCollections(depthOrder) {
|
|
579
|
+
let ec = this._entityCollections[depthOrder];
|
|
580
|
+
if (ec.length) {
|
|
581
|
+
// billboard pass
|
|
582
|
+
let i = ec.length;
|
|
583
|
+
while (i--) {
|
|
584
|
+
ec[i]._fadingOpacity && ec[i].billboardHandler.drawPicking();
|
|
585
|
+
}
|
|
586
|
+
// geoObject pass
|
|
587
|
+
i = ec.length;
|
|
588
|
+
while (i--) {
|
|
589
|
+
ec[i]._fadingOpacity && ec[i].geoObjectHandler.drawPicking();
|
|
590
|
+
}
|
|
591
|
+
// label pass
|
|
592
|
+
i = ec.length;
|
|
593
|
+
while (i--) {
|
|
594
|
+
ec[i]._fadingOpacity && ec[i].labelHandler.drawPicking();
|
|
595
|
+
}
|
|
596
|
+
// ray pass
|
|
597
|
+
i = ec.length;
|
|
598
|
+
while (i--) {
|
|
599
|
+
ec[i]._fadingOpacity && ec[i].rayHandler.drawPicking();
|
|
600
|
+
}
|
|
601
|
+
// polyline pass
|
|
602
|
+
i = ec.length;
|
|
603
|
+
while (i--) {
|
|
604
|
+
ec[i]._visibility && ec[i].polylineHandler.drawPicking();
|
|
605
|
+
}
|
|
606
|
+
//Strip pass
|
|
607
|
+
i = ec.length;
|
|
608
|
+
while (i--) {
|
|
609
|
+
ec[i]._visibility && ec[i].stripHandler.drawPicking();
|
|
610
|
+
}
|
|
611
|
+
// //pointClouds pass
|
|
612
|
+
// i = ec.length;
|
|
613
|
+
// while (i--) {
|
|
614
|
+
// ec[i]._visibility && ec[i].pointCloudHandler.drawPicking();
|
|
615
|
+
// }
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
_drawDepthEntityCollections(depthOrder) {
|
|
619
|
+
let ec = this._entityCollections[depthOrder];
|
|
620
|
+
if (ec.length) {
|
|
621
|
+
// geoObject pass
|
|
622
|
+
let i = ec.length;
|
|
623
|
+
while (i--) {
|
|
624
|
+
ec[i]._fadingOpacity && ec[i].geoObjectHandler.drawDepth();
|
|
625
|
+
}
|
|
626
|
+
// i = ec.length;
|
|
627
|
+
// while (i--) {
|
|
628
|
+
// ec[i]._fadingOpacity && ec[i].rayHandler.drawDepth();
|
|
629
|
+
// }
|
|
630
|
+
//
|
|
631
|
+
// // polyline pass
|
|
632
|
+
// i = ec.length;
|
|
633
|
+
// while (i--) {
|
|
634
|
+
// ec[i]._visibility && ec[i].polylineHandler.drawDepth();
|
|
635
|
+
// }
|
|
636
|
+
//
|
|
637
|
+
// //Strip pass
|
|
638
|
+
// i = ec.length;
|
|
639
|
+
// while (i--) {
|
|
640
|
+
// ec[i]._visibility && ec[i].stripHandler.drawDepth();
|
|
641
|
+
// }
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
_clearEntityCollectionQueue(depthOrder) {
|
|
645
|
+
this._entityCollections[depthOrder].length = 0;
|
|
646
|
+
this._entityCollections[depthOrder] = [];
|
|
706
647
|
}
|
|
707
648
|
/**
|
|
708
649
|
* Draw nodes.
|
|
@@ -725,6 +666,9 @@ class Renderer {
|
|
|
725
666
|
// Rendering scene nodes and entityCollections
|
|
726
667
|
let rn = this._renderNodesArr;
|
|
727
668
|
let k = frustums.length;
|
|
669
|
+
//
|
|
670
|
+
// RenderNodes PASS
|
|
671
|
+
//
|
|
728
672
|
while (k--) {
|
|
729
673
|
this.activeCamera.setCurrentFrustum(k);
|
|
730
674
|
gl.clear(gl.DEPTH_BUFFER_BIT);
|
|
@@ -732,30 +676,41 @@ class Renderer {
|
|
|
732
676
|
while (i--) {
|
|
733
677
|
rn[i].preDrawNode();
|
|
734
678
|
}
|
|
735
|
-
this._drawOpaqueEntityCollections();
|
|
736
679
|
i = rn.length;
|
|
737
680
|
while (i--) {
|
|
738
681
|
this.enableBlendDefault();
|
|
739
682
|
rn[i].drawNode();
|
|
740
683
|
}
|
|
741
|
-
this.
|
|
742
|
-
this._clearEntityCollectionQueue();
|
|
684
|
+
this._drawEntityCollections(0);
|
|
743
685
|
e.dispatch(e.drawtransparent, this);
|
|
744
686
|
if (pointerEvent && !mouseHold) {
|
|
745
|
-
this._drawPickingBuffer();
|
|
687
|
+
this._drawPickingBuffer(0);
|
|
688
|
+
}
|
|
689
|
+
this._drawDepthBuffer(0);
|
|
690
|
+
this._clearEntityCollectionQueue(0);
|
|
691
|
+
}
|
|
692
|
+
//
|
|
693
|
+
// EntityCollections PASS
|
|
694
|
+
//
|
|
695
|
+
for (let i = 1; i < this._entityCollections.length; i++) {
|
|
696
|
+
gl.clear(gl.DEPTH_BUFFER_BIT);
|
|
697
|
+
let k = frustums.length;
|
|
698
|
+
while (k--) {
|
|
699
|
+
this.activeCamera.setCurrentFrustum(k);
|
|
700
|
+
this._drawEntityCollections(i);
|
|
701
|
+
if (pointerEvent && !mouseHold) {
|
|
702
|
+
this._drawPickingBuffer(i);
|
|
703
|
+
}
|
|
704
|
+
this._drawDepthBuffer(i);
|
|
746
705
|
}
|
|
747
|
-
this.
|
|
706
|
+
this._clearEntityCollectionQueue(i);
|
|
748
707
|
}
|
|
749
708
|
sceneFramebuffer.deactivate();
|
|
750
709
|
this.blitFramebuffer && sceneFramebuffer.blitTo(this.blitFramebuffer, 0);
|
|
751
710
|
if (pointerEvent) {
|
|
752
|
-
if (h.isWebGl2()) {
|
|
753
|
-
// It works ONLY for 0 (closest) frustum
|
|
754
|
-
this._drawDepthBuffer();
|
|
755
|
-
}
|
|
756
711
|
this._readPickingBuffer();
|
|
757
712
|
}
|
|
758
|
-
this.
|
|
713
|
+
this._readDepthBuffer();
|
|
759
714
|
// Tone mapping followed by rendering on the screen
|
|
760
715
|
this._fnScreenFrame();
|
|
761
716
|
e.dispatch(e.postdraw, this);
|
|
@@ -764,6 +719,10 @@ class Renderer {
|
|
|
764
719
|
e.mouseState.moving = false;
|
|
765
720
|
e.touchState.moving = false;
|
|
766
721
|
}
|
|
722
|
+
getImageDataURL(type = "image/png", quality = 1.0) {
|
|
723
|
+
this.draw();
|
|
724
|
+
return this.handler.canvas ? this.handler.canvas.toDataURL(type, quality) : "";
|
|
725
|
+
}
|
|
767
726
|
_screenFrameMSAA() {
|
|
768
727
|
let h = this.handler;
|
|
769
728
|
let sh = h.programs.toneMapping, p = sh._program, gl = h.gl;
|
|
@@ -808,87 +767,86 @@ class Renderer {
|
|
|
808
767
|
* Draw picking objects framebuffer.
|
|
809
768
|
* @private
|
|
810
769
|
*/
|
|
811
|
-
_drawPickingBuffer() {
|
|
770
|
+
_drawPickingBuffer(depthOrder) {
|
|
812
771
|
this.pickingFramebuffer.activate();
|
|
813
772
|
let h = this.handler;
|
|
814
773
|
let gl = h.gl;
|
|
815
|
-
if (this.activeCamera.isFirstPass) {
|
|
774
|
+
if (this.activeCamera.isFirstPass && depthOrder === 0) {
|
|
816
775
|
gl.clearColor(0.0, 0.0, 0.0, 1.0);
|
|
817
776
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
818
777
|
}
|
|
819
778
|
else {
|
|
820
779
|
gl.clear(gl.DEPTH_BUFFER_BIT);
|
|
821
780
|
}
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
781
|
+
//
|
|
782
|
+
// draw picking scenes, usually we don't need blending,
|
|
783
|
+
// but sometimes set it manually in the callbacks
|
|
784
|
+
//
|
|
785
|
+
gl.disable(gl.BLEND);
|
|
786
|
+
if (depthOrder === 0) {
|
|
787
|
+
let dp = this._pickingCallbacks;
|
|
788
|
+
for (let i = 0, len = dp.length; i < len; i++) {
|
|
789
|
+
/**
|
|
790
|
+
* This callback renders picking frame.
|
|
791
|
+
*/
|
|
792
|
+
dp[i].callback.call(dp[i].sender);
|
|
793
|
+
}
|
|
834
794
|
}
|
|
795
|
+
this._drawPickingEntityCollections(depthOrder);
|
|
796
|
+
gl.enable(gl.BLEND);
|
|
835
797
|
this.pickingFramebuffer.deactivate();
|
|
836
798
|
}
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
* @protected
|
|
840
|
-
*/
|
|
841
|
-
_drawDistanceBuffer() {
|
|
842
|
-
this.distanceFramebuffer.activate();
|
|
799
|
+
_drawDepthBuffer(depthOrder) {
|
|
800
|
+
this.depthFramebuffer.activate();
|
|
843
801
|
let h = this.handler;
|
|
844
802
|
let gl = h.gl;
|
|
845
|
-
|
|
803
|
+
gl.disable(gl.BLEND);
|
|
804
|
+
if (this.activeCamera.isFirstPass && depthOrder === 0) {
|
|
846
805
|
gl.clearColor(0.0, 0.0, 0.0, 1.0);
|
|
847
806
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
848
807
|
}
|
|
849
808
|
else {
|
|
850
809
|
gl.clear(gl.DEPTH_BUFFER_BIT);
|
|
851
810
|
}
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
gl.enable(gl.BLEND);
|
|
862
|
-
this.distanceFramebuffer.deactivate();
|
|
863
|
-
}
|
|
864
|
-
_drawDepthBuffer() {
|
|
865
|
-
this.depthFramebuffer.activate();
|
|
866
|
-
let h = this.handler;
|
|
867
|
-
let gl = h.gl;
|
|
868
|
-
gl.clearColor(0.0, 0.0, 0.0, 1.0);
|
|
869
|
-
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
870
|
-
gl.enable(gl.DEPTH_TEST);
|
|
871
|
-
let dp = this._depthCallbacks;
|
|
872
|
-
let i = dp.length;
|
|
873
|
-
while (i--) {
|
|
874
|
-
/**
|
|
875
|
-
* This callback renders depth frame.
|
|
876
|
-
*/
|
|
877
|
-
dp[i].callback.call(dp[i].sender);
|
|
811
|
+
if (depthOrder === 0) {
|
|
812
|
+
let dp = this._depthCallbacks;
|
|
813
|
+
let i = dp.length;
|
|
814
|
+
while (i--) {
|
|
815
|
+
/**
|
|
816
|
+
* This callback renders depth frame.
|
|
817
|
+
*/
|
|
818
|
+
dp[i].callback.call(dp[i].sender);
|
|
819
|
+
}
|
|
878
820
|
}
|
|
821
|
+
this._drawDepthEntityCollections(depthOrder);
|
|
879
822
|
this.depthFramebuffer.deactivate();
|
|
880
823
|
//
|
|
881
|
-
//
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
824
|
+
// DEBUG SCREEN OUTPUTS
|
|
825
|
+
//
|
|
826
|
+
if (this._currentOutput === "depth" || this._currentOutput === "frustum") {
|
|
827
|
+
//
|
|
828
|
+
// PASS to depth visualization
|
|
829
|
+
this.screenDepthFramebuffer.activate();
|
|
830
|
+
let sh = h.programs.depth, p = sh._program;
|
|
831
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.screenFramePositionBuffer);
|
|
832
|
+
gl.vertexAttribPointer(p.attributes.corners, 2, gl.FLOAT, false, 0, 0);
|
|
833
|
+
sh.activate();
|
|
834
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
835
|
+
gl.bindTexture(gl.TEXTURE_2D, this.depthFramebuffer.textures[1]);
|
|
836
|
+
gl.uniform1i(p.uniforms.depthTexture, 0);
|
|
837
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
838
|
+
this.screenDepthFramebuffer.deactivate();
|
|
839
|
+
gl.enable(gl.BLEND);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
_readDepthBuffer() {
|
|
843
|
+
this.depthFramebuffer.readPixelBuffersAsync();
|
|
844
|
+
}
|
|
845
|
+
_readPickingBuffer_webgl1() {
|
|
846
|
+
this.pickingFramebuffer.readPixelBuffersAsync();
|
|
847
|
+
}
|
|
848
|
+
_readPickingBuffer_webgl2() {
|
|
849
|
+
this.pickingFramebuffer.readPixelBuffersAsync();
|
|
892
850
|
}
|
|
893
851
|
readPickingColor(x, y, outColor) {
|
|
894
852
|
let w = this.pickingFramebuffer.width;
|
|
@@ -896,19 +854,65 @@ class Renderer {
|
|
|
896
854
|
x = Math.round(x * w);
|
|
897
855
|
y = Math.round(y * h);
|
|
898
856
|
let ind = (y * w + x) * 4;
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
857
|
+
let _tempPickingPix_ = this.pickingFramebuffer?.pixelBuffers[0].data;
|
|
858
|
+
if (_tempPickingPix_) {
|
|
859
|
+
outColor[0] = _tempPickingPix_[ind];
|
|
860
|
+
outColor[1] = _tempPickingPix_[ind + 1];
|
|
861
|
+
outColor[2] = _tempPickingPix_[ind + 2];
|
|
862
|
+
}
|
|
902
863
|
}
|
|
903
|
-
|
|
904
|
-
let w = this.
|
|
905
|
-
let h = this.
|
|
864
|
+
readDepth(x, y, outDepth) {
|
|
865
|
+
let w = this.depthFramebuffer.width;
|
|
866
|
+
let h = this.depthFramebuffer.height;
|
|
906
867
|
x = Math.round(x * w);
|
|
907
868
|
y = Math.round(y * h);
|
|
908
869
|
let ind = (y * w + x) * 4;
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
870
|
+
let _tempDepthPix_ = this.depthFramebuffer?.pixelBuffers[1].data;
|
|
871
|
+
let _tempFrustumPix_ = this.depthFramebuffer?.pixelBuffers[0].data;
|
|
872
|
+
if (_tempDepthPix_) {
|
|
873
|
+
outDepth[0] = _tempDepthPix_[ind];
|
|
874
|
+
outDepth[1] = Math.round(_tempFrustumPix_[ind] / 10.0) - 1.0; // See Camera.frustumColorIndex
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* Returns the distance from the active (screen) camera to the 3d-surface using the defined screen coordinates
|
|
879
|
+
* @public
|
|
880
|
+
* @param {Vec2 | IBaseInputState} px - Screen coordinates.
|
|
881
|
+
* @returns {number | undefined} -
|
|
882
|
+
*/
|
|
883
|
+
getDistanceFromPixel(px, camera) {
|
|
884
|
+
camera = camera || this.activeCamera;
|
|
885
|
+
let r = this;
|
|
886
|
+
let cnv = r.handler.canvas;
|
|
887
|
+
let spx = px.x / cnv.width;
|
|
888
|
+
let spy = (cnv.height - px.y) / cnv.height;
|
|
889
|
+
_tempDepth_[0] = _tempDepth_[1] = 0.0;
|
|
890
|
+
let dist = 0;
|
|
891
|
+
r.readDepth(spx, spy, _tempDepth_);
|
|
892
|
+
if (_tempDepth_[1] === -1) {
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
let depth = _tempDepth_[0], frustum = camera.frustums[_tempDepth_[1]];
|
|
896
|
+
if (!frustum)
|
|
897
|
+
return;
|
|
898
|
+
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);
|
|
899
|
+
let viewPosition = frustum.inverseProjectionMatrix.mulVec4(screenPos);
|
|
900
|
+
let dir = px.direction || r.activeCamera.unproject(px.x, px.y);
|
|
901
|
+
dist = -(viewPosition.z / viewPosition.w) / dir.dot(r.activeCamera.getForward());
|
|
902
|
+
return dist;
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* Returns 3d coordinates from screen coordinates
|
|
906
|
+
* @public
|
|
907
|
+
* @param {Vec2 | IBaseInputState} px - Screen coordinates.
|
|
908
|
+
* @returns {Vec3 | undefined} -
|
|
909
|
+
*/
|
|
910
|
+
getCartesianFromPixel(px) {
|
|
911
|
+
let distance = this.getDistanceFromPixel(px);
|
|
912
|
+
if (distance) {
|
|
913
|
+
let direction = px.direction || this.activeCamera.unproject(px.x, px.y);
|
|
914
|
+
return direction.scaleTo(distance).addA(this.activeCamera.eye);
|
|
915
|
+
}
|
|
912
916
|
}
|
|
913
917
|
/**
|
|
914
918
|
* Function starts renderer
|
|
@@ -930,6 +934,7 @@ class Renderer {
|
|
|
930
934
|
this.div = null;
|
|
931
935
|
this._renderNodesArr = [];
|
|
932
936
|
this.renderNodes = {};
|
|
937
|
+
//@ts-ignore
|
|
933
938
|
this.activeCamera = null;
|
|
934
939
|
this.controls = {};
|
|
935
940
|
this.controlsBag = {};
|
|
@@ -940,10 +945,6 @@ class Renderer {
|
|
|
940
945
|
this.pickingFramebuffer = null;
|
|
941
946
|
//@ts-ignore
|
|
942
947
|
this._tempPickingPix_ = null;
|
|
943
|
-
this.distanceFramebuffer = null;
|
|
944
|
-
this._distanceCallbacks = [];
|
|
945
|
-
//@ts-ignore
|
|
946
|
-
this._tempDistancePix_ = null;
|
|
947
948
|
this._depthCallbacks = [];
|
|
948
949
|
this.depthFramebuffer = null;
|
|
949
950
|
this.sceneFramebuffer = null;
|
|
@@ -953,7 +954,7 @@ class Renderer {
|
|
|
953
954
|
//this.billboardsTextureAtlas.clear();
|
|
954
955
|
//this.geoObjectsTextureAtlas.clear()
|
|
955
956
|
//this.fontAtlas.clear();
|
|
956
|
-
this._entityCollections = [];
|
|
957
|
+
this._entityCollections = [[]];
|
|
957
958
|
this.handler.ONCANVASRESIZE = null;
|
|
958
959
|
this.handler.destroy();
|
|
959
960
|
// @ts-ignore
|