Namespace NeedleEngineModelLoader

NeedleEngineModelLoader is a namespace that provides functions to register custom model loaders and mimetype callbacks. It allows you to create custom loaders for specific file types and determine the mimetype of files based on their content.

import { NeedleEngineModelLoader } from "@needle-tools/engine";
import { STLLoader } from "three/examples/jsm/loaders/STLLoader";

NeedleEngineModelLoader.onCreateCustomModelLoader(args => {
if (args.mimetype === "model/stl") {
return new STLLoader();
}
});

NeedleEngineModelLoader.onDetermineModelMimetype((args) => {
// detect stl mimetype
const bytes = args.bytes;
if (bytes[0] === 0x73 && bytes[1] === 0x74 && bytes[2] === 0x6c) {
return "model/stl";
}
return null;
});

Functions

onCreateCustomModelLoader

Register a custom loader callback. For every file that is requested this callback is called with the url and mimetype. It should return a custom loader or null if it does not want to handle the file.

onDetermineModelMimetype

Register a callback to determine the mimetype of a file. This is to support custom loaders. The callback will provide the URL of the file to load + a range request response with the first few bytes of the file. The callback should return a mimetype or null if it does not want to handle the file.