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.
- package/LICENSE +201 -201
- package/README.md +453 -436
- package/dist/EditControl.d.ts +10 -0
- package/dist/EditControl.js +1 -1
- package/dist/EditControl.js.map +1 -1
- package/dist/EditControl.max.js +2 -2153
- package/dist/EditControl.max.js.LICENSE.txt +9 -0
- package/dist/EditControl.max.js.map +1 -1
- package/package.json +38 -37
- package/src/EditControl.ts +54 -32
package/package.json
CHANGED
|
@@ -1,37 +1,38 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "babylonjs-editcontrol",
|
|
3
|
-
"version": "3.
|
|
4
|
-
"description": "A transform control for Babylonjs mesh",
|
|
5
|
-
"repository": {
|
|
6
|
-
"type": "git",
|
|
7
|
-
"url": "git://github.com/ssatguru/BabylonJS-EditControl.git"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"babylonjs",
|
|
11
|
-
"transform control",
|
|
12
|
-
"widget",
|
|
13
|
-
"gizmo"
|
|
14
|
-
],
|
|
15
|
-
"author": "satguru <ssatguru@gmail.com>",
|
|
16
|
-
"license": "Apache-2.0",
|
|
17
|
-
"contributors": [],
|
|
18
|
-
"main": "dist/EditControl.js",
|
|
19
|
-
"types": "dist/EditControl.d.ts",
|
|
20
|
-
"dependencies": {},
|
|
21
|
-
"devDependencies": {
|
|
22
|
-
"babylonjs": "^
|
|
23
|
-
"babylonjs-gui": "^
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"webpack
|
|
30
|
-
"webpack-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"build": "webpack",
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "babylonjs-editcontrol",
|
|
3
|
+
"version": "3.3.0",
|
|
4
|
+
"description": "A transform control for Babylonjs mesh",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git://github.com/ssatguru/BabylonJS-EditControl.git"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"babylonjs",
|
|
11
|
+
"transform control",
|
|
12
|
+
"widget",
|
|
13
|
+
"gizmo"
|
|
14
|
+
],
|
|
15
|
+
"author": "satguru <ssatguru@gmail.com>",
|
|
16
|
+
"license": "Apache-2.0",
|
|
17
|
+
"contributors": [],
|
|
18
|
+
"main": "dist/EditControl.js",
|
|
19
|
+
"types": "dist/EditControl.d.ts",
|
|
20
|
+
"dependencies": {},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"babylonjs": "^5.41.0",
|
|
23
|
+
"babylonjs-gui": "^5.41.0",
|
|
24
|
+
"babylonjs-inspector": "^5.41.0",
|
|
25
|
+
"pepjs": "^0.4.3",
|
|
26
|
+
"terser-webpack-plugin": "^5.3.6",
|
|
27
|
+
"ts-loader": "^9.4.2",
|
|
28
|
+
"typescript": "^4.9.4",
|
|
29
|
+
"webpack": "^5.75.0",
|
|
30
|
+
"webpack-cli": "^5.0.1",
|
|
31
|
+
"webpack-dev-server": "^4.11.1"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build-prod": "webpack --mode production",
|
|
35
|
+
"build": "webpack",
|
|
36
|
+
"start": "webpack-dev-server --open /tst/test.html"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/EditControl.ts
CHANGED
|
@@ -18,7 +18,9 @@ import {
|
|
|
18
18
|
StandardMaterial,
|
|
19
19
|
Vector3,
|
|
20
20
|
TransformNode,
|
|
21
|
-
Engine
|
|
21
|
+
Engine,
|
|
22
|
+
DeepImmutableObject,
|
|
23
|
+
UtilityLayerRenderer
|
|
22
24
|
}
|
|
23
25
|
from 'babylonjs';
|
|
24
26
|
|
|
@@ -49,6 +51,7 @@ export class EditControl {
|
|
|
49
51
|
|
|
50
52
|
private _canvas: HTMLCanvasElement;
|
|
51
53
|
private _scene: Scene;
|
|
54
|
+
private _utilLayer: UtilityLayerRenderer;
|
|
52
55
|
private _mainCamera: Camera;
|
|
53
56
|
//root of the edit control
|
|
54
57
|
private _ecRoot: Mesh;
|
|
@@ -77,6 +80,7 @@ export class EditControl {
|
|
|
77
80
|
private _pointerdown: EventListener;
|
|
78
81
|
private _pointerup: EventListener;
|
|
79
82
|
private _pointermove: EventListener;
|
|
83
|
+
|
|
80
84
|
//axes visibility
|
|
81
85
|
private _visibility: number = 0.75;
|
|
82
86
|
|
|
@@ -104,7 +108,11 @@ export class EditControl {
|
|
|
104
108
|
this._pickWidth = pickWidth;
|
|
105
109
|
}
|
|
106
110
|
|
|
107
|
-
|
|
111
|
+
|
|
112
|
+
this._utilLayer = UtilityLayerRenderer.DefaultUtilityLayer;
|
|
113
|
+
this._utilLayer.onlyCheckPointerDownEvents = false;
|
|
114
|
+
this._scene = this._utilLayer.utilityLayerScene;
|
|
115
|
+
|
|
108
116
|
this._actHist = new ActHist(mesh, 10);
|
|
109
117
|
|
|
110
118
|
mesh.computeWorldMatrix(true);
|
|
@@ -262,7 +270,7 @@ export class EditControl {
|
|
|
262
270
|
private _cameraNormal: Vector3 = new Vector3(0, 0, 0);
|
|
263
271
|
private _setECScale() {
|
|
264
272
|
this._ecRoot.position.subtractToRef(this._mainCamera.position, this._cameraTOec);
|
|
265
|
-
Vector3.
|
|
273
|
+
Vector3.FromArrayToRef(<DeepImmutableObject<Float32Array>>this._mainCamera.getWorldMatrix().asArray(), 8, this._cameraNormal);
|
|
266
274
|
|
|
267
275
|
//get distance of edit control from the camera plane
|
|
268
276
|
//project "camera to edit control" vector onto the camera normal
|
|
@@ -501,7 +509,7 @@ export class EditControl {
|
|
|
501
509
|
if ((mesh == this._sX) || (mesh == this._sY) || (mesh == this._sZ) || (mesh == this._sXZ) || (mesh == this._sZY) || (mesh == this._sYX) || (mesh == this._sAll)) return true;
|
|
502
510
|
}
|
|
503
511
|
return false;
|
|
504
|
-
},
|
|
512
|
+
}, false, this._mainCamera);
|
|
505
513
|
|
|
506
514
|
if (pickResult.hit) {
|
|
507
515
|
//this.setAxesVisiblity(0);
|
|
@@ -594,7 +602,7 @@ export class EditControl {
|
|
|
594
602
|
if ((mesh == this._sX) || (mesh == this._sY) || (mesh == this._sZ) || (mesh == this._sXZ) || (mesh == this._sZY) || (mesh == this._sYX) || (mesh == this._sAll)) return true;
|
|
595
603
|
}
|
|
596
604
|
return false;
|
|
597
|
-
},
|
|
605
|
+
}, false, this._mainCamera);
|
|
598
606
|
if (pickResult.hit) {
|
|
599
607
|
//if we are still over the same axis mesh then don't do anything
|
|
600
608
|
if (<Mesh>pickResult.pickedMesh != this._prevOverMesh) {
|
|
@@ -672,7 +680,7 @@ export class EditControl {
|
|
|
672
680
|
if (this._editing) {
|
|
673
681
|
let engine: Engine = this._scene.getEngine();
|
|
674
682
|
if (!engine.isPointerLock) {
|
|
675
|
-
this._mainCamera.attachControl(
|
|
683
|
+
this._mainCamera.attachControl(true);
|
|
676
684
|
}
|
|
677
685
|
this._setEditing(false);
|
|
678
686
|
//this.setAxesVisiblity(1);
|
|
@@ -1035,9 +1043,9 @@ export class EditControl {
|
|
|
1035
1043
|
*/
|
|
1036
1044
|
private _setLocalAxes(mesh: Node) {
|
|
1037
1045
|
let meshMatrix: Matrix = mesh.getWorldMatrix();
|
|
1038
|
-
Vector3.
|
|
1039
|
-
Vector3.
|
|
1040
|
-
Vector3.
|
|
1046
|
+
Vector3.FromArrayToRef(<DeepImmutableObject<Float32Array>>meshMatrix.m, 0, this._localX);
|
|
1047
|
+
Vector3.FromArrayToRef(<DeepImmutableObject<Float32Array>>meshMatrix.m, 4, this._localY);
|
|
1048
|
+
Vector3.FromArrayToRef(<DeepImmutableObject<Float32Array>>meshMatrix.m, 8, this._localZ);
|
|
1041
1049
|
}
|
|
1042
1050
|
|
|
1043
1051
|
|
|
@@ -1357,9 +1365,9 @@ export class EditControl {
|
|
|
1357
1365
|
let guideAxes: Mesh = new Mesh("", this._scene);
|
|
1358
1366
|
|
|
1359
1367
|
//the big axes, shown when an axis is selected
|
|
1360
|
-
this._bXaxis =
|
|
1361
|
-
this._bYaxis =
|
|
1362
|
-
this._bZaxis =
|
|
1368
|
+
this._bXaxis = MeshBuilder.CreateLines("", { points: [new Vector3(-100, 0, 0), new Vector3(100, 0, 0)] }, this._scene);
|
|
1369
|
+
this._bYaxis = MeshBuilder.CreateLines("", { points: [new Vector3(0, -100, 0), new Vector3(0, 100, 0)] }, this._scene);
|
|
1370
|
+
this._bZaxis = MeshBuilder.CreateLines("", { points: [new Vector3(0, 0, -100), new Vector3(0, 0, 100)] }, this._scene);
|
|
1363
1371
|
|
|
1364
1372
|
//lines are now pickable too
|
|
1365
1373
|
this._bXaxis.isPickable = false;
|
|
@@ -1376,9 +1384,9 @@ export class EditControl {
|
|
|
1376
1384
|
|
|
1377
1385
|
//the small axis
|
|
1378
1386
|
let al: number = this._axesLen * this._axesScale * 0.75;
|
|
1379
|
-
this._xaxis =
|
|
1380
|
-
this._yaxis =
|
|
1381
|
-
this._zaxis =
|
|
1387
|
+
this._xaxis = MeshBuilder.CreateLines("", { points: [new Vector3(0, 0, 0), new Vector3(al, 0, 0)] }, this._scene);
|
|
1388
|
+
this._yaxis = MeshBuilder.CreateLines("", { points: [new Vector3(0, 0, 0), new Vector3(0, al, 0)] }, this._scene);
|
|
1389
|
+
this._zaxis = MeshBuilder.CreateLines("", { points: [new Vector3(0, 0, 0), new Vector3(0, 0, al)] }, this._scene);
|
|
1382
1390
|
|
|
1383
1391
|
//lines are now pickable too
|
|
1384
1392
|
this._xaxis.isPickable = false;
|
|
@@ -1406,10 +1414,10 @@ export class EditControl {
|
|
|
1406
1414
|
private _pYX: Mesh;
|
|
1407
1415
|
|
|
1408
1416
|
private _createPickPlanes() {
|
|
1409
|
-
this._pALL =
|
|
1410
|
-
this._pXZ =
|
|
1411
|
-
this._pZY =
|
|
1412
|
-
this._pYX =
|
|
1417
|
+
this._pALL = MeshBuilder.CreatePlane("", { size: 5 }, this._scene);
|
|
1418
|
+
this._pXZ = MeshBuilder.CreatePlane("", { size: 5 }, this._scene);
|
|
1419
|
+
this._pZY = MeshBuilder.CreatePlane("", { size: 5 }, this._scene);
|
|
1420
|
+
this._pYX = MeshBuilder.CreatePlane("", { size: 5 }, this._scene);
|
|
1413
1421
|
|
|
1414
1422
|
this._pALL.isPickable = false;
|
|
1415
1423
|
this._pXZ.isPickable = false;
|
|
@@ -1468,22 +1476,33 @@ export class EditControl {
|
|
|
1468
1476
|
|
|
1469
1477
|
this._tCtl = new Mesh("", this._scene);
|
|
1470
1478
|
|
|
1471
|
-
|
|
1479
|
+
// pickable invisible boxes around axes lines
|
|
1472
1480
|
this._createPickableTrans(r, l, this._tCtl, this._scene);
|
|
1473
1481
|
|
|
1474
1482
|
//non pickable but visible cones at end of axes lines
|
|
1475
1483
|
this._createNonPickableTrans(r, l, this._scene);
|
|
1476
1484
|
}
|
|
1477
1485
|
|
|
1486
|
+
/**
|
|
1487
|
+
* pickable but invisible
|
|
1488
|
+
* a) 3 boxes around each of the 3 small axes lines
|
|
1489
|
+
* b) 3 small planes near origin for movement along a plane
|
|
1490
|
+
* @param r
|
|
1491
|
+
* @param l
|
|
1492
|
+
* @param tCtl
|
|
1493
|
+
* @param scene
|
|
1494
|
+
*/
|
|
1495
|
+
|
|
1478
1496
|
private _createPickableTrans(r: number, l: number, tCtl: Mesh, scene: Scene) {
|
|
1479
1497
|
let tX = this._extrudeBox(r / 2, l);
|
|
1480
1498
|
tX.name = "X";
|
|
1481
1499
|
let tY = tX.clone("Y");
|
|
1482
1500
|
let tZ = tX.clone("Z");
|
|
1483
1501
|
|
|
1484
|
-
let
|
|
1485
|
-
let
|
|
1486
|
-
let
|
|
1502
|
+
let s = r * 2;
|
|
1503
|
+
let tXZ = MeshBuilder.CreatePlane("XZ", { size: s }, scene);
|
|
1504
|
+
let tZY = MeshBuilder.CreatePlane("ZY", { size: s }, scene);
|
|
1505
|
+
let tYX = MeshBuilder.CreatePlane("YX", { size: s }, scene);
|
|
1487
1506
|
|
|
1488
1507
|
tXZ.rotation.x = 1.57;
|
|
1489
1508
|
tZY.rotation.y = -1.57;
|
|
@@ -1501,7 +1520,7 @@ export class EditControl {
|
|
|
1501
1520
|
tZY.bakeCurrentTransformIntoVertices();
|
|
1502
1521
|
tYX.bakeCurrentTransformIntoVertices();
|
|
1503
1522
|
|
|
1504
|
-
let tAll =
|
|
1523
|
+
let tAll = MeshBuilder.CreateBox("ALL", { size: r * 2 }, scene);
|
|
1505
1524
|
|
|
1506
1525
|
tX.parent = tCtl;
|
|
1507
1526
|
tY.parent = tCtl;
|
|
@@ -1529,12 +1548,15 @@ export class EditControl {
|
|
|
1529
1548
|
this._setPickableFalse(this._all_t)
|
|
1530
1549
|
}
|
|
1531
1550
|
|
|
1551
|
+
//non pickable but visible
|
|
1552
|
+
// a) 3 cones at end of the 3 small axes lines
|
|
1553
|
+
// b) 3 small planes near origin for movement along a plane
|
|
1532
1554
|
private _createNonPickableTrans(r: number, l: number, scene: Scene) {
|
|
1533
1555
|
//cone length
|
|
1534
1556
|
let cl: number = l / 5;
|
|
1535
1557
|
//cone base radius
|
|
1536
1558
|
//let cr: number = r;
|
|
1537
|
-
let tEndX =
|
|
1559
|
+
let tEndX = MeshBuilder.CreateCylinder("", { height: cl, diameterTop: 0, diameterBottom: r, tessellation: 6, subdivisions: 1 }, scene);
|
|
1538
1560
|
let tEndY = tEndX.clone("");
|
|
1539
1561
|
let tEndZ = tEndX.clone("");
|
|
1540
1562
|
|
|
@@ -1544,7 +1566,7 @@ export class EditControl {
|
|
|
1544
1566
|
let tEndZY = MeshBuilder.CreatePlane("ZY", { size: s }, scene);
|
|
1545
1567
|
let tEndYX = MeshBuilder.CreatePlane("YX", { size: s }, scene);
|
|
1546
1568
|
|
|
1547
|
-
let tEndAll =
|
|
1569
|
+
let tEndAll = MeshBuilder.CreateBox("ALL", { size: r }, scene);
|
|
1548
1570
|
|
|
1549
1571
|
tEndX.rotation.x = 1.57;
|
|
1550
1572
|
tEndY.rotation.x = 1.57;
|
|
@@ -1723,7 +1745,7 @@ export class EditControl {
|
|
|
1723
1745
|
private _extrudeBox(w: number, l: number): Mesh {
|
|
1724
1746
|
let shape: Vector3[] = [new Vector3(w, w, 0), new Vector3(-w, w, 0), new Vector3(-w, -w, 0), new Vector3(w, -w, 0), new Vector3(w, w, 0)];
|
|
1725
1747
|
let path: Vector3[] = [new Vector3(0, 0, 0), new Vector3(0, 0, l)];
|
|
1726
|
-
let box: Mesh =
|
|
1748
|
+
let box: Mesh = MeshBuilder.ExtrudeShape("", { shape: shape, path: path, scale: 1, rotation: 0, cap: 2 }, this._scene);
|
|
1727
1749
|
return box;
|
|
1728
1750
|
}
|
|
1729
1751
|
|
|
@@ -1749,7 +1771,7 @@ export class EditControl {
|
|
|
1749
1771
|
p++;
|
|
1750
1772
|
}
|
|
1751
1773
|
}
|
|
1752
|
-
let circle: LinesMesh =
|
|
1774
|
+
let circle: LinesMesh = MeshBuilder.CreateLines("", { points: points }, this._scene);
|
|
1753
1775
|
return circle;
|
|
1754
1776
|
}
|
|
1755
1777
|
|
|
@@ -1766,7 +1788,7 @@ export class EditControl {
|
|
|
1766
1788
|
points[p] = new Vector3(x, 0, z);
|
|
1767
1789
|
p++;
|
|
1768
1790
|
}
|
|
1769
|
-
let tube: Mesh =
|
|
1791
|
+
let tube: Mesh = MeshBuilder.CreateTube("", { path: points, radius: this._pickWidth * this._axesScale * 2, tessellation: 3, cap: Mesh.NO_CAP }, this._scene);
|
|
1770
1792
|
return tube;
|
|
1771
1793
|
}
|
|
1772
1794
|
|
|
@@ -1834,7 +1856,7 @@ export class EditControl {
|
|
|
1834
1856
|
sZY.bakeCurrentTransformIntoVertices();
|
|
1835
1857
|
sYX.bakeCurrentTransformIntoVertices();
|
|
1836
1858
|
|
|
1837
|
-
let sAll: Mesh =
|
|
1859
|
+
let sAll: Mesh = MeshBuilder.CreateBox("ALL", { size: 2 * r }, this._scene);
|
|
1838
1860
|
|
|
1839
1861
|
sX.parent = sCtl;
|
|
1840
1862
|
sY.parent = sCtl;
|
|
@@ -1864,7 +1886,7 @@ export class EditControl {
|
|
|
1864
1886
|
|
|
1865
1887
|
private _createNonPickableScale(r: number, l: number) {
|
|
1866
1888
|
|
|
1867
|
-
let sEndX =
|
|
1889
|
+
let sEndX = MeshBuilder.CreateBox("", { size: r }, this._scene);
|
|
1868
1890
|
let sEndY = sEndX.clone("");
|
|
1869
1891
|
let sEndZ = sEndX.clone("");
|
|
1870
1892
|
|
|
@@ -1874,7 +1896,7 @@ export class EditControl {
|
|
|
1874
1896
|
let sEndYX = MeshBuilder.CreatePlane("YX", { size: s }, this._scene);
|
|
1875
1897
|
|
|
1876
1898
|
|
|
1877
|
-
let sEndAll =
|
|
1899
|
+
let sEndAll = MeshBuilder.CreateBox("ALL", { size: r }, this._scene);
|
|
1878
1900
|
|
|
1879
1901
|
sEndXZ.rotation.x = 1.57;
|
|
1880
1902
|
sEndZY.rotation.y = -1.57;
|