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/LICENSE +201 -201
- package/README.md +478 -436
- package/dist/EditControl.d.ts +323 -315
- package/dist/EditControl.js +1 -1
- package/dist/EditControl.js.map +1 -1
- package/dist/EditControl.max.js +2055 -2124
- package/dist/EditControl.max.js.map +1 -1
- package/package.json +37 -37
- package/src/EditControl.ts +84 -84
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
|
-
|
|
8
|
-
This EditControl is
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
-
|
|
194
|
-
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
editControl.
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
editControl.
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
editControl.
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
editControl.
|
|
258
|
-
editControl.
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
editControl.
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
```
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
To
|
|
331
|
-
|
|
332
|
-
```
|
|
333
|
-
editControl.
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
editControl.
|
|
351
|
-
editControl.
|
|
352
|
-
```
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
#### To
|
|
383
|
-
|
|
384
|
-
```
|
|
385
|
-
editControl.
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
```
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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)
|