@antv/g 3.5.0-beta.6 → 5.0.4
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/LICENSE +21 -0
- package/README.md +0 -546
- package/dist/index.umd.js +15 -0
- package/es/AbstractRenderer.d.ts +26 -0
- package/es/AbstractRenderer.js +42 -0
- package/es/Canvas.d.ts +98 -0
- package/es/Canvas.js +406 -0
- package/es/DisplayObjectPool.d.ts +7 -0
- package/es/DisplayObjectPool.js +27 -0
- package/es/camera/Camera.d.ts +279 -0
- package/es/camera/Camera.js +973 -0
- package/es/camera/Landmark.d.ts +28 -0
- package/es/camera/Landmark.js +68 -0
- package/es/camera/index.d.ts +2 -0
- package/es/camera/index.js +2 -0
- package/es/canvas-module.d.ts +1 -0
- package/es/canvas-module.js +33 -0
- package/es/components/Cullable.d.ts +14 -0
- package/es/components/Cullable.js +28 -0
- package/es/components/Geometry.d.ts +12 -0
- package/es/components/Geometry.js +10 -0
- package/es/components/Renderable.d.ts +24 -0
- package/es/components/Renderable.js +18 -0
- package/es/components/Sortable.d.ts +16 -0
- package/es/components/Sortable.js +15 -0
- package/es/components/Transform.d.ts +29 -0
- package/es/components/Transform.js +65 -0
- package/es/components/index.d.ts +5 -0
- package/es/components/index.js +5 -0
- package/es/display-objects/Circle.d.ts +12 -0
- package/es/display-objects/Circle.js +26 -0
- package/es/display-objects/CustomElement.d.ts +21 -0
- package/es/display-objects/CustomElement.js +89 -0
- package/es/display-objects/DisplayObject.d.ts +259 -0
- package/es/display-objects/DisplayObject.js +855 -0
- package/es/display-objects/Ellipse.d.ts +14 -0
- package/es/display-objects/Ellipse.js +27 -0
- package/es/display-objects/Group.d.ts +6 -0
- package/es/display-objects/Group.js +27 -0
- package/es/display-objects/HTML.d.ts +36 -0
- package/es/display-objects/HTML.js +93 -0
- package/es/display-objects/Image.d.ts +16 -0
- package/es/display-objects/Image.js +25 -0
- package/es/display-objects/Line.d.ts +23 -0
- package/es/display-objects/Line.js +56 -0
- package/es/display-objects/Path.d.ts +47 -0
- package/es/display-objects/Path.js +132 -0
- package/es/display-objects/Polygon.d.ts +12 -0
- package/es/display-objects/Polygon.js +25 -0
- package/es/display-objects/Polyline.d.ts +23 -0
- package/es/display-objects/Polyline.js +75 -0
- package/es/display-objects/Rect.d.ts +16 -0
- package/es/display-objects/Rect.js +26 -0
- package/es/display-objects/Text.d.ts +65 -0
- package/es/display-objects/Text.js +61 -0
- package/es/display-objects/index.d.ts +13 -0
- package/es/display-objects/index.js +13 -0
- package/es/dom/Animation.d.ts +132 -0
- package/es/dom/Animation.js +503 -0
- package/es/dom/AnimationEffectTiming.d.ts +58 -0
- package/es/dom/AnimationEffectTiming.js +68 -0
- package/es/dom/AnimationEvent.d.ts +11 -0
- package/es/dom/AnimationEvent.js +34 -0
- package/es/dom/AnimationTimeline.d.ts +37 -0
- package/es/dom/AnimationTimeline.js +218 -0
- package/es/dom/CustomElementRegistry.d.ts +15 -0
- package/es/dom/CustomElementRegistry.js +42 -0
- package/es/dom/CustomEvent.d.ts +16 -0
- package/es/dom/CustomEvent.js +35 -0
- package/es/dom/Document.d.ts +59 -0
- package/es/dom/Document.js +174 -0
- package/es/dom/Element.d.ts +149 -0
- package/es/dom/Element.js +494 -0
- package/es/dom/EventTarget.d.ts +40 -0
- package/es/dom/EventTarget.js +156 -0
- package/es/dom/FederatedEvent.d.ts +146 -0
- package/es/dom/FederatedEvent.js +232 -0
- package/es/dom/FederatedMouseEvent.d.ts +52 -0
- package/es/dom/FederatedMouseEvent.js +124 -0
- package/es/dom/FederatedPointerEvent.d.ts +69 -0
- package/es/dom/FederatedPointerEvent.js +53 -0
- package/es/dom/FederatedWheelEvent.d.ts +20 -0
- package/es/dom/FederatedWheelEvent.js +27 -0
- package/es/dom/KeyframeEffect.d.ts +47 -0
- package/es/dom/KeyframeEffect.js +174 -0
- package/es/dom/KeyframeList.d.ts +2 -0
- package/es/dom/KeyframeList.js +176 -0
- package/es/dom/Node.d.ts +106 -0
- package/es/dom/Node.js +220 -0
- package/es/dom/index.d.ts +17 -0
- package/es/dom/index.js +17 -0
- package/es/dom/interfaces.d.ts +324 -0
- package/es/dom/interfaces.js +32 -0
- package/es/global-module.d.ts +2 -0
- package/es/global-module.js +173 -0
- package/es/index.d.ts +15 -0
- package/es/index.js +18 -0
- package/es/plugins/CullingPlugin.d.ts +19 -0
- package/es/plugins/CullingPlugin.js +79 -0
- package/es/plugins/DirtyCheckPlugin.d.ts +10 -0
- package/es/plugins/DirtyCheckPlugin.js +52 -0
- package/es/plugins/EventPlugin.d.ts +27 -0
- package/es/plugins/EventPlugin.js +288 -0
- package/es/plugins/FrustumCullingStrategy.d.ts +20 -0
- package/es/plugins/FrustumCullingStrategy.js +98 -0
- package/es/plugins/PrepareRendererPlugin.d.ts +6 -0
- package/es/plugins/PrepareRendererPlugin.js +65 -0
- package/es/property-handlers/aabb.d.ts +2 -0
- package/es/property-handlers/aabb.js +132 -0
- package/es/property-handlers/anchor.d.ts +4 -0
- package/es/property-handlers/anchor.js +20 -0
- package/es/property-handlers/clipPath.d.ts +19 -0
- package/es/property-handlers/clipPath.js +36 -0
- package/es/property-handlers/color.d.ts +34 -0
- package/es/property-handlers/color.js +253 -0
- package/es/property-handlers/dimension.d.ts +18 -0
- package/es/property-handlers/dimension.js +123 -0
- package/es/property-handlers/filter.d.ts +8 -0
- package/es/property-handlers/filter.js +43 -0
- package/es/property-handlers/index.d.ts +18 -0
- package/es/property-handlers/index.js +18 -0
- package/es/property-handlers/interfaces.d.ts +20 -0
- package/es/property-handlers/interfaces.js +6 -0
- package/es/property-handlers/lineDash.d.ts +1 -0
- package/es/property-handlers/lineDash.js +8 -0
- package/es/property-handlers/localPosition.d.ts +2 -0
- package/es/property-handlers/localPosition.js +9 -0
- package/es/property-handlers/numeric.d.ts +5 -0
- package/es/property-handlers/numeric.js +34 -0
- package/es/property-handlers/offsetDistance.d.ts +5 -0
- package/es/property-handlers/offsetDistance.js +20 -0
- package/es/property-handlers/offsetPath.d.ts +5 -0
- package/es/property-handlers/offsetPath.js +18 -0
- package/es/property-handlers/origin.d.ts +11 -0
- package/es/property-handlers/origin.js +68 -0
- package/es/property-handlers/path.d.ts +4 -0
- package/es/property-handlers/path.js +200 -0
- package/es/property-handlers/points.d.ts +5 -0
- package/es/property-handlers/points.js +23 -0
- package/es/property-handlers/transform.d.ts +45 -0
- package/es/property-handlers/transform.js +411 -0
- package/es/property-handlers/zIndex.d.ts +2 -0
- package/es/property-handlers/zIndex.js +16 -0
- package/es/services/ContextService.d.ts +12 -0
- package/es/services/ContextService.js +5 -0
- package/es/services/EventService.d.ts +64 -0
- package/es/services/EventService.js +936 -0
- package/es/services/RenderingContext.d.ts +28 -0
- package/es/services/RenderingContext.js +13 -0
- package/es/services/RenderingService.d.ts +52 -0
- package/es/services/RenderingService.js +147 -0
- package/es/services/SceneGraphSelector.d.ts +20 -0
- package/es/services/SceneGraphSelector.js +65 -0
- package/es/services/SceneGraphService.d.ts +150 -0
- package/es/services/SceneGraphService.js +853 -0
- package/es/services/aabb/CircleUpdater.d.ts +10 -0
- package/es/services/aabb/CircleUpdater.js +35 -0
- package/es/services/aabb/EllipseUpdater.d.ts +10 -0
- package/es/services/aabb/EllipseUpdater.js +37 -0
- package/es/services/aabb/LineUpdater.d.ts +10 -0
- package/es/services/aabb/LineUpdater.js +39 -0
- package/es/services/aabb/PathUpdater.d.ts +10 -0
- package/es/services/aabb/PathUpdater.js +172 -0
- package/es/services/aabb/PolylineUpdater.d.ts +10 -0
- package/es/services/aabb/PolylineUpdater.js +48 -0
- package/es/services/aabb/RectUpdater.d.ts +10 -0
- package/es/services/aabb/RectUpdater.js +55 -0
- package/es/services/aabb/TextUpdater.d.ts +13 -0
- package/es/services/aabb/TextUpdater.js +81 -0
- package/es/services/aabb/index.d.ts +8 -0
- package/es/services/aabb/index.js +8 -0
- package/es/services/aabb/interfaces.d.ts +16 -0
- package/es/services/aabb/interfaces.js +2 -0
- package/es/services/index.d.ts +10 -0
- package/es/services/index.js +10 -0
- package/es/services/text/OffscreenCanvasCreator.d.ts +6 -0
- package/es/services/text/OffscreenCanvasCreator.js +47 -0
- package/es/services/text/index.d.ts +35 -0
- package/es/services/text/index.js +355 -0
- package/es/shapes/AABB.d.ts +34 -0
- package/es/shapes/AABB.js +217 -0
- package/es/shapes/BoundingSphere.d.ts +8 -0
- package/es/shapes/BoundingSphere.js +31 -0
- package/es/shapes/Frustum.d.ts +16 -0
- package/es/shapes/Frustum.js +79 -0
- package/es/shapes/Plane.d.ts +14 -0
- package/es/shapes/Plane.js +42 -0
- package/es/shapes/Point.d.ts +11 -0
- package/es/shapes/Point.js +31 -0
- package/es/shapes/Polygon.d.ts +9 -0
- package/es/shapes/Polygon.js +64 -0
- package/es/shapes/Ray.d.ts +24 -0
- package/es/shapes/Ray.js +138 -0
- package/es/shapes/Rect.d.ts +12 -0
- package/es/shapes/Rect.js +24 -0
- package/es/shapes/Rectangle.d.ts +12 -0
- package/es/shapes/Rectangle.js +20 -0
- package/es/shapes/index.d.ts +8 -0
- package/es/shapes/index.js +8 -0
- package/es/types.d.ts +219 -0
- package/es/types.js +17 -0
- package/es/utils/animation.d.ts +15 -0
- package/es/utils/animation.js +251 -0
- package/es/utils/bezier-easing.d.ts +20 -0
- package/es/utils/bezier-easing.js +90 -0
- package/es/utils/canvas.d.ts +5 -0
- package/es/utils/canvas.js +15 -0
- package/es/utils/custom-easing.d.ts +73 -0
- package/es/utils/custom-easing.js +333 -0
- package/es/utils/event.d.ts +11 -0
- package/es/utils/event.js +69 -0
- package/es/utils/index.d.ts +5 -0
- package/es/utils/index.js +5 -0
- package/es/utils/interpolation.d.ts +3 -0
- package/es/utils/interpolation.js +179 -0
- package/es/utils/math.d.ts +24 -0
- package/es/utils/math.js +165 -0
- package/es/utils/path.d.ts +15 -0
- package/es/utils/path.js +330 -0
- package/es/utils/raf.d.ts +3 -0
- package/es/utils/raf.js +16 -0
- package/es/utils/text.d.ts +2 -0
- package/es/utils/text.js +32 -0
- package/lib/AbstractRenderer.d.ts +26 -0
- package/lib/AbstractRenderer.js +49 -0
- package/lib/Canvas.d.ts +98 -0
- package/lib/Canvas.js +427 -0
- package/lib/DisplayObjectPool.d.ts +7 -0
- package/lib/DisplayObjectPool.js +35 -0
- package/lib/camera/Camera.d.ts +279 -0
- package/lib/camera/Camera.js +1046 -0
- package/lib/camera/Landmark.d.ts +28 -0
- package/lib/camera/Landmark.js +75 -0
- package/lib/camera/index.d.ts +2 -0
- package/lib/camera/index.js +31 -0
- package/lib/canvas-module.d.ts +1 -0
- package/lib/canvas-module.js +48 -0
- package/lib/components/Cullable.d.ts +14 -0
- package/lib/components/Cullable.js +36 -0
- package/lib/components/Geometry.d.ts +12 -0
- package/lib/components/Geometry.js +17 -0
- package/lib/components/Renderable.d.ts +24 -0
- package/lib/components/Renderable.js +25 -0
- package/lib/components/Sortable.d.ts +16 -0
- package/lib/components/Sortable.js +22 -0
- package/lib/components/Transform.d.ts +29 -0
- package/lib/components/Transform.js +72 -0
- package/lib/components/index.d.ts +5 -0
- package/lib/components/index.js +70 -0
- package/lib/display-objects/Circle.d.ts +12 -0
- package/lib/display-objects/Circle.js +34 -0
- package/lib/display-objects/CustomElement.d.ts +21 -0
- package/lib/display-objects/CustomElement.js +97 -0
- package/lib/display-objects/DisplayObject.d.ts +259 -0
- package/lib/display-objects/DisplayObject.js +877 -0
- package/lib/display-objects/Ellipse.d.ts +14 -0
- package/lib/display-objects/Ellipse.js +35 -0
- package/lib/display-objects/Group.d.ts +6 -0
- package/lib/display-objects/Group.js +36 -0
- package/lib/display-objects/HTML.d.ts +36 -0
- package/lib/display-objects/HTML.js +105 -0
- package/lib/display-objects/Image.d.ts +16 -0
- package/lib/display-objects/Image.js +33 -0
- package/lib/display-objects/Line.d.ts +23 -0
- package/lib/display-objects/Line.js +68 -0
- package/lib/display-objects/Path.d.ts +47 -0
- package/lib/display-objects/Path.js +143 -0
- package/lib/display-objects/Polygon.d.ts +12 -0
- package/lib/display-objects/Polygon.js +33 -0
- package/lib/display-objects/Polyline.d.ts +23 -0
- package/lib/display-objects/Polyline.js +85 -0
- package/lib/display-objects/Rect.d.ts +16 -0
- package/lib/display-objects/Rect.js +34 -0
- package/lib/display-objects/Text.d.ts +65 -0
- package/lib/display-objects/Text.js +69 -0
- package/lib/display-objects/index.d.ts +13 -0
- package/lib/display-objects/index.js +174 -0
- package/lib/dom/Animation.d.ts +132 -0
- package/lib/dom/Animation.js +511 -0
- package/lib/dom/AnimationEffectTiming.d.ts +58 -0
- package/lib/dom/AnimationEffectTiming.js +75 -0
- package/lib/dom/AnimationEvent.d.ts +11 -0
- package/lib/dom/AnimationEvent.js +42 -0
- package/lib/dom/AnimationTimeline.d.ts +37 -0
- package/lib/dom/AnimationTimeline.js +230 -0
- package/lib/dom/CustomElementRegistry.d.ts +15 -0
- package/lib/dom/CustomElementRegistry.js +50 -0
- package/lib/dom/CustomEvent.d.ts +16 -0
- package/lib/dom/CustomEvent.js +42 -0
- package/lib/dom/Document.d.ts +59 -0
- package/lib/dom/Document.js +184 -0
- package/lib/dom/Element.d.ts +149 -0
- package/lib/dom/Element.js +508 -0
- package/lib/dom/EventTarget.d.ts +40 -0
- package/lib/dom/EventTarget.js +170 -0
- package/lib/dom/FederatedEvent.d.ts +146 -0
- package/lib/dom/FederatedEvent.js +239 -0
- package/lib/dom/FederatedMouseEvent.d.ts +52 -0
- package/lib/dom/FederatedMouseEvent.js +133 -0
- package/lib/dom/FederatedPointerEvent.d.ts +69 -0
- package/lib/dom/FederatedPointerEvent.js +61 -0
- package/lib/dom/FederatedWheelEvent.d.ts +20 -0
- package/lib/dom/FederatedWheelEvent.js +35 -0
- package/lib/dom/KeyframeEffect.d.ts +47 -0
- package/lib/dom/KeyframeEffect.js +192 -0
- package/lib/dom/KeyframeList.d.ts +2 -0
- package/lib/dom/KeyframeList.js +183 -0
- package/lib/dom/Node.d.ts +106 -0
- package/lib/dom/Node.js +228 -0
- package/lib/dom/index.d.ts +17 -0
- package/lib/dom/index.js +226 -0
- package/lib/dom/interfaces.d.ts +324 -0
- package/lib/dom/interfaces.js +40 -0
- package/lib/global-module.d.ts +2 -0
- package/lib/global-module.js +192 -0
- package/lib/index.d.ts +14 -12
- package/lib/index.js +203 -26
- package/lib/plugins/CullingPlugin.d.ts +19 -0
- package/lib/plugins/CullingPlugin.js +90 -0
- package/lib/plugins/DirtyCheckPlugin.d.ts +10 -0
- package/lib/plugins/DirtyCheckPlugin.js +60 -0
- package/lib/plugins/EventPlugin.d.ts +27 -0
- package/lib/plugins/EventPlugin.js +297 -0
- package/lib/plugins/FrustumCullingStrategy.d.ts +20 -0
- package/lib/plugins/FrustumCullingStrategy.js +110 -0
- package/lib/plugins/PrepareRendererPlugin.d.ts +6 -0
- package/lib/plugins/PrepareRendererPlugin.js +73 -0
- package/lib/property-handlers/aabb.d.ts +2 -0
- package/lib/property-handlers/aabb.js +148 -0
- package/lib/property-handlers/anchor.d.ts +4 -0
- package/lib/property-handlers/anchor.js +32 -0
- package/lib/property-handlers/clipPath.d.ts +19 -0
- package/lib/property-handlers/clipPath.js +43 -0
- package/lib/property-handlers/color.d.ts +34 -0
- package/lib/property-handlers/color.js +274 -0
- package/lib/property-handlers/dimension.d.ts +18 -0
- package/lib/property-handlers/dimension.js +144 -0
- package/lib/property-handlers/filter.d.ts +8 -0
- package/lib/property-handlers/filter.js +56 -0
- package/lib/property-handlers/index.d.ts +18 -0
- package/lib/property-handlers/index.js +226 -0
- package/lib/property-handlers/interfaces.d.ts +20 -0
- package/lib/property-handlers/interfaces.js +18 -0
- package/lib/property-handlers/lineDash.d.ts +1 -0
- package/lib/property-handlers/lineDash.js +15 -0
- package/lib/property-handlers/localPosition.d.ts +2 -0
- package/lib/property-handlers/localPosition.js +16 -0
- package/lib/property-handlers/numeric.d.ts +5 -0
- package/lib/property-handlers/numeric.js +50 -0
- package/lib/property-handlers/offsetDistance.d.ts +5 -0
- package/lib/property-handlers/offsetDistance.js +27 -0
- package/lib/property-handlers/offsetPath.d.ts +5 -0
- package/lib/property-handlers/offsetPath.js +25 -0
- package/lib/property-handlers/origin.d.ts +11 -0
- package/lib/property-handlers/origin.js +79 -0
- package/lib/property-handlers/path.d.ts +4 -0
- package/lib/property-handlers/path.js +214 -0
- package/lib/property-handlers/points.d.ts +5 -0
- package/lib/property-handlers/points.js +33 -0
- package/lib/property-handlers/transform.d.ts +45 -0
- package/lib/property-handlers/transform.js +426 -0
- package/lib/property-handlers/zIndex.d.ts +2 -0
- package/lib/property-handlers/zIndex.js +23 -0
- package/lib/services/ContextService.d.ts +12 -0
- package/lib/services/ContextService.js +15 -0
- package/lib/services/EventService.d.ts +64 -0
- package/lib/services/EventService.js +960 -0
- package/lib/services/RenderingContext.d.ts +28 -0
- package/lib/services/RenderingContext.js +22 -0
- package/lib/services/RenderingService.d.ts +52 -0
- package/lib/services/RenderingService.js +159 -0
- package/lib/services/SceneGraphSelector.d.ts +20 -0
- package/lib/services/SceneGraphSelector.js +77 -0
- package/lib/services/SceneGraphService.d.ts +150 -0
- package/lib/services/SceneGraphService.js +902 -0
- package/lib/services/aabb/CircleUpdater.d.ts +10 -0
- package/lib/services/aabb/CircleUpdater.js +45 -0
- package/lib/services/aabb/EllipseUpdater.d.ts +10 -0
- package/lib/services/aabb/EllipseUpdater.js +47 -0
- package/lib/services/aabb/LineUpdater.d.ts +10 -0
- package/lib/services/aabb/LineUpdater.js +49 -0
- package/lib/services/aabb/PathUpdater.d.ts +10 -0
- package/lib/services/aabb/PathUpdater.js +183 -0
- package/lib/services/aabb/PolylineUpdater.d.ts +10 -0
- package/lib/services/aabb/PolylineUpdater.js +58 -0
- package/lib/services/aabb/RectUpdater.d.ts +10 -0
- package/lib/services/aabb/RectUpdater.js +66 -0
- package/lib/services/aabb/TextUpdater.d.ts +13 -0
- package/lib/services/aabb/TextUpdater.js +93 -0
- package/lib/services/aabb/index.d.ts +8 -0
- package/lib/services/aabb/index.js +84 -0
- package/lib/services/aabb/interfaces.d.ts +16 -0
- package/lib/services/aabb/interfaces.js +10 -0
- package/lib/services/index.d.ts +10 -0
- package/lib/services/index.js +122 -0
- package/lib/services/text/OffscreenCanvasCreator.d.ts +6 -0
- package/lib/services/text/OffscreenCanvasCreator.js +55 -0
- package/lib/services/text/index.d.ts +35 -0
- package/lib/services/text/index.js +364 -0
- package/lib/shapes/AABB.d.ts +34 -0
- package/lib/shapes/AABB.js +235 -0
- package/lib/shapes/BoundingSphere.d.ts +8 -0
- package/lib/shapes/BoundingSphere.js +41 -0
- package/lib/shapes/Frustum.d.ts +16 -0
- package/lib/shapes/Frustum.js +96 -0
- package/lib/shapes/Plane.d.ts +14 -0
- package/lib/shapes/Plane.js +51 -0
- package/lib/shapes/Point.d.ts +11 -0
- package/lib/shapes/Point.js +38 -0
- package/lib/shapes/Polygon.d.ts +9 -0
- package/lib/shapes/Polygon.js +71 -0
- package/lib/shapes/Ray.d.ts +24 -0
- package/lib/shapes/Ray.js +169 -0
- package/lib/shapes/Rect.d.ts +12 -0
- package/lib/shapes/Rect.js +31 -0
- package/lib/shapes/Rectangle.d.ts +12 -0
- package/lib/shapes/Rectangle.js +27 -0
- package/lib/shapes/index.d.ts +8 -13
- package/lib/shapes/index.js +108 -28
- package/lib/types.d.ts +219 -0
- package/lib/types.js +25 -0
- package/lib/utils/animation.d.ts +15 -0
- package/lib/utils/animation.js +275 -0
- package/lib/utils/bezier-easing.d.ts +20 -0
- package/lib/utils/bezier-easing.js +128 -0
- package/lib/utils/canvas.d.ts +5 -0
- package/lib/utils/canvas.js +21 -0
- package/lib/utils/custom-easing.d.ts +73 -0
- package/lib/utils/custom-easing.js +416 -0
- package/lib/utils/event.d.ts +11 -0
- package/lib/utils/event.js +88 -0
- package/lib/utils/index.d.ts +5 -0
- package/lib/utils/index.js +70 -0
- package/lib/utils/interpolation.d.ts +3 -0
- package/lib/utils/interpolation.js +194 -0
- package/lib/utils/math.d.ts +24 -0
- package/lib/utils/math.js +192 -0
- package/lib/utils/path.d.ts +15 -0
- package/lib/utils/path.js +356 -0
- package/lib/utils/raf.d.ts +3 -0
- package/lib/utils/raf.js +22 -0
- package/lib/utils/text.d.ts +2 -0
- package/lib/utils/text.js +41 -0
- package/package.json +35 -92
- package/dist/g.min.js +0 -17
- package/dist/g.min.js.map +0 -1
- package/esm/canvas.d.ts +0 -46
- package/esm/canvas.js +0 -383
- package/esm/canvas.js.map +0 -1
- package/esm/core/attribute.d.ts +0 -49
- package/esm/core/attribute.js +0 -277
- package/esm/core/attribute.js.map +0 -1
- package/esm/core/base.d.ts +0 -32
- package/esm/core/base.js +0 -190
- package/esm/core/base.js.map +0 -1
- package/esm/core/bbox.d.ts +0 -22
- package/esm/core/bbox.js +0 -34
- package/esm/core/bbox.js.map +0 -1
- package/esm/core/element.d.ts +0 -19
- package/esm/core/element.js +0 -203
- package/esm/core/element.js.map +0 -1
- package/esm/core/group.d.ts +0 -72
- package/esm/core/group.js +0 -437
- package/esm/core/group.js.map +0 -1
- package/esm/core/shape.d.ts +0 -35
- package/esm/core/shape.js +0 -158
- package/esm/core/shape.js.map +0 -1
- package/esm/core/timeline.d.ts +0 -15
- package/esm/core/timeline.js +0 -179
- package/esm/core/timeline.js.map +0 -1
- package/esm/event.d.ts +0 -25
- package/esm/event.js +0 -37
- package/esm/event.js.map +0 -1
- package/esm/index.d.ts +0 -13
- package/esm/index.js +0 -15
- package/esm/index.js.map +0 -1
- package/esm/interface.d.ts +0 -18
- package/esm/interface.js +0 -1
- package/esm/interface.js.map +0 -1
- package/esm/renderers/canvas/index.d.ts +0 -1
- package/esm/renderers/canvas/index.js +0 -2
- package/esm/renderers/canvas/index.js.map +0 -1
- package/esm/renderers/canvas/painter.d.ts +0 -17
- package/esm/renderers/canvas/painter.js +0 -157
- package/esm/renderers/canvas/painter.js.map +0 -1
- package/esm/renderers/canvas/util.d.ts +0 -2
- package/esm/renderers/canvas/util.js +0 -187
- package/esm/renderers/canvas/util.js.map +0 -1
- package/esm/renderers/index.d.ts +0 -3
- package/esm/renderers/index.js +0 -4
- package/esm/renderers/index.js.map +0 -1
- package/esm/renderers/svg/defs/arrow.d.ts +0 -15
- package/esm/renderers/svg/defs/arrow.js +0 -68
- package/esm/renderers/svg/defs/arrow.js.map +0 -1
- package/esm/renderers/svg/defs/clip.d.ts +0 -12
- package/esm/renderers/svg/defs/clip.js +0 -29
- package/esm/renderers/svg/defs/clip.js.map +0 -1
- package/esm/renderers/svg/defs/gradient.d.ts +0 -10
- package/esm/renderers/svg/defs/gradient.js +0 -117
- package/esm/renderers/svg/defs/gradient.js.map +0 -1
- package/esm/renderers/svg/defs/pattern.d.ts +0 -10
- package/esm/renderers/svg/defs/pattern.js +0 -46
- package/esm/renderers/svg/defs/pattern.js.map +0 -1
- package/esm/renderers/svg/defs/shadow.d.ts +0 -13
- package/esm/renderers/svg/defs/shadow.js +0 -62
- package/esm/renderers/svg/defs/shadow.js.map +0 -1
- package/esm/renderers/svg/defs.d.ts +0 -18
- package/esm/renderers/svg/defs.js +0 -90
- package/esm/renderers/svg/defs.js.map +0 -1
- package/esm/renderers/svg/get-shape.d.ts +0 -1
- package/esm/renderers/svg/get-shape.js +0 -28
- package/esm/renderers/svg/get-shape.js.map +0 -1
- package/esm/renderers/svg/index.d.ts +0 -2
- package/esm/renderers/svg/index.js +0 -3
- package/esm/renderers/svg/index.js.map +0 -1
- package/esm/renderers/svg/painter.d.ts +0 -32
- package/esm/renderers/svg/painter.js +0 -695
- package/esm/renderers/svg/painter.js.map +0 -1
- package/esm/shapes/arc.d.ts +0 -25
- package/esm/shapes/arc.js +0 -107
- package/esm/shapes/arc.js.map +0 -1
- package/esm/shapes/circle.d.ts +0 -17
- package/esm/shapes/circle.js +0 -62
- package/esm/shapes/circle.js.map +0 -1
- package/esm/shapes/dom.d.ts +0 -10
- package/esm/shapes/dom.js +0 -35
- package/esm/shapes/dom.js.map +0 -1
- package/esm/shapes/ellipse.d.ts +0 -18
- package/esm/shapes/ellipse.js +0 -88
- package/esm/shapes/ellipse.js.map +0 -1
- package/esm/shapes/fan.d.ts +0 -21
- package/esm/shapes/fan.js +0 -151
- package/esm/shapes/fan.js.map +0 -1
- package/esm/shapes/image.d.ts +0 -24
- package/esm/shapes/image.js +0 -154
- package/esm/shapes/image.js.map +0 -1
- package/esm/shapes/index.d.ts +0 -13
- package/esm/shapes/index.js +0 -14
- package/esm/shapes/index.js.map +0 -1
- package/esm/shapes/interface.d.ts +0 -3
- package/esm/shapes/interface.js +0 -1
- package/esm/shapes/interface.js.map +0 -1
- package/esm/shapes/line.d.ts +0 -22
- package/esm/shapes/line.js +0 -70
- package/esm/shapes/line.js.map +0 -1
- package/esm/shapes/marker/index.d.ts +0 -30
- package/esm/shapes/marker/index.js +0 -90
- package/esm/shapes/marker/index.js.map +0 -1
- package/esm/shapes/marker/symbols.d.ts +0 -14
- package/esm/shapes/marker/symbols.js +0 -39
- package/esm/shapes/marker/symbols.js.map +0 -1
- package/esm/shapes/math/arc.d.ts +0 -6
- package/esm/shapes/math/arc.js +0 -113
- package/esm/shapes/math/arc.js.map +0 -1
- package/esm/shapes/math/cubic.d.ts +0 -7
- package/esm/shapes/math/cubic.js +0 -141
- package/esm/shapes/math/cubic.js.map +0 -1
- package/esm/shapes/math/ellipse.d.ts +0 -4
- package/esm/shapes/math/ellipse.js +0 -13
- package/esm/shapes/math/ellipse.js.map +0 -1
- package/esm/shapes/math/line.d.ts +0 -5
- package/esm/shapes/math/line.js +0 -23
- package/esm/shapes/math/line.js.map +0 -1
- package/esm/shapes/math/quadratic.d.ts +0 -5
- package/esm/shapes/math/quadratic.js +0 -74
- package/esm/shapes/math/quadratic.js.map +0 -1
- package/esm/shapes/path.d.ts +0 -25
- package/esm/shapes/path.js +0 -270
- package/esm/shapes/path.js.map +0 -1
- package/esm/shapes/polygon.d.ts +0 -15
- package/esm/shapes/polygon.js +0 -103
- package/esm/shapes/polygon.js.map +0 -1
- package/esm/shapes/polyline.d.ts +0 -24
- package/esm/shapes/polyline.js +0 -171
- package/esm/shapes/polyline.js.map +0 -1
- package/esm/shapes/rect.d.ts +0 -19
- package/esm/shapes/rect.js +0 -107
- package/esm/shapes/rect.js.map +0 -1
- package/esm/shapes/text.d.ts +0 -35
- package/esm/shapes/text.js +0 -262
- package/esm/shapes/text.js.map +0 -1
- package/esm/shapes/util/arrow.d.ts +0 -3
- package/esm/shapes/util/arrow.js +0 -131
- package/esm/shapes/util/arrow.js.map +0 -1
- package/esm/shapes/util/inside.d.ts +0 -9
- package/esm/shapes/util/inside.js +0 -50
- package/esm/shapes/util/inside.js.map +0 -1
- package/esm/shapes/util/is-point-in-path-by-ctx.d.ts +0 -2
- package/esm/shapes/util/is-point-in-path-by-ctx.js +0 -14
- package/esm/shapes/util/is-point-in-path-by-ctx.js.map +0 -1
- package/esm/shapes/util/path-segment.d.ts +0 -18
- package/esm/shapes/util/path-segment.js +0 -594
- package/esm/shapes/util/path-segment.js.map +0 -1
- package/esm/util/format.d.ts +0 -7
- package/esm/util/format.js +0 -60
- package/esm/util/format.js.map +0 -1
- package/esm/util/path.d.ts +0 -11
- package/esm/util/path.js +0 -1327
- package/esm/util/path.js.map +0 -1
- package/lib/canvas.d.ts +0 -46
- package/lib/canvas.js +0 -385
- package/lib/canvas.js.map +0 -1
- package/lib/core/attribute.d.ts +0 -49
- package/lib/core/attribute.js +0 -279
- package/lib/core/attribute.js.map +0 -1
- package/lib/core/base.d.ts +0 -32
- package/lib/core/base.js +0 -192
- package/lib/core/base.js.map +0 -1
- package/lib/core/bbox.d.ts +0 -22
- package/lib/core/bbox.js +0 -36
- package/lib/core/bbox.js.map +0 -1
- package/lib/core/element.d.ts +0 -19
- package/lib/core/element.js +0 -205
- package/lib/core/element.js.map +0 -1
- package/lib/core/group.d.ts +0 -72
- package/lib/core/group.js +0 -439
- package/lib/core/group.js.map +0 -1
- package/lib/core/shape.d.ts +0 -35
- package/lib/core/shape.js +0 -160
- package/lib/core/shape.js.map +0 -1
- package/lib/core/timeline.d.ts +0 -15
- package/lib/core/timeline.js +0 -181
- package/lib/core/timeline.js.map +0 -1
- package/lib/event.d.ts +0 -25
- package/lib/event.js +0 -39
- package/lib/event.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/interface.d.ts +0 -18
- package/lib/interface.js +0 -3
- package/lib/interface.js.map +0 -1
- package/lib/renderers/canvas/index.d.ts +0 -1
- package/lib/renderers/canvas/index.js +0 -5
- package/lib/renderers/canvas/index.js.map +0 -1
- package/lib/renderers/canvas/painter.d.ts +0 -17
- package/lib/renderers/canvas/painter.js +0 -159
- package/lib/renderers/canvas/painter.js.map +0 -1
- package/lib/renderers/canvas/util.d.ts +0 -2
- package/lib/renderers/canvas/util.js +0 -192
- package/lib/renderers/canvas/util.js.map +0 -1
- package/lib/renderers/index.d.ts +0 -3
- package/lib/renderers/index.js +0 -8
- package/lib/renderers/index.js.map +0 -1
- package/lib/renderers/svg/defs/arrow.d.ts +0 -15
- package/lib/renderers/svg/defs/arrow.js +0 -70
- package/lib/renderers/svg/defs/arrow.js.map +0 -1
- package/lib/renderers/svg/defs/clip.d.ts +0 -12
- package/lib/renderers/svg/defs/clip.js +0 -31
- package/lib/renderers/svg/defs/clip.js.map +0 -1
- package/lib/renderers/svg/defs/gradient.d.ts +0 -10
- package/lib/renderers/svg/defs/gradient.js +0 -119
- package/lib/renderers/svg/defs/gradient.js.map +0 -1
- package/lib/renderers/svg/defs/pattern.d.ts +0 -10
- package/lib/renderers/svg/defs/pattern.js +0 -48
- package/lib/renderers/svg/defs/pattern.js.map +0 -1
- package/lib/renderers/svg/defs/shadow.d.ts +0 -13
- package/lib/renderers/svg/defs/shadow.js +0 -64
- package/lib/renderers/svg/defs/shadow.js.map +0 -1
- package/lib/renderers/svg/defs.d.ts +0 -18
- package/lib/renderers/svg/defs.js +0 -92
- package/lib/renderers/svg/defs.js.map +0 -1
- package/lib/renderers/svg/get-shape.d.ts +0 -1
- package/lib/renderers/svg/get-shape.js +0 -31
- package/lib/renderers/svg/get-shape.js.map +0 -1
- package/lib/renderers/svg/index.d.ts +0 -2
- package/lib/renderers/svg/index.js +0 -7
- package/lib/renderers/svg/index.js.map +0 -1
- package/lib/renderers/svg/painter.d.ts +0 -32
- package/lib/renderers/svg/painter.js +0 -697
- package/lib/renderers/svg/painter.js.map +0 -1
- package/lib/shapes/arc.d.ts +0 -25
- package/lib/shapes/arc.js +0 -109
- package/lib/shapes/arc.js.map +0 -1
- package/lib/shapes/circle.d.ts +0 -17
- package/lib/shapes/circle.js +0 -64
- package/lib/shapes/circle.js.map +0 -1
- package/lib/shapes/dom.d.ts +0 -10
- package/lib/shapes/dom.js +0 -37
- package/lib/shapes/dom.js.map +0 -1
- package/lib/shapes/ellipse.d.ts +0 -18
- package/lib/shapes/ellipse.js +0 -90
- package/lib/shapes/ellipse.js.map +0 -1
- package/lib/shapes/fan.d.ts +0 -21
- package/lib/shapes/fan.js +0 -153
- package/lib/shapes/fan.js.map +0 -1
- package/lib/shapes/image.d.ts +0 -24
- package/lib/shapes/image.js +0 -156
- package/lib/shapes/image.js.map +0 -1
- package/lib/shapes/index.js.map +0 -1
- package/lib/shapes/interface.d.ts +0 -3
- package/lib/shapes/interface.js +0 -3
- package/lib/shapes/interface.js.map +0 -1
- package/lib/shapes/line.d.ts +0 -22
- package/lib/shapes/line.js +0 -72
- package/lib/shapes/line.js.map +0 -1
- package/lib/shapes/marker/index.d.ts +0 -30
- package/lib/shapes/marker/index.js +0 -92
- package/lib/shapes/marker/index.js.map +0 -1
- package/lib/shapes/marker/symbols.d.ts +0 -14
- package/lib/shapes/marker/symbols.js +0 -41
- package/lib/shapes/marker/symbols.js.map +0 -1
- package/lib/shapes/math/arc.d.ts +0 -6
- package/lib/shapes/math/arc.js +0 -116
- package/lib/shapes/math/arc.js.map +0 -1
- package/lib/shapes/math/cubic.d.ts +0 -7
- package/lib/shapes/math/cubic.js +0 -149
- package/lib/shapes/math/cubic.js.map +0 -1
- package/lib/shapes/math/ellipse.d.ts +0 -4
- package/lib/shapes/math/ellipse.js +0 -20
- package/lib/shapes/math/ellipse.js.map +0 -1
- package/lib/shapes/math/line.d.ts +0 -5
- package/lib/shapes/math/line.js +0 -30
- package/lib/shapes/math/line.js.map +0 -1
- package/lib/shapes/math/quadratic.d.ts +0 -5
- package/lib/shapes/math/quadratic.js +0 -81
- package/lib/shapes/math/quadratic.js.map +0 -1
- package/lib/shapes/path.d.ts +0 -25
- package/lib/shapes/path.js +0 -272
- package/lib/shapes/path.js.map +0 -1
- package/lib/shapes/polygon.d.ts +0 -15
- package/lib/shapes/polygon.js +0 -105
- package/lib/shapes/polygon.js.map +0 -1
- package/lib/shapes/polyline.d.ts +0 -24
- package/lib/shapes/polyline.js +0 -173
- package/lib/shapes/polyline.js.map +0 -1
- package/lib/shapes/rect.d.ts +0 -19
- package/lib/shapes/rect.js +0 -109
- package/lib/shapes/rect.js.map +0 -1
- package/lib/shapes/text.d.ts +0 -35
- package/lib/shapes/text.js +0 -264
- package/lib/shapes/text.js.map +0 -1
- package/lib/shapes/util/arrow.d.ts +0 -3
- package/lib/shapes/util/arrow.js +0 -136
- package/lib/shapes/util/arrow.js.map +0 -1
- package/lib/shapes/util/inside.d.ts +0 -9
- package/lib/shapes/util/inside.js +0 -61
- package/lib/shapes/util/inside.js.map +0 -1
- package/lib/shapes/util/is-point-in-path-by-ctx.d.ts +0 -2
- package/lib/shapes/util/is-point-in-path-by-ctx.js +0 -17
- package/lib/shapes/util/is-point-in-path-by-ctx.js.map +0 -1
- package/lib/shapes/util/path-segment.d.ts +0 -18
- package/lib/shapes/util/path-segment.js +0 -596
- package/lib/shapes/util/path-segment.js.map +0 -1
- package/lib/util/format.d.ts +0 -7
- package/lib/util/format.js +0 -65
- package/lib/util/format.js.map +0 -1
- package/lib/util/path.d.ts +0 -11
- package/lib/util/path.js +0 -1339
- package/lib/util/path.js.map +0 -1
|
@@ -0,0 +1,973 @@
|
|
|
1
|
+
import { __extends } from "tslib";
|
|
2
|
+
import { EventEmitter } from 'eventemitter3';
|
|
3
|
+
import { mat3, mat4, quat, vec3, vec4 } from 'gl-matrix';
|
|
4
|
+
import { Landmark } from './Landmark';
|
|
5
|
+
import { Frustum } from '../shapes';
|
|
6
|
+
import { createVec3, getAngle, makePerspective } from '../utils/math';
|
|
7
|
+
import { requestAnimationFrame, cancelAnimationFrame } from '../utils/raf';
|
|
8
|
+
export var DefaultCamera = 'DefaultCamera';
|
|
9
|
+
export var CAMERA_TYPE;
|
|
10
|
+
|
|
11
|
+
(function (CAMERA_TYPE) {
|
|
12
|
+
CAMERA_TYPE["ORBITING"] = "ORBITING";
|
|
13
|
+
CAMERA_TYPE["EXPLORING"] = "EXPLORING";
|
|
14
|
+
CAMERA_TYPE["TRACKING"] = "TRACKING";
|
|
15
|
+
})(CAMERA_TYPE || (CAMERA_TYPE = {}));
|
|
16
|
+
|
|
17
|
+
export var CAMERA_TRACKING_MODE;
|
|
18
|
+
|
|
19
|
+
(function (CAMERA_TRACKING_MODE) {
|
|
20
|
+
CAMERA_TRACKING_MODE["DEFAULT"] = "DEFAULT";
|
|
21
|
+
CAMERA_TRACKING_MODE["ROTATIONAL"] = "ROTATIONAL";
|
|
22
|
+
CAMERA_TRACKING_MODE["TRANSLATIONAL"] = "TRANSLATIONAL";
|
|
23
|
+
CAMERA_TRACKING_MODE["CINEMATIC"] = "CINEMATIC";
|
|
24
|
+
})(CAMERA_TRACKING_MODE || (CAMERA_TRACKING_MODE = {}));
|
|
25
|
+
|
|
26
|
+
export var CAMERA_PROJECTION_MODE;
|
|
27
|
+
|
|
28
|
+
(function (CAMERA_PROJECTION_MODE) {
|
|
29
|
+
CAMERA_PROJECTION_MODE["ORTHOGRAPHIC"] = "ORTHOGRAPHIC";
|
|
30
|
+
CAMERA_PROJECTION_MODE["PERSPECTIVE"] = "PERSPECTIVE";
|
|
31
|
+
})(CAMERA_PROJECTION_MODE || (CAMERA_PROJECTION_MODE = {}));
|
|
32
|
+
|
|
33
|
+
export var CAMERA_EVENT = {
|
|
34
|
+
Updated: 'updated'
|
|
35
|
+
};
|
|
36
|
+
var DEG_2_RAD = Math.PI / 180;
|
|
37
|
+
var RAD_2_DEG = 180 / Math.PI;
|
|
38
|
+
/**
|
|
39
|
+
* 参考「WebGL Insights - 23.Designing Cameras for WebGL Applications」,基于 Responsible Camera 思路设计
|
|
40
|
+
* 保存相机参数,定义相机动作:
|
|
41
|
+
* 1. dolly 沿 n 轴移动
|
|
42
|
+
* 2. pan 沿 u v 轴移动
|
|
43
|
+
* 3. rotate 以方位角旋转
|
|
44
|
+
* 4. 移动到 Landmark,具有平滑的动画效果,其间禁止其他用户交互
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
var Camera =
|
|
48
|
+
/** @class */
|
|
49
|
+
function (_super) {
|
|
50
|
+
__extends(Camera, _super);
|
|
51
|
+
|
|
52
|
+
function Camera() {
|
|
53
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
54
|
+
/**
|
|
55
|
+
* 相机矩阵
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
_this.matrix = mat4.create();
|
|
60
|
+
/**
|
|
61
|
+
* u 轴
|
|
62
|
+
* @see http://learnwebgl.brown37.net/07_cameras/camera_introduction.html#a-camera-definition
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
_this.right = vec3.fromValues(1, 0, 0);
|
|
66
|
+
/**
|
|
67
|
+
* v 轴 +Y is down
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
_this.up = vec3.fromValues(0, 1, 0);
|
|
71
|
+
/**
|
|
72
|
+
* n 轴 +Z is inside
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
_this.forward = vec3.fromValues(0, 0, 1);
|
|
76
|
+
/**
|
|
77
|
+
* 相机位置
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
_this.position = vec3.fromValues(0, 0, 1);
|
|
81
|
+
/**
|
|
82
|
+
* 视点位置
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
_this.focalPoint = vec3.fromValues(0, 0, 0);
|
|
86
|
+
/**
|
|
87
|
+
* 相机位置到视点向量
|
|
88
|
+
* focalPoint - position
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
_this.distanceVector = vec3.fromValues(0, 0, 0);
|
|
92
|
+
/**
|
|
93
|
+
* 相机位置到视点距离
|
|
94
|
+
* length(focalPoint - position)
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
_this.distance = 1;
|
|
98
|
+
/**
|
|
99
|
+
* @see https://en.wikipedia.org/wiki/Azimuth
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
_this.azimuth = 0;
|
|
103
|
+
_this.elevation = 0;
|
|
104
|
+
_this.roll = 0;
|
|
105
|
+
_this.relAzimuth = 0;
|
|
106
|
+
_this.relElevation = 0;
|
|
107
|
+
_this.relRoll = 0;
|
|
108
|
+
/**
|
|
109
|
+
* 沿 n 轴移动时,保证移动速度从快到慢
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
_this.dollyingStep = 0;
|
|
113
|
+
_this.maxDistance = Infinity;
|
|
114
|
+
_this.minDistance = -Infinity;
|
|
115
|
+
/**
|
|
116
|
+
* zoom factor of the camera, default is 1
|
|
117
|
+
* eg. https://threejs.org/docs/#api/en/cameras/OrthographicCamera.zoom
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
_this.zoom = 1;
|
|
121
|
+
/**
|
|
122
|
+
* invert the horizontal coordinate system HCS
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
_this.rotateWorld = false; // @inject(IDENTIFIER.InteractorService)
|
|
126
|
+
// interactor: IInteractorService;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* 投影矩阵参数
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* field of view [0-360]
|
|
134
|
+
* @see http://en.wikipedia.org/wiki/Angle_of_view
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
_this.fov = 30;
|
|
138
|
+
_this.near = 0.1;
|
|
139
|
+
_this.far = 10000;
|
|
140
|
+
_this.aspect = 1;
|
|
141
|
+
_this.projectionMatrix = mat4.create();
|
|
142
|
+
_this.projectionMatrixInverse = mat4.create();
|
|
143
|
+
_this.jitteredProjectionMatrix = undefined;
|
|
144
|
+
_this.following = undefined;
|
|
145
|
+
_this.type = CAMERA_TYPE.EXPLORING;
|
|
146
|
+
_this.trackingMode = CAMERA_TRACKING_MODE.DEFAULT;
|
|
147
|
+
_this.projectionMode = CAMERA_PROJECTION_MODE.PERSPECTIVE;
|
|
148
|
+
/**
|
|
149
|
+
* for culling use
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
_this.frustum = new Frustum();
|
|
153
|
+
/**
|
|
154
|
+
* switch between multiple landmarks
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
_this.landmarks = [];
|
|
158
|
+
/**
|
|
159
|
+
* ortho matrix for Canvas2D & SVG
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
_this.orthoMatrix = mat4.create();
|
|
163
|
+
return _this;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
Camera.prototype.clone = function () {
|
|
167
|
+
var camera = new Camera();
|
|
168
|
+
camera.setType(this.type, undefined); // camera.interactor = this.interactor;
|
|
169
|
+
|
|
170
|
+
return camera;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
Camera.prototype.getProjectionMode = function () {
|
|
174
|
+
return this.projectionMode;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
Camera.prototype.getPerspective = function () {
|
|
178
|
+
// account for TAA
|
|
179
|
+
return this.jitteredProjectionMatrix || this.projectionMatrix;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
Camera.prototype.getPerspectiveInverse = function () {
|
|
183
|
+
return this.projectionMatrixInverse;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
Camera.prototype.getFrustum = function () {
|
|
187
|
+
return this.frustum;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
Camera.prototype.getPosition = function () {
|
|
191
|
+
return this.position;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
Camera.prototype.getFocalPoint = function () {
|
|
195
|
+
return this.focalPoint;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
Camera.prototype.getNear = function () {
|
|
199
|
+
return this.near;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
Camera.prototype.getFar = function () {
|
|
203
|
+
return this.far;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
Camera.prototype.getZoom = function () {
|
|
207
|
+
return this.zoom;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
Camera.prototype.getOrthoMatrix = function () {
|
|
211
|
+
return this.orthoMatrix;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
Camera.prototype.setType = function (type, trackingMode) {
|
|
215
|
+
this.type = type;
|
|
216
|
+
|
|
217
|
+
if (this.type === CAMERA_TYPE.EXPLORING) {
|
|
218
|
+
this.setWorldRotation(true);
|
|
219
|
+
} else {
|
|
220
|
+
this.setWorldRotation(false);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
this._getAngles();
|
|
224
|
+
|
|
225
|
+
if (this.type === CAMERA_TYPE.TRACKING && trackingMode !== undefined) {
|
|
226
|
+
this.setTrackingMode(trackingMode);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return this;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
Camera.prototype.setProjectionMode = function (projectionMode) {
|
|
233
|
+
this.projectionMode = projectionMode;
|
|
234
|
+
return this;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
Camera.prototype.setTrackingMode = function (trackingMode) {
|
|
238
|
+
if (this.type !== CAMERA_TYPE.TRACKING) {
|
|
239
|
+
throw new Error('Impossible to set a tracking mode if the camera is not of tracking type');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
this.trackingMode = trackingMode;
|
|
243
|
+
return this;
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* If flag is true, it reverses the azimuth and elevation angles.
|
|
247
|
+
* Subsequent calls to rotate, setAzimuth, setElevation,
|
|
248
|
+
* changeAzimuth or changeElevation will cause the inverted effect.
|
|
249
|
+
* setRoll or changeRoll is not affected by this method.
|
|
250
|
+
*
|
|
251
|
+
* This inversion is useful when one wants to simulate that the world
|
|
252
|
+
* is moving, instead of the camera.
|
|
253
|
+
*
|
|
254
|
+
* By default the camera angles are not reversed.
|
|
255
|
+
* @param {Boolean} flag the boolean flag to reverse the angles.
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
Camera.prototype.setWorldRotation = function (flag) {
|
|
260
|
+
this.rotateWorld = flag;
|
|
261
|
+
|
|
262
|
+
this._getAngles();
|
|
263
|
+
};
|
|
264
|
+
/**
|
|
265
|
+
* 计算 MV 矩阵,为相机矩阵的逆矩阵
|
|
266
|
+
*/
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
Camera.prototype.getViewTransform = function () {
|
|
270
|
+
return mat4.invert(mat4.create(), this.matrix);
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
Camera.prototype.getWorldTransform = function () {
|
|
274
|
+
return this.matrix;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
Camera.prototype.jitterProjectionMatrix = function (x, y) {
|
|
278
|
+
var translation = mat4.fromTranslation(mat4.create(), [x, y, 0]);
|
|
279
|
+
this.jitteredProjectionMatrix = mat4.multiply(mat4.create(), translation, this.projectionMatrix);
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
Camera.prototype.clearJitterProjectionMatrix = function () {
|
|
283
|
+
this.jitteredProjectionMatrix = undefined;
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* 设置相机矩阵
|
|
287
|
+
*/
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
Camera.prototype.setMatrix = function (matrix) {
|
|
291
|
+
this.matrix = matrix;
|
|
292
|
+
|
|
293
|
+
this._update();
|
|
294
|
+
|
|
295
|
+
return this;
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
Camera.prototype.setFov = function (fov) {
|
|
299
|
+
this.setPerspective(this.near, this.far, fov, this.aspect);
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
Camera.prototype.setAspect = function (aspect) {
|
|
303
|
+
this.setPerspective(this.near, this.far, this.fov, aspect);
|
|
304
|
+
return this;
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
Camera.prototype.setNear = function (near) {
|
|
308
|
+
if (this.projectionMode === CAMERA_PROJECTION_MODE.PERSPECTIVE) {
|
|
309
|
+
this.setPerspective(near, this.far, this.fov, this.aspect);
|
|
310
|
+
} else {
|
|
311
|
+
this.setOrthographic(this.left, this.rright, this.top, this.bottom, near, this.far);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return this;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
Camera.prototype.setFar = function (far) {
|
|
318
|
+
if (this.projectionMode === CAMERA_PROJECTION_MODE.PERSPECTIVE) {
|
|
319
|
+
this.setPerspective(this.near, far, this.fov, this.aspect);
|
|
320
|
+
} else {
|
|
321
|
+
this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, far);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return this;
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* Sets an offset in a larger frustum, used in PixelPicking
|
|
328
|
+
*/
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
Camera.prototype.setViewOffset = function (fullWidth, fullHeight, x, y, width, height) {
|
|
332
|
+
this.aspect = fullWidth / fullHeight;
|
|
333
|
+
|
|
334
|
+
if (this.view === undefined) {
|
|
335
|
+
this.view = {
|
|
336
|
+
enabled: true,
|
|
337
|
+
fullWidth: 1,
|
|
338
|
+
fullHeight: 1,
|
|
339
|
+
offsetX: 0,
|
|
340
|
+
offsetY: 0,
|
|
341
|
+
width: 1,
|
|
342
|
+
height: 1
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
this.view.enabled = true;
|
|
347
|
+
this.view.fullWidth = fullWidth;
|
|
348
|
+
this.view.fullHeight = fullHeight;
|
|
349
|
+
this.view.offsetX = x;
|
|
350
|
+
this.view.offsetY = y;
|
|
351
|
+
this.view.width = width;
|
|
352
|
+
this.view.height = height;
|
|
353
|
+
|
|
354
|
+
if (this.projectionMode === CAMERA_PROJECTION_MODE.PERSPECTIVE) {
|
|
355
|
+
this.setPerspective(this.near, this.far, this.fov, this.aspect);
|
|
356
|
+
} else {
|
|
357
|
+
this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, this.far);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return this;
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
Camera.prototype.clearViewOffset = function () {
|
|
364
|
+
if (this.view !== undefined) {
|
|
365
|
+
this.view.enabled = false;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (this.projectionMode === CAMERA_PROJECTION_MODE.PERSPECTIVE) {
|
|
369
|
+
this.setPerspective(this.near, this.far, this.fov, this.aspect);
|
|
370
|
+
} else {
|
|
371
|
+
this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, this.far);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
return this;
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
Camera.prototype.setZoom = function (zoom) {
|
|
378
|
+
this.zoom = zoom;
|
|
379
|
+
|
|
380
|
+
if (this.projectionMode === CAMERA_PROJECTION_MODE.ORTHOGRAPHIC) {
|
|
381
|
+
this.setOrthographic(this.left, this.rright, this.top, this.bottom, this.near, this.far);
|
|
382
|
+
} else if (this.projectionMode === CAMERA_PROJECTION_MODE.PERSPECTIVE) {
|
|
383
|
+
this.setPerspective(this.near, this.far, this.fov, this.aspect);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return this;
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
Camera.prototype.setPerspective = function (near, far, fov, aspect) {
|
|
390
|
+
this.projectionMode = CAMERA_PROJECTION_MODE.PERSPECTIVE;
|
|
391
|
+
this.fov = fov;
|
|
392
|
+
this.near = near;
|
|
393
|
+
this.far = far;
|
|
394
|
+
this.aspect = aspect;
|
|
395
|
+
var top = this.near * Math.tan(DEG_2_RAD * 0.5 * this.fov) / this.zoom;
|
|
396
|
+
var height = 2 * top;
|
|
397
|
+
var width = this.aspect * height;
|
|
398
|
+
var left = -0.5 * width;
|
|
399
|
+
|
|
400
|
+
if (this.view !== undefined && this.view.enabled) {
|
|
401
|
+
var fullWidth = this.view.fullWidth;
|
|
402
|
+
var fullHeight = this.view.fullHeight;
|
|
403
|
+
left += this.view.offsetX * width / fullWidth;
|
|
404
|
+
top -= this.view.offsetY * height / fullHeight;
|
|
405
|
+
width *= this.view.width / fullWidth;
|
|
406
|
+
height *= this.view.height / fullHeight;
|
|
407
|
+
} // flip Y
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
makePerspective(this.projectionMatrix, left, left + width, top - height, top, near, this.far);
|
|
411
|
+
mat4.invert(this.projectionMatrixInverse, this.projectionMatrix);
|
|
412
|
+
this.emit(CAMERA_EVENT.Updated);
|
|
413
|
+
return this;
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
Camera.prototype.setOrthographic = function (l, r, t, b, near, far) {
|
|
417
|
+
this.projectionMode = CAMERA_PROJECTION_MODE.ORTHOGRAPHIC;
|
|
418
|
+
this.rright = r;
|
|
419
|
+
this.left = l;
|
|
420
|
+
this.top = t;
|
|
421
|
+
this.bottom = b;
|
|
422
|
+
this.near = near;
|
|
423
|
+
this.far = far;
|
|
424
|
+
var dx = (this.rright - this.left) / (2 * this.zoom);
|
|
425
|
+
var dy = (this.top - this.bottom) / (2 * this.zoom);
|
|
426
|
+
var cx = (this.rright + this.left) / 2;
|
|
427
|
+
var cy = (this.top + this.bottom) / 2;
|
|
428
|
+
var left = cx - dx;
|
|
429
|
+
var right = cx + dx;
|
|
430
|
+
var top = cy + dy;
|
|
431
|
+
var bottom = cy - dy;
|
|
432
|
+
|
|
433
|
+
if (this.view !== undefined && this.view.enabled) {
|
|
434
|
+
var scaleW = (this.rright - this.left) / this.view.fullWidth / this.zoom;
|
|
435
|
+
var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
|
|
436
|
+
left += scaleW * this.view.offsetX;
|
|
437
|
+
right = left + scaleW * this.view.width;
|
|
438
|
+
top -= scaleH * this.view.offsetY;
|
|
439
|
+
bottom = top - scaleH * this.view.height;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
mat4.ortho(this.projectionMatrix, left, right, bottom, top, near, far);
|
|
443
|
+
mat4.invert(this.projectionMatrixInverse, this.projectionMatrix);
|
|
444
|
+
|
|
445
|
+
this._getOrthoMatrix();
|
|
446
|
+
|
|
447
|
+
this.emit(CAMERA_EVENT.Updated);
|
|
448
|
+
return this;
|
|
449
|
+
};
|
|
450
|
+
/**
|
|
451
|
+
* 设置相机位置
|
|
452
|
+
*/
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
Camera.prototype.setPosition = function (x, y, z) {
|
|
456
|
+
if (y === void 0) {
|
|
457
|
+
y = 0;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
if (z === void 0) {
|
|
461
|
+
z = 0;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
this._setPosition(x, y, z);
|
|
465
|
+
|
|
466
|
+
this.setFocalPoint(this.focalPoint);
|
|
467
|
+
return this;
|
|
468
|
+
};
|
|
469
|
+
/**
|
|
470
|
+
* 设置视点位置
|
|
471
|
+
*/
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
Camera.prototype.setFocalPoint = function (x, y, z) {
|
|
475
|
+
var up = vec3.fromValues(0, 1, 0);
|
|
476
|
+
this.focalPoint = createVec3(x, y, z);
|
|
477
|
+
|
|
478
|
+
if (this.trackingMode === CAMERA_TRACKING_MODE.CINEMATIC) {
|
|
479
|
+
var d = vec3.subtract(vec3.create(), this.focalPoint, this.position);
|
|
480
|
+
x = d[0];
|
|
481
|
+
y = d[1];
|
|
482
|
+
z = d[2];
|
|
483
|
+
var r = vec3.length(d);
|
|
484
|
+
var el = Math.asin(y / r) * RAD_2_DEG;
|
|
485
|
+
var az = 90 + Math.atan2(z, x) * RAD_2_DEG;
|
|
486
|
+
var m = mat4.create();
|
|
487
|
+
mat4.rotateY(m, m, az * DEG_2_RAD);
|
|
488
|
+
mat4.rotateX(m, m, el * DEG_2_RAD);
|
|
489
|
+
up = vec3.transformMat4(vec3.create(), [0, 1, 0], m);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
mat4.invert(this.matrix, mat4.lookAt(mat4.create(), this.position, this.focalPoint, up));
|
|
493
|
+
|
|
494
|
+
this._getAxes();
|
|
495
|
+
|
|
496
|
+
this._getDistance();
|
|
497
|
+
|
|
498
|
+
this._getAngles();
|
|
499
|
+
|
|
500
|
+
return this;
|
|
501
|
+
};
|
|
502
|
+
/**
|
|
503
|
+
* 固定当前视点,按指定距离放置相机
|
|
504
|
+
*/
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
Camera.prototype.setDistance = function (d) {
|
|
508
|
+
if (this.distance === d || d < 0) {
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
this.distance = d;
|
|
513
|
+
|
|
514
|
+
if (this.distance < 0.0002) {
|
|
515
|
+
this.distance = 0.0002;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
this.dollyingStep = this.distance / 100;
|
|
519
|
+
var pos = vec3.create();
|
|
520
|
+
d = this.distance;
|
|
521
|
+
var n = this.forward;
|
|
522
|
+
var f = this.focalPoint;
|
|
523
|
+
pos[0] = d * n[0] + f[0];
|
|
524
|
+
pos[1] = d * n[1] + f[1];
|
|
525
|
+
pos[2] = d * n[2] + f[2];
|
|
526
|
+
|
|
527
|
+
this._setPosition(pos);
|
|
528
|
+
|
|
529
|
+
return this;
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
Camera.prototype.setMaxDistance = function (d) {
|
|
533
|
+
this.maxDistance = d;
|
|
534
|
+
return this;
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
Camera.prototype.setMinDistance = function (d) {
|
|
538
|
+
this.minDistance = d;
|
|
539
|
+
return this;
|
|
540
|
+
};
|
|
541
|
+
/**
|
|
542
|
+
* Changes the initial azimuth of the camera
|
|
543
|
+
*/
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
Camera.prototype.changeAzimuth = function (az) {
|
|
547
|
+
this.setAzimuth(this.azimuth + az);
|
|
548
|
+
return this;
|
|
549
|
+
};
|
|
550
|
+
/**
|
|
551
|
+
* Changes the initial elevation of the camera
|
|
552
|
+
*/
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
Camera.prototype.changeElevation = function (el) {
|
|
556
|
+
this.setElevation(this.elevation + el);
|
|
557
|
+
return this;
|
|
558
|
+
};
|
|
559
|
+
/**
|
|
560
|
+
* Changes the initial roll of the camera
|
|
561
|
+
*/
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
Camera.prototype.changeRoll = function (rl) {
|
|
565
|
+
this.setRoll(this.roll + rl);
|
|
566
|
+
return this;
|
|
567
|
+
};
|
|
568
|
+
/**
|
|
569
|
+
* 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
|
|
570
|
+
* @param {Number} el the azimuth in degrees
|
|
571
|
+
*/
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
Camera.prototype.setAzimuth = function (az) {
|
|
575
|
+
this.azimuth = getAngle(az);
|
|
576
|
+
this.computeMatrix();
|
|
577
|
+
|
|
578
|
+
this._getAxes();
|
|
579
|
+
|
|
580
|
+
if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
|
|
581
|
+
this._getPosition();
|
|
582
|
+
} else if (this.type === CAMERA_TYPE.TRACKING) {
|
|
583
|
+
this._getFocalPoint();
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
return this;
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
Camera.prototype.getAzimuth = function () {
|
|
590
|
+
return this.azimuth;
|
|
591
|
+
};
|
|
592
|
+
/**
|
|
593
|
+
* 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
|
|
594
|
+
* @param {Number} el the elevation in degrees
|
|
595
|
+
*/
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
Camera.prototype.setElevation = function (el) {
|
|
599
|
+
this.elevation = getAngle(el);
|
|
600
|
+
this.computeMatrix();
|
|
601
|
+
|
|
602
|
+
this._getAxes();
|
|
603
|
+
|
|
604
|
+
if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
|
|
605
|
+
this._getPosition();
|
|
606
|
+
} else if (this.type === CAMERA_TYPE.TRACKING) {
|
|
607
|
+
this._getFocalPoint();
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
return this;
|
|
611
|
+
};
|
|
612
|
+
/**
|
|
613
|
+
* 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
|
|
614
|
+
* @param {Number} angle the roll angle
|
|
615
|
+
*/
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
Camera.prototype.setRoll = function (angle) {
|
|
619
|
+
this.roll = getAngle(angle);
|
|
620
|
+
this.computeMatrix();
|
|
621
|
+
|
|
622
|
+
this._getAxes();
|
|
623
|
+
|
|
624
|
+
if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
|
|
625
|
+
this._getPosition();
|
|
626
|
+
} else if (this.type === CAMERA_TYPE.TRACKING) {
|
|
627
|
+
this._getFocalPoint();
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
return this;
|
|
631
|
+
};
|
|
632
|
+
/**
|
|
633
|
+
* Changes the azimuth and elevation with respect to the current camera axes
|
|
634
|
+
* @param {Number} azimuth the relative azimuth
|
|
635
|
+
* @param {Number} elevation the relative elevation
|
|
636
|
+
* @param {Number} roll the relative roll
|
|
637
|
+
*/
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
Camera.prototype.rotate = function (azimuth, elevation, roll) {
|
|
641
|
+
this.relElevation = getAngle(elevation);
|
|
642
|
+
this.relAzimuth = getAngle(azimuth);
|
|
643
|
+
this.relRoll = getAngle(roll);
|
|
644
|
+
this.elevation += this.relElevation;
|
|
645
|
+
this.azimuth += this.relAzimuth;
|
|
646
|
+
this.roll += this.relRoll;
|
|
647
|
+
|
|
648
|
+
if (this.type === CAMERA_TYPE.EXPLORING) {
|
|
649
|
+
var rotX = quat.setAxisAngle(quat.create(), [1, 0, 0], (this.rotateWorld ? 1 : -1) * this.relElevation * DEG_2_RAD);
|
|
650
|
+
var rotY = quat.setAxisAngle(quat.create(), [0, 1, 0], (this.rotateWorld ? 1 : -1) * this.relAzimuth * DEG_2_RAD);
|
|
651
|
+
var rotZ = quat.setAxisAngle(quat.create(), [0, 0, 1], this.relRoll * DEG_2_RAD);
|
|
652
|
+
var rotQ = quat.multiply(quat.create(), rotY, rotX);
|
|
653
|
+
rotQ = quat.multiply(quat.create(), rotQ, rotZ);
|
|
654
|
+
var rotMatrix = mat4.fromQuat(mat4.create(), rotQ);
|
|
655
|
+
mat4.translate(this.matrix, this.matrix, [0, 0, -this.distance]);
|
|
656
|
+
mat4.multiply(this.matrix, this.matrix, rotMatrix);
|
|
657
|
+
mat4.translate(this.matrix, this.matrix, [0, 0, this.distance]);
|
|
658
|
+
} else {
|
|
659
|
+
if (Math.abs(this.elevation) > 90) {
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
this.computeMatrix();
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
this._getAxes();
|
|
667
|
+
|
|
668
|
+
if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
|
|
669
|
+
this._getPosition();
|
|
670
|
+
} else if (this.type === CAMERA_TYPE.TRACKING) {
|
|
671
|
+
this._getFocalPoint();
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
this._update();
|
|
675
|
+
|
|
676
|
+
return this;
|
|
677
|
+
};
|
|
678
|
+
/**
|
|
679
|
+
* 沿水平(right) & 垂直(up)平移相机
|
|
680
|
+
*/
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
Camera.prototype.pan = function (tx, ty) {
|
|
684
|
+
var coords = createVec3(tx, ty, 0);
|
|
685
|
+
var pos = vec3.clone(this.position);
|
|
686
|
+
vec3.add(pos, pos, vec3.scale(vec3.create(), this.right, coords[0]));
|
|
687
|
+
vec3.add(pos, pos, vec3.scale(vec3.create(), this.up, coords[1]));
|
|
688
|
+
|
|
689
|
+
this._setPosition(pos);
|
|
690
|
+
|
|
691
|
+
this.emit(CAMERA_EVENT.Updated);
|
|
692
|
+
return this;
|
|
693
|
+
};
|
|
694
|
+
/**
|
|
695
|
+
* 沿 n 轴移动,当距离视点远时移动速度较快,离视点越近速度越慢
|
|
696
|
+
*/
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
Camera.prototype.dolly = function (value) {
|
|
700
|
+
var n = this.forward;
|
|
701
|
+
var pos = vec3.clone(this.position);
|
|
702
|
+
var step = value * this.dollyingStep;
|
|
703
|
+
var updatedDistance = this.distance + value * this.dollyingStep; // 限制视点距离范围
|
|
704
|
+
|
|
705
|
+
step = Math.max(Math.min(updatedDistance, this.maxDistance), this.minDistance) - this.distance;
|
|
706
|
+
pos[0] += step * n[0];
|
|
707
|
+
pos[1] += step * n[1];
|
|
708
|
+
pos[2] += step * n[2];
|
|
709
|
+
|
|
710
|
+
this._setPosition(pos);
|
|
711
|
+
|
|
712
|
+
if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
|
|
713
|
+
// 重新计算视点距离
|
|
714
|
+
this._getDistance();
|
|
715
|
+
} else if (this.type === CAMERA_TYPE.TRACKING) {
|
|
716
|
+
// 保持视距,移动视点位置
|
|
717
|
+
vec3.add(this.focalPoint, pos, this.distanceVector);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
this.emit(CAMERA_EVENT.Updated);
|
|
721
|
+
return this;
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
Camera.prototype.createLandmark = function (name, params) {
|
|
725
|
+
var camera = this.clone();
|
|
726
|
+
camera.setPosition(params.position);
|
|
727
|
+
camera.setFocalPoint(params.focalPoint);
|
|
728
|
+
|
|
729
|
+
if (params.roll !== undefined) {
|
|
730
|
+
camera.setRoll(params.roll);
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
var landmark = new Landmark(name, camera);
|
|
734
|
+
this.landmarks.push(landmark);
|
|
735
|
+
return landmark;
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
Camera.prototype.setLandmark = function (name) {
|
|
739
|
+
var landmark = new Landmark(name, this);
|
|
740
|
+
this.landmarks.push(landmark);
|
|
741
|
+
return this;
|
|
742
|
+
};
|
|
743
|
+
|
|
744
|
+
Camera.prototype.gotoLandmark = function (name, duration) {
|
|
745
|
+
var _this = this;
|
|
746
|
+
|
|
747
|
+
if (duration === void 0) {
|
|
748
|
+
duration = 1000;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
var landmark = this.landmarks.find(function (l) {
|
|
752
|
+
return l.name === name;
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
if (landmark) {
|
|
756
|
+
if (duration === 0) {
|
|
757
|
+
landmark.retrieve(this);
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
if (this.landmarkAnimationID !== undefined) {
|
|
762
|
+
cancelAnimationFrame(this.landmarkAnimationID);
|
|
763
|
+
} // TODO: do not process events during animation
|
|
764
|
+
// this.interactor.disconnect();
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
var destPosition_1 = landmark.getPosition();
|
|
768
|
+
var destFocalPoint_1 = landmark.getFocalPoint();
|
|
769
|
+
var destRoll_1 = landmark.getRoll();
|
|
770
|
+
var timeStart_1;
|
|
771
|
+
|
|
772
|
+
var animate_1 = function animate_1(timestamp) {
|
|
773
|
+
if (timeStart_1 === undefined) {
|
|
774
|
+
timeStart_1 = timestamp;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
var elapsed = timestamp - timeStart_1; // TODO: use better ease function
|
|
778
|
+
|
|
779
|
+
var t = (1 - Math.cos(elapsed / duration * Math.PI)) / 2;
|
|
780
|
+
var interFocalPoint = vec3.create();
|
|
781
|
+
var interPosition = vec3.create();
|
|
782
|
+
var interRoll = 0;
|
|
783
|
+
vec3.lerp(interFocalPoint, _this.focalPoint, destFocalPoint_1, t);
|
|
784
|
+
vec3.lerp(interPosition, _this.position, destPosition_1, t);
|
|
785
|
+
interRoll = _this.roll * (1 - t) + destRoll_1 * t;
|
|
786
|
+
|
|
787
|
+
_this.setFocalPoint(interFocalPoint);
|
|
788
|
+
|
|
789
|
+
_this.setPosition(interPosition);
|
|
790
|
+
|
|
791
|
+
_this.setRoll(interRoll);
|
|
792
|
+
|
|
793
|
+
_this.computeMatrix();
|
|
794
|
+
|
|
795
|
+
_this.emit(CAMERA_EVENT.Updated);
|
|
796
|
+
|
|
797
|
+
var dist = vec3.dist(interFocalPoint, destFocalPoint_1) + vec3.dist(interPosition, destPosition_1);
|
|
798
|
+
|
|
799
|
+
if (dist > 0.01) {//
|
|
800
|
+
} else {
|
|
801
|
+
_this.setFocalPoint(interFocalPoint);
|
|
802
|
+
|
|
803
|
+
_this.setPosition(interPosition);
|
|
804
|
+
|
|
805
|
+
_this.setRoll(interRoll);
|
|
806
|
+
|
|
807
|
+
_this.computeMatrix(); // this.interactor.connect();
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
if (elapsed < duration) {
|
|
814
|
+
_this.landmarkAnimationID = requestAnimationFrame(animate_1);
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
|
|
818
|
+
requestAnimationFrame(animate_1);
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
/**
|
|
822
|
+
* 根据相机矩阵重新计算各种相机参数
|
|
823
|
+
*/
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
Camera.prototype._update = function () {
|
|
827
|
+
this._getAxes();
|
|
828
|
+
|
|
829
|
+
this._getPosition();
|
|
830
|
+
|
|
831
|
+
this._getDistance();
|
|
832
|
+
|
|
833
|
+
this._getAngles();
|
|
834
|
+
|
|
835
|
+
this._getOrthoMatrix();
|
|
836
|
+
|
|
837
|
+
this.emit(CAMERA_EVENT.Updated);
|
|
838
|
+
};
|
|
839
|
+
/**
|
|
840
|
+
* 计算相机矩阵
|
|
841
|
+
*/
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
Camera.prototype.computeMatrix = function () {
|
|
845
|
+
// 使用四元数描述 3D 旋转
|
|
846
|
+
// @see https://xiaoiver.github.io/coding/2018/12/28/Camera-%E8%AE%BE%E8%AE%A1-%E4%B8%80.html
|
|
847
|
+
var rotZ = quat.setAxisAngle(quat.create(), [0, 0, 1], this.roll * DEG_2_RAD);
|
|
848
|
+
mat4.identity(this.matrix); // only consider HCS for EXPLORING and ORBITING cameras
|
|
849
|
+
|
|
850
|
+
var rotX = quat.setAxisAngle(quat.create(), [1, 0, 0], (this.rotateWorld && this.type !== CAMERA_TYPE.TRACKING || this.type === CAMERA_TYPE.TRACKING ? 1 : -1) * this.elevation * DEG_2_RAD);
|
|
851
|
+
var rotY = quat.setAxisAngle(quat.create(), [0, 1, 0], (this.rotateWorld && this.type !== CAMERA_TYPE.TRACKING || this.type === CAMERA_TYPE.TRACKING ? 1 : -1) * this.azimuth * DEG_2_RAD);
|
|
852
|
+
var rotQ = quat.multiply(quat.create(), rotY, rotX);
|
|
853
|
+
rotQ = quat.multiply(quat.create(), rotQ, rotZ);
|
|
854
|
+
var rotMatrix = mat4.fromQuat(mat4.create(), rotQ);
|
|
855
|
+
|
|
856
|
+
if (this.type === CAMERA_TYPE.ORBITING || this.type === CAMERA_TYPE.EXPLORING) {
|
|
857
|
+
mat4.translate(this.matrix, this.matrix, this.focalPoint);
|
|
858
|
+
mat4.multiply(this.matrix, this.matrix, rotMatrix);
|
|
859
|
+
mat4.translate(this.matrix, this.matrix, [0, 0, this.distance]);
|
|
860
|
+
} else if (this.type === CAMERA_TYPE.TRACKING) {
|
|
861
|
+
mat4.translate(this.matrix, this.matrix, this.position);
|
|
862
|
+
mat4.multiply(this.matrix, this.matrix, rotMatrix);
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
/**
|
|
866
|
+
* Sets the camera position in the camera matrix
|
|
867
|
+
*/
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
Camera.prototype._setPosition = function (x, y, z) {
|
|
871
|
+
this.position = createVec3(x, y, z);
|
|
872
|
+
var m = this.matrix;
|
|
873
|
+
m[12] = this.position[0];
|
|
874
|
+
m[13] = this.position[1];
|
|
875
|
+
m[14] = this.position[2];
|
|
876
|
+
m[15] = 1;
|
|
877
|
+
|
|
878
|
+
this._getOrthoMatrix();
|
|
879
|
+
};
|
|
880
|
+
/**
|
|
881
|
+
* Recalculates axes based on the current matrix
|
|
882
|
+
*/
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
Camera.prototype._getAxes = function () {
|
|
886
|
+
vec3.copy(this.right, createVec3(vec4.transformMat4(vec4.create(), [1, 0, 0, 0], this.matrix)));
|
|
887
|
+
vec3.copy(this.up, createVec3(vec4.transformMat4(vec4.create(), [0, 1, 0, 0], this.matrix)));
|
|
888
|
+
vec3.copy(this.forward, createVec3(vec4.transformMat4(vec4.create(), [0, 0, 1, 0], this.matrix)));
|
|
889
|
+
vec3.normalize(this.right, this.right);
|
|
890
|
+
vec3.normalize(this.up, this.up);
|
|
891
|
+
vec3.normalize(this.forward, this.forward);
|
|
892
|
+
};
|
|
893
|
+
/**
|
|
894
|
+
* Recalculates euler angles based on the current state
|
|
895
|
+
*/
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
Camera.prototype._getAngles = function () {
|
|
899
|
+
// Recalculates angles
|
|
900
|
+
var x = this.distanceVector[0];
|
|
901
|
+
var y = this.distanceVector[1];
|
|
902
|
+
var z = this.distanceVector[2];
|
|
903
|
+
var r = vec3.length(this.distanceVector); // FAST FAIL: If there is no distance we cannot compute angles
|
|
904
|
+
|
|
905
|
+
if (r === 0) {
|
|
906
|
+
this.elevation = 0;
|
|
907
|
+
this.azimuth = 0;
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
if (this.type === CAMERA_TYPE.TRACKING) {
|
|
912
|
+
this.elevation = Math.asin(y / r) * RAD_2_DEG;
|
|
913
|
+
this.azimuth = Math.atan2(-x, -z) * RAD_2_DEG;
|
|
914
|
+
} else {
|
|
915
|
+
if (this.rotateWorld) {
|
|
916
|
+
this.elevation = Math.asin(y / r) * RAD_2_DEG;
|
|
917
|
+
this.azimuth = Math.atan2(-x, -z) * RAD_2_DEG;
|
|
918
|
+
} else {
|
|
919
|
+
this.elevation = -Math.asin(y / r) * RAD_2_DEG;
|
|
920
|
+
this.azimuth = -Math.atan2(-x, -z) * RAD_2_DEG;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
/**
|
|
925
|
+
* 重新计算相机位置,只有 ORBITING 模式相机位置才会发生变化
|
|
926
|
+
*/
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
Camera.prototype._getPosition = function () {
|
|
930
|
+
vec3.copy(this.position, createVec3(vec4.transformMat4(vec4.create(), [0, 0, 0, 1], this.matrix))); // 相机位置变化,需要重新计算视距
|
|
931
|
+
|
|
932
|
+
this._getDistance();
|
|
933
|
+
};
|
|
934
|
+
/**
|
|
935
|
+
* 重新计算视点,只有 TRACKING 模式视点才会发生变化
|
|
936
|
+
*/
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
Camera.prototype._getFocalPoint = function () {
|
|
940
|
+
vec3.transformMat3(this.distanceVector, [0, 0, -this.distance], mat3.fromMat4(mat3.create(), this.matrix));
|
|
941
|
+
vec3.add(this.focalPoint, this.position, this.distanceVector); // 视点变化,需要重新计算视距
|
|
942
|
+
|
|
943
|
+
this._getDistance();
|
|
944
|
+
};
|
|
945
|
+
/**
|
|
946
|
+
* 重新计算视距
|
|
947
|
+
*/
|
|
948
|
+
|
|
949
|
+
|
|
950
|
+
Camera.prototype._getDistance = function () {
|
|
951
|
+
this.distanceVector = vec3.subtract(vec3.create(), this.focalPoint, this.position);
|
|
952
|
+
this.distance = vec3.length(this.distanceVector);
|
|
953
|
+
this.dollyingStep = this.distance / 100;
|
|
954
|
+
};
|
|
955
|
+
|
|
956
|
+
Camera.prototype._getOrthoMatrix = function () {
|
|
957
|
+
if (this.projectionMode !== CAMERA_PROJECTION_MODE.ORTHOGRAPHIC) {
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
var position = this.position;
|
|
962
|
+
var rotZ = quat.setAxisAngle(quat.create(), [0, 0, 1], -this.roll * Math.PI / 180);
|
|
963
|
+
mat4.fromRotationTranslationScaleOrigin(this.orthoMatrix, rotZ, vec3.fromValues((this.rright - this.left) / 2 - position[0], (this.bottom - this.top) / 2 - position[1], 0), vec3.fromValues(this.zoom, this.zoom, 1), position);
|
|
964
|
+
};
|
|
965
|
+
|
|
966
|
+
Camera.ProjectionMode = {
|
|
967
|
+
ORTHOGRAPHIC: 'ORTHOGRAPHIC',
|
|
968
|
+
PERSPECTIVE: 'PERSPECTIVE'
|
|
969
|
+
};
|
|
970
|
+
return Camera;
|
|
971
|
+
}(EventEmitter);
|
|
972
|
+
|
|
973
|
+
export { Camera };
|