Giter Site home page Giter Site logo

angydev / threejs-offset Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 2.0 2.98 MB

Create an offset sets of points or an offset mesh from an STL file

License: MIT License

CSS 10.36% HTML 6.39% JavaScript 83.26%
threejs threejs-example threejs-learning 3d javascript

threejs-offset's Introduction

Offset with three.js

Create an offset set of points or an offset mesh from an STL file using the three.js library.

Demo

https://threejs-offset.netlify.app/

Offset

Table of Contents

General info

This simple application gives you a basic idea of an offset on a mesh. You can try the functionality with different files and different offset values.

With this application is possible to try adding an offset to your mesh and obtain a list of points or a meshed offset. We have two different algorithms, one to manipulate the point offset and another for the meshed offset.

The logic of the first algorithm is based on getting the vertices and the normals of the geometry of the selected mesh and creating an array of new vertices with the given offset and then creating a new 3D object, with points.

The logic of the second one is more complicated and the results are not perfect, but it's a starting point. Let's look at the steps to obtain the meshed offset.

A mesh has a geometry with a list of vertices and normals. We want to get the faces of the mesh, calculate a new position with the passed offset and the normal of the faces and then reposition the faces in the correct place.

  1. Exports the mesh as a not binary file and creates an object with the number of the face, the normal of this face and the three vertices of the face
  2. Creates a hash table with the vertex in common on more faces as the key and the value is a list of objects with the face, the normal and the position of the vertex in the face.
  3. Calculates the sum of the normals of the faces with the same vertex in common
  4. Normalizes the normal
  5. Calculates the new position with the offset, the normal and the vertex
  6. Adds the new position in the correct position of the new object (this is a clone of the initial object)
  7. At the end calculates the new normals with the new positions and completes the new object
  8. Creates a mesh from the new objects

Issues

  • The process can be slow when trying to load relatively complex models with a lot of faces. If you want, you can move the files offsetObjectHash and hashTable to a node.js server.
  • The process does not work in some cases, for example, with a sphere. I'm working on it. If you have some ideas on how to improve it, please open an issue, I appreciate that.

Setup

If you want to start the application locally:

  1. Clone the project git clone [email protected]:AngyDev/threejs-offset.git
  2. With your terminal go to the folder where you cloned the project
  3. Run the command npm install to install the project's dependencies
  4. Run the command npm run build that creates the dist folder
  5. Run the server with the command npm run start
  6. If all is correct the browser will be open to the localhost:8080 url

threejs-offset's People

Contributors

angydev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

xjindf fanqiehc

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.