Code Monkey home page Code Monkey logo

root2cad's Introduction

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

root2cad's People

Contributors

drateots avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

f3sch

root2cad's Issues

Question: visibility depth

We tried using the conversion ROOT->gltf with the OpenDataDetector, but somehow it looks like the visibility of the objects in the resulting gilt file is identical to the settings provided by

gGeoManager->GetTopVolume()->SetVisibilityLevel(-1)

while we would like to something like

SetVisibilityLevel(4) etc.

Is there a way to specify the depth for the visibility at conversion time ?

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.