@operato/scene-urdf 8.0.0-beta.0 → 8.0.0-beta.2

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@operato/scene-urdf",
3
3
  "description": "Scene module for manipulating robot simulation through URDF format",
4
4
  "author": "heartyoh",
5
- "version": "8.0.0-beta.0",
5
+ "version": "8.0.0-beta.2",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
8
8
  "license": "MIT",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@hatiolab/things-scene": "^8.0.0-beta",
31
- "@operato/styles": "^8.0.0-alpha",
31
+ "@operato/styles": "^8.0.0-beta",
32
32
  "lit": "^3.1.2",
33
33
  "three": "^0.164.0",
34
34
  "urdf-loader": "^0.10.4",
@@ -36,8 +36,8 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@hatiolab/prettier-config": "^1.0.0",
39
- "@things-factory/builder": "^8.0.0-alpha",
40
- "@things-factory/operato-board": "^8.0.0-alpha",
39
+ "@things-factory/builder": "^8.0.0-beta",
40
+ "@things-factory/operato-board": "^8.0.0-beta",
41
41
  "@types/three": "^0.159.0",
42
42
  "@types/tinycolor2": "^1.4.3",
43
43
  "@typescript-eslint/eslint-plugin": "^4.33.0",
@@ -64,5 +64,5 @@
64
64
  "prettier --write"
65
65
  ]
66
66
  },
67
- "gitHead": "b3cf6db1fbdcb9f4feac35560517fec3bb42c493"
67
+ "gitHead": "d6329b4f15ae63c2a99ec5b58ee1d527e88a4c36"
68
68
  }
