Skip to content

Commit

Permalink
feat(3d): init g6-extension-3d package
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarebecca committed Mar 5, 2024
1 parent 272e181 commit d20bd7a
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/g6-extension-3d/__tests__/unit/default.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('suite', () => {
it('case', () => {
expect(1).toBe(1);
});
});
48 changes: 48 additions & 0 deletions packages/g6-extension-3d/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "g6-extension-3d",
"version": "1.0.0",
"description": "",
"keywords": [
"antv",
"g6",
"extension",
"3d"
],
"license": "MIT",
"author": "",
"main": "lib/index.js",
"module": "esm/index.js",
"types": "lib/index.d.ts",
"files": [
"src",
"esm",
"lib",
"dist"
],
"scripts": {
"build": "run-p build:*",
"build:cjs": "rimraf ./lib && tsc --module commonjs --outDir lib",
"build:esm": "rimraf ./esm && tsc --module ESNext --outDir esm",
"build:esm:watch": "rimraf ./esm && tsc --module ESNext --outDir esm --watch",
"build:umd": "rimraf ./dist && rollup -c",
"ci": "run-s lint type-check build test",
"lint": "eslint ./src __tests__ --quiet && prettier ./src __tests__ --check",
"prepublishOnly": "npm run ci",
"test": "jest",
"type-check": "tsc --noEmit"
},
"dependencies": {
"@antv/g": "^5.18.25",
"@antv/g-canvas": "^1.11.27",
"@antv/g-device-api": "^1.6.4",
"@antv/g-plugin-3d": "^1.9.34",
"@antv/g-plugin-control": "^1.9.22",
"@antv/g-webgl": "^1.9.37"
},
"devDependencies": {
"@antv/g6": "workspace:*"
},
"peerDependencies": {
"@antv/g6": "workspace:*"
}
}
21 changes: 21 additions & 0 deletions packages/g6-extension-3d/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import nodePolyfills from 'rollup-plugin-polyfill-node';
import { visualizer } from 'rollup-plugin-visualizer';

const isBundleVis = !!process.env.BUNDLE_VIS;

export default[
{
input: 'src/index.ts',
output: {
file: 'dist/g6.min.js',
name: 'G6V5',
format: 'umd',
sourcemap: false,
},
plugins: [nodePolyfills(), resolve(), commonjs(), typescript(), terser(), ...(isBundleVis ? [visualizer()] : [])],
},
];
21 changes: 21 additions & 0 deletions packages/g6-extension-3d/src/elements/base-node-3d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { BaseStyleProps } from '@antv/g';
import { Device } from '@antv/g-device-api';
import type { BufferGeometry, Material } from '@antv/g-plugin-3d';
import type { BaseNodeStyleProps } from '@antv/g6';
import { BaseNode } from '@antv/g6';

export interface BaseNode3DStyleProps extends BaseNodeStyleProps<MeshStyleProps> {
z?: number;
device: Device;
material: Material;
}

export abstract class BaseNode3D extends BaseNode<BaseNode3DStyleProps> {}

export interface MeshStyleProps extends BaseStyleProps {
x?: number | string;
y?: number | string;
z?: number | string;
geometry: BufferGeometry;
material: Material;
}
5 changes: 5 additions & 0 deletions packages/g6-extension-3d/src/elements/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { BaseNode3D } from './base-node-3d';
export { Sphere } from './sphere';

export type { BaseNode3DStyleProps } from './base-node-3d';
export type { SphereStyleProps } from './sphere';
21 changes: 21 additions & 0 deletions packages/g6-extension-3d/src/elements/sphere.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { Group } from '@antv/g';
import { Mesh } from '@antv/g-plugin-3d';
import type { BaseNode3DStyleProps, MeshStyleProps } from './base-node-3d';
import { BaseNode3D } from './base-node-3d';

export interface SphereStyleProps extends BaseNode3DStyleProps {}

type ParsedSphereStyleProps = Required<SphereStyleProps>;

export class Sphere extends BaseNode3D {
protected drawKeyShape(attributes = this.parsedAttributes, container: Group = this) {
return this.upsert('key', Mesh, this.getKeyStyle(attributes), container);
}

protected getKeyStyle(attributes: ParsedSphereStyleProps): MeshStyleProps {
return {
...super.getKeyStyle(attributes),
z: attributes.z || 0,
};
}
}
4 changes: 4 additions & 0 deletions packages/g6-extension-3d/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { BaseNode3D, Sphere } from './elements';
export { renderer } from './renderer';

export type { BaseNode3DStyleProps, SphereStyleProps } from './elements';
20 changes: 20 additions & 0 deletions packages/g6-extension-3d/src/renderer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Renderer as CanvasRenderer } from '@antv/g-canvas';
import { Plugin as Plugin3D } from '@antv/g-plugin-3d';
import { Plugin as PluginControl } from '@antv/g-plugin-control';
import { Renderer as WebGLRenderer } from '@antv/g-webgl';
import type { CanvasOptions } from '@antv/g6';

export const renderer: CanvasOptions['renderer'] = (layer) => {
if (layer === 'label' || layer === 'transientLabel') {
return new CanvasRenderer();
}

const renderer = new WebGLRenderer();

if (layer === 'main') {
renderer.registerPlugin(new Plugin3D());
renderer.registerPlugin(new PluginControl());
}

return renderer;
};
7 changes: 7 additions & 0 deletions packages/g6-extension-3d/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"outDir": "lib"
},
"extends": "../../tsconfig.json",
"include": ["src/**/*"]
}

0 comments on commit d20bd7a

Please sign in to comment.