Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add plane-node for v5 #5189

Merged
merged 5 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/g6/src/stdlib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const {
ModelRectNode,
ImageNode,
CubeNode,
PlaneNode,
BaseNode,
BaseNode3D,
} = Nodes;
Expand Down Expand Up @@ -255,6 +256,7 @@ const Extensions = {
EllipseNode,
ModelRectNode,
CubeNode,
PlaneNode,
BaseNode,
BaseNode3D,
// edges
Expand Down
1 change: 1 addition & 0 deletions packages/g6/src/stdlib/item/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export * from './diamond';
export * from './modelRect';
export * from './image';
export * from './cube';
export * from './plane';
export * from './base';
export * from './base3d';
105 changes: 105 additions & 0 deletions packages/g6/src/stdlib/item/node/plane.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { DisplayObject } from '@antv/g';
import { NodeDisplayModel } from '../../../types';
import { State } from '../../../types/item';
import {
NodeModelData,
NodeShapeMap,
NodeShapeStyles,
} from '../../../types/node';
import { BaseNode3D } from './base3d';

export class PlaneNode extends BaseNode3D {
override defaultStyles = {
keyShape: {
width: 100,
depth: 100,
materialType: 'basic',
materialProps: {
wireframe: false,
wireframeColor: 'black',
cullMode: 0,
},
x: 0,
y: 0,
z: 0,
},
};
mergedStyles: NodeShapeStyles;
constructor(props) {
super(props);
}
public draw(
model: NodeDisplayModel,
shapeMap: NodeShapeMap,
diffData?: { previous: NodeModelData; current: NodeModelData },
diffState?: { previous: State[]; current: State[] },
): NodeShapeMap {
const { data = {} } = model;

let shapes: NodeShapeMap = { keyShape: undefined };

// keyShape
shapes.keyShape = this.drawKeyShape(model, shapeMap, diffData);

// haloShape
if (data.haloShape && this.drawHaloShape) {
shapes.haloShape = this.drawHaloShape(model, shapeMap, diffData);
}

// labelShape
if (data.labelShape) {
shapes.labelShape = this.drawLabelShape(model, shapeMap, diffData);
}

// labelBackgroundShape
if (data.labelBackgroundShape) {
shapes.labelBackgroundShape = this.drawLabelBackgroundShape(
model,
shapeMap,
diffData,
);
}

// iconShape
if (data.iconShape) {
shapes.iconShape = this.drawIconShape(model, shapeMap, diffData);
}

// badgeShape
if (data.badgeShapes) {
const badgeShapes = this.drawBadgeShapes(
model,
shapeMap,
diffData,
diffState,
);
shapes = {
...shapes,
...badgeShapes,
};
}

// otherShapes
if (data.otherShapes && this.drawOtherShapes) {
shapes = {
...shapes,
...this.drawOtherShapes(model, shapeMap, diffData),
};
}
return shapes;
}

public drawKeyShape(
model: NodeDisplayModel,
shapeMap: NodeShapeMap,
diffData?: { previous: NodeModelData; current: NodeModelData },
diffState?: { previous: State[]; current: State[] },
): DisplayObject {
return this.upsertShape(
'plane',
'keyShape',
this.mergedStyles.keyShape,
shapeMap,
);
}
}
14 changes: 8 additions & 6 deletions packages/g6/src/util/shape3d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const createShape3D = (
}

// materialType: 'lambert' | 'phong' | 'basic', TODO: type
const { materialType = 'lambert', ...otherStyles } = style as any;
const { materialType = 'lambert', materialProps = {}, ...otherStyles } = style as any;
if (!device.GeometryCache) {
device.GeometryCache = {};
}
Expand All @@ -59,21 +59,23 @@ export const createShape3D = (
case 'basic':
device.MaterialCache[materialType as string] = new MeshBasicMaterial(
device,
materialProps
);
break;
case 'phong': {
const materialProps = {
shininess: 30,
};
device.MaterialCache[materialType as string] = new MeshPhongMaterial(
device,
materialProps,
{
shininess: 30,
...materialProps
}
);
}
case 'lambert':
default: {
device.MaterialCache[materialType as string] = new MeshLambertMaterial(
device,
materialProps
);
break;
}
Expand Down Expand Up @@ -104,7 +106,7 @@ export const createShape3D = (
]);
break;
case 'plane':
shape.scale([style.width / GEOMETRY_SIZE, style.depth / GEOMETRY_SIZE]);
shape.scale(style.width / GEOMETRY_SIZE, style.depth / GEOMETRY_SIZE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scale(scaling: vec3 | vec2 | number, y?: number, z?: number): this; scale 第二个参数是 y 值,确认下是否正确呢

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改好啦

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改好啦

如果有参加 IssueHunt 计划,请将相关的 Issue 回复到下面哦~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌🏻

break;
case 'sphere':
default: {
Expand Down
Loading