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/README.md CHANGED
@@ -1,436 +1,453 @@
1
- # BabylonJS-EditControl
2
-
3
- An edit control for use in [BabylonJS](http://www.babylonjs.com/) (a 3D HTML Webgl framework) applications.
4
-
5
- ## About
6
-
7
- All 3d editors provide a widget, also referred to as transform control, to translate, rotate or scale 3d objects in the editor.
8
- This EditControl is similar to those widgets.
9
- You can embed this in your Babylonjs application to provide those same capabilities.
10
- It currently supports
11
-
12
- - Translate
13
- - Translate Snap
14
- - Rotate
15
- - Rotate Snap
16
- - Scale
17
- - Scale Snap
18
- - Local or Global Translation and Rotation. (Scaling only in local axis)
19
- - Create multiple instances in the same scene with each instance attached to a different mesh
20
- - Scale size of control
21
- - undo, redo
22
-
23
- For a demo, head on over to <a href="https://ssatguru.github.io/BabylonJS-EditControl-Samples/demo/Demo.html" target="_blank"> https://ssatguru.github.io/BabylonJS-EditControl-Samples/demo/Demo.html </a>
24
-
25
- For a list of know issues, shortcomings and planned enhancements see <a href="https://github.com/ssatguru/BabylonJS-EditControl/issues" target="_blank"> https://github.com/ssatguru/BabylonJS-EditControl/issues </a>
26
-
27
- ### Breaking change with 3.2.0
28
-
29
- Version 3.2.0 converts the project from a plain vanilla JavaScript project to a module based JavaScript project.
30
- With this change, the way to load the application has changed.
31
- In JavaScript, instead of
32
-
33
- ```
34
- var EditControl = org.ssatguru.babylonjs.component.EditControl;
35
- editControl = new EditControl(box,camera, canvas, 0.75);
36
- ```
37
-
38
- now do
39
-
40
- ```
41
- var editControl = new EditControl(box,camera, canvas, 0.75);
42
- ```
43
-
44
- In TypeScript, instead of
45
-
46
- ```
47
- import EditControl = org.ssatguru.babylonjs.component.EditControl;
48
- ```
49
-
50
- now do
51
-
52
- ```
53
- import {EditControl} from "babaylonjs-editcontrol";
54
- ```
55
-
56
- See below for more details.
57
-
58
- ## Quick start
59
-
60
- 1. add the following dependencies
61
-
62
- ```
63
- <script src="https://code.jquery.com/pep/0.4.2/pep.js"></script>
64
- <script src="https://cdn.babylonjs.com/babylon.js"></script>
65
- <script src="EditControl.js"></script>
66
- ```
67
-
68
- See INSTALL below to find where you can get "EditControl.js".
69
-
70
- 2. a small javascript code snippet to get you up and running
71
-
72
- ```
73
- //------------------EDIT CONTROL -------------------------------------------------
74
- //create edit control (mesh to attach to, active camera, canvas, scale of editcontrol)
75
- var editControl = new EditControl(box,camera, canvas, 0.75);
76
- //to show translation controls
77
- editControl.enableTranslation();
78
- //set transalation snap value in meters
79
- editControl.setTransSnapValue(0.5
80
- ```
81
-
82
- see sample project here
83
- [https://github.com/ssatguru/BabylonJS-EditControl-Samples/tree/master/sample-global](https://github.com/ssatguru/BabylonJS-EditControl-Samples/tree/master/sample-global)
84
-
85
- ## INSTALL
86
-
87
- You can find the "EditControl.js" from its git repository "dist" folder or "releases" section
88
- [https://github.com/ssatguru/BabylonJS-EditControl/tree/master/dist](https://github.com/ssatguru/BabylonJS-EditControl/tree/master/dist)
89
- [https://github.com/ssatguru/BabylonJS-EditControl/releases](https://github.com/ssatguru/BabylonJS-EditControl/releases)
90
-
91
- You can also install this from npm
92
-
93
- ```
94
- npm install babylonjs-editcontrol
95
- ```
96
-
97
- ## USAGE
98
-
99
- This has been built as an UMD module which means you can use it as a CommonJS/NodeJS module, AMD module or as a global object
100
- loaded using the script tag.
101
-
102
- Project "BabylonJS-EditControl-Samples" [https://github.com/ssatguru/BabylonJS-EditControl-Samples](https://github.com/ssatguru/BabylonJS-EditControl-Samples) has a
103
- collection of sample projects to show how to use this from TypeScript, NodeJs, AMD or plain vanilla JavaScript applications.
104
-
105
- Below is a quick summary of how you can use this as different module types.
106
-
107
- CommonJS/NodeJS Module
108
-
109
- ```
110
- let BABYLON = require("babylonjs");
111
- let EditControl = require("babylonjs-editcontrol").EditControl;
112
- let engine = new BABYLON.Engine(canvas, true);
113
- ...
114
- let editControl = new EditControl(box,camera, canvas, 0.75);
115
- ...
116
-
117
- ```
118
-
119
- AMD Module
120
-
121
- ```
122
- <script src="./lib/require.js"></script>
123
- <script>
124
- require.config({
125
- baseUrl: ".",
126
- paths: {
127
- "babylonjs": "./lib/babylon",
128
- "ec": "./lib/EditControl"
129
- }
130
- });
131
-
132
- require(['babylonjs', 'ec'], function (BABYLON, ec) {
133
- let EditControl = ec.EditControl;
134
- let engine = new BABYLON.Engine(canvas, true);
135
- ...
136
- let editControl = new EditControl(box,camera, canvas, 0.75);
137
- ...
138
- });
139
- </script>
140
- ```
141
-
142
- Global Module
143
-
144
- ```
145
- <script src="./lib/babylon.js"></script>
146
- <script src="./lib/EditControl.js"></script>
147
- <script>
148
- let engine = new BABYLON.Engine(canvas, true);
149
- ...
150
- let editControl = new EditControl(box,camera, canvas, 0.75);
151
- ...
152
- </script>
153
- ```
154
-
155
- ## DEPENDENCIES
156
-
157
- - pepjs
158
- - babylonjs
159
-
160
- The two can be installed from npm
161
-
162
- ```
163
- npm install babylonjs pepjs
164
- ```
165
-
166
- or via cdn
167
-
168
- ```
169
- <script src="https://code.jquery.com/pep/0.4.2/pep.js"></script>
170
- <script src="https://cdn.babylonjs.com/babylon.js"></script>
171
- ```
172
-
173
- ## API
174
-
175
- #### To Instantiate
176
-
177
- ```
178
- // JavaScript
179
- var editControl = new EditControl(mesh,camera, canvas, 0.75, true);
180
- ```
181
-
182
- ```
183
- // TypeScript
184
- import {EditControl} from "babaylonjs-editcontrol";
185
- let editControl:EditControl = new EditControl(mesh,camera, canvas, 0.75, true,0.02);
186
- ```
187
-
188
- This positions the edit control at the mesh pivot position and displays x,y,z axis.
189
- Takes five parms
190
-
191
- - mesh - the mesh to control using the editcontrol
192
- - camera - active camera
193
- - canvas - the mesh canvas
194
- - scale - number. Optional. Default 1. Determines how small or large the editcontrol should appear.
195
- - eulerian - true/false. Optional. Default false. True indicates that rotation of the mesh is in euler.If rotation is unresponsive then it is possible that the rotation may not have been initialized to either a eulerian or quaternion value.
196
- - pickWidth - number. Optional. Default 0.02. Determines how close to an axis should the pointer get before we can pick it
197
-
198
- #### To show Translation, Rotation or Scaling controls
199
-
200
- ```
201
- editControl.enableTranslation();
202
-
203
- editControl.enableRotation();
204
- editControl.setRotGuideFull(true/false) //This makes the rotation guides 360 degree(true) or 90 degree(false) .90 degree looks less cluttered.
205
- editControl.returnEuler(true); // Optional. This will return rotation in euler instead of quaternion. Quaternion is the default.
206
-
207
- editControl.enableScaling();
208
- ```
209
-
210
- #### To hide Translation, Rotation or Scaling controls (just displays x,y,z axis)
211
-
212
- ```
213
- editControl.disableTranslation();
214
- editControl.disableRotation();
215
- editControl.disableScaling();
216
- ```
217
-
218
- #### To check if Translation, Rotation or Scaling is enabled
219
-
220
- ```
221
- editControl.isTranslationEnabled();
222
- editControl.isRotationEnabled();
223
- editControl.isScalingEnabled();
224
- ```
225
-
226
- #### To turn on/off local/ global mode
227
-
228
- ```
229
- editControl.setLocal(boolean true/false);
230
- ```
231
-
232
- #### To check if local/ global mode
233
-
234
- ```
235
- editControl.isLocal();
236
- ```
237
-
238
- #### To turn on/off translation, rotation or scale snapping
239
-
240
- ```
241
- editControl.setTransSnap(boolean true/false);
242
- editControl.setRotSnap(boolean true/false);
243
- editControl.setScaleSnap(boolean true/false);
244
-
245
- editControl.isTransSnap();
246
- editControl.isRotSnap();
247
- editControl.isScaleSnap();
248
- ```
249
-
250
- #### To set/get translation, rotation or scale snap values
251
-
252
- ```
253
- editControl.setTransSnapValue(number n in meters);
254
- editControl.setRotSnapValue(number n in radians);
255
- editControl.setScaleSnapValue(number n a factor by which scale should increase);
256
-
257
- editControl.getTransSnapValue();
258
- editControl.getRotSnapValue();
259
- editControl.getScaleSnapValue();
260
- ```
261
-
262
- #### To bound translation, rotation or scaling
263
-
264
- This restricts tranlation, rotation,scaling between a minimum and maximum values
265
-
266
- ```
267
- setTransBounds(min?: Vector3,max?: Vector3) ;
268
- setRotBounds(min?: Vector3,max?: Vector3);
269
- setScaleBounds(min?: Vector3,max?: Vector3);
270
- ```
271
-
272
- ```
273
- removeTransBounds();
274
- removeRotBounds();
275
- removeScaleBounds();
276
- ```
277
-
278
- Note: rotation bounds has not been implemented. This is on TODO list.
279
-
280
- #### To undo or redo
281
-
282
- ```
283
- editControl.undo();
284
- editControl.redo();
285
- ```
286
-
287
- #### To set undo count
288
-
289
- By default does upto 10 undos
290
-
291
- ```
292
- editControl.setUndoCount(number count);
293
- ```
294
-
295
- #### To check if user editing (moving,translating or scaling object)
296
-
297
- ```
298
- editControl.isEditing();
299
- ```
300
-
301
- returns true if the use is in the process of editing
302
-
303
- #### To check if the pointer is over the edit control
304
-
305
- ```
306
- editControl.isPointeOver();
307
- ```
308
-
309
- returns true if the pointer is over the edit control
310
-
311
- #### To be called back whenever the user starts, takes or ends an action
312
-
313
- ```
314
- editControl.addActionStartListener(function(number actionType));
315
- editControl.addActionListener(function(number actionType));
316
- editControl.addActionEndListener(function(number actionType));
317
- ```
318
-
319
- Each of these take a function as a parameter.
320
- The ActionStartListener would be called when the user starts translating,rotating or scaling a mesh
321
- The ActionListener would be called when the user is translating,rotating or scaling a mesh
322
- The ActionEndListener would be called when the user ends translating,rotating or scaling a mesh
323
-
324
- When called, these listeners would be passed a number which would indicate the action being taken by the user.
325
- This number would have one of the following values
326
- 0 - ActionType.TRANS, Translation
327
- 1 - ActioneType.ROT, Rotation
328
- 2 - ActioneType.SCALE, Scaling
329
-
330
- To remove the listeners
331
-
332
- ```
333
- editControl.removeActionStartListener();
334
- editControl.removeActionListener();
335
- editControl.removeActionEndListener();
336
- editControl.removeAllActionListeners() // to remove all;
337
- ```
338
-
339
- #### To refresh mesh Bounding Info.
340
-
341
- EditControl uses mesh bounding info to provide the same smooth scaling experience for both small and large mesh. The bounding info changes when a mesh is baked. Use this method to refresh the bounding info if you baked the transform of the mesh.
342
-
343
- ```
344
- editControl.refreshBoundingInfo();
345
- ```
346
-
347
- #### To get position and rotaion of EditControl
348
-
349
- ```
350
- editControl.getPosition();//returns Vector3
351
- editControl.getRotationQuaternion(): //returns rotation in quaternion
352
- ```
353
-
354
- The postion and rotation of EditControl would be the same as that of the mesh to which it is attached
355
-
356
- #### To show/hide EditControl
357
-
358
- ```
359
- editControl.hide();
360
- editControl.isHidden(); //turns true or false
361
- editControl.show();
362
- ```
363
-
364
- #### To set visibililty (transparency)
365
-
366
- ```
367
- editControl.setVisibility(v:number);
368
- ```
369
-
370
- By default the visibility is set to 0.75
371
-
372
- #### To switch camera
373
-
374
- ```
375
- editControl.switchCamera(camera:Camera);
376
- ```
377
-
378
- The edit control uses the camera specified during instantiation to control how it is scaled or picked.
379
- Use this to swicth to a different camera after instantiation.
380
- You might want to use this for example when the active camera in your scene changes and you want to use the new one for the editcontrol.
381
-
382
- #### To switch edit control to another mesh
383
-
384
- ```
385
- editControl.switchTo(Mesh mesh, optional boolean isEuler );
386
- ```
387
-
388
- This quickly removes the edit control from one mesh and attaches it to another mesh.
389
-
390
- The translation, rotation, scaling mode is maintained.
391
-
392
- mesh : the mesh to which the control should switch to
393
- isEuler : true/false, optional, default false, true indicates that rotation of the mesh is in euler
394
-
395
- #### To detach from the mesh and clean up resources.
396
-
397
- ```
398
- editControl.detach();
399
- ```
400
-
401
- ## Build and Test
402
-
403
- If not already installed, install node js.
404
- Switch to the project folder.
405
- Run "npm install", once, to install all the dependencies.
406
-
407
- ### Build
408
-
409
- Run "npm run build" - this will compile the files in "src" and create a development module in the "dist" folder.
410
- Run "npm run build-prod" - this will compile and create a minified production module in the "dist" folder.
411
-
412
- ### To test
413
-
414
- Two ways to test.
415
-
416
- 1. using the webpack-dev-server.
417
- Start the development server
418
- "npm run start"
419
- This will start the live dev server on port 8080 (could be different if this port is already in use) and open the browser with the file http://localhost:8080/tst/test.html.
420
- The dev server will live compile your code any time you make changes.
421
- Note: The dev server does not write the build to disk, instead it serves it from memory. In our case the build, "EditControl.max.js", is served from location http://localhost:8080/dest. (see publicPath in wepack.config.js file).
422
-
423
- 2. using any other http server.
424
- Start the server , say http-server, from the project root folder (not from within "/tst " folder).
425
- Goto http://localhost:8080/tst/test.html (assuming the server was started on port 8080).
426
- Everytime you make changes you will have to build using "npm start build-dev".
427
-
428
- ## Note:
429
-
430
- The original version was written in Java and then transpiled to TypeScript/JavaScript using JSweet.
431
- It was originally written in Java, as at that time I wasn't very comfortable with the TypeScript language and its ecosystem.
432
- Over time I have become more comfortable with it.
433
- The new version is thus written in TypeScript.
434
- It is based on the initial TypeScript code generated by JSweet.
435
- Porting to Typescript was easy, as JSweet generates good human readable TypeScript which allows one to switch to TypeScript at any time.
436
- For those interested, the old java version is still available at [https://github.com/ssatguru/BabylonJS-EditControl.java](https://github.com/ssatguru/BabylonJS-EditControl.java)
1
+ # BabylonJS-EditControl
2
+
3
+ An edit control for use in [BabylonJS](http://www.babylonjs.com/) (a 3D HTML Webgl framework) applications.
4
+
5
+ ## About
6
+
7
+ Many 3d editors provide, what is called, a widget/gizmo/transform control, to help translate, rotate or scale 3d objects in the editor.
8
+ This EditControl is just that.
9
+ You can embed this in your Babylonjs application to provide those same capabilities.
10
+ It currently supports
11
+
12
+ - Translate
13
+ - Translate Snap
14
+ - Rotate
15
+ - Rotate Snap
16
+ - Scale
17
+ - Scale Snap
18
+ - Local or Global Translation and Rotation. (Scaling only in local axis)
19
+ - Create multiple instances in the same scene with each instance attached to a different mesh
20
+ - Scale size of control
21
+ - undo, redo
22
+
23
+ For a demo, head on over to <a href="https://ssatguru.github.io/BabylonJS-EditControl-Samples/demo/Demo.html" target="_blank"> https://ssatguru.github.io/BabylonJS-EditControl-Samples/demo/Demo.html </a>
24
+
25
+ ### Limitations/Issues
26
+
27
+ This currently does not handle properly, a right handed mesh in a left handed system (example gltf mesh in lhs babylon) or a left handed mesh in a right handed system.
28
+ A right handed mesh in a right handed system or a left handed mesh in a left handed system is handled properly.
29
+ A gltf mesh in a right handed babylon is handled properly.
30
+ I would address this in a future release.
31
+
32
+ For a list of other know issues, shortcomings and planned enhancements see <a href="https://github.com/ssatguru/BabylonJS-EditControl/issues" target="_blank"> https://github.com/ssatguru/BabylonJS-EditControl/issues </a>
33
+
34
+ ### 3.3.0 Major changes
35
+
36
+ Moved the EditControl to the Babylonjs DefaultUtilityLayer scene.
37
+ Because this scene is different from the main scene there is less interference with the main scene. Also makes it a bit faster.
38
+ This is similar to how the native gizmos of Babylonjs work.
39
+
40
+ Upgraded to latest version of Babylons js - 5.41.
41
+ Replaced deprecated methods with new ones.
42
+ Upgraded other dev dependenices to latest version - typescript, webpack etc.
43
+
44
+ ### 3.20 Major and Breaking changes
45
+
46
+ Version 3.2.0 converts the project from a plain vanilla JavaScript project to a module based JavaScript project.
47
+ With this change, the way to load the application has changed.
48
+ In JavaScript, instead of
49
+
50
+ ```
51
+ var EditControl = org.ssatguru.babylonjs.component.EditControl;
52
+ editControl = new EditControl(box,camera, canvas, 0.75);
53
+ ```
54
+
55
+ now do
56
+
57
+ ```
58
+ var editControl = new EditControl(box,camera, canvas, 0.75);
59
+ ```
60
+
61
+ In TypeScript, instead of
62
+
63
+ ```
64
+ import EditControl = org.ssatguru.babylonjs.component.EditControl;
65
+ ```
66
+
67
+ now do
68
+
69
+ ```
70
+ import {EditControl} from "babaylonjs-editcontrol";
71
+ ```
72
+
73
+ See below for more details.
74
+
75
+ ## Quick start
76
+
77
+ 1. add the following dependencies
78
+
79
+ ```
80
+ <script src="https://code.jquery.com/pep/0.4.2/pep.js"></script>
81
+ <script src="https://cdn.babylonjs.com/babylon.js"></script>
82
+ <script src="EditControl.js"></script>
83
+ ```
84
+
85
+ See INSTALL below to find where you can get "EditControl.js".
86
+
87
+ 2. a small javascript code snippet to get you up and running
88
+
89
+ ```
90
+ //------------------EDIT CONTROL -------------------------------------------------
91
+ //create edit control (mesh to attach to, active camera, canvas, scale of editcontrol)
92
+ var editControl = new EditControl(box,camera, canvas, 0.75);
93
+ //to show translation controls
94
+ editControl.enableTranslation();
95
+ //set transalation snap value in meters
96
+ editControl.setTransSnapValue(0.5
97
+ ```
98
+
99
+ see sample project here
100
+ [https://github.com/ssatguru/BabylonJS-EditControl-Samples/tree/master/sample-global](https://github.com/ssatguru/BabylonJS-EditControl-Samples/tree/master/sample-global)
101
+
102
+ ## INSTALL
103
+
104
+ You can find the "EditControl.js" from its git repository "dist" folder or "releases" section
105
+ [https://github.com/ssatguru/BabylonJS-EditControl/tree/master/dist](https://github.com/ssatguru/BabylonJS-EditControl/tree/master/dist)
106
+ [https://github.com/ssatguru/BabylonJS-EditControl/releases](https://github.com/ssatguru/BabylonJS-EditControl/releases)
107
+
108
+ You can also install this from npm
109
+
110
+ ```
111
+ npm install babylonjs-editcontrol
112
+ ```
113
+
114
+ ## USAGE
115
+
116
+ This has been built as an UMD module which means you can use it as a CommonJS/NodeJS module, AMD module or as a global object
117
+ loaded using the script tag.
118
+
119
+ Project "BabylonJS-EditControl-Samples" [https://github.com/ssatguru/BabylonJS-EditControl-Samples](https://github.com/ssatguru/BabylonJS-EditControl-Samples) has a
120
+ collection of sample projects to show how to use this from TypeScript, NodeJs, AMD or plain vanilla JavaScript applications.
121
+
122
+ Below is a quick summary of how you can use this as different module types.
123
+
124
+ CommonJS/NodeJS Module
125
+
126
+ ```
127
+ let BABYLON = require("babylonjs");
128
+ let EditControl = require("babylonjs-editcontrol").EditControl;
129
+ let engine = new BABYLON.Engine(canvas, true);
130
+ ...
131
+ let editControl = new EditControl(box,camera, canvas, 0.75);
132
+ ...
133
+
134
+ ```
135
+
136
+ AMD Module
137
+
138
+ ```
139
+ <script src="./lib/require.js"></script>
140
+ <script>
141
+ require.config({
142
+ baseUrl: ".",
143
+ paths: {
144
+ "babylonjs": "./lib/babylon",
145
+ "ec": "./lib/EditControl"
146
+ }
147
+ });
148
+
149
+ require(['babylonjs', 'ec'], function (BABYLON, ec) {
150
+ let EditControl = ec.EditControl;
151
+ let engine = new BABYLON.Engine(canvas, true);
152
+ ...
153
+ let editControl = new EditControl(box,camera, canvas, 0.75);
154
+ ...
155
+ });
156
+ </script>
157
+ ```
158
+
159
+ Global Module
160
+
161
+ ```
162
+ <script src="./lib/babylon.js"></script>
163
+ <script src="./lib/EditControl.js"></script>
164
+ <script>
165
+ let engine = new BABYLON.Engine(canvas, true);
166
+ ...
167
+ let editControl = new EditControl(box,camera, canvas, 0.75);
168
+ ...
169
+ </script>
170
+ ```
171
+
172
+ ## DEPENDENCIES
173
+
174
+ - pepjs
175
+ - babylonjs
176
+
177
+ The two can be installed from npm
178
+
179
+ ```
180
+ npm install babylonjs pepjs
181
+ ```
182
+
183
+ or via cdn
184
+
185
+ ```
186
+ <script src="https://code.jquery.com/pep/0.4.2/pep.js"></script>
187
+ <script src="https://cdn.babylonjs.com/babylon.js"></script>
188
+ ```
189
+
190
+ ## API
191
+
192
+ #### To Instantiate
193
+
194
+ ```
195
+ // JavaScript
196
+ var editControl = new EditControl(mesh,camera, canvas, 0.75, true);
197
+ ```
198
+
199
+ ```
200
+ // TypeScript
201
+ import {EditControl} from "babaylonjs-editcontrol";
202
+ let editControl:EditControl = new EditControl(mesh,camera, canvas, 0.75, true,0.02);
203
+ ```
204
+
205
+ This positions the edit control at the mesh pivot position and displays x,y,z axis.
206
+ Takes five parms
207
+
208
+ - mesh - the mesh to control using the editcontrol
209
+ - camera - active camera
210
+ - canvas - the mesh canvas
211
+ - scale - number. Optional. Default 1. Determines how small or large the editcontrol should appear.
212
+ - eulerian - true/false. Optional. Default false. True indicates that rotation of the mesh is in euler.If rotation is unresponsive then it is possible that the rotation may not have been initialized to either a eulerian or quaternion value.
213
+ - pickWidth - number. Optional. Default 0.02. Determines how close to an axis should the pointer get before we can pick it
214
+
215
+ #### To show Translation, Rotation or Scaling controls
216
+
217
+ ```
218
+ editControl.enableTranslation();
219
+
220
+ editControl.enableRotation();
221
+ editControl.setRotGuideFull(true/false) //This makes the rotation guides 360 degree(true) or 90 degree(false) .90 degree looks less cluttered.
222
+ editControl.returnEuler(true); // Optional. This will return rotation in euler instead of quaternion. Quaternion is the default.
223
+
224
+ editControl.enableScaling();
225
+ ```
226
+
227
+ #### To hide Translation, Rotation or Scaling controls (just displays x,y,z axis)
228
+
229
+ ```
230
+ editControl.disableTranslation();
231
+ editControl.disableRotation();
232
+ editControl.disableScaling();
233
+ ```
234
+
235
+ #### To check if Translation, Rotation or Scaling is enabled
236
+
237
+ ```
238
+ editControl.isTranslationEnabled();
239
+ editControl.isRotationEnabled();
240
+ editControl.isScalingEnabled();
241
+ ```
242
+
243
+ #### To turn on/off local/ global mode
244
+
245
+ ```
246
+ editControl.setLocal(boolean true/false);
247
+ ```
248
+
249
+ #### To check if local/ global mode
250
+
251
+ ```
252
+ editControl.isLocal();
253
+ ```
254
+
255
+ #### To turn on/off translation, rotation or scale snapping
256
+
257
+ ```
258
+ editControl.setTransSnap(boolean true/false);
259
+ editControl.setRotSnap(boolean true/false);
260
+ editControl.setScaleSnap(boolean true/false);
261
+
262
+ editControl.isTransSnap();
263
+ editControl.isRotSnap();
264
+ editControl.isScaleSnap();
265
+ ```
266
+
267
+ #### To set/get translation, rotation or scale snap values
268
+
269
+ ```
270
+ editControl.setTransSnapValue(number n in meters);
271
+ editControl.setRotSnapValue(number n in radians);
272
+ editControl.setScaleSnapValue(number n a factor by which scale should increase);
273
+
274
+ editControl.getTransSnapValue();
275
+ editControl.getRotSnapValue();
276
+ editControl.getScaleSnapValue();
277
+ ```
278
+
279
+ #### To bound translation, rotation or scaling
280
+
281
+ This restricts tranlation, rotation,scaling between a minimum and maximum values
282
+
283
+ ```
284
+ setTransBounds(min?: Vector3,max?: Vector3) ;
285
+ setRotBounds(min?: Vector3,max?: Vector3);
286
+ setScaleBounds(min?: Vector3,max?: Vector3);
287
+ ```
288
+
289
+ ```
290
+ removeTransBounds();
291
+ removeRotBounds();
292
+ removeScaleBounds();
293
+ ```
294
+
295
+ Note: rotation bounds has not been implemented. This is on TODO list.
296
+
297
+ #### To undo or redo
298
+
299
+ ```
300
+ editControl.undo();
301
+ editControl.redo();
302
+ ```
303
+
304
+ #### To set undo count
305
+
306
+ By default does upto 10 undos
307
+
308
+ ```
309
+ editControl.setUndoCount(number count);
310
+ ```
311
+
312
+ #### To check if user editing (moving,translating or scaling object)
313
+
314
+ ```
315
+ editControl.isEditing();
316
+ ```
317
+
318
+ returns true if the use is in the process of editing
319
+
320
+ #### To check if the pointer is over the edit control
321
+
322
+ ```
323
+ editControl.isPointeOver();
324
+ ```
325
+
326
+ returns true if the pointer is over the edit control
327
+
328
+ #### To be called back whenever the user starts, takes or ends an action
329
+
330
+ ```
331
+ editControl.addActionStartListener(function(number actionType));
332
+ editControl.addActionListener(function(number actionType));
333
+ editControl.addActionEndListener(function(number actionType));
334
+ ```
335
+
336
+ Each of these take a function as a parameter.
337
+ The ActionStartListener would be called when the user starts translating,rotating or scaling a mesh
338
+ The ActionListener would be called when the user is translating,rotating or scaling a mesh
339
+ The ActionEndListener would be called when the user ends translating,rotating or scaling a mesh
340
+
341
+ When called, these listeners would be passed a number which would indicate the action being taken by the user.
342
+ This number would have one of the following values
343
+ 0 - ActionType.TRANS, Translation
344
+ 1 - ActioneType.ROT, Rotation
345
+ 2 - ActioneType.SCALE, Scaling
346
+
347
+ To remove the listeners
348
+
349
+ ```
350
+ editControl.removeActionStartListener();
351
+ editControl.removeActionListener();
352
+ editControl.removeActionEndListener();
353
+ editControl.removeAllActionListeners() // to remove all;
354
+ ```
355
+
356
+ #### To refresh mesh Bounding Info.
357
+
358
+ EditControl uses mesh bounding info to provide the same smooth scaling experience for both small and large mesh. The bounding info changes when a mesh is baked. Use this method to refresh the bounding info if you baked the transform of the mesh.
359
+
360
+ ```
361
+ editControl.refreshBoundingInfo();
362
+ ```
363
+
364
+ #### To get position and rotaion of EditControl
365
+
366
+ ```
367
+ editControl.getPosition();//returns Vector3
368
+ editControl.getRotationQuaternion(): //returns rotation in quaternion
369
+ ```
370
+
371
+ The postion and rotation of EditControl would be the same as that of the mesh to which it is attached
372
+
373
+ #### To show/hide EditControl
374
+
375
+ ```
376
+ editControl.hide();
377
+ editControl.isHidden(); //turns true or false
378
+ editControl.show();
379
+ ```
380
+
381
+ #### To set visibililty (transparency)
382
+
383
+ ```
384
+ editControl.setVisibility(v:number);
385
+ ```
386
+
387
+ By default the visibility is set to 0.75
388
+
389
+ #### To switch camera
390
+
391
+ ```
392
+ editControl.switchCamera(camera:Camera);
393
+ ```
394
+
395
+ The edit control uses the camera specified during instantiation to control how it is scaled or picked.
396
+ Use this to swicth to a different camera after instantiation.
397
+ You might want to use this for example when the active camera in your scene changes and you want to use the new one for the editcontrol.
398
+
399
+ #### To switch edit control to another mesh
400
+
401
+ ```
402
+ editControl.switchTo(Mesh mesh, optional boolean isEuler );
403
+ ```
404
+
405
+ This quickly removes the edit control from one mesh and attaches it to another mesh.
406
+
407
+ The translation, rotation, scaling mode is maintained.
408
+
409
+ mesh : the mesh to which the control should switch to
410
+ isEuler : true/false, optional, default false, true indicates that rotation of the mesh is in euler
411
+
412
+ #### To detach from the mesh and clean up resources.
413
+
414
+ ```
415
+ editControl.detach();
416
+ ```
417
+
418
+ ## Build and Test
419
+
420
+ If not already installed, install node js.
421
+ Switch to the project folder.
422
+ Run "npm install", once, to install all the dependencies.
423
+
424
+ ### Build
425
+
426
+ Run "npm run build" - this will compile the files in "src" and create a development module in the "dist" folder.
427
+ Run "npm run build-prod" - this will compile and create a minified production module in the "dist" folder.
428
+
429
+ ### To test
430
+
431
+ Two ways to test.
432
+
433
+ 1. using the webpack-dev-server.
434
+ Start the development server
435
+ "npm run start"
436
+ This will start the live dev server on port 8080 (could be different if this port is already in use) and open the browser with the file http://localhost:8080/tst/test.html.
437
+ The dev server will live compile your code any time you make changes.
438
+ Note: The dev server does not write the build to disk, instead it serves it from memory. In our case the build, "EditControl.max.js", is served from location http://localhost:8080/dist. (see publicPath in wepack.config.js file).
439
+
440
+ 2. using any other http server.
441
+ Start the server , say http-server, from the project root folder (not from within "/tst " folder).
442
+ Goto http://localhost:8080/tst/test.html (assuming the server was started on port 8080).
443
+ Everytime you make changes you will have to build using "npm start build-dev".
444
+
445
+ ## Note:
446
+
447
+ The original version was written in Java and then transpiled to TypeScript/JavaScript using JSweet.
448
+ It was originally written in Java, as at that time I wasn't very comfortable with the TypeScript language and its ecosystem.
449
+ Over time I have become more comfortable with it.
450
+ The new version is thus written in TypeScript.
451
+ It is based on the initial TypeScript code generated by JSweet.
452
+ Porting to Typescript was easy, as JSweet generates good human readable TypeScript which allows one to switch to TypeScript at any time.
453
+ For those interested, the old java version is still available at [https://github.com/ssatguru/BabylonJS-EditControl.java](https://github.com/ssatguru/BabylonJS-EditControl.java)