From 5a09d9c59996eda812d833cd0e79a9fda682c63f Mon Sep 17 00:00:00 2001 From: xiaoiver Date: Sun, 28 Apr 2024 11:43:51 +0800 Subject: [PATCH] Release (#1673) * fix: sync proj & view matrix from webxr session (#1671) * fix: sync projection & view matrix from webxr session * chore: commit changeset * chore(release): bump version (#1672) Co-authored-by: github-actions[bot] --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] --- __tests__/demos/3d/force.ts | 31 ++++++++--- __tests__/demos/3d/webar.ts | 5 ++ packages/g-mobile-webgl/CHANGELOG.md | 7 +++ packages/g-mobile-webgl/package.json | 2 +- packages/g-plugin-3d/CHANGELOG.md | 7 +++ packages/g-plugin-3d/package.json | 2 +- .../g-plugin-device-renderer/CHANGELOG.md | 6 +++ .../g-plugin-device-renderer/package.json | 2 +- .../src/RenderGraphPlugin.ts | 53 ++++++++++--------- packages/g-web-components/CHANGELOG.md | 6 +++ packages/g-web-components/package.json | 2 +- packages/g-webgl/CHANGELOG.md | 7 +++ packages/g-webgl/package.json | 2 +- packages/g-webgpu/CHANGELOG.md | 7 +++ packages/g-webgpu/package.json | 2 +- 15 files changed, 104 insertions(+), 37 deletions(-) diff --git a/__tests__/demos/3d/force.ts b/__tests__/demos/3d/force.ts index de5417036..5a6b80141 100644 --- a/__tests__/demos/3d/force.ts +++ b/__tests__/demos/3d/force.ts @@ -4,7 +4,14 @@ import { forceManyBody, forceCenter, } from 'd3-force-3d'; -import { Line, Text, Rect, Image, Circle } from '../../../packages/g'; +import { + Line, + Text, + Rect, + Image, + Circle, + CanvasEvent, +} from '../../../packages/g'; import { SphereGeometry, MeshPhongMaterial, @@ -13,6 +20,7 @@ import { Plugin as Plugin3D, } from '../../../packages/g-plugin-3d'; import { Plugin as PluginControl } from '../../../packages/g-plugin-control'; +import { ARButton, DeviceRenderer } from '../../../packages/g-webgl'; // https://bl.ocks.org/vasturiano/f59675656258d3f490e9faa40828c0e7 const dataset = { @@ -1601,7 +1609,7 @@ const dataset = { }; export async function force(context) { - const { canvas, renderer } = context; + const { canvas, renderer, container } = context; // wait for canvas' initialization complete await canvas.ready; @@ -1655,9 +1663,9 @@ export async function force(context) { // create a mesh const sphere = new Mesh({ style: { - x: node.x + 300, - y: node.y + 250, - z: node.z, + // x: node.x + 300, + // y: node.y + 250, + // z: node.z, fill, opacity: 1, geometry: sphereGeometry, @@ -1665,6 +1673,7 @@ export async function force(context) { cursor: 'pointer', }, }); + sphere.setPosition(node.x + 300, node.y + 250, node.z); canvas.appendChild(sphere); sphere.addEventListener('mouseenter', () => { @@ -1758,7 +1767,17 @@ export async function force(context) { // adjust camera's position const camera = canvas.getCamera(); - camera.setPerspective(0.1, 5000, 45, 600 / 500); + camera.setPerspective(0.1, 5000, 45, 640 / 640); + + canvas.addEventListener(CanvasEvent.AFTER_RENDER, () => { + canvas.document.documentElement.setOrigin(320, 320, 0); + canvas.document.documentElement.rotate(0, 0.1, 0); + }); + + canvas.getConfig().disableHitTesting = true; + + const $button = ARButton.createButton(canvas, renderer, {}); + container.appendChild($button); } force.initRenderer = (renderer) => { diff --git a/__tests__/demos/3d/webar.ts b/__tests__/demos/3d/webar.ts index 316fbf733..ad0dadf22 100644 --- a/__tests__/demos/3d/webar.ts +++ b/__tests__/demos/3d/webar.ts @@ -27,6 +27,10 @@ export async function ar(context) { width: 200, height: 200, depth: 200, + + // width: 1, + // height: 1, + // depth: 1, }); const basicMaterial = new MeshBasicMaterial(device, { // wireframe: true, @@ -42,6 +46,7 @@ export async function ar(context) { }, }); + // cube.setOrigin(300, 250, 200); cube.setPosition(300, 250, 200); canvas.appendChild(cube); diff --git a/packages/g-mobile-webgl/CHANGELOG.md b/packages/g-mobile-webgl/CHANGELOG.md index 749a34f28..e00cffcec 100644 --- a/packages/g-mobile-webgl/CHANGELOG.md +++ b/packages/g-mobile-webgl/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-mobile-webgl +## 1.0.3 + +### Patch Changes + +- Updated dependencies [30c8eb0f] + - @antv/g-plugin-device-renderer@2.0.3 + ## 1.0.2 ### Patch Changes diff --git a/packages/g-mobile-webgl/package.json b/packages/g-mobile-webgl/package.json index 6d76a4f9a..422ba1d3c 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.2", + "version": "1.0.3", "description": "A renderer implemented by WebGL1/2 in mobile environment", "keywords": [ "antv", diff --git a/packages/g-plugin-3d/CHANGELOG.md b/packages/g-plugin-3d/CHANGELOG.md index ebff11ce5..fcfc74814 100644 --- a/packages/g-plugin-3d/CHANGELOG.md +++ b/packages/g-plugin-3d/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-plugin-3d +## 2.0.3 + +### Patch Changes + +- Updated dependencies [30c8eb0f] + - @antv/g-plugin-device-renderer@2.0.3 + ## 2.0.2 ### Patch Changes diff --git a/packages/g-plugin-3d/package.json b/packages/g-plugin-3d/package.json index 35699b8ef..d8edefd22 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.2", + "version": "2.0.3", "description": "Provide 3D extension for G", "keywords": [ "antv", diff --git a/packages/g-plugin-device-renderer/CHANGELOG.md b/packages/g-plugin-device-renderer/CHANGELOG.md index ded28c1c2..f8725de5b 100644 --- a/packages/g-plugin-device-renderer/CHANGELOG.md +++ b/packages/g-plugin-device-renderer/CHANGELOG.md @@ -1,5 +1,11 @@ # @antv/g-plugin-device-renderer +## 2.0.3 + +### Patch Changes + +- 30c8eb0f: Sync projection & view matrix from webxr session. + ## 2.0.2 ### Patch Changes diff --git a/packages/g-plugin-device-renderer/package.json b/packages/g-plugin-device-renderer/package.json index 972ea5751..a004235f7 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.2", + "version": "2.0.3", "description": "A G plugin of renderer implementation with GPUDevice", "keywords": [ "antv", diff --git a/packages/g-plugin-device-renderer/src/RenderGraphPlugin.ts b/packages/g-plugin-device-renderer/src/RenderGraphPlugin.ts index b4b68da3e..227c0b466 100644 --- a/packages/g-plugin-device-renderer/src/RenderGraphPlugin.ts +++ b/packages/g-plugin-device-renderer/src/RenderGraphPlugin.ts @@ -39,6 +39,7 @@ import { import type { BatchManager } from './renderer'; import type { TexturePool } from './TexturePool'; import { DeviceRendererPluginOptions } from './interfaces'; +import { mat4 } from 'gl-matrix'; // scene uniform block index export const SceneUniformBufferIndex = 0; @@ -257,6 +258,8 @@ export class RenderGraphPlugin implements RenderingPlugin { config.disableRenderHooks = false; }); + // let usedViewport: XRViewport | undefined; + /** * build frame graph at the beginning of each frame */ @@ -264,9 +267,9 @@ export class RenderGraphPlugin implements RenderingPlugin { RenderGraphPlugin.tag, (frame: XRFrame) => { const session = frame?.session; - // const { width, height } = this.context.config; + const { width, height } = this.context.config; if (session) { - // const camera = this.context.camera; + const camera = this.context.camera; // Assumed to be a XRWebGLLayer for now. let layer = session.renderState.baseLayer; if (!layer) { @@ -291,24 +294,26 @@ export class RenderGraphPlugin implements RenderingPlugin { if (pose) { // const p = pose.transform.position; // In mobile AR, we only have one view. - // const view = pose.views[0]; + 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; + // usedViewport = viewport; + // @ts-ignore + const cameraMatrix = mat4.fromValues(...view.transform.matrix); + cameraMatrix[12] *= width; + cameraMatrix[13] *= height; + cameraMatrix[14] *= 500; + + cameraMatrix[12] += width / 2; + cameraMatrix[13] += height / 2; + cameraMatrix[14] += 500 / 2; + // @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 projectionMatrix = mat4.fromValues(...view.projectionMatrix); + mat4.scale(projectionMatrix, projectionMatrix, [1, -1, 1]); // flipY + + // @ts-ignore + camera.setProjectionMatrix(projectionMatrix); + camera.setMatrix(cameraMatrix); } } @@ -370,6 +375,11 @@ export class RenderGraphPlugin implements RenderingPlugin { // main render pass this.builder.pushPass((pass) => { pass.setDebugName('Main Render Pass'); + // if (usedViewport) { + // const { x, y, width: vw, height: vh } = usedViewport; + // // pass.setViewport(x, y, vw / width / 2, vh / height / 2); + // console.log(x, y, vw, vh, width, height); + // } pass.attachRenderTargetID(RGAttachmentSlot.Color0, mainColorTargetID); pass.attachRenderTargetID( RGAttachmentSlot.DepthStencil, @@ -434,13 +444,6 @@ export class RenderGraphPlugin implements RenderingPlugin { // Update Scene Params const { width, height } = this.context.config; const camera = this.context.camera; - - // console.log( - // camera.getPerspective(), - // camera.getViewTransform(), - // camera.getPosition(), - // ); - template.setUniforms(SceneUniformBufferIndex, [ { name: SceneUniform.PROJECTION_MATRIX, diff --git a/packages/g-web-components/CHANGELOG.md b/packages/g-web-components/CHANGELOG.md index c16721c4d..649bafe12 100644 --- a/packages/g-web-components/CHANGELOG.md +++ b/packages/g-web-components/CHANGELOG.md @@ -1,5 +1,11 @@ # @antv/g-web-components +## 2.0.3 + +### Patch Changes + +- @antv/g-webgl@2.0.3 + ## 2.0.2 ### Patch Changes diff --git a/packages/g-web-components/package.json b/packages/g-web-components/package.json index 04e45a76a..5dfa5ab00 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.2", + "version": "2.0.3", "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 799125a5d..17ca3621f 100644 --- a/packages/g-webgl/CHANGELOG.md +++ b/packages/g-webgl/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-webgl +## 2.0.3 + +### Patch Changes + +- Updated dependencies [30c8eb0f] + - @antv/g-plugin-device-renderer@2.0.3 + ## 2.0.2 ### Patch Changes diff --git a/packages/g-webgl/package.json b/packages/g-webgl/package.json index f78755842..289076ed0 100644 --- a/packages/g-webgl/package.json +++ b/packages/g-webgl/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-webgl", - "version": "2.0.2", + "version": "2.0.3", "description": "A renderer implemented by WebGL1/2", "keywords": [ "antv", diff --git a/packages/g-webgpu/CHANGELOG.md b/packages/g-webgpu/CHANGELOG.md index f3de69777..9187ca539 100644 --- a/packages/g-webgpu/CHANGELOG.md +++ b/packages/g-webgpu/CHANGELOG.md @@ -1,5 +1,12 @@ # @antv/g-webgpu +## 2.0.3 + +### Patch Changes + +- Updated dependencies [30c8eb0f] + - @antv/g-plugin-device-renderer@2.0.3 + ## 2.0.2 ### Patch Changes diff --git a/packages/g-webgpu/package.json b/packages/g-webgpu/package.json index a33627ba5..5bf488bd1 100644 --- a/packages/g-webgpu/package.json +++ b/packages/g-webgpu/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g-webgpu", - "version": "2.0.2", + "version": "2.0.3", "description": "A renderer implemented by WebGPU", "keywords": [ "antv",