UNPKG

@visactor/vrender-core

Version:
59 lines (51 loc) 2.1 kB
import { min } from "@visactor/vutils"; import { Rect } from "./rect"; import { RECT3D_NUMBER_TYPE } from "./constants"; import { NOWORK_ANIMATE_ATTR } from "./graphic"; const CUBE_VERTICES = [ [ 0, 0, 0 ], [ 1, 0, 0 ], [ 1, 1, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ], [ 1, 0, 1 ], [ 1, 1, 1 ], [ 0, 1, 1 ] ]; export class Rect3d extends Rect { constructor(params) { super(params), this.type = "rect3d", this.numberType = RECT3D_NUMBER_TYPE; } findFace() { const faces = { polygons: [], vertices: [], edges: [] }, rectTheme = this.getGraphicTheme(), {x1: x1, y1: y1, x: x, y: y, length: length = min(rectTheme.width, rectTheme.height)} = this.attribute; let {width: width, height: height} = this.attribute; width = null != width ? width : x1 - x, height = null != height ? height : y1 - y; for (let i = 0; i < CUBE_VERTICES.length; i++) { const v = CUBE_VERTICES[i]; faces.vertices.push([ v[0] * width, v[1] * height, v[2] * length ]); } return faces.polygons.push({ polygon: [ 0, 1, 5, 4 ], normal: [ 0, -1, 0 ] }), faces.polygons.push({ polygon: [ 2, 3, 7, 6 ], normal: [ 0, 1, 0 ] }), faces.polygons.push({ polygon: [ 4, 7, 3, 0 ], normal: [ -1, 0, 0 ] }), faces.polygons.push({ polygon: [ 1, 2, 6, 5 ], normal: [ 1, 0, 0 ] }), faces.polygons.push({ polygon: [ 0, 1, 2, 3 ], normal: [ 0, 0, -1 ] }), faces.polygons.push({ polygon: [ 4, 5, 6, 7 ], normal: [ 0, 0, 1 ] }), faces.edges = [ [ 0, 1 ], [ 1, 2 ], [ 2, 3 ], [ 3, 0 ], [ 4, 5 ], [ 5, 6 ], [ 6, 7 ], [ 7, 4 ], [ 0, 4 ], [ 3, 7 ], [ 1, 5 ], [ 2, 6 ] ], faces; } getNoWorkAnimateAttr() { return Rect3d.NOWORK_ANIMATE_ATTR; } } Rect3d.NOWORK_ANIMATE_ATTR = NOWORK_ANIMATE_ATTR; export function createRect3d(attributes) { return new Rect3d(attributes); } //# sourceMappingURL=rect3d.js.map