@openglobus/og 0.15.0 → 0.15.2
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/README.md +10 -4
- package/css/og.css +44 -45
- package/dist/@openglobus/og.css +1 -1
- package/dist/@openglobus/og.esm.js +2 -2
- package/dist/@openglobus/og.esm.js.map +1 -1
- package/dist/@openglobus/og.umd.js +2 -2
- package/dist/@openglobus/og.umd.js.map +1 -1
- package/package.json +12 -12
- package/src/og/Clock.js +1 -1
- package/src/og/Events.js +1 -1
- package/src/og/Extent.js +1 -1
- package/src/og/Globe.js +3 -5
- package/src/og/Popup.js +38 -63
- package/src/og/astro/earth.js +2 -2
- package/src/og/astro/rotation.js +2 -2
- package/src/og/bv/Box.js +1 -0
- package/src/og/bv/index.js +1 -1
- package/src/og/camera/Camera.js +4 -4
- package/src/og/camera/PlanetCamera.js +26 -6
- package/src/og/camera/index.js +1 -1
- package/src/og/control/Atmosphere.js +3 -8
- package/src/og/control/CompassButton.js +4 -5
- package/src/og/control/Control.js +25 -15
- package/src/og/control/EarthCoordinates.js +3 -2
- package/src/og/control/EarthNavigation.js +0 -1
- package/src/og/control/GeoImageDragControl.js +2 -2
- package/src/og/control/KeyboardNavigation.js +3 -2
- package/src/og/control/LayerAnimation.js +2 -2
- package/src/og/control/LayerSwitcher.js +5 -4
- package/src/og/control/Lighting.js +106 -35
- package/src/og/control/MouseNavigation.js +4 -4
- package/src/og/control/MouseWheelZoomControl.js +2 -2
- package/src/og/control/RulerSwitcher.js +4 -3
- package/src/og/control/ScaleControl.js +2 -2
- package/src/og/control/ShowFps.js +2 -1
- package/src/og/control/SimpleNavigation.js +2 -1
- package/src/og/control/SimpleSkyBackground.js +2 -2
- package/src/og/control/Sun.js +9 -2
- package/src/og/control/ToggleWireframe.js +2 -1
- package/src/og/control/TouchNavigation.js +4 -3
- package/src/og/control/ZoomControl.js +6 -5
- package/src/og/control/index.js +10 -10
- package/src/og/control/ruler/RulerScene.js +19 -11
- package/src/og/control/selection/Selection.js +1 -1
- package/src/og/control/selection/SelectionScene.js +5 -8
- package/src/og/control/timeline/TimelineControl.js +3 -4
- package/src/og/control/timeline/TimelineModel.js +2 -2
- package/src/og/control/timeline/TimelineView.js +10 -5
- package/src/og/control/visibleExtent/Segment.js +5 -5
- package/src/og/control/visibleExtent/VisibleExtent.js +1 -1
- package/src/og/ellipsoid/Ellipsoid.js +3 -3
- package/src/og/entity/BaseBillboard.js +2 -2
- package/src/og/entity/BillboardHandler.js +10 -2
- package/src/og/entity/Entity.js +10 -51
- package/src/og/entity/EntityCollection.js +3 -20
- package/src/og/entity/GeoObject.js +2 -4
- package/src/og/entity/GeoObjectHandler.js +12 -11
- package/src/og/entity/Geometry.js +2 -2
- package/src/og/entity/GeometryHandler.js +2 -2
- package/src/og/entity/Label.js +2 -2
- package/src/og/entity/LabelHandler.js +7 -5
- package/src/og/entity/Polyline.js +8 -7
- package/src/og/entity/Ray.js +1 -2
- package/src/og/entity/RayHandler.js +4 -0
- package/src/og/entity/Strip.js +8 -5
- package/src/og/entity/index.js +1 -1
- package/src/og/index.core.js +4 -4
- package/src/og/index.js +7 -5
- package/src/og/index.webgl.js +3 -3
- package/src/og/layer/BaseGeoImage.js +2 -2
- package/src/og/layer/GeoImage.js +2 -2
- package/src/og/layer/GeoTexture2d.js +1 -1
- package/src/og/layer/Layer.js +3 -3
- package/src/og/layer/Vector.js +7 -11
- package/src/og/layer/WMS.js +2 -1
- package/src/og/layer/XYZ.js +2 -4
- package/src/og/math/Line3.js +0 -1
- package/src/og/math/Plane.js +0 -1
- package/src/og/math/Ray.js +0 -1
- package/src/og/math/Vec2.js +62 -62
- package/src/og/math/Vec3.js +1 -1
- package/src/og/math/Vec4.js +1 -1
- package/src/og/math/index.js +1 -1
- package/src/og/proj/EPSG3857.js +1 -1
- package/src/og/proj/EPSG4326.js +1 -1
- package/src/og/quadTree/EarthQuadTreeStrategy.js +4 -4
- package/src/og/quadTree/MarsQuadTreeStrategy.js +4 -4
- package/src/og/quadTree/Node.js +1 -1
- package/src/og/quadTree/Wgs84QuadTreeStrategy.js +4 -4
- package/src/og/quadTree/index.js +2 -2
- package/src/og/renderer/Renderer.js +196 -77
- package/src/og/renderer/RendererEvents.js +35 -10
- package/src/og/scene/Axes.js +2 -2
- package/src/og/scene/Planet.js +52 -80
- package/src/og/scene/RenderNode.js +2 -13
- package/src/og/scene/SkyBox.js +1 -1
- package/src/og/scene/index.js +2 -2
- package/src/og/segment/Segment.js +5 -5
- package/src/og/segment/SegmentLonLatWgs84.js +2 -3
- package/src/og/shaders/drawnode.js +5 -1
- package/src/og/shaders/geoObject.js +2 -6
- package/src/og/shaders/pickingMask.js +31 -0
- package/src/og/terrain/BilTerrain.js +4 -4
- package/src/og/terrain/GlobusTerrain.js +7 -7
- package/src/og/terrain/MapboxTerrain.js +2 -2
- package/src/og/terrain/index.js +2 -2
- package/src/og/ui/Button.js +5 -4
- package/src/og/ui/Dialog.js +3 -6
- package/src/og/ui/Slider.js +29 -3
- package/src/og/ui/View.js +5 -5
- package/src/og/ui/icons.js +3 -0
- package/src/og/utils/FontAtlas.js +2 -2
- package/src/og/utils/GeoImageCreator.js +0 -1
- package/src/og/utils/NormalMapCreator.js +6 -5
- package/src/og/utils/TerrainWorker.js +1 -1
- package/src/og/utils/VectorTileCreator.js +4 -4
- package/src/og/utils/shared.js +1 -1
- package/src/og/webgl/Framebuffer.js +3 -1
- package/src/og/webgl/Handler.js +77 -62
- package/src/og/webgl/Multisample.js +18 -7
- package/src/og/webgl/Program.js +2 -2
- package/src/og/webgl/index.js +2 -2
- package/types/Popup.d.ts +8 -21
- package/types/camera/PlanetCamera.d.ts +1 -0
- package/types/control/Sun.d.ts +1 -0
- package/types/control/ruler/RulerScene.d.ts +4 -3
- package/types/entity/Entity.d.ts +2 -19
- package/types/entity/EntityCollection.d.ts +0 -7
- package/types/index.d.ts +2 -1
- package/types/math/Vec2.d.ts +95 -95
- package/types/renderer/Renderer.d.ts +28 -16
- package/types/scene/Planet.d.ts +2 -7
- package/types/shaders/pickingMask.d.ts +2 -0
- package/types/ui/Slider.d.ts +3 -0
- package/types/ui/View.d.ts +1 -0
- package/types/ui/icons.d.ts +1 -0
- package/types/webgl/Framebuffer.d.ts +1 -0
- package/types/webgl/Handler.d.ts +3 -2
- package/src/og/entity/ShapeHandler.js +0 -99
- package/src/og/shaders/shape.js +0 -135
- package/src/og/shapes/BaseShape.js +0 -557
- package/src/og/shapes/Icosphere.js +0 -179
- package/src/og/shapes/Sphere.js +0 -100
- package/types/entity/ShapeHandler.d.ts +0 -22
- package/types/shaders/shape.d.ts +0 -4
- package/types/shapes/BaseShape.d.ts +0 -250
- package/types/shapes/Sphere.d.ts +0 -41
package/src/og/shaders/shape.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module og/shaders/shape
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
import { Program } from "../webgl/Program.js";
|
|
8
|
-
import { types } from "../webgl/types.js";
|
|
9
|
-
|
|
10
|
-
export function shape_wl() {
|
|
11
|
-
return new Program("shape_wl", {
|
|
12
|
-
uniforms: {
|
|
13
|
-
viewMatrix: { type: types.MAT4 },
|
|
14
|
-
projectionMatrix: { type: types.MAT4 },
|
|
15
|
-
modelMatrix: { type: types.MAT4 },
|
|
16
|
-
normalMatrix: { type: types.MAT4 },
|
|
17
|
-
|
|
18
|
-
lightsPositions: { type: types.VEC4 },
|
|
19
|
-
lightsParamsv: { type: types.VEC3 },
|
|
20
|
-
lightsParamsf: { type: types.FLOAT },
|
|
21
|
-
|
|
22
|
-
uColor: { type: types.VEC4 },
|
|
23
|
-
uSampler: { type: types.SAMPLER2D }
|
|
24
|
-
},
|
|
25
|
-
attributes: {
|
|
26
|
-
aVertexNormal: { type: types.VEC3 },
|
|
27
|
-
aVertexPosition: { type: types.VEC3 },
|
|
28
|
-
aTextureCoord: { type: types.VEC2 }
|
|
29
|
-
},
|
|
30
|
-
vertexShader: `attribute vec3 aVertexNormal;
|
|
31
|
-
attribute vec3 aVertexPosition;
|
|
32
|
-
attribute vec2 aTextureCoord;
|
|
33
|
-
uniform mat4 projectionMatrix;
|
|
34
|
-
uniform mat4 viewMatrix;
|
|
35
|
-
uniform mat4 modelMatrix;
|
|
36
|
-
uniform mat3 normalMatrix;
|
|
37
|
-
varying vec2 vTextureCoord;
|
|
38
|
-
varying vec3 vNormal;
|
|
39
|
-
varying vec4 vPosition;
|
|
40
|
-
|
|
41
|
-
void main(void) {
|
|
42
|
-
vTextureCoord = aTextureCoord;
|
|
43
|
-
vNormal = normalMatrix * aVertexNormal;
|
|
44
|
-
vPosition = viewMatrix * modelMatrix * vec4(aVertexPosition, 1.0);
|
|
45
|
-
gl_Position = projectionMatrix * vPosition;
|
|
46
|
-
}`,
|
|
47
|
-
fragmentShader: `precision highp float;
|
|
48
|
-
varying vec2 vTextureCoord;
|
|
49
|
-
varying vec3 vNormal;
|
|
50
|
-
varying vec4 vPosition;
|
|
51
|
-
uniform vec4 uColor;
|
|
52
|
-
uniform sampler2D uSampler;
|
|
53
|
-
#define MAX_POINT_LIGHTS 1
|
|
54
|
-
uniform int lightsQuantity;
|
|
55
|
-
uniform vec4 lightsPositions[MAX_POINT_LIGHTS];
|
|
56
|
-
uniform vec3 lightsParamsv[MAX_POINT_LIGHTS * 3];
|
|
57
|
-
uniform float lightsParamsf[MAX_POINT_LIGHTS];
|
|
58
|
-
void main(void) {
|
|
59
|
-
vec3 lightWeighting;
|
|
60
|
-
vec3 lightDirection;
|
|
61
|
-
vec3 normal;
|
|
62
|
-
vec3 eyeDirection;
|
|
63
|
-
vec3 reflectionDirection;
|
|
64
|
-
float specularLightWeighting;
|
|
65
|
-
float diffuseLightWeighting;
|
|
66
|
-
lightDirection = normalize(lightsPositions[0].xyz - vPosition.xyz * lightsPositions[0].w);
|
|
67
|
-
normal = normalize(vNormal);
|
|
68
|
-
eyeDirection = normalize(-vPosition.xyz);
|
|
69
|
-
reflectionDirection = reflect(-lightDirection, normal);
|
|
70
|
-
specularLightWeighting = pow(max(dot(reflectionDirection, eyeDirection), 0.0), lightsParamsf[0]);
|
|
71
|
-
diffuseLightWeighting = max(dot(normal, lightDirection), 0.0);
|
|
72
|
-
lightWeighting = lightsParamsv[0] + lightsParamsv[1] * diffuseLightWeighting + lightsParamsv[2] * specularLightWeighting;
|
|
73
|
-
vec4 cc = texture2D( uSampler, vTextureCoord.st );
|
|
74
|
-
gl_FragColor = vec4(lightWeighting, uColor.a) * cc * uColor;
|
|
75
|
-
}`
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function shape_nl() {
|
|
80
|
-
return new Program("shape_nl", {
|
|
81
|
-
uniforms: {
|
|
82
|
-
projectionViewMatrix: { type: types.MAT4 },
|
|
83
|
-
modelMatrix: { type: types.MAT4 },
|
|
84
|
-
uColor: { type: types.VEC4 },
|
|
85
|
-
uSampler: { type: types.SAMPLER2D }
|
|
86
|
-
},
|
|
87
|
-
attributes: {
|
|
88
|
-
aVertexPosition: { type: types.VEC3, enableArray: true },
|
|
89
|
-
aTextureCoord: { type: types.VEC2, enableArray: true }
|
|
90
|
-
},
|
|
91
|
-
vertexShader: `attribute vec3 aVertexPosition;
|
|
92
|
-
attribute vec2 aTextureCoord;
|
|
93
|
-
uniform mat4 projectionViewMatrix;
|
|
94
|
-
uniform mat4 modelMatrix;
|
|
95
|
-
varying vec2 vTextureCoord;
|
|
96
|
-
|
|
97
|
-
void main(void) {
|
|
98
|
-
gl_Position = projectionViewMatrix * (modelMatrix * vec4(aVertexPosition, 1.0));
|
|
99
|
-
vTextureCoord = aTextureCoord;
|
|
100
|
-
}`,
|
|
101
|
-
fragmentShader: `precision highp float;
|
|
102
|
-
uniform vec4 uColor;
|
|
103
|
-
uniform sampler2D uSampler;
|
|
104
|
-
varying vec2 vTextureCoord;
|
|
105
|
-
void main(void) {
|
|
106
|
-
gl_FragColor = uColor*texture2D( uSampler, vTextureCoord.st );
|
|
107
|
-
}`
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export function shape_picking() {
|
|
112
|
-
return new Program("shape_picking", {
|
|
113
|
-
uniforms: {
|
|
114
|
-
projectionViewMatrix: { type: types.MAT4 },
|
|
115
|
-
modelMatrix: { type: types.MAT4 },
|
|
116
|
-
uColor: { type: types.VEC4 }
|
|
117
|
-
},
|
|
118
|
-
attributes: {
|
|
119
|
-
aVertexPosition: { type: types.VEC3, enableArray: true }
|
|
120
|
-
},
|
|
121
|
-
vertexShader: `attribute vec3 aVertexPosition;
|
|
122
|
-
uniform mat4 projectionViewMatrix;
|
|
123
|
-
uniform mat4 modelMatrix;
|
|
124
|
-
|
|
125
|
-
void main(void) {
|
|
126
|
-
gl_Position = projectionViewMatrix * (modelMatrix * vec4(aVertexPosition, 1.0));
|
|
127
|
-
}`,
|
|
128
|
-
fragmentShader: `precision highp float;
|
|
129
|
-
uniform vec4 uColor;
|
|
130
|
-
uniform sampler2D uSampler;
|
|
131
|
-
void main(void) {
|
|
132
|
-
gl_FragColor = uColor;
|
|
133
|
-
}`
|
|
134
|
-
});
|
|
135
|
-
}
|
|
@@ -1,557 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module og/shape/BaseShape
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
import { Vec3 } from "../math/Vec3.js";
|
|
8
|
-
import { Quat } from "../math/Quat.js";
|
|
9
|
-
import { Mat4 } from "../math/Mat4.js";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Base geometry shape class.
|
|
13
|
-
* @class
|
|
14
|
-
* @param {Object} options - Shape parameters:
|
|
15
|
-
* @param {Vec3} [options.position] - Shape position.
|
|
16
|
-
* @param {Quat} [options.orientation] - Shape orientation(rotation).
|
|
17
|
-
* @param {Vec3} [options.scale] - Scale vector.
|
|
18
|
-
* @param {Array.<number>} [options.color] - Shape RGBA color. (exactly 4 entries)
|
|
19
|
-
* @param {string} [options.src] - Texture image url source.
|
|
20
|
-
* @param {boolean} [options.visibility] - Shape visibility.
|
|
21
|
-
*/
|
|
22
|
-
class BaseShape {
|
|
23
|
-
constructor(options) {
|
|
24
|
-
options = options || {};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Unic identifier.
|
|
28
|
-
* @public
|
|
29
|
-
* @readonly
|
|
30
|
-
* @type {number}
|
|
31
|
-
*/
|
|
32
|
-
this.id = BaseShape._staticCounter++;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Shape position.
|
|
36
|
-
* @public
|
|
37
|
-
* @type {Vec3}
|
|
38
|
-
*/
|
|
39
|
-
this.position = options.position || new Vec3();
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Shape orientation(rotation)
|
|
43
|
-
* @public
|
|
44
|
-
* @type {Quat}
|
|
45
|
-
*/
|
|
46
|
-
this.orientation = options.orientation || new Quat(0.0, 0.0, 0.0, 1.0);
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Scale.
|
|
50
|
-
* @public
|
|
51
|
-
* @type {Vec3}
|
|
52
|
-
*/
|
|
53
|
-
this.scale = options.scale || new Vec3(1.0, 1.0, 1.0);
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Shape RGBA color.
|
|
57
|
-
* @public
|
|
58
|
-
* @type {Array.<number>} - (exactly 4 entries)
|
|
59
|
-
*/
|
|
60
|
-
this.color = options.color
|
|
61
|
-
? new Float32Array(options.color)
|
|
62
|
-
: new Float32Array([1.0, 1.0, 1.0, 1.0]);
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Shape visibility.
|
|
66
|
-
* @public
|
|
67
|
-
* @type {boolean}
|
|
68
|
-
*/
|
|
69
|
-
this.visibility = options.visibility != undefined ? options.visibility : true;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Image url source.
|
|
73
|
-
* @protected
|
|
74
|
-
* @type {string}
|
|
75
|
-
*/
|
|
76
|
-
this._src = options.src || null;
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Vertices position gl buffer.
|
|
80
|
-
* @protected
|
|
81
|
-
*/
|
|
82
|
-
this._positionBuffer = null;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Vertices normal gl buffer.
|
|
86
|
-
* @protected
|
|
87
|
-
*/
|
|
88
|
-
this._normalBuffer = null;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Vertices indexes gl buffer.
|
|
92
|
-
* @protected
|
|
93
|
-
*/
|
|
94
|
-
this._indexBuffer = null;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Vertex texture coordinates gl buffer.
|
|
98
|
-
* @protected
|
|
99
|
-
*/
|
|
100
|
-
this._textureCoordBuffer = null;
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Vertex positions.
|
|
104
|
-
* @protected
|
|
105
|
-
* @type {Array.<number>}
|
|
106
|
-
*/
|
|
107
|
-
this._positionData = [];
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Vertex normals.
|
|
111
|
-
* @protected
|
|
112
|
-
* @type {Array.<number>}
|
|
113
|
-
*/
|
|
114
|
-
this._normalData = [];
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Vertex indeces.
|
|
118
|
-
* @protected
|
|
119
|
-
* @type {Array.<number>}
|
|
120
|
-
*/
|
|
121
|
-
this._indexData = [];
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Vertex texture coordinates.
|
|
125
|
-
* @protected
|
|
126
|
-
* @type {Array.<number>}
|
|
127
|
-
*/
|
|
128
|
-
this._textureCoordData = [];
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Scale matrix.
|
|
132
|
-
* @protected
|
|
133
|
-
* @type {Mat4}
|
|
134
|
-
*/
|
|
135
|
-
this._mxScale = new Mat4().setIdentity().scale(this.scale);
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Translation matrix.
|
|
139
|
-
* @protected
|
|
140
|
-
* @type {Mat4}
|
|
141
|
-
*/
|
|
142
|
-
this._mxTranslation = new Mat4().setIdentity();
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Model matrix.
|
|
146
|
-
* @protected
|
|
147
|
-
* @type {Mat4}
|
|
148
|
-
*/
|
|
149
|
-
this._mxModel = new Mat4().setIdentity();
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Gl texture pointer.
|
|
153
|
-
* @protected
|
|
154
|
-
*/
|
|
155
|
-
this.texture = null;
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Assigned render node.
|
|
159
|
-
* @protected
|
|
160
|
-
* @type {RenderNode}
|
|
161
|
-
*/
|
|
162
|
-
this._renderNode = null;
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Assigned picking color.
|
|
166
|
-
* @protected
|
|
167
|
-
* @type {Array.<number>} - (exactly 3 entries)
|
|
168
|
-
*/
|
|
169
|
-
this._pickingColor = [0.0, 0.0, 0.0, 0.0];
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Entity instance that holds this shape.
|
|
173
|
-
* @protected
|
|
174
|
-
* @type {Entity}
|
|
175
|
-
*/
|
|
176
|
-
this._entity = null;
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Handler that stores and renders this shape object.
|
|
180
|
-
* @protected
|
|
181
|
-
* @type {ShapeHandler}
|
|
182
|
-
*/
|
|
183
|
-
this._handler = null;
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Shape handler array index.
|
|
187
|
-
* @protected
|
|
188
|
-
* @type {number}
|
|
189
|
-
*/
|
|
190
|
-
this._handlerIndex = -1;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
static get _staticCounter() {
|
|
194
|
-
if (!this._counter && this._counter !== 0) {
|
|
195
|
-
this._counter = 0;
|
|
196
|
-
}
|
|
197
|
-
return this._counter;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
static set _staticCounter(n) {
|
|
201
|
-
this._counter = n;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Clear shape parameters.
|
|
206
|
-
* @public
|
|
207
|
-
*/
|
|
208
|
-
clear() {
|
|
209
|
-
this.position.set(0.0, 0.0, 0.0);
|
|
210
|
-
this.orientation.set(0.0, 0.0, 0.0, 1.0);
|
|
211
|
-
this.scale.set(1.0, 1.0, 1.0);
|
|
212
|
-
|
|
213
|
-
this._positionData.length = 0;
|
|
214
|
-
this._normalData.length = 0;
|
|
215
|
-
this._indexData.length = 0;
|
|
216
|
-
|
|
217
|
-
this._mxScale.setIdentity();
|
|
218
|
-
this._mxTranslation.setIdentity();
|
|
219
|
-
this._mxModel.setIdentity();
|
|
220
|
-
|
|
221
|
-
this._renderNode.handler.gl.deleteTexture(this.texture);
|
|
222
|
-
this.texture = null;
|
|
223
|
-
|
|
224
|
-
this._deleteBuffers();
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Sets shape color.
|
|
229
|
-
* @public
|
|
230
|
-
* @param {Array.<number>} color - RGBA color values array. (exactly 4 entries)
|
|
231
|
-
*/
|
|
232
|
-
setColor(color) {
|
|
233
|
-
this.color[0] = color[0];
|
|
234
|
-
this.color[1] = color[1];
|
|
235
|
-
this.color[2] = color[2];
|
|
236
|
-
this.color[3] = color[3];
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Sets shape color.
|
|
241
|
-
* @public
|
|
242
|
-
* @param {Vec4} color - RGBA color vector.
|
|
243
|
-
*/
|
|
244
|
-
setColor4v(color) {
|
|
245
|
-
this.color[0] = color.x;
|
|
246
|
-
this.color[1] = color.y;
|
|
247
|
-
this.color[2] = color.z;
|
|
248
|
-
this.color[3] = color.w;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Sets shape opacity value.
|
|
253
|
-
* @public
|
|
254
|
-
* @param {number} opacity - Opacity value.
|
|
255
|
-
*/
|
|
256
|
-
setOpacity(opacity) {
|
|
257
|
-
this.color[3] = opacity;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Delete gl buffers.
|
|
262
|
-
* @protected
|
|
263
|
-
*/
|
|
264
|
-
_deleteBuffers() {
|
|
265
|
-
var r = this._renderNode.renderer,
|
|
266
|
-
gl = r.handler.gl;
|
|
267
|
-
|
|
268
|
-
gl.deleteBuffer(this._positionBuffer);
|
|
269
|
-
gl.deleteBuffer(this._normalBuffer);
|
|
270
|
-
gl.deleteBuffer(this._indexBuffer);
|
|
271
|
-
|
|
272
|
-
this._positionBuffer = null;
|
|
273
|
-
this._normalBuffer = null;
|
|
274
|
-
this._indexBuffer = null;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Sets shape visibility.
|
|
279
|
-
* @public
|
|
280
|
-
* @param {boolean} visibility - Visibility.
|
|
281
|
-
*/
|
|
282
|
-
setVisibility(visibility) {
|
|
283
|
-
this.visibility = visibility;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Gets visibilty flag.
|
|
288
|
-
* @public
|
|
289
|
-
* @returns {boolean} -
|
|
290
|
-
*/
|
|
291
|
-
getVisibility() {
|
|
292
|
-
return this.visibility;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Assign render node.
|
|
297
|
-
* @public
|
|
298
|
-
* @param {RenderNode} renderNode - Render node to assign.
|
|
299
|
-
*/
|
|
300
|
-
setRenderNode(renderNode) {
|
|
301
|
-
this._renderNode = renderNode;
|
|
302
|
-
this._createBuffers();
|
|
303
|
-
if (this._src) {
|
|
304
|
-
var img = new Image();
|
|
305
|
-
var that = this;
|
|
306
|
-
img.onload = function () {
|
|
307
|
-
that.texture = renderNode.renderer.handler.createTextureDefault(this);
|
|
308
|
-
};
|
|
309
|
-
img.src = this._src;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Sets shape position.
|
|
315
|
-
* @public
|
|
316
|
-
* @param {Vec3} position - Shape position.
|
|
317
|
-
*/
|
|
318
|
-
setPosition3v(position) {
|
|
319
|
-
this.position.copy(position);
|
|
320
|
-
this._mxTranslation.translateToPosition(position);
|
|
321
|
-
this.refresh();
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* Translate shape position to vector.
|
|
326
|
-
* @public
|
|
327
|
-
* @param {Vec3} vec - Translation vector.
|
|
328
|
-
*/
|
|
329
|
-
translate3v(vec) {
|
|
330
|
-
this.position.addA(vec);
|
|
331
|
-
this._mxTranslation.translate(vec);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Sets shape scale.
|
|
336
|
-
* @param {Vec3} scale - Scale vector.
|
|
337
|
-
*/
|
|
338
|
-
setScale3v(scale) {
|
|
339
|
-
this.scale.copy(scale);
|
|
340
|
-
this._mxScale.setIdentity().scale(scale);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
setScale(scale) {
|
|
344
|
-
this.scale.x = this.scale.y = this.scale.z = scale;
|
|
345
|
-
this._mxScale.setIdentity().scale(this.scale);
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Removes shape from shape handler.
|
|
350
|
-
* @public
|
|
351
|
-
*/
|
|
352
|
-
remove() {
|
|
353
|
-
this._entity = null;
|
|
354
|
-
this._handler && this._handler.remove(this);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Assign picking color.
|
|
359
|
-
* @protected
|
|
360
|
-
* @param {Vec3} color - Picking RGB color.
|
|
361
|
-
*/
|
|
362
|
-
setPickingColor3v(color) {
|
|
363
|
-
//...
|
|
364
|
-
//TODO: check the renderer before
|
|
365
|
-
//...
|
|
366
|
-
this._pickingColor[0] = color.x / 255.0;
|
|
367
|
-
this._pickingColor[1] = color.y / 255.0;
|
|
368
|
-
this._pickingColor[2] = color.z / 255.0;
|
|
369
|
-
this._pickingColor[3] = 1.0;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* Creates buffers.
|
|
374
|
-
* @protected
|
|
375
|
-
*/
|
|
376
|
-
_createBuffers() {
|
|
377
|
-
this._deleteBuffers();
|
|
378
|
-
var r = this._renderNode.renderer;
|
|
379
|
-
this._positionBuffer = r.handler.createArrayBuffer(
|
|
380
|
-
new Float32Array(this._positionData),
|
|
381
|
-
3,
|
|
382
|
-
this._positionData.length / 3
|
|
383
|
-
);
|
|
384
|
-
this._normalBuffer = r.handler.createArrayBuffer(
|
|
385
|
-
new Float32Array(this._normalData),
|
|
386
|
-
3,
|
|
387
|
-
this._normalData.length / 3
|
|
388
|
-
);
|
|
389
|
-
this._indexBuffer = r.handler.createElementArrayBuffer(
|
|
390
|
-
new Uint16Array(this._indexData),
|
|
391
|
-
1,
|
|
392
|
-
this._indexData.length
|
|
393
|
-
);
|
|
394
|
-
this._textureCoordBuffer = r.handler.createArrayBuffer(
|
|
395
|
-
new Float32Array(this._textureCoordData),
|
|
396
|
-
2,
|
|
397
|
-
this._textureCoordData.length / 2
|
|
398
|
-
);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* Update model matrix.
|
|
403
|
-
* @public
|
|
404
|
-
*/
|
|
405
|
-
refresh() {
|
|
406
|
-
this._mxModel = this._mxTranslation.mul(this.orientation.getMat4().mul(this._mxScale));
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* Shape rendering.
|
|
411
|
-
* @public
|
|
412
|
-
*/
|
|
413
|
-
draw() {
|
|
414
|
-
if (this.visibility) {
|
|
415
|
-
let rn = this._renderNode;
|
|
416
|
-
let r = rn.renderer;
|
|
417
|
-
|
|
418
|
-
let sh,
|
|
419
|
-
p,
|
|
420
|
-
gl = r.handler.gl,
|
|
421
|
-
sha,
|
|
422
|
-
shu;
|
|
423
|
-
|
|
424
|
-
if (rn.lightEnabled) {
|
|
425
|
-
sh = r.handler.programs.shape_wl;
|
|
426
|
-
p = sh._program;
|
|
427
|
-
sha = p.attributes;
|
|
428
|
-
shu = p.uniforms;
|
|
429
|
-
|
|
430
|
-
sh.activate();
|
|
431
|
-
|
|
432
|
-
gl.uniform4fv(shu.lightsPositions, rn._lightsTransformedPositions);
|
|
433
|
-
gl.uniform3fv(shu.lightsParamsv, rn._lightsParamsv);
|
|
434
|
-
gl.uniform1fv(shu.lightsParamsf, rn._lightsParamsf);
|
|
435
|
-
gl.uniformMatrix4fv(
|
|
436
|
-
shu.projectionMatrix,
|
|
437
|
-
false,
|
|
438
|
-
r.activeCamera.getProjectionMatrix()
|
|
439
|
-
);
|
|
440
|
-
gl.uniformMatrix4fv(shu.viewMatrix, false, r.activeCamera.getViewMatrix());
|
|
441
|
-
gl.uniformMatrix3fv(shu.normalMatrix, false, r.activeCamera.getNormalMatrix());
|
|
442
|
-
|
|
443
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, this._normalBuffer);
|
|
444
|
-
gl.vertexAttribPointer(
|
|
445
|
-
sha.aVertexNormal,
|
|
446
|
-
this._normalBuffer.itemSize,
|
|
447
|
-
gl.FLOAT,
|
|
448
|
-
false,
|
|
449
|
-
0,
|
|
450
|
-
0
|
|
451
|
-
);
|
|
452
|
-
} else {
|
|
453
|
-
sh = r.handler.programs.shape_nl;
|
|
454
|
-
p = sh._program;
|
|
455
|
-
shu = p.uniforms;
|
|
456
|
-
sha = p.attributes;
|
|
457
|
-
|
|
458
|
-
sh.activate();
|
|
459
|
-
|
|
460
|
-
gl.uniformMatrix4fv(
|
|
461
|
-
shu.projectionViewMatrix,
|
|
462
|
-
false,
|
|
463
|
-
r.activeCamera.getProjectionViewMatrix()
|
|
464
|
-
);
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
gl.uniform4fv(shu.uColor, this.color);
|
|
468
|
-
|
|
469
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, this._positionBuffer);
|
|
470
|
-
gl.vertexAttribPointer(
|
|
471
|
-
sha.aVertexPosition,
|
|
472
|
-
this._positionBuffer.itemSize,
|
|
473
|
-
gl.FLOAT,
|
|
474
|
-
false,
|
|
475
|
-
0,
|
|
476
|
-
0
|
|
477
|
-
);
|
|
478
|
-
gl.uniformMatrix4fv(shu.modelMatrix, false, this._mxModel._m);
|
|
479
|
-
|
|
480
|
-
gl.activeTexture(gl.TEXTURE0);
|
|
481
|
-
gl.bindTexture(gl.TEXTURE_2D, this.texture);
|
|
482
|
-
gl.uniform1i(shu.uSampler, 0);
|
|
483
|
-
|
|
484
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, this._textureCoordBuffer);
|
|
485
|
-
gl.vertexAttribPointer(
|
|
486
|
-
sha.aTextureCoord,
|
|
487
|
-
this._textureCoordBuffer.itemSize,
|
|
488
|
-
gl.FLOAT,
|
|
489
|
-
false,
|
|
490
|
-
0,
|
|
491
|
-
0
|
|
492
|
-
);
|
|
493
|
-
|
|
494
|
-
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
|
495
|
-
gl.drawElements(
|
|
496
|
-
r.handler.gl.TRIANGLES,
|
|
497
|
-
this._indexBuffer.numItems,
|
|
498
|
-
gl.UNSIGNED_SHORT,
|
|
499
|
-
0
|
|
500
|
-
);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
drawPicking() {
|
|
505
|
-
if (this.visibility) {
|
|
506
|
-
let rn = this._renderNode;
|
|
507
|
-
let r = rn.renderer;
|
|
508
|
-
|
|
509
|
-
let sh,
|
|
510
|
-
p,
|
|
511
|
-
gl = r.handler.gl,
|
|
512
|
-
sha,
|
|
513
|
-
shu;
|
|
514
|
-
|
|
515
|
-
sh = r.handler.programs.shape_picking;
|
|
516
|
-
p = sh._program;
|
|
517
|
-
shu = p.uniforms;
|
|
518
|
-
sha = p.attributes;
|
|
519
|
-
|
|
520
|
-
sh.activate();
|
|
521
|
-
|
|
522
|
-
gl.uniformMatrix4fv(
|
|
523
|
-
shu.projectionViewMatrix,
|
|
524
|
-
false,
|
|
525
|
-
r.activeCamera.getProjectionViewMatrix()
|
|
526
|
-
);
|
|
527
|
-
|
|
528
|
-
gl.uniform4fv(shu.uColor, [
|
|
529
|
-
this._pickingColor[0],
|
|
530
|
-
this._pickingColor[1],
|
|
531
|
-
this._pickingColor[2],
|
|
532
|
-
1.0
|
|
533
|
-
]);
|
|
534
|
-
|
|
535
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, this._positionBuffer);
|
|
536
|
-
gl.vertexAttribPointer(
|
|
537
|
-
sha.aVertexPosition,
|
|
538
|
-
this._positionBuffer.itemSize,
|
|
539
|
-
gl.FLOAT,
|
|
540
|
-
false,
|
|
541
|
-
0,
|
|
542
|
-
0
|
|
543
|
-
);
|
|
544
|
-
gl.uniformMatrix4fv(shu.modelMatrix, false, this._mxModel._m);
|
|
545
|
-
|
|
546
|
-
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);
|
|
547
|
-
gl.drawElements(
|
|
548
|
-
r.handler.gl.TRIANGLES,
|
|
549
|
-
this._indexBuffer.numItems,
|
|
550
|
-
gl.UNSIGNED_SHORT,
|
|
551
|
-
0
|
|
552
|
-
);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
export { BaseShape };
|