123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- var Sandbox;
- (function (Sandbox) {
- var PointerEventTypes = BABYLON.PointerEventTypes;
- var AbstractMesh = BABYLON.AbstractMesh;
- /**
- * The purpose of this class is to allow the camera manipulation, single node selection and manipulation.
- * You can use it as an example to create your more complexe/different interaction helper
- */
- var SimpleInteractionHelper = (function () {
- function SimpleInteractionHelper(scene) {
- var _this = this;
- this._actionStack = new Array();
- this._scene = scene;
- this._pointerObserver = this._scene.onPointerObservable.add(function (p, s) { return _this.pointerCallback(p, s); }, -1, true);
- }
- Object.defineProperty(SimpleInteractionHelper.prototype, "currentAction", {
- get: function () {
- if (this._actionStack.length === 0) {
- return 1 /* Selector */;
- }
- return this._actionStack[this._actionStack.length - 1];
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(SimpleInteractionHelper.prototype, "manipulator", {
- get: function () {
- if (!this._manipulator) {
- this._manipulator = new Sandbox.ManipulatorInteractionHelper(this._scene);
- }
- return this._manipulator;
- },
- enumerable: true,
- configurable: true
- });
- SimpleInteractionHelper.prototype.pointerCallback = function (p, s) {
- this.detectActionChanged(p, s);
- switch (this.currentAction) {
- case 1 /* Selector */:
- this.doSelectorInteraction(p, s);
- break;
- case 2 /* Camerator */:
- if (p.type & (PointerEventTypes.POINTERUP | PointerEventTypes.POINTERWHEEL)) {
- this._actionStack.pop();
- }
- break;
- }
- };
- SimpleInteractionHelper.prototype.doSelectorInteraction = function (p, s) {
- s.skipNextObservers = true;
- // We want left button up.
- if (p.type !== PointerEventTypes.POINTERUP || p.event.button !== 0) {
- return;
- }
- var selectedMesh;
- if (p.pickInfo.hit) {
- selectedMesh = p.pickInfo.pickedMesh;
- }
- // We selected the same mesh? nothing to do
- if (this._pickedNode === selectedMesh) {
- selectedMesh.showBoundingBox = !selectedMesh.showBoundingBox;
- if (selectedMesh.showBoundingBox === false) {
- this.manipulator.detachManipulatedNode(this._pickedNode);
- this._pickedNode = null;
- }
- return;
- }
- // Detach the manipulator to the current selected mesh
- if (this._pickedNode) {
- if (this._pickedNode instanceof AbstractMesh) {
- var mesh = this._pickedNode;
- mesh.showBoundingBox = false;
- }
- this.manipulator.detachManipulatedNode(this._pickedNode);
- this._pickedNode = null;
- }
- // Nothing selected, our job's done
- if (!selectedMesh) {
- return;
- }
- this._pickedNode = selectedMesh;
- selectedMesh.showBoundingBox = true;
- this.manipulator.attachManipulatedNode(this._pickedNode);
- };
- SimpleInteractionHelper.prototype.detectActionChanged = function (p, s) {
- // Detect switch from selection to camerator
- if (this.currentAction === 1 /* Selector */) {
- if (p.type === PointerEventTypes.POINTERDOWN) {
- if (!p.pickInfo.hit) {
- this._actionStack.push(2 /* Camerator */);
- return;
- }
- }
- if (p.type === PointerEventTypes.POINTERWHEEL) {
- this._actionStack.push(2 /* Camerator */);
- return;
- }
- }
- };
- SimpleInteractionHelper.CameratorSwitchThreshold = 4.0;
- return SimpleInteractionHelper;
- }());
- Sandbox.SimpleInteractionHelper = SimpleInteractionHelper;
- })(Sandbox || (Sandbox = {}));
- //# sourceMappingURL=simpleinteractionhelper.js.map
|