Nonviolent Pirate Mobster

    mesh-to-svg
    TypeScript icon, indicating that this package has built-in type declarations

    2.1.6 • Public • Published

    Mesh to SVG

    Example

    WASM Library (written in Rust 🦀) to convert meshes (optionally with supplemental wireframe mesh) into an SVG line drawing

    It is recommended to use https://github.com/zakhenry/svg-from-wireframe which wraps this library in a more ergonomic interface, and provides demos for how to integrate with webworkers in Angular.

    Installation

    $ yarn add mesh-to-svg

    Contributing

    Setup

    Clone this repo

    $ git clone git@github.com:zakhenry/mesh-to-svg.git

    Ensure you have a rust toolchain set up, if not:

    $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

    Install wasm-pack (the tooling for making WASM modules with Rust)

    $ curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

    Fetch deps (this can be skipped as wasm-pack will do this too)

    $ cargo build

    Build

    $ wasm-pack build -- --features console_log

    or use the handy yarn helper if you're more familiar with frontend tooling

    $ yarn wasm:build:debug

    To do a release build (way faster to run, but runtime errors are less helpful)

    $ wasm-pack build --release -- --features console_log

    or use the handy yarn helper if you're more familiar with frontend tooling

    $ yarn wasm:build:release

    Link package

    Link npm package so other repos can use this module

    $ cd pkg && yarn link

    Link from your other package

    $ cd path/to/your/other/repo
    $ yarn link mesh-to-svg

    You only have to do this once (it sets up symlinks)

    Now you can just rebuild this project, and if you have a file watcher on the other project (the default for Angular for example) when you rebuild the wasm binary the webpage will automatically reload with the latest code.

    Releasing a package

    Package releases are all done automatically by semantic-release and TravisCI.

    Please follow the semantic commit guidelines so your commit messages will automatically generate the changelog and the correct semver.

    Issues & PRs

    Please raise issues for features you'd like to see, issues encountered etc. PRs are always welcome, I really want to learn how to make this package better, faster, stronger!

    Tips

    Debug with the log!() macro. It takes the same form as print!(), i.e.

    log!("Hello world, 1 + 1 is {res}", res = 1 + 1);

    You will see the output in the browser console. If an object that is logged implements the Display trait, it will be logged prettily (e.g. vectors, matrices etc all look good).

    Calling log!() is super slow. Any performance benchmarks you may do with logging will be seriously polluted by the calls out to JS.

    As such console_log is an optional feature, which is turned off for the release build

    Run a build with the feature console_log turned off:

    wasm-pack build --release

    or

    $ yarn wasm:build:prod

    Running Binary

    Output svg

    $ cargo run --example mesh-to-svg --release -- --file meshes/raspi.json > test.svg

    Output to console

    $ cargo run --example mesh-to-svg --release -- --file meshes/raspi.json term
          Finished release [optimized] target(s) in 0.06s
           Running `target/release/examples/mesh-to-svg --file meshes/raspi.json term`
                                                                       
                                                                       
                                             ⢀⡤⢤⣤⡤⣄⡀                   
                                             ⣼⡀⠑⠒⣃⣀⣹                   
                                             ⡇⣷⠒⠒⡇ ⣿⠒⠢⢤⣀               
                                             ⣇⣿  ⡇ ⠑⢲⢄⣠⡔⢳              
                                       ⢀⣀⣤⡴⠶⣛⣝⣋⣤⡤⢋⡭⡍⠛⠢⣻⢷⡉⠑⠢⣀           
                                  ⣀⡠⣤⣶⣚⡫⠭⠒⠊⠉ ⡇  ⢹⣷⠿⣷⡏⠉⠉⢱⠈⠑⠤⣀⠉⠢⢄⡀       
              ⢀⣀⠤⢄⣀⡀        ⢀⣀⢤⣔⢮⡽⠖⠋⠉     ⢀⣀⠤⠧⠤⣤⠼⠃⢠⣿⣇⣀⣀⣸    ⠑⠢⡶⣚⣊⣉⣒⣤   
       ⡤⢖⣒⣒⠦⠔⠉⢁⣀⠤⠤⠔⠊⡇  ⣀⣠⣤⢶⡽⠷⠛⠉⠉⠁     ⡠⠔⠒⠉⣁⣔⡲⢮⠝⠤⡄ ⣷⡋   ⠈⠢⢄⡀⣠⢤⣯⣊⠉⠁⢠⣖⣮⢑⡆ 
       ⡗⣮⠭⢍⣀⡤⡎⠁     ⡷⡾⠿⠛⠓⠊⠁    ⢀⣀⠤⠔⠒⣉⡩⠤⢲⡞⠋⠉  ⣸⣀⣰⠁⡴⠒⡯⠭⢭⣭⠭⣭⠭⡭⣧⣼⡇⢸⢹⠉⡟⠒⠚⠉  
       ⡇⣿⣀  ⡇⡇      ⠉    ⢀⣀⠤⠤⠒⢉⣁⠤⠒⠊⢩⠴⢲⠤⠤⠭⠭⠭⠵⠿⢶⣖⠋⡀⣇⡤⢇⣀⣿⢹⠒⡬⢲⠯⠟⠒⢉⣉⢾ ⡇   ⡀ 
       ⡇⡷⣄⠉⠉⠓⢧⠔⠒⢯⡇  ⢀⣀⠤⠤⢊⣁⢤⡴⠶⠛⠋⢹⠉⡹⠂⢸⣀⣸⣀⣀⣀⡠⢄⡠⠔⠚⠉⠉⢘⢧⣤⡶⠿⠯⠼⣀⡇⠸⠤⠒⠉⠁ ⠘⠒⢳⠒⠒⡏⠁ 
       ⠙⡇⢸⠒⡎⡏⢹⣿⣻⣤⣗⣒⣫⣥⣔⠒⠉⠁⠸⠧⣀⣀⣀⣤⣚⣒⡇⢠⣻⢡⣒⡊⠉⢀⡠⠔⠚⠲⠒⠒⠊⠁⢸⢀⣀⠤⠔⠒⠉    ⣀⣠⢤  ⢸ ⢠⠇  
        ⡇⢸ ⠫⡉⠉⠓⢿⡽⡤⣇⢀⣀ ⠉⠉⠉⡏⡇⢠⠚⣹⠒⠒⠒⠒⠒⠚⢻⡇⡏⡎⠁        ⠈⠁   ⣀⡠⣤⣒⠮⣍⡀⠙⣼ ⣀⠼⠴⠋   
        ⡇⢸  ⠈⠑⠒⢄⠈⢹⠷⡋ ⠑⠲⢖⠒⡗⠓⠊⠉⠘⢤⣤⡤⢤⡶⠶⠿⠳⢇⡇        ⢀⣀⠤⠔⣶⠛⠊⠉⣀⠼⣒⠶⠕⡞⠙⠉       
        ⢧⢸      ⠉⠚ ⠈⢱⢤⣀⣀⢹⢳⢤⣛⣛⣣⠞⡗⠊⠁⣀⠤⠔⠒⠉    ⣀⠤⠔⠒⢩⠗⠒⣦ ⢙⠶⠶⠛⠊⠉   ⣇⡤        
        ⠈⠛⠢⢄        ⢸   ⢹⢸     ⡗⠊⠉   ⣀⡠⠤⢒⣊⠭⢴⠛⣲⢄⣈⠭⠝⠓⠉⠁  ⢀⣀⠤⠔⠒⠉⠁         
            ⠉⠢⢄     ⢸   ⢸⣸    ⣰⠁⢀⣤⣒⣊⠉ ⢿⣉⣁⣠⡴⠮⠋⠉⠁   ⣀⡠⠤⠒⠊⠁               
               ⠉⠒⢄⡀ ⢸    ⠈⠉⠑⠚⡏⠁ ⢸  ⠈⡏⠓⠒⠒⡏   ⢀⣀⠤⠔⠊⠉                     
                  ⠈⠒⢼        ⣇⣀⠤⠼⠤⠤⠤⣇⣀ ⣀⡧⠔⠒⠉⠁                          
                     ⠉⠑⠒⠒⠒⠒⠒⠒⠁        ⠉⠁                               
                                                                       

    Animate to console

    cargo run --example mesh-to-svg --release -- --file meshes/raspi.json term --animate
        Finished release [optimized] target(s) in 0.05s
         Running `target/release/examples/mesh-to-svg --file meshes/raspi.json term --animate`
    Rendered 13 of 50 angles (806.828564ms)
    
                                                                     
                                                                     
                         ⢀⣠⠤⠤⢤⣀                                      
                     ⣀⣠⠤⠤⣏⡀⠛⠛⠃⢸⡇                                     
                   ⢰⠫⣄⣀⢤⠔⠃⠈⡟⠒⡜⡇⡇                                     
                 ⣀⠤⣊⢵⠿ ⡸⢖⣒⡒⠧⢄⡷⡷⠷⣒⠤⡴⢖⡉⡝⢳                              
          ⢀  ⣀⠤⣒⠭⣒⠭⠒⠁⡟⠛⢲⣬⣷⣥⡖⠋⠉⢻⠑⠒⠭⠇ ⢸⣇⠼⡀ ⢀⣀⡠⠤⢄⡀                      
     ⡔⢪⣭⣭⠉⠙⠲⠿⣔⢭⠒⠉    ⣇⣀⢸⣟⡄⢏⡇⣀⣀⣸     ⠈⠙⠭⣚⣵⡏⠑⠤⣀⡀⢈⡵⠦⠒⠢⢄⣀                
     ⡏⠓⠒⠒⡖⣶⡏⢹⢸⢿⣀ ⣀⠤⠒⠉ ⠈⠉⠻⡇⢸⠉  ⠈⠒⠒⢄⡀    ⣦⠤⡁   ⠈⠙⠈⠉⠒⠤⣀⢀⡝⡆              
     ⡇   ⡇⣿⡇⢸⣼⣣⣼⣿⠶⢶⢶⠒⠒⠒⢒⡯⡥⠤⠭⠭⠭⡭⢭⠉⣩⢭⠛⠛⠛⠛⠓⠒⠚⠓⡖⣦⢄      ⣿⡇⡇              
     ⡇   ⡇⡿⣓⠒⠫⢗⣫⢾⠤⢼⢸⠉⠒⠢⠬⢗⣓⠢⢄⣀⣀⣇⣸⡇⢣⣸⣀⣀⣀⣀⣀⣀⣀⣀⣇⣿ ⣩⠖⠶⡄  ⠻⢯⠵⣢⠤⣀ ⡴⣒⠉⠉⢹⣛⡯⢙⡆ 
     ⠈⠑⠒⢲⠓⠃ ⠉⠒⠒⢄⡉⠛⠵⣫⣖⡤⣀⡀  ⠉⠒⠬⣑⠒⠛⠁⢸⡀         ⣸⡇⢇⣀⣀⡇    ⠉⠒⠭⣒⣭⡇ ⣿⠒⠒⠒⢺⡏⡇ 
      ⢠ ⢸  ⢠⣤⣀  ⠈⠑⠒⠤⣈⠙⠫⠾⣵⣒⡤⣀⡀ ⠉⠒⠢⢤⠉⠉⠉⣭⢽⠛⠛⠛⠛⢻⠳⡄⢸  ⠈⠑⠒⠤⣀  ⢀⣯⠗⢒⣤⠟⠉⠉⢉⣽⡇⡇ 
       ⠳⠼⢄⡀⡼⠚⢀⣉⣒⣢⣄⡀  ⠉⠑⠢⠤⣉⠚⠳⢮⡵⣢⠤⣀ ⠉⠉⢢⣼⠛⠒⠢⢄⣀⣸⣀⣿⠈⢓⣦⣤⣤⣤⣤⣤⣭⣒⣺⣤⠯⣅⡀⢀⡠⠔⡏⢸⠷⠃ 
          ⠈⡗⡦⢜⣤⠤⣇⡈⠙⠫⢖⠤⣀⡀  ⠉⠒⠢⢌⣉⠛⠶⣫⣕⡢⢼⠉⠑⠒⠤⡀⠈⠑⠚⠭⣀⡏⢸      ⣸⣴⣿⠤⢇⣸⠁  ⡇⢸   
           ⣇⡇  ⠉⠒⠪⢵⡤⠼⠃⢀⣈⣑⡢⠤⣀   ⠉⠒⠤⢌⡙⢻    ⣿⣀⠶⠶⢆⡠⣗⣊⠭⠛⠯⣽⠿⠛⠉⣁⠤⠤⠒⠉   ⡇⢸   
           ⠈⠉⠑⠢⠤⣀  ⠈⠑⠒⠽⢶⣖⠋⢀⣠⠭⡖⠢⢄⡀  ⠈⠉    ⡇⠈⠉⠉⠉⡇⣇⣀⣠⠤⢶⠊⡧⠒⠉        ⡇⢸   
                 ⠉⠒⠢⢄⡀   ⠑⠪⠧⣄⡏⠑⠢⢌⣉⡒⠤⣀⡀   ⡇    ⡇⡇   ⢸           ⢀⠷⠁   
                     ⠈⠉⠒⠤⣀⡀  ⠉⠑⠲⣒⣚⣋⣀⡤⠬⠵⢦ ⢧⣀  ⢀⡧⡇   ⢸       ⢀⡠⠔⠊⠁     
                          ⠈⠑⠢⠤⣀ ⡇   ⡇  ⢸  ⢸⠉⠉⠁     ⢸   ⢀⡠⠔⠊⠁         
                               ⠉⠣⠤⠤⠴⠓⠋⠉⠚⠒⠤⢼        ⢸⡠⠔⠊⠁             
                                           ⠉⠑⠒⠒⠒⠒⠊⠉⠁                 
                                        

    CTRL+C to exit

    Keywords

    none

    Install

    npm i mesh-to-svg

    DownloadsWeekly Downloads

    6

    Version

    2.1.6

    License

    none

    Unpacked Size

    127 kB

    Total Files

    7

    Last publish

    Collaborators

    • zakhenry