npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ccp-nc/crystvis-js

v0.5.0

Published

A Three.js based crystallographic visualisation tool

Downloads

7

Readme

crystvis-js

A Three.js based crystallographic visualisation tool. It reads multiple file formats and renders them with WebGL to a canvas element, allowing the user to interact with them. A few of the key functionality:

  • visualize popular file formats as ball-and-stick structures, easily embedded within a webpage, with orbit mouse control for rotation and zooming;
  • interactive visualisation responsive to user clicks via customizable callbacks;
  • high definition text labels;
  • advanced searching and selection functions to interact with specific subset of atoms (select by proximity, bonding, species and more);
  • smart visualisation of molecular crystal: reconstruct full molecules across the periodic boundary;
  • compute and display isosurfaces from volumetric data;
  • visualize tensor data as ellipsoids centred on atoms.

Supported formats

The currently supported file formats are the following:

Getting started

In order to install crystvis-js, simply use the Node Package Manager:

npm install crystvis-js --save

You can then create a visualizer for your webpage by simply importing and instantiating it:

import CrystVis from 'crystvis-js';

const visualizer = CrystVis('#target-id', 800, 600)

will create an 800x600 canvas with the visualizer inside the element specified by the given selector. To load a model, simply load the contents of your file as a text string and then pass them to the visualizer's loadModels method:

var loaded = visualizer.loadModels(contents);
console.log('Models loaded: ', loaded);
visualizer.displayModel(loaded[0])

Preparing for development

If you want to develop for crystvis-js, you should follow these steps:

  • fork the repository
  • clone the forked repository locally to your system
  • install all the required packages, including the development dependencies, with npm install --production=false

You're then ready to develop. In particular you can use:

  • npm test to run with Mocha the suite of tests found in ./test
  • npm start to start a server that includes the in-browser tests from ./test/test-html as well as the demo from ./demo
  • npm run docs to compile the documents
  • npm run deploy-docs to compile the documents and then deploy them to the gh-pages branch of your repository

Fonts and shaders

Some additional steps are necessary when dealing with fonts and shaders. You generally shouldn't worry about these when working with most of the code, but in some special cases it might be necessary to do this.

Fonts in crystvis-js need to be translated to a bitmap format to be usable. In other words, a regular font format (like a TTF file) must be rendered into a bitmap texture and a table of coordinates designating each letter to then be used in graphical rendering. This operation relies on the library msdf-bmfont-xml and is executed by running the command npm run build-fonts. The original fonts are found in the ./fonts folder, and they get rendered to ./lib/assets/fonts. This command needs only to be rerun if the TTF files change.

Shaders are provided as .frag and .vert files. Both shaders and font textures need to baked directly into the JavaScript files in order to be included in the final build. Since ESBuild (the package used to build crystvis-js) has a hard time dealing with them in the final pass, they get pre-baked with an additional step that only needs to be repeated whenever either of them changes. This consists of taking "template" JS files (for shaders it's ./lib/shaders/index.in.js, for fonts ./lib/assets/fonts/bmpfonts.in.js) and rebuilding them into final files with the assets imported in data URL form. The script to do this is npm run build-resources. This command only needs to be rerun if the fonts were rebuilt, if the shader code was edited, or if any of the two template files was changed.