@openglobus/og 0.22.2 → 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 +63 -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 +1 -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/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 +63 -44
- package/lib/js/renderer/Renderer.js +260 -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 +1 -0
- package/lib/js/webgl/Handler.js +11 -1
- package/lib/js/webgl/Program.js +0 -8
- package/package.json +4 -2
package/lib/js/Object3d.d.ts
CHANGED
|
@@ -8,32 +8,39 @@ interface IObject3dParams {
|
|
|
8
8
|
indices?: number[];
|
|
9
9
|
normals?: number[];
|
|
10
10
|
center?: boolean;
|
|
11
|
-
src?: string;
|
|
12
11
|
color?: number[] | TypedArray | string;
|
|
13
12
|
scale?: number | Vec3;
|
|
13
|
+
ambient?: string | NumberArray3;
|
|
14
|
+
diffuse?: string | NumberArray3;
|
|
15
|
+
specular?: string | NumberArray3;
|
|
16
|
+
shininess?: number;
|
|
17
|
+
colorTexture?: string;
|
|
18
|
+
normalTexture?: string;
|
|
19
|
+
metallicRoughnessTexture?: string;
|
|
14
20
|
}
|
|
15
21
|
declare class Object3d {
|
|
16
22
|
protected _name: string;
|
|
17
23
|
protected _vertices: number[];
|
|
18
24
|
protected _numVertices: number;
|
|
19
25
|
protected _texCoords: number[];
|
|
20
|
-
/**
|
|
21
|
-
* Image src.
|
|
22
|
-
* @protected
|
|
23
|
-
* @type {string}
|
|
24
|
-
*/
|
|
25
|
-
protected _src: string | null;
|
|
26
|
-
protected color: Float32Array;
|
|
27
26
|
protected _indices: number[];
|
|
28
27
|
protected _normals: number[];
|
|
28
|
+
color: Float32Array;
|
|
29
|
+
ambient: Float32Array;
|
|
30
|
+
diffuse: Float32Array;
|
|
31
|
+
specular: Float32Array;
|
|
32
|
+
shininess: number;
|
|
33
|
+
colorTexture: string;
|
|
34
|
+
normalTexture: string;
|
|
35
|
+
metallicRoughnessTexture: string;
|
|
36
|
+
center: Vec3;
|
|
29
37
|
constructor(data?: IObject3dParams);
|
|
38
|
+
static getCenter(verts: number[]): Vec3;
|
|
30
39
|
static centering(verts: number[]): void;
|
|
31
40
|
centering(): this;
|
|
32
41
|
applyMat4(m: Mat4): this;
|
|
33
42
|
scale(s: Vec3): this;
|
|
34
43
|
translate(v: Vec3): this;
|
|
35
|
-
get src(): string | null;
|
|
36
|
-
set src(src: string | null);
|
|
37
44
|
get name(): string;
|
|
38
45
|
get vertices(): number[];
|
|
39
46
|
get normals(): number[];
|
|
@@ -63,8 +70,11 @@ declare class Object3d {
|
|
|
63
70
|
static createFrustum(length?: number, width?: number, height?: number, xOffset?: number, yOffset?: number, zOffset?: number): Object3d;
|
|
64
71
|
static createCylinder(radiusTop?: number, radiusBottom?: number, height?: number, radialSegments?: number, heightSegments?: number, isTop?: boolean, isBottom?: boolean, offsetX?: number, offsetY?: number, offsetZ?: number): Object3d;
|
|
65
72
|
static createCube(length?: number, height?: number, depth?: number, xOffset?: number, yOffset?: number, zOffset?: number): Object3d;
|
|
73
|
+
static createPlane(width?: number, height?: number, xOffset?: number, yOffset?: number, zOffset?: number): Object3d;
|
|
66
74
|
static createArrow(back?: number, height?: number, front?: number): Object3d;
|
|
75
|
+
static readFileObj(objFile: File, mtlFile?: File): Promise<Object3d[]>;
|
|
67
76
|
static loadObj(src: string): Promise<Object3d[]>;
|
|
68
77
|
merge(other: Object3d): Object3d;
|
|
78
|
+
static merge(objects: Object3d[], maxSize?: number): Object3d;
|
|
69
79
|
}
|
|
70
80
|
export { Object3d };
|
package/lib/js/Object3d.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { htmlColorToFloat32Array } from './utils/shared';
|
|
2
2
|
import { Vec3 } from './math/Vec3';
|
|
3
3
|
import { DEGREES_DOUBLE, MAX, MIN, RADIANS_HALF } from './math';
|
|
4
|
-
import {
|
|
4
|
+
import { Obj } from "./utils/objParser";
|
|
5
5
|
function getColor(color) {
|
|
6
6
|
if (color instanceof Array) {
|
|
7
7
|
return new Float32Array(color);
|
|
@@ -11,22 +11,40 @@ function getColor(color) {
|
|
|
11
11
|
}
|
|
12
12
|
return new Float32Array([1.0, 1.0, 1.0, 1.0]);
|
|
13
13
|
}
|
|
14
|
+
function getColor3v(color) {
|
|
15
|
+
let res = new Float32Array([1.0, 1.0, 1.0]);
|
|
16
|
+
if (color instanceof Array) {
|
|
17
|
+
res[0] = color[0];
|
|
18
|
+
res[1] = color[1];
|
|
19
|
+
res[2] = color[2];
|
|
20
|
+
}
|
|
21
|
+
else if (typeof color === 'string') {
|
|
22
|
+
let c = htmlColorToFloat32Array(color);
|
|
23
|
+
res[0] = c[0];
|
|
24
|
+
res[1] = c[1];
|
|
25
|
+
res[2] = c[2];
|
|
26
|
+
}
|
|
27
|
+
return res;
|
|
28
|
+
}
|
|
14
29
|
class Object3d {
|
|
15
30
|
constructor(data = {}) {
|
|
16
31
|
this._name = data.name || "noname";
|
|
17
32
|
this._vertices = data.vertices || [];
|
|
18
33
|
this._numVertices = this._vertices.length / 3;
|
|
19
34
|
this._texCoords = data.texCoords || new Array(2 * this._numVertices);
|
|
20
|
-
if (data.
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* @protected
|
|
26
|
-
* @type {string}
|
|
27
|
-
*/
|
|
28
|
-
this._src = data.src || null;
|
|
35
|
+
// if (data.texCoords) {
|
|
36
|
+
// this._texCoords = data.texCoords;
|
|
37
|
+
// } else {
|
|
38
|
+
// this._texCoords = Array.from({length: 2 * this._numVertices}, (_, i) => 0);
|
|
39
|
+
// }
|
|
29
40
|
this.color = getColor(data.color);
|
|
41
|
+
this.ambient = getColor3v(data.ambient);
|
|
42
|
+
this.diffuse = getColor3v(data.diffuse);
|
|
43
|
+
this.specular = getColor3v(data.specular);
|
|
44
|
+
this.shininess = data.shininess || 100;
|
|
45
|
+
this.colorTexture = data.colorTexture || "";
|
|
46
|
+
this.normalTexture = data.normalTexture || "";
|
|
47
|
+
this.metallicRoughnessTexture = data.metallicRoughnessTexture || "";
|
|
30
48
|
if (data.scale) {
|
|
31
49
|
let s = data.scale;
|
|
32
50
|
let scale;
|
|
@@ -38,19 +56,23 @@ class Object3d {
|
|
|
38
56
|
}
|
|
39
57
|
Object3d.scale(this._vertices, scale);
|
|
40
58
|
}
|
|
59
|
+
if (data.center) {
|
|
60
|
+
Object3d.centering(this._vertices);
|
|
61
|
+
}
|
|
62
|
+
this.center = Object3d.getCenter(this._vertices);
|
|
41
63
|
if (data.indices) {
|
|
42
64
|
this._indices = data.indices;
|
|
43
65
|
this._normals = data.normals || [];
|
|
44
66
|
}
|
|
45
67
|
else {
|
|
46
|
-
this._normals = Object3d.getNormals(this._vertices);
|
|
68
|
+
this._normals = data.normals || Object3d.getNormals(this._vertices);
|
|
47
69
|
this._indices = new Array(this._vertices.length / 3);
|
|
48
70
|
for (let i = 0, len = this._indices.length; i < len; i++) {
|
|
49
71
|
this._indices[i] = i;
|
|
50
72
|
}
|
|
51
73
|
}
|
|
52
74
|
}
|
|
53
|
-
static
|
|
75
|
+
static getCenter(verts) {
|
|
54
76
|
let min_x = MAX, min_y = MAX, min_z = MAX, max_x = MIN, max_y = MIN, max_z = MIN;
|
|
55
77
|
for (let i = 0, len = verts.length; i < len; i += 3) {
|
|
56
78
|
let x = verts[i], y = verts[i + 1], z = verts[i + 2];
|
|
@@ -67,13 +89,14 @@ class Object3d {
|
|
|
67
89
|
if (z > max_z)
|
|
68
90
|
max_z = z;
|
|
69
91
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
92
|
+
return new Vec3(min_x + (max_x - min_x) * 0.5, min_y + (max_y - min_y) * 0.5, min_z + (max_z - min_z) * 0.5);
|
|
93
|
+
}
|
|
94
|
+
static centering(verts) {
|
|
95
|
+
let c = Object3d.getCenter(verts);
|
|
73
96
|
for (let i = 0, len = verts.length; i < len; i += 3) {
|
|
74
|
-
verts[i] -=
|
|
75
|
-
verts[i + 1] -=
|
|
76
|
-
verts[i + 2] -=
|
|
97
|
+
verts[i] -= c.x;
|
|
98
|
+
verts[i + 1] -= c.y;
|
|
99
|
+
verts[i + 2] -= c.z;
|
|
77
100
|
}
|
|
78
101
|
}
|
|
79
102
|
centering() {
|
|
@@ -106,12 +129,6 @@ class Object3d {
|
|
|
106
129
|
}
|
|
107
130
|
return this;
|
|
108
131
|
}
|
|
109
|
-
get src() {
|
|
110
|
-
return this._src;
|
|
111
|
-
}
|
|
112
|
-
set src(src) {
|
|
113
|
-
this._src = src;
|
|
114
|
-
}
|
|
115
132
|
get name() {
|
|
116
133
|
return this._name;
|
|
117
134
|
}
|
|
@@ -390,6 +407,17 @@ class Object3d {
|
|
|
390
407
|
]
|
|
391
408
|
});
|
|
392
409
|
}
|
|
410
|
+
static createPlane(width = 1, height = 1, xOffset = 0, yOffset = 0, zOffset = 0) {
|
|
411
|
+
let sx = width * 0.5, sy = yOffset, sz = height * 0.5;
|
|
412
|
+
return new Object3d({
|
|
413
|
+
vertices: [
|
|
414
|
+
//bottom
|
|
415
|
+
-sx + xOffset, sy, sz + zOffset, sx + xOffset, sy, -sz + zOffset, sx + xOffset, sy, sz + zOffset, -sx + xOffset, sy, sz + zOffset, -sx + xOffset, sy, -sz + zOffset, sx + xOffset, sy, -sz + zOffset,
|
|
416
|
+
//top
|
|
417
|
+
-sx + xOffset, sy, sz + zOffset, sx + xOffset, sy, sz + zOffset, sx + xOffset, sy, -sz + zOffset, -sx + xOffset, sy, sz + zOffset, sx + xOffset, sy, -sz + zOffset, -sx + xOffset, sy, -sz + zOffset
|
|
418
|
+
]
|
|
419
|
+
});
|
|
420
|
+
}
|
|
393
421
|
static createArrow(back = 0.0, height = 2.1, front = -15) {
|
|
394
422
|
return new Object3d({
|
|
395
423
|
vertices: [0, height, 0, 7, 0, 6, 0, 0, front,
|
|
@@ -399,34 +427,82 @@ class Object3d {
|
|
|
399
427
|
-7, 0, 6, 0, 0, front, 0, 0, back, 0, 0, back, 0, 0, front, 7, 0, 6]
|
|
400
428
|
});
|
|
401
429
|
}
|
|
430
|
+
static async readFileObj(objFile, mtlFile) {
|
|
431
|
+
let obj = new Obj();
|
|
432
|
+
const res = await obj.readFile(objFile, mtlFile);
|
|
433
|
+
let materials = res.materials;
|
|
434
|
+
return res.geometries.map((obj) => {
|
|
435
|
+
let mat = materials[obj.material] || {};
|
|
436
|
+
return new Object3d({
|
|
437
|
+
name: obj.object,
|
|
438
|
+
vertices: obj.data.vertices,
|
|
439
|
+
normals: obj.data.normals,
|
|
440
|
+
texCoords: obj.data.texCoords,
|
|
441
|
+
ambient: mat.ambient,
|
|
442
|
+
diffuse: mat.diffuse,
|
|
443
|
+
specular: mat.specular,
|
|
444
|
+
shininess: mat.shininess,
|
|
445
|
+
color: mat.color,
|
|
446
|
+
colorTexture: mat.colorTexture,
|
|
447
|
+
normalTexture: mat.normalTexture,
|
|
448
|
+
metallicRoughnessTexture: mat.metallicRoughnessTexture
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
}
|
|
402
452
|
static async loadObj(src) {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
453
|
+
let obj = new Obj();
|
|
454
|
+
const res = await obj.load(src);
|
|
455
|
+
let materials = res.materials;
|
|
456
|
+
return res.geometries.map((obj) => {
|
|
457
|
+
let mat = materials[obj.material] || {};
|
|
458
|
+
return new Object3d({
|
|
459
|
+
name: obj.object,
|
|
460
|
+
vertices: obj.data.vertices,
|
|
461
|
+
normals: obj.data.normals,
|
|
462
|
+
texCoords: obj.data.texCoords,
|
|
463
|
+
ambient: mat.ambient,
|
|
464
|
+
diffuse: mat.diffuse,
|
|
465
|
+
specular: mat.specular,
|
|
466
|
+
shininess: mat.shininess,
|
|
467
|
+
color: mat.color,
|
|
468
|
+
colorTexture: mat.colorTexture,
|
|
469
|
+
normalTexture: mat.normalTexture,
|
|
470
|
+
metallicRoughnessTexture: mat.metallicRoughnessTexture
|
|
471
|
+
});
|
|
472
|
+
});
|
|
412
473
|
}
|
|
413
474
|
merge(other) {
|
|
414
|
-
const mergedVertices = [...this._vertices, ...other.vertices];
|
|
415
|
-
const mergedNormals = [...this._normals, ...other.normals];
|
|
416
|
-
const mergedTexCoords = [...this._texCoords, ...other.texCoords];
|
|
417
475
|
const offset = this._vertices.length / 3;
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
476
|
+
let temp = this._vertices.length;
|
|
477
|
+
this._vertices.length = temp + other._vertices.length;
|
|
478
|
+
for (let i = 0; i < other._vertices.length; i++) {
|
|
479
|
+
this._vertices[temp + i] = other._vertices[i];
|
|
480
|
+
}
|
|
481
|
+
temp = this._normals.length;
|
|
482
|
+
this._normals.length = temp + other._normals.length;
|
|
483
|
+
for (let i = 0; i < other._normals.length; i++) {
|
|
484
|
+
this._normals[temp + i] = other._normals[i];
|
|
485
|
+
}
|
|
486
|
+
temp = this._texCoords.length;
|
|
487
|
+
this._texCoords.length = temp + other._texCoords.length;
|
|
488
|
+
for (let i = 0; i < other._texCoords.length; i++) {
|
|
489
|
+
this._texCoords[temp + i] = other._texCoords[i];
|
|
490
|
+
}
|
|
491
|
+
temp = this._indices.length;
|
|
492
|
+
this._indices.length = temp + other._indices.length;
|
|
493
|
+
for (let i = 0; i < other._indices.length; i++) {
|
|
494
|
+
this._indices[temp + i] = other._indices[i] + offset;
|
|
495
|
+
}
|
|
496
|
+
this._numVertices = this._vertices.length / 3;
|
|
497
|
+
return this;
|
|
498
|
+
}
|
|
499
|
+
static merge(objects, maxSize) {
|
|
500
|
+
let res = new Object3d();
|
|
501
|
+
let size = maxSize ? maxSize : objects.length;
|
|
502
|
+
for (let i = 0; i < size; i++) {
|
|
503
|
+
res.merge(objects[i]);
|
|
504
|
+
}
|
|
505
|
+
return res;
|
|
430
506
|
}
|
|
431
507
|
}
|
|
432
508
|
export { Object3d };
|
|
@@ -80,6 +80,7 @@ declare class Camera {
|
|
|
80
80
|
* @type {Mat4}
|
|
81
81
|
*/
|
|
82
82
|
protected _viewMatrix: Mat4;
|
|
83
|
+
protected _viewMatrixRTE: Mat4;
|
|
83
84
|
/**
|
|
84
85
|
* Camera normal matrix.
|
|
85
86
|
* @protected
|
|
@@ -116,6 +117,7 @@ declare class Camera {
|
|
|
116
117
|
frustumColors: number[];
|
|
117
118
|
FARTHEST_FRUSTUM_INDEX: number;
|
|
118
119
|
currentFrustumIndex: number;
|
|
120
|
+
frustumColorIndex: number;
|
|
119
121
|
isFirstPass: boolean;
|
|
120
122
|
constructor(renderer: Renderer | null, options?: ICameraParams);
|
|
121
123
|
checkMoveEnd(): void;
|
|
@@ -300,6 +302,12 @@ declare class Camera {
|
|
|
300
302
|
* @return {Mat4} - Projection-view matrix.
|
|
301
303
|
*/
|
|
302
304
|
getProjectionViewMatrix(): NumberArray16;
|
|
305
|
+
/**
|
|
306
|
+
* Returns projection and model RTE matrix product.
|
|
307
|
+
* @public
|
|
308
|
+
* @return {Mat4} - Projection-view matrix.
|
|
309
|
+
*/
|
|
310
|
+
getProjectionViewRTEMatrix(): NumberArray16;
|
|
303
311
|
/**
|
|
304
312
|
* Returns inverse projection and model matrix product.
|
|
305
313
|
* @public
|
|
@@ -312,5 +320,6 @@ declare class Camera {
|
|
|
312
320
|
* @returns {Mat4} - Inverse projection-view matrix.
|
|
313
321
|
*/
|
|
314
322
|
getInverseProjectionMatrix(): NumberArray16;
|
|
323
|
+
viewDistance(cartesian: Vec3, distance?: number): void;
|
|
315
324
|
}
|
|
316
325
|
export { Camera };
|
package/lib/js/camera/Camera.js
CHANGED
|
@@ -6,6 +6,7 @@ import { Mat4 } from "../math/Mat4";
|
|
|
6
6
|
import { Vec2 } from "../math/Vec2";
|
|
7
7
|
import { Vec3 } from "../math/Vec3";
|
|
8
8
|
import { Vec4 } from "../math/Vec4";
|
|
9
|
+
import { Quat } from "../math/Quat";
|
|
9
10
|
const EVENT_NAMES = [
|
|
10
11
|
/**
|
|
11
12
|
* When camera has been updated.
|
|
@@ -44,6 +45,7 @@ class Camera {
|
|
|
44
45
|
this._aspect = options.aspect || 1.0;
|
|
45
46
|
this._viewAngle = options.viewAngle || 47.0;
|
|
46
47
|
this._viewMatrix = new Mat4();
|
|
48
|
+
this._viewMatrixRTE = new Mat4();
|
|
47
49
|
this._normalMatrix = new Mat3();
|
|
48
50
|
this._r = new Vec3(1.0, 0.0, 0.0);
|
|
49
51
|
this._u = new Vec3(0.0, 1.0, 0.0);
|
|
@@ -74,7 +76,7 @@ class Camera {
|
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
else {
|
|
77
|
-
let near = 1
|
|
79
|
+
let near = 0.1, far = 1000.0;
|
|
78
80
|
let fr = new Frustum({
|
|
79
81
|
fov: this._viewAngle,
|
|
80
82
|
aspect: this._aspect,
|
|
@@ -88,6 +90,7 @@ class Camera {
|
|
|
88
90
|
}
|
|
89
91
|
this.FARTHEST_FRUSTUM_INDEX = this.frustums.length - 1;
|
|
90
92
|
this.currentFrustumIndex = 0;
|
|
93
|
+
this.frustumColorIndex = 0;
|
|
91
94
|
this.isFirstPass = false;
|
|
92
95
|
this._projSizeConst = 0;
|
|
93
96
|
this.set(options.eye || new Vec3(0.0, 0.0, 1.0), options.look || new Vec3(), options.up || new Vec3(0.0, 1.0, 0.0));
|
|
@@ -163,10 +166,17 @@ class Camera {
|
|
|
163
166
|
u.z, v.z, n.z, 0.0,
|
|
164
167
|
-eye.dot(u), -eye.dot(v), -eye.dot(n), 1.0
|
|
165
168
|
]);
|
|
169
|
+
this._viewMatrixRTE.set([
|
|
170
|
+
u.x, v.x, n.x, 0.0,
|
|
171
|
+
u.y, v.y, n.y, 0.0,
|
|
172
|
+
u.z, v.z, n.z, 0.0,
|
|
173
|
+
0, 0, 0, 1.0
|
|
174
|
+
]);
|
|
166
175
|
// do not clean up, someday it will be using
|
|
167
176
|
//this._normalMatrix = this._viewMatrix.toMatrix3(); // this._viewMatrix.toInverseMatrix3().transposeTo();
|
|
168
177
|
for (let i = 0, len = this.frustums.length; i < len; i++) {
|
|
169
178
|
this.frustums[i].setViewMatrix(this._viewMatrix);
|
|
179
|
+
this.frustums[i].setProjectionViewRTEMatrix(this._viewMatrixRTE);
|
|
170
180
|
}
|
|
171
181
|
this.events.dispatch(this.events.viewchange, this);
|
|
172
182
|
}
|
|
@@ -409,6 +419,7 @@ class Camera {
|
|
|
409
419
|
}
|
|
410
420
|
setCurrentFrustum(k) {
|
|
411
421
|
this.currentFrustumIndex = k;
|
|
422
|
+
this.frustumColorIndex = (k + 1) * 10.0 / 255.0;
|
|
412
423
|
this.isFirstPass = k === this.FARTHEST_FRUSTUM_INDEX;
|
|
413
424
|
}
|
|
414
425
|
getCurrentFrustum() {
|
|
@@ -441,6 +452,14 @@ class Camera {
|
|
|
441
452
|
getProjectionViewMatrix() {
|
|
442
453
|
return this.frustum.projectionViewMatrix._m;
|
|
443
454
|
}
|
|
455
|
+
/**
|
|
456
|
+
* Returns projection and model RTE matrix product.
|
|
457
|
+
* @public
|
|
458
|
+
* @return {Mat4} - Projection-view matrix.
|
|
459
|
+
*/
|
|
460
|
+
getProjectionViewRTEMatrix() {
|
|
461
|
+
return this.frustum.projectionViewRTEMatrix._m;
|
|
462
|
+
}
|
|
444
463
|
/**
|
|
445
464
|
* Returns inverse projection and model matrix product.
|
|
446
465
|
* @public
|
|
@@ -457,5 +476,12 @@ class Camera {
|
|
|
457
476
|
getInverseProjectionMatrix() {
|
|
458
477
|
return this.frustum.inverseProjectionMatrix._m;
|
|
459
478
|
}
|
|
479
|
+
viewDistance(cartesian, distance = 10000.0) {
|
|
480
|
+
let p0 = this.eye.add(this.getForward().scaleTo(distance));
|
|
481
|
+
let _rot = Quat.getRotationBetweenVectors(p0.getNormal(), cartesian.getNormal());
|
|
482
|
+
let newPos = cartesian.add(this.getBackward().scaleTo(distance));
|
|
483
|
+
this.set(newPos, cartesian);
|
|
484
|
+
this.update();
|
|
485
|
+
}
|
|
460
486
|
}
|
|
461
487
|
export { Camera };
|
|
@@ -35,6 +35,7 @@ declare class Frustum {
|
|
|
35
35
|
* @type {Mat4}
|
|
36
36
|
*/
|
|
37
37
|
projectionViewMatrix: Mat4;
|
|
38
|
+
projectionViewRTEMatrix: Mat4;
|
|
38
39
|
/**
|
|
39
40
|
* Inverse projectionView Matrix.
|
|
40
41
|
* @protected
|
|
@@ -81,6 +82,7 @@ declare class Frustum {
|
|
|
81
82
|
getBackwardPlane(): NumberArray4;
|
|
82
83
|
getForwardPlane(): NumberArray4;
|
|
83
84
|
getProjectionViewMatrix(): NumberArray16;
|
|
85
|
+
getProjectionViewRTEMatrix(): NumberArray16;
|
|
84
86
|
getProjectionMatrix(): NumberArray16;
|
|
85
87
|
getInverseProjectionMatrix(): NumberArray16;
|
|
86
88
|
/**
|
|
@@ -92,6 +94,7 @@ declare class Frustum {
|
|
|
92
94
|
* @param {number} far - Far camera distance.
|
|
93
95
|
*/
|
|
94
96
|
setProjectionMatrix(angle: number, aspect: number, near: number, far: number): void;
|
|
97
|
+
setProjectionViewRTEMatrix(viewRTEMatrix: Mat4): void;
|
|
95
98
|
/**
|
|
96
99
|
* Camera's projection matrix values.
|
|
97
100
|
* @public
|
package/lib/js/camera/Frustum.js
CHANGED
|
@@ -19,6 +19,7 @@ class Frustum {
|
|
|
19
19
|
this.projectionMatrix = new Mat4();
|
|
20
20
|
this.inverseProjectionMatrix = new Mat4();
|
|
21
21
|
this.projectionViewMatrix = new Mat4();
|
|
22
|
+
this.projectionViewRTEMatrix = new Mat4();
|
|
22
23
|
this.inverseProjectionViewMatrix = new Mat4();
|
|
23
24
|
this.left = 0.0;
|
|
24
25
|
this.right = 0.0;
|
|
@@ -50,6 +51,9 @@ class Frustum {
|
|
|
50
51
|
getProjectionViewMatrix() {
|
|
51
52
|
return this.projectionViewMatrix._m;
|
|
52
53
|
}
|
|
54
|
+
getProjectionViewRTEMatrix() {
|
|
55
|
+
return this.projectionViewRTEMatrix._m;
|
|
56
|
+
}
|
|
53
57
|
getProjectionMatrix() {
|
|
54
58
|
return this.projectionMatrix._m;
|
|
55
59
|
}
|
|
@@ -74,6 +78,9 @@ class Frustum {
|
|
|
74
78
|
this.projectionMatrix.setPerspective(this.left, this.right, this.bottom, this.top, near, far);
|
|
75
79
|
this.projectionMatrix.inverseTo(this.inverseProjectionMatrix);
|
|
76
80
|
}
|
|
81
|
+
setProjectionViewRTEMatrix(viewRTEMatrix) {
|
|
82
|
+
this.projectionViewRTEMatrix = this.projectionMatrix.mul(viewRTEMatrix);
|
|
83
|
+
}
|
|
77
84
|
/**
|
|
78
85
|
* Camera's projection matrix values.
|
|
79
86
|
* @public
|
|
@@ -94,18 +94,22 @@ export class Atmosphere extends Control {
|
|
|
94
94
|
width: width,
|
|
95
95
|
height: height,
|
|
96
96
|
useDepth: false,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
targets: [{
|
|
98
|
+
filter: "LINEAR",
|
|
99
|
+
type: "FLOAT",
|
|
100
|
+
internalFormat: "RGBA16F"
|
|
101
|
+
}]
|
|
100
102
|
});
|
|
101
103
|
this._transmittanceBuffer.init();
|
|
102
104
|
this._scatteringBuffer = new Framebuffer(this.renderer.handler, {
|
|
103
105
|
width: width,
|
|
104
106
|
height: height,
|
|
105
107
|
useDepth: false,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
targets: [{
|
|
109
|
+
filter: "LINEAR",
|
|
110
|
+
type: "FLOAT",
|
|
111
|
+
internalFormat: "RGBA16F"
|
|
112
|
+
}]
|
|
109
113
|
});
|
|
110
114
|
this._scatteringBuffer.init();
|
|
111
115
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Control, IControlParams } from "./Control";
|
|
2
|
+
import { LonLat } from "../LonLat";
|
|
3
|
+
import { Vec3 } from "../math/Vec3";
|
|
4
|
+
import { EventsHandler } from "../Events";
|
|
5
|
+
import { Entity } from "../entity/Entity";
|
|
6
|
+
import { IMouseState } from "../renderer/RendererEvents";
|
|
7
|
+
import { Planet } from "../scene/Planet";
|
|
8
|
+
type CameraLockEventsList = ["lockview", "unlockview"];
|
|
9
|
+
interface ICameraLockParams extends IControlParams {
|
|
10
|
+
planet?: Planet | null;
|
|
11
|
+
}
|
|
12
|
+
export declare class CameraLock extends Control {
|
|
13
|
+
events: EventsHandler<CameraLockEventsList>;
|
|
14
|
+
protected _lockDistance: number;
|
|
15
|
+
protected _isFromTheBack: boolean;
|
|
16
|
+
protected _lockEntity: Entity | null;
|
|
17
|
+
protected _viewDir: Vec3;
|
|
18
|
+
constructor(options?: ICameraLockParams);
|
|
19
|
+
onactivate(): void;
|
|
20
|
+
ondeactivate(): void;
|
|
21
|
+
oninit(): void;
|
|
22
|
+
flyCartesian(cartesian: Vec3, dist?: number): void;
|
|
23
|
+
lockView(entity: Entity, fromTheBack?: boolean): void;
|
|
24
|
+
protected _activateNav(): void;
|
|
25
|
+
protected _deactivateNav(): void;
|
|
26
|
+
unlockView(): void;
|
|
27
|
+
private _getCenterDist;
|
|
28
|
+
protected _getDistance(entity: Entity, prevEntity?: Entity | null): number;
|
|
29
|
+
isVisibleDistance(cart: Vec3, C?: number): boolean;
|
|
30
|
+
get lockEntity(): Entity | null;
|
|
31
|
+
flyLonLat(lonLat: LonLat, dist?: number): void;
|
|
32
|
+
protected _activateLockViewEvents(): void;
|
|
33
|
+
protected _deactivateLockViewEvents(): void;
|
|
34
|
+
private _onLockViewDraw;
|
|
35
|
+
protected _onMouseWheel: (e: IMouseState) => void;
|
|
36
|
+
protected _onMouseMove: (ms: IMouseState) => void;
|
|
37
|
+
}
|
|
38
|
+
export {};
|