@operato/scene-urdf 10.0.0-beta.2 → 10.0.0-beta.22

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.
Files changed (68) hide show
  1. package/README.md +22 -25
  2. package/TODO.md +58 -0
  3. package/dist/editors/index.d.ts +7 -0
  4. package/dist/editors/index.js +12 -1
  5. package/dist/editors/index.js.map +1 -1
  6. package/dist/editors/property-editor-urdf-joints.d.ts +54 -0
  7. package/dist/editors/property-editor-urdf-joints.js +246 -0
  8. package/dist/editors/property-editor-urdf-joints.js.map +1 -0
  9. package/dist/editors/property-editor-urdf-preset.d.ts +8 -0
  10. package/dist/editors/property-editor-urdf-preset.js +114 -0
  11. package/dist/editors/property-editor-urdf-preset.js.map +1 -0
  12. package/dist/index.d.ts +8 -2
  13. package/dist/index.js +22 -2
  14. package/dist/index.js.map +1 -1
  15. package/dist/joint-controller.d.ts +35 -0
  16. package/dist/joint-controller.js +34 -0
  17. package/dist/joint-controller.js.map +1 -0
  18. package/dist/real-object-urdf.d.ts +106 -0
  19. package/dist/real-object-urdf.js +527 -0
  20. package/dist/real-object-urdf.js.map +1 -0
  21. package/dist/smoothing-controller.d.ts +15 -0
  22. package/dist/smoothing-controller.js +88 -0
  23. package/dist/smoothing-controller.js.map +1 -0
  24. package/dist/templates/index.d.ts +3 -0
  25. package/dist/templates/index.js +2 -3
  26. package/dist/templates/index.js.map +1 -1
  27. package/dist/templates/{urdf-controller.d.ts → urdf.d.ts} +3 -0
  28. package/dist/templates/urdf.js +19 -0
  29. package/dist/templates/urdf.js.map +1 -0
  30. package/dist/urdf-object.d.ts +264 -0
  31. package/dist/urdf-object.js +190 -0
  32. package/dist/urdf-object.js.map +1 -0
  33. package/dist/urdf-presets.d.ts +22 -0
  34. package/dist/urdf-presets.js +176 -0
  35. package/dist/urdf-presets.js.map +1 -0
  36. package/icons/urdf.png +0 -0
  37. package/package.json +5 -4
  38. package/translations/en.json +10 -16
  39. package/translations/ja.json +10 -16
  40. package/translations/ko.json +10 -16
  41. package/translations/ms.json +10 -16
  42. package/translations/zh.json +10 -16
  43. package/dist/elements/drag-n-drop.d.ts +0 -2
  44. package/dist/elements/drag-n-drop.js +0 -126
  45. package/dist/elements/drag-n-drop.js.map +0 -1
  46. package/dist/elements/urdf-controller-element.d.ts +0 -12
  47. package/dist/elements/urdf-controller-element.js +0 -283
  48. package/dist/elements/urdf-controller-element.js.map +0 -1
  49. package/dist/elements/urdf-drag-controls.d.ts +0 -32
  50. package/dist/elements/urdf-drag-controls.js +0 -197
  51. package/dist/elements/urdf-drag-controls.js.map +0 -1
  52. package/dist/elements/urdf-manipulator-element.d.ts +0 -15
  53. package/dist/elements/urdf-manipulator-element.js +0 -112
  54. package/dist/elements/urdf-manipulator-element.js.map +0 -1
  55. package/dist/elements/urdf-viewer-element.d.ts +0 -53
  56. package/dist/elements/urdf-viewer-element.js +0 -414
  57. package/dist/elements/urdf-viewer-element.js.map +0 -1
  58. package/dist/templates/urdf-controller.js +0 -16
  59. package/dist/templates/urdf-controller.js.map +0 -1
  60. package/dist/templates/urdf-viewer.d.ts +0 -14
  61. package/dist/templates/urdf-viewer.js +0 -16
  62. package/dist/templates/urdf-viewer.js.map +0 -1
  63. package/dist/urdf-controller.d.ts +0 -15
  64. package/dist/urdf-controller.js +0 -70
  65. package/dist/urdf-controller.js.map +0 -1
  66. package/dist/urdf-viewer.d.ts +0 -16
  67. package/dist/urdf-viewer.js +0 -202
  68. package/dist/urdf-viewer.js.map +0 -1
