@visactor/vrender-core
Version:
## Description
99 lines (93 loc) • 3.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.createPyramid3d = exports.Pyramid3d = void 0;
const vutils_1 = require("@visactor/vutils"), application_1 = require("../application"), polygon_1 = require("./polygon"), constants_1 = require("./constants"), graphic_1 = require("./graphic");
class Pyramid3d extends polygon_1.Polygon {
constructor(params) {
super(params), this.type = "pyramid3d", this.numberType = constants_1.PYRAMID3D_NUMBER_TYPE;
}
updateAABBBounds(attribute, polygonTheme, aabbBounds) {
const stage = this.stage;
if (!stage || !stage.camera) return aabbBounds;
return this.findFace().vertices.forEach((v => {
const x = v[0], y = v[1];
aabbBounds.add(x, y);
})), application_1.application.graphicService.updateTempAABBBounds(aabbBounds),
application_1.application.graphicService.transformAABBBounds(attribute, aabbBounds, polygonTheme, !1, this),
aabbBounds;
}
findFace() {
const {points: points} = this.attribute, kList = points.map(((p, i) => {
const p1 = 3 === i ? points[0] : points[i + 1], dx = p.x - p1.x;
return 0 === dx ? 0 : (p.y - p1.y) / dx;
})), pointsMap = points.map((p => ({
p: p,
d: 0
})));
let find = !1, maxD = 0;
for (let i = 0; i < kList.length - 1; i++) {
for (let j = i + 1; j < kList.length; j++) {
if (kList[i] === kList[j]) {
find = !0;
const d1 = vutils_1.PointService.distancePP(pointsMap[i].p, pointsMap[i + 1].p);
pointsMap[i].d = d1, pointsMap[i + 1].d = d1, maxD = (0, vutils_1.max)(maxD, d1);
const d2 = vutils_1.PointService.distancePP(pointsMap[j].p, pointsMap[j + 1].p);
pointsMap[j].d = d2, pointsMap[j + 1].d = d2, maxD = (0, vutils_1.max)(maxD, d2);
}
if (find) break;
}
if (find) break;
}
for (let i = points.length - 1; i >= 0; i--) {
const p = points[i];
pointsMap.unshift({
p: p,
d: 0
});
}
for (let i = 0; i < points.length; i++) {
const delta = (maxD - pointsMap[i + points.length].d) / 2;
pointsMap[i].d += delta, pointsMap[i + points.length].d += delta;
}
const faces = {
polygons: [],
vertices: [],
edges: []
};
return pointsMap.forEach((p => {
faces.vertices.push([ p.p.x, p.p.y, p.d ]);
})), faces.polygons.push({
polygon: [ 0, 4, 5, 1 ],
normal: [ 0, -1, 0 ]
}), faces.polygons.push({
polygon: [ 7, 6, 2, 3 ],
normal: [ 0, 1, 0 ]
}), faces.polygons.push({
polygon: [ 0, 4, 7, 3 ],
normal: [ -1, 0, 0 ]
}), faces.polygons.push({
polygon: [ 1, 5, 6, 2 ],
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;
}
_isValid() {
return super._isValid() && 4 === this.attribute.points.length;
}
getNoWorkAnimateAttr() {
return Pyramid3d.NOWORK_ANIMATE_ATTR;
}
}
function createPyramid3d(attributes) {
return new Pyramid3d(attributes);
}
exports.Pyramid3d = Pyramid3d, Pyramid3d.NOWORK_ANIMATE_ATTR = graphic_1.NOWORK_ANIMATE_ATTR,
exports.createPyramid3d = createPyramid3d;
//# sourceMappingURL=pyramid3d.js.map