@openglobus/og 0.22.2 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/css/og.css +137 -1
- package/lib/@openglobus/js/Globe.d.ts +0 -1
- package/lib/@openglobus/js/Object3d.d.ts +20 -10
- package/lib/@openglobus/js/camera/Camera.d.ts +57 -15
- package/lib/@openglobus/js/camera/Frustum.d.ts +3 -0
- package/lib/@openglobus/js/camera/PlanetCamera.d.ts +13 -0
- package/lib/@openglobus/js/control/CameraLock.d.ts +38 -0
- package/lib/@openglobus/js/control/MouseNavigation.d.ts +62 -51
- package/lib/@openglobus/js/control/OldMouseNavigation.d.ts +64 -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 +3 -2
- package/lib/@openglobus/js/entity/Entity.d.ts +282 -19
- package/lib/@openglobus/js/entity/EntityCollection.d.ts +8 -9
- package/lib/@openglobus/js/entity/GeoObject.d.ts +135 -39
- 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/input/MouseHandler.d.ts +1 -0
- 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/Mat3.d.ts +1 -1
- package/lib/@openglobus/js/math/Mat4.d.ts +10 -1
- package/lib/@openglobus/js/math/Plane.d.ts +3 -1
- package/lib/@openglobus/js/math/Quat.d.ts +47 -33
- package/lib/@openglobus/js/math/Ray.d.ts +10 -14
- package/lib/@openglobus/js/math/Vec2.d.ts +22 -0
- 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 +2 -0
- package/lib/@openglobus/js/scene/Planet.d.ts +15 -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 +22 -12
- package/lib/@openglobus/og.css +1 -1
- package/lib/@openglobus/og.esm.js +1 -1
- package/lib/@openglobus/og.esm.js.map +1 -1
- package/lib/@openglobus/og.umd.js +1 -1
- package/lib/@openglobus/og.umd.js.map +1 -1
- package/lib/js/Globe.d.ts +0 -1
- package/lib/js/Globe.js +4 -2
- package/lib/js/Object3d.d.ts +20 -10
- package/lib/js/Object3d.js +124 -48
- package/lib/js/Popup.js +1 -1
- package/lib/js/camera/Camera.d.ts +57 -15
- package/lib/js/camera/Camera.js +109 -29
- package/lib/js/camera/Frustum.d.ts +3 -0
- package/lib/js/camera/Frustum.js +7 -0
- package/lib/js/camera/PlanetCamera.d.ts +13 -0
- package/lib/js/camera/PlanetCamera.js +52 -5
- 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 +38 -8
- package/lib/js/control/KeyboardNavigation.js +9 -9
- package/lib/js/control/MouseNavigation.d.ts +62 -51
- package/lib/js/control/MouseNavigation.js +361 -305
- package/lib/js/control/MouseWheelZoomControl.d.ts +0 -44
- package/lib/js/control/MouseWheelZoomControl.js +270 -181
- package/lib/js/control/OldMouseNavigation.d.ts +64 -0
- package/lib/js/control/OldMouseNavigation.js +368 -0
- package/lib/js/control/ScaleControl.js +11 -5
- package/lib/js/control/SimpleNavigation.d.ts +27 -10
- package/lib/js/control/SimpleNavigation.js +149 -49
- package/lib/js/control/Sun.js +6 -6
- package/lib/js/control/TouchNavigation.js +11 -8
- package/lib/js/control/elevationProfile/ElevationProfileScene.js +6 -5
- 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 +488 -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 +107 -0
- package/lib/js/control/geoObjectEditor/MovePlaneEntity.d.ts +7 -0
- package/lib/js/control/geoObjectEditor/MovePlaneEntity.js +31 -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 +3 -2
- package/lib/js/control/index.js +3 -2
- package/lib/js/control/timeline/TimelineControl.js +2 -0
- package/lib/js/control/visibleExtent/Segment.js +4 -4
- package/lib/js/entity/Entity.d.ts +282 -19
- package/lib/js/entity/Entity.js +497 -62
- package/lib/js/entity/EntityCollection.d.ts +8 -9
- package/lib/js/entity/EntityCollection.js +48 -45
- package/lib/js/entity/GeoObject.d.ts +135 -39
- package/lib/js/entity/GeoObject.js +150 -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 +347 -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/input/MouseHandler.d.ts +1 -0
- package/lib/js/input/MouseHandler.js +12 -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/Mat3.d.ts +1 -1
- package/lib/js/math/Mat3.js +1 -1
- package/lib/js/math/Mat4.d.ts +10 -1
- package/lib/js/math/Mat4.js +17 -1
- package/lib/js/math/Plane.d.ts +3 -1
- package/lib/js/math/Plane.js +11 -1
- package/lib/js/math/Quat.d.ts +47 -33
- package/lib/js/math/Quat.js +92 -90
- package/lib/js/math/Ray.d.ts +10 -14
- package/lib/js/math/Ray.js +56 -33
- package/lib/js/math/Vec2.d.ts +22 -0
- package/lib/js/math/Vec2.js +32 -0
- 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 +267 -266
- package/lib/js/renderer/RendererEvents.d.ts +2 -0
- package/lib/js/renderer/RendererEvents.js +5 -2
- package/lib/js/scene/Planet.d.ts +15 -7
- package/lib/js/scene/Planet.js +133 -90
- package/lib/js/scene/RenderNode.d.ts +10 -25
- package/lib/js/scene/RenderNode.js +70 -58
- package/lib/js/segment/Segment.js +4 -4
- 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/terrain/GlobusTerrain.js +2 -2
- 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 +22 -12
- package/lib/js/webgl/Handler.js +53 -34
- package/lib/js/webgl/Program.js +0 -8
- package/package.json +5 -3
- package/lib/@openglobus/js/control/EarthNavigation.d.ts +0 -50
- package/lib/@openglobus/js/control/MouseWheelZoomControl.d.ts +0 -44
- package/lib/js/control/EarthNavigation.d.ts +0 -50
- package/lib/js/control/EarthNavigation.js +0 -202
package/lib/js/Globe.d.ts
CHANGED
package/lib/js/Globe.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// #StandWithUkraine
|
|
2
2
|
import { CompassButton } from "./control/CompassButton";
|
|
3
3
|
import { EarthCoordinates } from "./control/EarthCoordinates";
|
|
4
|
-
import { EarthNavigation } from "./control/EarthNavigation";
|
|
5
4
|
import { EmptyTerrain } from "./terrain/EmptyTerrain";
|
|
6
5
|
import { Handler } from "./webgl/Handler";
|
|
7
6
|
import { isEmpty } from "./utils/shared";
|
|
@@ -178,7 +177,7 @@ class Globe {
|
|
|
178
177
|
else {
|
|
179
178
|
this.planet.addControls([
|
|
180
179
|
new ZoomControl(),
|
|
181
|
-
|
|
180
|
+
new MouseNavigation(),
|
|
182
181
|
new TouchNavigation(),
|
|
183
182
|
new EarthCoordinates(),
|
|
184
183
|
new ScaleControl(),
|
|
@@ -262,6 +261,9 @@ class Globe {
|
|
|
262
261
|
t.appendChild(this.$inner);
|
|
263
262
|
}
|
|
264
263
|
}
|
|
264
|
+
else {
|
|
265
|
+
console.warn(`Target container not found. Provided target: ${target}`);
|
|
266
|
+
}
|
|
265
267
|
}
|
|
266
268
|
detach() {
|
|
267
269
|
if (this.$target) {
|
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 };
|
package/lib/js/Popup.js
CHANGED
|
@@ -117,7 +117,7 @@ class Popup extends View {
|
|
|
117
117
|
let look = cart.sub(cam.eye), v = Math.sqrt((f + g) * (f + g) - f * f);
|
|
118
118
|
if (v > look.length() && cam.getForward().dot(look.normalize()) > 0.0) {
|
|
119
119
|
this.el.style.display = "block";
|
|
120
|
-
this.setScreen(cam.
|
|
120
|
+
this.setScreen(cam.project3v(cart));
|
|
121
121
|
}
|
|
122
122
|
else {
|
|
123
123
|
this.el.style.display = "none";
|
|
@@ -6,6 +6,7 @@ import { Renderer } from "../renderer/Renderer";
|
|
|
6
6
|
import { Vec2, NumberArray2 } from "../math/Vec2";
|
|
7
7
|
import { Vec3 } from "../math/Vec3";
|
|
8
8
|
import { Sphere } from "../bv/Sphere";
|
|
9
|
+
import { Quat } from "../math/Quat";
|
|
9
10
|
type CameraEvents = ["viewchange", "moveend"];
|
|
10
11
|
export interface ICameraParams {
|
|
11
12
|
eye?: Vec3;
|
|
@@ -80,6 +81,7 @@ declare class Camera {
|
|
|
80
81
|
* @type {Mat4}
|
|
81
82
|
*/
|
|
82
83
|
protected _viewMatrix: Mat4;
|
|
84
|
+
protected _viewMatrixRTE: Mat4;
|
|
83
85
|
/**
|
|
84
86
|
* Camera normal matrix.
|
|
85
87
|
* @protected
|
|
@@ -88,22 +90,28 @@ declare class Camera {
|
|
|
88
90
|
protected _normalMatrix: Mat3;
|
|
89
91
|
/**
|
|
90
92
|
* Camera right vector.
|
|
91
|
-
* @
|
|
93
|
+
* @protected
|
|
92
94
|
* @type {Vec3}
|
|
93
95
|
*/
|
|
94
96
|
_r: Vec3;
|
|
95
97
|
/**
|
|
96
98
|
* Camera up vector.
|
|
97
|
-
* @
|
|
99
|
+
* @protected
|
|
98
100
|
* @type {Vec3}
|
|
99
101
|
*/
|
|
100
102
|
_u: Vec3;
|
|
101
103
|
/**
|
|
102
104
|
* Camera backward vector.
|
|
103
|
-
* @
|
|
105
|
+
* @protected
|
|
104
106
|
* @type {Vec3}
|
|
105
107
|
*/
|
|
106
108
|
_b: Vec3;
|
|
109
|
+
/**
|
|
110
|
+
* Camera forward vector.
|
|
111
|
+
* @protected
|
|
112
|
+
* @type {Vec3}
|
|
113
|
+
*/
|
|
114
|
+
_f: Vec3;
|
|
107
115
|
protected _pr: Vec3;
|
|
108
116
|
protected _pu: Vec3;
|
|
109
117
|
protected _pb: Vec3;
|
|
@@ -116,6 +124,7 @@ declare class Camera {
|
|
|
116
124
|
frustumColors: number[];
|
|
117
125
|
FARTHEST_FRUSTUM_INDEX: number;
|
|
118
126
|
currentFrustumIndex: number;
|
|
127
|
+
frustumColorIndex: number;
|
|
119
128
|
isFirstPass: boolean;
|
|
120
129
|
constructor(renderer: Renderer | null, options?: ICameraParams);
|
|
121
130
|
checkMoveEnd(): void;
|
|
@@ -206,23 +215,40 @@ declare class Camera {
|
|
|
206
215
|
*/
|
|
207
216
|
slide(du: number, dv: number, dn: number): void;
|
|
208
217
|
/**
|
|
209
|
-
* Roll the camera to the angle in
|
|
218
|
+
* Roll the camera to the angle in radians
|
|
219
|
+
* @public
|
|
220
|
+
* @param {number} angle - Delta roll angle in radians
|
|
221
|
+
*/
|
|
222
|
+
setRoll(angle: number): void;
|
|
223
|
+
/**
|
|
224
|
+
* Pitch the camera to the angle in radians
|
|
210
225
|
* @public
|
|
211
|
-
* @param {number} angle - Delta
|
|
226
|
+
* @param {number} angle - Delta pitch angle in radians
|
|
212
227
|
*/
|
|
213
|
-
|
|
228
|
+
setPitch(angle: number): void;
|
|
214
229
|
/**
|
|
215
|
-
*
|
|
230
|
+
* Yaw the camera to the angle in radians
|
|
216
231
|
* @public
|
|
217
|
-
* @param {number} angle - Delta
|
|
232
|
+
* @param {number} angle - Delta yaw angle in radians
|
|
218
233
|
*/
|
|
219
|
-
|
|
234
|
+
setYaw(angle: number): void;
|
|
235
|
+
setPitchYawRoll(pitch: number, yaw: number, roll: number): void;
|
|
236
|
+
getPitch(): number;
|
|
237
|
+
getYaw(): number;
|
|
238
|
+
getRoll(): number;
|
|
220
239
|
/**
|
|
221
|
-
*
|
|
240
|
+
* Returns camera quaternion
|
|
241
|
+
*/
|
|
242
|
+
getRotation(): Quat;
|
|
243
|
+
setRotation(rot: Quat, up?: Vec3, right?: Vec3, back?: Vec3): void;
|
|
244
|
+
rotate(rot: Quat): void;
|
|
245
|
+
/**
|
|
246
|
+
* Returns normal vector direction to the unprojected screen point from camera eye
|
|
222
247
|
* @public
|
|
223
|
-
* @param {
|
|
248
|
+
* @param {Vec2} pos - Screen X coordinate
|
|
249
|
+
* @returns {Vec3} - Direction vector
|
|
224
250
|
*/
|
|
225
|
-
|
|
251
|
+
unproject2v(pos: Vec2): Vec3;
|
|
226
252
|
/**
|
|
227
253
|
* Returns normal vector direction to the unprojected screen point from camera eye
|
|
228
254
|
* @public
|
|
@@ -237,7 +263,16 @@ declare class Camera {
|
|
|
237
263
|
* @param {Vec3} v - Cartesian 3d coordinates
|
|
238
264
|
* @returns {Vec2} - Screen point coordinates
|
|
239
265
|
*/
|
|
240
|
-
|
|
266
|
+
project3v(v: Vec3): Vec2;
|
|
267
|
+
/**
|
|
268
|
+
* Gets projected 3d point to the 2d screen coordinates
|
|
269
|
+
* @public
|
|
270
|
+
* @param {number} x - X coordinate
|
|
271
|
+
* @param {number} y - Y coordinate
|
|
272
|
+
* @param {number} z - Z coordinate
|
|
273
|
+
* @returns {Vec2} - Screen point coordinates
|
|
274
|
+
*/
|
|
275
|
+
project(x: number, y: number, z: number): Vec2;
|
|
241
276
|
/**
|
|
242
277
|
* Rotates camera around center point
|
|
243
278
|
* @public
|
|
@@ -247,7 +282,7 @@ declare class Camera {
|
|
|
247
282
|
* @param {Vec3} [center] - Point that the camera rotates around
|
|
248
283
|
* @param {Vec3} [up] - Camera up vector
|
|
249
284
|
*/
|
|
250
|
-
rotateAround(angle: number, isArc?: boolean, center?: Vec3
|
|
285
|
+
rotateAround(angle: number, isArc?: boolean, center?: Vec3, up?: Vec3): void;
|
|
251
286
|
/**
|
|
252
287
|
* Rotates camera around center point by horizontal.
|
|
253
288
|
* @public
|
|
@@ -257,7 +292,7 @@ declare class Camera {
|
|
|
257
292
|
* @param {Vec3} [center] - Point that the camera rotates around.
|
|
258
293
|
* @param {Vec3} [up] - Camera up vector.
|
|
259
294
|
*/
|
|
260
|
-
rotateHorizontal(angle: number, isArc?: boolean, center?: Vec3
|
|
295
|
+
rotateHorizontal(angle: number, isArc?: boolean, center?: Vec3, up?: Vec3): void;
|
|
261
296
|
/**
|
|
262
297
|
* Rotates camera around center point by vertical.
|
|
263
298
|
* @param {number} angle - Rotation angle in radians.
|
|
@@ -300,6 +335,12 @@ declare class Camera {
|
|
|
300
335
|
* @return {Mat4} - Projection-view matrix.
|
|
301
336
|
*/
|
|
302
337
|
getProjectionViewMatrix(): NumberArray16;
|
|
338
|
+
/**
|
|
339
|
+
* Returns projection and model RTE matrix product.
|
|
340
|
+
* @public
|
|
341
|
+
* @return {Mat4} - Projection-view matrix.
|
|
342
|
+
*/
|
|
343
|
+
getProjectionViewRTEMatrix(): NumberArray16;
|
|
303
344
|
/**
|
|
304
345
|
* Returns inverse projection and model matrix product.
|
|
305
346
|
* @public
|
|
@@ -312,5 +353,6 @@ declare class Camera {
|
|
|
312
353
|
* @returns {Mat4} - Inverse projection-view matrix.
|
|
313
354
|
*/
|
|
314
355
|
getInverseProjectionMatrix(): NumberArray16;
|
|
356
|
+
viewDistance(cartesian: Vec3, distance?: number): void;
|
|
315
357
|
}
|
|
316
358
|
export { Camera };
|