@@ -1,283 +0,0 @@
1
- import { __decorate } from "tslib";
2
- import { LitElement, css, html } from 'lit';
3
- import { customElement, property } from 'lit/decorators.js';
4
- import * as THREE from 'three';
5
- import { registerDragEvents } from './drag-n-drop.js';
6
- import { ScrollbarStyles } from '@operato/styles';
7
- const DEG2RAD = Math.PI / 180;
8
- const RAD2DEG = 1 / DEG2RAD;
9
- let URDFControllerElement = class URDFControllerElement extends LitElement {
10
- static styles = [
11
- ScrollbarStyles,
12
- css `
13
- :host {
14
- display: flex;
15
- flex-direction: column;
16
- width: 100%;
17
- margin: 15px 0;
18
- overflow: hidden;
19
- user-select: none;
20
- }
21
-
22
- :host > * {
23
- margin: 5px 0;
24
- }
25
-
26
- input[type='number'] {
27
- color: white;
28
- border: none;
29
- font-weight: 300;
30
- background: rgba(255, 255, 255, 0.25);
31
- padding: 1px 2px;
32
- }
33
-
34
- ul {
35
- list-style: none;
36
- padding: 0;
37
- margin: 0;
38
- }
39
-
40
- input[type='range'] {
41
- -webkit-appearance: none;
42
- border: none;
43
- outline: none;
44
- width: 100%;
45
- flex: 1;
46
- height: 16px;
47
- background-color: transparent;
48
- }
49
- input[type='range']::-webkit-slider-runnable-track {
50
- width: 100%;
51
- height: 1px;
52
- background: white;
53
- border: none;
54
- border-radius: 5px;
55
- }
56
- input[type='range']::-webkit-slider-thumb {
57
- -webkit-appearance: none;
58
- border: none;
59
- height: 10px;
60
- width: 10px;
61
- border-radius: 50%;
62
- background: white;
63
- margin-top: -5px;
64
- }
65
- input[type='range']:focus {
66
- outline: none;
67
- }
68
- input[type='range']:focus::-webkit-slider-runnable-track {
69
- background: white;
70
- }
71
-
72
- input[type='range']::-moz-range-track {
73
- width: 100%;
74
- height: 1px;
75
- background: white;
76
- border: none;
77
- border-radius: 5px;
78
- }
79
- input[type='range']::-moz-range-thumb {
80
- border: none;
81
- height: 10px;
82
- width: 10px;
83
- border-radius: 50%;
84
- background: white;
85
- }
86
-
87
- input[type='range']:-moz-focusring {
88
- outline: 1px solid white;
89
- outline-offset: -1px;
90
- }
91
-
92
- input[type='range']::-ms-track {
93
- width: 100%;
94
- height: 1px;
95
- background: white;
96
- border-radius: 10px;
97
- color: transparent;
98
- border: none;
99
- outline: none;
100
- }
101
- input[type='range']::-ms-thumb {
102
- height: 10px;
103
- width: 10px;
104
- border-radius: 50%;
105
- background: white;
106
- border: none;
107
- outline: none;
108
- margin-top: 2px;
109
- }
110
-
111
- input:focus {
112
- outline: none;
113
- opacity: 1;
114
- }
115
-
116
- /* list of joint sliders */
117
- ul {
118
- flex: 1;
119
- overflow-y: auto;
120
- }
121
-
122
- li {
123
- font-size: 16px;
124
- display: flex;
125
- align-items: center;
126
- padding: 1px 0;
127
-
128
- width: 100%;
129
- user-select: text;
130
-
131
- transition: background 0.25s ease;
132
- }
133
-
134
- li[robot-hovered] {
135
- background: rgba(255, 255, 255, 0.35);
136
- }
137
-
138
- li:hover {
139
- background: rgba(255, 255, 255, 0.35);
140
- }
141
-
142
- li span {
143
- padding: 0 5px;
144
- max-width: 125px;
145
- text-overflow: ellipsis;
146
- overflow: hidden;
147
- }
148
-
149
- li input[type='number'] {
150
- width: 50px;
151
- overflow: hidden;
152
- }
153
- `
154
- ];
155
- viewer;
156
- robot;
157
- render() {
158
- const { joints = {} } = this.robot || {};
159
- const { ignoreLimits = false } = this.viewer || {};
160
- const jointsArray = Object.values(joints);
161
- return html `
162
- <ul>
163
- ${jointsArray.map(joint => {
164
- var { jointType, name, angle, limit } = joint;
165
- var degVal = Number(angle || 0);
166
- if (jointType === 'revolute' || jointType === 'continuous') {
167
- degVal *= RAD2DEG;
168
- }
169
- if (Math.abs(degVal) > 1) {
170
- degVal = degVal.toFixed(1);
171
- }
172
- else {
173
- degVal = degVal.toPrecision(2);
174
- }
175
- var sliderMin;
176
- var sliderMax;
177
- var inputMin;
178
- var inputMax;
179
- if (ignoreLimits || jointType === 'continuous') {
180
- sliderMin = -6.28;
181
- sliderMax = 6.28;
182
- inputMin = -6.28 * RAD2DEG;
183
- inputMax = 6.28 * RAD2DEG;
184
- }
185
- else {
186
- sliderMin = limit.lower;
187
- sliderMax = limit.upper;
188
- inputMin = Number(limit.lower) * RAD2DEG;
189
- inputMax = Number(limit.upper) * RAD2DEG;
190
- }
191
- return html `
192
- <li joint-type=${jointType} joint-name=${name}>
193
- <span title=${name}>${name}</span>
194
- <input
195
- type="range"
196
- .value=${String(angle)}
197
- step="0.0001"
198
- min=${sliderMin}
199
- max=${sliderMax}
200
- @input=${(e) => {
201
- this.viewer?.setJointValue(name, e.target.value);
202
- }}
203
- />
204
- <input
205
- type="number"
206
- .value=${degVal}
207
- step="0.0001"
208
- min=${inputMin}
209
- max=${inputMax}
210
- @change=${(e) => {
211
- this.viewer?.setJointValue(name, Number(e.target.value) * DEG2RAD);
212
- }}
213
- />
214
- </li>
215
- `;
216
- })}
217
- </ul>
218
- `;
219
- }
220
- updated(changes) {
221
- if (changes.has('viewer')) {
222
- this._setupViewer(this.viewer);
223
- }
224
- }
225
- _setupViewer(viewer) {
226
- if (!viewer) {
227
- return;
228
- }
229
- this.robot = viewer.robot;
230
- viewer.addEventListener('urdf-processed', () => {
231
- this.robot = viewer.robot;
232
- });
233
- viewer.addEventListener('ignore-limits-change', () => {
234
- this.requestUpdate();
235
- });
236
- viewer.addEventListener('angle-change', (e) => {
237
- this.requestUpdate();
238
- });
239
- viewer.addEventListener('joint-mouseover', (e) => {
240
- const j = this.renderRoot.querySelector(`li[joint-name="${e.detail}"]`);
241
- if (j) {
242
- j.setAttribute('robot-hovered', 'true');
243
- }
244
- });
245
- viewer.addEventListener('joint-mouseout', (e) => {
246
- const j = this.renderRoot.querySelector(`li[joint-name="${e.detail}"]`);
247
- if (j) {
248
- j.removeAttribute('robot-hovered');
249
- }
250
- });
251
- let originalNoAutoRecenter;
252
- viewer.addEventListener('manipulate-start', (e) => {
253
- const j = this.renderRoot.querySelector(`li[joint-name="${e.detail}"]`);
254
- if (j) {
255
- // ??
256
- j.scrollIntoView({ block: 'nearest' });
257
- window.scrollTo(0, 0);
258
- }
259
- originalNoAutoRecenter = viewer.noAutoRecenter;
260
- viewer.noAutoRecenter = true;
261
- });
262
- viewer.addEventListener('manipulate-end', (e) => {
263
- viewer.noAutoRecenter = originalNoAutoRecenter;
264
- });
265
- registerDragEvents(viewer, () => {
266
- this.setColor('#263238');
267
- });
268
- }
269
- setColor(color) {
270
- this.viewer.highlightColor = '#' + new THREE.Color(0xffffff).lerp(new THREE.Color(color), 0.35).getHexString();
271
- }
272
- };
273
- __decorate([
274
- property({ type: Object })
275
- ], URDFControllerElement.prototype, "viewer", void 0);
276
- __decorate([
277
- property({ type: Object })
278
- ], URDFControllerElement.prototype, "robot", void 0);
279
- URDFControllerElement = __decorate([
280
- customElement('urdf-controller')
281
- ], URDFControllerElement);
282
- export default URDFControllerElement;
283
- //# sourceMappingURL=urdf-controller-element.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"urdf-controller-element.js","sourceRoot":"","sources":["../../src/elements/urdf-controller-element.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAkB,MAAM,KAAK,CAAA;AAC3D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAIjD,MAAM,OAAO,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,CAAA;AAC7B,MAAM,OAAO,GAAG,CAAC,GAAG,OAAO,CAAA;AAGZ,IAAM,qBAAqB,GAA3B,MAAM,qBAAsB,SAAQ,UAAU;IAC3D,MAAM,CAAC,MAAM,GAAG;QACd,eAAe;QACf,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA6IF;KACF,CAAA;IAE2B,MAAM,CAAyB;IAC/B,KAAK,CAAY;IAE7C,MAAM;QACJ,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAA;QACxC,MAAM,EAAE,YAAY,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC,MA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,GAAG,sBAAsB,CAAA;QAChD,CAAC,CAAC,CAAA;QAEF,kBAAkB,CAAC,MAAM,EAAE,GAAG,EAAE;YAC9B,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;QAC1B,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,QAAQ,CAAC,KAAa;QACpB,IAAI,CAAC,MAAO,CAAC,cAAc,GAAG,GAAG,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC,YAAY,EAAE,CAAA;IACjH,CAAC;;AAxI2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;qDAAgC;AAC/B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oDAAkB;AApJ1B,qBAAqB;IADzC,aAAa,CAAC,iBAAiB,CAAC;GACZ,qBAAqB,CA4RzC;eA5RoB,qBAAqB","sourcesContent":["import { LitElement, css, html, PropertyValues } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\nimport * as THREE from 'three'\nimport { registerDragEvents } from './drag-n-drop.js'\nimport { ScrollbarStyles } from '@operato/styles'\nimport { URDFRobot } from 'urdf-loader'\nimport URDFManipulatorElement from './urdf-manipulator-element.js'\n\nconst DEG2RAD = Math.PI / 180\nconst RAD2DEG = 1 / DEG2RAD\n\n@customElement('urdf-controller')\nexport default class URDFControllerElement extends LitElement {\n static styles = [\n ScrollbarStyles,\n css`\n :host {\n display: flex;\n flex-direction: column;\n width: 100%;\n margin: 15px 0;\n overflow: hidden;\n user-select: none;\n }\n\n :host > * {\n margin: 5px 0;\n }\n\n input[type='number'] {\n color: white;\n border: none;\n font-weight: 300;\n background: rgba(255, 255, 255, 0.25);\n padding: 1px 2px;\n }\n\n ul {\n list-style: none;\n padding: 0;\n margin: 0;\n }\n\n input[type='range'] {\n -webkit-appearance: none;\n border: none;\n outline: none;\n width: 100%;\n flex: 1;\n height: 16px;\n background-color: transparent;\n }\n input[type='range']::-webkit-slider-runnable-track {\n width: 100%;\n height: 1px;\n background: white;\n border: none;\n border-radius: 5px;\n }\n input[type='range']::-webkit-slider-thumb {\n -webkit-appearance: none;\n border: none;\n height: 10px;\n width: 10px;\n border-radius: 50%;\n background: white;\n margin-top: -5px;\n }\n input[type='range']:focus {\n outline: none;\n }\n input[type='range']:focus::-webkit-slider-runnable-track {\n background: white;\n }\n\n input[type='range']::-moz-range-track {\n width: 100%;\n height: 1px;\n background: white;\n border: none;\n border-radius: 5px;\n }\n input[type='range']::-moz-range-thumb {\n border: none;\n height: 10px;\n width: 10px;\n border-radius: 50%;\n background: white;\n }\n\n input[type='range']:-moz-focusring {\n outline: 1px solid white;\n outline-offset: -1px;\n }\n\n input[type='range']::-ms-track {\n width: 100%;\n height: 1px;\n background: white;\n border-radius: 10px;\n color: transparent;\n border: none;\n outline: none;\n }\n input[type='range']::-ms-thumb {\n height: 10px;\n width: 10px;\n border-radius: 50%;\n background: white;\n border: none;\n outline: none;\n margin-top: 2px;\n }\n\n input:focus {\n outline: none;\n opacity: 1;\n }\n\n /* list of joint sliders */\n ul {\n flex: 1;\n overflow-y: auto;\n }\n\n li {\n font-size: 16px;\n display: flex;\n align-items: center;\n padding: 1px 0;\n\n width: 100%;\n user-select: text;\n\n transition: background 0.25s ease;\n }\n\n li[robot-hovered] {\n background: rgba(255, 255, 255, 0.35);\n }\n\n li:hover {\n background: rgba(255, 255, 255, 0.35);\n }\n\n li span {\n padding: 0 5px;\n max-width: 125px;\n text-overflow: ellipsis;\n overflow: hidden;\n }\n\n li input[type='number'] {\n width: 50px;\n overflow: hidden;\n }\n `\n ]\n\n @property({ type: Object }) viewer?: URDFManipulatorElement\n @property({ type: Object }) robot?: URDFRobot\n\n render() {\n const { joints = {} } = this.robot || {}\n const { ignoreLimits = false } = this.viewer || {}\n const jointsArray = Object.values(joints)\n\n return html`\n <ul>\n ${jointsArray.map(joint => {\n var { jointType, name, angle, limit } = joint\n var degVal: number | string = Number(angle || 0)\n\n if (jointType === 'revolute' || jointType === 'continuous') {\n degVal *= RAD2DEG\n }\n\n if (Math.abs(degVal) > 1) {\n degVal = degVal.toFixed(1)\n } else {\n degVal = degVal.toPrecision(2)\n }\n\n var sliderMin\n var sliderMax\n var inputMin\n var inputMax\n\n if (ignoreLimits || jointType === 'continuous') {\n sliderMin = -6.28\n sliderMax = 6.28\n\n inputMin = -6.28 * RAD2DEG\n inputMax = 6.28 * RAD2DEG\n } else {\n sliderMin = limit.lower\n sliderMax = limit.upper\n\n inputMin = Number(limit.lower) * RAD2DEG\n inputMax = Number(limit.upper) * RAD2DEG\n }\n\n return html`\n <li joint-type=${jointType} joint-name=${name}>\n <span title=${name}>${name}</span>\n <input\n type=\"range\"\n .value=${String(angle)}\n step=\"0.0001\"\n min=${sliderMin}\n max=${sliderMax}\n @input=${(e: Event) => {\n this.viewer?.setJointValue(name, (e.target as any).value)\n }}\n />\n <input\n type=\"number\"\n .value=${degVal}\n step=\"0.0001\"\n min=${inputMin}\n max=${inputMax}\n @change=${(e: Event) => {\n this.viewer?.setJointValue(name, Number((e.target as HTMLInputElement).value) * DEG2RAD)\n }}\n />\n </li>\n `\n })}\n </ul>\n `\n }\n\n updated(changes: PropertyValues<this>) {\n if (changes.has('viewer')) {\n this._setupViewer(this.viewer)\n }\n }\n\n _setupViewer(viewer?: URDFManipulatorElement) {\n if (!viewer) {\n return\n }\n\n this.robot = viewer.robot\n\n viewer.addEventListener('urdf-processed', () => {\n this.robot = viewer.robot\n })\n\n viewer.addEventListener('ignore-limits-change', () => {\n this.requestUpdate()\n })\n\n viewer.addEventListener('angle-change', (e: Event) => {\n this.requestUpdate()\n })\n\n viewer.addEventListener('joint-mouseover', (e: Event) => {\n const j = this.renderRoot.querySelector(`li[joint-name=\"${(e as CustomEvent).detail}\"]`)\n if (j) {\n j.setAttribute('robot-hovered', 'true')\n }\n })\n\n viewer.addEventListener('joint-mouseout', (e: Event) => {\n const j = this.renderRoot.querySelector(`li[joint-name=\"${(e as CustomEvent).detail}\"]`)\n if (j) {\n j.removeAttribute('robot-hovered')\n }\n })\n\n let originalNoAutoRecenter: boolean\n viewer.addEventListener('manipulate-start', (e: Event) => {\n const j = this.renderRoot.querySelector(`li[joint-name=\"${(e as CustomEvent).detail}\"]`)\n if (j) {\n // ??\n j.scrollIntoView({ block: 'nearest' })\n window.scrollTo(0, 0)\n }\n\n originalNoAutoRecenter = viewer.noAutoRecenter\n viewer.noAutoRecenter = true\n })\n\n viewer.addEventListener('manipulate-end', (e: Event) => {\n viewer.noAutoRecenter = originalNoAutoRecenter\n })\n\n registerDragEvents(viewer, () => {\n this.setColor('#263238')\n })\n }\n\n setColor(color: string) {\n this.viewer!.highlightColor = '#' + new THREE.Color(0xffffff).lerp(new THREE.Color(color), 0.35).getHexString()\n }\n}\n"]}
@@ -1,32 +0,0 @@
1
- import { Raycaster, Vector3, Scene, Camera, Ray } from 'three';
2
- import { URDFJoint } from 'urdf-loader';
3
- export declare class URDFDragControls {
4
- scene: Scene;
5
- enabled: boolean;
6
- raycaster: Raycaster;
7
- initialGrabPoint: Vector3;
8
- hitDistance: number;
9
- hovered: any;
10
- manipulating: any;
11
- constructor(scene: Scene);
12
- update(): void;
13
- updateJoint(joint: URDFJoint, angle: number): void;
14
- onDragStart(joint: URDFJoint): void;
15
- onDragEnd(joint: URDFJoint): void;
16
- onHover(joint: URDFJoint): void;
17
- onUnhover(joint: URDFJoint): void;
18
- getRevoluteDelta(joint: URDFJoint, startPoint: Vector3, endPoint: Vector3): number;
19
- getPrismaticDelta(joint: URDFJoint, startPoint: Vector3, endPoint: Vector3): number;
20
- moveRay(toRay: Ray): void;
21
- setGrabbed(grabbed: boolean): void;
22
- }
23
- export declare class PointerURDFDragControls extends URDFDragControls {
24
- camera: Camera;
25
- domElement: HTMLElement;
26
- _mouseDown: (e: MouseEvent) => void;
27
- _mouseMove: (e: MouseEvent) => void;
28
- _mouseUp: (e: MouseEvent) => void;
29
- constructor(scene: Scene, camera: Camera, domElement: HTMLElement);
30
- getRevoluteDelta(joint: URDFJoint, startPoint: Vector3, endPoint: Vector3): number;
31
- dispose(): void;
32
- }
@@ -1,197 +0,0 @@
1
- import { Raycaster, Vector3, Plane, Vector2 } from 'three';
2
- // Find the nearest parent that is a joint
3
- function isJoint(j) {
4
- return j.isURDFJoint && j.jointType !== 'fixed';
5
- }
6
- function findNearestJoint(child) {
7
- let curr = child;
8
- while (curr) {
9
- if (isJoint(curr)) {
10
- return curr;
11
- }
12
- curr = curr.parent;
13
- }
14
- return curr;
15
- }
16
- const prevHitPoint = new Vector3();
17
- const newHitPoint = new Vector3();
18
- const pivotPoint = new Vector3();
19
- const tempVector = new Vector3();
20
- const tempVector2 = new Vector3();
21
- const projectedStartPoint = new Vector3();
22
- const projectedEndPoint = new Vector3();
23
- const plane = new Plane();
24
- export class URDFDragControls {
25
- scene;
26
- enabled;
27
- raycaster;
28
- initialGrabPoint;
29
- hitDistance;
30
- hovered;
31
- manipulating;
32
- constructor(scene) {
33
- this.enabled = true;
34
- this.scene = scene;
35
- this.raycaster = new Raycaster();
36
- this.initialGrabPoint = new Vector3();
37
- this.hitDistance = -1;
38
- this.hovered = null;
39
- this.manipulating = null;
40
- }
41
- update() {
42
- const { raycaster, hovered, manipulating, scene } = this;
43
- if (manipulating) {
44
- return;
45
- }
46
- let hoveredJoint = null;
47
- const intersections = raycaster.intersectObject(scene, true);
48
- if (intersections.length !== 0) {
49
- const hit = intersections[0];
50
- this.hitDistance = hit.distance;
51
- hoveredJoint = findNearestJoint(hit.object);
52
- this.initialGrabPoint.copy(hit.point);
53
- }
54
- if (hoveredJoint !== hovered) {
55
- if (hovered) {
56
- this.onUnhover(hovered);
57
- }
58
- this.hovered = hoveredJoint;
59
- if (hoveredJoint) {
60
- this.onHover(hoveredJoint);
61
- }
62
- }
63
- }
64
- updateJoint(joint, angle) {
65
- joint.setJointValue(angle);
66
- }
67
- onDragStart(joint) { }
68
- onDragEnd(joint) { }
69
- onHover(joint) { }
70
- onUnhover(joint) { }
71
- getRevoluteDelta(joint, startPoint, endPoint) {
72
- // set up the plane
73
- tempVector.copy(joint.axis).transformDirection(joint.matrixWorld).normalize();
74
- pivotPoint.set(0, 0, 0).applyMatrix4(joint.matrixWorld);
75
- plane.setFromNormalAndCoplanarPoint(tempVector, pivotPoint);
76
- // project the drag points onto the plane
77
- plane.projectPoint(startPoint, projectedStartPoint);
78
- plane.projectPoint(endPoint, projectedEndPoint);
79
- // get the directions relative to the pivot
80
- projectedStartPoint.sub(pivotPoint);
81
- projectedEndPoint.sub(pivotPoint);
82
- tempVector.crossVectors(projectedStartPoint, projectedEndPoint);
83
- const direction = Math.sign(tempVector.dot(plane.normal));
84
- return direction * projectedEndPoint.angleTo(projectedStartPoint);
85
- }
86
- getPrismaticDelta(joint, startPoint, endPoint) {
87
- tempVector.subVectors(endPoint, startPoint);
88
- plane.normal.copy(joint.axis).transformDirection(joint.parent.matrixWorld).normalize();
89
- return tempVector.dot(plane.normal);
90
- }
91
- moveRay(toRay) {
92
- const { raycaster, hitDistance, manipulating } = this;
93
- const { ray } = raycaster;
94
- if (manipulating) {
95
- ray.at(hitDistance, prevHitPoint);
96
- toRay.at(hitDistance, newHitPoint);
97
- let delta = 0;
98
- if (manipulating.jointType === 'revolute' || manipulating.jointType === 'continuous') {
99
- delta = this.getRevoluteDelta(manipulating, prevHitPoint, newHitPoint);
100
- }
101
- else if (manipulating.jointType === 'prismatic') {
102
- delta = this.getPrismaticDelta(manipulating, prevHitPoint, newHitPoint);
103
- }
104
- if (delta) {
105
- this.updateJoint(manipulating, manipulating.angle + delta);
106
- }
107
- }
108
- this.raycaster.ray.copy(toRay);
109
- this.update();
110
- }
111
- setGrabbed(grabbed) {
112
- const { hovered, manipulating } = this;
113
- if (grabbed) {
114
- if (manipulating !== null || hovered === null) {
115
- return;
116
- }
117
- this.manipulating = hovered;
118
- this.onDragStart(hovered);
119
- }
120
- else {
121
- if (this.manipulating === null) {
122
- return;
123
- }
124
- this.onDragEnd(this.manipulating);
125
- this.manipulating = null;
126
- this.update();
127
- }
128
- }
129
- }
130
- export class PointerURDFDragControls extends URDFDragControls {
131
- camera;
132
- domElement;
133
- _mouseDown;
134
- _mouseMove;
135
- _mouseUp;
136
- constructor(scene, camera, domElement) {
137
- super(scene);
138
- this.camera = camera;
139
- this.domElement = domElement;
140
- const raycaster = new Raycaster();
141
- const mouse = new Vector2();
142
- function updateMouse(e) {
143
- mouse.x = (e.offsetX / domElement.offsetWidth) * 2 - 1;
144
- mouse.y = -(e.offsetY / domElement.offsetHeight) * 2 + 1;
145
- }
146
- this._mouseDown = (e) => {
147
- updateMouse(e);
148
- raycaster.setFromCamera(mouse, this.camera);
149
- this.moveRay(raycaster.ray);
150
- this.setGrabbed(true);
151
- };
152
- this._mouseMove = (e) => {
153
- updateMouse(e);
154
- raycaster.setFromCamera(mouse, this.camera);
155
- this.moveRay(raycaster.ray);
156
- };
157
- this._mouseUp = (e) => {
158
- updateMouse(e);
159
- raycaster.setFromCamera(mouse, this.camera);
160
- this.moveRay(raycaster.ray);
161
- this.setGrabbed(false);
162
- };
163
- domElement.addEventListener('pointerdown', this._mouseDown);
164
- domElement.addEventListener('pointermove', this._mouseMove);
165
- domElement.addEventListener('pointerup', this._mouseUp);
166
- }
167
- getRevoluteDelta(joint, startPoint, endPoint) {
168
- const { camera, initialGrabPoint } = this;
169
- // set up the plane
170
- tempVector.copy(joint.axis).transformDirection(joint.matrixWorld).normalize();
171
- pivotPoint.set(0, 0, 0).applyMatrix4(joint.matrixWorld);
172
- plane.setFromNormalAndCoplanarPoint(tempVector, pivotPoint);
173
- tempVector.copy(camera.position).sub(initialGrabPoint).normalize();
174
- // if looking into the plane of rotation
175
- if (Math.abs(tempVector.dot(plane.normal)) > 0.3) {
176
- return super.getRevoluteDelta(joint, startPoint, endPoint);
177
- }
178
- else {
179
- // get the up direction
180
- tempVector.set(0, 1, 0).transformDirection(camera.matrixWorld);
181
- // get points projected onto the plane of rotation
182
- plane.projectPoint(startPoint, projectedStartPoint);
183
- plane.projectPoint(endPoint, projectedEndPoint);
184
- tempVector.set(0, 0, -1).transformDirection(camera.matrixWorld);
185
- tempVector.cross(plane.normal);
186
- tempVector2.subVectors(endPoint, startPoint);
187
- return tempVector.dot(tempVector2);
188
- }
189
- }
190
- dispose() {
191
- const { domElement } = this;
192
- domElement.removeEventListener('pointerdown', this._mouseDown);
193
- domElement.removeEventListener('pointermove', this._mouseMove);
194
- domElement.removeEventListener('pointerup', this._mouseUp);
195
- }
196
- }
197
- //# sourceMappingURL=urdf-drag-controls.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"urdf-drag-controls.js","sourceRoot":"","sources":["../../src/elements/urdf-drag-controls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAgC,MAAM,OAAO,CAAA;AAGxF,0CAA0C;AAC1C,SAAS,OAAO,CAAC,CAAY;IAC3B,OAAO,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,SAAS,KAAK,OAAO,CAAA;AACjD,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAe;IACvC,IAAI,IAAI,GAAoB,KAAK,CAAA;IACjC,OAAO,IAAI,EAAE,CAAC;QACZ,IAAI,OAAO,CAAC,IAAiB,CAAC,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAA;QACb,CAAC;QAED,IAAI,GAAG,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,YAAY,GAAG,IAAI,OAAO,EAAE,CAAA;AAClC,MAAM,WAAW,GAAG,IAAI,OAAO,EAAE,CAAA;AACjC,MAAM,UAAU,GAAG,IAAI,OAAO,EAAE,CAAA;AAChC,MAAM,UAAU,GAAG,IAAI,OAAO,EAAE,CAAA;AAChC,MAAM,WAAW,GAAG,IAAI,OAAO,EAAE,CA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AkB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;YAC/D,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;YAC9B,WAAW,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;YAE5C,OAAO,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;QACpC,CAAC;IACH,CAAC;IAED,OAAO;QACL,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAA;QAC3B,UAAU,CAAC,mBAAmB,CAAC,aAAa,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;QAC9D,UAAU,CAAC,mBAAmB,CAAC,aAAa,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;QAC9D,UAAU,CAAC,mBAAmB,CAAC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC5D,CAAC;CACF","sourcesContent":["import { Raycaster, Vector3, Plane, Vector2, Scene, Camera, Object3D, Ray } from 'three'\nimport { URDFJoint } from 'urdf-loader'\n\n// Find the nearest parent that is a joint\nfunction isJoint(j: URDFJoint) {\n return j.isURDFJoint && j.jointType !== 'fixed'\n}\n\nfunction findNearestJoint(child: Object3D) {\n let curr: Object3D | null = child\n while (curr) {\n if (isJoint(curr as URDFJoint)) {\n return curr\n }\n\n curr = curr.parent\n }\n\n return curr\n}\n\nconst prevHitPoint = new Vector3()\nconst newHitPoint = new Vector3()\nconst pivotPoint = new Vector3()\nconst tempVector = new Vector3()\nconst tempVector2 = new Vector3()\nconst projectedStartPoint = new Vector3()\nconst projectedEndPoint = new Vector3()\nconst plane = new Plane()\nexport class URDFDragControls {\n scene: Scene\n\n enabled: boolean\n raycaster: Raycaster\n initialGrabPoint: Vector3\n hitDistance: number\n\n hovered: any\n manipulating: any\n\n constructor(scene: Scene) {\n this.enabled = true\n this.scene = scene\n\n this.raycaster = new Raycaster()\n this.initialGrabPoint = new Vector3()\n\n this.hitDistance = -1\n this.hovered = null\n this.manipulating = null\n }\n\n update() {\n const { raycaster, hovered, manipulating, scene } = this\n\n if (manipulating) {\n return\n }\n\n let hoveredJoint = null\n const intersections = raycaster.intersectObject(scene, true)\n if (intersections.length !== 0) {\n const hit = intersections[0]\n this.hitDistance = hit.distance\n hoveredJoint = findNearestJoint(hit.object)\n this.initialGrabPoint.copy(hit.point)\n }\n\n if (hoveredJoint !== hovered) {\n if (hovered) {\n this.onUnhover(hovered)\n }\n\n this.hovered = hoveredJoint\n\n if (hoveredJoint) {\n this.onHover(hoveredJoint as URDFJoint)\n }\n }\n }\n\n updateJoint(joint: URDFJoint, angle: number) {\n joint.setJointValue(angle)\n }\n\n onDragStart(joint: URDFJoint) {}\n\n onDragEnd(joint: URDFJoint) {}\n\n onHover(joint: URDFJoint) {}\n\n onUnhover(joint: URDFJoint) {}\n\n getRevoluteDelta(joint: URDFJoint, startPoint: Vector3, endPoint: Vector3) {\n // set up the plane\n tempVector.copy(joint.axis).transformDirection(joint.matrixWorld).normalize()\n pivotPoint.set(0, 0, 0).applyMatrix4(joint.matrixWorld)\n plane.setFromNormalAndCoplanarPoint(tempVector, pivotPoint)\n\n // project the drag points onto the plane\n plane.projectPoint(startPoint, projectedStartPoint)\n plane.projectPoint(endPoint, projectedEndPoint)\n\n // get the directions relative to the pivot\n projectedStartPoint.sub(pivotPoint)\n projectedEndPoint.sub(pivotPoint)\n\n tempVector.crossVectors(projectedStartPoint, projectedEndPoint)\n\n const direction = Math.sign(tempVector.dot(plane.normal))\n return direction * projectedEndPoint.angleTo(projectedStartPoint)\n }\n\n getPrismaticDelta(joint: URDFJoint, startPoint: Vector3, endPoint: Vector3) {\n tempVector.subVectors(endPoint, startPoint)\n plane.normal.copy(joint.axis).transformDirection(joint.parent!.matrixWorld).normalize()\n\n return tempVector.dot(plane.normal)\n }\n\n moveRay(toRay: Ray) {\n const { raycaster, hitDistance, manipulating } = this\n const { ray } = raycaster\n\n if (manipulating) {\n ray.at(hitDistance, prevHitPoint)\n toRay.at(hitDistance, newHitPoint)\n\n let delta = 0\n if (manipulating.jointType === 'revolute' || manipulating.jointType === 'continuous') {\n delta = this.getRevoluteDelta(manipulating, prevHitPoint, newHitPoint)\n } else if (manipulating.jointType === 'prismatic') {\n delta = this.getPrismaticDelta(manipulating, prevHitPoint, newHitPoint)\n }\n\n if (delta) {\n this.updateJoint(manipulating, manipulating.angle + delta)\n }\n }\n\n this.raycaster.ray.copy(toRay)\n this.update()\n }\n\n setGrabbed(grabbed: boolean) {\n const { hovered, manipulating } = this\n if (grabbed) {\n if (manipulating !== null || hovered === null) {\n return\n }\n\n this.manipulating = hovered\n this.onDragStart(hovered)\n } else {\n if (this.manipulating === null) {\n return\n }\n\n this.onDragEnd(this.manipulating)\n this.manipulating = null\n this.update()\n }\n }\n}\n\nexport class PointerURDFDragControls extends URDFDragControls {\n camera: Camera\n domElement: HTMLElement\n\n _mouseDown: (e: MouseEvent) => void\n _mouseMove: (e: MouseEvent) => void\n _mouseUp: (e: MouseEvent) => void\n\n constructor(scene: Scene, camera: Camera, domElement: HTMLElement) {\n super(scene)\n\n this.camera = camera\n this.domElement = domElement\n\n const raycaster = new Raycaster()\n const mouse = new Vector2()\n\n function updateMouse(e: MouseEvent) {\n mouse.x = (e.offsetX / domElement.offsetWidth) * 2 - 1\n mouse.y = -(e.offsetY / domElement.offsetHeight) * 2 + 1\n }\n\n this._mouseDown = (e: MouseEvent) => {\n updateMouse(e)\n raycaster.setFromCamera(mouse, this.camera)\n this.moveRay(raycaster.ray)\n this.setGrabbed(true)\n }\n\n this._mouseMove = (e: MouseEvent) => {\n updateMouse(e)\n raycaster.setFromCamera(mouse, this.camera)\n this.moveRay(raycaster.ray)\n }\n\n this._mouseUp = (e: MouseEvent) => {\n updateMouse(e)\n raycaster.setFromCamera(mouse, this.camera)\n this.moveRay(raycaster.ray)\n this.setGrabbed(false)\n }\n\n domElement.addEventListener('pointerdown', this._mouseDown)\n domElement.addEventListener('pointermove', this._mouseMove)\n domElement.addEventListener('pointerup', this._mouseUp)\n }\n\n getRevoluteDelta(joint: URDFJoint, startPoint: Vector3, endPoint: Vector3) {\n const { camera, initialGrabPoint } = this\n\n // set up the plane\n tempVector.copy(joint.axis).transformDirection(joint.matrixWorld).normalize()\n pivotPoint.set(0, 0, 0).applyMatrix4(joint.matrixWorld)\n plane.setFromNormalAndCoplanarPoint(tempVector, pivotPoint)\n\n tempVector.copy(camera.position).sub(initialGrabPoint).normalize()\n\n // if looking into the plane of rotation\n if (Math.abs(tempVector.dot(plane.normal)) > 0.3) {\n return super.getRevoluteDelta(joint, startPoint, endPoint)\n } else {\n // get the up direction\n tempVector.set(0, 1, 0).transformDirection(camera.matrixWorld)\n\n // get points projected onto the plane of rotation\n plane.projectPoint(startPoint, projectedStartPoint)\n plane.projectPoint(endPoint, projectedEndPoint)\n\n tempVector.set(0, 0, -1).transformDirection(camera.matrixWorld)\n tempVector.cross(plane.normal)\n tempVector2.subVectors(endPoint, startPoint)\n\n return tempVector.dot(tempVector2)\n }\n }\n\n dispose() {\n const { domElement } = this\n domElement.removeEventListener('pointerdown', this._mouseDown)\n domElement.removeEventListener('pointermove', this._mouseMove)\n domElement.removeEventListener('pointerup', this._mouseUp)\n }\n}\n"]}
@@ -1,15 +0,0 @@
1
- import { PointerURDFDragControls } from './urdf-drag-controls.js';
2
- import { MeshPhongMaterial } from 'three';
3
- import URDFViewerElement from './urdf-viewer-element.js';
4
- export default class URDFManipulatorElement extends URDFViewerElement {
5
- static get observedAttributes(): string[];
6
- highlightMaterial: MeshPhongMaterial;
7
- dragControls: PointerURDFDragControls;
8
- get disableDragging(): boolean;
9
- set disableDragging(val: boolean);
10
- get highlightColor(): string;
11
- set highlightColor(val: string);
12
- constructor();
13
- disconnectedCallback(): void;
14
- attributeChangedCallback(attr: string, oldval: any, newval: any): void;
15
- }