Skip to content

Commit

Permalink
Release (#1670)
Browse files Browse the repository at this point in the history
* feat: support ar in webxr (#1665)

* feat: support ar in webxr

* feat: each tick on canvas will pass webxr frame

* chore: commit changeset

* chore(release): bump version (#1669)

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 24, 2024
1 parent ee938ca commit 520ff5e
Show file tree
Hide file tree
Showing 107 changed files with 1,055 additions and 219 deletions.
1 change: 1 addition & 0 deletions __tests__/demos/3d/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { sphere } from './sphere';
export { torus } from './torus';
export { cylinder } from './cylinder';
export { force } from './force';
export { ar } from './webar';
64 changes: 64 additions & 0 deletions __tests__/demos/3d/webar.ts
Original file line number Diff line number Diff line change
@@ -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());
}
};
1 change: 1 addition & 0 deletions __tests__/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ function createSpecRender(object) {
],
// Used for WebGPU renderer
shaderCompilerPath: '/glsl_wgsl_compiler_bg.wasm',
// enableAutoRendering: false,
// enableDirtyRectangleRendering: false,
// enableDirtyRectangleRenderingDebug: true,
});
Expand Down
7 changes: 7 additions & 0 deletions packages/g-camera-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/g-camera-api/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
13 changes: 13 additions & 0 deletions packages/g-canvas/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/g-canvas/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
13 changes: 13 additions & 0 deletions packages/g-canvaskit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/g-canvaskit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-canvaskit",
"version": "1.0.1",
"version": "1.0.2",
"description": "A renderer implemented by CanvasKit",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/g-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-components",
"version": "2.0.1",
"version": "2.0.2",
"description": "Components for g",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-dom-mutation-observer-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/g-dom-mutation-observer-api/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-gesture/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/g-gesture/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-gesture",
"version": "3.0.1",
"version": "3.0.2",
"description": "G Gesture",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-image-exporter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/g-image-exporter/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 6 additions & 0 deletions packages/g-lite/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions packages/g-lite/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions packages/g-lite/src/Canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions packages/g-lite/src/camera/Camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 9 additions & 5 deletions packages/g-lite/src/services/RenderingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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`
Expand Down Expand Up @@ -161,7 +161,11 @@ export class RenderingService {
);
}

render(canvasConfig: Partial<CanvasConfig>, rerenderCallback: () => void) {
render(
canvasConfig: Partial<CanvasConfig>,
frame: XRFrame,
rerenderCallback: () => void,
) {
this.stats.total = 0;
this.stats.rendered = 0;
this.zIndexCounter = 0;
Expand Down Expand Up @@ -191,7 +195,7 @@ export class RenderingService {
);
}

this.hooks.beginFrame.call();
this.hooks.beginFrame.call(frame);

if (shouldTriggerRenderHooks) {
renderingContext.renderListCurrentFrame.forEach((object) => {
Expand All @@ -201,7 +205,7 @@ export class RenderingService {
});
}

this.hooks.endFrame.call();
this.hooks.endFrame.call(frame);
renderingContext.renderListCurrentFrame = [];
renderingContext.renderReasons.clear();

Expand Down
7 changes: 7 additions & 0 deletions packages/g-lottie-player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/g-lottie-player/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-mobile-canvas-element/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading

0 comments on commit 520ff5e

Please sign in to comment.