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
8 changes: 4 additions & 4 deletions packages/core/docs/blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
## Inputs

- `FbxInputBlock`
- Input: `string` which is a URL (HTTPS or data) that points to an FBX file.
- Input: `string` HTTP(S) or data URL, or a Node filesystem path/file URL, pointing to an FBX file.
- Output: `Document`
- Uses: Babylon FBX loader
- Behavior: Uses the Babylon scene loader to load an FBX using NullEngine, exports it as a GLB, then reimports the bytes as a `Document`.
- `GltfInputBlock`
- Input: `string` URI accepted by the current `PlatformIO` that points to a glTF or GLB.
- Input: `string` URI accepted by the current `PlatformIO`, or a Node filesystem path/file URL, pointing to a glTF or GLB.
- Output: `Document`
- Behavior: Reads glTF or GLB into a `Document`, using glTF Transform's default extension handling.
- `ObjInputBlock`
- Input: `string` which is a URL (HTTPS or data) that points to an OBJ file.
- Input: `string` HTTP(S) or data URL, or a Node filesystem path/file URL, pointing to an OBJ file.
- Output: `Document`
- Uses: Babylon OBJ loader
- Behavior: Uses the Babylon scene loader to load an OBJ using NullEngine, exports it as a GLB, then reimports the bytes as a `Document`.
- `StlInputBlock`
- Input: `string` which is a URL (HTTPS or data) that points to an STL file.
- Input: `string` HTTP(S) or data URL, or a Node filesystem path/file URL, pointing to an STL file.
- Output: `Document`
- Uses: Babylon STL loader
- Behavior: Uses the Babylon scene loader to load an STL using NullEngine, exports it as a GLB, then reimports the bytes as a `Document`.
Expand Down
5 changes: 5 additions & 0 deletions packages/core/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const asset = new NodeAsset({
const result = await asset.executeAsync();
```

# Input locations

All input blocks accept HTTP(S) URLs and, in Node, filesystem paths and `file:` URLs.
Relative paths use the working directory.

# Example: CLI run reports

```sh
Expand Down
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"draco3dgltf": "1.5.7",
"gltf-validator": "2.0.0-dev.3.10",
"meshoptimizer": "1.2.0",
"sharp": "0.35.4"
"sharp": "0.35.4",
"xhr2": "0.2.1"
}
}
9 changes: 5 additions & 4 deletions packages/core/src/blocks/fbxInputBlock.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { ISceneLoaderPluginFactory } from "@babylonjs/core/Loading/sceneLoader.js";
import { FBXFileLoaderMetadata } from "@babylonjs/loaders/FBX/fbxFileLoader.metadata.js";

import { GltfDocumentType } from "../connectionPoints/gltfDocument";
import { UrlType } from "../connectionPoints/url";
import { convertBabylonSceneToDocumentAsync } from "../helpers/convertBabylonSceneToDocument";
import { loadSceneWithPluginAsync } from "../helpers/loadSceneWithPlugin";
import { NullEngineResource } from "../resources/nullEngineResource";
import { PlatformIOResource } from "../resources/platformIOResource";
import { Block, type BlockOptions } from "./block";
import { defineBlock } from "./blockDefinition";
import { loadSingleFileSceneWithPluginAsync, type SceneLoaderPluginFactory } from "../helpers/loadSceneWithPlugin";

const FbxLoaderFactory = {
...FBXFileLoaderMetadata,
Expand All @@ -19,7 +20,7 @@ const FbxLoaderFactory = {
RegisterStandardMaterial();
return new FBXFileLoader();
},
} satisfies SceneLoaderPluginFactory;
} satisfies ISceneLoaderPluginFactory;

const FbxInputBlockDefinition = /* @__PURE__ */ defineBlock({
type: "input.fbx",
Expand All @@ -31,14 +32,14 @@ const FbxInputBlockDefinition = /* @__PURE__ */ defineBlock({
},
runAsync: async (url, _config, { engine, io }) =>
convertBabylonSceneToDocumentAsync(
await loadSingleFileSceneWithPluginAsync(url, engine, FbxLoaderFactory, {
await loadSceneWithPluginAsync(url, engine, FbxLoaderFactory, {
pluginExtension: ".fbx",
}),
io
),
});

/** Loads an FBX URL. */
/** Loads an FBX URL or Node filesystem path. */
export class FbxInputBlock extends Block<typeof FbxInputBlockDefinition> {
public constructor(options?: BlockOptions<typeof FbxInputBlockDefinition>) {
super(FbxInputBlockDefinition, options);
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/blocks/gltfInputBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ALL_EXTENSIONS } from "@gltf-transform/extensions";

import { GltfDocumentType } from "../connectionPoints/gltfDocument";
import { UrlType } from "../connectionPoints/url";
import { resolveInputLocationAsync } from "../helpers/inputLocation";
import { GltfDecoderResource } from "../resources/gltfDecoderResource";
import { PlatformIOResource } from "../resources/platformIOResource";
import { Block, type BlockOptions } from "./block";
Expand All @@ -16,14 +17,18 @@ const GltfInputBlockDefinition = /* @__PURE__ */ defineBlock({
io: PlatformIOResource,
},
runAsync: async (url, _config, { decoders, io }) => {
const document = await io.registerExtensions(ALL_EXTENSIONS).registerDependencies(decoders).read(url);
const location = await resolveInputLocationAsync(url);
const document = await io
.registerExtensions(ALL_EXTENSIONS)
.registerDependencies(decoders)
.read(location.path ?? location.uri);
document.disposeExtension("KHR_draco_mesh_compression");
document.disposeExtension("EXT_meshopt_compression");
return document;
},
});

/** Loads a glTF or GLB URI. */
/** Loads a glTF or GLB URI or Node filesystem path. */
export class GltfInputBlock extends Block<typeof GltfInputBlockDefinition> {
public constructor(options?: BlockOptions<typeof GltfInputBlockDefinition>) {
super(GltfInputBlockDefinition, options);
Expand Down
Loading
Loading