Git Product home page Git Product logo

stl-parser's Introduction

STL Parser

What is STL?

  • STL (an abbreviation of "sterolithograpy") is a file format native to the sterolithograpy CAD software created by 3D Systems.

  • An STL file describes a raw, unstructured triangulated surface by the unit normal and vertices (ordered by the right-hand rule) of the triangles using a three-dimensional Cartesian coordinate system. In the original specification, all STL coordinates were required to be positive numbers, but this restriction is no longer enforced and negative coordinates are commonly encountered in STL files today. STL files contain no scale information, and the units are arbitrary. Wikipedia - STL

  • The following is an STL parser that is able to parse an ASCII STL file. It is written in Javascript and run in a Node environment. The parser will output the number of triangles in the model, the total surface area, and the bounding box.

To install


Clone from the repo and install npm will install require dependecies: npm install

To run tests


To run the accompanying tests run to following: npm run test

To run


  • Note Node.js must be installed for application to run Node JS

From the root directory run: npm run start

This will execute the sript and output the following:

  { numberOfTriangles: 2,
    surfaceArea: 1.4142135623730951,
    boundingBox: { x: 1, y: 1, z: 1 } 
  }

The default STL file that is parsed when the script is executed is the Moon.stl

To parse other STL files, from within root directory ./lib/index.js file change to following line to the correct file path that you wish to parse: const STLFileOutput = fs.readFileSync('../STLFiles/Moon.stl')

Design


In designing this parser I did the following:

  1. Attempted to seperate areas of concern.
  • Created function to read in STL file and control main parser processes.
  • Created seperate functions to handle business logic ( Calc area of triangle, bounding box).
  • Called business logic functions within main function convertSTLFileToStringAndParse to have a single place to control parsing logic to minimize the introduction of bugs.
  1. Maintain clean coding practices.
  2. Follow proper variable and function naming conventions.

Enhancements

While the largest STL file that I have tested with this parser has over 38k triangles (Liver.stl), I have identified some areas for improvement. The parser as it currently stands has a relatively fast runtime, however I do foresee an unacceptable runtime when parsing a model with millions of triangles. A possible improvement on the current algorithm implementation would be to use a hash table along with memoization while looping over the string representation of the STL file.

A future enhancement I propose would be to create a GUI for a much cleaner user expierence.

stl-parser's People

Contributors

eldoza1 avatar eldoza avatar

Stargazers

Valerie Fae Haupt avatar  avatar Saurabh Srivastava avatar Orlando Carnate avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.