Skip to content

Commit

Permalink
Release (#1673)
Browse files Browse the repository at this point in the history
* 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] <github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 28, 2024
1 parent 520ff5e commit 5a09d9c
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 37 deletions.
31 changes: 25 additions & 6 deletions __tests__/demos/3d/force.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1655,16 +1663,17 @@ 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,
material,
cursor: 'pointer',
},
});
sphere.setPosition(node.x + 300, node.y + 250, node.z);
canvas.appendChild(sphere);

sphere.addEventListener('mouseenter', () => {
Expand Down Expand Up @@ -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) => {
Expand Down
5 changes: 5 additions & 0 deletions __tests__/demos/3d/webar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -42,6 +46,7 @@ export async function ar(context) {
},
});

// cube.setOrigin(300, 250, 200);
cube.setPosition(300, 250, 200);

canvas.appendChild(cube);
Expand Down
7 changes: 7 additions & 0 deletions packages/g-mobile-webgl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/g-mobile-webgl/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-plugin-3d/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/g-plugin-3d/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 6 additions & 0 deletions packages/g-plugin-device-renderer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/g-plugin-device-renderer/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
53 changes: 28 additions & 25 deletions packages/g-plugin-device-renderer/src/RenderGraphPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -257,16 +258,18 @@ export class RenderGraphPlugin implements RenderingPlugin {
config.disableRenderHooks = false;
});

// let usedViewport: XRViewport | undefined;

/**
* build frame graph at the beginning of each frame
*/
renderingService.hooks.beginFrame.tap(
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) {
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions packages/g-web-components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @antv/g-web-components

## 2.0.3

### Patch Changes

- @antv/g-webgl@2.0.3

## 2.0.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-web-components/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-webgl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/g-webgl/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-webgpu/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/g-webgpu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-webgpu",
"version": "2.0.2",
"version": "2.0.3",
"description": "A renderer implemented by WebGPU",
"keywords": [
"antv",
Expand Down

0 comments on commit 5a09d9c

Please sign in to comment.