Giter Site home page Giter Site logo

angydev / threejs-clipping Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 0.0 69 KB

Clipping multiple objects and close the mesh with the original color of the object

License: MIT License

CSS 7.28% HTML 4.34% JavaScript 88.39%
javascript threejs threejs-example 3d threejs-learning

threejs-clipping's Introduction

Clipping with three.js

Clipping multiple objects and close the mesh with the original color of the object with the three.js library.

I created another repo, three-clipping-vr with the same clipping function but applied to the VR environment. A working progress work.

Demo

https://threejs-clipping.netlify.app

Clipping

Table of Contents

General info

The purpose of this example is to clip the objects, with multiple planes, and to close the mesh with the color of the object itself. It's also possibile to negate the clipping to have the other part of the clipping.

In this case is not possible to choose which part of the objects render with the clipping, maybe a future issue to develop.

The algorithm is composed by the following steps:

  1. Gets the planes in the scene (THREE.PlaneGeometry)
  2. Calculates the center of each plane
  3. Creates a plane (THREE.Plane) for each plane (THREE.PlaneGeometry)
  4. Calculates the barycenter of the planes
  5. Gets the distance from the plane and the barycenter
  6. Negates only the plane with negative distance
  7. Creates the clipping object with colors

Step seven is similar to the official three.js example

The file index1plane.js is the clipping with only one plane. If you want to try this change the name from index1plane to index.

Setup

If you want to start the application in local:

  1. Clone the project git clone [email protected]:AngyDev/threejs-clipping.git
  2. With your terminal go in the folder where you cloned the project
  3. Run the command npm init that create the package.json file
  4. Run the command npm i live-server that install the server on your project
  5. Run the server with the command live-server

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.