@babylonjs/gui 5.0.0-rc.5 → 5.0.0-rc.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/2D/adtInstrumentation.d.ts +52 -52
- package/2D/adtInstrumentation.js +126 -126
- package/2D/advancedDynamicTexture.d.ts +448 -448
- package/2D/advancedDynamicTexture.js +1318 -1318
- package/2D/controls/button.d.ts +135 -135
- package/2D/controls/button.js +276 -276
- package/2D/controls/checkbox.d.ts +59 -59
- package/2D/controls/checkbox.js +188 -188
- package/2D/controls/colorpicker.d.ts +103 -103
- package/2D/controls/colorpicker.js +1417 -1417
- package/2D/controls/container.d.ts +175 -175
- package/2D/controls/container.js +570 -570
- package/2D/controls/control.d.ts +866 -866
- package/2D/controls/control.js +2433 -2433
- package/2D/controls/displayGrid.d.ts +53 -53
- package/2D/controls/displayGrid.js +245 -245
- package/2D/controls/ellipse.d.ts +21 -21
- package/2D/controls/ellipse.js +85 -85
- package/2D/controls/focusableButton.d.ts +59 -59
- package/2D/controls/focusableButton.js +99 -99
- package/2D/controls/focusableControl.d.ts +34 -34
- package/2D/controls/focusableControl.js +1 -1
- package/2D/controls/grid.d.ts +139 -139
- package/2D/controls/grid.js +529 -529
- package/2D/controls/image.d.ts +204 -204
- package/2D/controls/image.js +887 -887
- package/2D/controls/index.d.ts +29 -29
- package/2D/controls/index.js +29 -29
- package/2D/controls/inputPassword.d.ts +8 -8
- package/2D/controls/inputPassword.js +25 -25
- package/2D/controls/inputText.d.ts +201 -201
- package/2D/controls/inputText.js +1119 -1119
- package/2D/controls/line.d.ts +66 -66
- package/2D/controls/line.js +271 -271
- package/2D/controls/multiLine.d.ts +75 -75
- package/2D/controls/multiLine.js +262 -262
- package/2D/controls/radioButton.d.ts +49 -49
- package/2D/controls/radioButton.js +205 -205
- package/2D/controls/rectangle.d.ts +29 -29
- package/2D/controls/rectangle.js +150 -150
- package/2D/controls/scrollViewers/scrollViewer.d.ts +182 -182
- package/2D/controls/scrollViewers/scrollViewer.js +677 -677
- package/2D/controls/scrollViewers/scrollViewerWindow.d.ts +57 -57
- package/2D/controls/scrollViewers/scrollViewerWindow.js +278 -278
- package/2D/controls/selector.d.ts +263 -263
- package/2D/controls/selector.js +692 -692
- package/2D/controls/sliders/baseSlider.d.ts +82 -82
- package/2D/controls/sliders/baseSlider.js +347 -347
- package/2D/controls/sliders/imageBasedSlider.d.ts +49 -49
- package/2D/controls/sliders/imageBasedSlider.js +192 -192
- package/2D/controls/sliders/imageScrollBar.d.ts +65 -65
- package/2D/controls/sliders/imageScrollBar.js +263 -263
- package/2D/controls/sliders/scrollBar.d.ts +38 -38
- package/2D/controls/sliders/scrollBar.js +143 -143
- package/2D/controls/sliders/slider.d.ts +35 -35
- package/2D/controls/sliders/slider.js +271 -271
- package/2D/controls/stackPanel.d.ts +64 -64
- package/2D/controls/stackPanel.js +246 -246
- package/2D/controls/statics.d.ts +6 -6
- package/2D/controls/statics.js +49 -49
- package/2D/controls/textBlock.d.ts +175 -175
- package/2D/controls/textBlock.js +603 -603
- package/2D/controls/textWrapper.d.ts +13 -13
- package/2D/controls/textWrapper.js +101 -101
- package/2D/controls/toggleButton.d.ts +117 -117
- package/2D/controls/toggleButton.js +268 -268
- package/2D/controls/virtualKeyboard.d.ts +96 -96
- package/2D/controls/virtualKeyboard.js +256 -256
- package/2D/index.d.ts +9 -9
- package/2D/index.js +9 -9
- package/2D/math2D.d.ts +117 -117
- package/2D/math2D.js +221 -221
- package/2D/measure.d.ts +77 -77
- package/2D/measure.js +139 -139
- package/2D/multiLinePoint.d.ts +47 -47
- package/2D/multiLinePoint.js +127 -127
- package/2D/style.d.ts +46 -46
- package/2D/style.js +97 -97
- package/2D/valueAndUnit.d.ts +89 -89
- package/2D/valueAndUnit.js +226 -226
- package/2D/xmlLoader.d.ts +60 -60
- package/2D/xmlLoader.js +348 -348
- package/3D/behaviors/defaultBehavior.d.ts +73 -73
- package/3D/behaviors/defaultBehavior.js +121 -121
- package/3D/controls/abstractButton3D.d.ts +15 -15
- package/3D/controls/abstractButton3D.js +25 -25
- package/3D/controls/button3D.d.ts +30 -30
- package/3D/controls/button3D.js +93 -93
- package/3D/controls/container3D.d.ts +72 -72
- package/3D/controls/container3D.js +139 -139
- package/3D/controls/contentDisplay3D.d.ts +30 -30
- package/3D/controls/contentDisplay3D.js +79 -79
- package/3D/controls/control3D.d.ts +201 -201
- package/3D/controls/control3D.js +445 -445
- package/3D/controls/cylinderPanel.d.ts +17 -17
- package/3D/controls/cylinderPanel.js +66 -66
- package/3D/controls/handMenu.d.ts +28 -28
- package/3D/controls/handMenu.js +47 -47
- package/3D/controls/holographicBackplate.d.ts +49 -49
- package/3D/controls/holographicBackplate.js +120 -120
- package/3D/controls/holographicButton.d.ts +84 -84
- package/3D/controls/holographicButton.js +339 -339
- package/3D/controls/holographicSlate.d.ts +131 -131
- package/3D/controls/holographicSlate.js +431 -431
- package/3D/controls/index.d.ts +21 -21
- package/3D/controls/index.js +21 -21
- package/3D/controls/meshButton3D.d.ts +21 -21
- package/3D/controls/meshButton3D.js +62 -62
- package/3D/controls/nearMenu.d.ts +44 -44
- package/3D/controls/nearMenu.js +114 -114
- package/3D/controls/planePanel.d.ts +9 -9
- package/3D/controls/planePanel.js +36 -36
- package/3D/controls/scatterPanel.d.ts +18 -18
- package/3D/controls/scatterPanel.js +108 -108
- package/3D/controls/slider3D.d.ts +81 -81
- package/3D/controls/slider3D.js +268 -268
- package/3D/controls/spherePanel.d.ts +17 -17
- package/3D/controls/spherePanel.js +67 -67
- package/3D/controls/stackPanel3D.d.ts +22 -22
- package/3D/controls/stackPanel3D.js +107 -107
- package/3D/controls/touchButton3D.d.ts +80 -80
- package/3D/controls/touchButton3D.js +233 -233
- package/3D/controls/touchHolographicButton.d.ts +110 -110
- package/3D/controls/touchHolographicButton.js +445 -445
- package/3D/controls/touchHolographicMenu.d.ts +61 -61
- package/3D/controls/touchHolographicMenu.js +149 -149
- package/3D/controls/touchMeshButton3D.d.ts +21 -21
- package/3D/controls/touchMeshButton3D.js +62 -62
- package/3D/controls/volumeBasedPanel.d.ts +53 -53
- package/3D/controls/volumeBasedPanel.js +174 -174
- package/3D/gizmos/gizmoHandle.d.ts +108 -108
- package/3D/gizmos/gizmoHandle.js +209 -209
- package/3D/gizmos/index.d.ts +2 -2
- package/3D/gizmos/index.js +2 -2
- package/3D/gizmos/slateGizmo.d.ts +57 -57
- package/3D/gizmos/slateGizmo.js +369 -369
- package/3D/gui3DManager.d.ts +94 -94
- package/3D/gui3DManager.js +257 -257
- package/3D/index.d.ts +5 -5
- package/3D/index.js +5 -5
- package/3D/materials/fluent/fluentMaterial.d.ts +90 -90
- package/3D/materials/fluent/fluentMaterial.js +292 -292
- package/3D/materials/fluent/index.d.ts +1 -1
- package/3D/materials/fluent/index.js +1 -1
- package/3D/materials/fluent/shaders/fluent.fragment.d.ts +5 -5
- package/3D/materials/fluent/shaders/fluent.fragment.js +8 -8
- package/3D/materials/fluent/shaders/fluent.vertex.d.ts +5 -5
- package/3D/materials/fluent/shaders/fluent.vertex.js +8 -8
- package/3D/materials/fluentBackplate/fluentBackplateMaterial.d.ts +154 -154
- package/3D/materials/fluentBackplate/fluentBackplateMaterial.js +469 -469
- package/3D/materials/fluentBackplate/index.d.ts +1 -1
- package/3D/materials/fluentBackplate/index.js +1 -1
- package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.d.ts +5 -5
- package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.js +8 -8
- package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.d.ts +5 -5
- package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.js +8 -8
- package/3D/materials/fluentButton/fluentButtonMaterial.d.ts +189 -189
- package/3D/materials/fluentButton/fluentButtonMaterial.js +539 -539
- package/3D/materials/fluentButton/index.d.ts +1 -1
- package/3D/materials/fluentButton/index.js +1 -1
- package/3D/materials/fluentButton/shaders/fluentButton.fragment.d.ts +5 -5
- package/3D/materials/fluentButton/shaders/fluentButton.fragment.js +8 -8
- package/3D/materials/fluentButton/shaders/fluentButton.vertex.d.ts +5 -5
- package/3D/materials/fluentButton/shaders/fluentButton.vertex.js +8 -8
- package/3D/materials/fluentMaterial.d.ts +4 -4
- package/3D/materials/fluentMaterial.js +4 -4
- package/3D/materials/handle/handleMaterial.d.ts +68 -68
- package/3D/materials/handle/handleMaterial.js +126 -126
- package/3D/materials/handle/index.d.ts +1 -1
- package/3D/materials/handle/index.js +1 -1
- package/3D/materials/handle/shaders/handle.fragment.d.ts +5 -5
- package/3D/materials/handle/shaders/handle.fragment.js +8 -8
- package/3D/materials/handle/shaders/handle.vertex.d.ts +5 -5
- package/3D/materials/handle/shaders/handle.vertex.js +8 -8
- package/3D/materials/index.d.ts +5 -5
- package/3D/materials/index.js +5 -5
- package/3D/materials/mrdl/index.d.ts +3 -3
- package/3D/materials/mrdl/index.js +3 -3
- package/3D/materials/mrdl/mrdlBackplateMaterial.d.ts +147 -147
- package/3D/materials/mrdl/mrdlBackplateMaterial.js +436 -436
- package/3D/materials/mrdl/mrdlSliderBarMaterial.d.ts +333 -333
- package/3D/materials/mrdl/mrdlSliderBarMaterial.js +851 -851
- package/3D/materials/mrdl/mrdlSliderThumbMaterial.d.ts +333 -333
- package/3D/materials/mrdl/mrdlSliderThumbMaterial.js +851 -851
- package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.d.ts +5 -5
- package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.js +8 -8
- package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.d.ts +5 -5
- package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.js +8 -8
- package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.d.ts +5 -5
- package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.js +8 -8
- package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.d.ts +5 -5
- package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.js +8 -8
- package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.d.ts +5 -5
- package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.js +8 -8
- package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.d.ts +5 -5
- package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.js +8 -8
- package/3D/vector3WithInfo.d.ts +16 -16
- package/3D/vector3WithInfo.js +23 -23
- package/index.d.ts +2 -2
- package/index.js +2 -2
- package/legacy/legacy.d.ts +1 -1
- package/legacy/legacy.js +13 -13
- package/package.json +2 -2
package/3D/gizmos/slateGizmo.js
CHANGED
|
@@ -1,370 +1,370 @@
|
|
|
1
|
-
import { __extends } from "tslib";
|
|
2
|
-
import { Gizmo } from "@babylonjs/core/Gizmos/gizmo.js";
|
|
3
|
-
import { Epsilon } from "@babylonjs/core/Maths/math.constants.js";
|
|
4
|
-
import { Matrix, Quaternion, TmpVectors, Vector3 } from "@babylonjs/core/Maths/math.vector.js";
|
|
5
|
-
import { TransformNode } from "@babylonjs/core/Meshes/transformNode.js";
|
|
6
|
-
import { PivotTools } from "@babylonjs/core/Misc/pivotTools.js";
|
|
7
|
-
import { CornerHandle, SideHandle } from "./gizmoHandle
|
|
8
|
-
/**
|
|
9
|
-
* Gizmo to resize 2D slates
|
|
10
|
-
*/
|
|
11
|
-
var SlateGizmo = /** @class */ (function (_super) {
|
|
12
|
-
__extends(SlateGizmo, _super);
|
|
13
|
-
function SlateGizmo(utilityLayer) {
|
|
14
|
-
var _this = _super.call(this, utilityLayer) || this;
|
|
15
|
-
_this._boundingDimensions = new Vector3(0, 0, 0);
|
|
16
|
-
_this._renderObserver = null;
|
|
17
|
-
_this._tmpQuaternion = new Quaternion();
|
|
18
|
-
_this._tmpVector = new Vector3(0, 0, 0);
|
|
19
|
-
// Ordered bl, br, tr, tl
|
|
20
|
-
_this._corners = [];
|
|
21
|
-
// Ordered left, bottom, right, top
|
|
22
|
-
_this._sides = [];
|
|
23
|
-
_this._boundingBoxGizmo = {
|
|
24
|
-
min: new Vector3(),
|
|
25
|
-
max: new Vector3(),
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Value we use to offset handles from mesh
|
|
29
|
-
*/
|
|
30
|
-
_this._margin = 0.35;
|
|
31
|
-
_this._handleSize = 0.075;
|
|
32
|
-
_this._attachedSlate = null;
|
|
33
|
-
_this._existingSlateScale = new Vector3();
|
|
34
|
-
/**
|
|
35
|
-
* If set, the handles will increase in size based on the distance away from the camera to have a consistent screen size (Default: true)
|
|
36
|
-
*/
|
|
37
|
-
_this.fixedScreenSize = false;
|
|
38
|
-
/**
|
|
39
|
-
* The distance away from the object which the draggable meshes should appear world sized when fixedScreenSize is set to true (default: 10)
|
|
40
|
-
*/
|
|
41
|
-
_this.fixedScreenSizeDistanceFactor = 10;
|
|
42
|
-
_this._createNode();
|
|
43
|
-
_this.updateScale = false;
|
|
44
|
-
_this._renderObserver = _this.gizmoLayer.originalScene.onBeforeRenderObservable.add(function () {
|
|
45
|
-
// Only update the bounding box if scaling has changed
|
|
46
|
-
if (_this.attachedMesh && !_this._existingSlateScale.equals(_this.attachedMesh.scaling)) {
|
|
47
|
-
_this.updateBoundingBox();
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
return _this;
|
|
51
|
-
}
|
|
52
|
-
Object.defineProperty(SlateGizmo.prototype, "attachedSlate", {
|
|
53
|
-
get: function () {
|
|
54
|
-
return this._attachedSlate;
|
|
55
|
-
},
|
|
56
|
-
/**
|
|
57
|
-
* The slate attached to this gizmo
|
|
58
|
-
*/
|
|
59
|
-
set: function (control) {
|
|
60
|
-
var _this = this;
|
|
61
|
-
if (control) {
|
|
62
|
-
this.attachedMesh = control.mesh;
|
|
63
|
-
this.updateBoundingBox();
|
|
64
|
-
this._pickedPointObserver = control._host.onPickingObservable.add(function (pickedMesh) {
|
|
65
|
-
if (_this._handleHovered && (!pickedMesh || pickedMesh.parent !== _this._handleHovered.node)) {
|
|
66
|
-
_this._handleHovered.hover = false;
|
|
67
|
-
_this._handleHovered = null;
|
|
68
|
-
}
|
|
69
|
-
if (pickedMesh && pickedMesh.parent && pickedMesh.parent.reservedDataStore && pickedMesh.parent.reservedDataStore.handle) {
|
|
70
|
-
var handle = pickedMesh.parent.reservedDataStore.handle;
|
|
71
|
-
if (handle.gizmo === _this) {
|
|
72
|
-
_this._handleHovered = handle;
|
|
73
|
-
_this._handleHovered.hover = true;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
else if (this._attachedSlate) {
|
|
79
|
-
this._attachedSlate._host.onPickingObservable.remove(this._pickedPointObserver);
|
|
80
|
-
}
|
|
81
|
-
this._attachedSlate = control;
|
|
82
|
-
},
|
|
83
|
-
enumerable: false,
|
|
84
|
-
configurable: true
|
|
85
|
-
});
|
|
86
|
-
SlateGizmo.prototype._createNode = function () {
|
|
87
|
-
var _this = this;
|
|
88
|
-
this._handlesParent = new TransformNode("handlesParent", this.gizmoLayer.utilityLayerScene);
|
|
89
|
-
this._handlesParent.rotationQuaternion = Quaternion.Identity();
|
|
90
|
-
var masksCorners = [
|
|
91
|
-
{
|
|
92
|
-
dimensions: new Vector3(-1, -1, 0),
|
|
93
|
-
origin: new Vector3(1, 0, 0),
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
dimensions: new Vector3(1, -1, 0),
|
|
97
|
-
origin: new Vector3(0, 0, 0),
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
dimensions: new Vector3(1, 1, 0),
|
|
101
|
-
origin: new Vector3(0, 1, 0),
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
dimensions: new Vector3(-1, 1, 0),
|
|
105
|
-
origin: new Vector3(1, 1, 0),
|
|
106
|
-
},
|
|
107
|
-
];
|
|
108
|
-
for (var i = 0; i < 4; i++) {
|
|
109
|
-
var corner = new CornerHandle(this, this.gizmoLayer.utilityLayerScene);
|
|
110
|
-
this._corners.push(corner);
|
|
111
|
-
corner.node.rotation.z = (Math.PI / 2) * i;
|
|
112
|
-
corner.node.parent = this._handlesParent;
|
|
113
|
-
this._assignDragBehaviorCorners(corner, function (originStart, dimensionsStart, offset, masks) { return _this._moveHandle(originStart, dimensionsStart, offset, masks, true); }, masksCorners[i]);
|
|
114
|
-
}
|
|
115
|
-
for (var i = 0; i < 4; i++) {
|
|
116
|
-
var side = new SideHandle(this, this.gizmoLayer.utilityLayerScene);
|
|
117
|
-
this._sides.push(side);
|
|
118
|
-
side.node.rotation.z = (Math.PI / 2) * i;
|
|
119
|
-
side.node.parent = this._handlesParent;
|
|
120
|
-
this._assignDragBehaviorSides(side, i % 2 === 0 ? new Vector3(0, 1, 0) : new Vector3(1, 0, 0));
|
|
121
|
-
}
|
|
122
|
-
this._handlesParent.parent = this._rootMesh;
|
|
123
|
-
};
|
|
124
|
-
SlateGizmo.prototype._keepAspectRatio = function (vector, aspectRatio, invertDiagonal) {
|
|
125
|
-
if (invertDiagonal === void 0) { invertDiagonal = false; }
|
|
126
|
-
var axis = TmpVectors.Vector3[0];
|
|
127
|
-
axis.copyFromFloats(aspectRatio, 1, 0).normalize();
|
|
128
|
-
if (invertDiagonal) {
|
|
129
|
-
axis.y *= -1;
|
|
130
|
-
}
|
|
131
|
-
var dot = Vector3.Dot(vector, axis);
|
|
132
|
-
vector.copyFrom(axis).scaleInPlace(dot);
|
|
133
|
-
};
|
|
134
|
-
SlateGizmo.prototype._clampDimensions = function (vector, dimensions, mask, keepAspectRatio) {
|
|
135
|
-
if (keepAspectRatio === void 0) { keepAspectRatio = false; }
|
|
136
|
-
var impact = TmpVectors.Vector3[0];
|
|
137
|
-
impact.copyFrom(vector).multiplyInPlace(mask);
|
|
138
|
-
var clampedDimensions = TmpVectors.Vector3[1];
|
|
139
|
-
clampedDimensions.copyFromFloats(Math.max(this._attachedSlate.minDimensions.x, impact.x + dimensions.x), Math.max(this._attachedSlate.minDimensions.y, impact.y + dimensions.y), 0);
|
|
140
|
-
if (keepAspectRatio) {
|
|
141
|
-
// Extra logic to ensure the ratio is maintained when the vector has been clamped
|
|
142
|
-
var ratio = dimensions.x / dimensions.y;
|
|
143
|
-
clampedDimensions.x = Math.max(clampedDimensions.x, clampedDimensions.y * ratio);
|
|
144
|
-
clampedDimensions.y = Math.max(clampedDimensions.y, clampedDimensions.x / ratio);
|
|
145
|
-
}
|
|
146
|
-
// Calculating the real impact of vector on clamped dimensions
|
|
147
|
-
impact.copyFrom(clampedDimensions).subtractInPlace(dimensions);
|
|
148
|
-
vector.x = Math.sign(vector.x) * Math.abs(impact.x);
|
|
149
|
-
vector.y = Math.sign(vector.y) * Math.abs(impact.y);
|
|
150
|
-
};
|
|
151
|
-
SlateGizmo.prototype._moveHandle = function (originStart, dimensionsStart, offset, masks, isCorner) {
|
|
152
|
-
if (!this._attachedSlate) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
if (isCorner) {
|
|
156
|
-
var aspectRatio = dimensionsStart.x / dimensionsStart.y;
|
|
157
|
-
this._keepAspectRatio(offset, aspectRatio, masks.dimensions.x * masks.dimensions.y < 0);
|
|
158
|
-
}
|
|
159
|
-
this._clampDimensions(offset, dimensionsStart, masks.dimensions, isCorner);
|
|
160
|
-
var offsetOriginMasked = TmpVectors.Vector3[0];
|
|
161
|
-
var offsetDimensionsMasked = TmpVectors.Vector3[1];
|
|
162
|
-
offsetOriginMasked.copyFrom(offset).multiplyInPlace(masks.origin);
|
|
163
|
-
offsetDimensionsMasked.copyFrom(offset).multiplyInPlace(masks.dimensions);
|
|
164
|
-
this._attachedSlate.origin.copyFrom(originStart).addInPlace(offsetOriginMasked);
|
|
165
|
-
this._attachedSlate.dimensions.set(dimensionsStart.x + offsetDimensionsMasked.x, dimensionsStart.y + offsetDimensionsMasked.y);
|
|
166
|
-
};
|
|
167
|
-
SlateGizmo.prototype._assignDragBehaviorCorners = function (handle, moveFn, masks) {
|
|
168
|
-
var _this = this;
|
|
169
|
-
var dimensionsStart = new Vector3();
|
|
170
|
-
var originStart = new Vector3();
|
|
171
|
-
var dragOrigin = new Vector3();
|
|
172
|
-
var toObjectFrame = new Matrix();
|
|
173
|
-
var dragPlaneNormal = new Vector3();
|
|
174
|
-
var projectToRef = function (position, normal, origin, ref) {
|
|
175
|
-
// Projects on the plane with its normal and origin
|
|
176
|
-
position.subtractToRef(origin, TmpVectors.Vector3[0]);
|
|
177
|
-
var dot = Vector3.Dot(TmpVectors.Vector3[0], normal);
|
|
178
|
-
TmpVectors.Vector3[1].copyFrom(normal).scaleInPlace(dot);
|
|
179
|
-
TmpVectors.Vector3[0].subtractInPlace(TmpVectors.Vector3[1]);
|
|
180
|
-
TmpVectors.Vector3[0].addToRef(origin, ref);
|
|
181
|
-
};
|
|
182
|
-
var dragStart = function (event) {
|
|
183
|
-
if (_this.attachedSlate && _this.attachedMesh) {
|
|
184
|
-
dimensionsStart.set(_this.attachedSlate.dimensions.x, _this.attachedSlate.dimensions.y, Epsilon);
|
|
185
|
-
originStart.copyFrom(_this.attachedSlate.origin);
|
|
186
|
-
dragOrigin.copyFrom(event.position);
|
|
187
|
-
toObjectFrame.copyFrom(_this.attachedMesh.computeWorldMatrix(true));
|
|
188
|
-
toObjectFrame.invert();
|
|
189
|
-
_this.attachedSlate._followButton.isToggled = false;
|
|
190
|
-
Vector3.TransformNormalToRef(Vector3.Forward(), _this.attachedMesh.getWorldMatrix(), dragPlaneNormal);
|
|
191
|
-
dragPlaneNormal.normalize();
|
|
192
|
-
if (_this._handleHovered) {
|
|
193
|
-
_this._handleDragged = _this._handleHovered;
|
|
194
|
-
_this._handleDragged.drag = true;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
var dragging = function (event) {
|
|
199
|
-
if (_this.attachedSlate && _this.attachedMesh) {
|
|
200
|
-
projectToRef(event.position, dragPlaneNormal, dragOrigin, _this._tmpVector);
|
|
201
|
-
_this._tmpVector.subtractInPlace(dragOrigin);
|
|
202
|
-
Vector3.TransformNormalToRef(_this._tmpVector, toObjectFrame, _this._tmpVector);
|
|
203
|
-
moveFn(originStart, dimensionsStart, _this._tmpVector, masks);
|
|
204
|
-
_this.attachedSlate._positionElements();
|
|
205
|
-
_this.updateBoundingBox();
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
var dragEnd = function () {
|
|
209
|
-
if (_this.attachedSlate && _this.attachedNode) {
|
|
210
|
-
_this.attachedSlate._updatePivot();
|
|
211
|
-
if (_this._handleDragged) {
|
|
212
|
-
_this._handleDragged.drag = false;
|
|
213
|
-
_this._handleDragged = null;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
handle.setDragBehavior(dragStart, dragging, dragEnd);
|
|
218
|
-
};
|
|
219
|
-
SlateGizmo.prototype._assignDragBehaviorSides = function (handle, dragPlaneNormal) {
|
|
220
|
-
var _this = this;
|
|
221
|
-
var quaternionOrigin = new Quaternion();
|
|
222
|
-
var dragOrigin = new Vector3();
|
|
223
|
-
var directionOrigin = new Vector3();
|
|
224
|
-
var worldPivot = new Vector3();
|
|
225
|
-
var worldPlaneNormal = new Vector3();
|
|
226
|
-
var dragStart = function (event) {
|
|
227
|
-
if (_this.attachedSlate && _this.attachedMesh) {
|
|
228
|
-
quaternionOrigin.copyFrom(_this.attachedMesh.rotationQuaternion);
|
|
229
|
-
dragOrigin.copyFrom(event.position);
|
|
230
|
-
worldPivot.copyFrom(_this.attachedMesh.getAbsolutePivotPoint());
|
|
231
|
-
directionOrigin.copyFrom(dragOrigin).subtractInPlace(worldPivot).normalize();
|
|
232
|
-
_this.attachedSlate._followButton.isToggled = false;
|
|
233
|
-
Vector3.TransformNormalToRef(dragPlaneNormal, _this.attachedMesh.getWorldMatrix(), worldPlaneNormal);
|
|
234
|
-
worldPlaneNormal.normalize();
|
|
235
|
-
if (_this._handleHovered) {
|
|
236
|
-
_this._handleDragged = _this._handleHovered;
|
|
237
|
-
_this._handleDragged.drag = true;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
var dragging = function (event) {
|
|
242
|
-
if (_this.attachedSlate && _this.attachedMesh) {
|
|
243
|
-
_this._tmpVector.copyFrom(event.position);
|
|
244
|
-
_this._tmpVector.subtractInPlace(worldPivot);
|
|
245
|
-
_this._tmpVector.normalize();
|
|
246
|
-
var angle = -Vector3.GetAngleBetweenVectorsOnPlane(_this._tmpVector, directionOrigin, worldPlaneNormal);
|
|
247
|
-
Quaternion.RotationAxisToRef(dragPlaneNormal, angle, _this._tmpQuaternion);
|
|
248
|
-
quaternionOrigin.multiplyToRef(_this._tmpQuaternion, _this.attachedMesh.rotationQuaternion);
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
var dragEnd = function () {
|
|
252
|
-
if (_this.attachedSlate && _this.attachedNode) {
|
|
253
|
-
_this.attachedSlate._updatePivot();
|
|
254
|
-
if (_this._handleDragged) {
|
|
255
|
-
_this._handleDragged.drag = false;
|
|
256
|
-
_this._handleDragged = null;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
handle.setDragBehavior(dragStart, dragging, dragEnd);
|
|
261
|
-
};
|
|
262
|
-
SlateGizmo.prototype._attachedNodeChanged = function (value) {
|
|
263
|
-
if (value) {
|
|
264
|
-
this.updateBoundingBox();
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
/**
|
|
268
|
-
* Updates the bounding box information for the gizmo
|
|
269
|
-
*/
|
|
270
|
-
SlateGizmo.prototype.updateBoundingBox = function () {
|
|
271
|
-
if (this.attachedMesh) {
|
|
272
|
-
PivotTools._RemoveAndStorePivotPoint(this.attachedMesh);
|
|
273
|
-
// Store original parent
|
|
274
|
-
var originalParent = this.attachedMesh.parent;
|
|
275
|
-
this.attachedMesh.setParent(null);
|
|
276
|
-
this._update();
|
|
277
|
-
// Rotate based on axis
|
|
278
|
-
if (!this.attachedMesh.rotationQuaternion) {
|
|
279
|
-
this.attachedMesh.rotationQuaternion = Quaternion.RotationYawPitchRoll(this.attachedMesh.rotation.y, this.attachedMesh.rotation.x, this.attachedMesh.rotation.z);
|
|
280
|
-
}
|
|
281
|
-
// Store original position and reset mesh to origin before computing the bounding box
|
|
282
|
-
this._tmpQuaternion.copyFrom(this.attachedMesh.rotationQuaternion);
|
|
283
|
-
this._tmpVector.copyFrom(this.attachedMesh.position);
|
|
284
|
-
this.attachedMesh.rotationQuaternion.set(0, 0, 0, 1);
|
|
285
|
-
this.attachedMesh.position.set(0, 0, 0);
|
|
286
|
-
// Update bounding dimensions/positions
|
|
287
|
-
var boundingMinMax = this.attachedMesh.getHierarchyBoundingVectors();
|
|
288
|
-
boundingMinMax.max.subtractToRef(boundingMinMax.min, this._boundingDimensions);
|
|
289
|
-
this._boundingBoxGizmo.min = boundingMinMax.min;
|
|
290
|
-
this._boundingBoxGizmo.max = boundingMinMax.max;
|
|
291
|
-
// Update handles of the gizmo
|
|
292
|
-
this._updateHandlesPosition();
|
|
293
|
-
this._updateHandlesScaling();
|
|
294
|
-
// Restore position/rotation values
|
|
295
|
-
this.attachedMesh.rotationQuaternion.copyFrom(this._tmpQuaternion);
|
|
296
|
-
this.attachedMesh.position.copyFrom(this._tmpVector);
|
|
297
|
-
PivotTools._RestorePivotPoint(this.attachedMesh);
|
|
298
|
-
// Restore original parent
|
|
299
|
-
this.attachedMesh.setParent(originalParent);
|
|
300
|
-
this.attachedMesh.computeWorldMatrix(true);
|
|
301
|
-
this._existingSlateScale.copyFrom(this.attachedMesh.scaling);
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
SlateGizmo.prototype._updateHandlesPosition = function () {
|
|
305
|
-
var min = this._boundingBoxGizmo.min.clone();
|
|
306
|
-
var max = this._boundingBoxGizmo.max.clone();
|
|
307
|
-
var handleScaling = this._corners[0].node.scaling.length();
|
|
308
|
-
min.x -= this._margin * handleScaling;
|
|
309
|
-
min.y -= this._margin * handleScaling;
|
|
310
|
-
max.x += this._margin * handleScaling;
|
|
311
|
-
max.y += this._margin * handleScaling;
|
|
312
|
-
var center = min.add(max).scaleInPlace(0.5);
|
|
313
|
-
this._corners[0].node.position.copyFromFloats(min.x, min.y, 0);
|
|
314
|
-
this._corners[1].node.position.copyFromFloats(max.x, min.y, 0);
|
|
315
|
-
this._corners[2].node.position.copyFromFloats(max.x, max.y, 0);
|
|
316
|
-
this._corners[3].node.position.copyFromFloats(min.x, max.y, 0);
|
|
317
|
-
this._sides[0].node.position.copyFromFloats(min.x, center.y, 0);
|
|
318
|
-
this._sides[1].node.position.copyFromFloats(center.x, min.y, 0);
|
|
319
|
-
this._sides[2].node.position.copyFromFloats(max.x, center.y, 0);
|
|
320
|
-
this._sides[3].node.position.copyFromFloats(center.x, max.y, 0);
|
|
321
|
-
};
|
|
322
|
-
SlateGizmo.prototype._updateHandlesScaling = function () {
|
|
323
|
-
if (this._attachedSlate && this._attachedSlate.mesh) {
|
|
324
|
-
var scaledWidth = this._attachedSlate.mesh.scaling.x * this._attachedSlate.dimensions.x;
|
|
325
|
-
var scaledHeight = this._attachedSlate.mesh.scaling.y * this._attachedSlate.dimensions.y;
|
|
326
|
-
var scale = Math.min(scaledWidth, scaledHeight) * this._handleSize;
|
|
327
|
-
for (var index = 0; index < this._corners.length; index++) {
|
|
328
|
-
this._corners[index].node.scaling.setAll(scale);
|
|
329
|
-
}
|
|
330
|
-
for (var index = 0; index < this._sides.length; index++) {
|
|
331
|
-
this._sides[index].node.scaling.setAll(scale);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
SlateGizmo.prototype._update = function () {
|
|
336
|
-
_super.prototype._update.call(this);
|
|
337
|
-
if (!this.gizmoLayer.utilityLayerScene.activeCamera) {
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
if (this._attachedSlate && this._attachedSlate.mesh) {
|
|
341
|
-
if (this.fixedScreenSize) {
|
|
342
|
-
this._attachedSlate.mesh.absolutePosition.subtractToRef(this.gizmoLayer.utilityLayerScene.activeCamera.position, this._tmpVector);
|
|
343
|
-
var distanceFromCamera = (this._handleSize * this._tmpVector.length()) / this.fixedScreenSizeDistanceFactor;
|
|
344
|
-
for (var i = 0; i < this._corners.length; i++) {
|
|
345
|
-
this._corners[i].node.scaling.set(distanceFromCamera, distanceFromCamera, distanceFromCamera);
|
|
346
|
-
}
|
|
347
|
-
for (var i = 0; i < this._sides.length; i++) {
|
|
348
|
-
this._sides[i].node.scaling.set(distanceFromCamera, distanceFromCamera, distanceFromCamera);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
this._updateHandlesPosition();
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
SlateGizmo.prototype.dispose = function () {
|
|
355
|
-
this.gizmoLayer.originalScene.onBeforeRenderObservable.remove(this._renderObserver);
|
|
356
|
-
// Will dispose rootMesh and all descendants
|
|
357
|
-
_super.prototype.dispose.call(this);
|
|
358
|
-
for (var _i = 0, _a = this._corners; _i < _a.length; _i++) {
|
|
359
|
-
var corner = _a[_i];
|
|
360
|
-
corner.dispose();
|
|
361
|
-
}
|
|
362
|
-
for (var _b = 0, _c = this._sides; _b < _c.length; _b++) {
|
|
363
|
-
var side = _c[_b];
|
|
364
|
-
side.dispose();
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
return SlateGizmo;
|
|
368
|
-
}(Gizmo));
|
|
369
|
-
export { SlateGizmo };
|
|
1
|
+
import { __extends } from "tslib";
|
|
2
|
+
import { Gizmo } from "@babylonjs/core/Gizmos/gizmo.js";
|
|
3
|
+
import { Epsilon } from "@babylonjs/core/Maths/math.constants.js";
|
|
4
|
+
import { Matrix, Quaternion, TmpVectors, Vector3 } from "@babylonjs/core/Maths/math.vector.js";
|
|
5
|
+
import { TransformNode } from "@babylonjs/core/Meshes/transformNode.js";
|
|
6
|
+
import { PivotTools } from "@babylonjs/core/Misc/pivotTools.js";
|
|
7
|
+
import { CornerHandle, SideHandle } from "./gizmoHandle";
|
|
8
|
+
/**
|
|
9
|
+
* Gizmo to resize 2D slates
|
|
10
|
+
*/
|
|
11
|
+
var SlateGizmo = /** @class */ (function (_super) {
|
|
12
|
+
__extends(SlateGizmo, _super);
|
|
13
|
+
function SlateGizmo(utilityLayer) {
|
|
14
|
+
var _this = _super.call(this, utilityLayer) || this;
|
|
15
|
+
_this._boundingDimensions = new Vector3(0, 0, 0);
|
|
16
|
+
_this._renderObserver = null;
|
|
17
|
+
_this._tmpQuaternion = new Quaternion();
|
|
18
|
+
_this._tmpVector = new Vector3(0, 0, 0);
|
|
19
|
+
// Ordered bl, br, tr, tl
|
|
20
|
+
_this._corners = [];
|
|
21
|
+
// Ordered left, bottom, right, top
|
|
22
|
+
_this._sides = [];
|
|
23
|
+
_this._boundingBoxGizmo = {
|
|
24
|
+
min: new Vector3(),
|
|
25
|
+
max: new Vector3(),
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Value we use to offset handles from mesh
|
|
29
|
+
*/
|
|
30
|
+
_this._margin = 0.35;
|
|
31
|
+
_this._handleSize = 0.075;
|
|
32
|
+
_this._attachedSlate = null;
|
|
33
|
+
_this._existingSlateScale = new Vector3();
|
|
34
|
+
/**
|
|
35
|
+
* If set, the handles will increase in size based on the distance away from the camera to have a consistent screen size (Default: true)
|
|
36
|
+
*/
|
|
37
|
+
_this.fixedScreenSize = false;
|
|
38
|
+
/**
|
|
39
|
+
* The distance away from the object which the draggable meshes should appear world sized when fixedScreenSize is set to true (default: 10)
|
|
40
|
+
*/
|
|
41
|
+
_this.fixedScreenSizeDistanceFactor = 10;
|
|
42
|
+
_this._createNode();
|
|
43
|
+
_this.updateScale = false;
|
|
44
|
+
_this._renderObserver = _this.gizmoLayer.originalScene.onBeforeRenderObservable.add(function () {
|
|
45
|
+
// Only update the bounding box if scaling has changed
|
|
46
|
+
if (_this.attachedMesh && !_this._existingSlateScale.equals(_this.attachedMesh.scaling)) {
|
|
47
|
+
_this.updateBoundingBox();
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return _this;
|
|
51
|
+
}
|
|
52
|
+
Object.defineProperty(SlateGizmo.prototype, "attachedSlate", {
|
|
53
|
+
get: function () {
|
|
54
|
+
return this._attachedSlate;
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* The slate attached to this gizmo
|
|
58
|
+
*/
|
|
59
|
+
set: function (control) {
|
|
60
|
+
var _this = this;
|
|
61
|
+
if (control) {
|
|
62
|
+
this.attachedMesh = control.mesh;
|
|
63
|
+
this.updateBoundingBox();
|
|
64
|
+
this._pickedPointObserver = control._host.onPickingObservable.add(function (pickedMesh) {
|
|
65
|
+
if (_this._handleHovered && (!pickedMesh || pickedMesh.parent !== _this._handleHovered.node)) {
|
|
66
|
+
_this._handleHovered.hover = false;
|
|
67
|
+
_this._handleHovered = null;
|
|
68
|
+
}
|
|
69
|
+
if (pickedMesh && pickedMesh.parent && pickedMesh.parent.reservedDataStore && pickedMesh.parent.reservedDataStore.handle) {
|
|
70
|
+
var handle = pickedMesh.parent.reservedDataStore.handle;
|
|
71
|
+
if (handle.gizmo === _this) {
|
|
72
|
+
_this._handleHovered = handle;
|
|
73
|
+
_this._handleHovered.hover = true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
else if (this._attachedSlate) {
|
|
79
|
+
this._attachedSlate._host.onPickingObservable.remove(this._pickedPointObserver);
|
|
80
|
+
}
|
|
81
|
+
this._attachedSlate = control;
|
|
82
|
+
},
|
|
83
|
+
enumerable: false,
|
|
84
|
+
configurable: true
|
|
85
|
+
});
|
|
86
|
+
SlateGizmo.prototype._createNode = function () {
|
|
87
|
+
var _this = this;
|
|
88
|
+
this._handlesParent = new TransformNode("handlesParent", this.gizmoLayer.utilityLayerScene);
|
|
89
|
+
this._handlesParent.rotationQuaternion = Quaternion.Identity();
|
|
90
|
+
var masksCorners = [
|
|
91
|
+
{
|
|
92
|
+
dimensions: new Vector3(-1, -1, 0),
|
|
93
|
+
origin: new Vector3(1, 0, 0),
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
dimensions: new Vector3(1, -1, 0),
|
|
97
|
+
origin: new Vector3(0, 0, 0),
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
dimensions: new Vector3(1, 1, 0),
|
|
101
|
+
origin: new Vector3(0, 1, 0),
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
dimensions: new Vector3(-1, 1, 0),
|
|
105
|
+
origin: new Vector3(1, 1, 0),
|
|
106
|
+
},
|
|
107
|
+
];
|
|
108
|
+
for (var i = 0; i < 4; i++) {
|
|
109
|
+
var corner = new CornerHandle(this, this.gizmoLayer.utilityLayerScene);
|
|
110
|
+
this._corners.push(corner);
|
|
111
|
+
corner.node.rotation.z = (Math.PI / 2) * i;
|
|
112
|
+
corner.node.parent = this._handlesParent;
|
|
113
|
+
this._assignDragBehaviorCorners(corner, function (originStart, dimensionsStart, offset, masks) { return _this._moveHandle(originStart, dimensionsStart, offset, masks, true); }, masksCorners[i]);
|
|
114
|
+
}
|
|
115
|
+
for (var i = 0; i < 4; i++) {
|
|
116
|
+
var side = new SideHandle(this, this.gizmoLayer.utilityLayerScene);
|
|
117
|
+
this._sides.push(side);
|
|
118
|
+
side.node.rotation.z = (Math.PI / 2) * i;
|
|
119
|
+
side.node.parent = this._handlesParent;
|
|
120
|
+
this._assignDragBehaviorSides(side, i % 2 === 0 ? new Vector3(0, 1, 0) : new Vector3(1, 0, 0));
|
|
121
|
+
}
|
|
122
|
+
this._handlesParent.parent = this._rootMesh;
|
|
123
|
+
};
|
|
124
|
+
SlateGizmo.prototype._keepAspectRatio = function (vector, aspectRatio, invertDiagonal) {
|
|
125
|
+
if (invertDiagonal === void 0) { invertDiagonal = false; }
|
|
126
|
+
var axis = TmpVectors.Vector3[0];
|
|
127
|
+
axis.copyFromFloats(aspectRatio, 1, 0).normalize();
|
|
128
|
+
if (invertDiagonal) {
|
|
129
|
+
axis.y *= -1;
|
|
130
|
+
}
|
|
131
|
+
var dot = Vector3.Dot(vector, axis);
|
|
132
|
+
vector.copyFrom(axis).scaleInPlace(dot);
|
|
133
|
+
};
|
|
134
|
+
SlateGizmo.prototype._clampDimensions = function (vector, dimensions, mask, keepAspectRatio) {
|
|
135
|
+
if (keepAspectRatio === void 0) { keepAspectRatio = false; }
|
|
136
|
+
var impact = TmpVectors.Vector3[0];
|
|
137
|
+
impact.copyFrom(vector).multiplyInPlace(mask);
|
|
138
|
+
var clampedDimensions = TmpVectors.Vector3[1];
|
|
139
|
+
clampedDimensions.copyFromFloats(Math.max(this._attachedSlate.minDimensions.x, impact.x + dimensions.x), Math.max(this._attachedSlate.minDimensions.y, impact.y + dimensions.y), 0);
|
|
140
|
+
if (keepAspectRatio) {
|
|
141
|
+
// Extra logic to ensure the ratio is maintained when the vector has been clamped
|
|
142
|
+
var ratio = dimensions.x / dimensions.y;
|
|
143
|
+
clampedDimensions.x = Math.max(clampedDimensions.x, clampedDimensions.y * ratio);
|
|
144
|
+
clampedDimensions.y = Math.max(clampedDimensions.y, clampedDimensions.x / ratio);
|
|
145
|
+
}
|
|
146
|
+
// Calculating the real impact of vector on clamped dimensions
|
|
147
|
+
impact.copyFrom(clampedDimensions).subtractInPlace(dimensions);
|
|
148
|
+
vector.x = Math.sign(vector.x) * Math.abs(impact.x);
|
|
149
|
+
vector.y = Math.sign(vector.y) * Math.abs(impact.y);
|
|
150
|
+
};
|
|
151
|
+
SlateGizmo.prototype._moveHandle = function (originStart, dimensionsStart, offset, masks, isCorner) {
|
|
152
|
+
if (!this._attachedSlate) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (isCorner) {
|
|
156
|
+
var aspectRatio = dimensionsStart.x / dimensionsStart.y;
|
|
157
|
+
this._keepAspectRatio(offset, aspectRatio, masks.dimensions.x * masks.dimensions.y < 0);
|
|
158
|
+
}
|
|
159
|
+
this._clampDimensions(offset, dimensionsStart, masks.dimensions, isCorner);
|
|
160
|
+
var offsetOriginMasked = TmpVectors.Vector3[0];
|
|
161
|
+
var offsetDimensionsMasked = TmpVectors.Vector3[1];
|
|
162
|
+
offsetOriginMasked.copyFrom(offset).multiplyInPlace(masks.origin);
|
|
163
|
+
offsetDimensionsMasked.copyFrom(offset).multiplyInPlace(masks.dimensions);
|
|
164
|
+
this._attachedSlate.origin.copyFrom(originStart).addInPlace(offsetOriginMasked);
|
|
165
|
+
this._attachedSlate.dimensions.set(dimensionsStart.x + offsetDimensionsMasked.x, dimensionsStart.y + offsetDimensionsMasked.y);
|
|
166
|
+
};
|
|
167
|
+
SlateGizmo.prototype._assignDragBehaviorCorners = function (handle, moveFn, masks) {
|
|
168
|
+
var _this = this;
|
|
169
|
+
var dimensionsStart = new Vector3();
|
|
170
|
+
var originStart = new Vector3();
|
|
171
|
+
var dragOrigin = new Vector3();
|
|
172
|
+
var toObjectFrame = new Matrix();
|
|
173
|
+
var dragPlaneNormal = new Vector3();
|
|
174
|
+
var projectToRef = function (position, normal, origin, ref) {
|
|
175
|
+
// Projects on the plane with its normal and origin
|
|
176
|
+
position.subtractToRef(origin, TmpVectors.Vector3[0]);
|
|
177
|
+
var dot = Vector3.Dot(TmpVectors.Vector3[0], normal);
|
|
178
|
+
TmpVectors.Vector3[1].copyFrom(normal).scaleInPlace(dot);
|
|
179
|
+
TmpVectors.Vector3[0].subtractInPlace(TmpVectors.Vector3[1]);
|
|
180
|
+
TmpVectors.Vector3[0].addToRef(origin, ref);
|
|
181
|
+
};
|
|
182
|
+
var dragStart = function (event) {
|
|
183
|
+
if (_this.attachedSlate && _this.attachedMesh) {
|
|
184
|
+
dimensionsStart.set(_this.attachedSlate.dimensions.x, _this.attachedSlate.dimensions.y, Epsilon);
|
|
185
|
+
originStart.copyFrom(_this.attachedSlate.origin);
|
|
186
|
+
dragOrigin.copyFrom(event.position);
|
|
187
|
+
toObjectFrame.copyFrom(_this.attachedMesh.computeWorldMatrix(true));
|
|
188
|
+
toObjectFrame.invert();
|
|
189
|
+
_this.attachedSlate._followButton.isToggled = false;
|
|
190
|
+
Vector3.TransformNormalToRef(Vector3.Forward(), _this.attachedMesh.getWorldMatrix(), dragPlaneNormal);
|
|
191
|
+
dragPlaneNormal.normalize();
|
|
192
|
+
if (_this._handleHovered) {
|
|
193
|
+
_this._handleDragged = _this._handleHovered;
|
|
194
|
+
_this._handleDragged.drag = true;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
var dragging = function (event) {
|
|
199
|
+
if (_this.attachedSlate && _this.attachedMesh) {
|
|
200
|
+
projectToRef(event.position, dragPlaneNormal, dragOrigin, _this._tmpVector);
|
|
201
|
+
_this._tmpVector.subtractInPlace(dragOrigin);
|
|
202
|
+
Vector3.TransformNormalToRef(_this._tmpVector, toObjectFrame, _this._tmpVector);
|
|
203
|
+
moveFn(originStart, dimensionsStart, _this._tmpVector, masks);
|
|
204
|
+
_this.attachedSlate._positionElements();
|
|
205
|
+
_this.updateBoundingBox();
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
var dragEnd = function () {
|
|
209
|
+
if (_this.attachedSlate && _this.attachedNode) {
|
|
210
|
+
_this.attachedSlate._updatePivot();
|
|
211
|
+
if (_this._handleDragged) {
|
|
212
|
+
_this._handleDragged.drag = false;
|
|
213
|
+
_this._handleDragged = null;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
handle.setDragBehavior(dragStart, dragging, dragEnd);
|
|
218
|
+
};
|
|
219
|
+
SlateGizmo.prototype._assignDragBehaviorSides = function (handle, dragPlaneNormal) {
|
|
220
|
+
var _this = this;
|
|
221
|
+
var quaternionOrigin = new Quaternion();
|
|
222
|
+
var dragOrigin = new Vector3();
|
|
223
|
+
var directionOrigin = new Vector3();
|
|
224
|
+
var worldPivot = new Vector3();
|
|
225
|
+
var worldPlaneNormal = new Vector3();
|
|
226
|
+
var dragStart = function (event) {
|
|
227
|
+
if (_this.attachedSlate && _this.attachedMesh) {
|
|
228
|
+
quaternionOrigin.copyFrom(_this.attachedMesh.rotationQuaternion);
|
|
229
|
+
dragOrigin.copyFrom(event.position);
|
|
230
|
+
worldPivot.copyFrom(_this.attachedMesh.getAbsolutePivotPoint());
|
|
231
|
+
directionOrigin.copyFrom(dragOrigin).subtractInPlace(worldPivot).normalize();
|
|
232
|
+
_this.attachedSlate._followButton.isToggled = false;
|
|
233
|
+
Vector3.TransformNormalToRef(dragPlaneNormal, _this.attachedMesh.getWorldMatrix(), worldPlaneNormal);
|
|
234
|
+
worldPlaneNormal.normalize();
|
|
235
|
+
if (_this._handleHovered) {
|
|
236
|
+
_this._handleDragged = _this._handleHovered;
|
|
237
|
+
_this._handleDragged.drag = true;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
var dragging = function (event) {
|
|
242
|
+
if (_this.attachedSlate && _this.attachedMesh) {
|
|
243
|
+
_this._tmpVector.copyFrom(event.position);
|
|
244
|
+
_this._tmpVector.subtractInPlace(worldPivot);
|
|
245
|
+
_this._tmpVector.normalize();
|
|
246
|
+
var angle = -Vector3.GetAngleBetweenVectorsOnPlane(_this._tmpVector, directionOrigin, worldPlaneNormal);
|
|
247
|
+
Quaternion.RotationAxisToRef(dragPlaneNormal, angle, _this._tmpQuaternion);
|
|
248
|
+
quaternionOrigin.multiplyToRef(_this._tmpQuaternion, _this.attachedMesh.rotationQuaternion);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
var dragEnd = function () {
|
|
252
|
+
if (_this.attachedSlate && _this.attachedNode) {
|
|
253
|
+
_this.attachedSlate._updatePivot();
|
|
254
|
+
if (_this._handleDragged) {
|
|
255
|
+
_this._handleDragged.drag = false;
|
|
256
|
+
_this._handleDragged = null;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
handle.setDragBehavior(dragStart, dragging, dragEnd);
|
|
261
|
+
};
|
|
262
|
+
SlateGizmo.prototype._attachedNodeChanged = function (value) {
|
|
263
|
+
if (value) {
|
|
264
|
+
this.updateBoundingBox();
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* Updates the bounding box information for the gizmo
|
|
269
|
+
*/
|
|
270
|
+
SlateGizmo.prototype.updateBoundingBox = function () {
|
|
271
|
+
if (this.attachedMesh) {
|
|
272
|
+
PivotTools._RemoveAndStorePivotPoint(this.attachedMesh);
|
|
273
|
+
// Store original parent
|
|
274
|
+
var originalParent = this.attachedMesh.parent;
|
|
275
|
+
this.attachedMesh.setParent(null);
|
|
276
|
+
this._update();
|
|
277
|
+
// Rotate based on axis
|
|
278
|
+
if (!this.attachedMesh.rotationQuaternion) {
|
|
279
|
+
this.attachedMesh.rotationQuaternion = Quaternion.RotationYawPitchRoll(this.attachedMesh.rotation.y, this.attachedMesh.rotation.x, this.attachedMesh.rotation.z);
|
|
280
|
+
}
|
|
281
|
+
// Store original position and reset mesh to origin before computing the bounding box
|
|
282
|
+
this._tmpQuaternion.copyFrom(this.attachedMesh.rotationQuaternion);
|
|
283
|
+
this._tmpVector.copyFrom(this.attachedMesh.position);
|
|
284
|
+
this.attachedMesh.rotationQuaternion.set(0, 0, 0, 1);
|
|
285
|
+
this.attachedMesh.position.set(0, 0, 0);
|
|
286
|
+
// Update bounding dimensions/positions
|
|
287
|
+
var boundingMinMax = this.attachedMesh.getHierarchyBoundingVectors();
|
|
288
|
+
boundingMinMax.max.subtractToRef(boundingMinMax.min, this._boundingDimensions);
|
|
289
|
+
this._boundingBoxGizmo.min = boundingMinMax.min;
|
|
290
|
+
this._boundingBoxGizmo.max = boundingMinMax.max;
|
|
291
|
+
// Update handles of the gizmo
|
|
292
|
+
this._updateHandlesPosition();
|
|
293
|
+
this._updateHandlesScaling();
|
|
294
|
+
// Restore position/rotation values
|
|
295
|
+
this.attachedMesh.rotationQuaternion.copyFrom(this._tmpQuaternion);
|
|
296
|
+
this.attachedMesh.position.copyFrom(this._tmpVector);
|
|
297
|
+
PivotTools._RestorePivotPoint(this.attachedMesh);
|
|
298
|
+
// Restore original parent
|
|
299
|
+
this.attachedMesh.setParent(originalParent);
|
|
300
|
+
this.attachedMesh.computeWorldMatrix(true);
|
|
301
|
+
this._existingSlateScale.copyFrom(this.attachedMesh.scaling);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
SlateGizmo.prototype._updateHandlesPosition = function () {
|
|
305
|
+
var min = this._boundingBoxGizmo.min.clone();
|
|
306
|
+
var max = this._boundingBoxGizmo.max.clone();
|
|
307
|
+
var handleScaling = this._corners[0].node.scaling.length();
|
|
308
|
+
min.x -= this._margin * handleScaling;
|
|
309
|
+
min.y -= this._margin * handleScaling;
|
|
310
|
+
max.x += this._margin * handleScaling;
|
|
311
|
+
max.y += this._margin * handleScaling;
|
|
312
|
+
var center = min.add(max).scaleInPlace(0.5);
|
|
313
|
+
this._corners[0].node.position.copyFromFloats(min.x, min.y, 0);
|
|
314
|
+
this._corners[1].node.position.copyFromFloats(max.x, min.y, 0);
|
|
315
|
+
this._corners[2].node.position.copyFromFloats(max.x, max.y, 0);
|
|
316
|
+
this._corners[3].node.position.copyFromFloats(min.x, max.y, 0);
|
|
317
|
+
this._sides[0].node.position.copyFromFloats(min.x, center.y, 0);
|
|
318
|
+
this._sides[1].node.position.copyFromFloats(center.x, min.y, 0);
|
|
319
|
+
this._sides[2].node.position.copyFromFloats(max.x, center.y, 0);
|
|
320
|
+
this._sides[3].node.position.copyFromFloats(center.x, max.y, 0);
|
|
321
|
+
};
|
|
322
|
+
SlateGizmo.prototype._updateHandlesScaling = function () {
|
|
323
|
+
if (this._attachedSlate && this._attachedSlate.mesh) {
|
|
324
|
+
var scaledWidth = this._attachedSlate.mesh.scaling.x * this._attachedSlate.dimensions.x;
|
|
325
|
+
var scaledHeight = this._attachedSlate.mesh.scaling.y * this._attachedSlate.dimensions.y;
|
|
326
|
+
var scale = Math.min(scaledWidth, scaledHeight) * this._handleSize;
|
|
327
|
+
for (var index = 0; index < this._corners.length; index++) {
|
|
328
|
+
this._corners[index].node.scaling.setAll(scale);
|
|
329
|
+
}
|
|
330
|
+
for (var index = 0; index < this._sides.length; index++) {
|
|
331
|
+
this._sides[index].node.scaling.setAll(scale);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
SlateGizmo.prototype._update = function () {
|
|
336
|
+
_super.prototype._update.call(this);
|
|
337
|
+
if (!this.gizmoLayer.utilityLayerScene.activeCamera) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
if (this._attachedSlate && this._attachedSlate.mesh) {
|
|
341
|
+
if (this.fixedScreenSize) {
|
|
342
|
+
this._attachedSlate.mesh.absolutePosition.subtractToRef(this.gizmoLayer.utilityLayerScene.activeCamera.position, this._tmpVector);
|
|
343
|
+
var distanceFromCamera = (this._handleSize * this._tmpVector.length()) / this.fixedScreenSizeDistanceFactor;
|
|
344
|
+
for (var i = 0; i < this._corners.length; i++) {
|
|
345
|
+
this._corners[i].node.scaling.set(distanceFromCamera, distanceFromCamera, distanceFromCamera);
|
|
346
|
+
}
|
|
347
|
+
for (var i = 0; i < this._sides.length; i++) {
|
|
348
|
+
this._sides[i].node.scaling.set(distanceFromCamera, distanceFromCamera, distanceFromCamera);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
this._updateHandlesPosition();
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
SlateGizmo.prototype.dispose = function () {
|
|
355
|
+
this.gizmoLayer.originalScene.onBeforeRenderObservable.remove(this._renderObserver);
|
|
356
|
+
// Will dispose rootMesh and all descendants
|
|
357
|
+
_super.prototype.dispose.call(this);
|
|
358
|
+
for (var _i = 0, _a = this._corners; _i < _a.length; _i++) {
|
|
359
|
+
var corner = _a[_i];
|
|
360
|
+
corner.dispose();
|
|
361
|
+
}
|
|
362
|
+
for (var _b = 0, _c = this._sides; _b < _c.length; _b++) {
|
|
363
|
+
var side = _c[_b];
|
|
364
|
+
side.dispose();
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
return SlateGizmo;
|
|
368
|
+
}(Gizmo));
|
|
369
|
+
export { SlateGizmo };
|
|
370
370
|
//# sourceMappingURL=slateGizmo.js.map
|