diff --git a/__tests__/demos/plugin/camera.ts b/__tests__/demos/plugin/camera.ts new file mode 100644 index 000000000..135663c50 --- /dev/null +++ b/__tests__/demos/plugin/camera.ts @@ -0,0 +1,26 @@ +import { Circle } from '../../../packages/g'; + +export async function camera(context) { + const { canvas } = context; + await canvas.ready; + + const circle = new Circle({ + style: { + cx: 10, + cy: 10, + r: 10, + fill: 'red', + }, + }); + + canvas.appendChild(circle); + + const camera = canvas.getCamera(); + + const landmark = camera.createLandmark('camera', { + position: [200, 200, 500], + focalPoint: [200, 200, 0], + }); + + camera.gotoLandmark(landmark, { duration: 0 }); +} diff --git a/__tests__/demos/plugin/index.ts b/__tests__/demos/plugin/index.ts index d09b9735b..81f5f5057 100644 --- a/__tests__/demos/plugin/index.ts +++ b/__tests__/demos/plugin/index.ts @@ -8,3 +8,4 @@ export { annotation } from './annotation'; export { exporter } from './exporter'; // export { yogaText } from './yoga-text'; export { a11y } from './a11y'; +export { camera } from './camera'; diff --git a/packages/g-camera-api/CHANGELOG.md b/packages/g-camera-api/CHANGELOG.md index 6d879bb39..ce4057468 100644 --- a/packages/g-camera-api/CHANGELOG.md +++ b/packages/g-camera-api/CHANGELOG.md @@ -1,5 +1,11 @@ # @antv/g-camera-api +## 2.0.8 + +### Patch Changes + +- a098d3ef: fix goto landmark + ## 2.0.7 ### Patch Changes diff --git a/packages/g-camera-api/package.json b/packages/g-camera-api/package.json index a32b87b1a..6cdfa95f3 100644 --- a/packages/g-camera-api/package.json +++ b/packages/g-camera-api/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-camera-api", - "version": "2.0.7", + "version": "2.0.8", "description": "A simple implementation of Camera API.", "keywords": [ "antv", diff --git a/packages/g-camera-api/src/AdvancedCamera.ts b/packages/g-camera-api/src/AdvancedCamera.ts index c3b526908..b11bab618 100644 --- a/packages/g-camera-api/src/AdvancedCamera.ts +++ b/packages/g-camera-api/src/AdvancedCamera.ts @@ -215,14 +215,6 @@ export class AdvancedCamera extends Camera { } = isNumber(options) ? { duration: options } : options; const epsilon = 0.01; - if (duration === 0) { - this.syncFromLandmark(landmark); - if (onfinish) { - onfinish(); - } - return; - } - // cancel ongoing animation this.cancelLandmarkAnimation(); @@ -234,18 +226,18 @@ export class AdvancedCamera extends Camera { const easingFunc = easingFunction || runtime.EasingFunction(easing); let timeStart: number | undefined; - const endAnimation = () => { + const end = () => { this.setFocalPoint(destFocalPoint); this.setPosition(destPosition); this.setRoll(destRoll); this.setZoom(destZoom); this.computeMatrix(); this.triggerUpdate(); - if (onfinish) { - onfinish(); - } + onfinish?.(); }; + if (duration === 0) return end(); + const animate = (timestamp: number) => { if (timeStart === undefined) { timeStart = timestamp; @@ -253,7 +245,7 @@ export class AdvancedCamera extends Camera { const elapsed = timestamp - timeStart; if (elapsed >= duration) { - endAnimation(); + end(); return; } // use the same ease function in animation system @@ -278,17 +270,14 @@ export class AdvancedCamera extends Camera { vec3.dist(interFocalPoint, destFocalPoint) + vec3.dist(interPosition, destPosition); if (dist <= epsilon && destZoom == undefined && destRoll == undefined) { - endAnimation(); - return; + return end(); } this.computeMatrix(); this.triggerUpdate(); if (elapsed < duration) { - if (onframe) { - onframe(t); - } + onframe?.(t); this.landmarkAnimationID = this.canvas.requestAnimationFrame(animate); } }; @@ -297,29 +286,6 @@ export class AdvancedCamera extends Camera { } } - private syncFromLandmark(landmark: Landmark) { - this.matrix = mat4.copy(this.matrix, landmark.matrix); - this.right = vec3.copy(this.right, landmark.right); - this.up = vec3.copy(this.up, landmark.up); - this.forward = vec3.copy(this.forward, landmark.forward); - this.position = vec3.copy(this.position, landmark.position); - this.focalPoint = vec3.copy(this.focalPoint, landmark.focalPoint); - this.distanceVector = vec3.copy( - this.distanceVector, - landmark.distanceVector, - ); - - this.azimuth = landmark.azimuth; - this.elevation = landmark.elevation; - this.roll = landmark.roll; - this.relAzimuth = landmark.relAzimuth; - this.relElevation = landmark.relElevation; - this.relRoll = landmark.relRoll; - this.dollyingStep = landmark.dollyingStep; - this.distance = landmark.distance; - this.zoom = landmark.zoom; - } - /** * Sets the camera to a distance such that the area covered by the bounding box is viewed. */ diff --git a/packages/g/CHANGELOG.md b/packages/g/CHANGELOG.md index e1cd19362..ea65e225c 100644 --- a/packages/g/CHANGELOG.md +++ b/packages/g/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g +## 6.0.9 + +### Patch Changes + +- Updated dependencies [a098d3ef] + - @antv/g-camera-api@2.0.8 + ## 6.0.8 ### Patch Changes diff --git a/packages/g/package.json b/packages/g/package.json index f9b0150f5..81dbe2ddc 100644 --- a/packages/g/package.json +++ b/packages/g/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g", - "version": "6.0.8", + "version": "6.0.9", "description": "A core module for rendering engine implements DOM API.", "keywords": [ "antv", diff --git a/packages/react-g/CHANGELOG.md b/packages/react-g/CHANGELOG.md index 99635bcd2..2b764ef6d 100644 --- a/packages/react-g/CHANGELOG.md +++ b/packages/react-g/CHANGELOG.md @@ -1,5 +1,11 @@ # @antv/react-g +## 2.0.9 + +### Patch Changes + +- @antv/g@6.0.9 + ## 2.0.8 ### Patch Changes diff --git a/packages/react-g/package.json b/packages/react-g/package.json index 5e424cd2b..2e32c37e9 100644 --- a/packages/react-g/package.json +++ b/packages/react-g/package.json @@ -1,6 +1,6 @@ { "name": "@antv/react-g", - "version": "2.0.8", + "version": "2.0.9", "description": "react render for @antv/g", "keywords": [ "react",