UNPKG

@turbox3d/design-engine

Version:

Large-scale design application engine library

896 lines (894 loc) 34 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = exports.EPerspectiveType = void 0; var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); var _reactivity = require("@turbox3d/reactivity"); var _shared = require("@turbox3d/shared"); var _math = require("@turbox3d/math"); function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(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; })(); } var __decorate = void 0 && (void 0).__decorate || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if ((typeof Reflect === "undefined" ? "undefined" : (0, _typeof2["default"])(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; /* eslint-disable no-else-return */ /** 视角类型 */ var EPerspectiveType; (function (EPerspectiveType) { /** 正视 */ EPerspectiveType["FRONT"] = "front"; /** 顶视 */ EPerspectiveType["TOP"] = "top"; /** 左视 */ EPerspectiveType["LEFT"] = "left"; })(EPerspectiveType || (exports.EPerspectiveType = EPerspectiveType = {})); /** * | y * | * | * | x * /— — — — — — * / * / * /z * 右手坐标系 */ var EntityObject = /*#__PURE__*/function (_Domain) { function EntityObject() { var _this; var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : (0, _shared.generateUUID)(); (0, _classCallCheck2["default"])(this, EntityObject); _this = _callSuper(this, EntityObject); /** 模型名称 */ _this.name = ''; /** 模型位置 */ _this.position = new _math.Vector3(0, 0, 0); /** 模型旋转角度(注意不是弧度) */ _this.rotation = new _math.Vector3(0, 0, 0); /** 模型缩放 */ _this.scale = new _math.Vector3(1, 1, 1); /** 模型尺寸 */ _this.size = new _math.Vector3(0, 0, 0); /** 模型子节点 */ _this.children = new Set(); /** 是否隐藏 */ _this.hidden = false; /** 是否锁定 */ _this.locked = false; /** 是否可被点击 */ _this.isClickable = true; /** 是否可被 hover */ _this.isHoverable = true; /** 是否可被拖拽 */ _this.isDraggable = true; /** 是否可被捏合(移动端) */ _this.isPinchable = true; /** 是否可被旋转(移动端) */ _this.isRotatable = true; /** 是否可被按压(移动端) */ _this.isPressable = true; /** 渲染顺序 */ _this.renderOrder = 0; /** 对应的模型网格 */ _this.meshes = []; /** 响应式的任务管线 */ _this.reactivePipeLine = []; _this.reactions = []; _this.id = id; EntityObject.entityMap.set(_this.id, _this); return _this; } (0, _inherits2["default"])(EntityObject, _Domain); return (0, _createClass2["default"])(EntityObject, [{ key: "initDomainContext", value: function initDomainContext() { return { isNeedRecord: true }; } /** 启动响应式任务管线 */ }, { key: "runReactivePipeLine", value: function runReactivePipeLine() { var _this2 = this; this.reactions = this.reactivePipeLine.map(function (pipe) { return (0, _reactivity.reactive)(function () { return pipe.func.call(_this2); }, pipe.options); }); } /** 销毁所有响应式任务管线 */ }, { key: "disposeReactivePipeLine", value: function disposeReactivePipeLine() { this.reactions.forEach(function (reaction) { return reaction.dispose(); }); } /** back * 0---------3 * | | * |left |right * | | * 1---------2 * front * 顶视的紧贴包围盒点集合,忽略 x、z 轴旋转 */ }, { key: "box2Top", get: function get() { return this.getBox2From3d(EPerspectiveType.TOP); } /** 基于世界坐标系的顶视的紧贴包围盒点集合,忽略 x、z 轴旋转 */ }, { key: "box2TopWCS", get: function get() { return this.getBox2From3d(EPerspectiveType.TOP, true); } /** * 基于世界坐标系的顶视的 AABB 包围盒点集合,忽略 x、z 轴旋转 */ }, { key: "box2TopAABBWCS", get: function get() { return this.getBox2AABBFrom3d(EPerspectiveType.TOP, true); } /** top * 3---------2 * | | * |left |right * | | * 0---------1 * bottom * 正视/立面的紧贴包围盒点集合,忽略 x、y 轴旋转 */ }, { key: "box2Front", get: function get() { return this.getBox2From3d(EPerspectiveType.FRONT); } /** 基于世界坐标系的正视/立面的紧贴包围盒点集合,忽略 x、y 轴旋转 */ }, { key: "box2FrontWCS", get: function get() { return this.getBox2From3d(EPerspectiveType.FRONT, true); } /** * 基于世界坐标系的正视/立面的 AABB 包围盒点集合,忽略 x、y 轴旋转 */ }, { key: "box2FrontAABBWCS", get: function get() { return this.getBox2AABBFrom3d(EPerspectiveType.FRONT, true); } /** top * 3---------2 * | | * |left |right * | | * 0---------1 * bottom * 左视的紧贴包围盒点集合,忽略 y、z 轴旋转 */ }, { key: "box2Left", get: function get() { return this.getBox2From3d(EPerspectiveType.LEFT); } /** 基于世界坐标系的左视的紧贴包围盒点集合,忽略 y、z 轴旋转 */ }, { key: "box2LeftWCS", get: function get() { return this.getBox2From3d(EPerspectiveType.LEFT, true); } /** * 基于世界坐标系的左视的 AABB 包围盒点集合,忽略 y、z 轴旋转 */ }, { key: "box2LeftAABBWCS", get: function get() { return this.getBox2AABBFrom3d(EPerspectiveType.LEFT, true); } /** * 7-----------6 * / . / | * / . / | * 4-----------5 | * | . | | * | . | | * | 0.......|...3 * | . | / * | . | / * 1-----------2 * 三维的紧贴包围盒点集合 */ }, { key: "box3", get: function get() { return this.getBox3(); } /** 基于世界坐标系的三维的紧贴包围盒点集合 */ }, { key: "box3WCS", get: function get() { return this.getBox3(undefined, true); } /** * 三维的 AABB 包围盒点集合 */ }, { key: "box3AABB", get: function get() { return this.getBox3AABB(); } /** * 基于世界坐标系的三维的 AABB 包围盒点集合 */ }, { key: "box3AABBWCS", get: function get() { return this.getBox3AABB(undefined, true); } /** 缩放过的尺寸 */ }, { key: "scaledSize", get: function get() { return this.getScaledSize(); } /** 3x3 entity 顶视矩阵 */ }, { key: "matrix3Top", get: function get() { return this.getMatrix3From3d(EPerspectiveType.TOP); } /** 3x3 entity 正视/立面矩阵 */ }, { key: "matrix3Front", get: function get() { return this.getMatrix3From3d(EPerspectiveType.FRONT); } /** 3x3 entity 左视矩阵 */ }, { key: "matrix3Left", get: function get() { return this.getMatrix3From3d(EPerspectiveType.LEFT); } /** 4x4 entity 矩阵 */ }, { key: "matrix4", get: function get() { return this.getMatrix4(); } }, { key: "setClickable", value: function setClickable(clickable) { this.isClickable = clickable; return this; } }, { key: "setHoverable", value: function setHoverable(hoverable) { this.isHoverable = hoverable; return this; } }, { key: "setDraggable", value: function setDraggable(draggable) { this.isDraggable = draggable; return this; } }, { key: "setPinchable", value: function setPinchable(pinchable) { this.isPinchable = pinchable; return this; } }, { key: "setRotatable", value: function setRotatable(rotatable) { this.isRotatable = rotatable; return this; } }, { key: "setPressable", value: function setPressable(pressable) { this.isPressable = pressable; return this; } /** 设置是否可交互 */ }, { key: "setInteractive", value: function setInteractive(interactive) { this.setClickable(interactive); this.setHoverable(interactive); this.setDraggable(interactive); this.setPinchable(interactive); this.setRotatable(interactive); this.setPressable(interactive); return this; } }, { key: "setRenderOrder", value: function setRenderOrder(renderOrder) { this.renderOrder = renderOrder; return this; } /** 锁定 */ }, { key: "lock", value: function lock() { this.locked = true; return this; } /** 解锁 */ }, { key: "unlock", value: function unlock() { this.locked = false; return this; } /** 隐藏模型 */ }, { key: "hide", value: function hide() { this.hidden = true; return this; } /** 显示模型 */ }, { key: "show", value: function show() { this.hidden = false; return this; } /** 设置名称 */ }, { key: "setName", value: function setName(name) { this.name = name; return this; } /** 设置一个 4x4 矩阵 */ }, { key: "setMatrix4", value: function setMatrix4(value) { var position = new _math.Vector3(); var quaternion = new _math.Quaternion(); var scale = new _math.Vector3(); value.decompose(position, quaternion, scale); var rotation = new _math.Euler().setFromQuaternion(quaternion).toVector3(); this.setPosition(position); this.setRotation({ x: rotation.x * _math.MathUtils.RAD2DEG, y: rotation.y * _math.MathUtils.RAD2DEG, z: rotation.z * _math.MathUtils.RAD2DEG }); this.setScale(scale); return this; } /** 相对于世界坐标系的矩阵 */ }, { key: "concatenatedMatrix", get: function get() { return this.getConcatenatedMatrix(); } /** 是否是顶层模型 */ }, { key: "isRoot", value: function isRoot() { return !this.parent; } /** * 获取该模型的顶层模型 * @param stopCondition 停止查找的条件函数,返回 true 就停下查找 */ }, { key: "getRoot", value: function getRoot(stopCondition) { // eslint-disable-next-line @typescript-eslint/no-this-alias var root = this; while (root.parent && (!stopCondition || !stopCondition(root))) { root = root.parent; } return root; } /** * 遍历 * @param callback 遍历的处理逻辑函数,返回值是布尔值,如果是 true,则会停止当前遍历到的节点继续往下遍历 */ }, { key: "traverse", value: function traverse(callback) { var isStop = callback(this); if (isStop) { return this; } this.children.forEach(function (child) { child.traverse(callback); }); return this; } /** 添加子模型 */ }, { key: "addChild", value: function addChild(child) { this.children.add(child); child.parent = this; return this; } /** 批量添加子模型 */ }, { key: "addChildren", value: function addChildren(children) { var _this3 = this; children.forEach(function (child) { return _this3.addChild(child); }); return this; } /** 删除子模型 */ }, { key: "removeChild", value: function removeChild(child) { child.parent = undefined; this.children["delete"](child); return this; } /** 批量移除指定的子模型,不传参则移除所有子模型 */ }, { key: "removeChildren", value: function removeChildren(children) { var _this4 = this; if (!children) { this.children.forEach(function (child) { child.parent = undefined; }); this.children.clear(); return this; } children.forEach(function (child) { return _this4.removeChild(child); }); return this; } /** 获取该模型与其祖先节点的路径链(从祖先节点到当前模型的顺序) */ }, { key: "getParentPathChain", value: function getParentPathChain() { var path = [this]; // eslint-disable-next-line @typescript-eslint/no-this-alias var t = this; while (t.parent) { t = t.parent; path.unshift(t); } return path; } /** 获取模型节点深度 */ }, { key: "getDepth", value: function getDepth() { // eslint-disable-next-line @typescript-eslint/no-this-alias var t = this; var result = 1; while (t.parent) { t = t.parent; result += 1; } return result; } }, { key: "getScaledSize", value: function getScaledSize() { var _this$size = this.size, x = _this$size.x, y = _this$size.y, z = _this$size.z; var _this$scale = this.scale, x1 = _this$scale.x, y1 = _this$scale.y, z1 = _this$scale.z; return new _math.Vector3(x * x1, y * y1, z * z1); } }, { key: "setPosition", value: function setPosition(position) { var x = position.x, y = position.y, z = position.z; x !== undefined && (this.position.x = x); y !== undefined && (this.position.y = y); z !== undefined && (this.position.z = z); return this; } }, { key: "setRotation", value: function setRotation(rotation) { var x = rotation.x, y = rotation.y, z = rotation.z; x !== undefined && (this.rotation.x = x); y !== undefined && (this.rotation.y = y); z !== undefined && (this.rotation.z = z); return this; } }, { key: "setScale", value: function setScale(scale) { var x = scale.x, y = scale.y, z = scale.z; x !== undefined && (this.scale.x = x); y !== undefined && (this.scale.y = y); z !== undefined && (this.scale.z = z); return this; } }, { key: "setSize", value: function setSize(size) { var x = size.x, y = size.y, z = size.z; x !== undefined && (this.size.x = x); y !== undefined && (this.size.y = y); z !== undefined && (this.size.z = z); return this; } }, { key: "setMeshes", value: function setMeshes(value) { this.meshes = value; return this; } }, { key: "getMatrix4", value: function getMatrix4() { var order = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'ZYX'; var quaternion = new _math.Quaternion().setFromEuler(new _math.Euler(this.rotation.x * _math.MathUtils.DEG2RAD, this.rotation.y * _math.MathUtils.DEG2RAD, this.rotation.z * _math.MathUtils.DEG2RAD, order)); var position = new _math.Vector3(this.position.x, this.position.y, this.position.z); var scale = new _math.Vector3(this.scale.x, this.scale.y, this.scale.z); return new _math.Matrix4().compose(position, quaternion, scale); } }, { key: "getMatrix3From3d", value: function getMatrix3From3d() { var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : EPerspectiveType.FRONT; var matrix3 = new _math.Matrix3(); if (type === EPerspectiveType.FRONT) { matrix3.compose(new _math.Vector2(this.position.x, this.position.y), this.rotation.z * _math.MathUtils.DEG2RAD, new _math.Vector2(this.scale.x, this.scale.y)); } else if (type === EPerspectiveType.TOP) { matrix3.compose(new _math.Vector2(this.position.x, this.position.z), this.rotation.y * _math.MathUtils.DEG2RAD, new _math.Vector2(this.scale.x, this.scale.z)); } else if (type === EPerspectiveType.LEFT) { matrix3.compose(new _math.Vector2(this.position.z, this.position.y), this.rotation.x * _math.MathUtils.DEG2RAD, new _math.Vector2(this.scale.z, this.scale.y)); } return matrix3; } }, { key: "getConcatenatedMatrix", value: function getConcatenatedMatrix() { var result = this.getMatrix4().clone(); // eslint-disable-next-line @typescript-eslint/no-this-alias var root = this; while (root.parent) { root = root.parent; result.premultiply(root.getMatrix4()); } return result; } /** * 初始建模包围盒,默认建模原点为几何中心,如需修改请重写该方法 * @BreakingChange 之前建模原点默认为左后下,现在默认为几何中心(更便于做计算) */ }, { key: "getRawBox3", value: function getRawBox3() { var size = new _math.Vector3(this.size.x, this.size.y, this.size.z); // const original = new Vector3(0.5, 0.5, 0.5); var original = new _math.Vector3(0, 0, 0); var center = size.clone().multiply(original); return new _math.Box3().setFromCenterAndSize(center, size); } }, { key: "getRawBox3Points", value: function getRawBox3Points() { var box3 = this.getRawBox3(); var points = [new _math.Vector3(box3.min.x, box3.min.y, box3.min.z), new _math.Vector3(box3.min.x, box3.min.y, box3.max.z), new _math.Vector3(box3.max.x, box3.min.y, box3.max.z), new _math.Vector3(box3.max.x, box3.min.y, box3.min.z), new _math.Vector3(box3.min.x, box3.max.y, box3.max.z), new _math.Vector3(box3.max.x, box3.max.y, box3.max.z), new _math.Vector3(box3.max.x, box3.max.y, box3.min.z), new _math.Vector3(box3.min.x, box3.max.y, box3.min.z)]; return points; } /** 获取 AABB 包围盒 */ }, { key: "getBox3AABB", value: function getBox3AABB(matrix4) { var useWCS = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var points = this.getBox3(matrix4, useWCS); var box3 = new _math.Box3().setFromPoints(points); return [new _math.Vector3(box3.min.x, box3.min.y, box3.min.z), new _math.Vector3(box3.min.x, box3.min.y, box3.max.z), new _math.Vector3(box3.max.x, box3.min.y, box3.max.z), new _math.Vector3(box3.max.x, box3.min.y, box3.min.z), new _math.Vector3(box3.min.x, box3.max.y, box3.max.z), new _math.Vector3(box3.max.x, box3.max.y, box3.max.z), new _math.Vector3(box3.max.x, box3.max.y, box3.min.z), new _math.Vector3(box3.min.x, box3.max.y, box3.min.z)]; } /** 获取紧贴包围盒 */ }, { key: "getBox3", value: function getBox3(matrix4) { var useWCS = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var matrix = matrix4 || (useWCS ? this.getConcatenatedMatrix() : this.getMatrix4()); var points = this.getRawBox3Points(); return points.map(function (point) { return point.clone().applyMatrix4(matrix); }); } }, { key: "getRawBox2PointsFrom3d", value: function getRawBox2PointsFrom3d() { var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : EPerspectiveType.FRONT; var box3 = this.getRawBox3(); if (type === EPerspectiveType.TOP) { return [new _math.Vector2(box3.min.x, box3.min.z), new _math.Vector2(box3.min.x, box3.max.z), new _math.Vector2(box3.max.x, box3.max.z), new _math.Vector2(box3.max.x, box3.min.z)]; } else if (type === EPerspectiveType.FRONT) { return [new _math.Vector2(box3.min.x, box3.min.y), new _math.Vector2(box3.max.x, box3.min.y), new _math.Vector2(box3.max.x, box3.max.y), new _math.Vector2(box3.min.x, box3.max.y)]; } else if (type === EPerspectiveType.LEFT) { return [new _math.Vector2(box3.min.z, box3.min.y), new _math.Vector2(box3.max.z, box3.min.y), new _math.Vector2(box3.max.z, box3.max.y), new _math.Vector2(box3.min.z, box3.max.y)]; } return []; } /** 从 3d 下不同视角获取 2d AABB 包围盒 */ }, { key: "getBox2AABBFrom3d", value: function getBox2AABBFrom3d() { var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : EPerspectiveType.FRONT; var useWCS = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var points = this.getBox2From3d(type, useWCS); var box2 = new _math.Box2().setFromPoints(points); return [new _math.Vector2(box2.min.x, box2.min.y), new _math.Vector2(box2.max.x, box2.min.y), new _math.Vector2(box2.max.x, box2.max.y), new _math.Vector2(box2.min.x, box2.max.y)]; } /** 从 3d 下不同视角获取 2d 紧贴包围盒 */ }, { key: "getBox2From3d", value: function getBox2From3d() { var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : EPerspectiveType.FRONT; var useWCS = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var matrix = useWCS ? this.getConcatenatedMatrix() : this.getMatrix4(); var points = this.getBox3(matrix, useWCS); var len = points.length / 2; var position = new _math.Vector3(); var rotation = new _math.Quaternion(); var scale = new _math.Vector3(); matrix.decompose(position, rotation, scale); var euler = new _math.Euler().setFromQuaternion(rotation); var _euler$toArray$slice$ = euler.toArray().slice(0, 3).map(function (rad) { return rad % (Math.PI / 2) === 0; }), _euler$toArray$slice$2 = (0, _slicedToArray2["default"])(_euler$toArray$slice$, 3), x = _euler$toArray$slice$2[0], y = _euler$toArray$slice$2[1], z = _euler$toArray$slice$2[2]; if (type === EPerspectiveType.TOP) { // 顶视图情况下,x 轴、z 轴只要有非 90 度倍数旋转,就得取投影包围盒,否则取真实紧贴包围盒 if (!x || !z) { var box3 = new _math.Box3().setFromPoints(points); return [new _math.Vector2(box3.min.x, box3.min.z), new _math.Vector2(box3.min.x, box3.max.z), new _math.Vector2(box3.max.x, box3.max.z), new _math.Vector2(box3.max.x, box3.min.z)]; } var newPoints = points.sort(function (a, b) { return b.y - a.y; }).slice(0, len).map(function (p) { return new _math.Vector2(p.x, p.z); }); return _math.MathUtils.clockwisePoints(newPoints); } else if (type === EPerspectiveType.FRONT) { // 正视图情况下,x 轴、y 轴只要有非 90 度倍数旋转,就得取投影包围盒,否则取真实紧贴包围盒 if (!x || !y) { var _box = new _math.Box3().setFromPoints(points); return [new _math.Vector2(_box.min.x, _box.min.y), new _math.Vector2(_box.max.x, _box.min.y), new _math.Vector2(_box.max.x, _box.max.y), new _math.Vector2(_box.min.x, _box.max.y)]; } var _newPoints = points.sort(function (a, b) { return b.z - a.z; }).slice(0, len).map(function (p) { return new _math.Vector2(p.x, p.y); }); return _math.MathUtils.clockwisePoints(_newPoints); } else if (type === EPerspectiveType.LEFT) { // 左视图情况下,z 轴、y 轴只要有非 90 度倍数旋转,就得取投影包围盒,否则取真实紧贴包围盒 if (!z || !y) { var _box2 = new _math.Box3().setFromPoints(points); return [new _math.Vector2(_box2.min.z, _box2.min.y), new _math.Vector2(_box2.max.z, _box2.min.y), new _math.Vector2(_box2.max.z, _box2.max.y), new _math.Vector2(_box2.min.z, _box2.max.y)]; } var _newPoints2 = points.sort(function (a, b) { return a.x - b.x; }).slice(0, len).map(function (p) { return new _math.Vector2(p.z, p.y); }); return _math.MathUtils.clockwisePoints(_newPoints2); } return []; } /** * ------------------------------------------------ 以下是纯 2d 坐标系下的方法 ------------------------------------------------ * x * |— — — — — — * | * | * | * y | * 2d 坐标系 */ }, { key: "getRawBox2", value: function getRawBox2() { var size = new _math.Vector2(this.size.x, this.size.y); // const original = new Vector2(0.5, 0.5); var original = new _math.Vector2(0, 0); var center = size.clone().multiply(original); return new _math.Box2().setFromCenterAndSize(center, size); } /** top * 3---------2 * | | * |left |right * | | * 0---------1 * bottom * 获取原始包围盒的 4 个点 */ }, { key: "getRawBox2Points", value: function getRawBox2Points() { var box2 = this.getRawBox2(); return [new _math.Vector2(box2.min.x, box2.max.y), new _math.Vector2(box2.max.x, box2.max.y), new _math.Vector2(box2.max.x, box2.min.y), new _math.Vector2(box2.min.x, box2.min.y)]; } }, { key: "getMatrix3", value: function getMatrix3() { var matrix3 = new _math.Matrix3(); return matrix3.compose(new _math.Vector2(this.position.x, this.position.y), this.rotation.z * _math.MathUtils.DEG2RAD, new _math.Vector2(this.scale.x, this.scale.y)); } }, { key: "getConcatenatedMatrix3", value: function getConcatenatedMatrix3() { var result = this.getMatrix3().clone(); // eslint-disable-next-line @typescript-eslint/no-this-alias var root = this; while (root.parent) { root = root.parent; result.premultiply(root.getMatrix3()); } return result; } /** 获取 AABB 包围盒 */ }, { key: "getBox2AABB", value: function getBox2AABB(matrix3) { var useWCS = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var points = this.getBox2(matrix3, useWCS); var box2 = new _math.Box2().setFromPoints(points); return [new _math.Vector2(box2.min.x, box2.max.y), new _math.Vector2(box2.max.x, box2.max.y), new _math.Vector2(box2.max.x, box2.min.y), new _math.Vector2(box2.min.x, box2.min.y)]; } /** 获取紧贴包围盒 */ }, { key: "getBox2", value: function getBox2(matrix3) { var useWCS = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var matrix = matrix3 || (useWCS ? this.getConcatenatedMatrix3() : this.getMatrix3()); var points = this.getRawBox2Points(); return points.map(function (point) { return point.clone().applyMatrix3(matrix); }); } }], [{ key: "getEntityById", value: function getEntityById(id) { return EntityObject.entityMap.get(id); } }]); }(_reactivity.Domain); EntityObject.EPerspectiveType = EPerspectiveType; EntityObject.entityMap = new Map(); var _default = exports["default"] = EntityObject; __decorate([(0, _reactivity.reactor)()], EntityObject.prototype, "id", void 0); __decorate([(0, _reactivity.reactor)()], EntityObject.prototype, "name", void 0); __decorate([(0, _reactivity.reactor)()], EntityObject.prototype, "position", void 0); __decorate([(0, _reactivity.reactor)()], EntityObject.prototype, "rotation", void 0); __decorate([(0, _reactivity.reactor)()], EntityObject.prototype, "scale", void 0); __decorate([(0, _reactivity.reactor)()], EntityObject.prototype, "size", void 0); __decorate([(0, _reactivity.reactor)()], EntityObject.prototype, "parent", void 0); __decorate([(0, _reactivity.reactor)()], EntityObject.prototype, "children", void 0); __decorate([(0, _reactivity.reactor)()], EntityObject.prototype, "hidden", void 0); __decorate([(0, _reactivity.reactor)()], EntityObject.prototype, "locked", void 0); __decorate([(0, _reactivity.reactor)()], EntityObject.prototype, "isClickable", void 0); __decorate([(0, _reactivity.reactor)()], EntityObject.prototype, "isHoverable", void 0); __decorate([(0, _reactivity.reactor)()], EntityObject.prototype, "isDraggable", void 0); __decorate([(0, _reactivity.reactor)()], EntityObject.prototype, "isPinchable", void 0); __decorate([(0, _reactivity.reactor)()], EntityObject.prototype, "isRotatable", void 0); __decorate([(0, _reactivity.reactor)()], EntityObject.prototype, "isPressable", void 0); __decorate([(0, _reactivity.reactor)()], EntityObject.prototype, "renderOrder", void 0); __decorate([(0, _reactivity.reactor)()], EntityObject.prototype, "meshes", void 0); __decorate([(0, _reactivity.computed)({ lazy: false })], EntityObject.prototype, "box2Top", null); __decorate([(0, _reactivity.computed)({ lazy: false })], EntityObject.prototype, "box2TopWCS", null); __decorate([(0, _reactivity.computed)({ lazy: false })], EntityObject.prototype, "box2TopAABBWCS", null); __decorate([(0, _reactivity.computed)({ lazy: false })], EntityObject.prototype, "box2Front", null); __decorate([(0, _reactivity.computed)({ lazy: false })], EntityObject.prototype, "box2FrontWCS", null); __decorate([(0, _reactivity.computed)({ lazy: false })], EntityObject.prototype, "box2FrontAABBWCS", null); __decorate([(0, _reactivity.computed)({ lazy: false })], EntityObject.prototype, "box2Left", null); __decorate([(0, _reactivity.computed)({ lazy: false })], EntityObject.prototype, "box2LeftWCS", null); __decorate([(0, _reactivity.computed)({ lazy: false })], EntityObject.prototype, "box2LeftAABBWCS", null); __decorate([(0, _reactivity.computed)({ lazy: false })], EntityObject.prototype, "box3", null); __decorate([(0, _reactivity.computed)({ lazy: false })], EntityObject.prototype, "box3WCS", null); __decorate([(0, _reactivity.computed)({ lazy: false })], EntityObject.prototype, "box3AABB", null); __decorate([(0, _reactivity.computed)({ lazy: false })], EntityObject.prototype, "box3AABBWCS", null); __decorate([(0, _reactivity.computed)({ lazy: false })], EntityObject.prototype, "scaledSize", null); __decorate([(0, _reactivity.computed)({ lazy: false })], EntityObject.prototype, "matrix3Top", null); __decorate([(0, _reactivity.computed)({ lazy: false })], EntityObject.prototype, "matrix3Front", null); __decorate([(0, _reactivity.computed)({ lazy: false })], EntityObject.prototype, "matrix3Left", null); __decorate([(0, _reactivity.computed)({ lazy: false })], EntityObject.prototype, "matrix4", null); __decorate([_reactivity.mutation], EntityObject.prototype, "setClickable", null); __decorate([_reactivity.mutation], EntityObject.prototype, "setHoverable", null); __decorate([_reactivity.mutation], EntityObject.prototype, "setDraggable", null); __decorate([_reactivity.mutation], EntityObject.prototype, "setPinchable", null); __decorate([_reactivity.mutation], EntityObject.prototype, "setRotatable", null); __decorate([_reactivity.mutation], EntityObject.prototype, "setPressable", null); __decorate([_reactivity.mutation], EntityObject.prototype, "setInteractive", null); __decorate([_reactivity.mutation], EntityObject.prototype, "setRenderOrder", null); __decorate([_reactivity.mutation], EntityObject.prototype, "lock", null); __decorate([_reactivity.mutation], EntityObject.prototype, "unlock", null); __decorate([_reactivity.mutation], EntityObject.prototype, "hide", null); __decorate([_reactivity.mutation], EntityObject.prototype, "show", null); __decorate([_reactivity.mutation], EntityObject.prototype, "setName", null); __decorate([_reactivity.mutation], EntityObject.prototype, "setMatrix4", null); __decorate([(0, _reactivity.computed)({ lazy: false })], EntityObject.prototype, "concatenatedMatrix", null); __decorate([_reactivity.mutation], EntityObject.prototype, "traverse", null); __decorate([_reactivity.mutation], EntityObject.prototype, "addChild", null); __decorate([_reactivity.mutation], EntityObject.prototype, "addChildren", null); __decorate([_reactivity.mutation], EntityObject.prototype, "removeChild", null); __decorate([_reactivity.mutation], EntityObject.prototype, "removeChildren", null); __decorate([_reactivity.mutation], EntityObject.prototype, "setPosition", null); __decorate([_reactivity.mutation], EntityObject.prototype, "setRotation", null); __decorate([_reactivity.mutation], EntityObject.prototype, "setScale", null); __decorate([_reactivity.mutation], EntityObject.prototype, "setSize", null); __decorate([_reactivity.mutation], EntityObject.prototype, "setMeshes", null);