MCPcopy Create free account
hub / github.com/CNCKitchen/stlTexturizer / loadSTLFile

Function loadSTLFile

js/stlLoader.js:16–37  ·  view source on GitHub ↗
(file)

Source from the content-addressed store, hash-verified

14const objLoader = new OBJLoader();
15
16/**
17 * Load an STL from a File object.
18 * Returns { geometry, bounds } where bounds = { min, max, center, size } (THREE.Vector3).
19 * The geometry is translated so its bounding-box centre is at the world origin.
20 */
21export function loadSTLFile(file) {
22 if (file.size > MAX_FILE_SIZE) {
23 return Promise.reject(new Error(
24 'File too large (' + Math.round(file.size / 1024 / 1024) + ' MB). Maximum supported: ' + (MAX_FILE_SIZE / 1024 / 1024) + ' MB.'
25 ));
26 }
27 return new Promise((resolve, reject) => {
28 const reader = new FileReader();
29 reader.onload = (e) => {
30 try {
31 const geometry = stlLoader.parse(e.target.result);
32 const { nanCount, degenerateCount, originOffset } = setupGeometry(geometry);
33 const bounds = computeBounds(geometry);
34 resolve({ geometry, bounds, nanCount, degenerateCount, originOffset });
35 } catch (err) {
36 reject(err);
37 }
38 };
39 reader.onerror = () => reject(new Error('Could not read file'));
40 reader.readAsArrayBuffer(file);

Callers 1

loadModelFileFunction · 0.85

Calls 2

setupGeometryFunction · 0.85
computeBoundsFunction · 0.85

Tested by

no test coverage detected