Giter Site home page Giter Site logo

three-cad-viewer's Introduction

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. Run yarn install to install dependencies
  4. Start web server: yarn run start and go to the page displayed in the logs (ie. 127.0.0.1:8080)
  5. 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

three-cad-viewer's People

Contributors

bernhard-42 avatar bogdanthegeek avatar jojain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

three-cad-viewer's Issues

Add yarn install to the readme

In the section Getting started after point 2 there should be a yarn install command before point 3.
Without it, at least in my case, yarn run start gives an error that it can't find rollup.

h3n3

Generation of model for the viewer

Hi,
I wanted to integrate this viewer in the documentation of a project, but I cannot find information about the actual format used by the example files.
How have those file been generated? Is it one of the export formats provided by CadQuery?
Thank you!

publish on yarn registry

Currently my VSCode extension attempt uses static files I manually download from the release page in this repository, and I don't want to commit them.

In order to correctly deal with the three-cad-viewer dependency, it could be appreciated to publish the package in the Yarn registry, as you did with jupyter_cadquery, and update it for each release. ๐Ÿ™‚

how to used ?

i have a stp model file ,how to used your project to load the stp file ?

custom cad

Sorry, I searched all the directories and didn't seem to see the local CAD file loaded. How can I modify it to support custom CAD files?

Enhancement: Add XYZ axis labels to the origin axis marker

See the original issue here: bernhard-42/vscode-ocp-cad-viewer#13

Probably best to have it here where the actual code resides. Here is my non-working attempt to modify orientation.js which holds the "trihedron"

    const loader = new THREE.FontLoader();
    loader.load('examples/fonts/helvetiker_regular.typeface.json', function ( font ) {
      var textGeometry = new THREE.TextGeometry( "text", {
        font: font,
        size: 50,
        height: 10,
        curveSegments: 12,
        bevelThickness: 1,
        bevelSize: 1,
        bevelEnabled: true
      });
      var textMaterial = new THREE.MeshPhongMaterial( 
        { color: 0xff0000, specular: 0xffffff }
      );
      const textmesh = new THREE.Mesh(textGeometry, textMaterial);
      this.scene.add(textmesh);

provide default up option

The new release introduced a new bug with error cameraUp[this.up] is undefined, coming from this.pCamera.up.set(...cameraUp[this.up]); in camera.js (probably introduced in af2cfc8).

I had to manually set options.up = 'Z' to fix this, but I think a default value should be set.

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.