• Stars
    star
    178
  • Rank 214,325 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 3 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A CAD viewer component based on three.js

A threejs based CAD viewer

Overview

The CAD viewer can visualize low level threejs objects (tessellated objects)

Live Examples

Shape and Shapes

A Shape contains the attributes

  • vertices (the BufferGeometry attribute position)
  • triangles (the triangle index of the BufferGeometry)
  • normals (the BufferGeometry attribute normal)

as described e.g. in BufferGeometry or Three.js Custom BufferGeometry

plus additionally the attribute

  • edges

to define which edges of the mesh should be shown.

The 4 attributes (vertices, triangles, normals, edges) define an object called Shape, see Class Shape

Multiple Shapes can be arranged as an hierarchical tree. This tree is modelled as Shapes object, see Class Shapes

The ids on each level define a path to each node and leaf of tree, e.g. /level1/level2_obj1/level3_object7 and so on.

States

For each leaf of the tree a 2 dim tuple needs to be provided to define whether shape and edges should be shown

  • 0 = shape/edges hidden
  • 1 = shape/edges shown
  • 3 = shape/edges does not exist

The value 2 is reserved for nodes and shows a mixed state, i.d. some of the children are show, some not.

For the States object, see Class States

Getting started

  1. Install yarn on your system (ie. npm i -g yarn) if not already done;
  2. Clone the repository: git clone https://github.com/bernhard-42/three-cad-viewer.git && cd three-cad-viewer;
  3. Start web server: yarn run start and go to the page displayed in the logs (ie. 127.0.0.1:8080)
  4. Build project: yarn run clean; yarn run build; yarn run docs;

Skeleton:

<html>
  <head>
    <link rel="stylesheet" href="./dist/three-cad-viewer.esm.css" />
    <script type="module">
      import { Viewer, Display, Timer } from "./dist/three-cad-viewer.esm.js";

      function nc(change) {
        console.log("NOTIFY:", JSON.stringify(change, null, 2));
      }

      const options = {
        theme: "light",
        ortho: true,
        control: "trackball", // "orbit",
        normalLen: 0,
        cadWidth: 800,
        height: 600,
        treeWidth: 240,
        ticks: 10,
        normalLen: 0,
        ambientIntensity: 0.9,
        directIntensity: 0.12,
        transparent: false,
        blackEdges: false,
        axes: true,
        grid: [false, false, false],
        timeit: false,
        rotateSpeed: 1,
      };

      const shapes = {}; // a Shapes object, see example or API docs
      const states = {}; // a States object, see example or API docs

      // 1) get the container
      const container = document.getElementById("cad_view");

      // 2) Create the CAD display in this container
      const display = new Display(container, options);

      // 3) Create the CAD viewer
      const viewer = new Viewer(display, true, options, nc);

      // 4) Render the shapes and provide states for the navigation tree in this viewer
      viewer.render(shapes, states);
    </script>
  </head>

  <body>
    <div id="cad_view"></div>
  </body>
</html>

Examples

To understand the data format, a look at the simple 1 unit sized box might be helpful:

APIs of Viewer, Display, Camera and Controls

Back to Github repo

Development

Run a web server in watch mode

yarn run start

For the deployment, see Release.md

Changes

see Changes.md

More Repositories

1

jupyter-cadquery

An extension to render cadquery objects in JupyterLab via pythreejs
Python
257
star
2

vscode-ocp-cad-viewer

A viewer for OCP based Code-CAD (CadQuery, build123d) integrated into VS Code
Python
96
star
3

spark-yarn-rest-api

Demonstrates how to submit a job to Spark on HDP directly via YARN's REST API from any workstation
Python
24
star
4

Spark-ETL-Atlas

A small project to show how to add lineage to Atlas when using Spark as ETL tool
Jupyter Notebook
12
star
5

cadquery-massembly

A manual assembly system based on mates
Python
11
star
6

cadquery-jupyter-extension

An extension to view X3DOM content created by CadQuery 2.x
Jupyter Notebook
9
star
7

ssh_ipykernel

A remote jupyter kernel via ssh
Python
9
star
8

cad-viewer-widget

An ipywidget based interface to the Javascript three-cad-viewer
Python
8
star
9

vscode-cadquery-viewer

A viewer for CadQuery integrated into VS Code based on three-cad-viewer
TypeScript
7
star
10

Spark-Masterclass

Shell
7
star
11

db-12-vscode

Send code blocks (Python, SQL, Scala, R) to a Databricks cluster
TypeScript
6
star
12

ranger-options

Helper to set some Apache Ranger 0.6 options
Python
5
star
13

Alg123d

Python
4
star
14

zeppelin-ipython-shim

A thin layer to enable visualisation libraries like Bokeh to draw into the browser using the IPython display system calls
Python
4
star
15

audio-fingerprinting-dejavu

Audio fingerprinting algorithm based on https://github.com/worldveil/dejavu ported to scala
Scala
4
star
16

spark-unzip

How to use zip and gzip files in Apache Spark
Python
4
star
17

kubernetes-on-bare-metal

Shell
3
star
18

zeppelin2md

Convert Zeppelin Notebooks to Github Markdown as Readme.md
Python
2
star
19

20newsgroups-spark

2
star
20

db-12-kernel

Python
2
star
21

tiny-hadoop

A pseudo-distributed HDFS with YARN, Spark 2.3 and Oozie in a docker container
Shell
2
star
22

advanced-angular-for-pyspark

Adding a way to call javascript methods from Python in Apache Zeppelin
Python
2
star
23

nvd3-stat

Python
1
star
24

mlflow-experiments

Jupyter Notebook
1
star
25

kerberos-hdfs

A podman pod with kdc, kereberized hdfs and spark
Shell
1
star
26

spark-app.g8

Scala
1
star
27

jupyter-cadquery-widgets

Widgets for jupyter-cadquery
JavaScript
1
star
28

ocp-tessellate

Tessellate OCP (https://github.com/cadquery/OCP) objects to use with threejs
Python
1
star
29

cadquery-vtk-viewer

Experimental vtk custom Juypter widget
JavaScript
1
star
30

zeppelin-visualizations

Python
1
star
31

Log-Over-Http

A logger to post log messages via HTTP to a central web server that renders it (useful for distributed programs, e.g. Soark on YARN)
Scala
1
star