@turbox3d/graphic-component-pixi
Version:
Graphic component library based on pixi
80 lines • 3.22 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/esm/inherits";
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
import { Mesh2D } from '@turbox3d/renderer-pixi';
import * as PIXI from 'pixi.js';
import DrawUtils from '../draw-utils/index';
/** 多边形 */
var Polygon = /*#__PURE__*/function (_Mesh2D) {
function Polygon() {
var _this;
_classCallCheck(this, Polygon);
_this = _callSuper(this, Polygon, arguments);
_this.view = new PIXI.Graphics();
_this.reactivePipeLine = [_this.updateGeometry, _this.updateMaterial, _this.updatePosition, _this.updateRotation, _this.updateScale];
return _this;
}
_inherits(Polygon, _Mesh2D);
return _createClass(Polygon, [{
key: "updateGeometry",
value: function updateGeometry() {
this.view.clear();
var _this$props = this.props,
path = _this$props.path,
lineWidth = _this$props.lineWidth,
lineColor = _this$props.lineColor,
lineAlpha = _this$props.lineAlpha,
fillColor = _this$props.fillColor,
fillAlpha = _this$props.fillAlpha,
alpha = _this$props.alpha,
zIndex = _this$props.zIndex,
alignment = _this$props.alignment,
_native = _this$props["native"];
zIndex && (this.view.zIndex = zIndex);
DrawUtils.drawPolygon(this.view, {
path: path.map(function (p) {
return {
x: p.x,
y: p.y
};
}),
lineWidth: lineWidth,
lineColor: lineColor,
lineAlpha: lineAlpha,
fillColor: fillColor,
fillAlpha: fillAlpha,
alpha: alpha,
alignment: alignment,
"native": _native
});
}
}, {
key: "updateMaterial",
value: function updateMaterial() {
//
}
}, {
key: "updatePosition",
value: function updatePosition() {
// const { position } = this.props;
// this.view.position.set(position!.x, position!.y);
}
}, {
key: "updateRotation",
value: function updateRotation() {
var _a;
this.view.rotation = (_a = this.props.rotation) !== null && _a !== void 0 ? _a : 0;
}
}, {
key: "updateScale",
value: function updateScale() {
var _a, _b, _c, _d;
this.view.scale.set((_b = (_a = this.props.scale) === null || _a === void 0 ? void 0 : _a.x) !== null && _b !== void 0 ? _b : 1, (_d = (_c = this.props.scale) === null || _c === void 0 ? void 0 : _c.y) !== null && _d !== void 0 ? _d : 1);
}
}]);
}(Mesh2D);
export { Polygon as default };