Coder Social home page Coder Social logo

newandy1 / occt-import-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kovacsv/occt-import-js

0.0 0.0 0.0 52.4 MB

The emscripten interface for OpenCascade import functionalities.

License: GNU Lesser General Public License v2.1

JavaScript 14.63% C++ 65.90% CMake 17.28% Batchfile 2.19%

occt-import-js's Introduction

occt-import-js

The emscripten interface for OpenCascade import functionalities. It runs entirely in the browser, and allows you to import brep, step and iges files and access the result in JSON format.

npm version WASM Build Native Build

See it in action in Online 3D Viewer, or check this fiddle for a code example.

How to install?

You can get occt-import-js from npm:

npm install occt-import-js

How to use?

The library runs in the browser and as a node.js module as well.

You will need two files from the dist folder: occt-import-js.js and occt-import-js.wasm. The wasm file is loaded runtime by the js file. There are three public functions in the library:

  • ReadBrepFile to import brep file.
  • ReadStepFile to import step file.
  • ReadIgesFile to import iges file.

All functions have two parameters:

  • content: The file content as a Uint8Array object.
  • params: Triangulation parameters as an object, can be null.
    • If the value is null, the triangulation density is calculated automatically based on the bounding boxes of elements.
    • If the value is not null, the object can have two number values, linearDeflection and angularDeflection. You can find more information about these values here.

Use from the browser

First, include the occt-import-js.js file in your website.

<script type="text/javascript" src="occt-import-js.js"></script>

After that, download the model file, and pass them to occt-import-js.

occtimportjs ().then (async function (occt) {
	let fileUrl = '../test/testfiles/simple-basic-cube/cube.stp';
	let response = await fetch (fileUrl);
	let buffer = await response.arrayBuffer ();
	let fileBuffer = new Uint8Array (buffer);
	let result = occt.ReadStepFile (fileBuffer, null);
	console.log (result);
});

Use as a node.js module

You should require the occt-import-js module in your script.

let fs = require ('fs');
const occtimportjs = require ('occt-import-js')();

occtimportjs.then ((occt) => {
	let fileUrl = '../test/testfiles/simple-basic-cube/cube.stp';
	let fileContent = fs.readFileSync (fileUrl);
	let result = occt.ReadStepFile (fileContent, null);
	console.log (result);
});

Processing the result

The result of the import is a JSON object with the following structure.

  • success (boolean): Tells if the import was successful.
  • root (object): The root node of the hierarchy.
    • name (string): Name of the node.
    • meshes (array): Indices of the meshes in the meshes array for this node.
    • children (array): Array of child nodes for this node.
  • meshes (array): Array of mesh objects. The geometry representation is compatible with three.js.
    • name (string): Name of the mesh.
    • color (array, optional): Array of r, g, and b values of the mesh color.
    • face_colors (array, optional): Array of face color groups.
      • first (number): The first triangle index with this color.
      • last (number): The last triangle index with this color.
      • color (array): Array of r, g, and b values of the color.
    • attributes (object)
      • position (object)
        • array (array): Array of number triplets defining the vertex positions.
      • normal (object, optional)
        • array (array): Array of number triplets defining the normal vectors.
    • index (object):
      • array (array): Array of number triplets defining triangles by indices.

How to build on Windows?

A set of batch scripts are prepared for building on Windows.

1. Install Prerequisites

Install CMake (3.6 minimum version is needed). Make sure that the cmake executable is in the PATH.

2. Install Emscripten SDK

Run the Emscripten setup script.

tools\setup_emscripten_win.bat

3. Compile the WASM library

Run the release build script.

tools\build_wasm_win_release.bat

4. Build the native project (optional)

If you want to debug the code, it's useful to build a native project. To do that, just use cmake to generate the project of your choice.

How to run locally?

To run the demo and the examples locally, you have to start a web server. Run npm install from the root directory, run npm start and visit http://localhost:8080.

occt-import-js's People

Contributors

kovacsv avatar matthijs166 avatar

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.