Skip to content

Commit c794387

Browse files
committed
feat: improve worker fetch logic
1 parent ad0b676 commit c794387

42 files changed

Lines changed: 143 additions & 284 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"access": "public"
3838
},
3939
"devDependencies": {
40-
"@thatopen/fragments": "~3.4.0",
40+
"@thatopen/fragments": "~3.4.2",
4141
"@thatopen/ui": "~3.4.0",
4242
"@types/convert-units": "2.3.11",
4343
"@types/three": "0.183.1",

packages/core/src/core/Clipper/example.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,9 @@ components.init();
4545
Now, let's configure the FragmentsManager. This will allow us to load models effortlessly and start manipulating them with ease:
4646
*/
4747

48-
const githubUrl =
49-
"https://thatopen.github.io/engine_fragment/resources/worker.mjs";
50-
const fetchedUrl = await fetch(githubUrl);
51-
const workerBlob = await fetchedUrl.blob();
52-
const workerFile = new File([workerBlob], "worker.mjs", {
53-
type: "text/javascript",
54-
});
55-
const workerUrl = URL.createObjectURL(workerFile);
48+
// `FragmentsManager.getWorker()` fetches the matching worker for this library version from unpkg and returns a blob URL.
49+
// You can also pass your own URL to `fragments.init(...)` if you'd rather host the worker yourself.
50+
const workerUrl = await OBC.FragmentsManager.getWorker();
5651
const fragments = components.get(OBC.FragmentsManager);
5752
fragments.init(workerUrl);
5853

packages/core/src/core/Grids/example.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,9 @@ components.init();
4545
Now, let's configure the FragmentsManager. This will allow us to load models effortlessly and start manipulating them with ease:
4646
*/
4747

48-
const githubUrl =
49-
"https://thatopen.github.io/engine_fragment/resources/worker.mjs";
50-
const fetchedUrl = await fetch(githubUrl);
51-
const workerBlob = await fetchedUrl.blob();
52-
const workerFile = new File([workerBlob], "worker.mjs", {
53-
type: "text/javascript",
54-
});
55-
const workerUrl = URL.createObjectURL(workerFile);
48+
// `FragmentsManager.getWorker()` fetches the matching worker for this library version from unpkg and returns a blob URL.
49+
// You can also pass your own URL to `fragments.init(...)` if you'd rather host the worker yourself.
50+
const workerUrl = await OBC.FragmentsManager.getWorker();
5651
const fragments = components.get(OBC.FragmentsManager);
5752
fragments.init(workerUrl);
5853

packages/core/src/core/OrthoPerspectiveCamera/example.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,9 @@ const grid = components.get(OBC.Grids).create(world);
4646
Now, let's configure the FragmentsManager. This will allow us to load models effortlessly and start manipulating them with ease:
4747
*/
4848

49-
const githubUrl =
50-
"https://thatopen.github.io/engine_fragment/resources/worker.mjs";
51-
const fetchedUrl = await fetch(githubUrl);
52-
const workerBlob = await fetchedUrl.blob();
53-
const workerFile = new File([workerBlob], "worker.mjs", {
54-
type: "text/javascript",
55-
});
56-
const workerUrl = URL.createObjectURL(workerFile);
49+
// `FragmentsManager.getWorker()` fetches the matching worker for this library version from unpkg and returns a blob URL.
50+
// You can also pass your own URL to `fragments.init(...)` if you'd rather host the worker yourself.
51+
const workerUrl = await OBC.FragmentsManager.getWorker();
5752
const fragments = components.get(OBC.FragmentsManager);
5853
fragments.init(workerUrl);
5954

packages/core/src/core/Raycasters/example.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,9 @@ components.init();
4646
Now, let's configure the FragmentsManager. This will allow us to load models effortlessly and start manipulating them with ease:
4747
*/
4848

49-
const githubUrl =
50-
"https://thatopen.github.io/engine_fragment/resources/worker.mjs";
51-
const fetchedUrl = await fetch(githubUrl);
52-
const workerBlob = await fetchedUrl.blob();
53-
const workerFile = new File([workerBlob], "worker.mjs", {
54-
type: "text/javascript",
55-
});
56-
const workerUrl = URL.createObjectURL(workerFile);
49+
// `FragmentsManager.getWorker()` fetches the matching worker for this library version from unpkg and returns a blob URL.
50+
// You can also pass your own URL to `fragments.init(...)` if you'd rather host the worker yourself.
51+
const workerUrl = await OBC.FragmentsManager.getWorker();
5752
const fragments = components.get(OBC.FragmentsManager);
5853
fragments.init(workerUrl);
5954

packages/core/src/core/ShadowedScene/example.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,9 @@ const grid = grids.create(world);
4646

4747
// Set up fragments
4848

49-
const githubUrl =
50-
"https://thatopen.github.io/engine_fragment/resources/worker.mjs";
51-
const fetchedUrl = await fetch(githubUrl);
52-
const workerBlob = await fetchedUrl.blob();
53-
const workerFile = new File([workerBlob], "worker.mjs", {
54-
type: "text/javascript",
55-
});
56-
const workerUrl = URL.createObjectURL(workerFile);
49+
// `FragmentsManager.getWorker()` fetches the matching worker for this library version from unpkg and returns a blob URL.
50+
// You can also pass your own URL to `fragments.init(...)` if you'd rather host the worker yourself.
51+
const workerUrl = await OBC.FragmentsManager.getWorker();
5752
const fragments = components.get(OBC.FragmentsManager);
5853
fragments.init(workerUrl);
5954

packages/core/src/core/Viewpoints/example.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,9 @@ components.init();
4242
Now, let's configure the FragmentsManager. This will allow us to load models effortlessly and start manipulating them with ease:
4343
*/
4444

45-
const githubUrl =
46-
"https://thatopen.github.io/engine_fragment/resources/worker.mjs";
47-
const fetchedUrl = await fetch(githubUrl);
48-
const workerBlob = await fetchedUrl.blob();
49-
const workerFile = new File([workerBlob], "worker.mjs", {
50-
type: "text/javascript",
51-
});
52-
const workerUrl = URL.createObjectURL(workerFile);
45+
// `FragmentsManager.getWorker()` fetches the matching worker for this library version from unpkg and returns a blob URL.
46+
// You can also pass your own URL to `fragments.init(...)` if you'd rather host the worker yourself.
47+
const workerUrl = await OBC.FragmentsManager.getWorker();
5348
const fragments = components.get(OBC.FragmentsManager);
5449
fragments.init(workerUrl);
5550

packages/core/src/core/Views/example.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,9 @@ components.init();
4444
Now, let's configure the FragmentsManager. This will allow us to load models effortlessly and start manipulating them with ease:
4545
*/
4646

47-
const githubUrl =
48-
"https://thatopen.github.io/engine_fragment/resources/worker.mjs";
49-
const fetchedUrl = await fetch(githubUrl);
50-
const workerBlob = await fetchedUrl.blob();
51-
const workerFile = new File([workerBlob], "worker.mjs", {
52-
type: "text/javascript",
53-
});
54-
const workerUrl = URL.createObjectURL(workerFile);
47+
// `FragmentsManager.getWorker()` fetches the matching worker for this library version from unpkg and returns a blob URL.
48+
// You can also pass your own URL to `fragments.init(...)` if you'd rather host the worker yourself.
49+
const workerUrl = await OBC.FragmentsManager.getWorker();
5550
const fragments = components.get(OBC.FragmentsManager);
5651
fragments.init(workerUrl);
5752

packages/core/src/core/Worlds/example.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,9 @@ world.scene.three.background = null;
9696
9797
*/
9898

99-
const githubUrl =
100-
"https://thatopen.github.io/engine_fragment/resources/worker.mjs";
101-
const fetchedUrl = await fetch(githubUrl);
102-
const workerBlob = await fetchedUrl.blob();
103-
const workerFile = new File([workerBlob], "worker.mjs", {
104-
type: "text/javascript",
105-
});
106-
const workerUrl = URL.createObjectURL(workerFile);
99+
// `FragmentsManager.getWorker()` fetches the matching worker for this library version from unpkg and returns a blob URL.
100+
// You can also pass your own URL to `fragments.init(...)` if you'd rather host the worker yourself.
101+
const workerUrl = await OBC.FragmentsManager.getWorker();
107102
const fragments = components.get(OBC.FragmentsManager);
108103
fragments.init(workerUrl);
109104

packages/core/src/drawings/TechnicalDrawings/example.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@ components.init();
5252
extracted directly from it.
5353
*/
5454

55-
const githubUrl = "https://thatopen.github.io/engine_fragment/resources/worker.mjs";
56-
const fetchedWorker = await fetch(githubUrl);
57-
const workerBlob = await fetchedWorker.blob();
58-
const workerFile = new File([workerBlob], "worker.mjs", { type: "text/javascript" });
59-
const workerUrl = URL.createObjectURL(workerFile);
55+
// `FragmentsManager.getWorker()` fetches the matching worker for this library version from unpkg and returns a blob URL.
56+
// You can also pass your own URL to `fragments.init(...)` if you'd rather host the worker yourself.
57+
const workerUrl = await OBC.FragmentsManager.getWorker();
6058

6159
const fragments = components.get(OBC.FragmentsManager);
6260
fragments.init(workerUrl);

0 commit comments

Comments
 (0)