urdf-loader 0.10.3 → 0.10.5
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 +578 -579
- package/package.json +1 -1
- package/src/URDFClasses.d.ts +66 -66
- package/src/URDFClasses.js +395 -402
- package/src/URDFDragControls.js +329 -329
- package/src/URDFLoader.d.ts +36 -36
- package/src/URDFLoader.js +664 -663
- package/src/urdf-manipulator-element.js +155 -150
- package/src/urdf-viewer-element.js +616 -551
- package/umd/URDFLoader.js +1047 -1053
- package/umd/URDFLoader.js.map +1 -1
- package/umd/urdf-manipulator-element.js +475 -470
- package/umd/urdf-manipulator-element.js.map +1 -1
- package/umd/urdf-viewer-element.js +609 -545
- package/umd/urdf-viewer-element.js.map +1 -1
package/src/URDFClasses.js
CHANGED
|
@@ -1,402 +1,395 @@
|
|
|
1
|
-
import { Object3D, Vector3 } from 'three';
|
|
2
|
-
|
|
3
|
-
class URDFBase extends Object3D {
|
|
4
|
-
|
|
5
|
-
constructor(...args) {
|
|
6
|
-
|
|
7
|
-
super(...args);
|
|
8
|
-
this.urdfNode = null;
|
|
9
|
-
this.urdfName = '';
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
copy(source, recursive) {
|
|
14
|
-
|
|
15
|
-
super.copy(source, recursive);
|
|
16
|
-
|
|
17
|
-
this.urdfNode = source.urdfNode;
|
|
18
|
-
this.urdfName = source.urdfName;
|
|
19
|
-
|
|
20
|
-
return this;
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
class URDFCollider extends URDFBase {
|
|
27
|
-
|
|
28
|
-
constructor(...args) {
|
|
29
|
-
|
|
30
|
-
super(...args);
|
|
31
|
-
this.isURDFCollider = true;
|
|
32
|
-
this.type = 'URDFCollider';
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
class URDFVisual extends URDFBase {
|
|
39
|
-
|
|
40
|
-
constructor(...args) {
|
|
41
|
-
|
|
42
|
-
super(...args);
|
|
43
|
-
this.isURDFVisual = true;
|
|
44
|
-
this.type = 'URDFVisual';
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
class URDFLink extends URDFBase {
|
|
51
|
-
|
|
52
|
-
constructor(...args) {
|
|
53
|
-
|
|
54
|
-
super(...args);
|
|
55
|
-
this.isURDFLink = true;
|
|
56
|
-
this.type = 'URDFLink';
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
class URDFJoint extends URDFBase {
|
|
63
|
-
|
|
64
|
-
get jointType() {
|
|
65
|
-
|
|
66
|
-
return this._jointType;
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
set jointType(v) {
|
|
71
|
-
|
|
72
|
-
if (this.jointType === v) return;
|
|
73
|
-
this._jointType = v;
|
|
74
|
-
this.matrixWorldNeedsUpdate = true;
|
|
75
|
-
switch (v) {
|
|
76
|
-
|
|
77
|
-
case 'fixed':
|
|
78
|
-
this.jointValue = [];
|
|
79
|
-
break;
|
|
80
|
-
|
|
81
|
-
case 'continuous':
|
|
82
|
-
case 'revolute':
|
|
83
|
-
case 'prismatic':
|
|
84
|
-
this.jointValue = new Array(1).fill(0);
|
|
85
|
-
break;
|
|
86
|
-
|
|
87
|
-
case 'planar':
|
|
88
|
-
this.jointValue = new Array(2).fill(0);
|
|
89
|
-
break;
|
|
90
|
-
|
|
91
|
-
case 'floating':
|
|
92
|
-
this.jointValue = new Array(6).fill(0);
|
|
93
|
-
break;
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
get angle() {
|
|
100
|
-
|
|
101
|
-
return this.jointValue[0];
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
constructor(...args) {
|
|
106
|
-
|
|
107
|
-
super(...args);
|
|
108
|
-
|
|
109
|
-
this.isURDFJoint = true;
|
|
110
|
-
this.type = 'URDFJoint';
|
|
111
|
-
|
|
112
|
-
this.jointValue = null;
|
|
113
|
-
this.jointType = 'fixed';
|
|
114
|
-
this.axis = new Vector3(1, 0, 0);
|
|
115
|
-
this.limit = { lower: 0, upper: 0 };
|
|
116
|
-
this.ignoreLimits = false;
|
|
117
|
-
|
|
118
|
-
this.origPosition = null;
|
|
119
|
-
this.origQuaternion = null;
|
|
120
|
-
|
|
121
|
-
this.mimicJoints = [];
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/* Overrides */
|
|
126
|
-
copy(source, recursive) {
|
|
127
|
-
|
|
128
|
-
super.copy(source, recursive);
|
|
129
|
-
|
|
130
|
-
this.jointType = source.jointType;
|
|
131
|
-
this.axis = source.axis.clone();
|
|
132
|
-
this.limit.lower = source.limit.lower;
|
|
133
|
-
this.limit.upper = source.limit.upper;
|
|
134
|
-
this.ignoreLimits = false;
|
|
135
|
-
|
|
136
|
-
this.jointValue = [...source.jointValue];
|
|
137
|
-
|
|
138
|
-
this.origPosition = source.origPosition ? source.origPosition.clone() : null;
|
|
139
|
-
this.origQuaternion = source.origQuaternion ? source.origQuaternion.clone() : null;
|
|
140
|
-
|
|
141
|
-
this.mimicJoints = [...source.mimicJoints];
|
|
142
|
-
|
|
143
|
-
return this;
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/* Public Functions */
|
|
148
|
-
setJointValue(...values) {
|
|
149
|
-
|
|
150
|
-
values = values.map(v => parseFloat(v));
|
|
151
|
-
|
|
152
|
-
if (!this.origPosition || !this.origQuaternion) {
|
|
153
|
-
|
|
154
|
-
this.origPosition = this.position.clone();
|
|
155
|
-
this.origQuaternion = this.quaternion.clone();
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
let didUpdate = false;
|
|
160
|
-
|
|
161
|
-
this.mimicJoints.forEach(joint => {
|
|
162
|
-
|
|
163
|
-
didUpdate = joint.updateFromMimickedJoint(...values) || didUpdate;
|
|
164
|
-
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
switch (this.jointType) {
|
|
168
|
-
|
|
169
|
-
case 'fixed': {
|
|
170
|
-
|
|
171
|
-
return didUpdate;
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
case 'continuous':
|
|
175
|
-
case 'revolute': {
|
|
176
|
-
|
|
177
|
-
let angle = values[0];
|
|
178
|
-
if (angle == null) return didUpdate;
|
|
179
|
-
if (angle === this.jointValue[0]) return didUpdate;
|
|
180
|
-
|
|
181
|
-
if (!this.ignoreLimits && this.jointType === 'revolute') {
|
|
182
|
-
|
|
183
|
-
angle = Math.min(this.limit.upper, angle);
|
|
184
|
-
angle = Math.max(this.limit.lower, angle);
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
this.quaternion
|
|
189
|
-
.setFromAxisAngle(this.axis, angle)
|
|
190
|
-
.premultiply(this.origQuaternion);
|
|
191
|
-
|
|
192
|
-
if (this.jointValue[0] !== angle) {
|
|
193
|
-
|
|
194
|
-
this.jointValue[0] = angle;
|
|
195
|
-
this.matrixWorldNeedsUpdate = true;
|
|
196
|
-
return true;
|
|
197
|
-
|
|
198
|
-
} else {
|
|
199
|
-
|
|
200
|
-
return didUpdate;
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
case 'prismatic': {
|
|
207
|
-
|
|
208
|
-
let pos = values[0];
|
|
209
|
-
if (pos == null) return didUpdate;
|
|
210
|
-
if (pos === this.jointValue[0]) return didUpdate;
|
|
211
|
-
|
|
212
|
-
if (!this.ignoreLimits) {
|
|
213
|
-
|
|
214
|
-
pos = Math.min(this.limit.upper, pos);
|
|
215
|
-
pos = Math.max(this.limit.lower, pos);
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
this.position.copy(this.origPosition);
|
|
220
|
-
this.position.addScaledVector(this.axis, pos);
|
|
221
|
-
|
|
222
|
-
if (this.jointValue[0] !== pos) {
|
|
223
|
-
|
|
224
|
-
this.jointValue[0] = pos;
|
|
225
|
-
this.matrixWorldNeedsUpdate = true;
|
|
226
|
-
return true;
|
|
227
|
-
|
|
228
|
-
} else {
|
|
229
|
-
|
|
230
|
-
return didUpdate;
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
case 'floating':
|
|
237
|
-
case 'planar':
|
|
238
|
-
// TODO: Support these joint types
|
|
239
|
-
console.warn(`'${ this.jointType }' joint not yet supported`);
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return didUpdate;
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
class URDFMimicJoint extends URDFJoint {
|
|
250
|
-
|
|
251
|
-
constructor(...args) {
|
|
252
|
-
|
|
253
|
-
super(...args);
|
|
254
|
-
this.type = 'URDFMimicJoint';
|
|
255
|
-
this.mimicJoint = null;
|
|
256
|
-
this.offset = 0;
|
|
257
|
-
this.multiplier = 1;
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
updateFromMimickedJoint(...values) {
|
|
262
|
-
|
|
263
|
-
const modifiedValues = values.map(x => x * this.multiplier + this.offset);
|
|
264
|
-
return super.setJointValue(...modifiedValues);
|
|
265
|
-
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/* Overrides */
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
this.
|
|
296
|
-
this.
|
|
297
|
-
|
|
298
|
-
this.
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
this.
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
this
|
|
350
|
-
|
|
351
|
-
|
|
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
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
return didChange;
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
export { URDFRobot, URDFLink, URDFJoint, URDFMimicJoint, URDFVisual, URDFCollider };
|
|
1
|
+
import { Object3D, Vector3 } from 'three';
|
|
2
|
+
|
|
3
|
+
class URDFBase extends Object3D {
|
|
4
|
+
|
|
5
|
+
constructor(...args) {
|
|
6
|
+
|
|
7
|
+
super(...args);
|
|
8
|
+
this.urdfNode = null;
|
|
9
|
+
this.urdfName = '';
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
copy(source, recursive) {
|
|
14
|
+
|
|
15
|
+
super.copy(source, recursive);
|
|
16
|
+
|
|
17
|
+
this.urdfNode = source.urdfNode;
|
|
18
|
+
this.urdfName = source.urdfName;
|
|
19
|
+
|
|
20
|
+
return this;
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
class URDFCollider extends URDFBase {
|
|
27
|
+
|
|
28
|
+
constructor(...args) {
|
|
29
|
+
|
|
30
|
+
super(...args);
|
|
31
|
+
this.isURDFCollider = true;
|
|
32
|
+
this.type = 'URDFCollider';
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
class URDFVisual extends URDFBase {
|
|
39
|
+
|
|
40
|
+
constructor(...args) {
|
|
41
|
+
|
|
42
|
+
super(...args);
|
|
43
|
+
this.isURDFVisual = true;
|
|
44
|
+
this.type = 'URDFVisual';
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
class URDFLink extends URDFBase {
|
|
51
|
+
|
|
52
|
+
constructor(...args) {
|
|
53
|
+
|
|
54
|
+
super(...args);
|
|
55
|
+
this.isURDFLink = true;
|
|
56
|
+
this.type = 'URDFLink';
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
class URDFJoint extends URDFBase {
|
|
63
|
+
|
|
64
|
+
get jointType() {
|
|
65
|
+
|
|
66
|
+
return this._jointType;
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
set jointType(v) {
|
|
71
|
+
|
|
72
|
+
if (this.jointType === v) return;
|
|
73
|
+
this._jointType = v;
|
|
74
|
+
this.matrixWorldNeedsUpdate = true;
|
|
75
|
+
switch (v) {
|
|
76
|
+
|
|
77
|
+
case 'fixed':
|
|
78
|
+
this.jointValue = [];
|
|
79
|
+
break;
|
|
80
|
+
|
|
81
|
+
case 'continuous':
|
|
82
|
+
case 'revolute':
|
|
83
|
+
case 'prismatic':
|
|
84
|
+
this.jointValue = new Array(1).fill(0);
|
|
85
|
+
break;
|
|
86
|
+
|
|
87
|
+
case 'planar':
|
|
88
|
+
this.jointValue = new Array(2).fill(0);
|
|
89
|
+
break;
|
|
90
|
+
|
|
91
|
+
case 'floating':
|
|
92
|
+
this.jointValue = new Array(6).fill(0);
|
|
93
|
+
break;
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
get angle() {
|
|
100
|
+
|
|
101
|
+
return this.jointValue[0];
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
constructor(...args) {
|
|
106
|
+
|
|
107
|
+
super(...args);
|
|
108
|
+
|
|
109
|
+
this.isURDFJoint = true;
|
|
110
|
+
this.type = 'URDFJoint';
|
|
111
|
+
|
|
112
|
+
this.jointValue = null;
|
|
113
|
+
this.jointType = 'fixed';
|
|
114
|
+
this.axis = new Vector3(1, 0, 0);
|
|
115
|
+
this.limit = { lower: 0, upper: 0 };
|
|
116
|
+
this.ignoreLimits = false;
|
|
117
|
+
|
|
118
|
+
this.origPosition = null;
|
|
119
|
+
this.origQuaternion = null;
|
|
120
|
+
|
|
121
|
+
this.mimicJoints = [];
|
|
122
|
+
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* Overrides */
|
|
126
|
+
copy(source, recursive) {
|
|
127
|
+
|
|
128
|
+
super.copy(source, recursive);
|
|
129
|
+
|
|
130
|
+
this.jointType = source.jointType;
|
|
131
|
+
this.axis = source.axis.clone();
|
|
132
|
+
this.limit.lower = source.limit.lower;
|
|
133
|
+
this.limit.upper = source.limit.upper;
|
|
134
|
+
this.ignoreLimits = false;
|
|
135
|
+
|
|
136
|
+
this.jointValue = [...source.jointValue];
|
|
137
|
+
|
|
138
|
+
this.origPosition = source.origPosition ? source.origPosition.clone() : null;
|
|
139
|
+
this.origQuaternion = source.origQuaternion ? source.origQuaternion.clone() : null;
|
|
140
|
+
|
|
141
|
+
this.mimicJoints = [...source.mimicJoints];
|
|
142
|
+
|
|
143
|
+
return this;
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/* Public Functions */
|
|
148
|
+
setJointValue(...values) {
|
|
149
|
+
|
|
150
|
+
values = values.map(v => parseFloat(v));
|
|
151
|
+
|
|
152
|
+
if (!this.origPosition || !this.origQuaternion) {
|
|
153
|
+
|
|
154
|
+
this.origPosition = this.position.clone();
|
|
155
|
+
this.origQuaternion = this.quaternion.clone();
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
let didUpdate = false;
|
|
160
|
+
|
|
161
|
+
this.mimicJoints.forEach(joint => {
|
|
162
|
+
|
|
163
|
+
didUpdate = joint.updateFromMimickedJoint(...values) || didUpdate;
|
|
164
|
+
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
switch (this.jointType) {
|
|
168
|
+
|
|
169
|
+
case 'fixed': {
|
|
170
|
+
|
|
171
|
+
return didUpdate;
|
|
172
|
+
|
|
173
|
+
}
|
|
174
|
+
case 'continuous':
|
|
175
|
+
case 'revolute': {
|
|
176
|
+
|
|
177
|
+
let angle = values[0];
|
|
178
|
+
if (angle == null) return didUpdate;
|
|
179
|
+
if (angle === this.jointValue[0]) return didUpdate;
|
|
180
|
+
|
|
181
|
+
if (!this.ignoreLimits && this.jointType === 'revolute') {
|
|
182
|
+
|
|
183
|
+
angle = Math.min(this.limit.upper, angle);
|
|
184
|
+
angle = Math.max(this.limit.lower, angle);
|
|
185
|
+
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
this.quaternion
|
|
189
|
+
.setFromAxisAngle(this.axis, angle)
|
|
190
|
+
.premultiply(this.origQuaternion);
|
|
191
|
+
|
|
192
|
+
if (this.jointValue[0] !== angle) {
|
|
193
|
+
|
|
194
|
+
this.jointValue[0] = angle;
|
|
195
|
+
this.matrixWorldNeedsUpdate = true;
|
|
196
|
+
return true;
|
|
197
|
+
|
|
198
|
+
} else {
|
|
199
|
+
|
|
200
|
+
return didUpdate;
|
|
201
|
+
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
case 'prismatic': {
|
|
207
|
+
|
|
208
|
+
let pos = values[0];
|
|
209
|
+
if (pos == null) return didUpdate;
|
|
210
|
+
if (pos === this.jointValue[0]) return didUpdate;
|
|
211
|
+
|
|
212
|
+
if (!this.ignoreLimits) {
|
|
213
|
+
|
|
214
|
+
pos = Math.min(this.limit.upper, pos);
|
|
215
|
+
pos = Math.max(this.limit.lower, pos);
|
|
216
|
+
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
this.position.copy(this.origPosition);
|
|
220
|
+
this.position.addScaledVector(this.axis, pos);
|
|
221
|
+
|
|
222
|
+
if (this.jointValue[0] !== pos) {
|
|
223
|
+
|
|
224
|
+
this.jointValue[0] = pos;
|
|
225
|
+
this.matrixWorldNeedsUpdate = true;
|
|
226
|
+
return true;
|
|
227
|
+
|
|
228
|
+
} else {
|
|
229
|
+
|
|
230
|
+
return didUpdate;
|
|
231
|
+
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
case 'floating':
|
|
237
|
+
case 'planar':
|
|
238
|
+
// TODO: Support these joint types
|
|
239
|
+
console.warn(`'${ this.jointType }' joint not yet supported`);
|
|
240
|
+
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return didUpdate;
|
|
244
|
+
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
class URDFMimicJoint extends URDFJoint {
|
|
250
|
+
|
|
251
|
+
constructor(...args) {
|
|
252
|
+
|
|
253
|
+
super(...args);
|
|
254
|
+
this.type = 'URDFMimicJoint';
|
|
255
|
+
this.mimicJoint = null;
|
|
256
|
+
this.offset = 0;
|
|
257
|
+
this.multiplier = 1;
|
|
258
|
+
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
updateFromMimickedJoint(...values) {
|
|
262
|
+
|
|
263
|
+
const modifiedValues = values.map(x => x * this.multiplier + this.offset);
|
|
264
|
+
return super.setJointValue(...modifiedValues);
|
|
265
|
+
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/* Overrides */
|
|
269
|
+
copy(source, recursive) {
|
|
270
|
+
|
|
271
|
+
super.copy(source, recursive);
|
|
272
|
+
|
|
273
|
+
this.mimicJoint = source.mimicJoint;
|
|
274
|
+
this.offset = source.offset;
|
|
275
|
+
this.multiplier = source.multiplier;
|
|
276
|
+
|
|
277
|
+
return this;
|
|
278
|
+
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
class URDFRobot extends URDFLink {
|
|
284
|
+
|
|
285
|
+
constructor(...args) {
|
|
286
|
+
|
|
287
|
+
super(...args);
|
|
288
|
+
this.isURDFRobot = true;
|
|
289
|
+
this.urdfNode = null;
|
|
290
|
+
|
|
291
|
+
this.urdfRobotNode = null;
|
|
292
|
+
this.robotName = null;
|
|
293
|
+
|
|
294
|
+
this.links = null;
|
|
295
|
+
this.joints = null;
|
|
296
|
+
this.colliders = null;
|
|
297
|
+
this.visual = null;
|
|
298
|
+
this.frames = null;
|
|
299
|
+
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
copy(source, recursive) {
|
|
303
|
+
|
|
304
|
+
super.copy(source, recursive);
|
|
305
|
+
|
|
306
|
+
this.urdfRobotNode = source.urdfRobotNode;
|
|
307
|
+
this.robotName = source.robotName;
|
|
308
|
+
|
|
309
|
+
this.links = {};
|
|
310
|
+
this.joints = {};
|
|
311
|
+
this.colliders = {};
|
|
312
|
+
this.visual = {};
|
|
313
|
+
|
|
314
|
+
this.traverse(c => {
|
|
315
|
+
|
|
316
|
+
if (c.isURDFJoint && c.urdfName in source.joints) {
|
|
317
|
+
|
|
318
|
+
this.joints[c.urdfName] = c;
|
|
319
|
+
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (c.isURDFLink && c.urdfName in source.links) {
|
|
323
|
+
|
|
324
|
+
this.links[c.urdfName] = c;
|
|
325
|
+
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (c.isURDFCollider && c.urdfName in source.colliders) {
|
|
329
|
+
|
|
330
|
+
this.colliders[c.urdfName] = c;
|
|
331
|
+
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (c.isURDFVisual && c.urdfName in source.visual) {
|
|
335
|
+
|
|
336
|
+
this.visual[c.urdfName] = c;
|
|
337
|
+
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
this.frames = {
|
|
343
|
+
...this.colliders,
|
|
344
|
+
...this.visual,
|
|
345
|
+
...this.links,
|
|
346
|
+
...this.joints,
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
return this;
|
|
350
|
+
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
getFrame(name) {
|
|
354
|
+
|
|
355
|
+
return this.frames[name];
|
|
356
|
+
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
setJointValue(jointName, ...angle) {
|
|
360
|
+
|
|
361
|
+
const joint = this.joints[jointName];
|
|
362
|
+
if (joint) {
|
|
363
|
+
|
|
364
|
+
return joint.setJointValue(...angle);
|
|
365
|
+
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
setJointValues(values) {
|
|
372
|
+
|
|
373
|
+
let didChange = false;
|
|
374
|
+
for (const name in values) {
|
|
375
|
+
|
|
376
|
+
const value = values[name];
|
|
377
|
+
if (Array.isArray(value)) {
|
|
378
|
+
|
|
379
|
+
didChange = this.setJointValue(name, ...value) || didChange;
|
|
380
|
+
|
|
381
|
+
} else {
|
|
382
|
+
|
|
383
|
+
didChange = this.setJointValue(name, value) || didChange;
|
|
384
|
+
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
return didChange;
|
|
390
|
+
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
export { URDFRobot, URDFLink, URDFJoint, URDFMimicJoint, URDFVisual, URDFCollider };
|