@antv/g 5.0.22-alpha.5 → 5.0.23-alpha.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/dist/index.umd.min.js +30 -0
- package/es/AbstractRenderer.js +8 -1
- package/es/Canvas.d.ts +1 -1
- package/es/Canvas.js +5 -3
- package/es/DisplayObjectPool.js +3 -1
- package/es/camera/Camera.d.ts +105 -66
- package/es/camera/Camera.js +306 -170
- package/es/camera/Landmark.d.ts +18 -25
- package/es/camera/Landmark.js +1 -72
- package/es/canvas-module.js +2 -4
- package/es/components/Cullable.js +3 -1
- package/es/components/Geometry.js +3 -1
- package/es/components/Renderable.js +3 -1
- package/es/components/Sortable.js +3 -1
- package/es/components/Transform.js +3 -1
- package/es/css/LayoutRegistry.js +3 -1
- package/es/css/StyleValueRegistry.d.ts +8 -0
- package/es/css/StyleValueRegistry.js +24 -19
- package/es/css/cssom/CSSColorValue.js +3 -1
- package/es/css/cssom/CSSGradientValue.js +8 -6
- package/es/css/cssom/CSSKeywordValue.js +3 -1
- package/es/css/cssom/CSSMathInvert.js +3 -1
- package/es/css/cssom/CSSMathMax.js +3 -1
- package/es/css/cssom/CSSMathMin.js +3 -1
- package/es/css/cssom/CSSMathNegate.js +3 -1
- package/es/css/cssom/CSSMathProduct.js +3 -1
- package/es/css/cssom/CSSMathSum.js +3 -1
- package/es/css/cssom/CSSMathValue.js +3 -1
- package/es/css/cssom/CSSMathVariadic.js +3 -1
- package/es/css/cssom/CSSNumericValue.js +3 -1
- package/es/css/cssom/CSSNumericValueType.d.ts +1 -1
- package/es/css/cssom/CSSNumericValueType.js +3 -1
- package/es/css/cssom/CSSRGB.js +4 -2
- package/es/css/cssom/CSSStyleValue.d.ts +1 -1
- package/es/css/cssom/CSSStyleValue.js +3 -1
- package/es/css/cssom/CSSTransformComponent.js +3 -1
- package/es/css/cssom/CSSTransformValue.js +3 -1
- package/es/css/cssom/CSSTranslate.js +3 -1
- package/es/css/cssom/CSSUnitValue.js +4 -2
- package/es/css/parser/color.js +2 -2
- package/es/css/parser/dimension.d.ts +1 -1
- package/es/css/parser/dimension.js +2 -3
- package/es/css/parser/numeric.js +1 -1
- package/es/css/parser/path.d.ts +2 -2
- package/es/css/parser/path.js +1 -1
- package/es/css/parser/points.js +1 -1
- package/es/css/parser/transform-origin.js +1 -1
- package/es/css/properties/CSSPropertyAnchor.js +3 -1
- package/es/css/properties/CSSPropertyClipPath.js +3 -1
- package/es/css/properties/CSSPropertyColor.js +3 -1
- package/es/css/properties/CSSPropertyFilter.js +3 -1
- package/es/css/properties/CSSPropertyLengthOrPercentage.js +3 -1
- package/es/css/properties/CSSPropertyLineDash.js +3 -1
- package/es/css/properties/CSSPropertyLocalPosition.js +3 -1
- package/es/css/properties/CSSPropertyOffsetDistance.js +3 -1
- package/es/css/properties/CSSPropertyOffsetPath.js +3 -1
- package/es/css/properties/CSSPropertyOpacity.js +3 -1
- package/es/css/properties/CSSPropertyPath.d.ts +14 -2
- package/es/css/properties/CSSPropertyPath.js +3 -1
- package/es/css/properties/CSSPropertyPoints.js +3 -1
- package/es/css/properties/CSSPropertyShadowBlur.js +3 -1
- package/es/css/properties/CSSPropertyText.d.ts +1 -1
- package/es/css/properties/CSSPropertyText.js +4 -2
- package/es/css/properties/CSSPropertyTextTransform.d.ts +3 -3
- package/es/css/properties/CSSPropertyTextTransform.js +3 -1
- package/es/css/properties/CSSPropertyTransform.js +4 -3
- package/es/css/properties/CSSPropertyTransformOrigin.js +3 -1
- package/es/css/properties/CSSPropertyVisibility.js +3 -1
- package/es/css/properties/CSSPropertyZIndex.js +3 -1
- package/es/display-objects/Circle.js +3 -1
- package/es/display-objects/CustomElement.js +3 -1
- package/es/display-objects/DisplayObject.js +10 -8
- package/es/display-objects/Ellipse.js +3 -1
- package/es/display-objects/Group.js +3 -1
- package/es/display-objects/HTML.js +6 -3
- package/es/display-objects/Image.js +3 -1
- package/es/display-objects/Line.js +3 -1
- package/es/display-objects/Path.d.ts +15 -15
- package/es/display-objects/Path.js +5 -3
- package/es/display-objects/Polygon.d.ts +8 -1
- package/es/display-objects/Polygon.js +3 -1
- package/es/display-objects/Polyline.d.ts +7 -5
- package/es/display-objects/Polyline.js +3 -1
- package/es/display-objects/Rect.js +3 -1
- package/es/display-objects/Text.js +6 -3
- package/es/dom/Animation.js +4 -2
- package/es/dom/AnimationEffectTiming.js +3 -1
- package/es/dom/AnimationEvent.js +3 -1
- package/es/dom/AnimationTimeline.js +3 -1
- package/es/dom/CustomElementRegistry.js +3 -1
- package/es/dom/CustomEvent.js +3 -1
- package/es/dom/Document.js +5 -3
- package/es/dom/Element.js +7 -6
- package/es/dom/EventTarget.js +6 -4
- package/es/dom/FederatedEvent.js +3 -1
- package/es/dom/FederatedMouseEvent.js +3 -1
- package/es/dom/FederatedPointerEvent.js +3 -1
- package/es/dom/FederatedTouchEvent.d.ts +15 -0
- package/es/dom/FederatedTouchEvent.js +19 -0
- package/es/dom/FederatedWheelEvent.js +3 -1
- package/es/dom/KeyframeEffect.js +3 -1
- package/es/dom/KeyframeList.js +1 -1
- package/es/dom/MutationEvent.js +3 -1
- package/es/dom/MutationObserver.js +10 -3
- package/es/dom/MutationRecord.js +3 -1
- package/es/dom/Node.js +4 -2
- package/es/plugins/CullingPlugin.d.ts +0 -1
- package/es/plugins/CullingPlugin.js +6 -9
- package/es/plugins/DirtyCheckPlugin.d.ts +1 -1
- package/es/plugins/DirtyCheckPlugin.js +12 -9
- package/es/plugins/EventPlugin.d.ts +1 -1
- package/es/plugins/EventPlugin.js +166 -149
- package/es/plugins/FrustumCullingStrategy.js +3 -1
- package/es/plugins/PrepareRendererPlugin.d.ts +0 -1
- package/es/plugins/PrepareRendererPlugin.js +18 -17
- package/es/services/EventService.d.ts +8 -0
- package/es/services/EventService.js +279 -23
- package/es/services/OffscreenCanvasCreator.js +3 -1
- package/es/services/RenderingService.d.ts +17 -16
- package/es/services/RenderingService.js +21 -18
- package/es/services/SceneGraphSelector.js +3 -1
- package/es/services/SceneGraphService.js +4 -2
- package/es/services/TextService.js +5 -3
- package/es/services/aabb/CircleUpdater.js +3 -1
- package/es/services/aabb/EllipseUpdater.js +3 -1
- package/es/services/aabb/LineUpdater.js +3 -1
- package/es/services/aabb/PathUpdater.d.ts +3 -3
- package/es/services/aabb/PathUpdater.js +3 -1
- package/es/services/aabb/PolylineUpdater.d.ts +3 -3
- package/es/services/aabb/PolylineUpdater.js +3 -1
- package/es/services/aabb/RectUpdater.js +4 -2
- package/es/services/aabb/TextUpdater.js +3 -1
- package/es/shapes/AABB.js +3 -1
- package/es/shapes/BoundingSphere.js +3 -1
- package/es/shapes/Frustum.js +3 -1
- package/es/shapes/Plane.js +3 -1
- package/es/shapes/Point.js +3 -1
- package/es/shapes/Ray.js +3 -1
- package/es/shapes/Rectangle.js +3 -1
- package/es/types.d.ts +9 -3
- package/es/utils/assert.d.ts +6 -0
- package/es/utils/assert.js +18 -0
- package/es/utils/custom-easing.js +1 -1
- package/es/utils/event.d.ts +18 -16
- package/es/utils/hooks.d.ts +280 -0
- package/es/utils/hooks.js +753 -0
- package/es/utils/index.d.ts +1 -0
- package/es/utils/index.js +2 -1
- package/es/utils/math.d.ts +2 -2
- package/es/utils/math.js +22 -6
- package/es/utils/path.d.ts +1 -1
- package/es/utils/path.js +3 -3
- package/es/utils/string.d.ts +1 -0
- package/es/utils/string.js +8 -0
- package/es/utils/text.js +5 -4
- package/lib/AbstractRenderer.js +8 -1
- package/lib/Canvas.d.ts +1 -1
- package/lib/Canvas.js +5 -3
- package/lib/DisplayObjectPool.js +3 -1
- package/lib/camera/Camera.d.ts +105 -66
- package/lib/camera/Camera.js +313 -178
- package/lib/camera/Landmark.d.ts +18 -25
- package/lib/camera/Landmark.js +1 -75
- package/lib/canvas-module.js +1 -3
- package/lib/components/Cullable.js +4 -2
- package/lib/components/Geometry.js +3 -1
- package/lib/components/Renderable.js +3 -1
- package/lib/components/Sortable.js +3 -1
- package/lib/components/Transform.js +3 -1
- package/lib/css/LayoutRegistry.js +3 -1
- package/lib/css/StyleValueRegistry.d.ts +8 -0
- package/lib/css/StyleValueRegistry.js +27 -20
- package/lib/css/cssom/CSSColorValue.js +3 -1
- package/lib/css/cssom/CSSGradientValue.js +9 -7
- package/lib/css/cssom/CSSKeywordValue.js +3 -1
- package/lib/css/cssom/CSSMathInvert.js +3 -1
- package/lib/css/cssom/CSSMathMax.js +3 -1
- package/lib/css/cssom/CSSMathMin.js +3 -1
- package/lib/css/cssom/CSSMathNegate.js +3 -1
- package/lib/css/cssom/CSSMathOperator.js +1 -1
- package/lib/css/cssom/CSSMathProduct.js +3 -1
- package/lib/css/cssom/CSSMathSum.js +3 -1
- package/lib/css/cssom/CSSMathValue.js +3 -1
- package/lib/css/cssom/CSSMathVariadic.js +4 -2
- package/lib/css/cssom/CSSNumericValue.js +3 -1
- package/lib/css/cssom/CSSNumericValueType.d.ts +1 -1
- package/lib/css/cssom/CSSNumericValueType.js +5 -3
- package/lib/css/cssom/CSSRGB.js +4 -2
- package/lib/css/cssom/CSSStyleValue.d.ts +1 -1
- package/lib/css/cssom/CSSStyleValue.js +4 -2
- package/lib/css/cssom/CSSTransformComponent.js +4 -2
- package/lib/css/cssom/CSSTransformValue.js +3 -1
- package/lib/css/cssom/CSSTranslate.js +3 -1
- package/lib/css/cssom/CSSUnitValue.js +4 -2
- package/lib/css/cssom/types.js +1 -1
- package/lib/css/parser/color.js +8 -8
- package/lib/css/parser/dimension.d.ts +1 -1
- package/lib/css/parser/dimension.js +8 -9
- package/lib/css/parser/numeric.js +6 -6
- package/lib/css/parser/path.d.ts +2 -2
- package/lib/css/parser/path.js +5 -5
- package/lib/css/parser/points.js +2 -2
- package/lib/css/parser/transform-origin.js +2 -2
- package/lib/css/parser/transform.js +2 -2
- package/lib/css/properties/CSSPropertyAnchor.js +3 -1
- package/lib/css/properties/CSSPropertyClipPath.js +3 -1
- package/lib/css/properties/CSSPropertyColor.js +3 -1
- package/lib/css/properties/CSSPropertyFilter.js +3 -1
- package/lib/css/properties/CSSPropertyLengthOrPercentage.js +3 -1
- package/lib/css/properties/CSSPropertyLineDash.js +3 -1
- package/lib/css/properties/CSSPropertyLocalPosition.js +3 -1
- package/lib/css/properties/CSSPropertyOffsetDistance.js +3 -1
- package/lib/css/properties/CSSPropertyOffsetPath.js +3 -1
- package/lib/css/properties/CSSPropertyOpacity.js +3 -1
- package/lib/css/properties/CSSPropertyPath.d.ts +14 -2
- package/lib/css/properties/CSSPropertyPath.js +3 -1
- package/lib/css/properties/CSSPropertyPoints.js +3 -1
- package/lib/css/properties/CSSPropertyShadowBlur.js +3 -1
- package/lib/css/properties/CSSPropertyText.d.ts +1 -1
- package/lib/css/properties/CSSPropertyText.js +4 -2
- package/lib/css/properties/CSSPropertyTextTransform.d.ts +3 -3
- package/lib/css/properties/CSSPropertyTextTransform.js +3 -1
- package/lib/css/properties/CSSPropertyTransform.js +3 -3
- package/lib/css/properties/CSSPropertyTransformOrigin.js +3 -1
- package/lib/css/properties/CSSPropertyVisibility.js +3 -1
- package/lib/css/properties/CSSPropertyZIndex.js +3 -1
- package/lib/display-objects/Circle.js +3 -1
- package/lib/display-objects/CustomElement.js +3 -1
- package/lib/display-objects/DisplayObject.js +13 -12
- package/lib/display-objects/Ellipse.js +3 -1
- package/lib/display-objects/Group.js +3 -1
- package/lib/display-objects/HTML.js +6 -4
- package/lib/display-objects/Image.js +3 -1
- package/lib/display-objects/Line.js +3 -1
- package/lib/display-objects/Path.d.ts +15 -15
- package/lib/display-objects/Path.js +7 -5
- package/lib/display-objects/Polygon.d.ts +8 -1
- package/lib/display-objects/Polygon.js +3 -1
- package/lib/display-objects/Polyline.d.ts +7 -5
- package/lib/display-objects/Polyline.js +3 -1
- package/lib/display-objects/Rect.js +3 -1
- package/lib/display-objects/Text.js +6 -4
- package/lib/dom/Animation.js +4 -2
- package/lib/dom/AnimationEffectTiming.js +3 -1
- package/lib/dom/AnimationEvent.js +3 -1
- package/lib/dom/AnimationTimeline.js +4 -2
- package/lib/dom/CustomElementRegistry.js +3 -1
- package/lib/dom/CustomEvent.js +3 -1
- package/lib/dom/Document.js +5 -3
- package/lib/dom/Element.js +7 -7
- package/lib/dom/EventTarget.js +14 -12
- package/lib/dom/FederatedEvent.js +3 -1
- package/lib/dom/FederatedMouseEvent.js +3 -1
- package/lib/dom/FederatedPointerEvent.js +3 -1
- package/lib/dom/FederatedTouchEvent.d.ts +15 -0
- package/lib/dom/FederatedTouchEvent.js +27 -0
- package/lib/dom/FederatedWheelEvent.js +3 -1
- package/lib/dom/KeyframeEffect.js +4 -2
- package/lib/dom/KeyframeList.js +1 -1
- package/lib/dom/MutationEvent.js +3 -1
- package/lib/dom/MutationObserver.js +11 -4
- package/lib/dom/MutationRecord.js +3 -1
- package/lib/dom/Node.js +4 -2
- package/lib/index.js +1 -1
- package/lib/plugins/CullingPlugin.d.ts +0 -1
- package/lib/plugins/CullingPlugin.js +7 -9
- package/lib/plugins/DirtyCheckPlugin.d.ts +1 -1
- package/lib/plugins/DirtyCheckPlugin.js +13 -9
- package/lib/plugins/EventPlugin.d.ts +1 -1
- package/lib/plugins/EventPlugin.js +175 -157
- package/lib/plugins/FrustumCullingStrategy.js +3 -1
- package/lib/plugins/PrepareRendererPlugin.d.ts +0 -1
- package/lib/plugins/PrepareRendererPlugin.js +17 -15
- package/lib/services/EventService.d.ts +8 -0
- package/lib/services/EventService.js +279 -22
- package/lib/services/OffscreenCanvasCreator.js +3 -1
- package/lib/services/RenderingService.d.ts +17 -16
- package/lib/services/RenderingService.js +22 -19
- package/lib/services/SceneGraphSelector.js +4 -2
- package/lib/services/SceneGraphService.js +8 -6
- package/lib/services/TextService.js +5 -3
- package/lib/services/aabb/CircleUpdater.js +3 -1
- package/lib/services/aabb/EllipseUpdater.js +3 -1
- package/lib/services/aabb/LineUpdater.js +3 -1
- package/lib/services/aabb/PathUpdater.d.ts +3 -3
- package/lib/services/aabb/PathUpdater.js +3 -1
- package/lib/services/aabb/PolylineUpdater.d.ts +3 -3
- package/lib/services/aabb/PolylineUpdater.js +3 -1
- package/lib/services/aabb/RectUpdater.js +6 -4
- package/lib/services/aabb/TextUpdater.js +3 -1
- package/lib/services/aabb/index.js +10 -10
- package/lib/services/aabb/interfaces.js +1 -1
- package/lib/shapes/AABB.js +3 -1
- package/lib/shapes/BoundingSphere.js +3 -1
- package/lib/shapes/Frustum.js +4 -2
- package/lib/shapes/Plane.js +3 -1
- package/lib/shapes/Point.js +3 -1
- package/lib/shapes/Ray.js +3 -1
- package/lib/shapes/Rectangle.js +3 -1
- package/lib/types.d.ts +9 -3
- package/lib/types.js +1 -1
- package/lib/utils/animation.js +3 -2
- package/lib/utils/assert.d.ts +6 -0
- package/lib/utils/assert.js +30 -0
- package/lib/utils/bezier-easing.js +1 -1
- package/lib/utils/custom-easing.js +2 -2
- package/lib/utils/event.d.ts +18 -16
- package/lib/utils/hooks.d.ts +280 -0
- package/lib/utils/hooks.js +759 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +13 -0
- package/lib/utils/math.d.ts +2 -2
- package/lib/utils/math.js +34 -18
- package/lib/utils/path.d.ts +1 -1
- package/lib/utils/path.js +6 -6
- package/lib/utils/string.d.ts +1 -0
- package/lib/utils/string.js +11 -0
- package/lib/utils/text.js +7 -5
- package/package.json +5 -6
package/es/camera/Camera.js
CHANGED
|
@@ -1,44 +1,76 @@
|
|
|
1
1
|
import { __extends } from "tslib";
|
|
2
|
+
import { Syringe } from 'mana-syringe';
|
|
2
3
|
import { EventEmitter } from 'eventemitter3';
|
|
3
4
|
import { mat3, mat4, quat, vec3, vec4 } from 'gl-matrix';
|
|
4
|
-
import { Landmark } from './Landmark';
|
|
5
5
|
import { Frustum } from '../shapes';
|
|
6
6
|
import { createVec3, getAngle, makePerspective } from '../utils/math';
|
|
7
7
|
import { parseEasingFunction } from '../utils/animation';
|
|
8
|
-
import { isNumber, isString
|
|
9
|
-
|
|
8
|
+
import { isNumber, isString } from '../utils'; // import { DisplayObject } from '../display-objects';
|
|
9
|
+
|
|
10
10
|
export var DefaultCamera = Syringe.defineToken('DefaultCamera');
|
|
11
|
-
export var
|
|
11
|
+
export var CameraType;
|
|
12
|
+
|
|
13
|
+
(function (CameraType) {
|
|
14
|
+
/**
|
|
15
|
+
* Performs all the rotational operations with the focal point instead of the camera position.
|
|
16
|
+
* This type of camera is useful in applications(like CAD) where 3D objects are being designed or explored.
|
|
17
|
+
* Camera cannot orbits over the north & south poles.
|
|
18
|
+
* @see http://voxelent.com/tutorial-cameras/
|
|
19
|
+
*
|
|
20
|
+
* In Three.js it's used in OrbitControls.
|
|
21
|
+
* @see https://threejs.org/docs/#examples/zh/controls/OrbitControls
|
|
22
|
+
*/
|
|
23
|
+
CameraType[CameraType["ORBITING"] = 0] = "ORBITING";
|
|
24
|
+
/**
|
|
25
|
+
* It's similar to the ORBITING camera, but it allows the camera to orbit over the north or south poles.
|
|
26
|
+
*
|
|
27
|
+
* In Three.js it's used in OrbitControls.
|
|
28
|
+
* @see https://threejs.org/docs/#examples/en/controls/TrackballControls
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
CameraType[CameraType["EXPLORING"] = 1] = "EXPLORING";
|
|
32
|
+
/**
|
|
33
|
+
* Performs all the rotational operations with the camera position.
|
|
34
|
+
* It's useful in first person shooting games.
|
|
35
|
+
* Camera cannot orbits over the north & south poles.
|
|
36
|
+
*
|
|
37
|
+
* In Three.js it's used in FirstPersonControls.
|
|
38
|
+
* @see https://threejs.org/docs/#examples/en/controls/FirstPersonControls
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
CameraType[CameraType["TRACKING"] = 2] = "TRACKING";
|
|
42
|
+
})(CameraType || (CameraType = {}));
|
|
43
|
+
/**
|
|
44
|
+
* CameraType must be TRACKING
|
|
45
|
+
*/
|
|
12
46
|
|
|
13
|
-
(function (CAMERA_TYPE) {
|
|
14
|
-
CAMERA_TYPE["ORBITING"] = "ORBITING";
|
|
15
|
-
CAMERA_TYPE["EXPLORING"] = "EXPLORING";
|
|
16
|
-
CAMERA_TYPE["TRACKING"] = "TRACKING";
|
|
17
|
-
})(CAMERA_TYPE || (CAMERA_TYPE = {}));
|
|
18
47
|
|
|
19
|
-
export var
|
|
48
|
+
export var CameraTrackingMode;
|
|
20
49
|
|
|
21
|
-
(function (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
})(
|
|
50
|
+
(function (CameraTrackingMode) {
|
|
51
|
+
CameraTrackingMode[CameraTrackingMode["DEFAULT"] = 0] = "DEFAULT";
|
|
52
|
+
CameraTrackingMode[CameraTrackingMode["ROTATIONAL"] = 1] = "ROTATIONAL";
|
|
53
|
+
CameraTrackingMode[CameraTrackingMode["TRANSLATIONAL"] = 2] = "TRANSLATIONAL";
|
|
54
|
+
CameraTrackingMode[CameraTrackingMode["CINEMATIC"] = 3] = "CINEMATIC";
|
|
55
|
+
})(CameraTrackingMode || (CameraTrackingMode = {}));
|
|
27
56
|
|
|
28
|
-
export var
|
|
57
|
+
export var CameraProjectionMode;
|
|
29
58
|
|
|
30
|
-
(function (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
})(
|
|
59
|
+
(function (CameraProjectionMode) {
|
|
60
|
+
CameraProjectionMode[CameraProjectionMode["ORTHOGRAPHIC"] = 0] = "ORTHOGRAPHIC";
|
|
61
|
+
CameraProjectionMode[CameraProjectionMode["PERSPECTIVE"] = 1] = "PERSPECTIVE";
|
|
62
|
+
})(CameraProjectionMode || (CameraProjectionMode = {}));
|
|
34
63
|
|
|
35
64
|
export var CameraEvent = {
|
|
36
65
|
UPDATED: 'updated'
|
|
37
66
|
};
|
|
38
67
|
var DEG_2_RAD = Math.PI / 180;
|
|
39
68
|
var RAD_2_DEG = 180 / Math.PI;
|
|
69
|
+
var MIN_DISTANCE = 0.0002;
|
|
40
70
|
/**
|
|
41
71
|
* 参考「WebGL Insights - 23.Designing Cameras for WebGL Applications」,基于 Responsible Camera 思路设计
|
|
72
|
+
* @see https://github.com/d13g0/nucleo.js/blob/master/source/camera/Camera.js
|
|
73
|
+
*
|
|
42
74
|
* 保存相机参数,定义相机动作:
|
|
43
75
|
* 1. dolly 沿 n 轴移动
|
|
44
76
|
* 2. pan 沿 u v 轴移动
|
|
@@ -46,11 +78,21 @@ var RAD_2_DEG = 180 / Math.PI;
|
|
|
46
78
|
* 4. 移动到 Landmark,具有平滑的动画效果,其间禁止其他用户交互
|
|
47
79
|
*/
|
|
48
80
|
|
|
49
|
-
var Camera =
|
|
81
|
+
var Camera =
|
|
82
|
+
/** @class */
|
|
83
|
+
function (_super) {
|
|
50
84
|
__extends(Camera, _super);
|
|
51
85
|
|
|
52
|
-
function Camera() {
|
|
53
|
-
|
|
86
|
+
function Camera(type, trackingMode) {
|
|
87
|
+
if (type === void 0) {
|
|
88
|
+
type = CameraType.EXPLORING;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (trackingMode === void 0) {
|
|
92
|
+
trackingMode = CameraTrackingMode.DEFAULT;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
var _this = _super.call(this) || this;
|
|
54
96
|
/**
|
|
55
97
|
* 相机矩阵
|
|
56
98
|
*/
|
|
@@ -84,11 +126,11 @@ var Camera = function (_super) {
|
|
|
84
126
|
|
|
85
127
|
_this.focalPoint = vec3.fromValues(0, 0, 0);
|
|
86
128
|
/**
|
|
87
|
-
*
|
|
129
|
+
* 视点到相机位置的向量
|
|
88
130
|
* focalPoint - position
|
|
89
131
|
*/
|
|
90
132
|
|
|
91
|
-
_this.distanceVector = vec3.fromValues(0, 0,
|
|
133
|
+
_this.distanceVector = vec3.fromValues(0, 0, -1);
|
|
92
134
|
/**
|
|
93
135
|
* 相机位置到视点距离
|
|
94
136
|
* length(focalPoint - position)
|
|
@@ -122,9 +164,7 @@ var Camera = function (_super) {
|
|
|
122
164
|
* invert the horizontal coordinate system HCS
|
|
123
165
|
*/
|
|
124
166
|
|
|
125
|
-
_this.rotateWorld = false;
|
|
126
|
-
// interactor: IInteractorService;
|
|
127
|
-
|
|
167
|
+
_this.rotateWorld = false;
|
|
128
168
|
/**
|
|
129
169
|
* 投影矩阵参数
|
|
130
170
|
*/
|
|
@@ -140,11 +180,12 @@ var Camera = function (_super) {
|
|
|
140
180
|
_this.aspect = 1;
|
|
141
181
|
_this.projectionMatrix = mat4.create();
|
|
142
182
|
_this.projectionMatrixInverse = mat4.create();
|
|
143
|
-
_this.jitteredProjectionMatrix = undefined;
|
|
183
|
+
_this.jitteredProjectionMatrix = undefined;
|
|
184
|
+
_this.enableUpdate = true; // private following = undefined;
|
|
144
185
|
|
|
145
|
-
_this.type =
|
|
146
|
-
_this.trackingMode =
|
|
147
|
-
_this.projectionMode =
|
|
186
|
+
_this.type = CameraType.EXPLORING;
|
|
187
|
+
_this.trackingMode = CameraTrackingMode.DEFAULT;
|
|
188
|
+
_this.projectionMode = CameraProjectionMode.PERSPECTIVE;
|
|
148
189
|
/**
|
|
149
190
|
* for culling use
|
|
150
191
|
*/
|
|
@@ -160,18 +201,14 @@ var Camera = function (_super) {
|
|
|
160
201
|
*/
|
|
161
202
|
|
|
162
203
|
_this.orthoMatrix = mat4.create();
|
|
204
|
+
|
|
205
|
+
_this.setType(type, trackingMode);
|
|
206
|
+
|
|
163
207
|
return _this;
|
|
164
208
|
}
|
|
165
209
|
|
|
166
210
|
Camera.prototype.isOrtho = function () {
|
|
167
|
-
return this.projectionMode ===
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
Camera.prototype.clone = function () {
|
|
171
|
-
var camera = new Camera();
|
|
172
|
-
camera.setType(this.type, undefined); // camera.interactor = this.interactor;
|
|
173
|
-
|
|
174
|
-
return camera;
|
|
211
|
+
return this.projectionMode === CameraProjectionMode.ORTHOGRAPHIC;
|
|
175
212
|
};
|
|
176
213
|
|
|
177
214
|
Camera.prototype.getProjectionMode = function () {
|
|
@@ -199,6 +236,10 @@ var Camera = function (_super) {
|
|
|
199
236
|
return this.focalPoint;
|
|
200
237
|
};
|
|
201
238
|
|
|
239
|
+
Camera.prototype.getDollyingStep = function () {
|
|
240
|
+
return this.dollyingStep;
|
|
241
|
+
};
|
|
242
|
+
|
|
202
243
|
Camera.prototype.getNear = function () {
|
|
203
244
|
return this.near;
|
|
204
245
|
};
|
|
@@ -215,10 +256,18 @@ var Camera = function (_super) {
|
|
|
215
256
|
return this.orthoMatrix;
|
|
216
257
|
};
|
|
217
258
|
|
|
259
|
+
Camera.prototype.getView = function () {
|
|
260
|
+
return this.view;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
Camera.prototype.setEnableUpdate = function (enabled) {
|
|
264
|
+
this.enableUpdate = enabled;
|
|
265
|
+
};
|
|
266
|
+
|
|
218
267
|
Camera.prototype.setType = function (type, trackingMode) {
|
|
219
268
|
this.type = type;
|
|
220
269
|
|
|
221
|
-
if (this.type ===
|
|
270
|
+
if (this.type === CameraType.EXPLORING) {
|
|
222
271
|
this.setWorldRotation(true);
|
|
223
272
|
} else {
|
|
224
273
|
this.setWorldRotation(false);
|
|
@@ -226,7 +275,7 @@ var Camera = function (_super) {
|
|
|
226
275
|
|
|
227
276
|
this._getAngles();
|
|
228
277
|
|
|
229
|
-
if (this.type ===
|
|
278
|
+
if (this.type === CameraType.TRACKING && trackingMode !== undefined) {
|
|
230
279
|
this.setTrackingMode(trackingMode);
|
|
231
280
|
}
|
|
232
281
|
|
|
@@ -239,7 +288,7 @@ var Camera = function (_super) {
|
|
|
239
288
|
};
|
|
240
289
|
|
|
241
290
|
Camera.prototype.setTrackingMode = function (trackingMode) {
|
|
242
|
-
if (this.type !==
|
|
291
|
+
if (this.type !== CameraType.TRACKING) {
|
|
243
292
|
throw new Error('Impossible to set a tracking mode if the camera is not of tracking type');
|
|
244
293
|
}
|
|
245
294
|
|
|
@@ -264,6 +313,8 @@ var Camera = function (_super) {
|
|
|
264
313
|
this.rotateWorld = flag;
|
|
265
314
|
|
|
266
315
|
this._getAngles();
|
|
316
|
+
|
|
317
|
+
return this;
|
|
267
318
|
};
|
|
268
319
|
/**
|
|
269
320
|
* 计算 MV 矩阵,为相机矩阵的逆矩阵
|
|
@@ -310,7 +361,7 @@ var Camera = function (_super) {
|
|
|
310
361
|
};
|
|
311
362
|
|
|
312
363
|
Camera.prototype.setNear = function (near) {
|
|
313
|
-
if (this.projectionMode ===
|
|
364
|
+
if (this.projectionMode === CameraProjectionMode.PERSPECTIVE) {
|
|
314
365
|
this.setPerspective(near, this.far, this.fov, this.aspect);
|
|
315
366
|
} else {
|
|
316
367
|
this.setOrthographic(this.left, this.rright, this.top, this.bottom, near, this.far);
|
|
@@ -320,7 +371,7 @@ var Camera = function (_super) {
|
|
|
320
371
|
};
|
|
321
372
|
|
|
322
373
|
Camera.prototype.setFar = function (far) {
|
|
323
|
-
if (this.projectionMode ===
|
|
374
|
+
if (this.projectionMode === CameraProjectionMode.PERSPECTIVE) {
|
|
324
375
|
this.setPerspective(this.near, far, this.fov, this.aspect);
|
|
325
376
|
} else {
|
|
326
377
|
this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, far);
|
|
@@ -356,7 +407,7 @@ var Camera = function (_super) {
|
|
|
356
407
|
this.view.width = width;
|
|
357
408
|
this.view.height = height;
|
|
358
409
|
|
|
359
|
-
if (this.projectionMode ===
|
|
410
|
+
if (this.projectionMode === CameraProjectionMode.PERSPECTIVE) {
|
|
360
411
|
this.setPerspective(this.near, this.far, this.fov, this.aspect);
|
|
361
412
|
} else {
|
|
362
413
|
this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, this.far);
|
|
@@ -370,7 +421,7 @@ var Camera = function (_super) {
|
|
|
370
421
|
this.view.enabled = false;
|
|
371
422
|
}
|
|
372
423
|
|
|
373
|
-
if (this.projectionMode ===
|
|
424
|
+
if (this.projectionMode === CameraProjectionMode.PERSPECTIVE) {
|
|
374
425
|
this.setPerspective(this.near, this.far, this.fov, this.aspect);
|
|
375
426
|
} else {
|
|
376
427
|
this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, this.far);
|
|
@@ -382,9 +433,9 @@ var Camera = function (_super) {
|
|
|
382
433
|
Camera.prototype.setZoom = function (zoom) {
|
|
383
434
|
this.zoom = zoom;
|
|
384
435
|
|
|
385
|
-
if (this.projectionMode ===
|
|
436
|
+
if (this.projectionMode === CameraProjectionMode.ORTHOGRAPHIC) {
|
|
386
437
|
this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, this.far);
|
|
387
|
-
} else if (this.projectionMode ===
|
|
438
|
+
} else if (this.projectionMode === CameraProjectionMode.PERSPECTIVE) {
|
|
388
439
|
this.setPerspective(this.near, this.far, this.fov, this.aspect);
|
|
389
440
|
}
|
|
390
441
|
|
|
@@ -392,7 +443,9 @@ var Camera = function (_super) {
|
|
|
392
443
|
};
|
|
393
444
|
|
|
394
445
|
Camera.prototype.setPerspective = function (near, far, fov, aspect) {
|
|
395
|
-
|
|
446
|
+
var _a;
|
|
447
|
+
|
|
448
|
+
this.projectionMode = CameraProjectionMode.PERSPECTIVE;
|
|
396
449
|
this.fov = fov;
|
|
397
450
|
this.near = near;
|
|
398
451
|
this.far = far;
|
|
@@ -402,7 +455,7 @@ var Camera = function (_super) {
|
|
|
402
455
|
var width = this.aspect * height;
|
|
403
456
|
var left = -0.5 * width;
|
|
404
457
|
|
|
405
|
-
if (this.view
|
|
458
|
+
if ((_a = this.view) === null || _a === void 0 ? void 0 : _a.enabled) {
|
|
406
459
|
var fullWidth = this.view.fullWidth;
|
|
407
460
|
var fullHeight = this.view.fullHeight;
|
|
408
461
|
left += this.view.offsetX * width / fullWidth;
|
|
@@ -420,7 +473,9 @@ var Camera = function (_super) {
|
|
|
420
473
|
};
|
|
421
474
|
|
|
422
475
|
Camera.prototype.setOrthographic = function (l, r, t, b, near, far) {
|
|
423
|
-
|
|
476
|
+
var _a;
|
|
477
|
+
|
|
478
|
+
this.projectionMode = CameraProjectionMode.ORTHOGRAPHIC;
|
|
424
479
|
this.rright = r;
|
|
425
480
|
this.left = l;
|
|
426
481
|
this.top = t;
|
|
@@ -436,7 +491,7 @@ var Camera = function (_super) {
|
|
|
436
491
|
var top = cy + dy;
|
|
437
492
|
var bottom = cy - dy;
|
|
438
493
|
|
|
439
|
-
if (this.view
|
|
494
|
+
if ((_a = this.view) === null || _a === void 0 ? void 0 : _a.enabled) {
|
|
440
495
|
var scaleW = (this.rright - this.left) / this.view.fullWidth / this.zoom;
|
|
441
496
|
var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
|
|
442
497
|
left += scaleW * this.view.offsetX;
|
|
@@ -456,34 +511,56 @@ var Camera = function (_super) {
|
|
|
456
511
|
return this;
|
|
457
512
|
};
|
|
458
513
|
/**
|
|
459
|
-
*
|
|
514
|
+
* Move the camera in world coordinates.
|
|
515
|
+
* It will keep looking at the current focal point.
|
|
516
|
+
*
|
|
517
|
+
* support scalars or vectors.
|
|
518
|
+
* @example
|
|
519
|
+
* setPosition(1, 2, 3);
|
|
520
|
+
* setPosition([1, 2, 3]);
|
|
460
521
|
*/
|
|
461
522
|
|
|
462
523
|
|
|
463
524
|
Camera.prototype.setPosition = function (x, y, z) {
|
|
464
525
|
if (y === void 0) {
|
|
465
|
-
y =
|
|
526
|
+
y = this.position[1];
|
|
466
527
|
}
|
|
467
528
|
|
|
468
529
|
if (z === void 0) {
|
|
469
|
-
z =
|
|
530
|
+
z = this.position[2];
|
|
470
531
|
}
|
|
471
532
|
|
|
472
|
-
|
|
533
|
+
var position = createVec3(x, y, z);
|
|
534
|
+
|
|
535
|
+
this._setPosition(position);
|
|
473
536
|
|
|
474
537
|
this.setFocalPoint(this.focalPoint);
|
|
538
|
+
this.triggerUpdate();
|
|
475
539
|
return this;
|
|
476
540
|
};
|
|
477
541
|
/**
|
|
478
|
-
*
|
|
542
|
+
* Sets the focal point of this camera in world coordinates.
|
|
543
|
+
*
|
|
544
|
+
* support scalars or vectors.
|
|
545
|
+
* @example
|
|
546
|
+
* setFocalPoint(1, 2, 3);
|
|
547
|
+
* setFocalPoint([1, 2, 3]);
|
|
479
548
|
*/
|
|
480
549
|
|
|
481
550
|
|
|
482
551
|
Camera.prototype.setFocalPoint = function (x, y, z) {
|
|
552
|
+
if (y === void 0) {
|
|
553
|
+
y = this.focalPoint[1];
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
if (z === void 0) {
|
|
557
|
+
z = this.focalPoint[2];
|
|
558
|
+
}
|
|
559
|
+
|
|
483
560
|
var up = vec3.fromValues(0, 1, 0);
|
|
484
561
|
this.focalPoint = createVec3(x, y, z);
|
|
485
562
|
|
|
486
|
-
if (this.trackingMode ===
|
|
563
|
+
if (this.trackingMode === CameraTrackingMode.CINEMATIC) {
|
|
487
564
|
var d = vec3.subtract(vec3.create(), this.focalPoint, this.position);
|
|
488
565
|
x = d[0];
|
|
489
566
|
y = d[1];
|
|
@@ -505,22 +582,27 @@ var Camera = function (_super) {
|
|
|
505
582
|
|
|
506
583
|
this._getAngles();
|
|
507
584
|
|
|
585
|
+
this.triggerUpdate();
|
|
508
586
|
return this;
|
|
509
587
|
};
|
|
588
|
+
|
|
589
|
+
Camera.prototype.getDistance = function () {
|
|
590
|
+
return this.distance;
|
|
591
|
+
};
|
|
510
592
|
/**
|
|
511
|
-
*
|
|
593
|
+
* Moves the camera towards/from the focal point.
|
|
512
594
|
*/
|
|
513
595
|
|
|
514
596
|
|
|
515
597
|
Camera.prototype.setDistance = function (d) {
|
|
516
598
|
if (this.distance === d || d < 0) {
|
|
517
|
-
return;
|
|
599
|
+
return this;
|
|
518
600
|
}
|
|
519
601
|
|
|
520
602
|
this.distance = d;
|
|
521
603
|
|
|
522
|
-
if (this.distance <
|
|
523
|
-
this.distance =
|
|
604
|
+
if (this.distance < MIN_DISTANCE) {
|
|
605
|
+
this.distance = MIN_DISTANCE;
|
|
524
606
|
}
|
|
525
607
|
|
|
526
608
|
this.dollyingStep = this.distance / 100;
|
|
@@ -534,6 +616,7 @@ var Camera = function (_super) {
|
|
|
534
616
|
|
|
535
617
|
this._setPosition(pos);
|
|
536
618
|
|
|
619
|
+
this.triggerUpdate();
|
|
537
620
|
return this;
|
|
538
621
|
};
|
|
539
622
|
|
|
@@ -545,37 +628,34 @@ var Camera = function (_super) {
|
|
|
545
628
|
Camera.prototype.setMinDistance = function (d) {
|
|
546
629
|
this.minDistance = d;
|
|
547
630
|
return this;
|
|
548
|
-
};
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
631
|
+
}; // /**
|
|
632
|
+
// * Changes the initial azimuth of the camera
|
|
633
|
+
// */
|
|
634
|
+
// changeAzimuth(az: number) {
|
|
635
|
+
// this.setAzimuth(this.azimuth + az);
|
|
636
|
+
// this.triggerUpdate();
|
|
637
|
+
// return this;
|
|
638
|
+
// }
|
|
639
|
+
// /**
|
|
640
|
+
// * Changes the initial elevation of the camera
|
|
641
|
+
// */
|
|
642
|
+
// changeElevation(el: number) {
|
|
643
|
+
// this.setElevation(this.elevation + el);
|
|
644
|
+
// this.triggerUpdate();
|
|
645
|
+
// return this;
|
|
646
|
+
// }
|
|
647
|
+
// /**
|
|
648
|
+
// * Changes the initial roll of the camera
|
|
649
|
+
// */
|
|
650
|
+
// changeRoll(rl: number) {
|
|
651
|
+
// this.setRoll(this.roll + rl);
|
|
652
|
+
// this.triggerUpdate();
|
|
653
|
+
// return this;
|
|
654
|
+
// }
|
|
571
655
|
|
|
572
|
-
Camera.prototype.changeRoll = function (rl) {
|
|
573
|
-
this.setRoll(this.roll + rl);
|
|
574
|
-
return this;
|
|
575
|
-
};
|
|
576
656
|
/**
|
|
577
657
|
* 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
|
|
578
|
-
*
|
|
658
|
+
* the azimuth in degrees
|
|
579
659
|
*/
|
|
580
660
|
|
|
581
661
|
|
|
@@ -585,12 +665,13 @@ var Camera = function (_super) {
|
|
|
585
665
|
|
|
586
666
|
this._getAxes();
|
|
587
667
|
|
|
588
|
-
if (this.type ===
|
|
668
|
+
if (this.type === CameraType.ORBITING || this.type === CameraType.EXPLORING) {
|
|
589
669
|
this._getPosition();
|
|
590
|
-
} else if (this.type ===
|
|
670
|
+
} else if (this.type === CameraType.TRACKING) {
|
|
591
671
|
this._getFocalPoint();
|
|
592
672
|
}
|
|
593
673
|
|
|
674
|
+
this.triggerUpdate();
|
|
594
675
|
return this;
|
|
595
676
|
};
|
|
596
677
|
|
|
@@ -599,7 +680,6 @@ var Camera = function (_super) {
|
|
|
599
680
|
};
|
|
600
681
|
/**
|
|
601
682
|
* 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
|
|
602
|
-
* @param {Number} el the elevation in degrees
|
|
603
683
|
*/
|
|
604
684
|
|
|
605
685
|
|
|
@@ -609,17 +689,21 @@ var Camera = function (_super) {
|
|
|
609
689
|
|
|
610
690
|
this._getAxes();
|
|
611
691
|
|
|
612
|
-
if (this.type ===
|
|
692
|
+
if (this.type === CameraType.ORBITING || this.type === CameraType.EXPLORING) {
|
|
613
693
|
this._getPosition();
|
|
614
|
-
} else if (this.type ===
|
|
694
|
+
} else if (this.type === CameraType.TRACKING) {
|
|
615
695
|
this._getFocalPoint();
|
|
616
696
|
}
|
|
617
697
|
|
|
698
|
+
this.triggerUpdate();
|
|
618
699
|
return this;
|
|
619
700
|
};
|
|
701
|
+
|
|
702
|
+
Camera.prototype.getElevation = function () {
|
|
703
|
+
return this.elevation;
|
|
704
|
+
};
|
|
620
705
|
/**
|
|
621
706
|
* 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
|
|
622
|
-
* @param {Number} angle the roll angle
|
|
623
707
|
*/
|
|
624
708
|
|
|
625
709
|
|
|
@@ -629,14 +713,19 @@ var Camera = function (_super) {
|
|
|
629
713
|
|
|
630
714
|
this._getAxes();
|
|
631
715
|
|
|
632
|
-
if (this.type ===
|
|
716
|
+
if (this.type === CameraType.ORBITING || this.type === CameraType.EXPLORING) {
|
|
633
717
|
this._getPosition();
|
|
634
|
-
} else if (this.type ===
|
|
718
|
+
} else if (this.type === CameraType.TRACKING) {
|
|
635
719
|
this._getFocalPoint();
|
|
636
720
|
}
|
|
637
721
|
|
|
722
|
+
this.triggerUpdate();
|
|
638
723
|
return this;
|
|
639
724
|
};
|
|
725
|
+
|
|
726
|
+
Camera.prototype.getRoll = function () {
|
|
727
|
+
return this.roll;
|
|
728
|
+
};
|
|
640
729
|
/**
|
|
641
730
|
* Changes the azimuth and elevation with respect to the current camera axes
|
|
642
731
|
* @param {Number} azimuth the relative azimuth
|
|
@@ -653,7 +742,7 @@ var Camera = function (_super) {
|
|
|
653
742
|
this.azimuth += this.relAzimuth;
|
|
654
743
|
this.roll += this.relRoll;
|
|
655
744
|
|
|
656
|
-
if (this.type ===
|
|
745
|
+
if (this.type === CameraType.EXPLORING) {
|
|
657
746
|
var rotX = quat.setAxisAngle(quat.create(), [1, 0, 0], (this.rotateWorld ? 1 : -1) * this.relElevation * DEG_2_RAD);
|
|
658
747
|
var rotY = quat.setAxisAngle(quat.create(), [0, 1, 0], (this.rotateWorld ? 1 : -1) * this.relAzimuth * DEG_2_RAD);
|
|
659
748
|
var rotZ = quat.setAxisAngle(quat.create(), [0, 0, 1], this.relRoll * DEG_2_RAD);
|
|
@@ -665,7 +754,7 @@ var Camera = function (_super) {
|
|
|
665
754
|
mat4.translate(this.matrix, this.matrix, [0, 0, this.distance]);
|
|
666
755
|
} else {
|
|
667
756
|
if (Math.abs(this.elevation) > 90) {
|
|
668
|
-
return;
|
|
757
|
+
return this;
|
|
669
758
|
}
|
|
670
759
|
|
|
671
760
|
this.computeMatrix();
|
|
@@ -673,9 +762,9 @@ var Camera = function (_super) {
|
|
|
673
762
|
|
|
674
763
|
this._getAxes();
|
|
675
764
|
|
|
676
|
-
if (this.type ===
|
|
765
|
+
if (this.type === CameraType.ORBITING || this.type === CameraType.EXPLORING) {
|
|
677
766
|
this._getPosition();
|
|
678
|
-
} else if (this.type ===
|
|
767
|
+
} else if (this.type === CameraType.TRACKING) {
|
|
679
768
|
this._getFocalPoint();
|
|
680
769
|
}
|
|
681
770
|
|
|
@@ -717,10 +806,10 @@ var Camera = function (_super) {
|
|
|
717
806
|
|
|
718
807
|
this._setPosition(pos);
|
|
719
808
|
|
|
720
|
-
if (this.type ===
|
|
809
|
+
if (this.type === CameraType.ORBITING || this.type === CameraType.EXPLORING) {
|
|
721
810
|
// 重新计算视点距离
|
|
722
811
|
this._getDistance();
|
|
723
|
-
} else if (this.type ===
|
|
812
|
+
} else if (this.type === CameraType.TRACKING) {
|
|
724
813
|
// 保持视距,移动视点位置
|
|
725
814
|
vec3.add(this.focalPoint, pos, this.distanceVector);
|
|
726
815
|
}
|
|
@@ -734,33 +823,41 @@ var Camera = function (_super) {
|
|
|
734
823
|
params = {};
|
|
735
824
|
}
|
|
736
825
|
|
|
737
|
-
var
|
|
738
|
-
|
|
826
|
+
var _a = params.position,
|
|
827
|
+
position = _a === void 0 ? this.position : _a,
|
|
828
|
+
_b = params.focalPoint,
|
|
829
|
+
focalPoint = _b === void 0 ? this.focalPoint : _b,
|
|
739
830
|
roll = params.roll,
|
|
740
831
|
zoom = params.zoom;
|
|
741
|
-
var camera =
|
|
742
|
-
camera.
|
|
743
|
-
camera.
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
camera.
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
832
|
+
var camera = new Camera();
|
|
833
|
+
camera.setType(this.type, undefined);
|
|
834
|
+
camera.setPosition(position[0], position[1] || this.position[1], position[2] || this.position[2]);
|
|
835
|
+
camera.setFocalPoint(focalPoint[0], focalPoint[1] || this.focalPoint[1], focalPoint[2] || this.focalPoint[2]);
|
|
836
|
+
camera.setRoll(roll || this.roll);
|
|
837
|
+
camera.setZoom(zoom || this.zoom);
|
|
838
|
+
var landmark = {
|
|
839
|
+
name: name,
|
|
840
|
+
matrix: mat4.clone(camera.matrix),
|
|
841
|
+
right: vec3.clone(camera.right),
|
|
842
|
+
up: vec3.clone(camera.up),
|
|
843
|
+
forward: vec3.clone(camera.forward),
|
|
844
|
+
position: vec3.clone(camera.position),
|
|
845
|
+
focalPoint: vec3.clone(camera.focalPoint),
|
|
846
|
+
distanceVector: vec3.clone(camera.distanceVector),
|
|
847
|
+
distance: camera.distance,
|
|
848
|
+
dollyingStep: camera.dollyingStep,
|
|
849
|
+
azimuth: camera.azimuth,
|
|
850
|
+
elevation: camera.elevation,
|
|
851
|
+
roll: camera.roll,
|
|
852
|
+
relAzimuth: camera.relAzimuth,
|
|
853
|
+
relElevation: camera.relElevation,
|
|
854
|
+
relRoll: camera.relRoll,
|
|
855
|
+
zoom: camera.zoom
|
|
856
|
+
};
|
|
754
857
|
this.landmarks.push(landmark);
|
|
755
858
|
return landmark;
|
|
756
859
|
};
|
|
757
860
|
|
|
758
|
-
Camera.prototype.setLandmark = function (name) {
|
|
759
|
-
var landmark = new Landmark(name, this);
|
|
760
|
-
this.landmarks.push(landmark);
|
|
761
|
-
return this;
|
|
762
|
-
};
|
|
763
|
-
|
|
764
861
|
Camera.prototype.gotoLandmark = function (name, options) {
|
|
765
862
|
var _this = this;
|
|
766
863
|
|
|
@@ -777,38 +874,70 @@ var Camera = function (_super) {
|
|
|
777
874
|
duration: options
|
|
778
875
|
} : options,
|
|
779
876
|
_b = _a.easing,
|
|
780
|
-
easing = _b === void 0 ? '
|
|
877
|
+
easing = _b === void 0 ? 'linear' : _b,
|
|
781
878
|
_c = _a.duration,
|
|
782
|
-
duration_1 = _c === void 0 ?
|
|
879
|
+
duration_1 = _c === void 0 ? 100 : _c,
|
|
880
|
+
_d = _a.easingFunction,
|
|
881
|
+
easingFunction = _d === void 0 ? undefined : _d,
|
|
882
|
+
_e = _a.onfinish,
|
|
883
|
+
onfinish_1 = _e === void 0 ? undefined : _e;
|
|
783
884
|
|
|
784
885
|
var epsilon_1 = 0.01;
|
|
785
886
|
|
|
786
887
|
if (duration_1 === 0) {
|
|
787
|
-
|
|
888
|
+
this.syncFromLandmark(landmark);
|
|
889
|
+
|
|
890
|
+
if (onfinish_1) {
|
|
891
|
+
onfinish_1();
|
|
892
|
+
}
|
|
893
|
+
|
|
788
894
|
return;
|
|
789
|
-
}
|
|
895
|
+
} // cancel ongoing animation
|
|
896
|
+
|
|
790
897
|
|
|
791
898
|
if (this.landmarkAnimationID !== undefined) {
|
|
792
899
|
this.canvas.cancelAnimationFrame(this.landmarkAnimationID);
|
|
793
|
-
}
|
|
794
|
-
// this.interactor.disconnect();
|
|
795
|
-
|
|
900
|
+
}
|
|
796
901
|
|
|
797
|
-
var destPosition_1 = landmark.
|
|
798
|
-
var destFocalPoint_1 = landmark.
|
|
799
|
-
var destZoom_1 = landmark.
|
|
800
|
-
var destRoll_1 = landmark.
|
|
801
|
-
var
|
|
902
|
+
var destPosition_1 = landmark.position;
|
|
903
|
+
var destFocalPoint_1 = landmark.focalPoint;
|
|
904
|
+
var destZoom_1 = landmark.zoom;
|
|
905
|
+
var destRoll_1 = landmark.roll;
|
|
906
|
+
var easingFunc_1 = easingFunction || parseEasingFunction(easing);
|
|
802
907
|
var timeStart_1;
|
|
803
908
|
|
|
909
|
+
var endAnimation_1 = function endAnimation_1() {
|
|
910
|
+
_this.setFocalPoint(destFocalPoint_1);
|
|
911
|
+
|
|
912
|
+
_this.setPosition(destPosition_1);
|
|
913
|
+
|
|
914
|
+
_this.setRoll(destRoll_1);
|
|
915
|
+
|
|
916
|
+
_this.setZoom(destZoom_1);
|
|
917
|
+
|
|
918
|
+
_this.computeMatrix();
|
|
919
|
+
|
|
920
|
+
_this.triggerUpdate();
|
|
921
|
+
|
|
922
|
+
if (onfinish_1) {
|
|
923
|
+
onfinish_1();
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
|
|
804
927
|
var animate_1 = function animate_1(timestamp) {
|
|
805
928
|
if (timeStart_1 === undefined) {
|
|
806
929
|
timeStart_1 = timestamp;
|
|
807
930
|
}
|
|
808
931
|
|
|
809
|
-
var elapsed = timestamp - timeStart_1;
|
|
932
|
+
var elapsed = timestamp - timeStart_1;
|
|
810
933
|
|
|
811
|
-
|
|
934
|
+
if (elapsed > duration_1) {
|
|
935
|
+
endAnimation_1();
|
|
936
|
+
return;
|
|
937
|
+
} // use the same ease function in animation system
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
var t = easingFunc_1(elapsed / duration_1);
|
|
812
941
|
var interFocalPoint = vec3.create();
|
|
813
942
|
var interPosition = vec3.create();
|
|
814
943
|
var interZoom = 1;
|
|
@@ -826,27 +955,17 @@ var Camera = function (_super) {
|
|
|
826
955
|
|
|
827
956
|
_this.setZoom(interZoom);
|
|
828
957
|
|
|
829
|
-
_this.computeMatrix();
|
|
830
|
-
|
|
831
|
-
_this.triggerUpdate();
|
|
832
|
-
|
|
833
958
|
var dist = vec3.dist(interFocalPoint, destFocalPoint_1) + vec3.dist(interPosition, destPosition_1);
|
|
834
959
|
|
|
835
960
|
if (dist <= epsilon_1) {
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
_this.setPosition(destPosition_1);
|
|
839
|
-
|
|
840
|
-
_this.setRoll(destRoll_1);
|
|
841
|
-
|
|
842
|
-
_this.setZoom(destZoom_1);
|
|
843
|
-
|
|
844
|
-
_this.computeMatrix(); // this.interactor.connect();
|
|
845
|
-
|
|
846
|
-
|
|
961
|
+
endAnimation_1();
|
|
847
962
|
return;
|
|
848
963
|
}
|
|
849
964
|
|
|
965
|
+
_this.computeMatrix();
|
|
966
|
+
|
|
967
|
+
_this.triggerUpdate();
|
|
968
|
+
|
|
850
969
|
if (elapsed < duration_1) {
|
|
851
970
|
_this.landmarkAnimationID = _this.canvas.requestAnimationFrame(animate_1);
|
|
852
971
|
}
|
|
@@ -884,17 +1003,17 @@ var Camera = function (_super) {
|
|
|
884
1003
|
var rotZ = quat.setAxisAngle(quat.create(), [0, 0, 1], this.roll * DEG_2_RAD);
|
|
885
1004
|
mat4.identity(this.matrix); // only consider HCS for EXPLORING and ORBITING cameras
|
|
886
1005
|
|
|
887
|
-
var rotX = quat.setAxisAngle(quat.create(), [1, 0, 0], (this.rotateWorld && this.type !==
|
|
888
|
-
var rotY = quat.setAxisAngle(quat.create(), [0, 1, 0], (this.rotateWorld && this.type !==
|
|
1006
|
+
var rotX = quat.setAxisAngle(quat.create(), [1, 0, 0], (this.rotateWorld && this.type !== CameraType.TRACKING || this.type === CameraType.TRACKING ? 1 : -1) * this.elevation * DEG_2_RAD);
|
|
1007
|
+
var rotY = quat.setAxisAngle(quat.create(), [0, 1, 0], (this.rotateWorld && this.type !== CameraType.TRACKING || this.type === CameraType.TRACKING ? 1 : -1) * this.azimuth * DEG_2_RAD);
|
|
889
1008
|
var rotQ = quat.multiply(quat.create(), rotY, rotX);
|
|
890
1009
|
rotQ = quat.multiply(quat.create(), rotQ, rotZ);
|
|
891
1010
|
var rotMatrix = mat4.fromQuat(mat4.create(), rotQ);
|
|
892
1011
|
|
|
893
|
-
if (this.type ===
|
|
1012
|
+
if (this.type === CameraType.ORBITING || this.type === CameraType.EXPLORING) {
|
|
894
1013
|
mat4.translate(this.matrix, this.matrix, this.focalPoint);
|
|
895
1014
|
mat4.multiply(this.matrix, this.matrix, rotMatrix);
|
|
896
1015
|
mat4.translate(this.matrix, this.matrix, [0, 0, this.distance]);
|
|
897
|
-
} else if (this.type ===
|
|
1016
|
+
} else if (this.type === CameraType.TRACKING) {
|
|
898
1017
|
mat4.translate(this.matrix, this.matrix, this.position);
|
|
899
1018
|
mat4.multiply(this.matrix, this.matrix, rotMatrix);
|
|
900
1019
|
}
|
|
@@ -945,7 +1064,7 @@ var Camera = function (_super) {
|
|
|
945
1064
|
return;
|
|
946
1065
|
}
|
|
947
1066
|
|
|
948
|
-
if (this.type ===
|
|
1067
|
+
if (this.type === CameraType.TRACKING) {
|
|
949
1068
|
this.elevation = Math.asin(y / r) * RAD_2_DEG;
|
|
950
1069
|
this.azimuth = Math.atan2(-x, -z) * RAD_2_DEG;
|
|
951
1070
|
} else {
|
|
@@ -991,7 +1110,7 @@ var Camera = function (_super) {
|
|
|
991
1110
|
};
|
|
992
1111
|
|
|
993
1112
|
Camera.prototype._getOrthoMatrix = function () {
|
|
994
|
-
if (this.projectionMode !==
|
|
1113
|
+
if (this.projectionMode !== CameraProjectionMode.ORTHOGRAPHIC) {
|
|
995
1114
|
return;
|
|
996
1115
|
}
|
|
997
1116
|
|
|
@@ -1001,17 +1120,34 @@ var Camera = function (_super) {
|
|
|
1001
1120
|
};
|
|
1002
1121
|
|
|
1003
1122
|
Camera.prototype.triggerUpdate = function () {
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1123
|
+
if (this.enableUpdate) {
|
|
1124
|
+
// update frustum
|
|
1125
|
+
var viewMatrix = this.getViewTransform();
|
|
1126
|
+
var vpMatrix = mat4.multiply(mat4.create(), this.getPerspective(), viewMatrix);
|
|
1127
|
+
this.getFrustum().extractFromVPMatrix(vpMatrix);
|
|
1128
|
+
this.emit(CameraEvent.UPDATED);
|
|
1129
|
+
}
|
|
1009
1130
|
};
|
|
1010
1131
|
|
|
1011
|
-
Camera.
|
|
1012
|
-
|
|
1013
|
-
|
|
1132
|
+
Camera.prototype.syncFromLandmark = function (landmark) {
|
|
1133
|
+
this.matrix = mat4.copy(this.matrix, landmark.matrix);
|
|
1134
|
+
this.right = vec3.copy(this.right, landmark.right);
|
|
1135
|
+
this.up = vec3.copy(this.up, landmark.up);
|
|
1136
|
+
this.forward = vec3.copy(this.forward, landmark.forward);
|
|
1137
|
+
this.position = vec3.copy(this.position, landmark.position);
|
|
1138
|
+
this.focalPoint = vec3.copy(this.focalPoint, landmark.focalPoint);
|
|
1139
|
+
this.distanceVector = vec3.copy(this.distanceVector, landmark.distanceVector);
|
|
1140
|
+
this.azimuth = landmark.azimuth;
|
|
1141
|
+
this.elevation = landmark.elevation;
|
|
1142
|
+
this.roll = landmark.roll;
|
|
1143
|
+
this.relAzimuth = landmark.relAzimuth;
|
|
1144
|
+
this.relElevation = landmark.relElevation;
|
|
1145
|
+
this.relRoll = landmark.relRoll;
|
|
1146
|
+
this.dollyingStep = landmark.dollyingStep;
|
|
1147
|
+
this.distance = landmark.distance;
|
|
1148
|
+
this.zoom = landmark.zoom;
|
|
1014
1149
|
};
|
|
1150
|
+
|
|
1015
1151
|
return Camera;
|
|
1016
1152
|
}(EventEmitter);
|
|
1017
1153
|
|