@openglobus/og 0.11.1 → 0.11.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +18 -20
- package/src/og/Clock.js +11 -11
- package/src/og/Deferred.js +1 -1
- package/src/og/Events.js +9 -7
- package/src/og/Extent.js +117 -72
- package/src/og/Globe.js +35 -22
- package/src/og/ImageCanvas.js +24 -18
- package/src/og/Lock.js +2 -2
- package/src/og/LonLat.js +40 -37
- package/src/og/Popup.js +21 -15
- package/src/og/QueueArray.js +7 -3
- package/src/og/Rectangle.js +11 -6
- package/src/og/Stack.js +8 -5
- package/src/og/ajax.js +21 -33
- package/src/og/astro/astro.js +5 -5
- package/src/og/astro/earth.js +23 -17
- package/src/og/astro/jd.js +44 -39
- package/src/og/astro/orbit.js +20 -18
- package/src/og/astro/rotation.js +17 -8
- package/src/og/bv/Box.js +7 -3
- package/src/og/bv/Sphere.js +17 -9
- package/src/og/camera/Camera.js +137 -86
- package/src/og/camera/Frustum.js +30 -19
- package/src/og/camera/PlanetCamera.js +30 -26
- package/src/og/control/CompassButton.js +8 -2
- package/src/og/control/Control.js +13 -11
- package/src/og/control/DebugInfo.js +4 -1
- package/src/og/control/EarthCoordinates.js +62 -41
- package/src/og/control/EarthNavigation.js +20 -22
- package/src/og/control/GeoImageDragControl.js +1 -1
- package/src/og/control/KeyboardNavigation.js +12 -12
- package/src/og/control/LayerSwitcher.js +24 -23
- package/src/og/control/Lighting.js +1 -1
- package/src/og/control/MouseNavigation.js +1 -1
- package/src/og/control/ScaleControl.js +1 -1
- package/src/og/control/SegmentBoundVisualization.js +8 -9
- package/src/og/control/ShowFps.js +15 -10
- package/src/og/control/SimpleNavigation.js +8 -10
- package/src/og/control/Sun.js +25 -15
- package/src/og/control/ToggleWireframe.js +5 -5
- package/src/og/control/TouchNavigation.js +58 -45
- package/src/og/control/ZoomControl.js +41 -25
- package/src/og/control/index.js +4 -0
- package/src/og/ellipsoid/Ellipsoid.js +181 -85
- package/src/og/ellipsoid/wgs84.js +4 -4
- package/src/og/entity/BaseBillboard.js +97 -44
- package/src/og/entity/Billboard.js +15 -11
- package/src/og/entity/BillboardHandler.js +314 -64
- package/src/og/entity/Entity.js +106 -74
- package/src/og/entity/EntityCollection.js +72 -49
- package/src/og/entity/GeoObject.js +228 -0
- package/src/og/entity/GeoObjectHandler.js +910 -0
- package/src/og/entity/Geometry.js +29 -26
- package/src/og/entity/GeometryHandler.js +598 -126
- package/src/og/entity/Label.js +74 -40
- package/src/og/entity/LabelHandler.js +47 -246
- package/src/og/entity/LabelWorker.js +213 -0
- package/src/og/entity/Object3d.js +504 -0
- package/src/og/entity/PointCloud.js +81 -33
- package/src/og/entity/PointCloudHandler.js +9 -9
- package/src/og/entity/Polyline.js +39 -39
- package/src/og/entity/Ray.js +61 -28
- package/src/og/entity/ShapeHandler.js +1 -1
- package/src/og/entity/Strip.js +77 -48
- package/src/og/entity/StripHandler.js +27 -27
- package/src/og/entity/index.js +8 -16
- package/src/og/input/KeyboardHandler.js +107 -104
- package/src/og/input/MouseHandler.js +81 -78
- package/src/og/input/TouchHandler.js +55 -51
- package/src/og/layer/BaseGeoImage.js +61 -30
- package/src/og/layer/CanvasTiles.js +26 -24
- package/src/og/layer/GeoImage.js +10 -10
- package/src/og/layer/GeoTexture2d.js +1 -1
- package/src/og/layer/GeoVideo.js +3 -3
- package/src/og/layer/KML.js +66 -40
- package/src/og/layer/Layer.js +27 -17
- package/src/og/layer/Material.js +93 -61
- package/src/og/layer/Vector.js +118 -72
- package/src/og/layer/WMS.js +36 -19
- package/src/og/layer/XYZ.js +55 -48
- package/src/og/light/LightSource.js +47 -40
- package/src/og/math/Line2.js +24 -24
- package/src/og/math/Line3.js +103 -102
- package/src/og/math/Mat3.js +134 -121
- package/src/og/math/Mat4.js +603 -459
- package/src/og/math/Plane.js +21 -20
- package/src/og/math/Quat.js +980 -927
- package/src/og/math/Ray.js +195 -187
- package/src/og/math/Vec2.js +127 -117
- package/src/og/math/Vec3.js +206 -176
- package/src/og/math/Vec4.js +49 -53
- package/src/og/math/coder.js +18 -18
- package/src/og/math.js +12 -12
- package/src/og/mercator.js +11 -11
- package/src/og/proj/EPSG3857.js +4 -4
- package/src/og/proj/EPSG4326.js +4 -4
- package/src/og/proj/Proj.js +31 -31
- package/src/og/quadTree/EntityCollectionNode.js +310 -300
- package/src/og/quadTree/Node.js +1008 -993
- package/src/og/renderer/Renderer.js +768 -747
- package/src/og/renderer/RendererEvents.js +9 -6
- package/src/og/scene/Axes.js +1 -1
- package/src/og/scene/BaseNode.js +8 -9
- package/src/og/scene/Planet.js +115 -87
- package/src/og/scene/RenderNode.js +29 -22
- package/src/og/scene/SkyBox.js +1 -1
- package/src/og/segment/Segment.js +1886 -1878
- package/src/og/segment/SegmentLonLat.js +298 -268
- package/src/og/segment/segmentHelper.js +11 -11
- package/src/og/shaders/bloom.js +1 -1
- package/src/og/shaders/blur.js +2 -2
- package/src/og/shaders/depth.js +1 -1
- package/src/og/shaders/geoObject.js +211 -0
- package/src/og/shaders/label.js +1 -1
- package/src/og/shaders/lumFilter.js +1 -1
- package/src/og/shaders/pointCloud.js +42 -42
- package/src/og/shaders/screenFrame.js +1 -1
- package/src/og/shaders/shape.js +15 -21
- package/src/og/shaders/skybox.js +37 -37
- package/src/og/shaders/toneMapping.js +1 -1
- package/src/og/shapes/BaseShape.js +129 -57
- package/src/og/shapes/Icosphere.js +30 -15
- package/src/og/shapes/Sphere.js +13 -16
- package/src/og/terrain/BilTerrain.js +2 -1
- package/src/og/terrain/EmptyTerrain.js +2 -2
- package/src/og/terrain/Geoid.js +2 -2
- package/src/og/terrain/GlobusTerrain.js +10 -10
- package/src/og/terrain/MapboxTerrain.js +1 -1
- package/src/og/utils/GeoImageCreator.js +9 -9
- package/src/og/utils/Loader.js +6 -6
- package/src/og/utils/NormalMapCreator.js +13 -13
- package/src/og/utils/TerrainWorker.js +1 -1
- package/src/og/utils/TextureAtlas.js +20 -22
- package/src/og/utils/VectorTileCreator.js +5 -5
- package/src/og/utils/earcut.js +1 -1
- package/src/og/utils/shared.js +15 -15
- package/src/og/webgl/Framebuffer.js +101 -53
- package/src/og/webgl/Handler.js +125 -85
- package/src/og/webgl/Multisample.js +55 -27
- package/src/og/webgl/Program.js +80 -35
- package/src/og/webgl/ProgramController.js +27 -23
- package/src/og/webgl/callbacks.js +8 -8
- package/types/Clock.d.ts +6 -2
- package/types/Deferred.d.ts +1 -1
- package/types/Events.d.ts +8 -4
- package/types/Extent.d.ts +37 -33
- package/types/Globe.d.ts +15 -13
- package/types/ImageCanvas.d.ts +5 -3
- package/types/LonLat.d.ts +24 -24
- package/types/Popup.d.ts +4 -0
- package/types/QueueArray.d.ts +6 -2
- package/types/Rectangle.d.ts +10 -4
- package/types/Stack.d.ts +4 -0
- package/types/ajax.d.ts +1 -1
- package/types/astro/earth.d.ts +3 -2
- package/types/bv/Box.d.ts +10 -5
- package/types/bv/Sphere.d.ts +13 -7
- package/types/camera/Camera.d.ts +90 -81
- package/types/camera/Frustum.d.ts +26 -22
- package/types/camera/PlanetCamera.d.ts +49 -53
- package/types/control/CompassButton.d.ts +4 -4
- package/types/control/Control.d.ts +7 -4
- package/types/control/DebugInfo.d.ts +3 -4
- package/types/control/EarthCoordinates.d.ts +6 -6
- package/types/control/EarthNavigation.d.ts +42 -0
- package/types/control/KeyboardNavigation.d.ts +3 -4
- package/types/control/LayerSwitcher.d.ts +3 -5
- package/types/control/Lighting.d.ts +3 -3
- package/types/control/MouseNavigation.d.ts +47 -0
- package/types/control/ScaleControl.d.ts +3 -3
- package/types/control/ShowFps.d.ts +3 -4
- package/types/control/SimpleNavigation.d.ts +3 -6
- package/types/control/Sun.d.ts +8 -10
- package/types/control/ToggleWireframe.d.ts +3 -3
- package/types/control/TouchNavigation.d.ts +48 -0
- package/types/control/ZoomControl.d.ts +3 -4
- package/types/control/index.d.ts +3 -1
- package/types/ellipsoid/Ellipsoid.d.ts +47 -43
- package/types/ellipsoid/wgs84.d.ts +3 -2
- package/types/entity/BaseBillboard.d.ts +41 -34
- package/types/entity/Billboard.d.ts +7 -7
- package/types/entity/BillboardHandler.d.ts +4 -0
- package/types/entity/Entity.d.ts +101 -83
- package/types/entity/EntityCollection.d.ts +57 -43
- package/types/entity/GeoObject.d.ts +111 -0
- package/types/entity/GeoObjectHandler.d.ts +77 -0
- package/types/entity/Geometry.d.ts +9 -7
- package/types/entity/GeometryHandler.d.ts +2 -2
- package/types/entity/Label.d.ts +24 -29
- package/types/entity/LabelHandler.d.ts +9 -2
- package/types/entity/LabelWorker.d.ts +9 -0
- package/types/entity/PointCloud.d.ts +8 -8
- package/types/entity/PointCloudHandler.d.ts +3 -3
- package/types/entity/Polyline.d.ts +58 -55
- package/types/entity/Ray.d.ts +19 -18
- package/types/entity/Strip.d.ts +8 -7
- package/types/entity/StripHandler.d.ts +3 -3
- package/types/entity/index.d.ts +7 -7
- package/types/input/KeyboardHandler.d.ts +10 -0
- package/types/input/MouseHandler.d.ts +5 -0
- package/types/input/TouchHandler.d.ts +5 -0
- package/types/layer/BaseGeoImage.d.ts +23 -35
- package/types/layer/CanvasTiles.d.ts +15 -22
- package/types/layer/GeoImage.d.ts +5 -18
- package/types/layer/GeoVideo.d.ts +5 -30
- package/types/layer/KML.d.ts +20 -15
- package/types/layer/Layer.d.ts +326 -0
- package/types/layer/Material.d.ts +45 -0
- package/types/layer/Vector.d.ts +208 -0
- package/types/layer/WMS.d.ts +4 -7
- package/types/layer/XYZ.d.ts +19 -25
- package/types/light/LightSource.d.ts +54 -53
- package/types/math/Line2.d.ts +11 -0
- package/types/math/Line3.d.ts +10 -0
- package/types/math/Mat3.d.ts +30 -18
- package/types/math/Mat4.d.ts +71 -52
- package/types/math/Plane.d.ts +5 -4
- package/types/math/Quat.d.ts +379 -0
- package/types/math/Ray.d.ts +82 -0
- package/types/math/Vec2.d.ts +102 -101
- package/types/math/Vec3.d.ts +143 -142
- package/types/math/Vec4.d.ts +40 -39
- package/types/math/coder.d.ts +12 -11
- package/types/math.d.ts +8 -8
- package/types/mercator.d.ts +3 -3
- package/types/proj/EPSG3857.d.ts +3 -2
- package/types/proj/EPSG4326.d.ts +3 -2
- package/types/proj/Proj.d.ts +42 -0
- package/types/quadTree/EntityCollectionNode.d.ts +34 -0
- package/types/quadTree/Node.d.ts +61 -0
- package/types/renderer/Renderer.d.ts +300 -0
- package/types/renderer/RendererEvents.d.ts +10 -7
- package/types/scene/BaseNode.d.ts +9 -9
- package/types/scene/Planet.d.ts +131 -126
- package/types/scene/RenderNode.d.ts +22 -23
- package/types/segment/Segment.d.ts +279 -0
- package/types/segment/SegmentLonLat.d.ts +16 -0
- package/types/shaders/geoObject.d.ts +3 -0
- package/types/shapes/BaseShape.d.ts +43 -40
- package/types/shapes/Sphere.d.ts +7 -7
- package/types/terrain/BilTerrain.d.ts +0 -1
- package/types/terrain/EmptyTerrain.d.ts +4 -4
- package/types/terrain/GlobusTerrain.d.ts +17 -54
- package/types/terrain/MapboxTerrain.d.ts +0 -1
- package/types/utils/GeoImageCreator.d.ts +3 -2
- package/types/utils/TextureAtlas.d.ts +8 -8
- package/types/utils/shared.d.ts +25 -24
- package/types/webgl/Framebuffer.d.ts +5 -5
- package/types/webgl/Handler.d.ts +68 -43
- package/types/webgl/Multisample.d.ts +5 -5
- package/types/webgl/Program.d.ts +8 -2
- package/types/webgl/ProgramController.d.ts +18 -13
- package/src/og/inherits.js +0 -8
- package/src/og/utils/polylabel.js +0 -176
- package/types/inherits.d.ts +0 -4
|
@@ -16,11 +16,16 @@ import { TextureAtlas } from "../utils/TextureAtlas.js";
|
|
|
16
16
|
import * as arial from "../arial.js";
|
|
17
17
|
import { depth } from "../shaders/depth.js";
|
|
18
18
|
import { ARIAL_FONT_B64 } from "../res/images.js";
|
|
19
|
+
import { LabelWorker } from "../entity/LabelWorker.js";
|
|
20
|
+
|
|
21
|
+
let __pickingCallbackCounter__ = 0;
|
|
22
|
+
|
|
23
|
+
let __depthCallbackCounter__ = 0;
|
|
19
24
|
|
|
20
25
|
/**
|
|
21
26
|
* Represents high level WebGL context interface that starts WebGL handler working in real time.
|
|
22
27
|
* @class
|
|
23
|
-
* @param {
|
|
28
|
+
* @param {Handler} handler - WebGL handler context.
|
|
24
29
|
* @param {Object} [params] - Renderer parameters:
|
|
25
30
|
* @fires og.RendererEvents#draw
|
|
26
31
|
* @fires og.RendererEvents#resize
|
|
@@ -50,917 +55,933 @@ import { ARIAL_FONT_B64 } from "../res/images.js";
|
|
|
50
55
|
* @fires og.RendererEvents#touchleave
|
|
51
56
|
* @fires og.RendererEvents#touchenter
|
|
52
57
|
*/
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
class Renderer {
|
|
59
|
+
constructor(handler, params) {
|
|
60
|
+
params = params || {};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Div element with WebGL canvas.
|
|
64
|
+
* @public
|
|
65
|
+
* @type {object}
|
|
66
|
+
*/
|
|
67
|
+
this.div = null;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* WebGL handler context.
|
|
71
|
+
* @public
|
|
72
|
+
* @type {Handler}
|
|
73
|
+
*/
|
|
74
|
+
this.handler = handler;
|
|
75
|
+
|
|
76
|
+
this.exposure = 4;
|
|
77
|
+
|
|
78
|
+
this.gamma = 0.5;
|
|
79
|
+
|
|
80
|
+
this.whitepoint = 1.0;
|
|
81
|
+
|
|
82
|
+
this.brightThreshold = 0.9;
|
|
83
|
+
|
|
84
|
+
this.backgroundColor = params.backgroundColor || new Vec3(115 / 255, 203 / 255, 249 / 255);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Render nodes drawing queue.
|
|
88
|
+
* @private
|
|
89
|
+
* @type {Array.<scene.RenderNode>}
|
|
90
|
+
*/
|
|
91
|
+
this._renderNodesArr = [];
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Render nodes store for the comfortable access by the node name.
|
|
95
|
+
* @public
|
|
96
|
+
* @type {Object.<og.scene.RenderNode>}
|
|
97
|
+
*/
|
|
98
|
+
this.renderNodes = {};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Current active camera.
|
|
102
|
+
* @public
|
|
103
|
+
* @type {Camera}
|
|
104
|
+
*/
|
|
105
|
+
this.activeCamera = null;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Renderer events. Represents interface for setting events like mousemove, draw, keypress etc.
|
|
109
|
+
* @public
|
|
110
|
+
* @type {RendererEvents}
|
|
111
|
+
*/
|
|
112
|
+
this.events = new RendererEvents(this);
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* OpenGlobus controls array.
|
|
116
|
+
* @public
|
|
117
|
+
* @type {Object}
|
|
118
|
+
*/
|
|
119
|
+
this.controls = {};
|
|
120
|
+
|
|
121
|
+
if (params.controls) {
|
|
122
|
+
for (let i in params.controls) {
|
|
123
|
+
this.controls[params.controls[i].name] = params.controls[i];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
69
126
|
|
|
70
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Provides exchange between controls.
|
|
129
|
+
* @public
|
|
130
|
+
* @type {Object}
|
|
131
|
+
*/
|
|
132
|
+
this.controlsBag = {};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Hash table for drawing objects.
|
|
136
|
+
* @public
|
|
137
|
+
* @type {Object}
|
|
138
|
+
*/
|
|
139
|
+
this.colorObjects = {};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Color picking objects rendering queue.
|
|
143
|
+
* @type {Array.<Renderer~pickingCallback>}
|
|
144
|
+
*/
|
|
145
|
+
this._pickingCallbacks = [];
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Picking objects(labels and billboards) framebuffer.
|
|
149
|
+
* @public
|
|
150
|
+
* @type {Framebuffer}
|
|
151
|
+
*/
|
|
152
|
+
this.pickingFramebuffer = null;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Depth objects rendering queue.
|
|
156
|
+
* @type {Array.<Renderer~depthCallback>}
|
|
157
|
+
*/
|
|
158
|
+
this._depthCallbacks = [];
|
|
159
|
+
|
|
160
|
+
this.depthFramebuffer = null;
|
|
161
|
+
|
|
162
|
+
this._msaa = params.msaa || 8;
|
|
163
|
+
this._internalFormat = "RGBA16F";
|
|
164
|
+
this._format = "RGBA";
|
|
165
|
+
this._type = "FLOAT";
|
|
166
|
+
|
|
167
|
+
this._screenScale = params.screenScale || 1.0;
|
|
168
|
+
|
|
169
|
+
this.sceneFramebuffer = null;
|
|
170
|
+
|
|
171
|
+
this.blitFramebuffer = null;
|
|
172
|
+
|
|
173
|
+
this.toneMappingFramebuffer = null;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Stores current picking rgb color.
|
|
177
|
+
* @private
|
|
178
|
+
* @type {Array.<number>} - (exactly 3 entries)
|
|
179
|
+
*/
|
|
180
|
+
this._currPickingColor = new Uint8Array(4);
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Stores previous picked rgb color.
|
|
184
|
+
* @private
|
|
185
|
+
* @type {Array.<number>} - (exactly 3 entries)
|
|
186
|
+
*/
|
|
187
|
+
this._prevPickingColor = [0, 0, 0];
|
|
188
|
+
|
|
189
|
+
this._tempPickingColor_ = new Uint8Array(4);
|
|
190
|
+
|
|
191
|
+
this._initialized = false;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Texture atlas for the billboards images. One atlas per node.
|
|
195
|
+
* @protected
|
|
196
|
+
* @type {utils.TextureAtlas}
|
|
197
|
+
*/
|
|
198
|
+
this.billboardsTextureAtlas = new TextureAtlas();
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Texture font atlas for the font families and styles. One atlas per node.
|
|
202
|
+
* @public
|
|
203
|
+
* @type {utils.FontAtlas}
|
|
204
|
+
*/
|
|
205
|
+
this.fontAtlas = new FontAtlas();
|
|
71
206
|
|
|
72
|
-
|
|
207
|
+
this._entityCollections = [];
|
|
73
208
|
|
|
74
|
-
|
|
209
|
+
if (params.autoActivate || isEmpty(params.autoActivate)) {
|
|
210
|
+
this.initialize();
|
|
211
|
+
this.start();
|
|
212
|
+
}
|
|
75
213
|
|
|
76
|
-
|
|
214
|
+
this._currentOutput = "screen";
|
|
77
215
|
|
|
78
|
-
|
|
216
|
+
this.labelWorker = new LabelWorker();
|
|
217
|
+
}
|
|
79
218
|
|
|
80
219
|
/**
|
|
81
|
-
*
|
|
82
|
-
* @
|
|
83
|
-
* @type {Array.<og.scene.RenderNode>}
|
|
220
|
+
* Sets renderer events activity.
|
|
221
|
+
* @param {Boolean} activity - Events activity.
|
|
84
222
|
*/
|
|
85
|
-
|
|
223
|
+
setEventsActivity(activity) {
|
|
224
|
+
this.events.active = activity;
|
|
225
|
+
}
|
|
86
226
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
227
|
+
setScreenScale(scale) {
|
|
228
|
+
this._screenScale = scale;
|
|
229
|
+
this._resize();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
addDepthCallback(sender, callback) {
|
|
233
|
+
var id = __depthCallbackCounter__++;
|
|
234
|
+
this._depthCallbacks.push({
|
|
235
|
+
id: id,
|
|
236
|
+
callback: callback,
|
|
237
|
+
sender: sender
|
|
238
|
+
});
|
|
239
|
+
return id;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
removeDepthCallback(id) {
|
|
243
|
+
for (var i = 0; i < this._depthCallbacks.length; i++) {
|
|
244
|
+
if (id === this._depthCallbacks[i].id) {
|
|
245
|
+
this._depthCallbacks.splice(i, 1);
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
93
250
|
|
|
94
251
|
/**
|
|
95
|
-
*
|
|
96
|
-
* @
|
|
97
|
-
* @
|
|
252
|
+
* Adds picking rendering callback function.
|
|
253
|
+
* @param {object} sender - Callback context.
|
|
254
|
+
* @param {Renderer~pickingCallback} callback - Rendering callback.
|
|
255
|
+
* @returns {Number} Handler id
|
|
98
256
|
*/
|
|
99
|
-
|
|
257
|
+
addPickingCallback(sender, callback) {
|
|
258
|
+
var id = __pickingCallbackCounter__++;
|
|
259
|
+
this._pickingCallbacks.push({
|
|
260
|
+
id: id,
|
|
261
|
+
callback: callback,
|
|
262
|
+
sender: sender
|
|
263
|
+
});
|
|
264
|
+
return id;
|
|
265
|
+
}
|
|
100
266
|
|
|
101
267
|
/**
|
|
102
|
-
*
|
|
103
|
-
* @
|
|
104
|
-
* @type {og.RendererEvents}
|
|
268
|
+
* Removes picking rendering callback function.
|
|
269
|
+
* @param {Number} id - Handler id to remove.
|
|
105
270
|
*/
|
|
106
|
-
|
|
271
|
+
removePickingCallback(id) {
|
|
272
|
+
for (var i = 0; i < this._pickingCallbacks.length; i++) {
|
|
273
|
+
if (id === this._pickingCallbacks[i].id) {
|
|
274
|
+
this._pickingCallbacks.splice(i, 1);
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
getPickingObjectByColor(r, g, b) {
|
|
281
|
+
return this.colorObjects[r + "_" + g + "_" + b];
|
|
282
|
+
}
|
|
107
283
|
|
|
108
284
|
/**
|
|
109
|
-
*
|
|
285
|
+
* Assign picking color to the object.
|
|
110
286
|
* @public
|
|
111
|
-
* @
|
|
287
|
+
* @param {Object} obj - Object that pressume to be picked.
|
|
112
288
|
*/
|
|
113
|
-
|
|
289
|
+
assignPickingColor(obj) {
|
|
290
|
+
if (!obj._pickingColor || obj._pickingColor.isZero()) {
|
|
291
|
+
var r = 0,
|
|
292
|
+
g = 0,
|
|
293
|
+
b = 0;
|
|
294
|
+
var str = "0_0_0";
|
|
295
|
+
while (!(r || g || b) || this.colorObjects[str]) {
|
|
296
|
+
r = randomi(1, 255);
|
|
297
|
+
g = randomi(1, 255);
|
|
298
|
+
b = randomi(1, 255);
|
|
299
|
+
str = r + "_" + g + "_" + b;
|
|
300
|
+
}
|
|
114
301
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
302
|
+
if (!obj._pickingColor) {
|
|
303
|
+
obj._pickingColor = new Vec3(r, g, b);
|
|
304
|
+
} else {
|
|
305
|
+
obj._pickingColor.set(r, g, b);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
obj._pickingColorU = new Float32Array([r / 255, g / 255, b / 255]);
|
|
309
|
+
|
|
310
|
+
this.colorObjects[str] = obj;
|
|
118
311
|
}
|
|
119
312
|
}
|
|
120
313
|
|
|
121
314
|
/**
|
|
122
|
-
*
|
|
315
|
+
* Removes picking color from object.
|
|
123
316
|
* @public
|
|
124
|
-
* @
|
|
317
|
+
* @param {Object} obj - Object to remove picking color.
|
|
125
318
|
*/
|
|
126
|
-
|
|
319
|
+
clearPickingColor(obj) {
|
|
320
|
+
if (!obj._pickingColor.isZero()) {
|
|
321
|
+
var c = obj._pickingColor;
|
|
322
|
+
if (!c.isZero()) {
|
|
323
|
+
this.colorObjects[c.x + "_" + c.y + "_" + c.z] = null;
|
|
324
|
+
delete this.colorObjects[c.x + "_" + c.y + "_" + c.z];
|
|
325
|
+
c.x = c.y = c.z = 0;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
127
329
|
|
|
128
330
|
/**
|
|
129
|
-
*
|
|
331
|
+
* Get the client width.
|
|
130
332
|
* @public
|
|
131
|
-
* @
|
|
132
|
-
*/
|
|
133
|
-
this.colorObjects = {};
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Color picking objects rendering queue.
|
|
137
|
-
* @type {Array.<og.Renderer~pickingCallback>}
|
|
333
|
+
* @returns {number} -
|
|
138
334
|
*/
|
|
139
|
-
|
|
335
|
+
getWidth() {
|
|
336
|
+
return this.handler.canvas.width;
|
|
337
|
+
}
|
|
140
338
|
|
|
141
339
|
/**
|
|
142
|
-
*
|
|
340
|
+
* Get the client height.
|
|
143
341
|
* @public
|
|
144
|
-
* @
|
|
342
|
+
* @returns {number} -
|
|
145
343
|
*/
|
|
146
|
-
|
|
344
|
+
getHeight() {
|
|
345
|
+
return this.handler.canvas.height;
|
|
346
|
+
}
|
|
147
347
|
|
|
148
348
|
/**
|
|
149
|
-
*
|
|
150
|
-
* @
|
|
349
|
+
* Get center of the screen
|
|
350
|
+
* @public
|
|
351
|
+
* @returns {math.Vec2} -
|
|
151
352
|
*/
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
this._msaa = params.msaa || 8;
|
|
157
|
-
this._internalFormat = "RGBA16F";
|
|
158
|
-
this._format = "RGBA";
|
|
159
|
-
this._type = "FLOAT";
|
|
160
|
-
|
|
161
|
-
this._screenScale = params.screenScale || 1.0;
|
|
162
|
-
|
|
163
|
-
this.sceneFramebuffer = null;
|
|
164
|
-
|
|
165
|
-
this.blitFramebuffer = null;
|
|
166
|
-
|
|
167
|
-
this.toneMappingFramebuffer = null;
|
|
353
|
+
getCenter() {
|
|
354
|
+
var cnv = this.handler.canvas;
|
|
355
|
+
return new Vec2(Math.round(cnv.width * 0.5), Math.round(cnv.height * 0.5));
|
|
356
|
+
}
|
|
168
357
|
|
|
169
358
|
/**
|
|
170
|
-
*
|
|
171
|
-
* @
|
|
172
|
-
* @type {Array.<number,number,number>}
|
|
359
|
+
* Add the given control to the renderer.
|
|
360
|
+
* @param {control.Control} control - Control.
|
|
173
361
|
*/
|
|
174
|
-
|
|
362
|
+
addControl(control) {
|
|
363
|
+
control.addTo(this);
|
|
364
|
+
}
|
|
175
365
|
|
|
176
366
|
/**
|
|
177
|
-
*
|
|
178
|
-
* @
|
|
179
|
-
* @type {Array.<number,number,number>}
|
|
367
|
+
* Add the given controls array to the planet node.
|
|
368
|
+
* @param {Array.<control.Control>} cArr - Control array.
|
|
180
369
|
*/
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
370
|
+
addControls(cArr) {
|
|
371
|
+
for (var i = 0; i < cArr.length; i++) {
|
|
372
|
+
cArr[i].addTo(this);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
186
375
|
|
|
187
376
|
/**
|
|
188
|
-
*
|
|
189
|
-
* @
|
|
190
|
-
* @type {og.utils.TextureAtlas}
|
|
377
|
+
* Remove control from the renderer.
|
|
378
|
+
* @param {control.Control} control - Control.
|
|
191
379
|
*/
|
|
192
|
-
|
|
380
|
+
removeControl(control) {
|
|
381
|
+
control.remove();
|
|
382
|
+
}
|
|
193
383
|
|
|
194
384
|
/**
|
|
195
|
-
*
|
|
385
|
+
* Renderer initialization.
|
|
196
386
|
* @public
|
|
197
|
-
* @type {og.utils.FontAtlas}
|
|
198
387
|
*/
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
if (params.autoActivate || isEmpty(params.autoActivate)) {
|
|
204
|
-
this.initialize();
|
|
205
|
-
this.start();
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
this._currentOutput = "screen";
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
Renderer.__pickingCallbackCounter__ = 0;
|
|
212
|
-
|
|
213
|
-
Renderer.__depthCallbackCounter__ = 0;
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Sets renderer events activity.
|
|
217
|
-
* @param {Boolean} activity - Events activity.
|
|
218
|
-
*/
|
|
219
|
-
Renderer.prototype.setEventsActivity = function (activity) {
|
|
220
|
-
this.events.active = activity;
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
Renderer.prototype.setScreenScale = function (scale) {
|
|
224
|
-
this._screenScale = scale;
|
|
225
|
-
this._resize();
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
Renderer.prototype.addDepthCallback = function (sender, callback) {
|
|
229
|
-
var id = Renderer.__depthCallbackCounter__++;
|
|
230
|
-
this._depthCallbacks.push({
|
|
231
|
-
id: id,
|
|
232
|
-
callback: callback,
|
|
233
|
-
sender: sender
|
|
234
|
-
});
|
|
235
|
-
return id;
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
Renderer.prototype.removeDepthCallback = function (id) {
|
|
239
|
-
for (var i = 0; i < this._depthCallbacks.length; i++) {
|
|
240
|
-
if (id === this._depthCallbacks[i].id) {
|
|
241
|
-
this._depthCallbacks.splice(i, 1);
|
|
242
|
-
break;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Adds picking rendering callback function.
|
|
249
|
-
* @param {object} sender - Callback context.
|
|
250
|
-
* @param {og.Renderer~pickingCallback} callback - Rendering callback.
|
|
251
|
-
* @returns {Number} Handler id
|
|
252
|
-
*/
|
|
253
|
-
Renderer.prototype.addPickingCallback = function (sender, callback) {
|
|
254
|
-
var id = Renderer.__pickingCallbackCounter__++;
|
|
255
|
-
this._pickingCallbacks.push({
|
|
256
|
-
id: id,
|
|
257
|
-
callback: callback,
|
|
258
|
-
sender: sender
|
|
259
|
-
});
|
|
260
|
-
return id;
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Removes picking rendering callback function.
|
|
265
|
-
* @param {Number} id - Handler id to remove.
|
|
266
|
-
*/
|
|
267
|
-
Renderer.prototype.removePickingCallback = function (id) {
|
|
268
|
-
for (var i = 0; i < this._pickingCallbacks.length; i++) {
|
|
269
|
-
if (id === this._pickingCallbacks[i].id) {
|
|
270
|
-
this._pickingCallbacks.splice(i, 1);
|
|
271
|
-
break;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
Renderer.prototype.getPickingObjectByColor = function (r, g, b) {
|
|
277
|
-
return this.colorObjects[r + "_" + g + "_" + b];
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Assign picking color to the object.
|
|
282
|
-
* @public
|
|
283
|
-
* @param {Object} obj - Object that pressume to be picked.
|
|
284
|
-
*/
|
|
285
|
-
Renderer.prototype.assignPickingColor = function (obj) {
|
|
286
|
-
if (!obj._pickingColor || obj._pickingColor.isZero()) {
|
|
287
|
-
var r = 0,
|
|
288
|
-
g = 0,
|
|
289
|
-
b = 0;
|
|
290
|
-
var str = "0_0_0";
|
|
291
|
-
while (!(r || g || b) || this.colorObjects[str]) {
|
|
292
|
-
r = randomi(1, 255);
|
|
293
|
-
g = randomi(1, 255);
|
|
294
|
-
b = randomi(1, 255);
|
|
295
|
-
str = r + "_" + g + "_" + b;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
if (!obj._pickingColor) {
|
|
299
|
-
obj._pickingColor = new Vec3(r, g, b);
|
|
388
|
+
initialize() {
|
|
389
|
+
if (this._initialized) {
|
|
390
|
+
return;
|
|
300
391
|
} else {
|
|
301
|
-
|
|
392
|
+
this._initialized = true;
|
|
302
393
|
}
|
|
303
394
|
|
|
304
|
-
|
|
395
|
+
var that = this;
|
|
305
396
|
|
|
306
|
-
this.
|
|
307
|
-
}
|
|
308
|
-
};
|
|
397
|
+
this.billboardsTextureAtlas.assignHandler(this.handler);
|
|
309
398
|
|
|
310
|
-
|
|
311
|
-
* Removes picking color from object.
|
|
312
|
-
* @public
|
|
313
|
-
* @param {Object} obj - Object to remove picking color.
|
|
314
|
-
*/
|
|
315
|
-
Renderer.prototype.clearPickingColor = function (obj) {
|
|
316
|
-
if (!obj._pickingColor.isZero()) {
|
|
317
|
-
var c = obj._pickingColor;
|
|
318
|
-
if (!c.isZero()) {
|
|
319
|
-
this.colorObjects[c.x + "_" + c.y + "_" + c.z] = null;
|
|
320
|
-
delete this.colorObjects[c.x + "_" + c.y + "_" + c.z];
|
|
321
|
-
c.x = c.y = c.z = 0;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
};
|
|
399
|
+
this.fontAtlas.assignHandler(this.handler);
|
|
325
400
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
* @returns {number} -
|
|
330
|
-
*/
|
|
331
|
-
Renderer.prototype.getWidth = function () {
|
|
332
|
-
return this.handler.canvas.width;
|
|
333
|
-
};
|
|
401
|
+
this.handler.setFrameCallback(function () {
|
|
402
|
+
that.draw();
|
|
403
|
+
});
|
|
334
404
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
Renderer.prototype.getHeight = function () {
|
|
341
|
-
return this.handler.canvas.height;
|
|
342
|
-
};
|
|
405
|
+
this.activeCamera = new Camera(this, {
|
|
406
|
+
eye: new Vec3(0, 0, 0),
|
|
407
|
+
look: new Vec3(0, 0, -1),
|
|
408
|
+
up: new Vec3(0, 1, 0)
|
|
409
|
+
});
|
|
343
410
|
|
|
344
|
-
|
|
345
|
-
* Get center of the screen
|
|
346
|
-
* @public
|
|
347
|
-
* @returns {og.math.Vec2} -
|
|
348
|
-
*/
|
|
349
|
-
Renderer.prototype.getCenter = function () {
|
|
350
|
-
var cnv = this.handler.canvas;
|
|
351
|
-
return new Vec2(Math.round(cnv.width * 0.5), Math.round(cnv.height * 0.5));
|
|
352
|
-
};
|
|
411
|
+
this.events.initialize();
|
|
353
412
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
Renderer.prototype.addControl = function (control) {
|
|
359
|
-
control.addTo(this);
|
|
360
|
-
};
|
|
413
|
+
// Bind console key
|
|
414
|
+
this.events.on("charkeypress", input.KEY_APOSTROPHE, function () {
|
|
415
|
+
cons.setVisibility(!cons.getVisibility());
|
|
416
|
+
});
|
|
361
417
|
|
|
362
|
-
|
|
363
|
-
* Add the given controls array to the planet node.
|
|
364
|
-
* @param {Array.<og.control.Control>} cArr - Control array.
|
|
365
|
-
*/
|
|
366
|
-
Renderer.prototype.addControls = function (cArr) {
|
|
367
|
-
for (var i = 0; i < cArr.length; i++) {
|
|
368
|
-
cArr[i].addTo(this);
|
|
369
|
-
}
|
|
370
|
-
};
|
|
418
|
+
this.handler.addProgram(screenFrame());
|
|
371
419
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
Renderer.prototype.removeControl = function (control) {
|
|
377
|
-
control.remove();
|
|
378
|
-
};
|
|
420
|
+
this.pickingFramebuffer = new Framebuffer(this.handler, {
|
|
421
|
+
width: 640,
|
|
422
|
+
height: 480
|
|
423
|
+
}).init();
|
|
379
424
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
this._initialized = true;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
var that = this;
|
|
392
|
-
|
|
393
|
-
this.billboardsTextureAtlas.assignHandler(this.handler);
|
|
394
|
-
|
|
395
|
-
this.fontAtlas.assignHandler(this.handler);
|
|
396
|
-
|
|
397
|
-
this.handler.setFrameCallback(function () {
|
|
398
|
-
that.draw();
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
this.activeCamera = new Camera(this, {
|
|
402
|
-
eye: new Vec3(0, 0, 0),
|
|
403
|
-
look: new Vec3(0, 0, -1),
|
|
404
|
-
up: new Vec3(0, 1, 0)
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
this.events.initialize();
|
|
408
|
-
|
|
409
|
-
// Bind console key
|
|
410
|
-
this.events.on("charkeypress", input.KEY_APOSTROPHE, function () {
|
|
411
|
-
cons.setVisibility(!cons.getVisibility());
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
this.handler.addProgram(screenFrame());
|
|
415
|
-
|
|
416
|
-
this.pickingFramebuffer = new Framebuffer(this.handler, {
|
|
417
|
-
width: 640,
|
|
418
|
-
height: 480
|
|
419
|
-
}).init();
|
|
420
|
-
|
|
421
|
-
this.depthFramebuffer = new Framebuffer(this.handler, {
|
|
422
|
-
size: 2,
|
|
423
|
-
internalFormat: ["RGBA", "DEPTH_COMPONENT24"],
|
|
424
|
-
format: ["RGBA", "DEPTH_COMPONENT"],
|
|
425
|
-
type: ["UNSIGNED_BYTE", "UNSIGNED_INT"],
|
|
426
|
-
attachment: ["COLOR_ATTACHMENT", "DEPTH_ATTACHMENT"],
|
|
427
|
-
useDepth: false
|
|
428
|
-
}).init();
|
|
429
|
-
|
|
430
|
-
//this.depthFramebuffer = new Framebuffer(this.handler, {
|
|
431
|
-
// size: 2,
|
|
432
|
-
// internalFormat: ["RGBA", "RGBA"],
|
|
433
|
-
// format: ["RGBA", "RGBA"],
|
|
434
|
-
// type: ["UNSIGNED_BYTE", "UNSIGNED_BYTE"],
|
|
435
|
-
// attachment: ["COLOR_ATTACHMENT", "COLOR_ATTACHMENT"],
|
|
436
|
-
// useDepth: true
|
|
437
|
-
//}).init();
|
|
438
|
-
this.screenDepthFramebuffer = new Framebuffer(this.handler, {
|
|
439
|
-
useDepth: false
|
|
440
|
-
}).init();
|
|
441
|
-
|
|
442
|
-
this.readPixels = () => {};
|
|
443
|
-
|
|
444
|
-
if (this.handler.gl.type === "webgl") {
|
|
445
|
-
this.sceneFramebuffer = new Framebuffer(this.handler);
|
|
446
|
-
this.sceneFramebuffer.init();
|
|
447
|
-
|
|
448
|
-
this._fnScreenFrame = this._screenFrameNoMSAA;
|
|
449
|
-
|
|
450
|
-
this.screenTexture = {
|
|
451
|
-
screen: this.sceneFramebuffer.textures[0],
|
|
452
|
-
picking: this.pickingFramebuffer.textures[0],
|
|
453
|
-
depth: this.screenDepthFramebuffer.textures[0]
|
|
454
|
-
};
|
|
455
|
-
} else {
|
|
456
|
-
let _maxMSAA = this.getMaxMSAA(this._internalFormat);
|
|
425
|
+
this.depthFramebuffer = new Framebuffer(this.handler, {
|
|
426
|
+
size: 2,
|
|
427
|
+
internalFormat: ["RGBA", "DEPTH_COMPONENT24"],
|
|
428
|
+
format: ["RGBA", "DEPTH_COMPONENT"],
|
|
429
|
+
type: ["UNSIGNED_BYTE", "UNSIGNED_INT"],
|
|
430
|
+
attachment: ["COLOR_ATTACHMENT", "DEPTH_ATTACHMENT"],
|
|
431
|
+
useDepth: false
|
|
432
|
+
}).init();
|
|
457
433
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
434
|
+
//this.depthFramebuffer = new Framebuffer(this.handler, {
|
|
435
|
+
// size: 2,
|
|
436
|
+
// internalFormat: ["RGBA", "RGBA"],
|
|
437
|
+
// format: ["RGBA", "RGBA"],
|
|
438
|
+
// type: ["UNSIGNED_BYTE", "UNSIGNED_BYTE"],
|
|
439
|
+
// attachment: ["COLOR_ATTACHMENT", "COLOR_ATTACHMENT"],
|
|
440
|
+
// useDepth: true
|
|
441
|
+
//}).init();
|
|
442
|
+
this.screenDepthFramebuffer = new Framebuffer(this.handler, {
|
|
443
|
+
useDepth: false
|
|
444
|
+
}).init();
|
|
461
445
|
|
|
462
|
-
this.
|
|
446
|
+
this.readPixels = () => {};
|
|
463
447
|
|
|
464
|
-
this.handler.
|
|
448
|
+
if (this.handler.gl.type === "webgl") {
|
|
449
|
+
this.sceneFramebuffer = new Framebuffer(this.handler);
|
|
450
|
+
this.sceneFramebuffer.init();
|
|
465
451
|
|
|
466
|
-
|
|
467
|
-
size: 1,
|
|
468
|
-
msaa: this._msaa,
|
|
469
|
-
internalFormat: this._internalFormat,
|
|
470
|
-
filter: "LINEAR"
|
|
471
|
-
}).init();
|
|
452
|
+
this._fnScreenFrame = this._screenFrameNoMSAA;
|
|
472
453
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
454
|
+
this.screenTexture = {
|
|
455
|
+
screen: this.sceneFramebuffer.textures[0],
|
|
456
|
+
picking: this.pickingFramebuffer.textures[0],
|
|
457
|
+
depth: this.screenDepthFramebuffer.textures[0]
|
|
458
|
+
};
|
|
459
|
+
} else {
|
|
460
|
+
let _maxMSAA = this.getMaxMSAA(this._internalFormat);
|
|
480
461
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
462
|
+
if (this._msaa > _maxMSAA) {
|
|
463
|
+
this._msaa = _maxMSAA;
|
|
464
|
+
}
|
|
484
465
|
|
|
485
|
-
|
|
466
|
+
this.handler.addPrograms([toneMapping()]);
|
|
467
|
+
|
|
468
|
+
this.handler.addPrograms([depth()]);
|
|
469
|
+
|
|
470
|
+
this.sceneFramebuffer = new Multisample(this.handler, {
|
|
471
|
+
size: 1,
|
|
472
|
+
msaa: this._msaa,
|
|
473
|
+
internalFormat: this._internalFormat,
|
|
474
|
+
filter: "LINEAR"
|
|
475
|
+
}).init();
|
|
476
|
+
|
|
477
|
+
this.blitFramebuffer = new Framebuffer(this.handler, {
|
|
478
|
+
useDepth: false,
|
|
479
|
+
internalFormat: this._internalFormat,
|
|
480
|
+
format: this._format,
|
|
481
|
+
type: this._type,
|
|
482
|
+
filter: "LINEAR"
|
|
483
|
+
}).init();
|
|
484
|
+
|
|
485
|
+
this.toneMappingFramebuffer = new Framebuffer(this.handler, {
|
|
486
|
+
useDepth: false
|
|
487
|
+
}).init();
|
|
488
|
+
|
|
489
|
+
this._fnScreenFrame = this._screenFrameMSAA;
|
|
490
|
+
|
|
491
|
+
this.screenTexture = {
|
|
492
|
+
screen: this.toneMappingFramebuffer.textures[0],
|
|
493
|
+
picking: this.pickingFramebuffer.textures[0],
|
|
494
|
+
depth: this.screenDepthFramebuffer.textures[0],
|
|
495
|
+
frustum: this.depthFramebuffer.textures[0]
|
|
496
|
+
};
|
|
497
|
+
}
|
|
486
498
|
|
|
487
|
-
this.
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
depth: this.screenDepthFramebuffer.textures[0],
|
|
491
|
-
frustum: this.depthFramebuffer.textures[0]
|
|
499
|
+
this.handler.onCanvasResize = () => {
|
|
500
|
+
this.events.dispatch(this.events.resize, this.handler.canvas);
|
|
501
|
+
this._resize();
|
|
492
502
|
};
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
this.handler.onCanvasResize = () => {
|
|
496
|
-
this.events.dispatch(this.events.resize, this.handler.canvas);
|
|
497
|
-
this._resize();
|
|
498
|
-
};
|
|
499
503
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
504
|
+
this._screenFrameCornersBuffer = this.handler.createArrayBuffer(
|
|
505
|
+
new Float32Array([1, 1, -1, 1, 1, -1, -1, -1]),
|
|
506
|
+
2,
|
|
507
|
+
4
|
|
508
|
+
);
|
|
505
509
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
510
|
+
let temp = this.controls;
|
|
511
|
+
this.controls = {};
|
|
512
|
+
for (let i in temp) {
|
|
513
|
+
this.addControl(temp[i]);
|
|
514
|
+
}
|
|
511
515
|
|
|
512
|
-
|
|
516
|
+
this.outputTexture = this.screenTexture.screen;
|
|
513
517
|
|
|
514
|
-
|
|
515
|
-
}
|
|
518
|
+
this.fontAtlas.initFont("arial", arial.data, ARIAL_FONT_B64);
|
|
519
|
+
}
|
|
516
520
|
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
+
setCurrentScreen(screenName) {
|
|
522
|
+
this._currentOutput = screenName;
|
|
523
|
+
if (this.screenTexture[screenName]) {
|
|
524
|
+
this.outputTexture = this.screenTexture[screenName];
|
|
525
|
+
}
|
|
521
526
|
}
|
|
522
|
-
};
|
|
523
527
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
obj.clientWidth * this._screenScale,
|
|
529
|
-
obj.clientHeight * this._screenScale
|
|
530
|
-
);
|
|
531
|
-
this.blitFramebuffer &&
|
|
532
|
-
this.blitFramebuffer.setSize(
|
|
528
|
+
_resize() {
|
|
529
|
+
let obj = this.handler.canvas;
|
|
530
|
+
this.activeCamera.setAspectRatio(obj.clientWidth / obj.clientHeight);
|
|
531
|
+
this.sceneFramebuffer.setSize(
|
|
533
532
|
obj.clientWidth * this._screenScale,
|
|
534
|
-
obj.clientHeight * this._screenScale
|
|
535
|
-
true
|
|
533
|
+
obj.clientHeight * this._screenScale
|
|
536
534
|
);
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
this.
|
|
546
|
-
|
|
547
|
-
this.
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
this.
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
}
|
|
535
|
+
this.blitFramebuffer &&
|
|
536
|
+
this.blitFramebuffer.setSize(
|
|
537
|
+
obj.clientWidth * this._screenScale,
|
|
538
|
+
obj.clientHeight * this._screenScale,
|
|
539
|
+
true
|
|
540
|
+
);
|
|
541
|
+
this.toneMappingFramebuffer &&
|
|
542
|
+
this.toneMappingFramebuffer.setSize(obj.clientWidth, obj.clientHeight, true);
|
|
543
|
+
this.depthFramebuffer &&
|
|
544
|
+
this.depthFramebuffer.setSize(obj.clientWidth, obj.clientHeight, true);
|
|
545
|
+
this.screenDepthFramebuffer &&
|
|
546
|
+
this.screenDepthFramebuffer.setSize(obj.clientWidth, obj.clientHeight, true);
|
|
547
|
+
|
|
548
|
+
if (this.handler.gl.type === "webgl") {
|
|
549
|
+
this.screenTexture.screen = this.sceneFramebuffer.textures[0];
|
|
550
|
+
this.screenTexture.picking = this.pickingFramebuffer.textures[0];
|
|
551
|
+
this.screenTexture.depth = this.screenDepthFramebuffer.textures[0];
|
|
552
|
+
this.screenTexture.frustum = this.depthFramebuffer.textures[0];
|
|
553
|
+
} else {
|
|
554
|
+
this.screenTexture.screen = this.toneMappingFramebuffer.textures[0];
|
|
555
|
+
this.screenTexture.picking = this.pickingFramebuffer.textures[0];
|
|
556
|
+
this.screenTexture.depth = this.screenDepthFramebuffer.textures[0];
|
|
557
|
+
this.screenTexture.frustum = this.depthFramebuffer.textures[0];
|
|
558
|
+
}
|
|
561
559
|
|
|
562
|
-
|
|
563
|
-
* Adds render node to the renderer.
|
|
564
|
-
* @public
|
|
565
|
-
* @param {og.scene.RenderNode} renderNode - Render node.
|
|
566
|
-
*/
|
|
567
|
-
Renderer.prototype.addNode = function (renderNode) {
|
|
568
|
-
if (!this.renderNodes[renderNode.name]) {
|
|
569
|
-
renderNode.assign(this);
|
|
570
|
-
this._renderNodesArr.unshift(renderNode);
|
|
571
|
-
this.renderNodes[renderNode.name] = renderNode;
|
|
572
|
-
} else {
|
|
573
|
-
cons.logWrn("Node name " + renderNode.name + " allready exists.");
|
|
560
|
+
this.setCurrentScreen(this._currentOutput);
|
|
574
561
|
}
|
|
575
|
-
};
|
|
576
562
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
* @public
|
|
580
|
-
* @param {og.scene.RenderNode} renderNode - Render node.
|
|
581
|
-
*/
|
|
582
|
-
Renderer.prototype.addNodeBefore = function (renderNode, renderNodeBefore) {
|
|
583
|
-
if (!this.renderNodes[renderNode.name]) {
|
|
584
|
-
renderNode.assign(this);
|
|
585
|
-
this.renderNodes[renderNode.name] = renderNode;
|
|
586
|
-
for (let i = 0; i < this._renderNodesArr.length; i++) {
|
|
587
|
-
if (this._renderNodesArr[i].isEqual(renderNodeBefore)) {
|
|
588
|
-
this._renderNodesArr.splice(i, 0, renderNode);
|
|
589
|
-
break;
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
this._renderNodesArr.unshift(renderNode);
|
|
593
|
-
} else {
|
|
594
|
-
cons.logWrn("Node name " + renderNode.name + " allready exists.");
|
|
563
|
+
removeNode(renderNode) {
|
|
564
|
+
renderNode.remove();
|
|
595
565
|
}
|
|
596
|
-
};
|
|
597
566
|
|
|
598
|
-
/**
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
567
|
+
/**
|
|
568
|
+
* Adds render node to the renderer.
|
|
569
|
+
* @public
|
|
570
|
+
* @param {RenderNode} renderNode - Render node.
|
|
571
|
+
*/
|
|
572
|
+
addNode(renderNode) {
|
|
573
|
+
if (!this.renderNodes[renderNode.name]) {
|
|
574
|
+
renderNode.assign(this);
|
|
575
|
+
this._renderNodesArr.unshift(renderNode);
|
|
576
|
+
this.renderNodes[renderNode.name] = renderNode;
|
|
577
|
+
} else {
|
|
578
|
+
cons.logWrn("Node name " + renderNode.name + " allready exists.");
|
|
579
|
+
}
|
|
606
580
|
}
|
|
607
|
-
};
|
|
608
|
-
|
|
609
|
-
Renderer.prototype.getMaxMSAA = function (internalFormat) {
|
|
610
|
-
var gl = this.handler.gl;
|
|
611
|
-
let samples = gl.getInternalformatParameter(gl.RENDERBUFFER, gl[internalFormat], gl.SAMPLES);
|
|
612
|
-
return samples[0];
|
|
613
|
-
};
|
|
614
581
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
582
|
+
/**
|
|
583
|
+
* Adds render node to the renderer before specific node.
|
|
584
|
+
* @public
|
|
585
|
+
* @param {RenderNode} renderNode - Render node.
|
|
586
|
+
*/
|
|
587
|
+
addNodeBefore(renderNode, renderNodeBefore) {
|
|
588
|
+
if (!this.renderNodes[renderNode.name]) {
|
|
589
|
+
renderNode.assign(this);
|
|
590
|
+
this.renderNodes[renderNode.name] = renderNode;
|
|
591
|
+
for (let i = 0; i < this._renderNodesArr.length; i++) {
|
|
592
|
+
if (this._renderNodesArr[i].isEqual(renderNodeBefore)) {
|
|
593
|
+
this._renderNodesArr.splice(i, 0, renderNode);
|
|
594
|
+
break;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
this._renderNodesArr.unshift(renderNode);
|
|
598
|
+
} else {
|
|
599
|
+
cons.logWrn("Node name " + renderNode.name + " allready exists.");
|
|
600
|
+
}
|
|
601
|
+
}
|
|
625
602
|
|
|
626
|
-
/**
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
603
|
+
/**
|
|
604
|
+
* Adds render nodes array to the renderer.
|
|
605
|
+
* @public
|
|
606
|
+
* @param {Array.<scene.RenderNode>} nodesArr - Render nodes array.
|
|
607
|
+
*/
|
|
608
|
+
addNodes(nodesArr) {
|
|
609
|
+
for (var i = 0; i < nodesArr.length; i++) {
|
|
610
|
+
this.addNode(nodesArr[i]);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
633
613
|
|
|
634
|
-
|
|
614
|
+
getMaxMSAA(internalFormat) {
|
|
635
615
|
var gl = this.handler.gl;
|
|
616
|
+
let samples = gl.getInternalformatParameter(
|
|
617
|
+
gl.RENDERBUFFER,
|
|
618
|
+
gl[internalFormat],
|
|
619
|
+
gl.SAMPLES
|
|
620
|
+
);
|
|
621
|
+
return samples[0];
|
|
622
|
+
}
|
|
636
623
|
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
gl.disable(gl.CULL_FACE);
|
|
624
|
+
getMSAA() {
|
|
625
|
+
return this._msaa;
|
|
626
|
+
}
|
|
641
627
|
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
628
|
+
/**
|
|
629
|
+
* TODO: replace with cahce frendly linked list by bilboardHandler, label handler etc.
|
|
630
|
+
*/
|
|
631
|
+
enqueueEntityCollectionsToDraw(ecArr) {
|
|
632
|
+
this._entityCollections.push.apply(this._entityCollections, ecArr);
|
|
633
|
+
}
|
|
645
634
|
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
635
|
+
/**
|
|
636
|
+
* Draws entity collections.
|
|
637
|
+
* @public
|
|
638
|
+
* @param {Array<og.EntityCollection>} ec - Entity collection array.
|
|
639
|
+
*/
|
|
640
|
+
_drawEntityCollections() {
|
|
641
|
+
let ec = this._entityCollections;
|
|
642
|
+
|
|
643
|
+
if (ec.length) {
|
|
644
|
+
var gl = this.handler.gl;
|
|
645
|
+
|
|
646
|
+
gl.enable(gl.BLEND);
|
|
647
|
+
gl.blendEquation(gl.FUNC_ADD);
|
|
648
|
+
gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE);
|
|
649
|
+
gl.disable(gl.CULL_FACE);
|
|
650
|
+
|
|
651
|
+
// Z-buffer offset
|
|
652
|
+
gl.enable(gl.POLYGON_OFFSET_FILL);
|
|
653
|
+
gl.polygonOffset(0.0, 0.0);
|
|
654
|
+
|
|
655
|
+
// billboards pass
|
|
656
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
657
|
+
gl.bindTexture(gl.TEXTURE_2D, this.billboardsTextureAtlas.texture);
|
|
658
|
+
|
|
659
|
+
var i = ec.length;
|
|
660
|
+
while (i--) {
|
|
661
|
+
var eci = ec[i];
|
|
662
|
+
if (eci._fadingOpacity) {
|
|
663
|
+
// first begin draw event
|
|
664
|
+
eci.events.dispatch(eci.events.draw, eci);
|
|
665
|
+
eci.billboardHandler.draw();
|
|
666
|
+
}
|
|
657
667
|
}
|
|
658
|
-
}
|
|
659
668
|
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
669
|
+
// labels pass
|
|
670
|
+
var fa = this.fontAtlas.atlasesArr;
|
|
671
|
+
for (i = 0; i < fa.length; i++) {
|
|
672
|
+
gl.activeTexture(gl.TEXTURE0 + i);
|
|
673
|
+
gl.bindTexture(gl.TEXTURE_2D, fa[i].texture);
|
|
674
|
+
}
|
|
666
675
|
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
676
|
+
i = ec.length;
|
|
677
|
+
while (i--) {
|
|
678
|
+
ec[i]._fadingOpacity && ec[i].labelHandler.draw();
|
|
679
|
+
}
|
|
671
680
|
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
681
|
+
//geoObject
|
|
682
|
+
i = ec.length;
|
|
683
|
+
while (i--) {
|
|
684
|
+
ec[i]._fadingOpacity && ec[i].geoObjectHandler.draw();
|
|
685
|
+
}
|
|
677
686
|
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
687
|
+
// rays
|
|
688
|
+
i = ec.length;
|
|
689
|
+
while (i--) {
|
|
690
|
+
ec[i]._fadingOpacity && ec[i].rayHandler.draw();
|
|
691
|
+
}
|
|
683
692
|
|
|
684
|
-
|
|
693
|
+
// polyline pass
|
|
694
|
+
i = ec.length;
|
|
695
|
+
while (i--) {
|
|
696
|
+
ec[i]._fadingOpacity && ec[i].polylineHandler.draw();
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
gl.enable(gl.CULL_FACE);
|
|
685
700
|
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
701
|
+
// pointClouds pass
|
|
702
|
+
i = ec.length;
|
|
703
|
+
while (i--) {
|
|
704
|
+
if (ec[i]._fadingOpacity) {
|
|
705
|
+
ec[i].pointCloudHandler.draw();
|
|
706
|
+
}
|
|
691
707
|
}
|
|
692
|
-
}
|
|
693
708
|
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
709
|
+
// shapes pass
|
|
710
|
+
i = ec.length;
|
|
711
|
+
while (i--) {
|
|
712
|
+
eci = ec[i];
|
|
713
|
+
if (eci._fadingOpacity) {
|
|
714
|
+
eci.shapeHandler.draw();
|
|
715
|
+
}
|
|
700
716
|
}
|
|
701
|
-
}
|
|
702
717
|
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
718
|
+
// Strip pass
|
|
719
|
+
i = ec.length;
|
|
720
|
+
while (i--) {
|
|
721
|
+
if (ec[i]._fadingOpacity) {
|
|
722
|
+
ec[i].stripHandler.draw();
|
|
723
|
+
// post draw event
|
|
724
|
+
eci.events.dispatch(eci.events.drawend, eci);
|
|
725
|
+
}
|
|
710
726
|
}
|
|
711
|
-
}
|
|
712
727
|
|
|
713
|
-
|
|
714
|
-
|
|
728
|
+
// gl.polygonOffset(0.0, 0.0);
|
|
729
|
+
gl.disable(gl.POLYGON_OFFSET_FILL);
|
|
715
730
|
|
|
716
|
-
|
|
717
|
-
|
|
731
|
+
this._entityCollections.length = 0;
|
|
732
|
+
this._entityCollections = [];
|
|
733
|
+
}
|
|
718
734
|
}
|
|
719
|
-
};
|
|
720
|
-
|
|
721
|
-
/**
|
|
722
|
-
* Draw nodes.
|
|
723
|
-
* @public
|
|
724
|
-
*/
|
|
725
|
-
Renderer.prototype.draw = function () {
|
|
726
|
-
this.activeCamera.checkMoveEnd();
|
|
727
735
|
|
|
728
|
-
|
|
729
|
-
|
|
736
|
+
/**
|
|
737
|
+
* Draw nodes.
|
|
738
|
+
* @public
|
|
739
|
+
*/
|
|
740
|
+
draw() {
|
|
741
|
+
this.activeCamera.checkMoveEnd();
|
|
730
742
|
|
|
731
|
-
|
|
732
|
-
|
|
743
|
+
let e = this.events;
|
|
744
|
+
e.handleEvents();
|
|
733
745
|
|
|
734
|
-
|
|
746
|
+
let sfb = this.sceneFramebuffer;
|
|
747
|
+
sfb.activate();
|
|
735
748
|
|
|
736
|
-
|
|
737
|
-
h.gl.clear(h.gl.COLOR_BUFFER_BIT | h.gl.DEPTH_BUFFER_BIT);
|
|
749
|
+
let h = this.handler;
|
|
738
750
|
|
|
739
|
-
|
|
751
|
+
h.gl.clearColor(
|
|
752
|
+
this.backgroundColor.x,
|
|
753
|
+
this.backgroundColor.y,
|
|
754
|
+
this.backgroundColor.z,
|
|
755
|
+
1.0
|
|
756
|
+
);
|
|
757
|
+
h.gl.clear(h.gl.COLOR_BUFFER_BIT | h.gl.DEPTH_BUFFER_BIT);
|
|
740
758
|
|
|
741
|
-
|
|
742
|
-
//h.gl.bindTexture(h.gl.TEXTURE_2D, h.transparentTexture);
|
|
759
|
+
e.dispatch(e.draw, this);
|
|
743
760
|
|
|
744
|
-
|
|
761
|
+
//h.gl.activeTexture(h.gl.TEXTURE0);
|
|
762
|
+
//h.gl.bindTexture(h.gl.TEXTURE_2D, h.transparentTexture);
|
|
745
763
|
|
|
746
|
-
|
|
747
|
-
let rn = this._renderNodesArr;
|
|
748
|
-
let k = frustums.length;
|
|
749
|
-
while (k--) {
|
|
750
|
-
this.activeCamera.setCurrentFrustum(k);
|
|
751
|
-
h.gl.clear(h.gl.DEPTH_BUFFER_BIT);
|
|
752
|
-
let i = rn.length;
|
|
753
|
-
while (i--) {
|
|
754
|
-
rn[i].drawNode();
|
|
755
|
-
}
|
|
756
|
-
this._drawEntityCollections();
|
|
764
|
+
let frustums = this.activeCamera.frustums;
|
|
757
765
|
|
|
758
|
-
|
|
766
|
+
// Rendering scene nodes and entityCollections
|
|
767
|
+
let rn = this._renderNodesArr;
|
|
768
|
+
let k = frustums.length;
|
|
769
|
+
while (k--) {
|
|
770
|
+
this.activeCamera.setCurrentFrustum(k);
|
|
771
|
+
h.gl.clear(h.gl.DEPTH_BUFFER_BIT);
|
|
772
|
+
let i = rn.length;
|
|
773
|
+
while (i--) {
|
|
774
|
+
rn[i].drawNode();
|
|
775
|
+
}
|
|
776
|
+
this._drawEntityCollections();
|
|
759
777
|
|
|
760
|
-
|
|
761
|
-
this._drawPickingBuffer(k);
|
|
762
|
-
}
|
|
778
|
+
this._drawDepthBuffer(k);
|
|
763
779
|
|
|
764
|
-
|
|
780
|
+
// Rendering picking callbacks and refresh pickingColor
|
|
781
|
+
this._drawPickingBuffer(k);
|
|
782
|
+
}
|
|
765
783
|
|
|
766
|
-
|
|
784
|
+
sfb.deactivate();
|
|
767
785
|
|
|
768
|
-
|
|
769
|
-
this._readPickingColor();
|
|
770
|
-
}
|
|
786
|
+
this.blitFramebuffer && sfb.blitTo(this.blitFramebuffer);
|
|
771
787
|
|
|
772
|
-
|
|
773
|
-
|
|
788
|
+
if (e.mouseState.anyEvent()) {
|
|
789
|
+
this._readPickingColor();
|
|
790
|
+
}
|
|
774
791
|
|
|
775
|
-
|
|
792
|
+
// Tone mapping followed by rendering on the screen
|
|
793
|
+
this._fnScreenFrame();
|
|
776
794
|
|
|
777
|
-
|
|
778
|
-
e.touchState.moving = false;
|
|
779
|
-
};
|
|
795
|
+
e.dispatch(e.postdraw, this);
|
|
780
796
|
|
|
781
|
-
|
|
782
|
-
|
|
797
|
+
e.mouseState.moving = false;
|
|
798
|
+
e.touchState.moving = false;
|
|
799
|
+
}
|
|
783
800
|
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
gl = h.gl;
|
|
801
|
+
_screenFrameMSAA() {
|
|
802
|
+
var h = this.handler;
|
|
787
803
|
|
|
788
|
-
|
|
804
|
+
var sh = h.programs.toneMapping,
|
|
805
|
+
p = sh._program,
|
|
806
|
+
gl = h.gl;
|
|
789
807
|
|
|
790
|
-
|
|
791
|
-
gl.vertexAttribPointer(p.attributes.corners, 2, gl.FLOAT, false, 0, 0);
|
|
808
|
+
gl.disable(gl.DEPTH_TEST);
|
|
792
809
|
|
|
793
|
-
|
|
810
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._screenFrameCornersBuffer);
|
|
811
|
+
gl.vertexAttribPointer(p.attributes.corners, 2, gl.FLOAT, false, 0, 0);
|
|
794
812
|
|
|
795
|
-
|
|
813
|
+
this.toneMappingFramebuffer.activate();
|
|
796
814
|
|
|
797
|
-
|
|
798
|
-
gl.activeTexture(gl.TEXTURE0);
|
|
799
|
-
gl.bindTexture(gl.TEXTURE_2D, this.blitFramebuffer.textures[0]);
|
|
800
|
-
gl.uniform1i(p.uniforms.hdrBuffer, 0);
|
|
815
|
+
sh.activate();
|
|
801
816
|
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
817
|
+
// screen texture
|
|
818
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
819
|
+
gl.bindTexture(gl.TEXTURE_2D, this.blitFramebuffer.textures[0]);
|
|
820
|
+
gl.uniform1i(p.uniforms.hdrBuffer, 0);
|
|
806
821
|
|
|
807
|
-
|
|
822
|
+
gl.uniform1f(p.uniforms.gamma, this.gamma);
|
|
823
|
+
gl.uniform1f(p.uniforms.exposure, this.exposure);
|
|
824
|
+
gl.uniform1f(p.uniforms.whitepoint, this.whitepoint);
|
|
825
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
808
826
|
|
|
809
|
-
|
|
810
|
-
p = sh._program;
|
|
811
|
-
gl = h.gl;
|
|
827
|
+
this.toneMappingFramebuffer.deactivate();
|
|
812
828
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
gl.uniform1i(p.uniforms.texture, 0);
|
|
817
|
-
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
829
|
+
sh = h.programs.screenFrame;
|
|
830
|
+
p = sh._program;
|
|
831
|
+
gl = h.gl;
|
|
818
832
|
|
|
819
|
-
|
|
820
|
-
|
|
833
|
+
sh.activate();
|
|
834
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
835
|
+
gl.bindTexture(gl.TEXTURE_2D, this.outputTexture);
|
|
836
|
+
gl.uniform1i(p.uniforms.texture, 0);
|
|
837
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
821
838
|
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
var sh = h.programs.screenFrame,
|
|
825
|
-
p = sh._program,
|
|
826
|
-
gl = h.gl;
|
|
839
|
+
gl.enable(gl.DEPTH_TEST);
|
|
840
|
+
}
|
|
827
841
|
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, this._screenFrameCornersBuffer);
|
|
834
|
-
gl.vertexAttribPointer(p.attributes.corners, 2, gl.FLOAT, false, 0, 0);
|
|
835
|
-
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
836
|
-
gl.enable(gl.DEPTH_TEST);
|
|
837
|
-
};
|
|
842
|
+
_screenFrameNoMSAA() {
|
|
843
|
+
var h = this.handler;
|
|
844
|
+
var sh = h.programs.screenFrame,
|
|
845
|
+
p = sh._program,
|
|
846
|
+
gl = h.gl;
|
|
838
847
|
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
return this.colorObjects[c[0] + "_" + c[1] + "_" + c[2]];
|
|
850
|
-
};
|
|
848
|
+
gl.disable(gl.DEPTH_TEST);
|
|
849
|
+
sh.activate();
|
|
850
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
851
|
+
gl.bindTexture(gl.TEXTURE_2D, this.outputTexture);
|
|
852
|
+
gl.uniform1i(p.uniforms.texture, 0);
|
|
853
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._screenFrameCornersBuffer);
|
|
854
|
+
gl.vertexAttribPointer(p.attributes.corners, 2, gl.FLOAT, false, 0, 0);
|
|
855
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
856
|
+
gl.enable(gl.DEPTH_TEST);
|
|
857
|
+
}
|
|
851
858
|
|
|
852
|
-
/**
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
+
/**
|
|
860
|
+
* Returns picking object by screen coordinates
|
|
861
|
+
* @param {number} x - X position
|
|
862
|
+
* @param {number} y - Y position
|
|
863
|
+
* @return {Object} -
|
|
864
|
+
*/
|
|
865
|
+
getPickingObject(x, y) {
|
|
866
|
+
let cnv = this.renderer.handler.canvas,
|
|
867
|
+
c = new Uint8Array(3);
|
|
868
|
+
this.readPixels(c, x / cnv.width, (cnv.height - y) / cnv.height, 1);
|
|
869
|
+
return this.colorObjects[c[0] + "_" + c[1] + "_" + c[2]];
|
|
870
|
+
}
|
|
859
871
|
|
|
860
|
-
|
|
861
|
-
|
|
872
|
+
/**
|
|
873
|
+
* Draw picking objects framebuffer.
|
|
874
|
+
* @private
|
|
875
|
+
*/
|
|
876
|
+
_drawPickingBuffer(frustumIndex) {
|
|
877
|
+
if (this.events.mouseState.anyEvent()) {
|
|
878
|
+
this.pickingFramebuffer.activate();
|
|
879
|
+
|
|
880
|
+
var h = this.handler;
|
|
881
|
+
var gl = h.gl;
|
|
882
|
+
|
|
883
|
+
if (frustumIndex === this.activeCamera.FARTHEST_FRUSTUM_INDEX) {
|
|
884
|
+
gl.clearColor(0.0, 0.0, 0.0, 1.0);
|
|
885
|
+
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
886
|
+
} else {
|
|
887
|
+
gl.clear(gl.DEPTH_BUFFER_BIT);
|
|
888
|
+
}
|
|
862
889
|
|
|
863
|
-
|
|
864
|
-
gl.clearColor(0.0, 0.0, 0.0, 1.0);
|
|
865
|
-
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
866
|
-
} else {
|
|
867
|
-
gl.clear(gl.DEPTH_BUFFER_BIT);
|
|
868
|
-
}
|
|
890
|
+
gl.disable(h.gl.BLEND);
|
|
869
891
|
|
|
870
|
-
|
|
892
|
+
var dp = this._pickingCallbacks;
|
|
893
|
+
var i = dp.length;
|
|
894
|
+
while (i--) {
|
|
895
|
+
/**
|
|
896
|
+
* This callback renders picking frame.
|
|
897
|
+
* @callback og.Renderer~pickingCallback
|
|
898
|
+
*/
|
|
899
|
+
dp[i].callback.call(dp[i].sender);
|
|
900
|
+
}
|
|
871
901
|
|
|
872
|
-
|
|
873
|
-
var i = dp.length;
|
|
874
|
-
while (i--) {
|
|
875
|
-
/**
|
|
876
|
-
* This callback renders picking frame.
|
|
877
|
-
* @callback og.Renderer~pickingCallback
|
|
878
|
-
*/
|
|
879
|
-
dp[i].callback.call(dp[i].sender);
|
|
902
|
+
this.pickingFramebuffer.deactivate();
|
|
880
903
|
}
|
|
881
|
-
|
|
882
|
-
this.pickingFramebuffer.deactivate();
|
|
883
904
|
}
|
|
884
|
-
};
|
|
885
905
|
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
906
|
+
_drawDepthBuffer(frustumIndex) {
|
|
907
|
+
if (frustumIndex === 0) {
|
|
908
|
+
this.depthFramebuffer.activate();
|
|
889
909
|
|
|
890
|
-
|
|
891
|
-
|
|
910
|
+
var h = this.handler;
|
|
911
|
+
var gl = h.gl;
|
|
892
912
|
|
|
893
|
-
|
|
894
|
-
|
|
913
|
+
gl.clearColor(0.0, 0.0, 0.0, 1.0);
|
|
914
|
+
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
895
915
|
|
|
896
|
-
|
|
916
|
+
gl.enable(gl.DEPTH_TEST);
|
|
897
917
|
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
918
|
+
var dp = this._depthCallbacks;
|
|
919
|
+
var i = dp.length;
|
|
920
|
+
while (i--) {
|
|
921
|
+
/**
|
|
922
|
+
* This callback renders depth frame.
|
|
923
|
+
* @callback og.Renderer~depthCallback
|
|
924
|
+
*/
|
|
925
|
+
dp[i].callback.call(dp[i].sender);
|
|
926
|
+
}
|
|
907
927
|
|
|
908
|
-
|
|
928
|
+
this.depthFramebuffer.deactivate();
|
|
909
929
|
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
930
|
+
//
|
|
931
|
+
// PASS to depth visualization
|
|
932
|
+
var sh = h.programs.depth,
|
|
933
|
+
p = sh._program;
|
|
914
934
|
|
|
915
|
-
|
|
935
|
+
gl = h.gl;
|
|
916
936
|
|
|
917
|
-
|
|
918
|
-
|
|
937
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._screenFrameCornersBuffer);
|
|
938
|
+
gl.vertexAttribPointer(p.attributes.corners, 2, gl.FLOAT, false, 0, 0);
|
|
919
939
|
|
|
920
|
-
|
|
940
|
+
this.screenDepthFramebuffer.activate();
|
|
921
941
|
|
|
922
|
-
|
|
942
|
+
sh.activate();
|
|
923
943
|
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
944
|
+
gl.activeTexture(gl.TEXTURE1);
|
|
945
|
+
gl.bindTexture(gl.TEXTURE_2D, this.depthFramebuffer.textures[1]);
|
|
946
|
+
gl.uniform1i(p.uniforms.depthTexture, 1);
|
|
927
947
|
|
|
928
|
-
|
|
948
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
929
949
|
|
|
930
|
-
|
|
950
|
+
this.screenDepthFramebuffer.deactivate();
|
|
951
|
+
}
|
|
931
952
|
}
|
|
932
|
-
};
|
|
933
|
-
|
|
934
|
-
Renderer.prototype._readPickingColor = function () {
|
|
935
|
-
var ms = this.events.mouseState;
|
|
936
|
-
var ts = this.events.touchState;
|
|
937
|
-
|
|
938
|
-
if (!(ms.leftButtonHold || ms.rightButtonHold || ms.middleButtonHold)) {
|
|
939
|
-
this._prevPickingColor[0] = this._currPickingColor[0];
|
|
940
|
-
this._prevPickingColor[1] = this._currPickingColor[1];
|
|
941
|
-
this._prevPickingColor[2] = this._currPickingColor[2];
|
|
942
953
|
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
this.
|
|
951
|
-
|
|
952
|
-
|
|
954
|
+
_readPickingColor() {
|
|
955
|
+
var ms = this.events.mouseState;
|
|
956
|
+
var ts = this.events.touchState;
|
|
957
|
+
|
|
958
|
+
if (!(ms.leftButtonHold || ms.rightButtonHold || ms.middleButtonHold)) {
|
|
959
|
+
this._prevPickingColor[0] = this._currPickingColor[0];
|
|
960
|
+
this._prevPickingColor[1] = this._currPickingColor[1];
|
|
961
|
+
this._prevPickingColor[2] = this._currPickingColor[2];
|
|
962
|
+
|
|
963
|
+
var pc = this._currPickingColor;
|
|
964
|
+
if (ts.x || ts.y) {
|
|
965
|
+
this.pickingFramebuffer.readPixels(pc, ts.nx, 1.0 - ts.ny);
|
|
966
|
+
if (!(pc[0] || pc[1] || pc[2])) {
|
|
967
|
+
this.readPixels(pc, ts.nx, 1.0 - ts.ny, 1);
|
|
968
|
+
}
|
|
969
|
+
} else {
|
|
970
|
+
this.pickingFramebuffer.readPixels(pc, ms.nx, 1.0 - ms.ny);
|
|
971
|
+
if (!(pc[0] || pc[1] || pc[2])) {
|
|
972
|
+
this.readPixels(pc, ms.nx, 1.0 - ms.ny, 1);
|
|
973
|
+
}
|
|
953
974
|
}
|
|
954
975
|
}
|
|
955
976
|
}
|
|
956
|
-
};
|
|
957
977
|
|
|
958
|
-
/**
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
}
|
|
978
|
+
/**
|
|
979
|
+
* Function starts rendering.
|
|
980
|
+
* @public
|
|
981
|
+
*/
|
|
982
|
+
start() {
|
|
983
|
+
this.handler.start();
|
|
984
|
+
}
|
|
985
|
+
}
|
|
965
986
|
|
|
966
987
|
export { Renderer };
|