UNPKG

@awayjs/scene

Version:
204 lines (203 loc) 7.86 kB
import { __extends } from "tslib"; import { Box, Sphere } from '@awayjs/core'; import { _Pick_PickableBase, PickEntity } from '@awayjs/view'; import { DisplayObject } from './DisplayObject'; /** * A Line Segment primitive. */ var LineSegment = /** @class */ (function (_super) { __extends(LineSegment, _super); /** * Create a line segment * * @param startPosition Start position of the line segment * @param endPosition Ending position of the line segment * @param thickness Thickness of the line */ function LineSegment(material, startPosition, endPosition, thickness) { if (thickness === void 0) { thickness = 1; } var _this = _super.call(this) || this; _this._pickObjects = {}; _this.material = material; _this._startPosition = startPosition; _this._endPosition = endPosition; _this._halfThickness = thickness * 0.5; return _this; } Object.defineProperty(LineSegment.prototype, "assetType", { /** * */ get: function () { return LineSegment.assetType; }, enumerable: false, configurable: true }); Object.defineProperty(LineSegment.prototype, "startPosition", { /** * */ get: function () { return this._startPosition; }, set: function (value) { if (this._startPosition == value) return; this._startPosition = value; this.invalidateElements(); }, enumerable: false, configurable: true }); Object.defineProperty(LineSegment.prototype, "endPosition", { /** * */ get: function () { return this._endPosition; }, set: function (value) { if (this._endPosition == value) return; this._endPosition = value; this.invalidateElements(); }, enumerable: false, configurable: true }); Object.defineProperty(LineSegment.prototype, "thickness", { /** * */ get: function () { return this._halfThickness * 2; }, set: function (value) { if (this._halfThickness == value) return; this._halfThickness = value * 0.5; this.invalidateElements(); }, enumerable: false, configurable: true }); LineSegment.prototype.invalidateElements = function () { for (var key in this._pickObjects) this._pickObjects[key]._onInvalidateElements(); _super.prototype.invalidateElements.call(this); }; LineSegment.prototype.getEntity = function () { return this; }; LineSegment.prototype._acceptTraverser = function (traverser) { traverser.applyTraversable(this); }; LineSegment.assetType = '[asset LineSegment]'; return LineSegment; }(DisplayObject)); export { LineSegment }; import { LineElements } from '@awayjs/renderer'; import { _Render_RenderableBase, RenderEntity, MaterialUtils } from '@awayjs/renderer'; /** * @class away.pool._Render_LineSegment */ var _Render_LineSegment = /** @class */ (function (_super) { __extends(_Render_LineSegment, _super); function _Render_LineSegment() { return _super !== null && _super.apply(this, arguments) || this; } /** * //TODO * * @returns {base.LineElements} * @protected */ _Render_LineSegment.prototype._getStageElements = function () { var lineSegment = this.renderable; var elements = _Render_LineSegment._lineGraphics[lineSegment.id] || (_Render_LineSegment._lineGraphics[lineSegment.id] = new LineElements()); var start = lineSegment.startPosition; var end = lineSegment.endPosition; var positions = new Float32Array(6); var thickness = new Float32Array(1); positions[0] = start.x; positions[1] = start.y; positions[2] = start.z; positions[3] = end.x; positions[4] = end.y; positions[5] = end.z; thickness[0] = lineSegment.thickness; elements.setPositions(positions); elements.setThickness(thickness); return this._stage.abstractions.getAbstraction(elements); }; _Render_LineSegment.prototype._getRenderMaterial = function () { return this.entity.renderer .getRenderElements(this.stageElements.elements).abstractions .getAbstraction(this.renderable.material || MaterialUtils.getDefaultColorMaterial()); }; _Render_LineSegment.prototype._getStyle = function () { return this.renderable.style; }; _Render_LineSegment._lineGraphics = {}; return _Render_LineSegment; }(_Render_RenderableBase)); export { _Render_LineSegment }; /** * @class away.pool._Render_Shape */ var _Pick_LineSegment = /** @class */ (function (_super) { __extends(_Pick_LineSegment, _super); function _Pick_LineSegment() { return _super !== null && _super.apply(this, arguments) || this; } _Pick_LineSegment.prototype.hitTestPoint = function (x, y, z) { return true; }; _Pick_LineSegment.prototype.getBoxBounds = function (matrix3D, strokeFlag, cache, target) { if (matrix3D === void 0) { matrix3D = null; } if (strokeFlag === void 0) { strokeFlag = true; } if (cache === void 0) { cache = null; } if (target === void 0) { target = null; } if (this._orientedBoxBoundsDirty) { this._orientedBoxBoundsDirty = false; var lineSegment = this.pickable; var startPosition = lineSegment.startPosition; var endPosition = lineSegment.endPosition; this._orientedBoxBounds = new Box(Math.min(startPosition.x, endPosition.x), Math.min(startPosition.y, endPosition.y), Math.min(startPosition.z, endPosition.z), Math.abs(startPosition.x - endPosition.x), Math.abs(startPosition.y - endPosition.y), Math.abs(startPosition.z - endPosition.z)); } return (matrix3D ? matrix3D.transformBox(this._orientedBoxBounds) : this._orientedBoxBounds).union(target, target || cache); }; _Pick_LineSegment.prototype.getSphereBounds = function (center, matrix3D, strokeFlag, cache, target) { if (matrix3D === void 0) { matrix3D = null; } if (strokeFlag === void 0) { strokeFlag = true; } if (cache === void 0) { cache = null; } if (target === void 0) { target = null; } if (this._orientedSphereBoundsDirty) { this._orientedSphereBoundsDirty = false; var lineSegment = this.pickable; var startPosition = lineSegment.startPosition; var endPosition = lineSegment.endPosition; var halfWidth = (endPosition.x - startPosition.x) / 2; var halfHeight = (endPosition.y - startPosition.y) / 2; var halfDepth = (endPosition.z - startPosition.z) / 2; this._orientedSphereBounds = new Sphere(startPosition.x + halfWidth, startPosition.y + halfHeight, startPosition.z + halfDepth, Math.sqrt(halfWidth * halfWidth + halfHeight * halfHeight + halfDepth * halfDepth)); } return (matrix3D ? matrix3D.transformSphere(this._orientedSphereBounds) : this._orientedSphereBounds).union(target, target || cache); }; _Pick_LineSegment.prototype.testCollision = function (collision, closestFlag) { collision.pickable = null; //TODO return false; }; return _Pick_LineSegment; }(_Pick_PickableBase)); export { _Pick_LineSegment }; RenderEntity.registerRenderable(_Render_LineSegment, LineSegment); PickEntity.registerPickable(_Pick_LineSegment, LineSegment);