babylonjs-editcontrol 3.2.5 → 3.3.0

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.
@@ -1,2154 +1,3 @@
1
- (function webpackUniversalModuleDefinition(root, factory) {
2
- if(typeof exports === 'object' && typeof module === 'object')
3
- module.exports = factory(require("babylonjs"));
4
- else if(typeof define === 'function' && define.amd)
5
- define(["babylonjs"], factory);
6
- else {
7
- var a = typeof exports === 'object' ? factory(require("babylonjs")) : factory(root["BABYLON"]);
8
- for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
9
- }
10
- })(window, function(__WEBPACK_EXTERNAL_MODULE_babylonjs__) {
11
- return /******/ (function(modules) { // webpackBootstrap
12
- /******/ // The module cache
13
- /******/ var installedModules = {};
14
- /******/
15
- /******/ // The require function
16
- /******/ function __webpack_require__(moduleId) {
17
- /******/
18
- /******/ // Check if module is in cache
19
- /******/ if(installedModules[moduleId]) {
20
- /******/ return installedModules[moduleId].exports;
21
- /******/ }
22
- /******/ // Create a new module (and put it into the cache)
23
- /******/ var module = installedModules[moduleId] = {
24
- /******/ i: moduleId,
25
- /******/ l: false,
26
- /******/ exports: {}
27
- /******/ };
28
- /******/
29
- /******/ // Execute the module function
30
- /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
31
- /******/
32
- /******/ // Flag the module as loaded
33
- /******/ module.l = true;
34
- /******/
35
- /******/ // Return the exports of the module
36
- /******/ return module.exports;
37
- /******/ }
38
- /******/
39
- /******/
40
- /******/ // expose the modules object (__webpack_modules__)
41
- /******/ __webpack_require__.m = modules;
42
- /******/
43
- /******/ // expose the module cache
44
- /******/ __webpack_require__.c = installedModules;
45
- /******/
46
- /******/ // define getter function for harmony exports
47
- /******/ __webpack_require__.d = function(exports, name, getter) {
48
- /******/ if(!__webpack_require__.o(exports, name)) {
49
- /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
50
- /******/ }
51
- /******/ };
52
- /******/
53
- /******/ // define __esModule on exports
54
- /******/ __webpack_require__.r = function(exports) {
55
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
56
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
57
- /******/ }
58
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
59
- /******/ };
60
- /******/
61
- /******/ // create a fake namespace object
62
- /******/ // mode & 1: value is a module id, require it
63
- /******/ // mode & 2: merge all properties of value into the ns
64
- /******/ // mode & 4: return value when already ns object
65
- /******/ // mode & 8|1: behave like require
66
- /******/ __webpack_require__.t = function(value, mode) {
67
- /******/ if(mode & 1) value = __webpack_require__(value);
68
- /******/ if(mode & 8) return value;
69
- /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
70
- /******/ var ns = Object.create(null);
71
- /******/ __webpack_require__.r(ns);
72
- /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
73
- /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
74
- /******/ return ns;
75
- /******/ };
76
- /******/
77
- /******/ // getDefaultExport function for compatibility with non-harmony modules
78
- /******/ __webpack_require__.n = function(module) {
79
- /******/ var getter = module && module.__esModule ?
80
- /******/ function getDefault() { return module['default']; } :
81
- /******/ function getModuleExports() { return module; };
82
- /******/ __webpack_require__.d(getter, 'a', getter);
83
- /******/ return getter;
84
- /******/ };
85
- /******/
86
- /******/ // Object.prototype.hasOwnProperty.call
87
- /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
88
- /******/
89
- /******/ // __webpack_public_path__
90
- /******/ __webpack_require__.p = "";
91
- /******/
92
- /******/
93
- /******/ // Load entry module and return exports
94
- /******/ return __webpack_require__(__webpack_require__.s = "./src/EditControl.ts");
95
- /******/ })
96
- /************************************************************************/
97
- /******/ ({
98
-
99
- /***/ "./src/EditControl.ts":
100
- /*!****************************!*\
101
- !*** ./src/EditControl.ts ***!
102
- \****************************/
103
- /*! exports provided: EditControl */
104
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
105
-
106
- "use strict";
107
- __webpack_require__.r(__webpack_exports__);
108
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EditControl", function() { return EditControl; });
109
- /* harmony import */ var babylonjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs */ "babylonjs");
110
- /* harmony import */ var babylonjs__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs__WEBPACK_IMPORTED_MODULE_0__);
111
-
112
- var ActionType;
113
- (function (ActionType) {
114
- ActionType[ActionType["TRANS"] = 0] = "TRANS";
115
- ActionType[ActionType["ROT"] = 1] = "ROT";
116
- ActionType[ActionType["SCALE"] = 2] = "SCALE";
117
- })(ActionType || (ActionType = {}));
118
- /**
119
- * Draws a transform widget at the mesh's location (its pivot location).
120
- * The widget transforms(translates,rotates and scales) the mesh based on user
121
- * interactions with the widget.
122
- * The widget shows the mesh position and rotation at any time.
123
- * The widget follows the mesh constantly.
124
- * Note: An alternate approach would have been for the mesh to follow the widget.
125
- * The problem with the alternate approach - syncing the transforms
126
- * if the mesh was being transformed by entities other than the widget say physics
127
- * or script for example.
128
- *
129
- */
130
- var EditControl = /** @class */ (function () {
131
- function EditControl(mesh, camera, canvas, scale, eulerian, pickWidth) {
132
- var _this = this;
133
- this._local = true;
134
- this._snapT = false;
135
- this._snapR = false;
136
- this._transSnap = 1;
137
- this._rotSnap = Math.PI / 18;
138
- this._axesLen = 0.4;
139
- this._axesScale = 1;
140
- //how close to an axis should we get before we can pick it
141
- this._pickWidth = 0.02;
142
- this._redCol = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Color3"](1, 0.2, 0.2);
143
- this._greenCol = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Color3"](0.2, 1, 0.2);
144
- this._blueCol = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Color3"](0.2, 0.2, 1);
145
- this._whiteCol = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Color3"](1, 1, 1);
146
- this._yellowCol = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Color3"](1, 1, 0.2);
147
- //axes visibility
148
- this._visibility = 0.75;
149
- //lhs-rhs issue. lhs mesh in rhs or rhs mesh in lhs
150
- this._lhsRhs = false;
151
- this._ecMatrix = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Matrix"]();
152
- //edit control to camera vector
153
- this._ecTOcamera = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, 0);
154
- //how far away from camera should the edit control appear to be
155
- this._distFromCamera = 2;
156
- //vector from camera to edit control
157
- this._cameraTOec = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, 0);
158
- this._cameraNormal = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, 0);
159
- this._prevState = "";
160
- this._hidden = false;
161
- this._actionListener = null;
162
- this._actionStartListener = null;
163
- this._actionEndListener = null;
164
- this._pDown = false;
165
- this._pointerIsOver = false;
166
- this._editing = false;
167
- //rotate differently if camera is too close to the rotation plane
168
- this._rotate2 = false;
169
- //TODO when translating, the orientation of pALL keeps changing
170
- //TODo this is not so with rotation or scaling
171
- //TODO so for translation instead of pALL maybe we should use the camera view plane for picking
172
- this._transBy = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, 0);
173
- this._snapTV = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, 0);
174
- this._snapS = false;
175
- this._snapSV = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, 0);
176
- this._scaleSnap = 0.25;
177
- this._scale = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, 0);
178
- this._localX = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, 0);
179
- this._localY = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, 0);
180
- this._localZ = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, 0);
181
- this._eulerian = false;
182
- this._snapRA = 0;
183
- this._transEnabled = false;
184
- this._rotEnabled = false;
185
- this._scaleEnabled = false;
186
- this._guideSize = 180;
187
- this._tSnap = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](this._transSnap, this._transSnap, this._transSnap);
188
- //few temp vectors & matrix
189
- this._tv1 = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, 0);
190
- this._tv2 = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, 0);
191
- this._tv3 = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, 0);
192
- this._tm = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Matrix"]();
193
- this._mesh = mesh;
194
- this._mainCamera = camera;
195
- this._canvas = canvas;
196
- if (scale != null) {
197
- this._axesScale = scale;
198
- }
199
- if (eulerian !== null) {
200
- this._eulerian = eulerian;
201
- }
202
- else {
203
- this._eulerian = false;
204
- }
205
- this._checkQuaternion();
206
- if (pickWidth != null) {
207
- this._pickWidth = pickWidth;
208
- }
209
- this._scene = mesh.getScene();
210
- this._actHist = new ActHist(mesh, 10);
211
- mesh.computeWorldMatrix(true);
212
- this._boundingDimesion = this._getBoundingDimension(mesh);
213
- this._setLocalAxes(mesh);
214
- this._lhsRhs = this._check_LHS_RHS(mesh);
215
- console.log("lhs rhs issue " + this._lhsRhs);
216
- //build the edit control axes
217
- this._ecRoot = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("", this._scene);
218
- this._ecRoot.rotationQuaternion = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
219
- this._ecRoot.visibility = 0;
220
- this._ecRoot.isPickable = false;
221
- this._createMaterials(this._scene);
222
- var guideAxes = this._createCommonAxes();
223
- guideAxes.parent = this._ecRoot;
224
- //build the pickplanes
225
- var pickPlanes = this._createPickPlanes();
226
- pickPlanes.parent = this._ecRoot;
227
- this._pointerdown = function (evt) { return _this._onPointerDown(evt); };
228
- this._pointerup = function (evt) { return _this._onPointerUp(evt); };
229
- this._pointermove = function (evt) { return _this._onPointerMove(evt); };
230
- //use canvas rather than scene to handle pointer events
231
- //scene cannot have mutiple eventlisteners for an event
232
- //with canvas one will have to do ones own pickinfo generation.
233
- canvas.addEventListener("pointerdown", this._pointerdown, false);
234
- canvas.addEventListener("pointerup", this._pointerup, false);
235
- canvas.addEventListener("pointermove", this._pointermove, false);
236
- this._renderer = function () { return _this._renderLoopProcess(); };
237
- this._scene.registerBeforeRender(this._renderer);
238
- }
239
- EditControl.prototype.getRoot = function () {
240
- return this._ecRoot;
241
- };
242
- //make sure that if eulerian is set to false then mesh's rotation is in quaternion
243
- //throw error and exit if not so.
244
- EditControl.prototype._checkQuaternion = function () {
245
- if (!this._eulerian) {
246
- if ((this._mesh.rotationQuaternion == null) || (this._mesh.rotationQuaternion == undefined)) {
247
- throw "Error: Eulerian is set to false but the mesh's rotationQuaternion is not set.";
248
- }
249
- }
250
- };
251
- /**
252
- * checks if a have left hand , right hand issue.
253
- * In other words if a mesh is a LHS mesh in RHS system or
254
- * a RHS mesh in LHS system
255
- * The X axis will be reversed in such cases.
256
- * thus Cross product of X and Y should be inverse of Z.
257
- *
258
- * if no parent then we are ok.
259
- * If parent and parent has issue then we have issue.
260
- *
261
- */
262
- EditControl.prototype._check_LHS_RHS = function (mesh) {
263
- var _issue = false;
264
- var root = mesh.parent;
265
- if (root == null)
266
- return false;
267
- this._setLocalAxes(root);
268
- var actualZ = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Cross(this._localX, this._localY);
269
- //same direction or opposite direction of Z
270
- if (babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Dot(actualZ, this._localZ) < 0)
271
- _issue = true;
272
- else
273
- _issue = false;
274
- this._setLocalAxes(mesh);
275
- return _issue;
276
- };
277
- EditControl.prototype._renderLoopProcess = function () {
278
- //sync the edit control position and rotation with that of mesh
279
- this._ecRoot.position = this._mesh.getAbsolutePivotPoint();
280
- this._setECRotation();
281
- //scale the EditControl so it seems at the same distance from camera/user
282
- this._setECScale();
283
- //rotate the free move,rotate,scale pick plane to face the camera/user
284
- if (this._local) {
285
- this._ecRoot.getWorldMatrix().invertToRef(this._ecMatrix);
286
- babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].TransformCoordinatesToRef(this._mainCamera.position, this._ecMatrix, this._ecTOcamera);
287
- //note pALL is child of ecRoot hence lookAt in local space
288
- this._pALL.lookAt(this._ecTOcamera, 0, 0, 0, babylonjs__WEBPACK_IMPORTED_MODULE_0__["Space"].LOCAL);
289
- }
290
- else {
291
- this._mainCamera.position.subtractToRef(this._ecRoot.position, this._ecTOcamera);
292
- this._pALL.lookAt(this._mainCamera.position, 0, 0, 0, babylonjs__WEBPACK_IMPORTED_MODULE_0__["Space"].WORLD);
293
- }
294
- //rotate the rotation and planar guide to face the camera/user
295
- if (this._rotEnabled) {
296
- this._rotRotGuides();
297
- }
298
- else if (this._transEnabled)
299
- this._rotPlanarGuides(this._tXZ, this._tZY, this._tYX);
300
- else if (this._scaleEnabled)
301
- this._rotPlanarGuides(this._sXZ, this._sZY, this._sYX);
302
- //check pointer over axes only during pointer moves
303
- //this.onPointerOver();
304
- };
305
- /**
306
- * sets rotaion of edit control to that of the mesh
307
- */
308
- EditControl.prototype._setECRotation = function () {
309
- if (this._local) {
310
- if (this._mesh.parent == null) {
311
- if (this._eulerian) {
312
- var rot = this._mesh.rotation;
313
- babylonjs__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].RotationYawPitchRollToRef(rot.y, rot.x, rot.z, this._ecRoot.rotationQuaternion);
314
- }
315
- else {
316
- this._ecRoot.rotationQuaternion.copyFrom(this._mesh.rotationQuaternion);
317
- }
318
- }
319
- else {
320
- if (this._isScaleUnEqual(this._mesh))
321
- return;
322
- this._mesh.getWorldMatrix().getRotationMatrixToRef(this._tm);
323
- babylonjs__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromRotationMatrixToRef(this._tm, this._ecRoot.rotationQuaternion);
324
- //this._ecRoot.rotationQuaternion.normalize();
325
- }
326
- }
327
- };
328
- /**
329
- * checks if any of the mesh's ancestors has non uniform scale
330
- */
331
- EditControl.prototype._isScaleUnEqual = function (mesh) {
332
- if (mesh.parent == null)
333
- return false;
334
- while (mesh.parent != null) {
335
- if ((mesh.parent.scaling.x != mesh.parent.scaling.y ||
336
- mesh.parent.scaling.y != mesh.parent.scaling.z)) {
337
- return true;
338
- }
339
- else {
340
- mesh = mesh.parent;
341
- }
342
- }
343
- return false;
344
- };
345
- EditControl.prototype._setECScale = function () {
346
- this._ecRoot.position.subtractToRef(this._mainCamera.position, this._cameraTOec);
347
- babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromFloatArrayToRef(this._mainCamera.getWorldMatrix().asArray(), 8, this._cameraNormal);
348
- //get distance of edit control from the camera plane
349
- //project "camera to edit control" vector onto the camera normal
350
- var parentOnNormal = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Dot(this._cameraTOec, this._cameraNormal) / this._cameraNormal.length();
351
- var s = Math.abs(parentOnNormal / this._distFromCamera);
352
- babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromFloatsToRef(s, s, s, this._ecRoot.scaling);
353
- //Vector3.FromFloatsToRef(s,s,s,this.pALL.scaling);
354
- };
355
- //rotate the rotation guides so that they are facing the camera
356
- EditControl.prototype._rotRotGuides = function () {
357
- var rotX = Math.atan(this._ecTOcamera.y / this._ecTOcamera.z);
358
- if (this._ecTOcamera.z >= 0) {
359
- this._rX.rotation.x = -rotX;
360
- }
361
- else {
362
- this._rX.rotation.x = -rotX - Math.PI;
363
- }
364
- var rotY = Math.atan(this._ecTOcamera.x / this._ecTOcamera.z);
365
- if (this._ecTOcamera.z >= 0) {
366
- this._rY.rotation.y = rotY;
367
- }
368
- else {
369
- this._rY.rotation.y = rotY + Math.PI;
370
- }
371
- var rotZ = Math.atan(this._ecTOcamera.x / this._ecTOcamera.y);
372
- if (this._ecTOcamera.y >= 0) {
373
- this._rZ.rotation.z = -rotZ;
374
- }
375
- else {
376
- this._rZ.rotation.z = -rotZ - Math.PI;
377
- }
378
- };
379
- /**
380
- * rotate the planar guide so that they are facing the camera
381
- */
382
- EditControl.prototype._rotPlanarGuides = function (XZ, ZY, YX) {
383
- var ec = this._ecTOcamera;
384
- XZ.rotation.x = 0;
385
- XZ.rotation.y = 0;
386
- XZ.rotation.z = 0;
387
- ZY.rotation.x = 0;
388
- ZY.rotation.y = 0;
389
- ZY.rotation.z = 0;
390
- YX.rotation.x = 0;
391
- YX.rotation.y = 0;
392
- YX.rotation.z = 0;
393
- if (ec.x <= 0 && ec.y >= 0 && ec.z >= 0) {
394
- XZ.rotation.z = 3.14;
395
- YX.rotation.y = 3.14;
396
- }
397
- else if (ec.x <= 0 && ec.y >= 0 && ec.z <= 0) {
398
- XZ.rotation.y = 3.14;
399
- ZY.rotation.y = 3.14;
400
- YX.rotation.y = 3.14;
401
- }
402
- else if (ec.x >= 0 && ec.y >= 0 && ec.z <= 0) {
403
- XZ.rotation.x = 3.14;
404
- ZY.rotation.y = 3.14;
405
- }
406
- else if (ec.x >= 0 && ec.y <= 0 && ec.z >= 0) {
407
- ZY.rotation.z = 3.14;
408
- YX.rotation.x = 3.14;
409
- }
410
- else if (ec.x <= 0 && ec.y <= 0 && ec.z >= 0) {
411
- XZ.rotation.z = 3.14;
412
- ZY.rotation.z = 3.14;
413
- YX.rotation.z = 3.14;
414
- }
415
- else if (ec.x <= 0 && ec.y <= 0 && ec.z <= 0) {
416
- XZ.rotation.y = 3.14;
417
- ZY.rotation.x = 3.14;
418
- YX.rotation.z = 3.14;
419
- }
420
- else if (ec.x >= 0 && ec.y <= 0 && ec.z <= 0) {
421
- XZ.rotation.x = 3.14;
422
- ZY.rotation.x = 3.14;
423
- YX.rotation.x = 3.14;
424
- }
425
- };
426
- EditControl.prototype.switchTo = function (mesh, eulerian) {
427
- mesh.computeWorldMatrix(true);
428
- this._mesh = mesh;
429
- if (eulerian != null) {
430
- this._eulerian = eulerian;
431
- }
432
- this._checkQuaternion();
433
- this._setLocalAxes(mesh);
434
- this._actHist = new ActHist(mesh, 10);
435
- this._lhsRhs = this._check_LHS_RHS(mesh);
436
- this.refreshBoundingInfo();
437
- };
438
- EditControl.prototype.switchCamera = function (camera) {
439
- this._mainCamera = camera;
440
- };
441
- EditControl.prototype.setUndoCount = function (c) {
442
- this._actHist.setCapacity(c);
443
- };
444
- EditControl.prototype.undo = function () {
445
- var at = this._actHist.undo();
446
- this._mesh.computeWorldMatrix(true);
447
- this._setLocalAxes(this._mesh);
448
- this._callActionStartListener(at);
449
- this._callActionListener(at);
450
- this._callActionEndListener(at);
451
- };
452
- EditControl.prototype.redo = function () {
453
- var at = this._actHist.redo();
454
- this._mesh.computeWorldMatrix(true);
455
- this._setLocalAxes(this._mesh);
456
- this._callActionStartListener(at);
457
- this._callActionListener(at);
458
- this._callActionEndListener(at);
459
- };
460
- /**
461
- * detach the edit control from the mesh and dispose off all
462
- * resources created by the edit control
463
- */
464
- EditControl.prototype.detach = function () {
465
- this._canvas.removeEventListener("pointerdown", this._pointerdown, false);
466
- this._canvas.removeEventListener("pointerup", this._pointerup, false);
467
- this._canvas.removeEventListener("pointermove", this._pointermove, false);
468
- this._scene.unregisterBeforeRender(this._renderer);
469
- this.removeAllActionListeners();
470
- this._disposeAll();
471
- };
472
- /**
473
- * hide the edit control. use show() to unhide the control.
474
- */
475
- EditControl.prototype.hide = function () {
476
- this._hidden = true;
477
- if (this._transEnabled) {
478
- this._prevState = "T";
479
- this.disableTranslation();
480
- }
481
- else if (this._rotEnabled) {
482
- this._prevState = "R";
483
- this.disableRotation();
484
- }
485
- else if (this._scaleEnabled) {
486
- this._prevState = "S";
487
- this.disableScaling();
488
- }
489
- this._hideCommonAxes();
490
- };
491
- EditControl.prototype._hideCommonAxes = function () {
492
- this._xaxis.visibility = 0;
493
- this._yaxis.visibility = 0;
494
- this._zaxis.visibility = 0;
495
- };
496
- EditControl.prototype._showCommonAxes = function () {
497
- this._xaxis.visibility = this._visibility;
498
- this._yaxis.visibility = this._visibility;
499
- this._zaxis.visibility = this._visibility;
500
- };
501
- /**
502
- * unhide the editcontrol hidden using the hide() method
503
- */
504
- EditControl.prototype.show = function () {
505
- this._hidden = false;
506
- this._showCommonAxes();
507
- if (this._prevState == "T")
508
- this.enableTranslation();
509
- else if (this._prevState == "R")
510
- this.enableRotation();
511
- else if (this._prevState == "S")
512
- this.enableScaling();
513
- };
514
- /**
515
- * check if the editcontrol was hidden using the hide() methods
516
- */
517
- EditControl.prototype.isHidden = function () {
518
- return this._hidden;
519
- };
520
- EditControl.prototype._disposeAll = function () {
521
- this._ecRoot.dispose();
522
- this._disposeMaterials();
523
- this._actHist = null;
524
- };
525
- EditControl.prototype.addActionListener = function (actionListener) {
526
- this._actionListener = actionListener;
527
- };
528
- EditControl.prototype.removeActionListener = function () {
529
- this._actionListener = null;
530
- };
531
- EditControl.prototype.addActionStartListener = function (actionStartListener) {
532
- this._actionStartListener = actionStartListener;
533
- };
534
- EditControl.prototype.removeActionStartListener = function () {
535
- this._actionStartListener = null;
536
- };
537
- EditControl.prototype.addActionEndListener = function (actionEndListener) {
538
- this._actionEndListener = actionEndListener;
539
- };
540
- EditControl.prototype.removeActionEndListener = function () {
541
- this._actionEndListener = null;
542
- };
543
- EditControl.prototype.removeAllActionListeners = function () {
544
- this._actionListener = null;
545
- this._actionStartListener = null;
546
- this._actionEndListener = null;
547
- };
548
- EditControl.prototype._onPointerDown = function (evt) {
549
- var _this = this;
550
- evt.preventDefault();
551
- this._pDown = true;
552
- if (evt.button != 0)
553
- return;
554
- var engine = this._scene.getEngine();
555
- var x = (engine.isPointerLock) ? this._canvas.width * 0.5 : this._scene.pointerX;
556
- var y = (engine.isPointerLock) ? this._canvas.height * 0.5 : this._scene.pointerY;
557
- var pickResult = this._scene.pick(x, y, function (mesh) {
558
- if (_this._transEnabled) {
559
- if ((mesh == _this._tX) || (mesh == _this._tY) || (mesh == _this._tZ) || (mesh == _this._tXZ) || (mesh == _this._tZY) || (mesh == _this._tYX) || (mesh == _this._tAll))
560
- return true;
561
- }
562
- else if ((_this._rotEnabled)) {
563
- if ((mesh == _this._rX) || (mesh == _this._rY) || (mesh == _this._rZ) || (mesh == _this._rAll))
564
- return true;
565
- }
566
- else if ((_this._scaleEnabled)) {
567
- if ((mesh == _this._sX) || (mesh == _this._sY) || (mesh == _this._sZ) || (mesh == _this._sXZ) || (mesh == _this._sZY) || (mesh == _this._sYX) || (mesh == _this._sAll))
568
- return true;
569
- }
570
- return false;
571
- }, null, this._mainCamera);
572
- if (pickResult.hit) {
573
- //this.setAxesVisiblity(0);
574
- this._axisPicked = pickResult.pickedMesh;
575
- var childs = this._axisPicked.getChildren();
576
- if (childs.length > 0) {
577
- childs[0].visibility = this._visibility;
578
- }
579
- else {
580
- this._axisPicked.visibility = this._visibility;
581
- }
582
- var name_1 = this._axisPicked.name;
583
- if ((name_1 == "X"))
584
- this._bXaxis.visibility = 1;
585
- else if ((name_1 == "Y"))
586
- this._bYaxis.visibility = 1;
587
- else if ((name_1 == "Z"))
588
- this._bZaxis.visibility = 1;
589
- else if ((name_1 == "XZ")) {
590
- this._bXaxis.visibility = 1;
591
- this._bZaxis.visibility = 1;
592
- }
593
- else if ((name_1 == "ZY")) {
594
- this._bZaxis.visibility = 1;
595
- this._bYaxis.visibility = 1;
596
- }
597
- else if ((name_1 == "YX")) {
598
- this._bYaxis.visibility = 1;
599
- this._bXaxis.visibility = 1;
600
- }
601
- else if ((name_1 == "ALL")) {
602
- this._bXaxis.visibility = 1;
603
- this._bYaxis.visibility = 1;
604
- this._bZaxis.visibility = 1;
605
- }
606
- this._setEditing(true);
607
- //lets find out where we are on the pickplane
608
- this._pickedPlane = this._getPickPlane(this._axisPicked);
609
- if (this._pickedPlane != null) {
610
- this._prevPos = this._getPosOnPickPlane();
611
- }
612
- else {
613
- this._prevPos = null;
614
- }
615
- window.setTimeout((function (cam, can) { return _this._detachCamera(cam, can); }), 0, this._mainCamera, this._canvas);
616
- }
617
- };
618
- EditControl.prototype._setEditing = function (editing) {
619
- this._editing = editing;
620
- if (editing) {
621
- this._setActionType();
622
- if (this._actionType == ActionType.ROT) {
623
- this._snapRA = 0;
624
- }
625
- this._callActionStartListener(this._actionType);
626
- }
627
- else {
628
- this._callActionEndListener(this._actionType);
629
- }
630
- };
631
- EditControl.prototype.isEditing = function () {
632
- return this._editing;
633
- };
634
- /**
635
- * no camera movement during edit
636
- */
637
- EditControl.prototype._detachCamera = function (cam, can) {
638
- var camera = cam;
639
- var canvas = can;
640
- var engine = this._scene.getEngine();
641
- if (!engine.isPointerLock) {
642
- camera.detachControl(canvas);
643
- }
644
- };
645
- EditControl.prototype.isPointerOver = function () {
646
- return this._pointerIsOver;
647
- };
648
- EditControl.prototype._onPointerOver = function () {
649
- var _this = this;
650
- //if(this.pDown) return;
651
- var engine = this._scene.getEngine();
652
- var x = (engine.isPointerLock) ? this._canvas.width * 0.5 : this._scene.pointerX;
653
- var y = (engine.isPointerLock) ? this._canvas.height * 0.5 : this._scene.pointerY;
654
- var pickResult = this._scene.pick(x, y, function (mesh) {
655
- if (_this._transEnabled) {
656
- if ((mesh == _this._tX) || (mesh == _this._tY) || (mesh == _this._tZ) || (mesh == _this._tXZ) || (mesh == _this._tZY) || (mesh == _this._tYX) || (mesh == _this._tAll))
657
- return true;
658
- }
659
- else if ((_this._rotEnabled)) {
660
- if ((mesh == _this._rX) || (mesh == _this._rY) || (mesh == _this._rZ) || (mesh == _this._rAll))
661
- return true;
662
- }
663
- else if (_this._scaleEnabled) {
664
- if ((mesh == _this._sX) || (mesh == _this._sY) || (mesh == _this._sZ) || (mesh == _this._sXZ) || (mesh == _this._sZY) || (mesh == _this._sYX) || (mesh == _this._sAll))
665
- return true;
666
- }
667
- return false;
668
- }, null, this._mainCamera);
669
- if (pickResult.hit) {
670
- //if we are still over the same axis mesh then don't do anything
671
- if (pickResult.pickedMesh != this._prevOverMesh) {
672
- this._pointerIsOver = true;
673
- //if we moved directly from one axis mesh to this then clean up the prev axis mesh
674
- this._clearPrevOverMesh();
675
- this._prevOverMesh = pickResult.pickedMesh;
676
- if (this._rotEnabled) {
677
- this._savedCol = this._prevOverMesh.getChildren()[0].color;
678
- this._prevOverMesh.getChildren()[0].color = this._whiteCol;
679
- }
680
- else {
681
- var childs = this._prevOverMesh.getChildren();
682
- if (childs.length > 0) {
683
- this._savedMat = childs[0].material;
684
- childs[0].material = this._whiteMat;
685
- }
686
- else {
687
- this._savedMat = this._prevOverMesh.material;
688
- this._prevOverMesh.material = this._whiteMat;
689
- }
690
- }
691
- if (this._prevOverMesh.name == "X") {
692
- this._xaxis.color = this._whiteCol;
693
- }
694
- else if (this._prevOverMesh.name == "Y") {
695
- this._yaxis.color = this._whiteCol;
696
- }
697
- else if (this._prevOverMesh.name == "Z") {
698
- this._zaxis.color = this._whiteCol;
699
- }
700
- }
701
- }
702
- else {
703
- this._pointerIsOver = false;
704
- if (this._prevOverMesh != null) {
705
- this._restoreColor(this._prevOverMesh);
706
- this._prevOverMesh = null;
707
- }
708
- }
709
- };
710
- //clean up any axis we might have been howering over before
711
- EditControl.prototype._clearPrevOverMesh = function () {
712
- if (this._prevOverMesh != null) {
713
- this._prevOverMesh.visibility = 0;
714
- this._restoreColor(this._prevOverMesh);
715
- }
716
- };
717
- EditControl.prototype._restoreColor = function (mesh) {
718
- switch (mesh.name) {
719
- case "X":
720
- this._xaxis.color = this._redCol;
721
- break;
722
- case "Y":
723
- this._yaxis.color = this._greenCol;
724
- break;
725
- case "Z":
726
- this._zaxis.color = this._blueCol;
727
- break;
728
- }
729
- if (this._rotEnabled) {
730
- mesh.getChildren()[0].color = this._savedCol;
731
- }
732
- else {
733
- var childs = mesh.getChildren();
734
- if (childs.length > 0) {
735
- childs[0].material = this._savedMat;
736
- }
737
- else {
738
- mesh.material = this._savedMat;
739
- }
740
- }
741
- };
742
- EditControl.prototype._onPointerUp = function (evt) {
743
- this._pDown = false;
744
- if (this._editing) {
745
- var engine = this._scene.getEngine();
746
- if (!engine.isPointerLock) {
747
- this._mainCamera.attachControl(this._canvas);
748
- }
749
- this._setEditing(false);
750
- //this.setAxesVisiblity(1);
751
- this._hideBaxis();
752
- if (this._prevOverMesh != null) {
753
- this._restoreColor(this._prevOverMesh);
754
- this._prevOverMesh = null;
755
- }
756
- this._actHist.add(this._actionType);
757
- }
758
- };
759
- EditControl.prototype._setActionType = function () {
760
- if (this._transEnabled) {
761
- this._actionType = ActionType.TRANS;
762
- }
763
- else if ((this._rotEnabled)) {
764
- this._actionType = ActionType.ROT;
765
- }
766
- else if ((this._scaleEnabled)) {
767
- this._actionType = ActionType.SCALE;
768
- }
769
- };
770
- EditControl.prototype._callActionListener = function (at) {
771
- //call actionListener if registered
772
- if (this._actionListener != null) {
773
- this._actionListener(at);
774
- }
775
- };
776
- EditControl.prototype._callActionStartListener = function (at) {
777
- //call actionListener if registered
778
- if (this._actionStartListener != null) {
779
- this._actionStartListener(at);
780
- }
781
- };
782
- EditControl.prototype._callActionEndListener = function (at) {
783
- //call actionListener if registered
784
- if (this._actionEndListener != null) {
785
- this._actionEndListener(at);
786
- }
787
- };
788
- EditControl.prototype._onPointerMove = function (evt) {
789
- if (!this._pDown) {
790
- this._onPointerOver();
791
- return;
792
- }
793
- if (!this._editing)
794
- return;
795
- if (this._prevPos == null)
796
- return;
797
- var newPos = this._getPosOnPickPlane();
798
- if (newPos == null)
799
- return;
800
- if (this._rotEnabled) {
801
- this._doRotation(this._mesh, this._axisPicked, newPos, this._prevPos);
802
- }
803
- else {
804
- var diff = newPos.subtract(this._prevPos);
805
- if (diff.x == 0 && diff.y == 0 && diff.z == 0)
806
- return;
807
- if (this._transEnabled) {
808
- this._doTranslation(diff);
809
- }
810
- else {
811
- if (this._scaleEnabled && this._local)
812
- this._doScaling(diff);
813
- }
814
- }
815
- this._prevPos = newPos;
816
- this._callActionListener(this._actionType);
817
- };
818
- EditControl.prototype._getPickPlane = function (axis) {
819
- var n = axis.name;
820
- if (this._transEnabled || this._scaleEnabled) {
821
- if (n == "XZ")
822
- return this._pXZ;
823
- else if (n == "ZY")
824
- return this._pZY;
825
- else if (n == "YX")
826
- return this._pYX;
827
- else if (n == "ALL")
828
- return this._pALL;
829
- else {
830
- //get the position of camera in the edit control frame of reference
831
- this._ecRoot.getWorldMatrix().invertToRef(this._ecMatrix);
832
- babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].TransformCoordinatesToRef(this._mainCamera.position, this._ecMatrix, this._ecTOcamera);
833
- var c = this._ecTOcamera;
834
- if (n === "X") {
835
- if (Math.abs(c.y) > Math.abs(c.z)) {
836
- return this._pXZ;
837
- }
838
- else
839
- return this._pYX;
840
- }
841
- else if (n === "Z") {
842
- if (Math.abs(c.y) > Math.abs(c.x)) {
843
- return this._pXZ;
844
- }
845
- else
846
- return this._pZY;
847
- }
848
- else if (n === "Y") {
849
- if (Math.abs(c.z) > Math.abs(c.x)) {
850
- return this._pYX;
851
- }
852
- else
853
- return this._pZY;
854
- }
855
- }
856
- }
857
- else if (this._rotEnabled) {
858
- this._rotate2 = false;
859
- //get the position of camera in the edit control frame of reference
860
- this._ecRoot.getWorldMatrix().invertToRef(this._ecMatrix);
861
- babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].TransformCoordinatesToRef(this._mainCamera.position, this._ecMatrix, this._ecTOcamera);
862
- var c = this._ecTOcamera;
863
- //if camera is too close to the rotation plane then use alternate rotation process
864
- switch (n) {
865
- case "X":
866
- if (Math.abs(c.x) < 0.2) {
867
- this._rotate2 = true;
868
- return this._pALL;
869
- }
870
- else
871
- return this._pZY;
872
- case "Y":
873
- if (Math.abs(c.y) < 0.2) {
874
- this._rotate2 = true;
875
- return this._pALL;
876
- }
877
- else
878
- return this._pXZ;
879
- case "Z":
880
- if (Math.abs(c.z) < 0.2) {
881
- this._rotate2 = true;
882
- return this._pALL;
883
- }
884
- else
885
- return this._pYX;
886
- default:
887
- return this._pALL;
888
- }
889
- }
890
- else
891
- return null;
892
- };
893
- EditControl.prototype._doTranslation = function (diff) {
894
- if ((this._mesh.parent != null) && this._isScaleUnEqual(this._mesh)) {
895
- this._setLocalAxes(this._ecRoot);
896
- }
897
- else {
898
- this._setLocalAxes(this._mesh);
899
- }
900
- var n = this._axisPicked.name;
901
- this._transBy.x = 0;
902
- this._transBy.y = 0;
903
- this._transBy.z = 0;
904
- if ((n == "X") || (n == "XZ") || (n == "YX") || (n == "ALL")) {
905
- if (this._local)
906
- this._transBy.x = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Dot(diff, this._localX) / this._localX.length();
907
- else
908
- this._transBy.x = diff.x;
909
- }
910
- if ((n == "Y") || (n == "ZY") || (n == "YX") || (n == "ALL")) {
911
- if (this._local)
912
- this._transBy.y = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Dot(diff, this._localY) / this._localY.length();
913
- else
914
- this._transBy.y = diff.y;
915
- }
916
- if ((n == "Z") || (n == "XZ") || (n == "ZY") || (n == "ALL")) {
917
- if (this._local)
918
- this._transBy.z = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Dot(diff, this._localZ) / this._localZ.length();
919
- else
920
- this._transBy.z = diff.z;
921
- }
922
- this._transWithSnap(this._mesh, this._transBy, this._local);
923
- // bound the translation
924
- if (this._transBoundsMin) {
925
- this._mesh.position.x = Math.max(this._mesh.position.x, this._transBoundsMin.x);
926
- this._mesh.position.y = Math.max(this._mesh.position.y, this._transBoundsMin.y);
927
- this._mesh.position.z = Math.max(this._mesh.position.z, this._transBoundsMin.z);
928
- }
929
- if (this._transBoundsMax) {
930
- this._mesh.position.x = Math.min(this._mesh.position.x, this._transBoundsMax.x);
931
- this._mesh.position.y = Math.min(this._mesh.position.y, this._transBoundsMax.y);
932
- this._mesh.position.z = Math.min(this._mesh.position.z, this._transBoundsMax.z);
933
- }
934
- this._mesh.computeWorldMatrix(true);
935
- };
936
- EditControl.prototype._transWithSnap = function (mesh, trans, local) {
937
- if (this._snapT) {
938
- var snapit = false;
939
- this._snapTV.addInPlace(trans);
940
- if (Math.abs(this._snapTV.x) > this._tSnap.x) {
941
- if (this._snapTV.x > 0)
942
- trans.x = this._tSnap.x;
943
- else
944
- trans.x = -this._tSnap.x;
945
- snapit = true;
946
- }
947
- if (Math.abs(this._snapTV.y) > this._tSnap.y) {
948
- if (this._snapTV.y > 0)
949
- trans.y = this._tSnap.y;
950
- else
951
- trans.y = -this._tSnap.y;
952
- snapit = true;
953
- }
954
- if (Math.abs(this._snapTV.z) > this._tSnap.z) {
955
- if (this._snapTV.z > 0)
956
- trans.z = this._tSnap.z;
957
- else
958
- trans.z = -this._tSnap.z;
959
- snapit = true;
960
- }
961
- if (snapit) {
962
- if (Math.abs(trans.x) !== this._tSnap.x)
963
- trans.x = 0;
964
- if (Math.abs(trans.y) !== this._tSnap.y)
965
- trans.y = 0;
966
- if (Math.abs(trans.z) !== this._tSnap.z)
967
- trans.z = 0;
968
- babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromFloatsToRef(0, 0, 0, this._snapTV);
969
- snapit = false;
970
- }
971
- else {
972
- return;
973
- }
974
- }
975
- if (local) {
976
- //locallyTranslate moves the mesh wrt the absolute location not pivotlocation :(
977
- //this.mesh.locallyTranslate(trans);
978
- //
979
- this._localX.normalizeToRef(this._tv1);
980
- this._localY.normalizeToRef(this._tv2);
981
- this._localZ.normalizeToRef(this._tv3);
982
- this._mesh.translate(this._tv1, trans.x, babylonjs__WEBPACK_IMPORTED_MODULE_0__["Space"].WORLD);
983
- this._mesh.translate(this._tv2, trans.y, babylonjs__WEBPACK_IMPORTED_MODULE_0__["Space"].WORLD);
984
- this._mesh.translate(this._tv3, trans.z, babylonjs__WEBPACK_IMPORTED_MODULE_0__["Space"].WORLD);
985
- }
986
- else {
987
- if (this._mesh.parent == null) {
988
- this._mesh.position.addInPlace(trans);
989
- }
990
- else {
991
- this._mesh.setAbsolutePosition(trans.addInPlace(this._mesh.absolutePosition));
992
- }
993
- }
994
- };
995
- EditControl.prototype._doScaling = function (diff) {
996
- this._setLocalAxes(this._mesh);
997
- this._scale.x = 0;
998
- this._scale.y = 0;
999
- this._scale.z = 0;
1000
- var n = this._axisPicked.name;
1001
- if ((n == "X") || (n == "XZ") || (n == "YX")) {
1002
- this._scale.x = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Dot(diff, this._localX) / this._localX.length();
1003
- if (this._mesh.scaling.x < 0)
1004
- this._scale.x = -this._scale.x;
1005
- //if(this.lhsRhs) this.scale.x=-this.scale.x;
1006
- }
1007
- if ((n == "Y") || (n == "ZY") || (n == "YX")) {
1008
- this._scale.y = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Dot(diff, this._localY) / this._localY.length();
1009
- if (this._mesh.scaling.y < 0)
1010
- this._scale.y = -this._scale.y;
1011
- }
1012
- if ((n == "Z") || (n == "XZ") || (n == "ZY")) {
1013
- this._scale.z = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Dot(diff, this._localZ) / this._localZ.length();
1014
- if (this._mesh.scaling.z < 0)
1015
- this._scale.z = -this._scale.z;
1016
- }
1017
- //as the mesh becomes large reduce the amount by which we scale.
1018
- var bbd = this._boundingDimesion;
1019
- this._scale.x = this._scale.x / bbd.x;
1020
- this._scale.y = this._scale.y / bbd.y;
1021
- this._scale.z = this._scale.z / bbd.z;
1022
- if (n == "ALL") {
1023
- //project movement along camera up vector
1024
- //if up then scale up else scale down
1025
- var s = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Dot(diff, this._mainCamera.upVector);
1026
- s = s / Math.max(bbd.x, bbd.y, bbd.z);
1027
- this._scale.copyFromFloats(s, s, s);
1028
- }
1029
- else {
1030
- var inPlane = false;
1031
- if (n == "XZ") {
1032
- inPlane = true;
1033
- if (Math.abs(this._scale.x) > Math.abs(this._scale.z)) {
1034
- this._scale.z = this._scale.x;
1035
- }
1036
- else
1037
- this._scale.x = this._scale.z;
1038
- }
1039
- else if (n == "ZY") {
1040
- inPlane = true;
1041
- if (Math.abs(this._scale.z) > Math.abs(this._scale.y)) {
1042
- this._scale.y = this._scale.z;
1043
- }
1044
- else
1045
- this._scale.z = this._scale.y;
1046
- }
1047
- else if (n == "YX") {
1048
- inPlane = true;
1049
- if (Math.abs(this._scale.y) > Math.abs(this._scale.x)) {
1050
- this._scale.x = this._scale.y;
1051
- }
1052
- else
1053
- this._scale.y = this._scale.x;
1054
- }
1055
- if (inPlane) {
1056
- //check if the mouse/pointer was moved towards camera or away from camera
1057
- //if towards then scale up else scale down
1058
- this._ecRoot.position.subtractToRef(this._mainCamera.position, this._cameraTOec);
1059
- var s = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Dot(diff, this._cameraTOec);
1060
- this._scale.x = Math.abs(this._scale.x);
1061
- this._scale.y = Math.abs(this._scale.y);
1062
- this._scale.z = Math.abs(this._scale.z);
1063
- if (s > 0) {
1064
- if (this._mesh.scaling.x > 0)
1065
- this._scale.x = -this._scale.x;
1066
- //if(this.lhsRhs) this.scale.y=Math.abs(this.scale.y);
1067
- if (this._mesh.scaling.y > 0)
1068
- this._scale.y = -this._scale.y;
1069
- if (this._mesh.scaling.z > 0)
1070
- this._scale.z = -this._scale.z;
1071
- }
1072
- else {
1073
- //this.scale.x=Math.abs(this.scale.x);
1074
- //if(this.lhsRhs) this.scale.y=-Math.abs(this.scale.y);
1075
- //else this.scale.y=Math.abs(this.scale.y);
1076
- if (this._mesh.scaling.x < 0)
1077
- this._scale.x = -this._scale.x;
1078
- if (this._mesh.scaling.y < 0)
1079
- this._scale.y = -this._scale.y;
1080
- if (this._mesh.scaling.z < 0)
1081
- this._scale.z = -this._scale.z;
1082
- }
1083
- }
1084
- }
1085
- this._scaleWithSnap(this._mesh, this._scale);
1086
- // bound the scale
1087
- if (this._scaleBoundsMin) {
1088
- this._mesh.scaling.x = Math.max(this._mesh.scaling.x, this._scaleBoundsMin.x);
1089
- this._mesh.scaling.y = Math.max(this._mesh.scaling.y, this._scaleBoundsMin.y);
1090
- this._mesh.scaling.z = Math.max(this._mesh.scaling.z, this._scaleBoundsMin.z);
1091
- }
1092
- if (this._scaleBoundsMax) {
1093
- this._mesh.scaling.x = Math.min(this._mesh.scaling.x, this._scaleBoundsMax.x);
1094
- this._mesh.scaling.y = Math.min(this._mesh.scaling.y, this._scaleBoundsMax.y);
1095
- this._mesh.scaling.z = Math.min(this._mesh.scaling.z, this._scaleBoundsMax.z);
1096
- }
1097
- };
1098
- EditControl.prototype._scaleWithSnap = function (mesh, p) {
1099
- if (this._snapS) {
1100
- var snapit = false;
1101
- this._snapSV.addInPlace(p);
1102
- if (Math.abs(this._snapSV.x) > this._scaleSnap) {
1103
- if (p.x > 0)
1104
- p.x = this._scaleSnap;
1105
- else
1106
- p.x = -this._scaleSnap;
1107
- snapit = true;
1108
- }
1109
- if (Math.abs(this._snapSV.y) > this._scaleSnap) {
1110
- if (p.y > 0)
1111
- p.y = this._scaleSnap;
1112
- else
1113
- p.y = -this._scaleSnap;
1114
- snapit = true;
1115
- }
1116
- if (Math.abs(this._snapSV.z) > this._scaleSnap) {
1117
- if (p.z > 0)
1118
- p.z = this._scaleSnap;
1119
- else
1120
- p.z = -this._scaleSnap;
1121
- snapit = true;
1122
- }
1123
- if (!snapit)
1124
- return;
1125
- if ((Math.abs(p.x) !== this._scaleSnap) && (p.x !== 0))
1126
- p.x = 0;
1127
- if ((Math.abs(p.y) !== this._scaleSnap) && (p.y !== 0))
1128
- p.y = 0;
1129
- if ((Math.abs(p.z) !== this._scaleSnap) && (p.z !== 0))
1130
- p.z = 0;
1131
- babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromFloatsToRef(0, 0, 0, this._snapSV);
1132
- snapit = false;
1133
- }
1134
- mesh.scaling.addInPlace(p);
1135
- };
1136
- /*
1137
- * This would be called after rotation or scaling as the local axes direction or length might have changed
1138
- * We need to set the local axis as these are used in all three modes to figure out
1139
- * direction of mouse move wrt the axes
1140
- * TODO should use world pivotmatrix instead of worldmatrix - incase pivot axes were rotated?
1141
- */
1142
- EditControl.prototype._setLocalAxes = function (mesh) {
1143
- var meshMatrix = mesh.getWorldMatrix();
1144
- babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromFloatArrayToRef(meshMatrix.m, 0, this._localX);
1145
- babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromFloatArrayToRef(meshMatrix.m, 4, this._localY);
1146
- babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromFloatArrayToRef(meshMatrix.m, 8, this._localZ);
1147
- };
1148
- EditControl.prototype._getBoundingDimension = function (mesh) {
1149
- if (mesh instanceof babylonjs__WEBPACK_IMPORTED_MODULE_0__["AbstractMesh"]) {
1150
- { }
1151
- var bb = mesh.getBoundingInfo().boundingBox;
1152
- var bd = bb.maximum.subtract(bb.minimum);
1153
- if (bd.x == 0)
1154
- bd.x = 1;
1155
- if (bd.y == 0)
1156
- bd.y = 1;
1157
- if (bd.z == 0)
1158
- bd.z = 1;
1159
- return bd;
1160
- }
1161
- else
1162
- return new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](1, 1, 1);
1163
- };
1164
- /*
1165
- *
1166
- * For the sake of speed the editcontrol calculates bounding info only once.
1167
- * This is in the constructor.
1168
- * Now The boundingbox dimension can change if the mesh is baked.
1169
- * If the editcontrol is attached to the mesh when the mesh was baked then
1170
- * the scaling speed will be incorrect.
1171
- * Thus client application should call refreshBoundingInfo if it bakes the mesh.
1172
- *
1173
- */
1174
- EditControl.prototype.refreshBoundingInfo = function () {
1175
- this._boundingDimesion = this._getBoundingDimension(this._mesh);
1176
- };
1177
- EditControl.prototype._doRotation = function (mesh, axis, newPos, prevPos) {
1178
- //for now no rotation if parents have non uniform scale
1179
- if (this._local && (this._mesh.parent != null) && this._isScaleUnEqual(mesh)) {
1180
- this._setLocalAxes(this._ecRoot);
1181
- }
1182
- else {
1183
- this._setLocalAxes(mesh);
1184
- }
1185
- var angle = 0;
1186
- //rotation axis
1187
- var rAxis;
1188
- if (axis == this._rX)
1189
- rAxis = this._local ? this._localX : babylonjs__WEBPACK_IMPORTED_MODULE_0__["Axis"].X;
1190
- else if (axis == this._rY)
1191
- rAxis = this._local ? this._localY : babylonjs__WEBPACK_IMPORTED_MODULE_0__["Axis"].Y;
1192
- else if (axis == this._rZ)
1193
- rAxis = this._local ? this._localZ : babylonjs__WEBPACK_IMPORTED_MODULE_0__["Axis"].Z;
1194
- this._ecRoot.position.subtractToRef(this._mainCamera.position, this._cameraTOec);
1195
- /**
1196
- * A)first find the angle and the direction (clockwise or anticlockwise) by which the user was trying to rotate
1197
- * from the user(camera) perspective
1198
- */
1199
- if (this._rotate2) {
1200
- angle = this._getAngle2(prevPos, newPos, this._mainCamera.position, this._cameraTOec, rAxis);
1201
- //TODO check why we need to handle righ hand this way
1202
- if (this._scene.useRightHandedSystem)
1203
- angle = -angle;
1204
- }
1205
- else {
1206
- angle = this._getAngle(prevPos, newPos, mesh.getAbsolutePivotPoint(), this._cameraTOec);
1207
- }
1208
- if (this._lhsRhs) {
1209
- angle = -angle;
1210
- }
1211
- /**
1212
- * B)then rotate based on users(camera) postion and orientation in the local/world space
1213
- *
1214
- */
1215
- if (this._snapR) {
1216
- this._snapRA += angle;
1217
- angle = 0;
1218
- if (Math.abs(this._snapRA) >= this._rotSnap) {
1219
- if (this._snapRA > 0)
1220
- angle = this._rotSnap;
1221
- else
1222
- angle = -this._rotSnap;
1223
- this._snapRA = 0;
1224
- }
1225
- }
1226
- if (angle !== 0) {
1227
- this._cameraTOec.normalize();
1228
- if (axis == this._rAll) {
1229
- mesh.rotate(this._cameraTOec, -angle, babylonjs__WEBPACK_IMPORTED_MODULE_0__["Space"].WORLD);
1230
- }
1231
- else {
1232
- if (babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Dot(rAxis, this._cameraTOec) >= 0)
1233
- angle = -angle;
1234
- mesh.rotate(rAxis, angle, babylonjs__WEBPACK_IMPORTED_MODULE_0__["Space"].WORLD);
1235
- }
1236
- if (this._eulerian) {
1237
- mesh.rotation = mesh.rotationQuaternion.toEulerAngles();
1238
- mesh.rotationQuaternion = null;
1239
- }
1240
- if (this._local) {
1241
- if (this._lhsRhs) {
1242
- angle = -angle;
1243
- }
1244
- if ((this._mesh.parent != null) && this._isScaleUnEqual(mesh)) {
1245
- if (axis == this._rAll) {
1246
- this._ecRoot.rotate(this._cameraTOec, -angle, babylonjs__WEBPACK_IMPORTED_MODULE_0__["Space"].WORLD);
1247
- }
1248
- else {
1249
- this._ecRoot.rotate(rAxis, angle, babylonjs__WEBPACK_IMPORTED_MODULE_0__["Space"].WORLD);
1250
- }
1251
- }
1252
- }
1253
- }
1254
- };
1255
- EditControl.prototype._getPosOnPickPlane = function () {
1256
- var _this = this;
1257
- var engine = this._scene.getEngine();
1258
- var x = (engine.isPointerLock) ? this._canvas.width * 0.5 : this._scene.pointerX;
1259
- var y = (engine.isPointerLock) ? this._canvas.height * 0.5 : this._scene.pointerY;
1260
- var pickinfo = this._scene.pick(x, y, function (mesh) {
1261
- return mesh == _this._pickedPlane;
1262
- }, null, this._mainCamera);
1263
- if (pickinfo.hit) {
1264
- return pickinfo.pickedPoint;
1265
- }
1266
- else {
1267
- return null;
1268
- }
1269
- };
1270
- EditControl.prototype._hideBaxis = function () {
1271
- this._bXaxis.visibility = 0;
1272
- this._bYaxis.visibility = 0;
1273
- this._bZaxis.visibility = 0;
1274
- };
1275
- // private _setAxesVisiblity(v: number) {
1276
- // if (this._transEnabled) {
1277
- // this._tEndX.visibility = v;
1278
- // this._tEndY.visibility = v;
1279
- // this._tEndZ.visibility = v;
1280
- // this._tEndXZ.visibility = v;
1281
- // this._tEndZY.visibility = v;
1282
- // this._tEndYX.visibility = v;
1283
- // this._tEndAll.visibility = v;
1284
- // }
1285
- // if (this._rotEnabled) {
1286
- // this._rEndX.visibility = v;
1287
- // this._rEndY.visibility = v;
1288
- // this._rEndZ.visibility = v;
1289
- // this._rEndAll.visibility = v;
1290
- // }
1291
- // if (this._scaleEnabled) {
1292
- // this._sEndX.visibility = v;
1293
- // this._sEndY.visibility = v;
1294
- // this._sEndZ.visibility = v;
1295
- // this._sEndXZ.visibility = v;
1296
- // this._sEndZY.visibility = v;
1297
- // this._sEndYX.visibility = v;
1298
- // this._sEndAll.visibility = v;
1299
- // }
1300
- // }
1301
- EditControl.prototype.getRotationQuaternion = function () {
1302
- return this._ecRoot.rotationQuaternion;
1303
- };
1304
- EditControl.prototype.getPosition = function () {
1305
- return this._ecRoot.position;
1306
- };
1307
- EditControl.prototype.isTranslationEnabled = function () {
1308
- return this._transEnabled;
1309
- };
1310
- EditControl.prototype.enableTranslation = function () {
1311
- if (this._hidden)
1312
- return;
1313
- if (this._tX == null) {
1314
- this._createTransAxes();
1315
- this._tCtl.parent = this._ecRoot;
1316
- }
1317
- this._clearPrevOverMesh();
1318
- if (!this._transEnabled) {
1319
- this._setVisibility(this._all_tEnd, this._visibility);
1320
- this._transEnabled = true;
1321
- this.disableRotation();
1322
- this.disableScaling();
1323
- }
1324
- };
1325
- EditControl.prototype.disableTranslation = function () {
1326
- if (this._transEnabled) {
1327
- this._setVisibility(this._all_tEnd, 0);
1328
- this._transEnabled = false;
1329
- }
1330
- };
1331
- EditControl.prototype.isRotationEnabled = function () {
1332
- return this._rotEnabled;
1333
- };
1334
- EditControl.prototype.returnEuler = function (euler) {
1335
- this._eulerian = euler;
1336
- };
1337
- EditControl.prototype.enableRotation = function () {
1338
- if (this._hidden)
1339
- return;
1340
- if (this._rCtl == null) {
1341
- this._createRotAxes();
1342
- this._rCtl.parent = this._ecRoot;
1343
- }
1344
- this._clearPrevOverMesh();
1345
- if (!this._rotEnabled) {
1346
- this._setVisibility(this._all_rEnd, this._visibility);
1347
- this._rotEnabled = true;
1348
- this.disableTranslation();
1349
- this.disableScaling();
1350
- }
1351
- };
1352
- EditControl.prototype.disableRotation = function () {
1353
- if (this._rotEnabled) {
1354
- this._setVisibility(this._all_rEnd, 0);
1355
- this._rotEnabled = false;
1356
- }
1357
- };
1358
- EditControl.prototype.isScalingEnabled = function () {
1359
- return this._scaleEnabled;
1360
- };
1361
- EditControl.prototype.enableScaling = function () {
1362
- if (this._hidden)
1363
- return;
1364
- if (this._sX == null) {
1365
- this._createScaleAxes();
1366
- this._sCtl.parent = this._ecRoot;
1367
- }
1368
- this._clearPrevOverMesh();
1369
- if (!this._scaleEnabled) {
1370
- this._setVisibility(this._all_sEnd, this._visibility);
1371
- this._scaleEnabled = true;
1372
- this.disableTranslation();
1373
- this.disableRotation();
1374
- }
1375
- };
1376
- EditControl.prototype.disableScaling = function () {
1377
- if (this._scaleEnabled) {
1378
- this._setVisibility(this._all_sEnd, 0);
1379
- this._scaleEnabled = false;
1380
- }
1381
- };
1382
- EditControl.prototype.setScaleBounds = function (min, max) {
1383
- this._scaleBoundsMin = min ? min : null;
1384
- this._scaleBoundsMax = max ? max : null;
1385
- if (this._scaleBoundsMin != null) {
1386
- if (this._scaleBoundsMin.x == 0)
1387
- this._scaleBoundsMin.x = 0.00000001;
1388
- if (this._scaleBoundsMin.y == 0)
1389
- this._scaleBoundsMin.y = 0.00000001;
1390
- if (this._scaleBoundsMin.z == 0)
1391
- this._scaleBoundsMin.z = 0.00000001;
1392
- }
1393
- };
1394
- EditControl.prototype.removeScaleBounds = function () {
1395
- this._scaleBoundsMin = null;
1396
- this._scaleBoundsMax = null;
1397
- };
1398
- EditControl.prototype.setTransBounds = function (min, max) {
1399
- this._transBoundsMin = min ? min : null;
1400
- this._transBoundsMax = max ? max : null;
1401
- };
1402
- EditControl.prototype.removeTransBounds = function () {
1403
- this._transBoundsMin = null;
1404
- this._transBoundsMax = null;
1405
- };
1406
- EditControl.prototype.setRotBounds = function (min, max) {
1407
- this._rotBoundsMin = min ? min : null;
1408
- this._rotBoundsMax = max ? max : null;
1409
- };
1410
- EditControl.prototype.removeRotBounds = function () {
1411
- this._rotBoundsMin = null;
1412
- this._rotBoundsMax = null;
1413
- };
1414
- /*
1415
- * create big and small axeses which will be shown in translate, rotate and scale mode.
1416
- *
1417
- */
1418
- EditControl.prototype._createCommonAxes = function () {
1419
- var guideAxes = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("", this._scene);
1420
- //the big axes, shown when an axis is selected
1421
- this._bXaxis = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].CreateLines("", [new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](-100, 0, 0), new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](100, 0, 0)], this._scene);
1422
- this._bYaxis = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].CreateLines("", [new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, -100, 0), new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 100, 0)], this._scene);
1423
- this._bZaxis = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].CreateLines("", [new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, -100), new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, 100)], this._scene);
1424
- //lines are now pickable too
1425
- this._bXaxis.isPickable = false;
1426
- this._bYaxis.isPickable = false;
1427
- this._bZaxis.isPickable = false;
1428
- this._bXaxis.parent = guideAxes;
1429
- this._bYaxis.parent = guideAxes;
1430
- this._bZaxis.parent = guideAxes;
1431
- this._bXaxis.color = this._redCol;
1432
- this._bYaxis.color = this._greenCol;
1433
- this._bZaxis.color = this._blueCol;
1434
- this._hideBaxis();
1435
- //the small axis
1436
- var al = this._axesLen * this._axesScale * 0.75;
1437
- this._xaxis = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].CreateLines("", [new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, 0), new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](al, 0, 0)], this._scene);
1438
- this._yaxis = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].CreateLines("", [new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, 0), new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, al, 0)], this._scene);
1439
- this._zaxis = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].CreateLines("", [new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, 0), new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, al)], this._scene);
1440
- //lines are now pickable too
1441
- this._xaxis.isPickable = false;
1442
- this._yaxis.isPickable = false;
1443
- this._zaxis.isPickable = false;
1444
- this._xaxis.parent = guideAxes;
1445
- this._yaxis.parent = guideAxes;
1446
- this._zaxis.parent = guideAxes;
1447
- this._xaxis.color = this._redCol;
1448
- this._yaxis.color = this._greenCol;
1449
- this._zaxis.color = this._blueCol;
1450
- this._xaxis.renderingGroupId = 1;
1451
- this._yaxis.renderingGroupId = 1;
1452
- this._zaxis.renderingGroupId = 1;
1453
- return guideAxes;
1454
- };
1455
- EditControl.prototype._createPickPlanes = function () {
1456
- this._pALL = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].CreatePlane("", 5, this._scene);
1457
- this._pXZ = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].CreatePlane("", 5, this._scene);
1458
- this._pZY = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].CreatePlane("", 5, this._scene);
1459
- this._pYX = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].CreatePlane("", 5, this._scene);
1460
- this._pALL.isPickable = false;
1461
- this._pXZ.isPickable = false;
1462
- this._pZY.isPickable = false;
1463
- this._pYX.isPickable = false;
1464
- this._pALL.visibility = 0;
1465
- this._pXZ.visibility = 0;
1466
- this._pZY.visibility = 0;
1467
- this._pYX.visibility = 0;
1468
- this._pALL.renderingGroupId = 1;
1469
- this._pXZ.renderingGroupId = 1;
1470
- this._pZY.renderingGroupId = 1;
1471
- this._pYX.renderingGroupId = 1;
1472
- this._pALL.lookAt(this._mainCamera.position);
1473
- this._pXZ.rotate(babylonjs__WEBPACK_IMPORTED_MODULE_0__["Axis"].X, 1.57);
1474
- this._pZY.rotate(babylonjs__WEBPACK_IMPORTED_MODULE_0__["Axis"].Y, 1.57);
1475
- var pickPlanes = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("", this._scene);
1476
- this._pALL.parent = pickPlanes;
1477
- this._pXZ.parent = pickPlanes;
1478
- this._pZY.parent = pickPlanes;
1479
- this._pYX.parent = pickPlanes;
1480
- return pickPlanes;
1481
- };
1482
- EditControl.prototype._createTransAxes = function () {
1483
- var r = this._pickWidth * 2 * this._axesScale;
1484
- var l = this._axesLen * this._axesScale;
1485
- this._tCtl = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("", this._scene);
1486
- /*pickable invisible boxes around axes lines*/
1487
- this._createPickableTrans(r, l, this._tCtl, this._scene);
1488
- //non pickable but visible cones at end of axes lines
1489
- this._createNonPickableTrans(r, l, this._scene);
1490
- };
1491
- EditControl.prototype._createPickableTrans = function (r, l, tCtl, scene) {
1492
- var tX = this._extrudeBox(r / 2, l);
1493
- tX.name = "X";
1494
- var tY = tX.clone("Y");
1495
- var tZ = tX.clone("Z");
1496
- var tXZ = babylonjs__WEBPACK_IMPORTED_MODULE_0__["MeshBuilder"].CreatePlane("XZ", { size: r * 2 }, scene);
1497
- var tZY = babylonjs__WEBPACK_IMPORTED_MODULE_0__["MeshBuilder"].CreatePlane("ZY", { size: r * 2 }, scene);
1498
- var tYX = babylonjs__WEBPACK_IMPORTED_MODULE_0__["MeshBuilder"].CreatePlane("YX", { size: r * 2 }, scene);
1499
- tXZ.rotation.x = 1.57;
1500
- tZY.rotation.y = -1.57;
1501
- tXZ.position.x = 2 * r;
1502
- tXZ.position.z = 2 * r;
1503
- tZY.position.z = 2 * r;
1504
- tZY.position.y = 2 * r;
1505
- tYX.position.y = 2 * r;
1506
- tYX.position.x = 2 * r;
1507
- tXZ.bakeCurrentTransformIntoVertices();
1508
- tZY.bakeCurrentTransformIntoVertices();
1509
- tYX.bakeCurrentTransformIntoVertices();
1510
- var tAll = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].CreateBox("ALL", r * 2, scene);
1511
- tX.parent = tCtl;
1512
- tY.parent = tCtl;
1513
- tZ.parent = tCtl;
1514
- tXZ.parent = tCtl;
1515
- tZY.parent = tCtl;
1516
- tYX.parent = tCtl;
1517
- tAll.parent = tCtl;
1518
- tX.rotation.y = 1.57;
1519
- tY.rotation.x -= 1.57;
1520
- this._tX = tX;
1521
- this._tY = tY;
1522
- this._tZ = tZ;
1523
- this._tXZ = tXZ;
1524
- this._tZY = tZY;
1525
- this._tYX = tYX;
1526
- this._tAll = tAll;
1527
- this._all_t = [tX, tY, tZ, tXZ, tZY, tYX, tAll];
1528
- this._setVisibility(this._all_t, 0);
1529
- //do not want clients picking this
1530
- //we will pick using mesh filter in scene.pick function
1531
- this._setPickableFalse(this._all_t);
1532
- };
1533
- EditControl.prototype._createNonPickableTrans = function (r, l, scene) {
1534
- //cone length
1535
- var cl = l / 5;
1536
- //cone base radius
1537
- //let cr: number = r;
1538
- var tEndX = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].CreateCylinder("", cl, 0, r, 6, 1, scene);
1539
- var tEndY = tEndX.clone("");
1540
- var tEndZ = tEndX.clone("");
1541
- var s = r * 2;
1542
- var tEndXZ = babylonjs__WEBPACK_IMPORTED_MODULE_0__["MeshBuilder"].CreatePlane("XZ", { size: s }, scene);
1543
- var tEndZY = babylonjs__WEBPACK_IMPORTED_MODULE_0__["MeshBuilder"].CreatePlane("ZY", { size: s }, scene);
1544
- var tEndYX = babylonjs__WEBPACK_IMPORTED_MODULE_0__["MeshBuilder"].CreatePlane("YX", { size: s }, scene);
1545
- var tEndAll = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].CreateBox("ALL", r, scene);
1546
- tEndX.rotation.x = 1.57;
1547
- tEndY.rotation.x = 1.57;
1548
- tEndZ.rotation.x = 1.57;
1549
- tEndXZ.rotation.x = 1.57;
1550
- tEndZY.rotation.y = 1.57;
1551
- //tEndYX.rotation.x = 0;
1552
- tEndXZ.position.x = s;
1553
- tEndXZ.position.z = s;
1554
- tEndZY.position.z = s;
1555
- tEndZY.position.y = s;
1556
- tEndYX.position.y = s;
1557
- tEndYX.position.x = s;
1558
- tEndX.parent = this._tX;
1559
- tEndY.parent = this._tY;
1560
- tEndZ.parent = this._tZ;
1561
- tEndXZ.parent = this._tXZ;
1562
- tEndZY.parent = this._tZY;
1563
- tEndYX.parent = this._tYX;
1564
- tEndAll.parent = this._tAll;
1565
- tEndX.position.z = l - cl / 2;
1566
- tEndY.position.z = l - cl / 2;
1567
- tEndZ.position.z = l - cl / 2;
1568
- tEndX.material = this._redMat;
1569
- tEndY.material = this._greenMat;
1570
- tEndZ.material = this._blueMat;
1571
- tEndXZ.material = this._greenMat;
1572
- tEndZY.material = this._redMat;
1573
- tEndYX.material = this._blueMat;
1574
- tEndAll.material = this._yellowMat;
1575
- this._tEndX = tEndX;
1576
- this._tEndY = tEndY;
1577
- this._tEndZ = tEndZ;
1578
- this._tEndXZ = tEndXZ;
1579
- this._tEndZY = tEndZY;
1580
- this._tEndYX = tEndYX;
1581
- this._tEndAll = tEndAll;
1582
- this._all_tEnd = [tEndX, tEndY, tEndZ, tEndXZ, tEndZY, tEndYX, tEndAll];
1583
- this._setPickableFalse(this._all_tEnd);
1584
- this._setRenderingGroup(this._all_tEnd);
1585
- };
1586
- EditControl.prototype.setRotGuideFull = function (y) {
1587
- if (y)
1588
- this._guideSize = 360;
1589
- else
1590
- this._guideSize = 180;
1591
- if (this._rCtl != null) {
1592
- this._rCtl.dispose();
1593
- this._rAll.dispose();
1594
- this._rCtl = null;
1595
- this.enableRotation();
1596
- }
1597
- };
1598
- EditControl.prototype._createRotAxes = function () {
1599
- var d = this._axesLen * this._axesScale * 2;
1600
- this._rCtl = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("", this._scene);
1601
- //pickable invisible torus around the rotation circles
1602
- this._createPickableRot(d, this._rCtl);
1603
- /*non pickable but visible circles */
1604
- this._createNonPickableRot(d);
1605
- };
1606
- EditControl.prototype._createPickableRot = function (d, rCtl) {
1607
- var rX = this._createTube(d / 2, this._guideSize);
1608
- var rY = this._createTube(d / 2, this._guideSize);
1609
- var rZ = this._createTube(d / 2, this._guideSize);
1610
- var rAll = this._createTube(d / 1.75, 360);
1611
- rX.name = "X";
1612
- rY.name = "Y";
1613
- rZ.name = "Z";
1614
- rAll.name = "ALL";
1615
- rX.rotation.z = 1.57;
1616
- rZ.rotation.x = -1.57;
1617
- rX.bakeCurrentTransformIntoVertices();
1618
- rZ.bakeCurrentTransformIntoVertices();
1619
- rAll.rotation.x = 1.57;
1620
- rX.parent = rCtl;
1621
- rY.parent = rCtl;
1622
- rZ.parent = rCtl;
1623
- rAll.parent = this._pALL;
1624
- this._rX = rX;
1625
- this._rY = rY;
1626
- this._rZ = rZ;
1627
- this._rAll = rAll;
1628
- this._all_r = [rX, rY, rZ, rAll];
1629
- this._setVisibility(this._all_r, 0);
1630
- //do not want clients picking this
1631
- //we will pick using mesh filter in scene.pick function
1632
- this._setPickableFalse(this._all_r);
1633
- };
1634
- EditControl.prototype._createNonPickableRot = function (d) {
1635
- var rEndX = this._createCircle(d / 2, this._guideSize, false);
1636
- var rEndY = rEndX.clone("");
1637
- var rEndZ = rEndX.clone("");
1638
- var rEndAll = this._createCircle(d / 1.75, 360, false);
1639
- var rEndAll2 = this._createCircle(d / 2, 360, false);
1640
- rEndX.parent = this._rX;
1641
- rEndY.parent = this._rY;
1642
- rEndZ.parent = this._rZ;
1643
- rEndX.rotation.z = 1.57;
1644
- rEndZ.rotation.x = -1.57;
1645
- rEndAll.parent = this._rAll;
1646
- rEndAll2.parent = this._rAll;
1647
- rEndX.color = this._redCol;
1648
- rEndY.color = this._greenCol;
1649
- rEndZ.color = this._blueCol;
1650
- rEndAll.color = this._yellowCol;
1651
- rEndAll2.color = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Color3"].Gray();
1652
- this._rEndX = rEndX;
1653
- this._rEndY = rEndY;
1654
- this._rEndZ = rEndZ;
1655
- this._rEndAll = rEndAll;
1656
- this._rEndAll2 = rEndAll2;
1657
- this._all_rEnd = [rEndX, rEndY, rEndZ, rEndAll, rEndAll2];
1658
- this._setPickableFalse(this._all_rEnd);
1659
- this._setRenderingGroup(this._all_rEnd);
1660
- };
1661
- EditControl.prototype._setVisibility = function (meshes, v) {
1662
- meshes.map(function (m) { return m.visibility = v; });
1663
- };
1664
- EditControl.prototype._setPickableFalse = function (meshes) {
1665
- meshes.map(function (m) { m.isPickable = false; });
1666
- };
1667
- EditControl.prototype._setRenderingGroup = function (meshes) {
1668
- meshes.map(function (m) { return m.renderingGroupId = 2; });
1669
- };
1670
- EditControl.prototype._extrudeBox = function (w, l) {
1671
- var shape = [new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](w, w, 0), new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](-w, w, 0), new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](-w, -w, 0), new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](w, -w, 0), new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](w, w, 0)];
1672
- var path = [new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, 0), new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, 0, l)];
1673
- var box = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].ExtrudeShape("", shape, path, 1, 0, 2, this._scene);
1674
- return box;
1675
- };
1676
- EditControl.prototype._createCircle = function (r, t, double) {
1677
- if (t === null)
1678
- t = 360;
1679
- var points = [];
1680
- var x;
1681
- var z;
1682
- var a = 3.14 / 180;
1683
- var p = 0;
1684
- for (var i = 0; i <= t; i = i + 5) {
1685
- x = r * Math.cos(i * a);
1686
- if (i == 90)
1687
- z = r;
1688
- else if (i == 270)
1689
- z = -r;
1690
- else
1691
- z = r * Math.sin(i * a);
1692
- points[p] = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](x, 0, z);
1693
- p++;
1694
- }
1695
- if (double) {
1696
- r = r - 0.04;
1697
- for (var i = 0; i <= t; i = i + 5) {
1698
- x = r * Math.cos(i * a);
1699
- if (i == 90)
1700
- z = r;
1701
- else if (i == 270)
1702
- z = -r;
1703
- else
1704
- z = r * Math.sin(i * a);
1705
- points[p] = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](x, 0, z);
1706
- p++;
1707
- }
1708
- }
1709
- var circle = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].CreateLines("", points, this._scene);
1710
- return circle;
1711
- };
1712
- EditControl.prototype._createTube = function (r, t) {
1713
- if (t === null)
1714
- t = 360;
1715
- var points = [];
1716
- var x;
1717
- var z;
1718
- var a = 3.14 / 180;
1719
- var p = 0;
1720
- for (var i = 0; i <= t; i = i + 30) {
1721
- x = r * Math.cos(i * a);
1722
- if (i == 90)
1723
- z = r;
1724
- else if (i == 270)
1725
- z = -r;
1726
- else
1727
- z = r * Math.sin(i * a);
1728
- points[p] = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"](x, 0, z);
1729
- p++;
1730
- }
1731
- var tube = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].CreateTube("", points, this._pickWidth * this._axesScale * 2, 3, null, babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].NO_CAP, this._scene);
1732
- return tube;
1733
- };
1734
- EditControl.prototype._createScaleAxes = function () {
1735
- var r = this._pickWidth * 2 * this._axesScale;
1736
- var l = this._axesLen * this._axesScale;
1737
- this._sCtl = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("", this._scene);
1738
- /* pickable , invisible part */
1739
- this._createPickableScale(r, l, this._sCtl);
1740
- /* non pickable visible boxes at end of axes */
1741
- this._createNonPickableScale(r, l);
1742
- };
1743
- EditControl.prototype._createPickableScale = function (r, l, sCtl) {
1744
- var sX = this._extrudeBox(r / 2, l);
1745
- sX.name = "X";
1746
- var sY = sX.clone("Y");
1747
- var sZ = sX.clone("Z");
1748
- var sXZ = babylonjs__WEBPACK_IMPORTED_MODULE_0__["MeshBuilder"].CreatePlane("XZ", { size: r * 2 }, this._scene);
1749
- var sZY = babylonjs__WEBPACK_IMPORTED_MODULE_0__["MeshBuilder"].CreatePlane("ZY", { size: r * 2 }, this._scene);
1750
- var sYX = babylonjs__WEBPACK_IMPORTED_MODULE_0__["MeshBuilder"].CreatePlane("YX", { size: r * 2 }, this._scene);
1751
- sXZ.rotation.x = 1.57;
1752
- sZY.rotation.y = -1.57;
1753
- sXZ.position.x = 2 * r;
1754
- sXZ.position.z = 2 * r;
1755
- sZY.position.z = 2 * r;
1756
- sZY.position.y = 2 * r;
1757
- sYX.position.y = 2 * r;
1758
- sYX.position.x = 2 * r;
1759
- sXZ.bakeCurrentTransformIntoVertices();
1760
- sZY.bakeCurrentTransformIntoVertices();
1761
- sYX.bakeCurrentTransformIntoVertices();
1762
- var sAll = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].CreateBox("ALL", 2 * r, this._scene);
1763
- sX.parent = sCtl;
1764
- sY.parent = sCtl;
1765
- sZ.parent = sCtl;
1766
- sAll.parent = sCtl;
1767
- sXZ.parent = sCtl;
1768
- sZY.parent = sCtl;
1769
- sYX.parent = sCtl;
1770
- sX.rotation.y = 1.57;
1771
- sY.rotation.x -= 1.57;
1772
- this._sX = sX;
1773
- this._sY = sY;
1774
- this._sZ = sZ;
1775
- this._sXZ = sXZ;
1776
- this._sZY = sZY;
1777
- this._sYX = sYX;
1778
- this._sAll = sAll;
1779
- this._all_s = [sX, sY, sZ, sXZ, sZY, sYX, sAll];
1780
- this._setVisibility(this._all_s, 0);
1781
- //do not want clients picking this
1782
- //we will pick using mesh filter in scene.pick function
1783
- this._setPickableFalse(this._all_s);
1784
- };
1785
- EditControl.prototype._createNonPickableScale = function (r, l) {
1786
- var sEndX = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].CreateBox("", r, this._scene);
1787
- var sEndY = sEndX.clone("");
1788
- var sEndZ = sEndX.clone("");
1789
- var s = r * 2;
1790
- var sEndXZ = babylonjs__WEBPACK_IMPORTED_MODULE_0__["MeshBuilder"].CreatePlane("XZ", { size: s }, this._scene);
1791
- var sEndZY = babylonjs__WEBPACK_IMPORTED_MODULE_0__["MeshBuilder"].CreatePlane("ZY", { size: s }, this._scene);
1792
- var sEndYX = babylonjs__WEBPACK_IMPORTED_MODULE_0__["MeshBuilder"].CreatePlane("YX", { size: s }, this._scene);
1793
- var sEndAll = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Mesh"].CreateBox("ALL", r, this._scene);
1794
- sEndXZ.rotation.x = 1.57;
1795
- sEndZY.rotation.y = -1.57;
1796
- sEndXZ.position.x = s;
1797
- sEndXZ.position.z = s;
1798
- sEndZY.position.z = s;
1799
- sEndZY.position.y = s;
1800
- sEndYX.position.y = s;
1801
- sEndYX.position.x = s;
1802
- sEndX.parent = this._sX;
1803
- sEndY.parent = this._sY;
1804
- sEndZ.parent = this._sZ;
1805
- sEndXZ.parent = this._sXZ;
1806
- sEndZY.parent = this._sZY;
1807
- sEndYX.parent = this._sYX;
1808
- sEndAll.parent = this._sAll;
1809
- sEndX.position.z = l - r / 2;
1810
- sEndY.position.z = l - r / 2;
1811
- sEndZ.position.z = l - r / 2;
1812
- sEndX.material = this._redMat;
1813
- sEndY.material = this._greenMat;
1814
- sEndZ.material = this._blueMat;
1815
- sEndXZ.material = this._greenMat;
1816
- sEndZY.material = this._redMat;
1817
- sEndYX.material = this._blueMat;
1818
- sEndAll.material = this._yellowMat;
1819
- this._sEndX = sEndX;
1820
- this._sEndY = sEndY;
1821
- this._sEndZ = sEndZ;
1822
- this._sEndXZ = sEndXZ;
1823
- this._sEndZY = sEndZY;
1824
- this._sEndYX = sEndYX;
1825
- this._sEndAll = sEndAll;
1826
- this._all_sEnd = [sEndX, sEndY, sEndZ, sEndXZ, sEndZY, sEndYX, sEndAll];
1827
- this._setPickableFalse(this._all_sEnd);
1828
- this._setRenderingGroup(this._all_sEnd);
1829
- };
1830
- /**
1831
- * checks if a have left hand , right hand issue.
1832
- * In other words if a mesh is a LHS mesh in RHS system or
1833
- * a RHS mesh in LHS system
1834
- * The X axis will be reversed in such cases.
1835
- * thus Cross product of X and Y should be inverse of Z.
1836
- *
1837
- */
1838
- // private _check_LHS_RHS(mesh: Mesh) {
1839
- // let actualZ = Vector3.Cross(this._localX, this._localY);
1840
- // //same direction or opposite direction of Z
1841
- // if (Vector3.Dot(actualZ, this._localZ) < 0) return true;
1842
- // else return false;
1843
- // }
1844
- /**
1845
- * set how transparent the axes are
1846
- * 0 to 1
1847
- * 0 - completely transparent
1848
- * 1 - completely non transparent
1849
- * default is 0.75
1850
- */
1851
- EditControl.prototype.setVisibility = function (v) {
1852
- this._visibility = v;
1853
- };
1854
- EditControl.prototype.setLocal = function (l) {
1855
- if (this._local == l)
1856
- return;
1857
- this._local = l;
1858
- if (!l) {
1859
- this._ecRoot.rotationQuaternion = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
1860
- }
1861
- };
1862
- EditControl.prototype.isLocal = function () {
1863
- return this._local;
1864
- };
1865
- EditControl.prototype.setTransSnap = function (s) {
1866
- this._snapT = s;
1867
- };
1868
- EditControl.prototype.isTransSnap = function () {
1869
- return this._snapT;
1870
- };
1871
- EditControl.prototype.setRotSnap = function (s) {
1872
- this._snapR = s;
1873
- };
1874
- EditControl.prototype.isRotSnap = function () {
1875
- return this._snapR;
1876
- };
1877
- EditControl.prototype.setScaleSnap = function (s) {
1878
- this._snapS = s;
1879
- };
1880
- EditControl.prototype.isScaleSnap = function () {
1881
- return this._snapS;
1882
- };
1883
- EditControl.prototype.setTransSnapValue = function (t) {
1884
- this._tSnap.copyFromFloats(t, t, t);
1885
- this._transSnap = t;
1886
- };
1887
- EditControl.prototype.getTransSnapValue = function () {
1888
- return this._transSnap;
1889
- };
1890
- EditControl.prototype.setRotSnapValue = function (r) {
1891
- this._rotSnap = r;
1892
- };
1893
- EditControl.prototype.getRotSnapValue = function () {
1894
- return this._rotSnap;
1895
- };
1896
- EditControl.prototype.setScaleSnapValue = function (r) {
1897
- this._scaleSnap = r;
1898
- };
1899
- EditControl.prototype.getScaleSnapValue = function () {
1900
- return this._scaleSnap;
1901
- };
1902
- EditControl.prototype._getAngle2 = function (p1, p2, cameraPos, c2ec, mN) {
1903
- /**
1904
- * A) find out if the camera is above , below, left, right of the rotation plane
1905
- */
1906
- //project "camera to ec" vector onto mesh normal to get distance to rotation plane
1907
- var d = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Dot(c2ec, mN);
1908
- //scale mesh normal by above ammount to get vector to rotation plane
1909
- mN.scaleToRef(d, this._tv1);
1910
- //get the point of intersection of vector from camera perpendicular to rotation plane
1911
- cameraPos.addToRef(this._tv1, this._tv2);
1912
- var i = this._tv2; //save some typing
1913
- //find the co-ordinate of this point in the cameras frame of reference
1914
- this._mainCamera.getWorldMatrix().invertToRef(this._tm);
1915
- babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].TransformCoordinatesToRef(this._tv2, this._tm, this._tv2);
1916
- //find in which quadarant the point (and thus the rotation plane) is in the camera xy plane
1917
- var q = 0; //(1=x y,2=-x y,3=-x -y,4=x -y)
1918
- if (i.x >= 0 && i.y >= 0)
1919
- q = 1;
1920
- else if (i.x <= 0 && i.y >= 0)
1921
- q = 2;
1922
- else if (i.x <= 0 && i.y <= 0)
1923
- q = 3;
1924
- else if (i.x >= 0 && i.y <= 0)
1925
- q = 4;
1926
- /**
1927
- * B) find out if the user moved pointer up,down, right, left
1928
- */
1929
- //find movement vector in camera frame of reference
1930
- babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].TransformCoordinatesToRef(p1, this._tm, this._tv1);
1931
- babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].TransformCoordinatesToRef(p2, this._tm, this._tv2);
1932
- this._tv2.subtractInPlace(this._tv1);
1933
- var mv = this._tv2; //save some typing
1934
- //for now lets set the angle magnitutde same as amount by which the mouse moved
1935
- var angle = mv.length();
1936
- var m = ""; //(u ,d ,r,l)
1937
- if (mv.x >= 0 && mv.y >= 0) {
1938
- if (mv.x >= mv.y)
1939
- m = "r";
1940
- else
1941
- m = "u";
1942
- }
1943
- else if (mv.x <= 0 && mv.y >= 0) {
1944
- if (-mv.x >= mv.y)
1945
- m = "l";
1946
- else
1947
- m = "u";
1948
- }
1949
- else if (mv.x <= 0 && mv.y <= 0) {
1950
- if (-mv.x >= -mv.y)
1951
- m = "l";
1952
- else
1953
- m = "d";
1954
- }
1955
- else if (mv.x >= 0 && mv.y <= 0) {
1956
- if (mv.x >= -mv.y)
1957
- m = "r";
1958
- else
1959
- m = "d";
1960
- }
1961
- /**
1962
- * C) decide if the user was trying to rotate clockwise (+1) or anti-clockwise(-1)
1963
- */
1964
- var r = 0;
1965
- //if mouse moved down /up and rotation plane is on right or left side of user
1966
- if (m == "d") {
1967
- if (q == 1 || q == 4)
1968
- r = 1;
1969
- else
1970
- r = -1;
1971
- }
1972
- else if (m == "u") {
1973
- if (q == 1 || q == 4)
1974
- r = -1;
1975
- else
1976
- r = 1;
1977
- //if mouse moved right/left and rotation plane is above or below user
1978
- }
1979
- else if (m == "r") {
1980
- if (q == 2 || q == 1)
1981
- r = 1;
1982
- else
1983
- r = -1;
1984
- }
1985
- else if (m == "l") {
1986
- if (q == 2 || q == 1)
1987
- r = -1;
1988
- else
1989
- r = 1;
1990
- }
1991
- return r * angle;
1992
- };
1993
- /**
1994
- * finds the angle subtended from points p1 to p2 around the point p
1995
- * checks if the user was trying to rotate clockwise (+ve in LHS) or anticlockwise (-ve in LHS)
1996
- * to figure this check the orientation of the user(camera)to ec vector with the rotation normal vector
1997
- */
1998
- EditControl.prototype._getAngle = function (p1, p2, p, c2ec) {
1999
- p1.subtractToRef(p, this._tv1);
2000
- p2.subtractToRef(p, this._tv2);
2001
- babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].CrossToRef(this._tv1, this._tv2, this._tv3);
2002
- var angle = Math.asin(this._tv3.length() / (this._tv1.length() * this._tv2.length()));
2003
- //camera looking down from front of plane or looking up from behind plane
2004
- if ((babylonjs__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Dot(this._tv3, c2ec) > 0)) {
2005
- angle = -1 * angle;
2006
- }
2007
- return angle;
2008
- };
2009
- EditControl._getStandardMaterial = function (col, scene) {
2010
- var mat = new babylonjs__WEBPACK_IMPORTED_MODULE_0__["StandardMaterial"]("", scene);
2011
- mat.emissiveColor = col;
2012
- mat.diffuseColor = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Color3"].Black();
2013
- mat.specularColor = babylonjs__WEBPACK_IMPORTED_MODULE_0__["Color3"].Black();
2014
- mat.backFaceCulling = false;
2015
- return mat;
2016
- };
2017
- EditControl.prototype._createMaterials = function (scene) {
2018
- this._redMat = EditControl._getStandardMaterial(this._redCol, scene);
2019
- this._greenMat = EditControl._getStandardMaterial(this._greenCol, scene);
2020
- this._blueMat = EditControl._getStandardMaterial(this._blueCol, scene);
2021
- this._whiteMat = EditControl._getStandardMaterial(this._whiteCol, scene);
2022
- this._yellowMat = EditControl._getStandardMaterial(this._yellowCol, scene);
2023
- };
2024
- EditControl.prototype._disposeMaterials = function () {
2025
- this._redMat.dispose();
2026
- this._greenMat.dispose();
2027
- this._blueMat.dispose();
2028
- this._whiteMat.dispose();
2029
- this._yellowMat.dispose();
2030
- };
2031
- return EditControl;
2032
- }());
2033
-
2034
- var ActHist = /** @class */ (function () {
2035
- function ActHist(mesh, capacity) {
2036
- this.lastMax = 10;
2037
- this.acts = new Array();
2038
- this.last = -1;
2039
- this.current = -1;
2040
- this.mesh = mesh;
2041
- this.lastMax = capacity - 1;
2042
- this.add();
2043
- }
2044
- ActHist.prototype.setCapacity = function (c) {
2045
- if ((c == 0)) {
2046
- console.error("capacity should be more than zero");
2047
- return;
2048
- }
2049
- this.lastMax = c - 1;
2050
- this.last = -1;
2051
- this.current = -1;
2052
- this.acts = new Array();
2053
- this.add();
2054
- };
2055
- ActHist.prototype.add = function (at) {
2056
- if (at === undefined)
2057
- at = null;
2058
- var act = new Act(this.mesh, at);
2059
- if ((this.current < this.last)) {
2060
- this.acts.splice(this.current + 1);
2061
- this.last = this.current;
2062
- }
2063
- if ((this.last == this.lastMax)) {
2064
- this.acts.shift();
2065
- this.acts.push(act);
2066
- }
2067
- else {
2068
- this.acts.push(act);
2069
- this.last++;
2070
- this.current++;
2071
- }
2072
- };
2073
- ActHist.prototype.undo = function () {
2074
- if ((this.current > 0)) {
2075
- var at = this.acts[this.current].getActionType();
2076
- this.current--;
2077
- this.acts[this.current].perform(this.mesh);
2078
- return at;
2079
- }
2080
- };
2081
- ActHist.prototype.redo = function () {
2082
- if ((this.current < this.last)) {
2083
- this.current++;
2084
- this.acts[this.current].perform(this.mesh);
2085
- return this.acts[this.current].getActionType();
2086
- }
2087
- };
2088
- return ActHist;
2089
- }());
2090
- var Act = /** @class */ (function () {
2091
- function Act(mesh, at) {
2092
- this._p = mesh.position.clone();
2093
- //if (mesh.rotationQuaternion == null) {
2094
- if (mesh.rotationQuaternion == null) {
2095
- this._rQ = null;
2096
- this._rE = mesh.rotation.clone();
2097
- }
2098
- else {
2099
- this._rQ = mesh.rotationQuaternion.clone();
2100
- this._rE = null;
2101
- }
2102
- this._s = mesh.scaling.clone();
2103
- this._at = at;
2104
- }
2105
- Act.prototype.getActionType = function () {
2106
- return this._at;
2107
- };
2108
- Act.prototype.perform = function (mesh) {
2109
- mesh.position.copyFrom(this._p);
2110
- //check if we are doing euler or quaternion now
2111
- //also check what were we doing when the rotation value
2112
- //was captured and set value accordingly
2113
- if (mesh.rotationQuaternion == null) {
2114
- if (this._rE != null) {
2115
- //mesh.rotation = this.rE.clone();
2116
- mesh.rotation.copyFrom(this._rE);
2117
- }
2118
- else {
2119
- //mesh.rotation = this.r.toEulerAngles();
2120
- mesh.rotation.copyFrom(this._rQ.toEulerAngles());
2121
- }
2122
- }
2123
- else {
2124
- if (this._rQ != null) {
2125
- mesh.rotationQuaternion.copyFrom(this._rQ);
2126
- }
2127
- else {
2128
- //TODO use BABYLON.Quaternion.RotationYawPitchRoll(rot.y, rot.x, rot.z) instead of toQuaternion.
2129
- //mesh.rotationQuaternion.copyFrom(this.rE.toQuaternion());
2130
- mesh.rotationQuaternion.copyFrom(babylonjs__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].RotationYawPitchRoll(this._rE.y, this._rE.x, this._rE.z));
2131
- }
2132
- }
2133
- mesh.scaling.copyFrom(this._s);
2134
- };
2135
- return Act;
2136
- }());
2137
-
2138
-
2139
- /***/ }),
2140
-
2141
- /***/ "babylonjs":
2142
- /*!****************************************************************************************************!*\
2143
- !*** external {"commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs","root":"BABYLON"} ***!
2144
- \****************************************************************************************************/
2145
- /*! no static exports found */
2146
- /***/ (function(module, exports) {
2147
-
2148
- module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs__;
2149
-
2150
- /***/ })
2151
-
2152
- /******/ });
2153
- });
1
+ /*! For license information please see EditControl.max.js.LICENSE.txt */
2
+ !function(t,i){if("object"==typeof exports&&"object"==typeof module)module.exports=i(require("babylonjs"));else if("function"==typeof define&&define.amd)define(["babylonjs"],i);else{var s="object"==typeof exports?i(require("babylonjs")):i(t.BABYLON);for(var h in s)("object"==typeof exports?exports:t)[h]=s[h]}}(self,(t=>(()=>{"use strict";var i={babylonjs:i=>{i.exports=t}},s={};function h(t){var n=s[t];if(void 0!==n)return n.exports;var u=s[t]={exports:{}};return i[t](u,u.exports,h),u.exports}h.n=t=>{var i=t&&t.t?()=>t.default:()=>t;return h.d(i,{a:i}),i},h.d=(t,i)=>{for(var s in i)h.o(i,s)&&!h.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:i[s]})},h.o=(t,i)=>Object.prototype.hasOwnProperty.call(t,i),h.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"t",{value:!0})};var n={};return(()=>{h.r(n),h.d(n,{EditControl:()=>s});var t,i=h("babylonjs");!function(t){t[t.TRANS=0]="TRANS",t[t.ROT=1]="ROT",t[t.SCALE=2]="SCALE"}(t||(t={}));var s=function(){function s(t,s,h,n,e,r){var o=this;this.i=!0,this.h=!1,this.u=!1,this.l=1,this.v=Math.PI/18,this.M=.4,this.p=1,this.L=.02,this.A=new i.Color3(1,.2,.2),this.j=new i.Color3(.2,1,.2),this.S=new i.Color3(.2,.2,1),this.O=new i.Color3(1,1,1),this.T=new i.Color3(1,1,.2),this.R=.75,this.g=!1,this.k=new i.Matrix,this.q=new i.Vector3(0,0,0),this.C=2,this._=new i.Vector3(0,0,0),this.B=new i.Vector3(0,0,0),this.N="",this.D=!1,this.F=null,this.G=null,this.H=null,this.I=!1,this.J=!1,this.K=!1,this.P=!1,this.U=new i.Vector3(0,0,0),this.V=new i.Vector3(0,0,0),this.W=!1,this.$=new i.Vector3(0,0,0),this.tt=.25,this.it=new i.Vector3(0,0,0),this.st=new i.Vector3(0,0,0),this.ht=new i.Vector3(0,0,0),this.nt=new i.Vector3(0,0,0),this.ut=!1,this.et=0,this.rt=!1,this.ot=!1,this.ft=!1,this.lt=180,this.ct=new i.Vector3(this.l,this.l,this.l),this.vt=new i.Vector3(0,0,0),this.wt=new i.Vector3(0,0,0),this.Mt=new i.Vector3(0,0,0),this.Xt=new i.Matrix,this.Yt=t,this.Zt=s,this.bt=h,null!=n&&(this.p=n),this.ut=null!==e&&e,this.dt(),null!=r&&(this.L=r),this.Lt=i.UtilityLayerRenderer.DefaultUtilityLayer,this.Lt.onlyCheckPointerDownEvents=!1,this.zt=this.Lt.utilityLayerScene,this.yt=new u(t,10),t.computeWorldMatrix(!0),this.At=this.jt(t),this.St(t),this.g=this.xt(t),console.log("lhs rhs issue "+this.g),this.Ot=new i.Mesh("",this.zt),this.Ot.rotationQuaternion=i.Quaternion.Identity(),this.Ot.visibility=0,this.Ot.isPickable=!1,this.Tt(this.zt),this.Et().parent=this.Ot,this.Rt().parent=this.Ot,this.gt=function(t){return o.kt(t)},this.qt=function(t){return o.Ct(t)},this._t=function(t){return o.Bt(t)},h.addEventListener("pointerdown",this.gt,!1),h.addEventListener("pointerup",this.qt,!1),h.addEventListener("pointermove",this._t,!1),this.Nt=function(){return o.Qt()},this.zt.registerBeforeRender(this.Nt)}return s.prototype.getRoot=function(){return this.Ot},s.prototype.dt=function(){if(!this.ut&&(null==this.Yt.rotationQuaternion||null==this.Yt.rotationQuaternion))throw"Error: Eulerian is set to false but the mesh's rotationQuaternion is not set."},s.prototype.xt=function(t){var s=!1,h=t.parent;if(null==h)return!1;this.St(h);var n=i.Vector3.Cross(this.st,this.ht);return s=i.Vector3.Dot(n,this.nt)<0,this.St(t),s},s.prototype.Qt=function(){this.Ot.position=this.Yt.getAbsolutePivotPoint(),this.Dt(),this.Ft(),this.i?(this.Ot.getWorldMatrix().invertToRef(this.k),i.Vector3.TransformCoordinatesToRef(this.Zt.position,this.k,this.q),this.Gt.lookAt(this.q,0,0,0,i.Space.LOCAL)):(this.Zt.position.subtractToRef(this.Ot.position,this.q),this.Gt.lookAt(this.Zt.position,0,0,0,i.Space.WORLD)),this.ot?this.Ht():this.rt?this.It(this.Jt,this.Kt,this.Pt):this.ft&&this.It(this.Ut,this.Vt,this.Wt)},s.prototype.Dt=function(){if(this.i)if(null==this.Yt.parent)if(this.ut){var t=this.Yt.rotation;i.Quaternion.RotationYawPitchRollToRef(t.y,t.x,t.z,this.Ot.rotationQuaternion)}else this.Ot.rotationQuaternion.copyFrom(this.Yt.rotationQuaternion);else{if(this.$t(this.Yt))return;this.Yt.getWorldMatrix().getRotationMatrixToRef(this.Xt),i.Quaternion.FromRotationMatrixToRef(this.Xt,this.Ot.rotationQuaternion)}},s.prototype.$t=function(t){if(null==t.parent)return!1;for(;null!=t.parent;){if(t.parent.scaling.x!=t.parent.scaling.y||t.parent.scaling.y!=t.parent.scaling.z)return!0;t=t.parent}return!1},s.prototype.Ft=function(){this.Ot.position.subtractToRef(this.Zt.position,this._),i.Vector3.FromArrayToRef(this.Zt.getWorldMatrix().asArray(),8,this.B);var t=i.Vector3.Dot(this._,this.B)/this.B.length(),s=Math.abs(t/this.C);i.Vector3.FromFloatsToRef(s,s,s,this.Ot.scaling)},s.prototype.Ht=function(){var t=Math.atan(this.q.y/this.q.z);this.q.z>=0?this.ti.rotation.x=-t:this.ti.rotation.x=-t-Math.PI;var i=Math.atan(this.q.x/this.q.z);this.q.z>=0?this.ii.rotation.y=i:this.ii.rotation.y=i+Math.PI;var s=Math.atan(this.q.x/this.q.y);this.q.y>=0?this.si.rotation.z=-s:this.si.rotation.z=-s-Math.PI},s.prototype.It=function(t,i,s){var h=this.q;t.rotation.x=0,t.rotation.y=0,t.rotation.z=0,i.rotation.x=0,i.rotation.y=0,i.rotation.z=0,s.rotation.x=0,s.rotation.y=0,s.rotation.z=0,h.x<=0&&h.y>=0&&h.z>=0?(t.rotation.z=3.14,s.rotation.y=3.14):h.x<=0&&h.y>=0&&h.z<=0?(t.rotation.y=3.14,i.rotation.y=3.14,s.rotation.y=3.14):h.x>=0&&h.y>=0&&h.z<=0?(t.rotation.x=3.14,i.rotation.y=3.14):h.x>=0&&h.y<=0&&h.z>=0?(i.rotation.z=3.14,s.rotation.x=3.14):h.x<=0&&h.y<=0&&h.z>=0?(t.rotation.z=3.14,i.rotation.z=3.14,s.rotation.z=3.14):h.x<=0&&h.y<=0&&h.z<=0?(t.rotation.y=3.14,i.rotation.x=3.14,s.rotation.z=3.14):h.x>=0&&h.y<=0&&h.z<=0&&(t.rotation.x=3.14,i.rotation.x=3.14,s.rotation.x=3.14)},s.prototype.switchTo=function(t,i){t.computeWorldMatrix(!0),this.Yt=t,null!=i&&(this.ut=i),this.dt(),this.St(t),this.yt=new u(t,10),this.g=this.xt(t),this.refreshBoundingInfo()},s.prototype.switchCamera=function(t){this.Zt=t},s.prototype.setUndoCount=function(t){this.yt.setCapacity(t)},s.prototype.undo=function(){var t=this.yt.undo();this.Yt.computeWorldMatrix(!0),this.St(this.Yt),this.hi(t),this.ni(t),this.ui(t)},s.prototype.redo=function(){var t=this.yt.redo();this.Yt.computeWorldMatrix(!0),this.St(this.Yt),this.hi(t),this.ni(t),this.ui(t)},s.prototype.detach=function(){this.bt.removeEventListener("pointerdown",this.gt,!1),this.bt.removeEventListener("pointerup",this.qt,!1),this.bt.removeEventListener("pointermove",this._t,!1),this.zt.unregisterBeforeRender(this.Nt),this.removeAllActionListeners(),this.ei()},s.prototype.hide=function(){this.D=!0,this.rt?(this.N="T",this.disableTranslation()):this.ot?(this.N="R",this.disableRotation()):this.ft&&(this.N="S",this.disableScaling()),this.ri()},s.prototype.ri=function(){this.oi.visibility=0,this.fi.visibility=0,this.li.visibility=0},s.prototype.ai=function(){this.oi.visibility=this.R,this.fi.visibility=this.R,this.li.visibility=this.R},s.prototype.show=function(){this.D=!1,this.ai(),"T"==this.N?this.enableTranslation():"R"==this.N?this.enableRotation():"S"==this.N&&this.enableScaling()},s.prototype.isHidden=function(){return this.D},s.prototype.ei=function(){this.Ot.dispose(),this.ci(),this.yt=null},s.prototype.addActionListener=function(t){this.F=t},s.prototype.removeActionListener=function(){this.F=null},s.prototype.addActionStartListener=function(t){this.G=t},s.prototype.removeActionStartListener=function(){this.G=null},s.prototype.addActionEndListener=function(t){this.H=t},s.prototype.removeActionEndListener=function(){this.H=null},s.prototype.removeAllActionListeners=function(){this.F=null,this.G=null,this.H=null},s.prototype.kt=function(t){var i=this;if(t.preventDefault(),this.I=!0,0==t.button){var s=this.zt.getEngine(),h=s.isPointerLock?.5*this.bt.width:this.zt.pointerX,n=s.isPointerLock?.5*this.bt.height:this.zt.pointerY,u=this.zt.pick(h,n,(function(t){if(i.rt){if(t==i.vi||t==i.wi||t==i.Mi||t==i.Jt||t==i.Kt||t==i.Pt||t==i.pi)return!0}else if(i.ot){if(t==i.ti||t==i.ii||t==i.si||t==i.Xi)return!0}else if(i.ft&&(t==i.Yi||t==i.Zi||t==i.bi||t==i.Ut||t==i.Vt||t==i.Wt||t==i.di))return!0;return!1}),!1,this.Zt);if(u.hit){this.Li=u.pickedMesh;var e=this.Li.getChildren();e.length>0?e[0].visibility=this.R:this.Li.visibility=this.R;var r=this.Li.name;"X"==r?this.zi.visibility=1:"Y"==r?this.yi.visibility=1:"Z"==r?this.Ai.visibility=1:"XZ"==r?(this.zi.visibility=1,this.Ai.visibility=1):"ZY"==r?(this.Ai.visibility=1,this.yi.visibility=1):"YX"==r?(this.yi.visibility=1,this.zi.visibility=1):"ALL"==r&&(this.zi.visibility=1,this.yi.visibility=1,this.Ai.visibility=1),this.ji(!0),this.mi=this.Si(this.Li),null!=this.mi?this.xi=this.Oi():this.xi=null,window.setTimeout((function(t,s){return i.Ti(t,s)}),0,this.Zt,this.bt)}}},s.prototype.ji=function(i){this.K=i,i?(this.Ei(),this.Ri==t.ROT&&(this.et=0),this.hi(this.Ri)):this.ui(this.Ri)},s.prototype.isEditing=function(){return this.K},s.prototype.Ti=function(t,i){var s=t,h=i;this.zt.getEngine().isPointerLock||s.detachControl(h)},s.prototype.isPointerOver=function(){return this.J},s.prototype.gi=function(){var t=this,i=this.zt.getEngine(),s=i.isPointerLock?.5*this.bt.width:this.zt.pointerX,h=i.isPointerLock?.5*this.bt.height:this.zt.pointerY,n=this.zt.pick(s,h,(function(i){if(t.rt){if(i==t.vi||i==t.wi||i==t.Mi||i==t.Jt||i==t.Kt||i==t.Pt||i==t.pi)return!0}else if(t.ot){if(i==t.ti||i==t.ii||i==t.si||i==t.Xi)return!0}else if(t.ft&&(i==t.Yi||i==t.Zi||i==t.bi||i==t.Ut||i==t.Vt||i==t.Wt||i==t.di))return!0;return!1}),!1,this.Zt);if(n.hit){if(n.pickedMesh!=this.ki){if(this.J=!0,this.qi(),this.ki=n.pickedMesh,this.ot)this.Ci=this.ki.getChildren()[0].color,this.ki.getChildren()[0].color=this.O;else{var u=this.ki.getChildren();u.length>0?(this._i=u[0].material,u[0].material=this.Bi):(this._i=this.ki.material,this.ki.material=this.Bi)}"X"==this.ki.name?this.oi.color=this.O:"Y"==this.ki.name?this.fi.color=this.O:"Z"==this.ki.name&&(this.li.color=this.O)}}else this.J=!1,null!=this.ki&&(this.Ni(this.ki),this.ki=null)},s.prototype.qi=function(){null!=this.ki&&(this.ki.visibility=0,this.Ni(this.ki))},s.prototype.Ni=function(t){switch(t.name){case"X":this.oi.color=this.A;break;case"Y":this.fi.color=this.j;break;case"Z":this.li.color=this.S}if(this.ot)t.getChildren()[0].color=this.Ci;else{var i=t.getChildren();i.length>0?i[0].material=this._i:t.material=this._i}},s.prototype.Ct=function(t){(this.I=!1,this.K)&&(this.zt.getEngine().isPointerLock||this.Zt.attachControl(!0),this.ji(!1),this.Qi(),null!=this.ki&&(this.Ni(this.ki),this.ki=null),this.yt.add(this.Ri))},s.prototype.Ei=function(){this.rt?this.Ri=t.TRANS:this.ot?this.Ri=t.ROT:this.ft&&(this.Ri=t.SCALE)},s.prototype.ni=function(t){null!=this.F&&this.F(t)},s.prototype.hi=function(t){null!=this.G&&this.G(t)},s.prototype.ui=function(t){null!=this.H&&this.H(t)},s.prototype.Bt=function(t){if(this.I){if(this.K&&null!=this.xi){var i=this.Oi();if(null!=i){if(this.ot)this.Di(this.Yt,this.Li,i,this.xi);else{var s=i.subtract(this.xi);if(0==s.x&&0==s.y&&0==s.z)return;this.rt?this.Fi(s):this.ft&&this.i&&this.Gi(s)}this.xi=i,this.ni(this.Ri)}}}else this.gi()},s.prototype.Si=function(t){var s=t.name;if(this.rt||this.ft){if("XZ"==s)return this.Hi;if("ZY"==s)return this.Ii;if("YX"==s)return this.Ji;if("ALL"==s)return this.Gt;this.Ot.getWorldMatrix().invertToRef(this.k),i.Vector3.TransformCoordinatesToRef(this.Zt.position,this.k,this.q);var h=this.q;if("X"===s)return Math.abs(h.y)>Math.abs(h.z)?this.Hi:this.Ji;if("Z"===s)return Math.abs(h.y)>Math.abs(h.x)?this.Hi:this.Ii;if("Y"===s)return Math.abs(h.z)>Math.abs(h.x)?this.Ji:this.Ii}else{if(!this.ot)return null;this.P=!1,this.Ot.getWorldMatrix().invertToRef(this.k),i.Vector3.TransformCoordinatesToRef(this.Zt.position,this.k,this.q);h=this.q;switch(s){case"X":return Math.abs(h.x)<.2?(this.P=!0,this.Gt):this.Ii;case"Y":return Math.abs(h.y)<.2?(this.P=!0,this.Gt):this.Hi;case"Z":return Math.abs(h.z)<.2?(this.P=!0,this.Gt):this.Ji;default:return this.Gt}}},s.prototype.Fi=function(t){null!=this.Yt.parent&&this.$t(this.Yt)?this.St(this.Ot):this.St(this.Yt);var s=this.Li.name;this.U.x=0,this.U.y=0,this.U.z=0,"X"!=s&&"XZ"!=s&&"YX"!=s&&"ALL"!=s||(this.i?this.U.x=i.Vector3.Dot(t,this.st)/this.st.length():this.U.x=t.x),"Y"!=s&&"ZY"!=s&&"YX"!=s&&"ALL"!=s||(this.i?this.U.y=i.Vector3.Dot(t,this.ht)/this.ht.length():this.U.y=t.y),"Z"!=s&&"XZ"!=s&&"ZY"!=s&&"ALL"!=s||(this.i?this.U.z=i.Vector3.Dot(t,this.nt)/this.nt.length():this.U.z=t.z),this.Ki(this.Yt,this.U,this.i),this.Pi&&(this.Yt.position.x=Math.max(this.Yt.position.x,this.Pi.x),this.Yt.position.y=Math.max(this.Yt.position.y,this.Pi.y),this.Yt.position.z=Math.max(this.Yt.position.z,this.Pi.z)),this.Ui&&(this.Yt.position.x=Math.min(this.Yt.position.x,this.Ui.x),this.Yt.position.y=Math.min(this.Yt.position.y,this.Ui.y),this.Yt.position.z=Math.min(this.Yt.position.z,this.Ui.z)),this.Yt.computeWorldMatrix(!0)},s.prototype.Ki=function(t,s,h){if(this.h){var n=!1;if(this.V.addInPlace(s),Math.abs(this.V.x)>this.ct.x&&(this.V.x>0?s.x=this.ct.x:s.x=-this.ct.x,n=!0),Math.abs(this.V.y)>this.ct.y&&(this.V.y>0?s.y=this.ct.y:s.y=-this.ct.y,n=!0),Math.abs(this.V.z)>this.ct.z&&(this.V.z>0?s.z=this.ct.z:s.z=-this.ct.z,n=!0),!n)return;Math.abs(s.x)!==this.ct.x&&(s.x=0),Math.abs(s.y)!==this.ct.y&&(s.y=0),Math.abs(s.z)!==this.ct.z&&(s.z=0),i.Vector3.FromFloatsToRef(0,0,0,this.V),n=!1}h?(this.st.normalizeToRef(this.vt),this.ht.normalizeToRef(this.wt),this.nt.normalizeToRef(this.Mt),this.Yt.translate(this.vt,s.x,i.Space.WORLD),this.Yt.translate(this.wt,s.y,i.Space.WORLD),this.Yt.translate(this.Mt,s.z,i.Space.WORLD)):null==this.Yt.parent?this.Yt.position.addInPlace(s):this.Yt.setAbsolutePosition(s.addInPlace(this.Yt.absolutePosition))},s.prototype.Gi=function(t){this.St(this.Yt),this.it.x=0,this.it.y=0,this.it.z=0;var s=this.Li.name;"X"!=s&&"XZ"!=s&&"YX"!=s||(this.it.x=i.Vector3.Dot(t,this.st)/this.st.length(),this.Yt.scaling.x<0&&(this.it.x=-this.it.x)),"Y"!=s&&"ZY"!=s&&"YX"!=s||(this.it.y=i.Vector3.Dot(t,this.ht)/this.ht.length(),this.Yt.scaling.y<0&&(this.it.y=-this.it.y)),"Z"!=s&&"XZ"!=s&&"ZY"!=s||(this.it.z=i.Vector3.Dot(t,this.nt)/this.nt.length(),this.Yt.scaling.z<0&&(this.it.z=-this.it.z));var h=this.At;if(this.it.x=this.it.x/h.x,this.it.y=this.it.y/h.y,this.it.z=this.it.z/h.z,"ALL"==s){var n=i.Vector3.Dot(t,this.Zt.upVector);n/=Math.max(h.x,h.y,h.z),this.it.copyFromFloats(n,n,n)}else{var u=!1;if("XZ"==s?(u=!0,Math.abs(this.it.x)>Math.abs(this.it.z)?this.it.z=this.it.x:this.it.x=this.it.z):"ZY"==s?(u=!0,Math.abs(this.it.z)>Math.abs(this.it.y)?this.it.y=this.it.z:this.it.z=this.it.y):"YX"==s&&(u=!0,Math.abs(this.it.y)>Math.abs(this.it.x)?this.it.x=this.it.y:this.it.y=this.it.x),u){this.Ot.position.subtractToRef(this.Zt.position,this._);n=i.Vector3.Dot(t,this._);this.it.x=Math.abs(this.it.x),this.it.y=Math.abs(this.it.y),this.it.z=Math.abs(this.it.z),n>0?(this.Yt.scaling.x>0&&(this.it.x=-this.it.x),this.Yt.scaling.y>0&&(this.it.y=-this.it.y),this.Yt.scaling.z>0&&(this.it.z=-this.it.z)):(this.Yt.scaling.x<0&&(this.it.x=-this.it.x),this.Yt.scaling.y<0&&(this.it.y=-this.it.y),this.Yt.scaling.z<0&&(this.it.z=-this.it.z))}}this.Vi(this.Yt,this.it),this.Wi&&(this.Yt.scaling.x=Math.max(this.Yt.scaling.x,this.Wi.x),this.Yt.scaling.y=Math.max(this.Yt.scaling.y,this.Wi.y),this.Yt.scaling.z=Math.max(this.Yt.scaling.z,this.Wi.z)),this.$i&&(this.Yt.scaling.x=Math.min(this.Yt.scaling.x,this.$i.x),this.Yt.scaling.y=Math.min(this.Yt.scaling.y,this.$i.y),this.Yt.scaling.z=Math.min(this.Yt.scaling.z,this.$i.z))},s.prototype.Vi=function(t,s){if(this.W){var h=!1;if(this.$.addInPlace(s),Math.abs(this.$.x)>this.tt&&(s.x>0?s.x=this.tt:s.x=-this.tt,h=!0),Math.abs(this.$.y)>this.tt&&(s.y>0?s.y=this.tt:s.y=-this.tt,h=!0),Math.abs(this.$.z)>this.tt&&(s.z>0?s.z=this.tt:s.z=-this.tt,h=!0),!h)return;Math.abs(s.x)!==this.tt&&0!==s.x&&(s.x=0),Math.abs(s.y)!==this.tt&&0!==s.y&&(s.y=0),Math.abs(s.z)!==this.tt&&0!==s.z&&(s.z=0),i.Vector3.FromFloatsToRef(0,0,0,this.$),h=!1}t.scaling.addInPlace(s)},s.prototype.St=function(t){var s=t.getWorldMatrix();i.Vector3.FromArrayToRef(s.m,0,this.st),i.Vector3.FromArrayToRef(s.m,4,this.ht),i.Vector3.FromArrayToRef(s.m,8,this.nt)},s.prototype.jt=function(t){if(t instanceof i.AbstractMesh){var s=t.getBoundingInfo().boundingBox,h=s.maximum.subtract(s.minimum);return 0==h.x&&(h.x=1),0==h.y&&(h.y=1),0==h.z&&(h.z=1),h}return new i.Vector3(1,1,1)},s.prototype.refreshBoundingInfo=function(){this.At=this.jt(this.Yt)},s.prototype.Di=function(t,s,h,n){this.i&&null!=this.Yt.parent&&this.$t(t)?this.St(this.Ot):this.St(t);var u,e=0;s==this.ti?u=this.i?this.st:i.Axis.X:s==this.ii?u=this.i?this.ht:i.Axis.Y:s==this.si&&(u=this.i?this.nt:i.Axis.Z),this.Ot.position.subtractToRef(this.Zt.position,this._),this.P?(e=this.ts(n,h,this.Zt.position,this._,u),this.zt.useRightHandedSystem&&(e=-e)):e=this.ss(n,h,t.getAbsolutePivotPoint(),this._),this.g&&(e=-e),this.u&&(this.et+=e,e=0,Math.abs(this.et)>=this.v&&(e=this.et>0?this.v:-this.v,this.et=0)),0!==e&&(this._.normalize(),s==this.Xi?t.rotate(this._,-e,i.Space.WORLD):(i.Vector3.Dot(u,this._)>=0&&(e=-e),t.rotate(u,e,i.Space.WORLD)),this.ut&&(t.rotation=t.rotationQuaternion.toEulerAngles(),t.rotationQuaternion=null),this.i&&(this.g&&(e=-e),null!=this.Yt.parent&&this.$t(t)&&(s==this.Xi?this.Ot.rotate(this._,-e,i.Space.WORLD):this.Ot.rotate(u,e,i.Space.WORLD))))},s.prototype.Oi=function(){var t=this,i=this.zt.getEngine(),s=i.isPointerLock?.5*this.bt.width:this.zt.pointerX,h=i.isPointerLock?.5*this.bt.height:this.zt.pointerY,n=this.zt.pick(s,h,(function(i){return i==t.mi}),null,this.Zt);return n.hit?n.pickedPoint:null},s.prototype.Qi=function(){this.zi.visibility=0,this.yi.visibility=0,this.Ai.visibility=0},s.prototype.getRotationQuaternion=function(){return this.Ot.rotationQuaternion},s.prototype.getPosition=function(){return this.Ot.position},s.prototype.isTranslationEnabled=function(){return this.rt},s.prototype.enableTranslation=function(){this.D||(null==this.vi&&(this.hs(),this.ns.parent=this.Ot),this.qi(),this.rt||(this.us(this.es,this.R),this.rt=!0,this.disableRotation(),this.disableScaling()))},s.prototype.disableTranslation=function(){this.rt&&(this.us(this.es,0),this.rt=!1)},s.prototype.isRotationEnabled=function(){return this.ot},s.prototype.returnEuler=function(t){this.ut=t},s.prototype.enableRotation=function(){this.D||(null==this.rs&&(this.os(),this.rs.parent=this.Ot),this.qi(),this.ot||(this.us(this.fs,this.R),this.ot=!0,this.disableTranslation(),this.disableScaling()))},s.prototype.disableRotation=function(){this.ot&&(this.us(this.fs,0),this.ot=!1)},s.prototype.isScalingEnabled=function(){return this.ft},s.prototype.enableScaling=function(){this.D||(null==this.Yi&&(this.ls(),this.cs.parent=this.Ot),this.qi(),this.ft||(this.us(this.vs,this.R),this.ft=!0,this.disableTranslation(),this.disableRotation()))},s.prototype.disableScaling=function(){this.ft&&(this.us(this.vs,0),this.ft=!1)},s.prototype.setScaleBounds=function(t,i){this.Wi=t||null,this.$i=i||null,null!=this.Wi&&(0==this.Wi.x&&(this.Wi.x=1e-8),0==this.Wi.y&&(this.Wi.y=1e-8),0==this.Wi.z&&(this.Wi.z=1e-8))},s.prototype.removeScaleBounds=function(){this.Wi=null,this.$i=null},s.prototype.setTransBounds=function(t,i){this.Pi=t||null,this.Ui=i||null},s.prototype.removeTransBounds=function(){this.Pi=null,this.Ui=null},s.prototype.setRotBounds=function(t,i){this.ws=t||null,this.Ms=i||null},s.prototype.removeRotBounds=function(){this.ws=null,this.Ms=null},s.prototype.Et=function(){var t=new i.Mesh("",this.zt);this.zi=i.MeshBuilder.CreateLines("",{points:[new i.Vector3(-100,0,0),new i.Vector3(100,0,0)]},this.zt),this.yi=i.MeshBuilder.CreateLines("",{points:[new i.Vector3(0,-100,0),new i.Vector3(0,100,0)]},this.zt),this.Ai=i.MeshBuilder.CreateLines("",{points:[new i.Vector3(0,0,-100),new i.Vector3(0,0,100)]},this.zt),this.zi.isPickable=!1,this.yi.isPickable=!1,this.Ai.isPickable=!1,this.zi.parent=t,this.yi.parent=t,this.Ai.parent=t,this.zi.color=this.A,this.yi.color=this.j,this.Ai.color=this.S,this.Qi();var s=this.M*this.p*.75;return this.oi=i.MeshBuilder.CreateLines("",{points:[new i.Vector3(0,0,0),new i.Vector3(s,0,0)]},this.zt),this.fi=i.MeshBuilder.CreateLines("",{points:[new i.Vector3(0,0,0),new i.Vector3(0,s,0)]},this.zt),this.li=i.MeshBuilder.CreateLines("",{points:[new i.Vector3(0,0,0),new i.Vector3(0,0,s)]},this.zt),this.oi.isPickable=!1,this.fi.isPickable=!1,this.li.isPickable=!1,this.oi.parent=t,this.fi.parent=t,this.li.parent=t,this.oi.color=this.A,this.fi.color=this.j,this.li.color=this.S,this.oi.renderingGroupId=1,this.fi.renderingGroupId=1,this.li.renderingGroupId=1,t},s.prototype.Rt=function(){this.Gt=i.MeshBuilder.CreatePlane("",{size:5},this.zt),this.Hi=i.MeshBuilder.CreatePlane("",{size:5},this.zt),this.Ii=i.MeshBuilder.CreatePlane("",{size:5},this.zt),this.Ji=i.MeshBuilder.CreatePlane("",{size:5},this.zt),this.Gt.isPickable=!1,this.Hi.isPickable=!1,this.Ii.isPickable=!1,this.Ji.isPickable=!1,this.Gt.visibility=0,this.Hi.visibility=0,this.Ii.visibility=0,this.Ji.visibility=0,this.Gt.renderingGroupId=1,this.Hi.renderingGroupId=1,this.Ii.renderingGroupId=1,this.Ji.renderingGroupId=1,this.Gt.lookAt(this.Zt.position),this.Hi.rotate(i.Axis.X,1.57),this.Ii.rotate(i.Axis.Y,1.57);var t=new i.Mesh("",this.zt);return this.Gt.parent=t,this.Hi.parent=t,this.Ii.parent=t,this.Ji.parent=t,t},s.prototype.hs=function(){var t=2*this.L*this.p,s=this.M*this.p;this.ns=new i.Mesh("",this.zt),this.ps(t,s,this.ns,this.zt),this.Xs(t,s,this.zt)},s.prototype.ps=function(t,s,h,n){var u=this.Ys(t/2,s);u.name="X";var e=u.clone("Y"),r=u.clone("Z"),o=2*t,f=i.MeshBuilder.CreatePlane("XZ",{size:o},n),l=i.MeshBuilder.CreatePlane("ZY",{size:o},n),a=i.MeshBuilder.CreatePlane("YX",{size:o},n);f.rotation.x=1.57,l.rotation.y=-1.57,f.position.x=2*t,f.position.z=2*t,l.position.z=2*t,l.position.y=2*t,a.position.y=2*t,a.position.x=2*t,f.bakeCurrentTransformIntoVertices(),l.bakeCurrentTransformIntoVertices(),a.bakeCurrentTransformIntoVertices();var c=i.MeshBuilder.CreateBox("ALL",{size:2*t},n);u.parent=h,e.parent=h,r.parent=h,f.parent=h,l.parent=h,a.parent=h,c.parent=h,u.rotation.y=1.57,e.rotation.x-=1.57,this.vi=u,this.wi=e,this.Mi=r,this.Jt=f,this.Kt=l,this.Pt=a,this.pi=c,this.Zs=[u,e,r,f,l,a,c],this.us(this.Zs,0),this.bs(this.Zs)},s.prototype.Xs=function(t,s,h){var n=s/5,u=i.MeshBuilder.CreateCylinder("",{height:n,diameterTop:0,diameterBottom:t,tessellation:6,subdivisions:1},h),e=u.clone(""),r=u.clone(""),o=2*t,f=i.MeshBuilder.CreatePlane("XZ",{size:o},h),l=i.MeshBuilder.CreatePlane("ZY",{size:o},h),a=i.MeshBuilder.CreatePlane("YX",{size:o},h),c=i.MeshBuilder.CreateBox("ALL",{size:t},h);u.rotation.x=1.57,e.rotation.x=1.57,r.rotation.x=1.57,f.rotation.x=1.57,l.rotation.y=1.57,f.position.x=o,f.position.z=o,l.position.z=o,l.position.y=o,a.position.y=o,a.position.x=o,u.parent=this.vi,e.parent=this.wi,r.parent=this.Mi,f.parent=this.Jt,l.parent=this.Kt,a.parent=this.Pt,c.parent=this.pi,u.position.z=s-n/2,e.position.z=s-n/2,r.position.z=s-n/2,u.material=this.ds,e.material=this.Ls,r.material=this.zs,f.material=this.Ls,l.material=this.ds,a.material=this.zs,c.material=this.ys,this.As=u,this.js=e,this.Ss=r,this.xs=f,this.Os=l,this.Ts=a,this.Es=c,this.es=[u,e,r,f,l,a,c],this.bs(this.es),this.Rs(this.es)},s.prototype.setRotGuideFull=function(t){this.lt=t?360:180,null!=this.rs&&(this.rs.dispose(),this.Xi.dispose(),this.rs=null,this.enableRotation())},s.prototype.os=function(){var t=this.M*this.p*2;this.rs=new i.Mesh("",this.zt),this.gs(t,this.rs),this.ks(t)},s.prototype.gs=function(t,i){var s=this.qs(t/2,this.lt),h=this.qs(t/2,this.lt),n=this.qs(t/2,this.lt),u=this.qs(t/1.75,360);s.name="X",h.name="Y",n.name="Z",u.name="ALL",s.rotation.z=1.57,n.rotation.x=-1.57,s.bakeCurrentTransformIntoVertices(),n.bakeCurrentTransformIntoVertices(),u.rotation.x=1.57,s.parent=i,h.parent=i,n.parent=i,u.parent=this.Gt,this.ti=s,this.ii=h,this.si=n,this.Xi=u,this.Cs=[s,h,n,u],this.us(this.Cs,0),this.bs(this.Cs)},s.prototype.ks=function(t){var s=this._s(t/2,this.lt,!1),h=s.clone(""),n=s.clone(""),u=this._s(t/1.75,360,!1),e=this._s(t/2,360,!1);s.parent=this.ti,h.parent=this.ii,n.parent=this.si,s.rotation.z=1.57,n.rotation.x=-1.57,u.parent=this.Xi,e.parent=this.Xi,s.color=this.A,h.color=this.j,n.color=this.S,u.color=this.T,e.color=i.Color3.Gray(),this.Bs=s,this.Ns=h,this.Qs=n,this.Ds=u,this.Fs=e,this.fs=[s,h,n,u,e],this.bs(this.fs),this.Rs(this.fs)},s.prototype.us=function(t,i){t.map((function(t){return t.visibility=i}))},s.prototype.bs=function(t){t.map((function(t){t.isPickable=!1}))},s.prototype.Rs=function(t){t.map((function(t){return t.renderingGroupId=2}))},s.prototype.Ys=function(t,s){var h=[new i.Vector3(t,t,0),new i.Vector3(-t,t,0),new i.Vector3(-t,-t,0),new i.Vector3(t,-t,0),new i.Vector3(t,t,0)],n=[new i.Vector3(0,0,0),new i.Vector3(0,0,s)];return i.MeshBuilder.ExtrudeShape("",{shape:h,path:n,scale:1,rotation:0,cap:2},this.zt)},s.prototype._s=function(t,s,h){null===s&&(s=360);for(var n,u,e=[],r=3.14/180,o=0,f=0;f<=s;f+=5)n=t*Math.cos(f*r),u=90==f?t:270==f?-t:t*Math.sin(f*r),e[o]=new i.Vector3(n,0,u),o++;if(h){t-=.04;for(f=0;f<=s;f+=5)n=t*Math.cos(f*r),u=90==f?t:270==f?-t:t*Math.sin(f*r),e[o]=new i.Vector3(n,0,u),o++}return i.MeshBuilder.CreateLines("",{points:e},this.zt)},s.prototype.qs=function(t,s){null===s&&(s=360);for(var h,n,u=[],e=3.14/180,r=0,o=0;o<=s;o+=30)h=t*Math.cos(o*e),n=90==o?t:270==o?-t:t*Math.sin(o*e),u[r]=new i.Vector3(h,0,n),r++;return i.MeshBuilder.CreateTube("",{path:u,radius:this.L*this.p*2,tessellation:3,cap:i.Mesh.NO_CAP},this.zt)},s.prototype.ls=function(){var t=2*this.L*this.p,s=this.M*this.p;this.cs=new i.Mesh("",this.zt),this.Gs(t,s,this.cs),this.Hs(t,s)},s.prototype.Gs=function(t,s,h){var n=this.Ys(t/2,s);n.name="X";var u=n.clone("Y"),e=n.clone("Z"),r=i.MeshBuilder.CreatePlane("XZ",{size:2*t},this.zt),o=i.MeshBuilder.CreatePlane("ZY",{size:2*t},this.zt),f=i.MeshBuilder.CreatePlane("YX",{size:2*t},this.zt);r.rotation.x=1.57,o.rotation.y=-1.57,r.position.x=2*t,r.position.z=2*t,o.position.z=2*t,o.position.y=2*t,f.position.y=2*t,f.position.x=2*t,r.bakeCurrentTransformIntoVertices(),o.bakeCurrentTransformIntoVertices(),f.bakeCurrentTransformIntoVertices();var l=i.MeshBuilder.CreateBox("ALL",{size:2*t},this.zt);n.parent=h,u.parent=h,e.parent=h,l.parent=h,r.parent=h,o.parent=h,f.parent=h,n.rotation.y=1.57,u.rotation.x-=1.57,this.Yi=n,this.Zi=u,this.bi=e,this.Ut=r,this.Vt=o,this.Wt=f,this.di=l,this.Is=[n,u,e,r,o,f,l],this.us(this.Is,0),this.bs(this.Is)},s.prototype.Hs=function(t,s){var h=i.MeshBuilder.CreateBox("",{size:t},this.zt),n=h.clone(""),u=h.clone(""),e=2*t,r=i.MeshBuilder.CreatePlane("XZ",{size:e},this.zt),o=i.MeshBuilder.CreatePlane("ZY",{size:e},this.zt),f=i.MeshBuilder.CreatePlane("YX",{size:e},this.zt),l=i.MeshBuilder.CreateBox("ALL",{size:t},this.zt);r.rotation.x=1.57,o.rotation.y=-1.57,r.position.x=e,r.position.z=e,o.position.z=e,o.position.y=e,f.position.y=e,f.position.x=e,h.parent=this.Yi,n.parent=this.Zi,u.parent=this.bi,r.parent=this.Ut,o.parent=this.Vt,f.parent=this.Wt,l.parent=this.di,h.position.z=s-t/2,n.position.z=s-t/2,u.position.z=s-t/2,h.material=this.ds,n.material=this.Ls,u.material=this.zs,r.material=this.Ls,o.material=this.ds,f.material=this.zs,l.material=this.ys,this.Js=h,this.Ks=n,this.Ps=u,this.Us=r,this.Vs=o,this.Ws=f,this.$s=l,this.vs=[h,n,u,r,o,f,l],this.bs(this.vs),this.Rs(this.vs)},s.prototype.setVisibility=function(t){this.R=t},s.prototype.setLocal=function(t){this.i!=t&&(this.i=t,t||(this.Ot.rotationQuaternion=i.Quaternion.Identity()))},s.prototype.isLocal=function(){return this.i},s.prototype.setTransSnap=function(t){this.h=t},s.prototype.isTransSnap=function(){return this.h},s.prototype.setRotSnap=function(t){this.u=t},s.prototype.isRotSnap=function(){return this.u},s.prototype.setScaleSnap=function(t){this.W=t},s.prototype.isScaleSnap=function(){return this.W},s.prototype.setTransSnapValue=function(t){this.ct.copyFromFloats(t,t,t),this.l=t},s.prototype.getTransSnapValue=function(){return this.l},s.prototype.setRotSnapValue=function(t){this.v=t},s.prototype.getRotSnapValue=function(){return this.v},s.prototype.setScaleSnapValue=function(t){this.tt=t},s.prototype.getScaleSnapValue=function(){return this.tt},s.prototype.ts=function(t,s,h,n,u){var e=i.Vector3.Dot(n,u);u.scaleToRef(e,this.vt),h.addToRef(this.vt,this.wt);var r=this.wt;this.Zt.getWorldMatrix().invertToRef(this.Xt),i.Vector3.TransformCoordinatesToRef(this.wt,this.Xt,this.wt);var o=0;r.x>=0&&r.y>=0?o=1:r.x<=0&&r.y>=0?o=2:r.x<=0&&r.y<=0?o=3:r.x>=0&&r.y<=0&&(o=4),i.Vector3.TransformCoordinatesToRef(t,this.Xt,this.vt),i.Vector3.TransformCoordinatesToRef(s,this.Xt,this.wt),this.wt.subtractInPlace(this.vt);var f=this.wt,l=f.length(),a="";f.x>=0&&f.y>=0?a=f.x>=f.y?"r":"u":f.x<=0&&f.y>=0?a=-f.x>=f.y?"l":"u":f.x<=0&&f.y<=0?a=-f.x>=-f.y?"l":"d":f.x>=0&&f.y<=0&&(a=f.x>=-f.y?"r":"d");var c=0;return"d"==a?c=1==o||4==o?1:-1:"u"==a?c=1==o||4==o?-1:1:"r"==a?c=2==o||1==o?1:-1:"l"==a&&(c=2==o||1==o?-1:1),c*l},s.prototype.ss=function(t,s,h,n){t.subtractToRef(h,this.vt),s.subtractToRef(h,this.wt),i.Vector3.CrossToRef(this.vt,this.wt,this.Mt);var u=Math.asin(this.Mt.length()/(this.vt.length()*this.wt.length()));return i.Vector3.Dot(this.Mt,n)>0&&(u*=-1),u},s.th=function(t,s){var h=new i.StandardMaterial("",s);return h.emissiveColor=t,h.diffuseColor=i.Color3.Black(),h.specularColor=i.Color3.Black(),h.backFaceCulling=!1,h},s.prototype.Tt=function(t){this.ds=s.th(this.A,t),this.Ls=s.th(this.j,t),this.zs=s.th(this.S,t),this.Bi=s.th(this.O,t),this.ys=s.th(this.T,t)},s.prototype.ci=function(){this.ds.dispose(),this.Ls.dispose(),this.zs.dispose(),this.Bi.dispose(),this.ys.dispose()},s}(),u=function(){function t(t,i){this.lastMax=10,this.acts=new Array,this.last=-1,this.current=-1,this.mesh=t,this.lastMax=i-1,this.add()}return t.prototype.setCapacity=function(t){0!=t?(this.lastMax=t-1,this.last=-1,this.current=-1,this.acts=new Array,this.add()):console.error("capacity should be more than zero")},t.prototype.add=function(t){void 0===t&&(t=null);var i=new e(this.mesh,t);this.current<this.last&&(this.acts.splice(this.current+1),this.last=this.current),this.last==this.lastMax?(this.acts.shift(),this.acts.push(i)):(this.acts.push(i),this.last++,this.current++)},t.prototype.undo=function(){if(this.current>0){var t=this.acts[this.current].getActionType();return this.current--,this.acts[this.current].perform(this.mesh),t}},t.prototype.redo=function(){if(this.current<this.last)return this.current++,this.acts[this.current].perform(this.mesh),this.acts[this.current].getActionType()},t}(),e=function(){function t(t,i){this.ih=t.position.clone(),null==t.rotationQuaternion?(this.sh=null,this.hh=t.rotation.clone()):(this.sh=t.rotationQuaternion.clone(),this.hh=null),this.nh=t.scaling.clone(),this.uh=i}return t.prototype.getActionType=function(){return this.uh},t.prototype.perform=function(t){t.position.copyFrom(this.ih),null==t.rotationQuaternion?null!=this.hh?t.rotation.copyFrom(this.hh):t.rotation.copyFrom(this.sh.toEulerAngles()):null!=this.sh?t.rotationQuaternion.copyFrom(this.sh):t.rotationQuaternion.copyFrom(i.Quaternion.RotationYawPitchRoll(this.hh.y,this.hh.x,this.hh.z)),t.scaling.copyFrom(this.nh)},t}()})(),n})()));
2154
3
  //# sourceMappingURL=EditControl.max.js.map