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

root2cad

v1.1.1

Published

CERN ROOT geometry export to CAD

Downloads

3

Readme

root2cad

CERN ROOT geometry converter to CAD format (GLTF)

root2cad is a batch converter that can be used from pure command line (tested on linux, but should work on mac and windows). There is also an online converter, that could be used from your browser. Online converter, (GitHub)

Quick start


npm install -g root2cad

# For drich.root that has DRICH geometry object saved to it
xvfb-run root2cad drich.root DRICH -o drich2.gltf

# EIC ePIC latest full detector geometry. Look files here: 
# https://eicweb.phy.anl.gov/EIC/detectors/athena/-/jobs/artifacts/master/browse/geo?job=report
xvfb-run root2cad  detector_geo_full.root Default -o detector_geo_full.gltf

# Convert from gdml (CERN ROOT has to be installed)
root -e 'TGeoManager::Import("my.gdml")->Export("my.root")'
xvfb-run root2cad  my.root Default -o my.gltf

# Convert to other cad formats
assimp export drich.gltf drich.obj

# list file contents
xvfb-run root2cad --ls detector_geo_full.root

# list geometry hierarchy
xvfb-run root2cad --ls --ls-depth=1 detector_geo_full.root Default

# this will output something like
# ...
# 1    /world_volume/DRICH
# ...

# Convert subdetector DRICH
xvfb-run root2cad detector_geo_full.root default DRICH -o drich.gltf

Installation

Prerequesties:

  • One needs nodejs>13 and npm installed Installation instructions
  • xvfb (X virtual framebuffer). For Ubuntu: sudo apt-get install xvfb

NPM install

npm install -g root2cad

If npm bin paths are set correctly you should have root2cad command working.

Usage

root2cad can convert ROOT geometry objects saved in root file to GLTF format. The conversion works for compound and tasselated geometry.

Usage: root2cad [options] [file] [object] [volname]

Arguments:
  file         [required] File name to open (CERN ROOT files)
  object       [required] Geometry object name in ROOT file to open
  volname      [optional] Volume name in geometry hierarchy

Options:
  -o, --output <string>  Output file name. "exported.gltf" if not set
  --ls                   Lists all objects in file or geometry (same as --ls-vol)
  --ls-vol               Lists geometry hierarchy of VOLUME names. See also --list-depth
  --ls-node              Lists geometry hierarchy of NODE names. See also --list-depth
  --ls-depth <int>       Works with --list, defines the level to print. Default 0
  -V, --version          output the version number
  -h, --help             display help for command

Examples:

# For drich.root that has DRICH geometry object saved to it
xvfb-run root2cad drich.root DRICH -o drich2.gltf

# List objects in file (for convenietnce)
xvfb-run root2cad  --ls drich.root

# List geometry hierarchy
xvfb-run root2cad  --ls drich.root DRICH
xvfb-run root2cad  --ls --ls-depth=5 drich.root DRICH

Use GLTF VIEWER online to see the results!

GDML conversion

To convert GDML one can convert it to ROOT with this one liner:

root -e 'TGeoManager::Import("drich.gdml")->Export("drich.root")'
xvfb-run node export.mjs drich.root default -o drich.gltf

During this conversion, the saved object is named 'default' thus we use it to convert the resulting root geometry

Individual volumes conversion

One can provide a volume name to export only this volume. So one has to specify file name, geometry object name inside file and volume name inside the geometry. There is --ls command that helps to see detector hierarchy and volume names.

# list geometry hierarchy
xvfb-run root2cad --ls --ls-depth=1 detector_geo_full.root default

# this will output something like
# ...
# 1    /world_volume/DRICH
# ...

# Convert subdetector DRICH
xvfb-run root2cad detector_geo_full.root default DRICH -o drich.gltf

Using --ls and volume names could be used to automatically split DD4HEP geometry hierarchy to components in gftl format. See auto_split_example.py for example (files in test folder)

Other formats

glTF (GL Transmission Format) is a 3D file format that stores 3D model information in JSON format. It is common for web 3d graphics but not all CAD software can work with it. Free options to convert from GLTF to other formats:

  • assimp (Asset Import library)
  • Blender
  • Microsoft 3D Builder

Assimp has a command line tool, that allows easy conversion:

# Convert to other cad formats
assimp export drich.gltf drich.obj

Assimp supports many formats for export: collada, x, stp, obj, objnomtl, stl, stlb, ply, plyb, 3ds, gltf2, glb2, gltf, glb, assbin, assxml, x3d fbx, fbxa, 3mf, assjson

(!) While STEP is a common format for EIC cad exchange, our experimets opening exported files in different CAD software shows that other formats like obj or x3d produce cleaner conversion and better results for complex geometry

Development

Github clone


git clone --recurse-submodules https://github.com/eic/root2cad.git
cd root2cad
npm install

# Running root2cad is the same as
xvfb-run node export.mjs --help    # should work

TODO

  • Switch JSROOT from git submodule to npm dependency
    (possible after the next JSroot release)

  • After this it is possible to remove JSROOT depenencies we have to carry:

        "atob": "^2.1.2",
        "btoa": "^1.2.1",
        "canvas": "^2.9.0",
        "gl": "^5.0.0",
        "jsdom": "^19.0.0",
        "mathjax": "3.2.0",
        "xhr2": "^0.2.1",
        "zstd-codec": "^0.1.2"
  • Convert geometry element