package/CHANGELOG.md DELETED
@@ -1,370 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- ## [8.0.0-beta.0](https://github.com/things-scene/operato-scene/compare/v8.0.0-alpha.12...v8.0.0-beta.0) (2025-01-07)
7
-
8
-
9
- ### :bug: Bug Fix
10
-
11
- * @hatiolab/things-scene@^8.0.0-beta ([c32f4c0](https://github.com/things-scene/operato-scene/commit/c32f4c00decf244ca82ae17a41e33f269e1882e7))
12
-
13
-
14
-
15
- ## [8.0.0-alpha.1](https://github.com/things-scene/operato-scene/compare/v8.0.0-alpha.0...v8.0.0-alpha.1) (2024-09-09)
16
-
17
-
18
- ### :bug: Bug Fix
19
-
20
- * update [@things-factory](https://github.com/things-factory)@^8.0.0-alpha ([1dc3163](https://github.com/things-scene/operato-scene/commit/1dc31638ed9d3fd0ecb2ac55be0ce541e5599ab8))
21
-
22
-
23
-
24
- ## [8.0.0-alpha.0](https://github.com/things-scene/operato-scene/compare/v7.3.7...v8.0.0-alpha.0) (2024-09-01)
25
-
26
-
27
- ### :bug: Bug Fix
28
-
29
- * dependencies for 8.0.0-alpha.0 ([128676a](https://github.com/things-scene/operato-scene/commit/128676a699896ed403c8ce5620e703042f8e59cf))
30
-
31
-
32
-
33
- ## [7.0.1](https://github.com/things-scene/operato-scene/compare/v7.0.0...v7.0.1) (2024-06-30)
34
-
35
-
36
- ### :bug: Bug Fix
37
-
38
- * things-factory@7.0.0 ([f4cfe44](https://github.com/things-scene/operato-scene/commit/f4cfe44cb565e7b8fdc0df210a722b6526871848))
39
-
40
-
41
-
42
- ## [7.0.0](https://github.com/things-scene/operato-scene/compare/v7.0.0-rc.4...v7.0.0) (2024-06-30)
43
-
44
- **Note:** Version bump only for package @operato/scene-urdf
45
-
46
-
47
-
48
-
49
-
50
- ## [7.0.0-rc.4](https://github.com/things-scene/operato-scene/compare/v7.0.0-rc.3...v7.0.0-rc.4) (2024-06-30)
51
-
52
-
53
- ### :bug: Bug Fix
54
-
55
- * operato@7.0.0 ([9740f89](https://github.com/things-scene/operato-scene/commit/9740f8949654b9dd9388558059e89cbed3d8235a))
56
-
57
-
58
-
59
- ## [7.0.0-rc.1](https://github.com/things-scene/operato-scene/compare/v7.0.0-rc.0...v7.0.0-rc.1) (2024-06-21)
60
-
61
-
62
- ### :bug: Bug Fix
63
-
64
- * apply v7-rc dependencies ([eee5612](https://github.com/things-scene/operato-scene/commit/eee5612e1d569387c284a7c6c49d64ef44b6d701))
65
-
66
-
67
-
68
- ## [7.0.0-rc.0](https://github.com/things-scene/operato-scene/compare/v2.0.0-beta.8...v7.0.0-rc.0) (2024-06-21)
69
-
70
-
71
- ### :bug: Bug Fix
72
-
73
- * apply operato@7.0.0-rc ([7d5fa6e](https://github.com/things-scene/operato-scene/commit/7d5fa6e9bef5f6d2231e4d1eface82578fe794f3))
74
-
75
-
76
-
77
- ## [2.0.0-beta.0](https://github.com/things-scene/operato-scene/compare/v2.0.0-alpha.12...v2.0.0-beta.0) (2024-06-01)
78
-
79
-
80
- ### :rocket: New Features
81
-
82
- * 2.0.0-beta.0 ([a2e2869](https://github.com/things-scene/operato-scene/commit/a2e28694eedf5bab0c54bcab5432d54ec59edd7f))
83
-
84
-
85
- ### :bug: Bug Fix
86
-
87
- * allowJs in tsconfig option ([fa77174](https://github.com/things-scene/operato-scene/commit/fa771742188f21f177f0a85281570f59f0c478cf))
88
-
89
-
90
-
91
- ## [2.0.0-alpha.12](https://github.com/things-scene/operato-scene/compare/v2.0.0-alpha.11...v2.0.0-alpha.12) (2024-05-11)
92
-
93
-
94
- ### :bug: Bug Fix
95
-
96
- * ignore 'cache' folder for git and npm ([d70f811](https://github.com/things-scene/operato-scene/commit/d70f8118ff3e9248f80aa9435d6e6cbb8aacfcaf))
97
-
98
-
99
-
100
- ## [2.0.0-alpha.9](https://github.com/things-scene/operato-scene/compare/v2.0.0-alpha.8...v2.0.0-alpha.9) (2024-04-11)
101
-
102
-
103
- ### :bug: Bug Fix
104
-
105
- * things-factory@7.0.1 ([a9f4c18](https://github.com/things-scene/operato-scene/commit/a9f4c1873b80c540e4c2e16649e127ccffcf9a4c))
106
-
107
-
108
-
109
- ## [2.0.0-alpha.8](https://github.com/things-scene/operato-scene/compare/v2.0.0-alpha.7...v2.0.0-alpha.8) (2024-03-29)
110
-
111
-
112
- ### :bug: Bug Fix
113
-
114
- * upgrade lit ([87e6494](https://github.com/things-scene/operato-scene/commit/87e6494e02a74ec768d0695089aea36184afe572))
115
-
116
-
117
-
118
- ## [2.0.0-alpha.6](https://github.com/things-scene/operato-scene/compare/v2.0.0-alpha.5...v2.0.0-alpha.6) (2024-03-24)
119
-
120
-
121
- ### :bug: Bug Fix
122
-
123
- * translation ([266d423](https://github.com/things-scene/operato-scene/commit/266d423d9d6992464f45a437acc90ccf8ed33bf6))
124
-
125
-
126
-
127
- ## [2.0.0-alpha.4](https://github.com/things-scene/operato-scene/compare/v2.0.0-alpha.3...v2.0.0-alpha.4) (2024-03-21)
128
-
129
-
130
- ### :bug: Bug Fix
131
-
132
- * 컴포넌트 명 다국어 ([64e1f08](https://github.com/things-scene/operato-scene/commit/64e1f08af32d2ac193c3d31b0025f8d06f569ca4))
133
-
134
-
135
-
136
- ## [2.0.0-alpha.3](https://github.com/things-scene/operato-scene/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-04)
137
-
138
-
139
- ### :bug: Bug Fix
140
-
141
- * upgrade three.js ([4319dab](https://github.com/things-scene/operato-scene/commit/4319dabec8a0ae04577ca401db333d9b3303df4f))
142
-
143
-
144
-
145
- ## [2.0.0-alpha.1](https://github.com/things-scene/operato-scene/compare/v2.0.0-alpha.0...v2.0.0-alpha.1) (2024-02-04)
146
-
147
-
148
- ### :bug: Bug Fix
149
-
150
- * upgrade three@161 ([b41788e](https://github.com/things-scene/operato-scene/commit/b41788e7dbe0321c2c8b4dc98126ebc7f97d8285))
151
-
152
-
153
-
154
- ## [2.0.0-alpha.0](https://github.com/things-scene/operato-scene/compare/v1.3.9...v2.0.0-alpha.0) (2024-01-14)
155
-
156
-
157
- ### :bug: Bug Fix
158
-
159
- * 2.0.0-alpha.0 ([93274e3](https://github.com/things-scene/operato-scene/commit/93274e36c5d184f339f83899654dd48b4786ac2b))
160
-
161
-
162
-
163
- ## [1.3.8](https://github.com/things-scene/operato-scene/compare/v1.3.7...v1.3.8) (2024-01-01)
164
-
165
-
166
- ### :bug: Bug Fix
167
-
168
- * upgrade three ([6f0e8f4](https://github.com/things-scene/operato-scene/commit/6f0e8f4faa1f30640468da0755502e8b9a999d0c))
169
-
170
-
171
-
172
- ## [1.3.7](https://github.com/things-scene/operato-scene/compare/v1.3.6...v1.3.7) (2024-01-01)
173
-
174
-
175
- ### :bug: Bug Fix
176
-
177
- * mpi module moved from things-factory ([47b743f](https://github.com/things-scene/operato-scene/commit/47b743fd19001f195db85e50b8f6e457a1573aa5))
178
-
179
-
180
-
181
- ## [1.3.2](https://github.com/things-scene/operato-scene/compare/v1.3.1...v1.3.2) (2023-12-01)
182
-
183
-
184
- ### :bug: Bug Fix
185
-
186
- * upgrade theejs ([55f49c2](https://github.com/things-scene/operato-scene/commit/55f49c23fbaf17c79130b63868e12a685e8039e2))
187
-
188
-
189
-
190
- ## [1.2.90](https://github.com/things-scene/operato-scene/compare/v1.2.89...v1.2.90) (2023-11-22)
191
-
192
- **Note:** Version bump only for package @operato/scene-urdf
193
-
194
-
195
-
196
-
197
-
198
- ## [1.2.88](https://github.com/things-scene/operato-scene/compare/v1.2.87...v1.2.88) (2023-11-12)
199
-
200
-
201
- ### :bug: Bug Fix
202
-
203
- * three@0.158.0 ([8f56203](https://github.com/things-scene/operato-scene/commit/8f5620347e290c53dffc43319e08d77ab66b7caa))
204
-
205
-
206
-
207
- ## [1.2.87](https://github.com/things-scene/operato-scene/compare/v1.2.86...v1.2.87) (2023-11-10)
208
-
209
- **Note:** Version bump only for package @operato/scene-urdf
210
-
211
-
212
-
213
-
214
-
215
- ## [1.2.76](https://github.com/things-scene/operato-scene/compare/v1.2.75...v1.2.76) (2023-10-28)
216
-
217
-
218
- ### :bug: Bug Fix
219
-
220
- * scene-tab ([ad62f96](https://github.com/things-scene/operato-scene/commit/ad62f967b149eb5adf8f2e0714d79e8a9dc7186c))
221
-
222
-
223
-
224
- ## [1.2.70](https://github.com/things-scene/operato-scene/compare/v1.2.69...v1.2.70) (2023-10-06)
225
-
226
-
227
- ### :bug: Bug Fix
228
-
229
- * upgrade three@0.157.0 ([cb6eaf5](https://github.com/things-scene/operato-scene/commit/cb6eaf519d10ba60b0d9aa3ea4aa46e684e3acc2))
230
-
231
-
232
-
233
- ## [1.2.66](https://github.com/things-scene/operato-scene/compare/v1.2.65...v1.2.66) (2023-09-14)
234
-
235
- **Note:** Version bump only for package @operato/scene-urdf
236
-
237
-
238
-
239
-
240
-
241
- ## [1.2.65](https://github.com/things-scene/operato-scene/compare/v1.2.64...v1.2.65) (2023-09-14)
242
-
243
- **Note:** Version bump only for package @operato/scene-urdf
244
-
245
-
246
-
247
-
248
-
249
- ## [1.2.62](https://github.com/things-scene/operato-scene/compare/v1.2.61...v1.2.62) (2023-09-11)
250
-
251
- **Note:** Version bump only for package @operato/scene-urdf
252
-
253
-
254
-
255
-
256
-
257
- ## [1.2.57](https://github.com/things-scene/operato-scene/compare/v1.2.56...v1.2.57) (2023-09-05)
258
-
259
-
260
- ### :bug: Bug Fix
261
-
262
- * revoke three version to 0.152.2 ([cabdaba](https://github.com/things-scene/operato-scene/commit/cabdaba60abd28de261dfbcd1c483793d157bcc3))
263
-
264
-
265
-
266
- ## [1.2.56](https://github.com/things-scene/operato-scene/compare/v1.2.55...v1.2.56) (2023-09-05)
267
-
268
-
269
- ### :bug: Bug Fix
270
-
271
- * upgrade three.js ([e74e5e6](https://github.com/things-scene/operato-scene/commit/e74e5e69910aadcd59f49fcf1f56aec0e8529d48))
272
-
273
-
274
-
275
- ## [1.2.46](https://github.com/things-scene/operato-scene/compare/v1.2.45...v1.2.46) (2023-06-10)
276
-
277
-
278
- ### :bug: Bug Fix
279
-
280
- * typescript build options ([3eb0d7f](https://github.com/things-scene/operato-scene/commit/3eb0d7fd80e2c3cea698501aa1d9d54903423a7b))
281
-
282
-
283
-
284
- ## [1.2.39](https://github.com/things-scene/operato-scene/compare/v1.2.38...v1.2.39) (2023-05-25)
285
-
286
-
287
- ### :bug: Bug Fix
288
-
289
- * add light component into 3d module ([110b312](https://github.com/things-scene/operato-scene/commit/110b3121a0ee6e65bd1cbcffb8254e16c0592460))
290
-
291
-
292
-
293
- ## [1.2.36](https://github.com/things-scene/operato-scene/compare/v1.2.35...v1.2.36) (2023-05-13)
294
-
295
-
296
- ### :bug: Bug Fix
297
-
298
- * license ([d37d485](https://github.com/things-scene/operato-scene/commit/d37d48597407dea1ad022e674f2899720e56d695))
299
-
300
-
301
-
302
- ## [1.2.30](https://github.com/things-scene/operato-scene/compare/v1.2.29...v1.2.30) (2023-04-30)
303
-
304
-
305
- ### :bug: Bug Fix
306
-
307
- * improve performance for visualizer ([d57aa3d](https://github.com/things-scene/operato-scene/commit/d57aa3da34e9539b8d7db89c195af1e2d789e37d))
308
- * update dependencies ([59357a0](https://github.com/things-scene/operato-scene/commit/59357a04eb0211f51db84cb37b0fda0d53c4ec41))
309
-
310
-
311
-
312
- ## [1.2.29](https://github.com/things-scene/operato-scene/compare/v1.2.28...v1.2.29) (2023-04-30)
313
-
314
-
315
- ### :bug: Bug Fix
316
-
317
- * update module's version ([047d08b](https://github.com/things-scene/operato-scene/commit/047d08b5d912d12c04b2f6b63156d1e812588365))
318
-
319
-
320
-
321
- ### [1.2.27](https://github.com/things-scene/operato-scene/compare/v1.2.26...v1.2.27) (2023-04-22)
322
-
323
- **Note:** Version bump only for package @operato/scene-urdf
324
-
325
-
326
-
327
-
328
-
329
- ### [1.2.24](https://github.com/things-scene/operato-scene/compare/v1.2.23...v1.2.24) (2023-04-08)
330
-
331
-
332
- ### :bug: Bug Fix
333
-
334
- * latest three@0.151.3 ([4dfb5f3](https://github.com/things-scene/operato-scene/commit/4dfb5f384b8d299ac56a1237dec21039528f4523))
335
-
336
-
337
-
338
- ### [1.2.11](https://github.com/things-scene/operato-scene/compare/v1.2.10...v1.2.11) (2023-03-03)
339
-
340
-
341
- ### :bug: Bug Fix
342
-
343
- * merge Object3D => RealObject ([201886b](https://github.com/things-scene/operato-scene/commit/201886b135064c1625d5f02a1e85221822d7e449))
344
-
345
-
346
-
347
- ### [1.2.4](https://github.com/things-scene/operato-scene/compare/v1.2.3...v1.2.4) (2023-02-13)
348
-
349
-
350
- ### :bug: Bug Fix
351
-
352
- * [#5](https://github.com/things-scene/operato-scene/issues/5) done ([8de018c](https://github.com/things-scene/operato-scene/commit/8de018c61c3195a557ba69121a4255865dfa2345))
353
-
354
-
355
-
356
- ### [1.2.3](https://github.com/things-scene/operato-scene/compare/v1.2.2...v1.2.3) (2023-02-09)
357
-
358
-
359
- ### :bug: Bug Fix
360
-
361
- * add robot-arm assets for scene-urdf ([a63ce4c](https://github.com/things-scene/operato-scene/commit/a63ce4cc0ecbe6b05ecf94ff6afd82378d04d163))
362
-
363
-
364
-
365
- ### [1.2.2](https://github.com/things-scene/operato-scene/compare/v1.2.1...v1.2.2) (2023-02-09)
366
-
367
-
368
- ### :bug: Bug Fix
369
-
370
- * migrate scene-urdf from things-factory ([3f75f87](https://github.com/things-scene/operato-scene/commit/3f75f8743e993a9a3ed595eed8f94b15da042a31))
package/demo/index.html DELETED
@@ -1,109 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en-GB">
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" />
6
- <style>
7
- body {
8
- margin: 0;
9
- padding: 0;
10
- overflow: hidden;
11
-
12
- /* This is a font-stack that tries to use the system-default sans-serifs first */
13
- font-family: Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
14
- line-height: 1.5;
15
- -webkit-font-smoothing: antialiased;
16
- }
17
-
18
- ox-board-viewer {
19
- width: 100vw;
20
- height: 100vh;
21
- }
22
- </style>
23
- <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet" />
24
- <link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet" />
25
- </head>
26
- <body>
27
- <div id="demo"></div>
28
- <script type="module">
29
- import { html, render } from 'lit'
30
- import { ReferenceMap, create, error } from '@hatiolab/things-scene'
31
- import '@operato/board/ox-board-viewer.js'
32
- import '../dist/simple-switch.js'
33
-
34
- const colors = ['red', 'blue', 'orange', 'yellow', 'magenta', 'violet', 'navy', 'green', 'cyan', 'lime']
35
- const boards = colors.map((color, idx) => {
36
- var to = colors[(idx + 1) % colors.length]
37
- return {
38
- id: color,
39
- model: {
40
- width: 400,
41
- height: 300,
42
- fillStyle: color,
43
- components: [
44
- {
45
- type: 'text',
46
- left: 100,
47
- top: 100,
48
- width: 200,
49
- height: 30,
50
- text: `Click to move to ${to}`,
51
- event: {
52
- tap: {
53
- action: 'goto',
54
- target: to
55
- }
56
- }
57
- },
58
- {
59
- type: 'simple-switch',
60
- left: 100,
61
- top: 200,
62
- width: 100,
63
- height: 30
64
- }
65
- ]
66
- }
67
- }
68
- })
69
-
70
- var provider = new ReferenceMap(
71
- async (boardId, resolve, reject) => {
72
- try {
73
- const board = boards.find(board => {
74
- return board.id === boardId
75
- })
76
- if (!board) {
77
- throw `no board named as ${boardId}`
78
- }
79
-
80
- var scene
81
-
82
- try {
83
- scene = await provider.get(boardId)
84
- console.warn('Board fetched more than twice.', boardId)
85
- } catch (e) {
86
- scene = create({
87
- model: JSON.parse(JSON.stringify(board.model)),
88
- mode: 0,
89
- refProvider: provider
90
- })
91
- }
92
- resolve(scene, board)
93
- } catch (e) {
94
- error(e)
95
- reject(e)
96
- }
97
- },
98
- async (id, ref) => {
99
- ref.dispose()
100
- }
101
- )
102
-
103
- render(
104
- html` <ox-board-viewer .board=${boards[0]} .provider=${provider}></ox-board-viewer> `,
105
- document.querySelector('#demo')
106
- )
107
- </script>
108
- </body>
109
- </html>
File without changes
@@ -1,142 +0,0 @@
1
- // Converts a datatransfer structer into an object with all paths and files
2
-
3
- import URDFViewerElement from './urdf-viewer-element'
4
-
5
- // listed out. Returns a promise that resolves with the file structure.
6
- function dataTransferToFiles(dataTransfer: DataTransfer) {
7
- if (!(dataTransfer instanceof DataTransfer)) {
8
- throw new Error('Data must be of type "DataTransfer"')
9
- }
10
-
11
- const files = {} as any
12
-
13
- // recurse down the webkit file structure resolving
14
- // the paths to files names to store in the `files`
15
- // object
16
- function recurseDirectory(item: any): Promise<void> {
17
- if (item.isFile) {
18
- return new Promise(resolve => {
19
- item.file((file: any) => {
20
- files[item.fullPath] = file
21
- resolve()
22
- })
23
- })
24
- } else {
25
- const reader = item.createReader()
26
-
27
- return new Promise(resolve => {
28
- const promises = [] as any
29
-
30
- // exhaustively read all the directory entries
31
- function readNextEntries() {
32
- reader.readEntries((et: any) => {
33
- if (et.length === 0) {
34
- Promise.all(promises).then(() => resolve())
35
- } else {
36
- et.forEach((e: any) => {
37
- promises.push(recurseDirectory(e))
38
- })
39
- readNextEntries()
40
- }
41
- })
42
- }
43
-
44
- readNextEntries()
45
- })
46
- }
47
- }
48
-
49
- return new Promise(resolve => {
50
- // Traverse down the tree and add the files into the zip
51
- // const dtitems = dataTransfer.items && [...dataTransfer.items]
52
- // const dtfiles = [...dataTransfer.files]
53
- var dtitems = [] as DataTransferItem[]
54
- if (dataTransfer.items) {
55
- for (let i = 0; i < dataTransfer.items.length; i++) {
56
- dtitems.push(dataTransfer.items[i])
57
- }
58
- }
59
-
60
- var dtfiles = [] as File[]
61
- if (dataTransfer.files) {
62
- for (let i = 0; i < dataTransfer.files.length; i++) {
63
- dtfiles.push(dataTransfer.files[i])
64
- }
65
- }
66
-
67
- if (dtitems.length && (dtitems[0].webkitGetAsEntry as any)) {
68
- const promises = []
69
- for (let i = 0; i < dtitems.length; i++) {
70
- const item = dtitems[i]
71
- const entry = item.webkitGetAsEntry()
72
-
73
- promises.push(recurseDirectory(entry))
74
- }
75
- Promise.all(promises).then(() => resolve(files))
76
- } else {
77
- // add a '/' prefix to math the file directory entry
78
- // on webkit browsers
79
- dtfiles.filter(f => f.size !== 0).forEach(f => (files['/' + f.name] = f))
80
-
81
- resolve(files)
82
- }
83
- })
84
- }
85
-
86
- export function registerDragEvents(viewer: URDFViewerElement, callback: () => void) {
87
- document.addEventListener('dragover', e => e.preventDefault())
88
- document.addEventListener('dragenter', e => e.preventDefault())
89
- document.addEventListener('drop', e => {
90
- e.preventDefault()
91
-
92
- // convert the files
93
- dataTransferToFiles(e.dataTransfer!).then((files: any) => {
94
- // removes '..' and '.' tokens and normalizes slashes
95
- const cleanFilePath = (path: string) => {
96
- return path
97
- .replace(/\\/g, '/')
98
- .split(/\//g)
99
- .reduce((acc, el) => {
100
- if (el === '..') acc.pop()
101
- else if (el !== '.') acc.push(el)
102
- return acc
103
- }, [] as string[])
104
- .join('/')
105
- }
106
-
107
- // set the loader url modifier to check the list
108
- // of files
109
- const fileNames = Object.keys(files).map(n => cleanFilePath(n))
110
- viewer.urlModifierFunc = (url: string) => {
111
- // find the matching file given the requested url
112
- const cleaned = cleanFilePath(url.replace(viewer.package, ''))
113
- const fileName = fileNames
114
- .filter(name => {
115
- // check if the end of file and url are the same
116
- const len = Math.min(name.length, cleaned.length)
117
- return cleaned.substr(cleaned.length - len) === name.substr(name.length - len)
118
- })
119
- .pop()
120
-
121
- if (fileName !== undefined) {
122
- // revoke the url after it's been used
123
- const bloburl = URL.createObjectURL(files[fileName])
124
- requestAnimationFrame(() => URL.revokeObjectURL(bloburl))
125
-
126
- return bloburl
127
- }
128
-
129
- return url
130
- }
131
-
132
- // set the source of the element to the most likely intended display model
133
- const filesNames = Object.keys(files)
134
- viewer.up = '+Z'
135
- ;(document.getElementById('up-select') as any)!.value = viewer.up
136
-
137
- viewer.urdf = filesNames.filter(n => /urdf$/i.test(n)).shift()!
138
- })
139
-
140
- callback()
141
- })
142
- }