babylonjs-editcontrol 3.2.4 → 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,339 +1,453 @@
1
- # BabylonJS-EditControl
2
- An edit control for use in [BabylonJS](http://www.babylonjs.com/) (a 3D HTML Webgl framework) applications.
3
-
4
- ## About
5
- All 3d editors provide a widget, also referred to as transform control, to translate, rotate or scale 3d objects in the editor.
6
- This EditControl is similar to those widgets.
7
- You can embed this in your Babylonjs application to provide those same capabilities.
8
- It currently supports
9
- * Translate
10
- * Translate Snap
11
- * Rotate
12
- * Rotate Snap
13
- * Scale
14
- * Scale Snap
15
- * Local or Global Translation and Rotation. (Scaling only in local axis)
16
- * Create multiple instances in the same scene with each instance attached to a different mesh
17
- * Scale size of control
18
- * undo, redo
19
-
20
- 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>
21
-
22
- 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>
23
-
24
- ### Breaking change with 3.2.0
25
- Version 3.2.0 converts the project from a plain vanilla JavaScript project to a module based JavaScript project.
26
- With this change, the way to load the application has changed.
27
- In JavaScript, instead of
28
- ```
29
- var EditControl = org.ssatguru.babylonjs.component.EditControl;
30
- editControl = new EditControl(box,camera, canvas, 0.75);
31
- ```
32
- now do
33
- ```
34
- var editControl = new EditControl(box,camera, canvas, 0.75);
35
- ```
36
- In TypeScript, instead of
37
- ```
38
- import EditControl = org.ssatguru.babylonjs.component.EditControl;
39
- ```
40
- now do
41
- ```
42
- import {EditControl} from "babaylonjs-editcontrol";
43
- ```
44
- See below for more details.
45
-
46
- ## Quick start
47
-
48
- 1) add the following dependencies
49
- ```
50
- <script src="https://code.jquery.com/pep/0.4.2/pep.js"></script>
51
- <script src="https://cdn.babylonjs.com/babylon.js"></script>
52
- <script src="EditControl.js"></script>
53
- ```
54
-
55
- See INSTALL below to find where you can get "EditControl.js".
56
-
57
- 2) a small javascript code snippet to get you up and running
58
- ```
59
- //------------------EDIT CONTROL -------------------------------------------------
60
- //create edit control (mesh to attach to, active camera, canvas, scale of editcontrol)
61
- var editControl = new EditControl(box,camera, canvas, 0.75);
62
- //to show translation controls
63
- editControl.enableTranslation();
64
- //set transalation snap value in meters
65
- editControl.setTransSnapValue(0.5
66
- ```
67
-
68
- see sample project here
69
- [https://github.com/ssatguru/BabylonJS-EditControl-Samples/tree/master/sample-global](https://github.com/ssatguru/BabylonJS-EditControl-Samples/tree/master/sample-global)
70
-
71
- ## INSTALL
72
-
73
- You can find the "EditControl.js" from its git repository "dist" folder or "releases" section
74
- [https://github.com/ssatguru/BabylonJS-EditControl/tree/master/dist](https://github.com/ssatguru/BabylonJS-EditControl/tree/master/dist)
75
- [https://github.com/ssatguru/BabylonJS-EditControl/releases](https://github.com/ssatguru/BabylonJS-EditControl/releases)
76
-
77
- You can also install this from npm
78
- ```
79
- npm install babylonjs-editcontrol
80
- ```
81
- ## USAGE
82
-
83
- 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
84
- loaded using the script tag.
85
-
86
- Project "BabylonJS-EditControl-Samples" [https://github.com/ssatguru/BabylonJS-EditControl-Samples](https://github.com/ssatguru/BabylonJS-EditControl-Samples) has a
87
- collection of sample projects to show how to use this from TypeScript, NodeJs, AMD or plain vanilla JavaScript applications.
88
-
89
- Below is a quick summary of how you can use this as different module types.
90
-
91
- CommonJS/NodeJS Module
92
- ```
93
- let BABYLON = require("babylonjs");
94
- let EditControl = require("babylonjs-editcontrol").EditControl;
95
- let engine = new BABYLON.Engine(canvas, true);
96
- ...
97
- let editControl = new EditControl(box,camera, canvas, 0.75);
98
- ...
99
-
100
- ```
101
- AMD Module
102
- ```
103
- <script src="./lib/require.js"></script>
104
- <script>
105
- require.config({
106
- baseUrl: ".",
107
- paths: {
108
- "babylonjs": "./lib/babylon",
109
- "ec": "./lib/EditControl"
110
- }
111
- });
112
-
113
- require(['babylonjs', 'ec'], function (BABYLON, ec) {
114
- let EditControl = ec.EditControl;
115
- let engine = new BABYLON.Engine(canvas, true);
116
- ...
117
- let editControl = new EditControl(box,camera, canvas, 0.75);
118
- ...
119
- });
120
- </script>
121
- ```
122
- Global Module
123
- ```
124
- <script src="./lib/babylon.js"></script>
125
- <script src="./lib/EditControl.js"></script>
126
- <script>
127
- let engine = new BABYLON.Engine(canvas, true);
128
- ...
129
- let editControl = new EditControl(box,camera, canvas, 0.75);
130
- ...
131
- </script>
132
- ```
133
- ## DEPENDENCIES
134
-
135
- * pepjs
136
- * babylonjs
137
-
138
- The two can be installed from npm
139
- ```
140
- npm install babylonjs pepjs
141
- ```
142
- or via cdn
143
- ```
144
- <script src="https://code.jquery.com/pep/0.4.2/pep.js"></script>
145
- <script src="https://cdn.babylonjs.com/babylon.js"></script>
146
- ```
147
-
148
- ## API
149
- #### To Instantiate
150
- ```
151
- // JavaScript
152
- var editControl = new EditControl(mesh,camera, canvas, 0.75, true);
153
- ```
154
- ```
155
- // TypeScript
156
- import {EditControl} from "babaylonjs-editcontrol";
157
- let editControl:EditControl = new EditControl(mesh,camera, canvas, 0.75, true,0.02);
158
- ```
159
- This positions the edit control at the mesh pivot position and displays x,y,z axis.
160
- Takes five parms
161
- * mesh - the mesh to control using the editcontrol
162
- * camera - active camera
163
- * canvas - the mesh canvas
164
- * scale - number. Optional. Default 1. Determines how small or large the editcontrol should appear.
165
- * 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.
166
- * pickWidth - number. Optional. Default 0.02. Determines how close to an axis should the pointer get before we can pick it
167
-
168
-
169
- #### To show Translation, Rotation or Scaling controls
170
- ```
171
- editControl.enableTranslation();
172
-
173
- editControl.enableRotation();
174
- editControl.setRotGuideFull(true/false) //This makes the rotation guides 360 degree(true) or 90 degree(false) .90 degree looks less cluttered.
175
- editControl.returnEuler(true); // Optional. This will return rotation in euler instead of quaternion. Quaternion is the default.
176
-
177
- editControl.enableScaling();
178
- ```
179
- #### To hide Translation, Rotation or Scaling controls (just displays x,y,z axis)
180
- ```
181
- editControl.disableTranslation();
182
- editControl.disableRotation();
183
- editControl.disableScaling();
184
- ```
185
- #### To check if Translation, Rotation or Scaling is enabled
186
- ```
187
- editControl.isTranslationEnabled();
188
- editControl.isRotationEnabled();
189
- editControl.isScalingEnabled();
190
- ```
191
- #### To turn on/off local/ global mode
192
- ```
193
- editControl.setLocal(boolean true/false);
194
- ```
195
- #### To check if local/ global mode
196
- ```
197
- editControl.isLocal();
198
- ```
199
- #### To turn on/off translation, rotation or scale snapping
200
- ```
201
- editControl.setTransSnap(boolean true/false);
202
- editControl.setRotSnap(boolean true/false);
203
- editControl.setScaleSnap(boolean true/false);
204
- ```
205
- #### To set translation, rotation or scale snap values
206
- ```
207
- editControl.setTransSnapValue(number n in meters);
208
- editControl.setRotSnapValue(number n in radians);
209
- editControl.setScaleSnapValue(number n a factor by which scale should increase);
210
- ```
211
- #### To bound translation, rotation or scaling
212
- This restricts tranlation, rotation,scaling between a minimum and maximum values
213
- ```
214
- setTransBounds(min?: Vector3,max?: Vector3) ;
215
- setRotBounds(min?: Vector3,max?: Vector3);
216
- setScaleBounds(min?: Vector3,max?: Vector3);
217
- ```
218
- ```
219
- removeTransBounds();
220
- removeRotBounds();
221
- removeScaleBounds();
222
- ```
223
- Note: rotation bounds has not been implemented. This is on TODO list.
224
- #### To undo or redo
225
- ```
226
- editControl.undo();
227
- editControl.redo();
228
- ```
229
- #### To set undo count
230
-
231
- By default does upto 10 undos
232
- ```
233
- editControl.setUndoCount(number count);
234
- ```
235
- #### To check if user editing (moving,translating or scaling object)
236
- ```
237
- editControl.isEditing();
238
- ```
239
- returns true if the use is in the process of editing
240
-
241
- #### To check if the pointer is over the edit control
242
- ```
243
- editControl.isPointeOver();
244
- ```
245
- returns true if the pointer is over the edit control
246
-
247
- #### To be called back whenever the user starts, takes or ends an action
248
- ```
249
- editControl.addActionStartListener(function(number actionType));
250
- editControl.addActionListener(function(number actionType));
251
- editControl.addActionEndListener(function(number actionType));
252
- ```
253
- Each of these take a function as a parameter.
254
- The ActionStartListener would be called when the user starts translating,rotating or scaling a mesh
255
- The ActionListener would be called when the user is translating,rotating or scaling a mesh
256
- The ActionEndListener would be called when the user ends translating,rotating or scaling a mesh
257
-
258
- When called, these listeners would be passed a number which would indicate the action being taken by the user.
259
- This number would have one of the following values
260
- 0 - ActionType.TRANS, Translation
261
- 1 - ActioneType.ROT, Rotation
262
- 2 - ActioneType.SCALE, Scaling
263
-
264
- To remove the listeners
265
- ```
266
- editControl.removeActionStartListener();
267
- editControl.removeActionListener();
268
- editControl.removeActionEndListener();
269
- editControl.removeAllActionListeners() // to remove all;
270
- ```
271
-
272
- #### To refresh mesh Bounding Info.
273
- 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.
274
- ```
275
- editControl.refreshBoundingInfo();
276
- ```
277
- #### To get position and rotaion of EditControl
278
- ```
279
- editControl.getPosition();//returns Vector3
280
- editControl.getRotationQuaternion(): //returns rotation in quaternion
281
- ```
282
- The postion and rotation of EditControl would be the same as that of the mesh to which it is attached
283
- #### To show/hide EditControl
284
- ```
285
- editControl.hide();
286
- editControl.isHidden(); //turns true or false
287
- editControl.show();
288
- ```
289
- #### To set visibililty (transparency)
290
- ```
291
- editControl.setVisibility(v:number);
292
- ```
293
- By default the visibility is set to 0.75
294
-
295
- #### To switch camera
296
- ```
297
- editControl.switchCamera(camera:Camera);
298
- ```
299
- The edit control uses the camera specified during instantiation to control how it is scaled or picked.
300
- Use this to swicth to a different camera after instantiation.
301
- 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.
302
-
303
- #### To switch edit control to another mesh
304
- ```
305
- editControl.switchTo(Mesh mesh, optional boolean isEuler );
306
- ```
307
- This quickly removes the edit control from one mesh and attaches it to another mesh.
308
-
309
- The translation, rotation, scaling mode is maintained.
310
-
311
- mesh : the mesh to which the control should switch to
312
- isEuler : true/false, optional, default false, true indicates that rotation of the mesh is in euler
313
-
314
- #### To detach from the mesh and clean up resources.
315
- ```
316
- editControl.detach();
317
- ```
318
-
319
- ## Build and Test
320
- If not already installed, install node js.
321
- Switch to the project folder.
322
- Run "npm install", once, to install all the dependencies.
323
- ### Build
324
- Run "npm run build" - this will compile the files in "src" and create a development module in the "dist" folder.
325
- Run "npm run build-prod" - this will compile and create a minified production module in the "dist" folder.
326
- ### Test
327
- Run "npm run start" to start the webpack dev server on localhost:8080. It will watch for any changes and serve out the latest "EditControl.js".
328
- Double click "tst/comprehensive.html" or tst/simple.html" to open them in browser and test your changes.
329
- These two html pull "EditControl.js" from http://localhost:8080.
330
-
331
- ## Note:
332
- The original version was written in Java and then transpiled to TypeScript/JavaScript using JSweet.
333
- It was originally written in Java, as at that time I wasn't very comfortable with the TypeScript language and its ecosystem.
334
- Over time I have become more comfortable with it.
335
- The new version is thus written in TypeScript.
336
- It is based on the initial TypeScript code generated by JSweet.
337
- Porting to Typescript was easy, as JSweet generates good human readable TypeScript which allows one to switch to TypeScript at any time.
338
- 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)
339
-
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)