@visactor/vrender-core
Version:
## Description
43 lines (39 loc) • 2.28 kB
JavaScript
import { Generator } from "../../common/generator";
import { Factory } from "../../factory";
export class ViewTransform3dPlugin {
constructor() {
this.name = "ViewTransform3dPlugin", this.activeEvent = "onRegister", this._uid = Generator.GenAutoIncrementId(),
this.key = this.name + this._uid, this.onMouseDown = e => {
this.option3d || (this.option3d = this.pluginService.stage.option3d), this.option3d && (this.mousedown = !0,
this.pageX = e.page.x, this.pageY = e.page.y);
}, this.onMouseUp = e => {
this.option3d || (this.option3d = this.pluginService.stage.option3d), this.option3d && (this.mousedown = !1);
}, this.onMouseMove = e => {
var _a, _b;
const stage = this.pluginService.stage;
if (this.option3d || (this.option3d = stage.option3d), this.option3d && this.mousedown) if (this.pageX && this.pageY) {
const deltaX = e.page.x - this.pageX, deltaY = e.page.y - this.pageY;
this.pageX = e.page.x, this.pageY = e.page.y;
const angle1 = deltaX / 100, angle2 = deltaY / 100;
this.option3d.alpha = (null !== (_a = this.option3d.alpha) && void 0 !== _a ? _a : 0) + angle1,
this.option3d.beta = (null !== (_b = this.option3d.beta) && void 0 !== _b ? _b : 0) + angle2,
stage.set3dOptions(this.option3d), stage.renderNextFrame();
} else this.pageX = e.page.x, this.pageY = e.page.y;
};
}
activate(context) {
this.pluginService = context;
const stage = context.stage;
this.option3d = stage.option3d, stage.addEventListener("mousedown", this.onMouseDown),
stage.addEventListener("mouseup", this.onMouseUp), stage.addEventListener("mousemove", this.onMouseMove);
}
deactivate(context) {
const stage = context.stage;
stage.removeEventListener("mousedown", this.onMouseDown), stage.removeEventListener("mouseup", this.onMouseUp),
stage.removeEventListener("mousemove", this.onMouseMove);
}
}
export const registerViewTransform3dPlugin = () => {
Factory.registerPlugin("ViewTransform3dPlugin", ViewTransform3dPlugin);
};
//# sourceMappingURL=3dview-transform-plugin.js.map