babylonjs-editcontrol 3.3.0 → 4.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babylonjs-editcontrol",
3
- "version": "3.3.0",
3
+ "version": "4.0.0",
4
4
  "description": "A transform control for Babylonjs mesh",
5
5
  "repository": {
6
6
  "type": "git",
@@ -19,16 +19,15 @@
19
19
  "types": "dist/EditControl.d.ts",
20
20
  "dependencies": {},
21
21
  "devDependencies": {
22
- "babylonjs": "^5.41.0",
23
- "babylonjs-gui": "^5.41.0",
24
- "babylonjs-inspector": "^5.41.0",
25
- "pepjs": "^0.4.3",
22
+ "babylonjs": "^8.47.0",
23
+ "babylonjs-gui": "^8.47.0",
24
+ "babylonjs-inspector": "^8.47.0",
26
25
  "terser-webpack-plugin": "^5.3.6",
27
26
  "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"
27
+ "typescript": "^5.9.3",
28
+ "webpack": "^5.104.1",
29
+ "webpack-cli": "^6.0.1",
30
+ "webpack-dev-server": "^5.2.3"
32
31
  },
33
32
  "scripts": {
34
33
  "build-prod": "webpack --mode production",
@@ -69,11 +69,13 @@ export class EditControl {
69
69
  private _blueMat: StandardMaterial;
70
70
  private _whiteMat: StandardMaterial;
71
71
  private _yellowMat: StandardMaterial;
72
- private _redCol: Color3 = new Color3(1, 0.2, 0.2);
73
- private _greenCol: Color3 = new Color3(0.2, 1, 0.2);
74
- private _blueCol: Color3 = new Color3(0.2, 0.2, 1);
75
- private _whiteCol: Color3 = new Color3(1, 1, 1);
76
- private _yellowCol: Color3 = new Color3(1, 1, 0.2);
72
+
73
+ private _redCol: Color3 = new Color3(1, 0.34, 0.26);
74
+ private _greenCol: Color3 = new Color3(0.0, 0.8, 0.16);
75
+ private _blueCol: Color3 = new Color3(0.21, 0.5, 1);
76
+
77
+ private _whiteCol: Color3 = new Color3(0.7, 0.7, 0.7);
78
+ private _yellowCol: Color3 = new Color3(1, 1, 0);
77
79
 
78
80
  private _actHist: ActHist;
79
81
  private _renderer: () => void;
@@ -87,7 +89,11 @@ export class EditControl {
87
89
  //lhs-rhs issue. lhs mesh in rhs or rhs mesh in lhs
88
90
  private _lhsRhs: boolean = false;
89
91
 
90
- public constructor(mesh: TransformNode, camera: Camera, canvas: HTMLCanvasElement, scale?: number, eulerian?: boolean, pickWidth?: number) {
92
+ private _isEulerian(mesh:TransformNode):boolean{
93
+ return ((mesh.rotationQuaternion == null) || (mesh.rotationQuaternion == undefined));
94
+ }
95
+
96
+ public constructor(mesh: TransformNode, camera: Camera, canvas: HTMLCanvasElement, scale?: number, pickWidth?: number) {
91
97
 
92
98
  this._mesh = mesh;
93
99
  this._mainCamera = camera;
@@ -96,13 +102,7 @@ export class EditControl {
96
102
  if (scale != null) {
97
103
  this._axesScale = scale;
98
104
  }
99
-
100
- if (eulerian !== null) {
101
- this._eulerian = eulerian;
102
- } else {
103
- this._eulerian = false;
104
- }
105
- this._checkQuaternion();
105
+
106
106
 
107
107
  if (pickWidth != null) {
108
108
  this._pickWidth = pickWidth;
@@ -119,7 +119,7 @@ export class EditControl {
119
119
  this._boundingDimesion = this._getBoundingDimension(mesh);
120
120
  this._setLocalAxes(mesh);
121
121
  this._lhsRhs = this._check_LHS_RHS(mesh);
122
- console.log("lhs rhs issue " + this._lhsRhs);
122
+ if (this._lhsRhs) console.warn("we have lhs rhs issue " + this._lhsRhs);
123
123
 
124
124
  //build the edit control axes
125
125
  this._ecRoot = new Mesh("", this._scene);
@@ -157,16 +157,6 @@ export class EditControl {
157
157
  return this._ecRoot;
158
158
  }
159
159
 
160
- //make sure that if eulerian is set to false then mesh's rotation is in quaternion
161
- //throw error and exit if not so.
162
- private _checkQuaternion() {
163
- if (!this._eulerian) {
164
- if ((this._mesh.rotationQuaternion == null) || (this._mesh.rotationQuaternion == undefined)) {
165
- throw "Error: Eulerian is set to false but the mesh's rotationQuaternion is not set.";
166
- }
167
- }
168
- }
169
-
170
160
  /**
171
161
  * checks if a have left hand , right hand issue.
172
162
  * In other words if a mesh is a LHS mesh in RHS system or
@@ -231,7 +221,7 @@ export class EditControl {
231
221
  private _setECRotation() {
232
222
  if (this._local) {
233
223
  if (this._mesh.parent == null) {
234
- if (this._eulerian) {
224
+ if (this._isEulerian(this._mesh)) {
235
225
  let rot: Vector3 = this._mesh.rotation;
236
226
  Quaternion.RotationYawPitchRollToRef(rot.y, rot.x, rot.z, this._ecRoot.rotationQuaternion);
237
227
  } else {
@@ -270,7 +260,7 @@ export class EditControl {
270
260
  private _cameraNormal: Vector3 = new Vector3(0, 0, 0);
271
261
  private _setECScale() {
272
262
  this._ecRoot.position.subtractToRef(this._mainCamera.position, this._cameraTOec);
273
- Vector3.FromArrayToRef(<DeepImmutableObject<Float32Array>>this._mainCamera.getWorldMatrix().asArray(), 8, this._cameraNormal);
263
+ Vector3.FromArrayToRef(this._mainCamera.getWorldMatrix().asArray(), 8, this._cameraNormal);
274
264
 
275
265
  //get distance of edit control from the camera plane
276
266
  //project "camera to edit control" vector onto the camera normal
@@ -354,13 +344,9 @@ export class EditControl {
354
344
 
355
345
 
356
346
 
357
- public switchTo(mesh: TransformNode, eulerian?: boolean) {
347
+ public switchTo(mesh: TransformNode) {
358
348
  mesh.computeWorldMatrix(true);
359
349
  this._mesh = mesh;
360
- if (eulerian != null) {
361
- this._eulerian = eulerian;
362
- }
363
- this._checkQuaternion();
364
350
  this._setLocalAxes(mesh);
365
351
  this._actHist = new ActHist(mesh, 10);
366
352
  this._lhsRhs = this._check_LHS_RHS(mesh);
@@ -497,7 +483,7 @@ export class EditControl {
497
483
  evt.preventDefault();
498
484
  this._pDown = true;
499
485
  if ((<PointerEvent>evt).button != 0) return;
500
- let engine: Engine = this._scene.getEngine();
486
+ let engine: Engine = <Engine> this._scene.getEngine();
501
487
  let x = (engine.isPointerLock) ? this._canvas.width * 0.5 : this._scene.pointerX;
502
488
  let y = (engine.isPointerLock) ? this._canvas.height * 0.5 : this._scene.pointerY;
503
489
  let pickResult: PickingInfo = this._scene.pick(x, y, (mesh) => {
@@ -573,7 +559,7 @@ export class EditControl {
573
559
  private _detachCamera(cam: Object, can: Object) {
574
560
  let camera: Camera = <Camera>cam;
575
561
  let canvas: HTMLCanvasElement = <HTMLCanvasElement>can;
576
- let engine: Engine = this._scene.getEngine();
562
+ let engine: Engine = <Engine> this._scene.getEngine();
577
563
  if (!engine.isPointerLock) {
578
564
  camera.detachControl(canvas)
579
565
  }
@@ -590,7 +576,7 @@ export class EditControl {
590
576
  private _savedCol: Color3;
591
577
  private _onPointerOver() {
592
578
  //if(this.pDown) return;
593
- let engine: Engine = this._scene.getEngine();
579
+ let engine: Engine = <Engine> this._scene.getEngine();
594
580
  let x = (engine.isPointerLock) ? this._canvas.width * 0.5 : this._scene.pointerX;
595
581
  let y = (engine.isPointerLock) ? this._canvas.height * 0.5 : this._scene.pointerY;
596
582
  let pickResult: PickingInfo = this._scene.pick(x, y, (mesh) => {
@@ -612,7 +598,7 @@ export class EditControl {
612
598
  this._prevOverMesh = <Mesh>pickResult.pickedMesh;
613
599
  if (this._rotEnabled) {
614
600
  this._savedCol = (<LinesMesh>this._prevOverMesh.getChildren()[0]).color;
615
- (<LinesMesh>this._prevOverMesh.getChildren()[0]).color = this._whiteCol;
601
+ (<LinesMesh>this._prevOverMesh.getChildren()[0]).color = this._yellowCol;
616
602
  } else {
617
603
  let childs: Node[] = this._prevOverMesh.getChildren();
618
604
  if (childs.length > 0) {
@@ -624,11 +610,11 @@ export class EditControl {
624
610
  }
625
611
  }
626
612
  if (this._prevOverMesh.name == "X") {
627
- this._xaxis.color = this._whiteCol;
613
+ this._xaxis.color = this._yellowCol;
628
614
  } else if (this._prevOverMesh.name == "Y") {
629
- this._yaxis.color = this._whiteCol;
615
+ this._yaxis.color = this._yellowCol;
630
616
  } else if (this._prevOverMesh.name == "Z") {
631
- this._zaxis.color = this._whiteCol;
617
+ this._zaxis.color = this._yellowCol;
632
618
  }
633
619
  }
634
620
  } else {
@@ -678,7 +664,7 @@ export class EditControl {
678
664
  private _onPointerUp(evt: Event) {
679
665
  this._pDown = false;
680
666
  if (this._editing) {
681
- let engine: Engine = this._scene.getEngine();
667
+ let engine: Engine = <Engine> this._scene.getEngine();
682
668
  if (!engine.isPointerLock) {
683
669
  this._mainCamera.attachControl(true);
684
670
  }
@@ -1043,9 +1029,9 @@ export class EditControl {
1043
1029
  */
1044
1030
  private _setLocalAxes(mesh: Node) {
1045
1031
  let meshMatrix: Matrix = mesh.getWorldMatrix();
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);
1032
+ Vector3.FromArrayToRef(meshMatrix.m, 0, this._localX);
1033
+ Vector3.FromArrayToRef(meshMatrix.m, 4, this._localY);
1034
+ Vector3.FromArrayToRef(meshMatrix.m, 8, this._localZ);
1049
1035
  }
1050
1036
 
1051
1037
 
@@ -1080,7 +1066,7 @@ export class EditControl {
1080
1066
  this._boundingDimesion = this._getBoundingDimension(this._mesh);
1081
1067
  }
1082
1068
 
1083
- private _eulerian: boolean = false;
1069
+ // private _eulerian: boolean = false;
1084
1070
  private _snapRA: number = 0;
1085
1071
  private _doRotation(mesh: TransformNode, axis: Mesh, newPos: Vector3, prevPos: Vector3) {
1086
1072
 
@@ -1139,10 +1125,6 @@ export class EditControl {
1139
1125
  mesh.rotate(rAxis, angle, Space.WORLD);
1140
1126
  }
1141
1127
 
1142
- if (this._eulerian) {
1143
- mesh.rotation = mesh.rotationQuaternion.toEulerAngles();
1144
- mesh.rotationQuaternion = null;
1145
- }
1146
1128
 
1147
1129
  if (this._local) {
1148
1130
  if (this._lhsRhs) {
@@ -1160,7 +1142,7 @@ export class EditControl {
1160
1142
  }
1161
1143
 
1162
1144
  private _getPosOnPickPlane(): Vector3 {
1163
- let engine: Engine = this._scene.getEngine();
1145
+ let engine: Engine = <Engine> this._scene.getEngine();
1164
1146
  let x = (engine.isPointerLock) ? this._canvas.width * 0.5 : this._scene.pointerX;
1165
1147
  let y = (engine.isPointerLock) ? this._canvas.height * 0.5 : this._scene.pointerY;
1166
1148
  let pickinfo: PickingInfo = this._scene.pick(x, y, (mesh) => {
@@ -1249,10 +1231,7 @@ export class EditControl {
1249
1231
  return this._rotEnabled;
1250
1232
  }
1251
1233
 
1252
- public returnEuler(euler: boolean) {
1253
- this._eulerian = euler;
1254
- }
1255
-
1234
+
1256
1235
  public enableRotation() {
1257
1236
  if (this._hidden) return;
1258
1237
  if (this._rCtl == null) {
@@ -1718,7 +1697,7 @@ export class EditControl {
1718
1697
  rEndX.color = this._redCol;
1719
1698
  rEndY.color = this._greenCol;
1720
1699
  rEndZ.color = this._blueCol;
1721
- rEndAll.color = this._yellowCol;
1700
+ rEndAll.color = this._whiteCol;
1722
1701
  rEndAll2.color = Color3.Gray();
1723
1702
 
1724
1703
  this._rEndX = rEndX;
@@ -2128,8 +2107,8 @@ export class EditControl {
2128
2107
  this._redMat = EditControl._getStandardMaterial(this._redCol, scene);
2129
2108
  this._greenMat = EditControl._getStandardMaterial(this._greenCol, scene);
2130
2109
  this._blueMat = EditControl._getStandardMaterial(this._blueCol, scene);
2131
- this._whiteMat = EditControl._getStandardMaterial(this._whiteCol, scene);
2132
- this._yellowMat = EditControl._getStandardMaterial(this._yellowCol, scene);
2110
+ this._whiteMat = EditControl._getStandardMaterial(this._yellowCol, scene);
2111
+ this._yellowMat = EditControl._getStandardMaterial(this._whiteCol, scene);
2133
2112
  }
2134
2113
 
2135
2114
  private _disposeMaterials() {
@@ -2220,7 +2199,6 @@ class Act {
2220
2199
 
2221
2200
  public constructor(mesh: TransformNode, at: number) {
2222
2201
  this._p = mesh.position.clone();
2223
- //if (mesh.rotationQuaternion == null) {
2224
2202
  if (mesh.rotationQuaternion == null) {
2225
2203
  this._rQ = null;
2226
2204
  this._rE = mesh.rotation.clone();
@@ -1,9 +0,0 @@
1
- /*! babylonjs */
2
-
3
- /*!****************************!*\
4
- !*** ./src/EditControl.ts ***!
5
- \****************************/
6
-
7
- /*!****************************************************************************************************!*\
8
- !*** external {"commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs","root":"BABYLON"} ***!
9
- \****************************************************************************************************/