diff --git a/__tests__/demos/3d/index.ts b/__tests__/demos/3d/index.ts index 245f6459b..114e25d29 100644 --- a/__tests__/demos/3d/index.ts +++ b/__tests__/demos/3d/index.ts @@ -3,3 +3,4 @@ export { sphere } from './sphere'; export { torus } from './torus'; export { cylinder } from './cylinder'; export { force } from './force'; +export { ar } from './webar'; diff --git a/__tests__/demos/3d/webar.ts b/__tests__/demos/3d/webar.ts new file mode 100644 index 000000000..316fbf733 --- /dev/null +++ b/__tests__/demos/3d/webar.ts @@ -0,0 +1,64 @@ +import { CanvasEvent } from '../../../packages/g'; +import { + MeshBasicMaterial, + CubeGeometry, + Mesh, + Plugin as Plugin3D, +} from '../../../packages/g-plugin-3d'; +import { Plugin as PluginControl } from '../../../packages/g-plugin-control'; +import { ARButton, DeviceRenderer } from '../../../packages/g-webgl'; + +export async function ar(context) { + const { canvas, renderer, container } = context; + + // wait for canvas' initialization complete + await canvas.ready; + + // use GPU device + const plugin = renderer.getPlugin('device-renderer') as DeviceRenderer.Plugin; + const device = plugin.getDevice(); + + // 1. load texture with URL + const map = plugin.loadTexture( + 'https://gw.alipayobjects.com/mdn/rms_6ae20b/afts/img/A*_aqoS73Se3sAAAAAAAAAAAAAARQnAQ', + ); + + const cubeGeometry = new CubeGeometry(device, { + width: 200, + height: 200, + depth: 200, + }); + const basicMaterial = new MeshBasicMaterial(device, { + // wireframe: true, + map, + }); + + const cube = new Mesh({ + style: { + fill: '#1890FF', + opacity: 1, + geometry: cubeGeometry, + material: basicMaterial, + }, + }); + + cube.setPosition(300, 250, 200); + + canvas.appendChild(cube); + + canvas.addEventListener(CanvasEvent.AFTER_RENDER, () => { + cube.rotate(1, 0, 0); + }); + + canvas.getConfig().disableHitTesting = true; + + const $button = ARButton.createButton(canvas, renderer, {}); + container.appendChild($button); +} + +ar.initRenderer = (renderer, type) => { + if (type === 'webgl' || type === 'webgpu') { + renderer.registerPlugin(new Plugin3D()); + renderer.registerPlugin(new PluginControl()); + } +}; diff --git a/__tests__/main.ts b/__tests__/main.ts index 3babf869e..c46aebfd6 100644 --- a/__tests__/main.ts +++ b/__tests__/main.ts @@ -189,6 +189,7 @@ function createSpecRender(object) { ], // Used for WebGPU renderer shaderCompilerPath: '/glsl_wgsl_compiler_bg.wasm', + // enableAutoRendering: false, // enableDirtyRectangleRendering: false, // enableDirtyRectangleRenderingDebug: true, }); diff --git a/packages/g-camera-api/CHANGELOG.md b/packages/g-camera-api/CHANGELOG.md index ce327c709..42859baea 100644 --- a/packages/g-camera-api/CHANGELOG.md +++ b/packages/g-camera-api/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-camera-api +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-camera-api/package.json b/packages/g-camera-api/package.json index ad8dfda80..c8c9a33a5 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.1", + "version": "2.0.2", "description": "A simple implementation of Camera API.", "keywords": [ "antv", diff --git a/packages/g-canvas/CHANGELOG.md b/packages/g-canvas/CHANGELOG.md index 28280ff2b..ad95f8494 100644 --- a/packages/g-canvas/CHANGELOG.md +++ b/packages/g-canvas/CHANGELOG.md @@ -1,5 +1,18 @@ # @antv/g-canvas +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + - @antv/g-plugin-canvas-path-generator@2.0.2 + - @antv/g-plugin-canvas-picker@2.0.2 + - @antv/g-plugin-canvas-renderer@2.0.2 + - @antv/g-plugin-dom-interaction@2.0.2 + - @antv/g-plugin-html-renderer@2.0.2 + - @antv/g-plugin-image-loader@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-canvas/package.json b/packages/g-canvas/package.json index d2e6d71f1..631c9427d 100644 --- a/packages/g-canvas/package.json +++ b/packages/g-canvas/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-canvas", - "version": "2.0.1", + "version": "2.0.2", "description": "A renderer implemented by Canvas 2D API", "keywords": [ "antv", diff --git a/packages/g-canvaskit/CHANGELOG.md b/packages/g-canvaskit/CHANGELOG.md index fb1eee592..9e35aa2fd 100644 --- a/packages/g-canvaskit/CHANGELOG.md +++ b/packages/g-canvaskit/CHANGELOG.md @@ -1,5 +1,18 @@ # @antv/g-canvaskit +## 1.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + - @antv/g-plugin-canvas-path-generator@2.0.2 + - @antv/g-plugin-canvas-picker@2.0.2 + - @antv/g-plugin-canvaskit-renderer@2.0.2 + - @antv/g-plugin-dom-interaction@2.0.2 + - @antv/g-plugin-html-renderer@2.0.2 + - @antv/g-plugin-image-loader@2.0.2 + ## 1.0.1 ### Patch Changes diff --git a/packages/g-canvaskit/package.json b/packages/g-canvaskit/package.json index 861a26dd9..c77bbb21e 100644 --- a/packages/g-canvaskit/package.json +++ b/packages/g-canvaskit/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-canvaskit", - "version": "1.0.1", + "version": "1.0.2", "description": "A renderer implemented by CanvasKit", "keywords": [ "antv", diff --git a/packages/g-components/CHANGELOG.md b/packages/g-components/CHANGELOG.md index 7c9848435..2b8a46442 100644 --- a/packages/g-components/CHANGELOG.md +++ b/packages/g-components/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-components +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-components/package.json b/packages/g-components/package.json index 1936c4e24..f630e8f56 100644 --- a/packages/g-components/package.json +++ b/packages/g-components/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-components", - "version": "2.0.1", + "version": "2.0.2", "description": "Components for g", "keywords": [ "antv", diff --git a/packages/g-dom-mutation-observer-api/CHANGELOG.md b/packages/g-dom-mutation-observer-api/CHANGELOG.md index 8949ae606..350ce1fab 100644 --- a/packages/g-dom-mutation-observer-api/CHANGELOG.md +++ b/packages/g-dom-mutation-observer-api/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-dom-mutation-observer-api +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-dom-mutation-observer-api/package.json b/packages/g-dom-mutation-observer-api/package.json index e25a4bae3..7e3b35b29 100644 --- a/packages/g-dom-mutation-observer-api/package.json +++ b/packages/g-dom-mutation-observer-api/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-dom-mutation-observer-api", - "version": "2.0.1", + "version": "2.0.2", "description": "A simple implementation of DOM MutationObserver API.", "keywords": [ "antv", diff --git a/packages/g-gesture/CHANGELOG.md b/packages/g-gesture/CHANGELOG.md index 936ae3453..958a4d7e1 100644 --- a/packages/g-gesture/CHANGELOG.md +++ b/packages/g-gesture/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-gesture +## 3.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 3.0.1 ### Patch Changes diff --git a/packages/g-gesture/package.json b/packages/g-gesture/package.json index b31450949..8826daa38 100644 --- a/packages/g-gesture/package.json +++ b/packages/g-gesture/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-gesture", - "version": "3.0.1", + "version": "3.0.2", "description": "G Gesture", "keywords": [ "antv", diff --git a/packages/g-image-exporter/CHANGELOG.md b/packages/g-image-exporter/CHANGELOG.md index 2d15aab4a..c6c73ca1f 100644 --- a/packages/g-image-exporter/CHANGELOG.md +++ b/packages/g-image-exporter/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-image-exporter +## 1.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 1.0.1 ### Patch Changes diff --git a/packages/g-image-exporter/package.json b/packages/g-image-exporter/package.json index ee3c99d12..2d319d848 100644 --- a/packages/g-image-exporter/package.json +++ b/packages/g-image-exporter/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-image-exporter", - "version": "1.0.1", + "version": "1.0.2", "description": "A image exporter for G using DOM API", "keywords": [ "antv", diff --git a/packages/g-lite/CHANGELOG.md b/packages/g-lite/CHANGELOG.md index 7f873dfe6..3d35dff88 100644 --- a/packages/g-lite/CHANGELOG.md +++ b/packages/g-lite/CHANGELOG.md @@ -1,5 +1,11 @@ # @antv/g-lite +## 2.0.2 + +### Patch Changes + +- 2948b0f8: Pass webxr frame on each tick when rendering. + ## 2.0.1 ### Patch Changes diff --git a/packages/g-lite/package.json b/packages/g-lite/package.json index 962260aef..148dfc6f7 100644 --- a/packages/g-lite/package.json +++ b/packages/g-lite/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-lite", - "version": "2.0.1", + "version": "2.0.2", "description": "A core module for rendering engine implements DOM API.", "keywords": [ "antv", @@ -53,7 +53,8 @@ "@types/d3-color": "^3.0.2", "@types/gl-matrix": "^2.4.5", "@types/offscreencanvas": "^2019.6.4", - "@types/rbush": "^3.0.0" + "@types/rbush": "^3.0.0", + "@types/webxr": "0.5.5" }, "publishConfig": { "access": "public" diff --git a/packages/g-lite/src/Canvas.ts b/packages/g-lite/src/Canvas.ts index 806eb057a..984394587 100644 --- a/packages/g-lite/src/Canvas.ts +++ b/packages/g-lite/src/Canvas.ts @@ -481,11 +481,11 @@ export class Canvas extends EventTarget implements ICanvas { this.document.documentElement.destroyChildren(); } - render() { + render(frame?: XRFrame) { this.dispatchEvent(beforeRenderEvent); const renderingService = this.getRenderingService(); - renderingService.render(this.getConfig(), () => { + renderingService.render(this.getConfig(), frame, () => { // trigger actual rerender event // @see https://github.com/antvis/G/issues/1268 this.dispatchEvent(rerenderEvent); @@ -495,11 +495,11 @@ export class Canvas extends EventTarget implements ICanvas { } private run() { - const tick = () => { - this.render(); + const tick = (time: number, frame?: XRFrame) => { + this.render(frame); this.frameId = this.requestAnimationFrame(tick); }; - tick(); + tick(0); } private initRenderer(renderer: IRenderer, firstContentfullPaint = false) { diff --git a/packages/g-lite/src/camera/Camera.ts b/packages/g-lite/src/camera/Camera.ts index b0955eda2..6fd153013 100644 --- a/packages/g-lite/src/camera/Camera.ts +++ b/packages/g-lite/src/camera/Camera.ts @@ -305,6 +305,13 @@ export class Camera implements ICamera { return this; } + /** + * Set projection matrix manually. + */ + setProjectionMatrix(matrix: mat4) { + this.projectionMatrix = matrix; + } + setFov(fov: number) { this.setPerspective(this.near, this.far, fov, this.aspect); return this; diff --git a/packages/g-lite/src/services/RenderingService.ts b/packages/g-lite/src/services/RenderingService.ts index 12b20a15a..d7113b231 100644 --- a/packages/g-lite/src/services/RenderingService.ts +++ b/packages/g-lite/src/services/RenderingService.ts @@ -84,7 +84,7 @@ export class RenderingService { /** * called at beginning of each frame, won't get called if nothing to re-render */ - beginFrame: new SyncHook<[]>(), + beginFrame: new SyncHook<[XRFrame]>(), /** * called before every dirty object get rendered */ @@ -97,7 +97,7 @@ export class RenderingService { * called after every dirty object get rendered */ afterRender: new SyncHook<[DisplayObject]>(), - endFrame: new SyncHook<[]>(), + endFrame: new SyncHook<[XRFrame]>(), destroy: new SyncHook<[]>(), /** * use async but faster method such as GPU-based picking in `g-plugin-device-renderer` @@ -161,7 +161,11 @@ export class RenderingService { ); } - render(canvasConfig: Partial, rerenderCallback: () => void) { + render( + canvasConfig: Partial, + frame: XRFrame, + rerenderCallback: () => void, + ) { this.stats.total = 0; this.stats.rendered = 0; this.zIndexCounter = 0; @@ -191,7 +195,7 @@ export class RenderingService { ); } - this.hooks.beginFrame.call(); + this.hooks.beginFrame.call(frame); if (shouldTriggerRenderHooks) { renderingContext.renderListCurrentFrame.forEach((object) => { @@ -201,7 +205,7 @@ export class RenderingService { }); } - this.hooks.endFrame.call(); + this.hooks.endFrame.call(frame); renderingContext.renderListCurrentFrame = []; renderingContext.renderReasons.clear(); diff --git a/packages/g-lottie-player/CHANGELOG.md b/packages/g-lottie-player/CHANGELOG.md index eed7c360c..57a2c4e9d 100644 --- a/packages/g-lottie-player/CHANGELOG.md +++ b/packages/g-lottie-player/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-lottie-player +## 1.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 1.0.1 ### Patch Changes diff --git a/packages/g-lottie-player/package.json b/packages/g-lottie-player/package.json index 60e79f541..8d6195204 100644 --- a/packages/g-lottie-player/package.json +++ b/packages/g-lottie-player/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-lottie-player", - "version": "1.0.1", + "version": "1.0.2", "description": "A lottie player for G", "keywords": [ "antv", diff --git a/packages/g-mobile-canvas-element/CHANGELOG.md b/packages/g-mobile-canvas-element/CHANGELOG.md index 602abcd3b..79fab995c 100644 --- a/packages/g-mobile-canvas-element/CHANGELOG.md +++ b/packages/g-mobile-canvas-element/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-mobile-canvas-element +## 1.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 1.0.1 ### Patch Changes diff --git a/packages/g-mobile-canvas-element/package.json b/packages/g-mobile-canvas-element/package.json index 2326ae1b3..c32454363 100644 --- a/packages/g-mobile-canvas-element/package.json +++ b/packages/g-mobile-canvas-element/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-mobile-canvas-element", - "version": "1.0.1", + "version": "1.0.2", "description": "Create a CanvasLike element from existed context in mobile environment", "keywords": [ "antv", diff --git a/packages/g-mobile-canvas/CHANGELOG.md b/packages/g-mobile-canvas/CHANGELOG.md index f4c94b2cd..f53fde022 100644 --- a/packages/g-mobile-canvas/CHANGELOG.md +++ b/packages/g-mobile-canvas/CHANGELOG.md @@ -1,5 +1,19 @@ # @antv/g-mobile-canvas +## 1.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + - @antv/g-plugin-canvas-path-generator@2.0.2 + - @antv/g-plugin-canvas-picker@2.0.2 + - @antv/g-plugin-canvas-renderer@2.0.2 + - @antv/g-plugin-dragndrop@2.0.2 + - @antv/g-plugin-gesture@2.0.2 + - @antv/g-plugin-image-loader@2.0.2 + - @antv/g-plugin-mobile-interaction@1.0.2 + ## 1.0.1 ### Patch Changes diff --git a/packages/g-mobile-canvas/package.json b/packages/g-mobile-canvas/package.json index 9a716ce3a..dbc4c4bd2 100644 --- a/packages/g-mobile-canvas/package.json +++ b/packages/g-mobile-canvas/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-mobile-canvas", - "version": "1.0.1", + "version": "1.0.2", "description": "A renderer implemented with Canvas2D API in mobile environment", "keywords": [ "antv", diff --git a/packages/g-mobile-svg/CHANGELOG.md b/packages/g-mobile-svg/CHANGELOG.md index 068c2c6cf..ac2564f64 100644 --- a/packages/g-mobile-svg/CHANGELOG.md +++ b/packages/g-mobile-svg/CHANGELOG.md @@ -1,5 +1,17 @@ # @antv/g-mobile-svg +## 1.0.3 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + - @antv/g-plugin-dragndrop@2.0.2 + - @antv/g-plugin-gesture@2.0.2 + - @antv/g-plugin-mobile-interaction@1.0.2 + - @antv/g-plugin-svg-picker@2.0.3 + - @antv/g-plugin-svg-renderer@2.0.3 + ## 1.0.2 ### Patch Changes diff --git a/packages/g-mobile-svg/package.json b/packages/g-mobile-svg/package.json index 1638761b6..f58619f8d 100644 --- a/packages/g-mobile-svg/package.json +++ b/packages/g-mobile-svg/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-mobile-svg", - "version": "1.0.2", + "version": "1.0.3", "description": "A renderer implemented by SVG in mobile environment", "keywords": [ "antv", diff --git a/packages/g-mobile-webgl/CHANGELOG.md b/packages/g-mobile-webgl/CHANGELOG.md index 4a154409c..749a34f28 100644 --- a/packages/g-mobile-webgl/CHANGELOG.md +++ b/packages/g-mobile-webgl/CHANGELOG.md @@ -1,5 +1,18 @@ # @antv/g-mobile-webgl +## 1.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-plugin-device-renderer@2.0.2 + - @antv/g-lite@2.0.2 + - @antv/g-plugin-dragndrop@2.0.2 + - @antv/g-plugin-gesture@2.0.2 + - @antv/g-plugin-html-renderer@2.0.2 + - @antv/g-plugin-image-loader@2.0.2 + - @antv/g-plugin-mobile-interaction@1.0.2 + ## 1.0.1 ### Patch Changes diff --git a/packages/g-mobile-webgl/package.json b/packages/g-mobile-webgl/package.json index 82b633034..6d76a4f9a 100644 --- a/packages/g-mobile-webgl/package.json +++ b/packages/g-mobile-webgl/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-mobile-webgl", - "version": "1.0.1", + "version": "1.0.2", "description": "A renderer implemented by WebGL1/2 in mobile environment", "keywords": [ "antv", diff --git a/packages/g-pattern/CHANGELOG.md b/packages/g-pattern/CHANGELOG.md index a270ed038..d80d89bc6 100644 --- a/packages/g-pattern/CHANGELOG.md +++ b/packages/g-pattern/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-pattern +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-pattern/package.json b/packages/g-pattern/package.json index 922fdc8da..3232b5a68 100644 --- a/packages/g-pattern/package.json +++ b/packages/g-pattern/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-pattern", - "version": "2.0.1", + "version": "2.0.2", "description": "A pattern libs for G", "keywords": [ "antv", diff --git a/packages/g-plugin-3d/CHANGELOG.md b/packages/g-plugin-3d/CHANGELOG.md index 38a7aeae1..ebff11ce5 100644 --- a/packages/g-plugin-3d/CHANGELOG.md +++ b/packages/g-plugin-3d/CHANGELOG.md @@ -1,5 +1,13 @@ # @antv/g-plugin-3d +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-plugin-device-renderer@2.0.2 + - @antv/g-lite@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-plugin-3d/package.json b/packages/g-plugin-3d/package.json index 7bffe39a4..35699b8ef 100644 --- a/packages/g-plugin-3d/package.json +++ b/packages/g-plugin-3d/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-3d", - "version": "2.0.1", + "version": "2.0.2", "description": "Provide 3D extension for G", "keywords": [ "antv", diff --git a/packages/g-plugin-a11y/CHANGELOG.md b/packages/g-plugin-a11y/CHANGELOG.md index 5edb0abe5..93d1216ef 100644 --- a/packages/g-plugin-a11y/CHANGELOG.md +++ b/packages/g-plugin-a11y/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-plugin-a11y +## 1.0.3 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 1.0.2 ### Patch Changes diff --git a/packages/g-plugin-a11y/package.json b/packages/g-plugin-a11y/package.json index 97c442cb7..3c31f5172 100644 --- a/packages/g-plugin-a11y/package.json +++ b/packages/g-plugin-a11y/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-a11y", - "version": "1.0.2", + "version": "1.0.3", "description": "A G plugin for accessibility", "keywords": [ "antv", diff --git a/packages/g-plugin-annotation/CHANGELOG.md b/packages/g-plugin-annotation/CHANGELOG.md index 305d831d6..454fd945b 100644 --- a/packages/g-plugin-annotation/CHANGELOG.md +++ b/packages/g-plugin-annotation/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-plugin-annotation +## 1.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 1.0.1 ### Patch Changes diff --git a/packages/g-plugin-annotation/package.json b/packages/g-plugin-annotation/package.json index 4cecd2bed..151b0c0fd 100644 --- a/packages/g-plugin-annotation/package.json +++ b/packages/g-plugin-annotation/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-annotation", - "version": "1.0.1", + "version": "1.0.2", "description": "A G plugin for annotation", "keywords": [ "antv", diff --git a/packages/g-plugin-box2d/CHANGELOG.md b/packages/g-plugin-box2d/CHANGELOG.md index edd084129..823f9f8a6 100644 --- a/packages/g-plugin-box2d/CHANGELOG.md +++ b/packages/g-plugin-box2d/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-plugin-box2d +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-plugin-box2d/package.json b/packages/g-plugin-box2d/package.json index 2f09668bc..d0da89b0b 100644 --- a/packages/g-plugin-box2d/package.json +++ b/packages/g-plugin-box2d/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-box2d", - "version": "2.0.1", + "version": "2.0.2", "description": "A G plugin for Box2D", "keywords": [ "antv", diff --git a/packages/g-plugin-canvas-path-generator/CHANGELOG.md b/packages/g-plugin-canvas-path-generator/CHANGELOG.md index 5dcb9b08b..f9e672744 100644 --- a/packages/g-plugin-canvas-path-generator/CHANGELOG.md +++ b/packages/g-plugin-canvas-path-generator/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-plugin-canvas-path-generator +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-plugin-canvas-path-generator/package.json b/packages/g-plugin-canvas-path-generator/package.json index 8e2a35f5e..697f9696c 100644 --- a/packages/g-plugin-canvas-path-generator/package.json +++ b/packages/g-plugin-canvas-path-generator/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-canvas-path-generator", - "version": "2.0.1", + "version": "2.0.2", "description": "A G plugin of path generator with Canvas2D API", "keywords": [ "antv", diff --git a/packages/g-plugin-canvas-picker/CHANGELOG.md b/packages/g-plugin-canvas-picker/CHANGELOG.md index 4d02297e6..a6ca3d6c4 100644 --- a/packages/g-plugin-canvas-picker/CHANGELOG.md +++ b/packages/g-plugin-canvas-picker/CHANGELOG.md @@ -1,5 +1,14 @@ # @antv/g-plugin-canvas-picker +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + - @antv/g-plugin-canvas-path-generator@2.0.2 + - @antv/g-plugin-canvas-renderer@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-plugin-canvas-picker/package.json b/packages/g-plugin-canvas-picker/package.json index 6db96b1b1..a12ab61b6 100644 --- a/packages/g-plugin-canvas-picker/package.json +++ b/packages/g-plugin-canvas-picker/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-canvas-picker", - "version": "2.0.1", + "version": "2.0.2", "description": "A G plugin for picking in canvas", "keywords": [ "antv", diff --git a/packages/g-plugin-canvas-renderer/CHANGELOG.md b/packages/g-plugin-canvas-renderer/CHANGELOG.md index d62290de5..01f90ec7b 100644 --- a/packages/g-plugin-canvas-renderer/CHANGELOG.md +++ b/packages/g-plugin-canvas-renderer/CHANGELOG.md @@ -1,5 +1,14 @@ # @antv/g-plugin-canvas-renderer +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + - @antv/g-plugin-canvas-path-generator@2.0.2 + - @antv/g-plugin-image-loader@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-plugin-canvas-renderer/package.json b/packages/g-plugin-canvas-renderer/package.json index c325570fa..f0740a4cb 100644 --- a/packages/g-plugin-canvas-renderer/package.json +++ b/packages/g-plugin-canvas-renderer/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-canvas-renderer", - "version": "2.0.1", + "version": "2.0.2", "description": "A G plugin of renderer implementation with Canvas2D API", "keywords": [ "antv", diff --git a/packages/g-plugin-canvaskit-renderer/CHANGELOG.md b/packages/g-plugin-canvaskit-renderer/CHANGELOG.md index 1b83a0dc9..1788f841f 100644 --- a/packages/g-plugin-canvaskit-renderer/CHANGELOG.md +++ b/packages/g-plugin-canvaskit-renderer/CHANGELOG.md @@ -1,5 +1,13 @@ # @antv/g-plugin-canvaskit-renderer +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + - @antv/g-plugin-image-loader@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-plugin-canvaskit-renderer/package.json b/packages/g-plugin-canvaskit-renderer/package.json index 8fb1644c1..8d071039b 100644 --- a/packages/g-plugin-canvaskit-renderer/package.json +++ b/packages/g-plugin-canvaskit-renderer/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-canvaskit-renderer", - "version": "2.0.1", + "version": "2.0.2", "description": "A G plugin of renderer implementation with CanvasKit", "keywords": [ "antv", diff --git a/packages/g-plugin-control/CHANGELOG.md b/packages/g-plugin-control/CHANGELOG.md index d2d24df5c..d9e9a41f7 100644 --- a/packages/g-plugin-control/CHANGELOG.md +++ b/packages/g-plugin-control/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-plugin-control +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-plugin-control/package.json b/packages/g-plugin-control/package.json index 486d11ef2..b19e431b2 100644 --- a/packages/g-plugin-control/package.json +++ b/packages/g-plugin-control/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-control", - "version": "2.0.1", + "version": "2.0.2", "description": "A G plugin for orbit control", "keywords": [ "antv", diff --git a/packages/g-plugin-css-select/CHANGELOG.md b/packages/g-plugin-css-select/CHANGELOG.md index 373be6c18..aa72727a1 100644 --- a/packages/g-plugin-css-select/CHANGELOG.md +++ b/packages/g-plugin-css-select/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-plugin-css-select +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-plugin-css-select/package.json b/packages/g-plugin-css-select/package.json index 7f8514694..a95aabc3d 100644 --- a/packages/g-plugin-css-select/package.json +++ b/packages/g-plugin-css-select/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-css-select", - "version": "2.0.1", + "version": "2.0.2", "description": "A G plugin for using CSS select syntax in query selector", "keywords": [ "antv", diff --git a/packages/g-plugin-device-renderer/CHANGELOG.md b/packages/g-plugin-device-renderer/CHANGELOG.md index 5ee23d3a3..ded28c1c2 100644 --- a/packages/g-plugin-device-renderer/CHANGELOG.md +++ b/packages/g-plugin-device-renderer/CHANGELOG.md @@ -1,5 +1,14 @@ # @antv/g-plugin-device-renderer +## 2.0.2 + +### Patch Changes + +- 2948b0f8: Pass webxr frame on each tick when rendering. +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + - @antv/g-plugin-image-loader@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-plugin-device-renderer/package.json b/packages/g-plugin-device-renderer/package.json index ae06110d1..972ea5751 100644 --- a/packages/g-plugin-device-renderer/package.json +++ b/packages/g-plugin-device-renderer/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-device-renderer", - "version": "2.0.1", + "version": "2.0.2", "description": "A G plugin of renderer implementation with GPUDevice", "keywords": [ "antv", @@ -54,6 +54,7 @@ "@rollup/plugin-wasm": "^5.1.2", "@types/earcut": "^2.1.1", "@types/offscreencanvas": "^2019.6.4", + "@types/webxr": "0.5.5", "glslify-import": "3.1.0", "rollup-plugin-glslify": "^1.2.1" }, diff --git a/packages/g-plugin-device-renderer/src/RenderGraphPlugin.ts b/packages/g-plugin-device-renderer/src/RenderGraphPlugin.ts index e195b5455..b4b68da3e 100644 --- a/packages/g-plugin-device-renderer/src/RenderGraphPlugin.ts +++ b/packages/g-plugin-device-renderer/src/RenderGraphPlugin.ts @@ -8,24 +8,25 @@ import type { RenderingPluginContext, } from '@antv/g-lite'; import { CanvasEvent, ElementEvent, Shape, parseColor } from '@antv/g-lite'; -import { Renderable3D } from './components/Renderable3D'; -import type { LightPool } from './LightPool'; -import { Fog, Light } from './lights'; -import { pushFXAAPass } from './passes/FXAA'; -import { +import type { + Color, Device, SwapChain, Texture, TextureDescriptor, - TransparentBlack, - TransparentWhite, } from '@antv/g-device-api'; import { BlendFactor, BlendMode, colorNewFromRGBA, setAttachmentStateSimple, + TransparentBlack, + TransparentWhite, } from '@antv/g-device-api'; +import { Renderable3D } from './components/Renderable3D'; +import type { LightPool } from './LightPool'; +import { Fog, Light } from './lights'; +import { pushFXAAPass } from './passes/FXAA'; import type { RGGraphBuilder, RenderHelper } from './render'; import { AntialiasingMode, @@ -259,175 +260,240 @@ export class RenderGraphPlugin implements RenderingPlugin { /** * build frame graph at the beginning of each frame */ - renderingService.hooks.beginFrame.tap(RenderGraphPlugin.tag, () => { - const canvas = this.swapChain.getCanvas() as HTMLCanvasElement; - const renderInstManager = this.renderHelper.renderInstManager; - this.builder = this.renderHelper.renderGraph.newGraphBuilder(); - - let clearColor; - if (this.context.config.background === 'transparent') { - clearColor = TransparentBlack; - } else { - // use canvas.background - const backgroundColor = parseColor( - this.context.config.background, - ) as CSSRGB; - - clearColor = this.context.config.background - ? // use premultipliedAlpha - // @see https://canvatechblog.com/alpha-blending-and-webgl-99feb392779e - colorNewFromRGBA( - (Number(backgroundColor.r) / 255) * Number(backgroundColor.alpha), - (Number(backgroundColor.g) / 255) * Number(backgroundColor.alpha), - (Number(backgroundColor.b) / 255) * Number(backgroundColor.alpha), - Number(backgroundColor.alpha), - ) - : TransparentWhite; - } + renderingService.hooks.beginFrame.tap( + RenderGraphPlugin.tag, + (frame: XRFrame) => { + const session = frame?.session; + // const { width, height } = this.context.config; + if (session) { + // const camera = this.context.camera; + // Assumed to be a XRWebGLLayer for now. + let layer = session.renderState.baseLayer; + if (!layer) { + layer = session.renderState.layers![0] as XRWebGLLayer; + } else { + // Bind the graphics framebuffer to the baseLayer's framebuffer. + // Only baseLayer has framebuffer and we need to bind it, even if it is null (for inline sessions). + // gl.bindFramebuffer(gl.FRAMEBUFFER, layer.framebuffer); + } - // retrieve at each frame since canvas may resize - const renderInput = { - backbufferWidth: canvas.width, - backbufferHeight: canvas.height, - antialiasingMode: AntialiasingMode.None, - }; - // create main Color RT - const mainRenderDesc = makeBackbufferDescSimple( - RGAttachmentSlot.Color0, - renderInput, - makeAttachmentClearDescriptor(clearColor), - ); - // create main Depth RT - const mainDepthDesc = makeBackbufferDescSimple( - RGAttachmentSlot.DepthStencil, - renderInput, - opaqueWhiteFullClearRenderPassDescriptor, - ); - const mainColorTargetID = this.builder.createRenderTargetID( - mainRenderDesc, - 'Main Color', - ); - const mainDepthTargetID = this.builder.createRenderTargetID( - mainDepthDesc, - 'Main Depth', - ); + this.swapChain.configureSwapChain( + layer.framebufferWidth, + layer.framebufferHeight, + layer.framebuffer, + ); + + // @ts-ignore + const referenceSpace = session.referenceSpace as XRReferenceSpace; + // Retrieve the pose of the device. + // XRFrame.getViewerPose can return null while the session attempts to establish tracking. + const pose = frame.getViewerPose(referenceSpace); + if (pose) { + // const p = pose.transform.position; + // In mobile AR, we only have one view. + // const view = pose.views[0]; + // const viewport = session.renderState.baseLayer!.getViewport(view)!; + // Use the view's transform matrix and projection matrix + // const viewMatrix = mat4.invert(mat4.create(), view.transform.matrix); + // const cameraMatrix = view.transform.matrix; + // const projectionMatrix = view.projectionMatrix; + // @ts-ignore + // camera.setProjectionMatrix(projectionMatrix); + // camera.setViewOffset( + // camera.getView().fullWidth, + // camera.getView().fullHeight, + // 0, + // 0, + // viewport.width, + // viewport.height, + // ); + // camera.setMatrix(cameraMatrix); + // console.log(viewport, camera.getView()); + } + } + + const canvas = this.swapChain.getCanvas() as HTMLCanvasElement; + const renderInstManager = this.renderHelper.renderInstManager; + this.builder = this.renderHelper.renderGraph.newGraphBuilder(); - // main render pass - this.builder.pushPass((pass) => { - pass.setDebugName('Main Render Pass'); - pass.attachRenderTargetID(RGAttachmentSlot.Color0, mainColorTargetID); - pass.attachRenderTargetID( + let clearColor: Color; + if (this.context.config.background === 'transparent') { + clearColor = TransparentBlack; + } else { + // use canvas.background + const backgroundColor = parseColor( + this.context.config.background, + ) as CSSRGB; + + clearColor = this.context.config.background + ? // use premultipliedAlpha + // @see https://canvatechblog.com/alpha-blending-and-webgl-99feb392779e + colorNewFromRGBA( + (Number(backgroundColor.r) / 255) * + Number(backgroundColor.alpha), + (Number(backgroundColor.g) / 255) * + Number(backgroundColor.alpha), + (Number(backgroundColor.b) / 255) * + Number(backgroundColor.alpha), + Number(backgroundColor.alpha), + ) + : TransparentWhite; + } + + // retrieve at each frame since canvas may resize + const renderInput = { + backbufferWidth: canvas.width, + backbufferHeight: canvas.height, + antialiasingMode: AntialiasingMode.None, + }; + // create main Color RT + const mainRenderDesc = makeBackbufferDescSimple( + RGAttachmentSlot.Color0, + renderInput, + makeAttachmentClearDescriptor(clearColor), + ); + // create main Depth RT + const mainDepthDesc = makeBackbufferDescSimple( RGAttachmentSlot.DepthStencil, - mainDepthTargetID, + renderInput, + opaqueWhiteFullClearRenderPassDescriptor, + ); + const mainColorTargetID = this.builder.createRenderTargetID( + mainRenderDesc, + 'Main Color', ); - pass.exec((passRenderer) => { - this.renderLists.world.drawOnPassRenderer( - renderInstManager.renderCache, - passRenderer, + const mainDepthTargetID = this.builder.createRenderTargetID( + mainDepthDesc, + 'Main Depth', + ); + + // main render pass + this.builder.pushPass((pass) => { + pass.setDebugName('Main Render Pass'); + pass.attachRenderTargetID(RGAttachmentSlot.Color0, mainColorTargetID); + pass.attachRenderTargetID( + RGAttachmentSlot.DepthStencil, + mainDepthTargetID, ); + pass.exec((passRenderer) => { + this.renderLists.world.drawOnPassRenderer( + renderInstManager.renderCache, + passRenderer, + ); + }); }); - }); - - // TODO: other post-processing passes - if (this.options?.enableFXAA) { - // FXAA - pushFXAAPass( - this.builder, - this.renderHelper, - renderInput, + + // TODO: other post-processing passes + if (this.options?.enableFXAA) { + // FXAA + pushFXAAPass( + this.builder, + this.renderHelper, + renderInput, + mainColorTargetID, + ); + } + + // output to screen + this.builder.resolveRenderTargetToExternalTexture( mainColorTargetID, + this.swapChain.getOnscreenTexture(), ); - } + }, + ); - // output to screen - this.builder.resolveRenderTargetToExternalTexture( - mainColorTargetID, - this.swapChain.getOnscreenTexture(), - ); - }); + renderingService.hooks.endFrame.tap( + RenderGraphPlugin.tag, + (frame: XRFrame) => { + const renderInstManager = this.renderHelper.renderInstManager; + + // TODO: time for GPU Animation + // const timeInMilliseconds = window.performance.now(); + + // Push our outer template, which contains the dynamic UBO bindings... + const template = this.renderHelper.pushTemplateRenderInst(); + // SceneParams: binding = 0, ObjectParams: binding = 1 + template.setBindingLayout({ numUniformBuffers: 2, numSamplers: 0 }); + template.setMegaStateFlags( + setAttachmentStateSimple( + { + depthWrite: true, + blendConstant: TransparentBlack, + }, + { + rgbBlendMode: BlendMode.ADD, + alphaBlendMode: BlendMode.ADD, + rgbBlendSrcFactor: BlendFactor.SRC_ALPHA, + alphaBlendSrcFactor: BlendFactor.ONE, + rgbBlendDstFactor: BlendFactor.ONE_MINUS_SRC_ALPHA, + alphaBlendDstFactor: BlendFactor.ONE_MINUS_SRC_ALPHA, + }, + ), + ); - renderingService.hooks.endFrame.tap(RenderGraphPlugin.tag, () => { - const renderInstManager = this.renderHelper.renderInstManager; + // Update Scene Params + const { width, height } = this.context.config; + const camera = this.context.camera; - // TODO: time for GPU Animation - // const timeInMilliseconds = window.performance.now(); + // console.log( + // camera.getPerspective(), + // camera.getViewTransform(), + // camera.getPosition(), + // ); - // Push our outer template, which contains the dynamic UBO bindings... - const template = this.renderHelper.pushTemplateRenderInst(); - // SceneParams: binding = 0, ObjectParams: binding = 1 - template.setBindingLayout({ numUniformBuffers: 2, numSamplers: 0 }); - template.setMegaStateFlags( - setAttachmentStateSimple( + template.setUniforms(SceneUniformBufferIndex, [ { - depthWrite: true, - blendConstant: TransparentBlack, + name: SceneUniform.PROJECTION_MATRIX, + value: camera.getPerspective(), }, { - rgbBlendMode: BlendMode.ADD, - alphaBlendMode: BlendMode.ADD, - rgbBlendSrcFactor: BlendFactor.SRC_ALPHA, - alphaBlendSrcFactor: BlendFactor.ONE, - rgbBlendDstFactor: BlendFactor.ONE_MINUS_SRC_ALPHA, - alphaBlendDstFactor: BlendFactor.ONE_MINUS_SRC_ALPHA, + name: SceneUniform.VIEW_MATRIX, + value: camera.getViewTransform(), }, - ), - ); + { + name: SceneUniform.CAMERA_POSITION, + value: camera.getPosition(), + }, + { + name: SceneUniform.DEVICE_PIXEL_RATIO, + value: this.context.contextService.getDPR(), + }, + { + name: SceneUniform.VIEWPORT, + value: [width, height], + }, + { + name: SceneUniform.IS_ORTHO, + value: camera.isOrtho() ? 1 : 0, + }, + { + name: SceneUniform.IS_PICKING, + value: 0, + }, + ]); - // Update Scene Params - const { width, height } = this.context.config; - const camera = this.context.camera; - template.setUniforms(SceneUniformBufferIndex, [ - { - name: SceneUniform.PROJECTION_MATRIX, - value: camera.getPerspective(), - }, - { - name: SceneUniform.VIEW_MATRIX, - value: camera.getViewTransform(), - }, - { - name: SceneUniform.CAMERA_POSITION, - value: camera.getPosition(), - }, - { - name: SceneUniform.DEVICE_PIXEL_RATIO, - value: this.context.contextService.getDPR(), - }, - { - name: SceneUniform.VIEWPORT, - value: [width, height], - }, - { - name: SceneUniform.IS_ORTHO, - value: camera.isOrtho() ? 1 : 0, - }, - { - name: SceneUniform.IS_PICKING, - value: 0, - }, - ]); - - this.batchManager.render(this.renderLists.world); - - renderInstManager.popTemplateRenderInst(); - - this.renderHelper.prepareToRender(); - this.renderHelper.renderGraph.execute(); - - renderInstManager.resetRenderInsts(); - - // capture here since we don't preserve drawing buffer - if (this.enableCapture && this.resolveCapturePromise) { - const { type, encoderOptions } = this.captureOptions; - const dataURL = ( - this.context.contextService.getDomElement() as HTMLCanvasElement - ).toDataURL(type, encoderOptions); - this.resolveCapturePromise(dataURL); - this.enableCapture = false; - this.captureOptions = undefined; - this.resolveCapturePromise = undefined; - } - }); + this.batchManager.render(this.renderLists.world); + + renderInstManager.popTemplateRenderInst(); + + this.renderHelper.prepareToRender(); + this.renderHelper.renderGraph.execute(); + + renderInstManager.resetRenderInsts(); + + // capture here since we don't preserve drawing buffer + if (this.enableCapture && this.resolveCapturePromise) { + const { type, encoderOptions } = this.captureOptions; + const dataURL = ( + this.context.contextService.getDomElement() as HTMLCanvasElement + ).toDataURL(type, encoderOptions); + this.resolveCapturePromise(dataURL); + this.enableCapture = false; + this.captureOptions = undefined; + this.resolveCapturePromise = undefined; + } + }, + ); } /** diff --git a/packages/g-plugin-device-renderer/src/drawcalls/Mesh.ts b/packages/g-plugin-device-renderer/src/drawcalls/Mesh.ts index 473a696fe..60f19c6a4 100644 --- a/packages/g-plugin-device-renderer/src/drawcalls/Mesh.ts +++ b/packages/g-plugin-device-renderer/src/drawcalls/Mesh.ts @@ -3,7 +3,7 @@ import { Shape } from '@antv/g-lite'; import type { Mesh } from '../Mesh'; import { Instanced } from './Instanced'; export class MeshDrawcall extends Instanced { - protected mergeXYZIntoModelMatrix = true; + protected mergeXYZIntoModelMatrix = false; shouldMerge(object: DisplayObject, index: number) { const shouldMerge = super.shouldMerge(object, index); diff --git a/packages/g-plugin-device-renderer/src/index.ts b/packages/g-plugin-device-renderer/src/index.ts index d91dcca4d..d2e2824f5 100644 --- a/packages/g-plugin-device-renderer/src/index.ts +++ b/packages/g-plugin-device-renderer/src/index.ts @@ -114,6 +114,10 @@ export class Plugin extends AbstractRendererPlugin { return this.getRenderGraphPlugin().getDevice(); } + getSwapChain() { + return this.getRenderGraphPlugin().getSwapChain(); + } + loadTexture( src: string | TexImageSource, descriptor?: TextureDescriptor, diff --git a/packages/g-plugin-dom-interaction/CHANGELOG.md b/packages/g-plugin-dom-interaction/CHANGELOG.md index a968aab72..7d1dd8f18 100644 --- a/packages/g-plugin-dom-interaction/CHANGELOG.md +++ b/packages/g-plugin-dom-interaction/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-plugin-dom-interaction +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-plugin-dom-interaction/package.json b/packages/g-plugin-dom-interaction/package.json index df4eb8f02..27dbde2be 100644 --- a/packages/g-plugin-dom-interaction/package.json +++ b/packages/g-plugin-dom-interaction/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-dom-interaction", - "version": "2.0.1", + "version": "2.0.2", "description": "A G plugin", "keywords": [ "antv", diff --git a/packages/g-plugin-dragndrop/CHANGELOG.md b/packages/g-plugin-dragndrop/CHANGELOG.md index f8b87e486..500d3e4fc 100644 --- a/packages/g-plugin-dragndrop/CHANGELOG.md +++ b/packages/g-plugin-dragndrop/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-plugin-dragndrop +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-plugin-dragndrop/package.json b/packages/g-plugin-dragndrop/package.json index b0e9845e7..fda2c2a3b 100644 --- a/packages/g-plugin-dragndrop/package.json +++ b/packages/g-plugin-dragndrop/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-dragndrop", - "version": "2.0.1", + "version": "2.0.2", "description": "A G plugin for Drag n Drop implemented with PointerEvents", "keywords": [ "antv", diff --git a/packages/g-plugin-gesture/CHANGELOG.md b/packages/g-plugin-gesture/CHANGELOG.md index 4d3ed5fe1..c9db385b7 100644 --- a/packages/g-plugin-gesture/CHANGELOG.md +++ b/packages/g-plugin-gesture/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-plugin-gesture +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-plugin-gesture/package.json b/packages/g-plugin-gesture/package.json index d5d98fd5b..560003ae8 100644 --- a/packages/g-plugin-gesture/package.json +++ b/packages/g-plugin-gesture/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-gesture", - "version": "2.0.1", + "version": "2.0.2", "description": "A G plugin for Gesture implemented with PointerEvents", "keywords": [ "antv", diff --git a/packages/g-plugin-html-renderer/CHANGELOG.md b/packages/g-plugin-html-renderer/CHANGELOG.md index 6922deb3f..1ebf54356 100644 --- a/packages/g-plugin-html-renderer/CHANGELOG.md +++ b/packages/g-plugin-html-renderer/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-plugin-html-renderer +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-plugin-html-renderer/package.json b/packages/g-plugin-html-renderer/package.json index 0ecefbeab..6b7a24c22 100644 --- a/packages/g-plugin-html-renderer/package.json +++ b/packages/g-plugin-html-renderer/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-html-renderer", - "version": "2.0.1", + "version": "2.0.2", "description": "A G plugin for rendering HTML", "keywords": [ "antv", diff --git a/packages/g-plugin-image-loader/CHANGELOG.md b/packages/g-plugin-image-loader/CHANGELOG.md index fde2acced..8fbeade57 100644 --- a/packages/g-plugin-image-loader/CHANGELOG.md +++ b/packages/g-plugin-image-loader/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-plugin-image-loader +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-plugin-image-loader/package.json b/packages/g-plugin-image-loader/package.json index fbcbbe5c9..460f60415 100644 --- a/packages/g-plugin-image-loader/package.json +++ b/packages/g-plugin-image-loader/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-image-loader", - "version": "2.0.1", + "version": "2.0.2", "description": "A G plugin for loading image", "keywords": [ "antv", diff --git a/packages/g-plugin-matterjs/CHANGELOG.md b/packages/g-plugin-matterjs/CHANGELOG.md index 0b5b87015..c461e104d 100644 --- a/packages/g-plugin-matterjs/CHANGELOG.md +++ b/packages/g-plugin-matterjs/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-plugin-matterjs +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-plugin-matterjs/package.json b/packages/g-plugin-matterjs/package.json index 72697aab7..ba1082f62 100644 --- a/packages/g-plugin-matterjs/package.json +++ b/packages/g-plugin-matterjs/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-matterjs", - "version": "2.0.1", + "version": "2.0.2", "description": "A G plugin for matter.js physics engine", "keywords": [ "antv", diff --git a/packages/g-plugin-mobile-interaction/CHANGELOG.md b/packages/g-plugin-mobile-interaction/CHANGELOG.md index 5bf3e3e29..4ac8a0392 100644 --- a/packages/g-plugin-mobile-interaction/CHANGELOG.md +++ b/packages/g-plugin-mobile-interaction/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-plugin-mobile-interaction +## 1.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 1.0.1 ### Patch Changes diff --git a/packages/g-plugin-mobile-interaction/package.json b/packages/g-plugin-mobile-interaction/package.json index 2a32613bb..f3b99fc22 100644 --- a/packages/g-plugin-mobile-interaction/package.json +++ b/packages/g-plugin-mobile-interaction/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-mobile-interaction", - "version": "1.0.1", + "version": "1.0.2", "description": "A G plugin listening events in mobile environment", "keywords": [ "antv", diff --git a/packages/g-plugin-physx/CHANGELOG.md b/packages/g-plugin-physx/CHANGELOG.md index daacb6533..a4322b9f6 100644 --- a/packages/g-plugin-physx/CHANGELOG.md +++ b/packages/g-plugin-physx/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-plugin-physx +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-plugin-physx/package.json b/packages/g-plugin-physx/package.json index a490c6f09..4579e48fe 100644 --- a/packages/g-plugin-physx/package.json +++ b/packages/g-plugin-physx/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-physx", - "version": "2.0.1", + "version": "2.0.2", "description": "A G plugin for PhysX", "keywords": [ "antv", diff --git a/packages/g-plugin-rough-canvas-renderer/CHANGELOG.md b/packages/g-plugin-rough-canvas-renderer/CHANGELOG.md index 08d6da266..b5762d575 100644 --- a/packages/g-plugin-rough-canvas-renderer/CHANGELOG.md +++ b/packages/g-plugin-rough-canvas-renderer/CHANGELOG.md @@ -1,5 +1,13 @@ # @antv/g-plugin-rough-canvas-renderer +## 2.0.3 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + - @antv/g-canvas@2.0.2 + ## 2.0.2 ### Patch Changes diff --git a/packages/g-plugin-rough-canvas-renderer/package.json b/packages/g-plugin-rough-canvas-renderer/package.json index 5d1a1bac5..37df92fc3 100644 --- a/packages/g-plugin-rough-canvas-renderer/package.json +++ b/packages/g-plugin-rough-canvas-renderer/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-rough-canvas-renderer", - "version": "2.0.2", + "version": "2.0.3", "description": "A G plugin of renderer implementation with rough.js", "keywords": [ "antv", diff --git a/packages/g-plugin-rough-svg-renderer/CHANGELOG.md b/packages/g-plugin-rough-svg-renderer/CHANGELOG.md index 8cbc218df..8b3f03fbf 100644 --- a/packages/g-plugin-rough-svg-renderer/CHANGELOG.md +++ b/packages/g-plugin-rough-svg-renderer/CHANGELOG.md @@ -1,5 +1,13 @@ # @antv/g-plugin-rough-svg-renderer +## 2.0.4 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + - @antv/g-svg@2.0.3 + ## 2.0.3 ### Patch Changes diff --git a/packages/g-plugin-rough-svg-renderer/package.json b/packages/g-plugin-rough-svg-renderer/package.json index b2733fdb6..394a70575 100644 --- a/packages/g-plugin-rough-svg-renderer/package.json +++ b/packages/g-plugin-rough-svg-renderer/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-rough-svg-renderer", - "version": "2.0.3", + "version": "2.0.4", "description": "A G plugin of renderer implementation with rough.js", "keywords": [ "antv", diff --git a/packages/g-plugin-svg-picker/CHANGELOG.md b/packages/g-plugin-svg-picker/CHANGELOG.md index d1294cd91..6bcea468c 100644 --- a/packages/g-plugin-svg-picker/CHANGELOG.md +++ b/packages/g-plugin-svg-picker/CHANGELOG.md @@ -1,5 +1,13 @@ # @antv/g-plugin-svg-picker +## 2.0.3 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + - @antv/g-plugin-svg-renderer@2.0.3 + ## 2.0.2 ### Patch Changes diff --git a/packages/g-plugin-svg-picker/package.json b/packages/g-plugin-svg-picker/package.json index 53cd51811..5b518b423 100644 --- a/packages/g-plugin-svg-picker/package.json +++ b/packages/g-plugin-svg-picker/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-svg-picker", - "version": "2.0.2", + "version": "2.0.3", "description": "A G plugin for picking in SVG", "keywords": [ "antv", diff --git a/packages/g-plugin-svg-renderer/CHANGELOG.md b/packages/g-plugin-svg-renderer/CHANGELOG.md index e59a83001..1dbbfda1b 100644 --- a/packages/g-plugin-svg-renderer/CHANGELOG.md +++ b/packages/g-plugin-svg-renderer/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-plugin-svg-renderer +## 2.0.3 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 2.0.2 ### Patch Changes diff --git a/packages/g-plugin-svg-renderer/package.json b/packages/g-plugin-svg-renderer/package.json index 7e1ec8d7a..aec9ebb70 100644 --- a/packages/g-plugin-svg-renderer/package.json +++ b/packages/g-plugin-svg-renderer/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-svg-renderer", - "version": "2.0.2", + "version": "2.0.3", "description": "A G plugin of renderer implementation with SVG", "keywords": [ "antv", diff --git a/packages/g-plugin-yoga/CHANGELOG.md b/packages/g-plugin-yoga/CHANGELOG.md index 5312024b6..3f460a7fb 100644 --- a/packages/g-plugin-yoga/CHANGELOG.md +++ b/packages/g-plugin-yoga/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-plugin-yoga +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-plugin-yoga/package.json b/packages/g-plugin-yoga/package.json index b80609233..ebd900fc3 100644 --- a/packages/g-plugin-yoga/package.json +++ b/packages/g-plugin-yoga/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-yoga", - "version": "2.0.1", + "version": "2.0.2", "description": "A G plugin for Yoga layout engine", "keywords": [ "antv", diff --git a/packages/g-plugin-zdog-canvas-renderer/CHANGELOG.md b/packages/g-plugin-zdog-canvas-renderer/CHANGELOG.md index 728d88da0..ff9ca8e9a 100644 --- a/packages/g-plugin-zdog-canvas-renderer/CHANGELOG.md +++ b/packages/g-plugin-zdog-canvas-renderer/CHANGELOG.md @@ -1,5 +1,13 @@ # @antv/g-plugin-zdog-canvas-renderer +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + - @antv/g-canvas@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-plugin-zdog-canvas-renderer/package.json b/packages/g-plugin-zdog-canvas-renderer/package.json index 036c83f40..87db323e3 100644 --- a/packages/g-plugin-zdog-canvas-renderer/package.json +++ b/packages/g-plugin-zdog-canvas-renderer/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-zdog-canvas-renderer", - "version": "2.0.1", + "version": "2.0.2", "description": "A G plugin of renderer implementation with Zdog", "keywords": [ "antv", diff --git a/packages/g-plugin-zdog-svg-renderer/CHANGELOG.md b/packages/g-plugin-zdog-svg-renderer/CHANGELOG.md index 2d0a5b436..c5477dea4 100644 --- a/packages/g-plugin-zdog-svg-renderer/CHANGELOG.md +++ b/packages/g-plugin-zdog-svg-renderer/CHANGELOG.md @@ -1,5 +1,14 @@ # @antv/g-plugin-zdog-svg-renderer +## 2.0.3 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + - @antv/g-plugin-svg-renderer@2.0.3 + - @antv/g-svg@2.0.3 + ## 2.0.2 ### Patch Changes diff --git a/packages/g-plugin-zdog-svg-renderer/package.json b/packages/g-plugin-zdog-svg-renderer/package.json index c47a5e2df..0e1cd62a2 100644 --- a/packages/g-plugin-zdog-svg-renderer/package.json +++ b/packages/g-plugin-zdog-svg-renderer/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-plugin-zdog-svg-renderer", - "version": "2.0.2", + "version": "2.0.3", "description": "A G plugin of renderer implementation with Zdog", "keywords": [ "antv", diff --git a/packages/g-svg/CHANGELOG.md b/packages/g-svg/CHANGELOG.md index 7af3b9994..61b3e90a9 100644 --- a/packages/g-svg/CHANGELOG.md +++ b/packages/g-svg/CHANGELOG.md @@ -1,5 +1,15 @@ # @antv/g-svg +## 2.0.3 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + - @antv/g-plugin-dom-interaction@2.0.2 + - @antv/g-plugin-svg-picker@2.0.3 + - @antv/g-plugin-svg-renderer@2.0.3 + ## 2.0.2 ### Patch Changes diff --git a/packages/g-svg/package.json b/packages/g-svg/package.json index bb82f8749..7348ec1b2 100644 --- a/packages/g-svg/package.json +++ b/packages/g-svg/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-svg", - "version": "2.0.2", + "version": "2.0.3", "description": "A renderer implemented by SVG", "keywords": [ "antv", diff --git a/packages/g-web-animations-api/CHANGELOG.md b/packages/g-web-animations-api/CHANGELOG.md index 2abbab80c..4f01d94e9 100644 --- a/packages/g-web-animations-api/CHANGELOG.md +++ b/packages/g-web-animations-api/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-web-animations-api +## 2.0.3 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + ## 2.0.2 ### Patch Changes diff --git a/packages/g-web-animations-api/package.json b/packages/g-web-animations-api/package.json index 1258cafba..7074932dd 100644 --- a/packages/g-web-animations-api/package.json +++ b/packages/g-web-animations-api/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-web-animations-api", - "version": "2.0.2", + "version": "2.0.3", "description": "A simple implementation of Web Animations API.", "keywords": [ "antv", diff --git a/packages/g-web-components/CHANGELOG.md b/packages/g-web-components/CHANGELOG.md index a2a9719cc..c16721c4d 100644 --- a/packages/g-web-components/CHANGELOG.md +++ b/packages/g-web-components/CHANGELOG.md @@ -1,5 +1,14 @@ # @antv/g-web-components +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-webgl@2.0.2 + - @antv/g-lite@2.0.2 + - @antv/g-canvas@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-web-components/package.json b/packages/g-web-components/package.json index 129237c93..04e45a76a 100644 --- a/packages/g-web-components/package.json +++ b/packages/g-web-components/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-web-components", - "version": "2.0.1", + "version": "2.0.2", "description": "A declarative usage for G implemented with WebComponents", "keywords": [ "antv", diff --git a/packages/g-webgl/CHANGELOG.md b/packages/g-webgl/CHANGELOG.md index c362e4b44..799125a5d 100644 --- a/packages/g-webgl/CHANGELOG.md +++ b/packages/g-webgl/CHANGELOG.md @@ -1,5 +1,17 @@ # @antv/g-webgl +## 2.0.2 + +### Patch Changes + +- 2948b0f8: Pass webxr frame on each tick when rendering. +- Updated dependencies [2948b0f8] + - @antv/g-plugin-device-renderer@2.0.2 + - @antv/g-lite@2.0.2 + - @antv/g-plugin-dom-interaction@2.0.2 + - @antv/g-plugin-html-renderer@2.0.2 + - @antv/g-plugin-image-loader@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-webgl/package.json b/packages/g-webgl/package.json index 7641c5ce8..f78755842 100644 --- a/packages/g-webgl/package.json +++ b/packages/g-webgl/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-webgl", - "version": "2.0.1", + "version": "2.0.2", "description": "A renderer implemented by WebGL1/2", "keywords": [ "antv", @@ -49,7 +49,8 @@ }, "devDependencies": { "@types/gl-matrix": "^2.4.5", - "@types/offscreencanvas": "^2019.6.4" + "@types/offscreencanvas": "^2019.6.4", + "@types/webxr": "0.5.5" }, "publishConfig": { "access": "public" diff --git a/packages/g-webgl/src/ARButton.ts b/packages/g-webgl/src/ARButton.ts new file mode 100644 index 000000000..f550e0124 --- /dev/null +++ b/packages/g-webgl/src/ARButton.ts @@ -0,0 +1,181 @@ +import { Canvas } from '@antv/g-lite'; +import { Renderer } from '.'; + +/** + * @see https://github.com/mrdoob/three.js/blob/master/examples/jsm/webxr/ARButton.js + * @example + * + * import { ARButton } from '@antv/g-webgl'; + * const $button = ARButton.createButton(renderer, { domOverlay: { root: document.body } }); + */ +export class ARButton { + static createButton( + canvas: Canvas, + renderer: Renderer, + sessionInit: XRSessionInit = {}, + ) { + const button = document.createElement('button'); + + const disableButton = () => { + button.style.display = ''; + + button.style.cursor = 'auto'; + button.style.left = 'calc(50% - 75px)'; + button.style.width = '150px'; + + button.onmouseenter = null; + button.onmouseleave = null; + + button.onclick = null; + }; + + const showARNotSupported = () => { + disableButton(); + button.textContent = 'AR NOT SUPPORTED'; + }; + + const showARNotAllowed = (exception: Error) => { + disableButton(); + + console.warn( + 'Exception when trying to call xr.isSessionSupported', + exception, + ); + + button.textContent = 'AR NOT ALLOWED'; + }; + + const stylizeElement = (element: HTMLElement) => { + element.style.position = 'absolute'; + element.style.bottom = '20px'; + element.style.padding = '12px 6px'; + element.style.border = '1px solid #fff'; + element.style.borderRadius = '4px'; + element.style.background = 'rgba(0,0,0,0.1)'; + element.style.color = '#fff'; + element.style.font = 'normal 13px sans-serif'; + element.style.textAlign = 'center'; + element.style.opacity = '0.5'; + element.style.outline = 'none'; + element.style.zIndex = '999'; + }; + + const showStartAR = () => { + let currentSession: XRSession; + button.style.display = ''; + button.style.cursor = 'pointer'; + button.style.left = 'calc(50% - 50px)'; + button.style.width = '100px'; + button.textContent = 'START AR'; + + const onSessionEnded = () => { + currentSession.removeEventListener('end', onSessionEnded); + + button.textContent = 'START AR'; + (sessionInit.domOverlay.root as HTMLElement).style.display = 'none'; + currentSession = undefined; + }; + + const onSessionStarted = async (session: XRSession) => { + session.addEventListener('end', onSessionEnded); + + renderer.xr.setReferenceSpaceType('local'); + + await renderer.xr.setSession(canvas, session); + + button.textContent = 'STOP AR'; + (sessionInit.domOverlay.root as HTMLElement).style.display = ''; + currentSession = session; + }; + + if (sessionInit.domOverlay === undefined) { + const overlay = document.createElement('div'); + overlay.style.display = 'none'; + document.body.appendChild(overlay); + + const svg = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'svg', + ); + svg.setAttribute('width', '38'); + svg.setAttribute('height', '38'); + svg.style.position = 'absolute'; + svg.style.right = '20px'; + svg.style.top = '20px'; + svg.addEventListener('click', function () { + currentSession.end(); + }); + overlay.appendChild(svg); + + const path = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'path', + ); + path.setAttribute('d', 'M 12,12 L 28,28 M 28,12 12,28'); + path.setAttribute('stroke', '#fff'); + path.setAttribute('stroke-width', '2'); + svg.appendChild(path); + + if (sessionInit.optionalFeatures === undefined) { + sessionInit.optionalFeatures = []; + } + + sessionInit.optionalFeatures.push('dom-overlay'); + sessionInit.domOverlay = { root: overlay }; + } + + /** + * Bind event listeners to button. + */ + button.onclick = () => { + if (!currentSession) { + navigator.xr + .requestSession('immersive-ar', sessionInit) + .then(onSessionStarted); + } else { + currentSession.end(); + } + }; + button.onmouseenter = () => { + button.style.opacity = '1.0'; + }; + button.onmouseleave = () => { + button.style.opacity = '0.5'; + }; + }; + + if ('xr' in navigator) { + button.id = 'ARButton'; + button.style.display = 'none'; + + stylizeElement(button); + + navigator.xr + .isSessionSupported('immersive-ar') + .then(function (supported) { + supported ? showStartAR() : showARNotSupported(); + }) + .catch(showARNotAllowed); + + return button; + } else { + const message = document.createElement('a'); + + if (window.isSecureContext === false) { + message.href = document.location.href.replace(/^http:/, 'https:'); + message.innerHTML = 'WEBXR NEEDS HTTPS'; // TODO Improve message + } else { + message.href = 'https://immersiveweb.dev/'; + message.innerHTML = 'WEBXR NOT AVAILABLE'; + } + + message.style.left = 'calc(50% - 90px)'; + message.style.width = '180px'; + message.style.textDecoration = 'none'; + + stylizeElement(message); + + return message; + } + } +} diff --git a/packages/g-webgl/src/WebXRManager.ts b/packages/g-webgl/src/WebXRManager.ts new file mode 100644 index 000000000..a50ce577d --- /dev/null +++ b/packages/g-webgl/src/WebXRManager.ts @@ -0,0 +1,98 @@ +import { Canvas } from '@antv/g-lite'; +import { DeviceRenderer } from '.'; + +export class WebXRManager { + private session: XRSession; + private referenceSpaceType: XRReferenceSpaceType; + private referenceSpace: XRReferenceSpace; + private glBaseLayer: XRWebGLLayer; + + constructor(private plugin: DeviceRenderer.Plugin) {} + + async setSession(canvas: Canvas, session: XRSession) { + if (session) { + this.session = session; + const gl = this.plugin.getDevice()['gl'] as WebGL2RenderingContext; + // const swapChain = this.plugin.getSwapChain(); + const attributes = gl.getContextAttributes(); + + if (attributes.xrCompatible !== true) { + // @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/makeXRCompatible + await gl.makeXRCompatible(); + } + + // session.addEventListener('select', this.onSessionEvent); + session.addEventListener('end', this.onSessionEnd); + + if (session.renderState.layers === undefined) { + const layerInit = { + antialias: attributes.antialias, + alpha: true, + depth: attributes.depth, + stencil: attributes.stencil, + framebufferScaleFactor: 1.0, + }; + + this.glBaseLayer = new XRWebGLLayer(session, gl, layerInit); + session.updateRenderState({ baseLayer: this.glBaseLayer }); + + this.referenceSpace = await session.requestReferenceSpace( + this.referenceSpaceType, + ); + + // @ts-ignore + session.referenceSpace = this.referenceSpace; + } + + canvas.requestAnimationFrame = + session.requestAnimationFrame.bind(session); + + // const onXRFrame: XRFrameRequestCallback = (time, frame) => { + // // Assumed to be a XRWebGLLayer for now. + // let layer = session.renderState.baseLayer; + // if (!layer) { + // layer = session.renderState.layers![0] as XRWebGLLayer; + // } else { + // // Bind the graphics framebuffer to the baseLayer's framebuffer. + // // Only baseLayer has framebuffer and we need to bind it, even if it is null (for inline sessions). + // // gl.bindFramebuffer(gl.FRAMEBUFFER, layer.framebuffer); + // } + + // swapChain.configureSwapChain( + // layer.framebufferWidth, + // layer.framebufferHeight, + // layer.framebuffer, + // ); + + // // Retrieve the pose of the device. + // // XRFrame.getViewerPose can return null while the session attempts to establish tracking. + // const pose = frame.getViewerPose(this.referenceSpace); + // if (pose) { + // const p = pose.transform.position; + + // // In mobile AR, we only have one view. + // const view = pose.views[0]; + // const viewport = session.renderState.baseLayer!.getViewport(view)!; + + // // Use the view's transform matrix and projection matrix + // // const viewMatrix = mat4.invert(mat4.create(), view.transform.matrix); + // const viewMatrix = view.transform.inverse.matrix; + // const projectionMatrix = view.projectionMatrix; + // } + + // // Queue up the next draw request. + // session.requestAnimationFrame(onXRFrame); + // }; + + // session.requestAnimationFrame(onXRFrame); + } + } + + setReferenceSpaceType(referenceSpaceType: XRReferenceSpaceType) { + this.referenceSpaceType = referenceSpaceType; + } + + private onSessionEnd = () => { + this.session.removeEventListener('end', this.onSessionEnd); + }; +} diff --git a/packages/g-webgl/src/index.ts b/packages/g-webgl/src/index.ts index 4a86426c2..e1285afc6 100644 --- a/packages/g-webgl/src/index.ts +++ b/packages/g-webgl/src/index.ts @@ -5,8 +5,11 @@ import * as DomInteraction from '@antv/g-plugin-dom-interaction'; import * as HTMLRenderer from '@antv/g-plugin-html-renderer'; import * as ImageLoader from '@antv/g-plugin-image-loader'; import { ContextRegisterPlugin } from './ContextRegisterPlugin'; +import { WebXRManager } from './WebXRManager'; export { DomInteraction, DeviceRenderer, HTMLRenderer }; +export { ARButton } from './ARButton'; +export { WebXRManager } from './WebXRManager'; export interface WebGLRendererConfig extends RendererConfig { targets: ('webgl1' | 'webgl2')[]; @@ -17,6 +20,8 @@ export interface WebGLRendererConfig extends RendererConfig { } export class Renderer extends AbstractRenderer { + xr: WebXRManager; + constructor(config?: Partial) { super({ enableSizeAttenuation: false, @@ -24,6 +29,7 @@ export class Renderer extends AbstractRenderer { }); const deviceRendererPlugin = new DeviceRenderer.Plugin(config); + this.xr = new WebXRManager(deviceRendererPlugin); this.registerPlugin( new ContextRegisterPlugin(deviceRendererPlugin, config), diff --git a/packages/g-webgpu/CHANGELOG.md b/packages/g-webgpu/CHANGELOG.md index 83fec12e2..f3de69777 100644 --- a/packages/g-webgpu/CHANGELOG.md +++ b/packages/g-webgpu/CHANGELOG.md @@ -1,5 +1,16 @@ # @antv/g-webgpu +## 2.0.2 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-plugin-device-renderer@2.0.2 + - @antv/g-lite@2.0.2 + - @antv/g-plugin-dom-interaction@2.0.2 + - @antv/g-plugin-html-renderer@2.0.2 + - @antv/g-plugin-image-loader@2.0.2 + ## 2.0.1 ### Patch Changes diff --git a/packages/g-webgpu/package.json b/packages/g-webgpu/package.json index 573907528..a33627ba5 100644 --- a/packages/g-webgpu/package.json +++ b/packages/g-webgpu/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-webgpu", - "version": "2.0.1", + "version": "2.0.2", "description": "A renderer implemented by WebGPU", "keywords": [ "antv", diff --git a/packages/g/CHANGELOG.md b/packages/g/CHANGELOG.md index f505c2936..ee37877d7 100644 --- a/packages/g/CHANGELOG.md +++ b/packages/g/CHANGELOG.md @@ -1,5 +1,15 @@ # @antv/g +## 6.0.3 + +### Patch Changes + +- Updated dependencies [2948b0f8] + - @antv/g-lite@2.0.2 + - @antv/g-camera-api@2.0.2 + - @antv/g-dom-mutation-observer-api@2.0.2 + - @antv/g-web-animations-api@2.0.3 + ## 6.0.2 ### Patch Changes diff --git a/packages/g/package.json b/packages/g/package.json index 236dee758..d6ced37e7 100644 --- a/packages/g/package.json +++ b/packages/g/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g", - "version": "6.0.2", + "version": "6.0.3", "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 b11ec2500..2b3228a90 100644 --- a/packages/react-g/CHANGELOG.md +++ b/packages/react-g/CHANGELOG.md @@ -1,5 +1,11 @@ # @antv/react-g +## 2.0.3 + +### Patch Changes + +- @antv/g@6.0.3 + ## 2.0.2 ### Patch Changes diff --git a/packages/react-g/package.json b/packages/react-g/package.json index 4a8f80246..f985850ca 100644 --- a/packages/react-g/package.json +++ b/packages/react-g/package.json @@ -1,6 +1,6 @@ { "name": "@antv/react-g", - "version": "2.0.2", + "version": "2.0.3", "description": "react render for @antv/g", "keywords": [ "react", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6c020f1fa..f3be6a19e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -354,6 +354,9 @@ importers: '@types/rbush': specifier: ^3.0.0 version: 3.0.0 + '@types/webxr': + specifier: 0.5.5 + version: 0.5.5 packages/g-lottie-player: dependencies: @@ -742,6 +745,9 @@ importers: '@types/offscreencanvas': specifier: ^2019.6.4 version: 2019.6.4 + '@types/webxr': + specifier: 0.5.5 + version: 0.5.5 glslify-import: specifier: 3.1.0 version: 3.1.0 @@ -1069,6 +1075,9 @@ importers: '@types/offscreencanvas': specifier: ^2019.6.4 version: 2019.6.4 + '@types/webxr': + specifier: 0.5.5 + version: 0.5.5 packages/g-webgpu: dependencies: @@ -2633,6 +2642,10 @@ packages: resolution: {integrity: sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA==} dev: true + /@types/webxr@0.5.5: + resolution: {integrity: sha512-HVOsSRTQYx3zpVl0c0FBmmmcY/60BkQLzVnpE9M1aG4f2Z0aKlBWfj4XZ2zr++XNBfkQWYcwhGlmuu44RJPDqg==} + dev: true + /@types/yargs-parser@21.0.3: resolution: {integrity: sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==} dev: true