Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ Named by noun.
- Output: output (BabylonScene)
- Resources: Babylon glTF loader
- Behavior: Uses the Babylon scene loader to load a glTF using NullEngine.
- `ObjInputBlock`
- Input: `string` which is a URL (HTTPS or data) that points to an OBJ file.
- Output: output (BabylonScene)
- Resources: Babylon OBJ loader
- Behavior: Uses the Babylon scene loader to load an OBJ using NullEngine. For HTTP(S) OBJ URLs, referenced MTL files and supported relative textures are fetched automatically and embedded before loading. Data-URI OBJ inputs must be self-contained; relative MTL or texture references require an HTTP(S) base URL.
- `StlInputBlock`
- Input: `string` which is a URL (HTTPS or data) that points to an STL file.
- Output: output (BabylonScene)
Expand Down
16 changes: 3 additions & 13 deletions src/blocks/gltfInputBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Block, type BlockOptions } from "../block/block";
import { defineBlock } from "../block/blockDefinition";
import { BabylonSceneType, UrlType } from "../block/connectionPointType";
import { NullEngineResource } from "../resources/nullEngineResource";
import { fetchOrThrowAsync, isHttpUrl, loadSceneWithPluginAsync, toBase64 } from "../helpers/loadSceneWithPlugin";
import { fetchAsDataUriAsync, fetchOrThrowAsync, isHttpUrl, loadSceneWithPluginAsync } from "../helpers/loadSceneWithPlugin";

const GltfInputBlockDefinition = /* @__PURE__ */ defineBlock({
type: "input.gltf",
Expand All @@ -28,7 +28,8 @@ const GltfInputBlockDefinition = /* @__PURE__ */ defineBlock({
name: new URL(resolvedUrl).pathname.split("/").pop() ?? "",
pluginOptions: {
gltf: {
preprocessUrlAsync: (dependencyUrl) => fetchAsDataUriAsync(dependencyUrl, abortController.signal),
preprocessUrlAsync: (dependencyUrl) =>
isHttpUrl(dependencyUrl) ? fetchAsDataUriAsync(dependencyUrl, abortController.signal) : Promise.resolve(dependencyUrl),
},
},
});
Expand Down Expand Up @@ -105,14 +106,3 @@ function isGltfJson(json: string): boolean {
return false;
}
}

async function fetchAsDataUriAsync(url: string, signal: AbortSignal): Promise<string> {
if (!isHttpUrl(url)) {
return url;
}

const response = await fetchOrThrowAsync(url, signal);
const contentType = response.headers.get("content-type")?.split(";", 1)[0] || "application/octet-stream";
const data = new Uint8Array(await response.arrayBuffer());
return `data:${contentType};base64,${toBase64(data)}`;
}
Loading
Loading