g6/packages/g6-extension-3d
Aaron 7ce727aacd
chore: update version (#6129)
* chore: update deps version

* chore: update version

---------

Co-authored-by: antv <antv@antfin.com>
2024-08-06 10:53:39 +08:00
..
__tests__ fix: fix unexpected canvas access after switch renderer (#6110) 2024-08-02 10:06:51 +08:00
src refactor: support dynamic switch renderer (#6062) 2024-07-19 12:22:46 +08:00
CHANGELOG.md chore: update version (#6064) 2024-07-19 12:42:47 +08:00
jest.config.js fix: fix jest config (#5786) 2024-05-29 21:10:16 +08:00
package.json chore: update version (#6129) 2024-08-06 10:53:39 +08:00
README.md docs: update README (#5927) 2024-06-25 13:57:19 +08:00
rollup.config.mjs chore: adjust umd name (#5668) 2024-04-22 18:17:44 +08:00
tsconfig.build.json feat: add 3d elements, plugin (#5597) 2024-03-29 11:57:10 +08:00
tsconfig.json feat: add 3d elements, plugin (#5597) 2024-03-29 11:57:10 +08:00
tsconfig.test.json feat: add 3d elements, plugin (#5597) 2024-03-29 11:57:10 +08:00
vite.config.js feat: add 3d elements, plugin (#5597) 2024-03-29 11:57:10 +08:00

3D extension for G6

This extension package provides 3D elements, behaviors and plugins for G6.

Usage

  1. Install
npm install @antv/g6-extension-3d
  1. Import and Register

Where renderer, elements and lighting are necessary

import { ExtensionCategory, register } from '@antv/g6';
import { DragCanvas3D, Light, Line3D, Sphere, renderer } from '@antv/g6-extension-3d';

// 3d light plugin
register(ExtensionCategory.PLUGIN, '3d-light', Light);
// sphere node element
register(ExtensionCategory.NODE, 'sphere', Sphere);
// line edge element
register(ExtensionCategory.EDGE, 'line3d', Line3D);
// drag canvas in 3d scene
register(ExtensionCategory.BEHAVIOR, 'drag-canvas-3d', DragCanvas3D);
// camera setting plugin
register(ExtensionCategory.PLUGIN, 'camera-setting', CameraSetting);
  1. Use
import { Graph } from '@antv/g6';

const graph = new Graph({
  container: 'container',
  renderer, // use 3d renderer
  data: {
    // your data
  },
  node: {
    type: 'sphere', // use sphere node
  },
  edge: {
    type: 'line3d', // use 3d line edge
  },
  behaviors: ['drag-canvas-3d'],
  plugins: [
    // set camera configs, see: https://g.antv.antgroup.com/en/api/camera/intro
    {
      type: 'camera-setting',
      projectionMode: 'perspective',
      near: 0.1,
      far: 1000,
      fov: 45,
      aspect: 1,
    },
    // add directional light
    {
      type: '3d-light',
      directional: {
        direction: [0, 0, 1],
      },
    },
  ],
});

Resources