unified-3d-loader

Unified 3D file loader. Intended for use as a frontend for triangle-based 3D processing.

Usage no npm install needed!

<script type="module">
  import unified3dLoader from 'https://cdn.skypack.dev/unified-3d-loader';
</script>

README

Unified 3D Loader

status npm tests issues last commit

A 3D file loader designed to produce consistent mesh data regardless of file format. Intended for use as a front-end for triangle-based 3D processing.

Features

  • Get indexed or non-indexed (raw) vertices and normals regardless of input format
  • Support for many files associated with CNC machine workflows
  • Written in modern TypeScript
  • Thoroughly commented

Documentation

File Formats

Name Extension Status ThreeJS Loader Cura Reader Specification Specification Compliance Comment
3D Manufacturing Format .3mf ✔️ 3MFLoader 3MFReader 3MF.io ~70% Does not support print tickets or many other OPC features. Always recalculates normals.
Additive Manufacturing Format .amf ✔️ AMFLoader AMFReader ISO/ASTM 52915:2020 ~99% Does not specifically extract model name metadata (This can be extracted from the metadata mesh property). Always recalculates normals.
Stanford Triangle Format .ply ✔️ PLYLoader TrimeshReader Gamma Research Group (University of North Carolina) ~100% Supports non-triangular, planar polygons. Always recalculates normals.
Wavefront OBJ Format .obj ✔️ OBJLoader2 N/A Wikipedia ~30% Supports non-triangular, planar polygons. Does not support complex geometries (Basis Matrixes, Beizer/NURBS/Cardinal/Taylor surfaces and/or curves). Always recalculates normals.
Stereolithography Format .stl ✔️ STLLoader N/A Wikipedia 100% Never recalculates normals (Always uses user-supplied instead).

Example

//Imports
import {FileFormats, Unified3dLoader} from 'unified-3d-loader';

const main = async () =>
{
  //Instantiate a new loader
  const loader = new Unified3dLoader();

  //Progress logger (Ranges from 0 to 100)
  loader.on('progress', percent =>
  {
    console.log(`Progress: ${percent}%`);
  });

  //Load a file (in indexed mode)
  const indexedObjects = await loader.load(/* <ArrayBuffer> */, FileFormats.STL);

  console.log(indexedObjects);
  /**
   * name: 'Cube',
   * normals: {
   *  indices: number[]
   *  vectors: number[]
   * },
   * vertices: {
   *  indices: number[]
   *  vectors: number[]
   * }
   */

  //Load a file (in non-indexed mode)
  const nonIndexedObjects = await loader.load(/* <ArrayBuffer> */, FileFormats.STL, false);

  console.log(nonIndexedObjects);
  /**
   * name: 'Cube',
   * normals: number[],
   * vertices: number[]
   */
};

main();