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