Three JS tutorial: Slicing a 3D shape with a vertical plane

Can Three JS achieve the functionality of slicing a mesh or object with a plane (specifically along the Y axis) that is movable? I am looking to replicate the capability shown in this image:

The objective is to maintain the integrity of the mesh so that users can adjust the position of the plane and observe how it affects the mesh along the Y-axis.

Answer №1

As per the insights provided by WestLangley in the comment, it appears that the code snippet shared in the reference link is crucial for accomplishing your desired outcome:

// ***** Defining Clipping Planes: *****
var customPlane = new THREE.Plane(new THREE.Vector3(0, -1, 0), 0.8);

// Creating Material
var material = new THREE.MeshPhongMaterial({
    color: 0x80ee10,
    shininess: 100,
    side: THREE.DoubleSide,

    // ***** Configuring Clipping (material): *****
    clippingPlanes: [ customPlane ],
    clipShadows: true
});

var geometry = new THREE.TorusKnotBufferGeometry(0.4, 0.08, 95, 20);

var mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
scene.add(mesh);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Modal window closed - back to the top of the page

I am struggling with a simple modal popup window that does not maintain the scroll position when closed, instead returning you to the top of the page. I am looking for a way to keep it at the same scroll position without much knowledge of Javascript. You ...

Creating movement effects for a line on an HTML5 canvas following a previous animation

I am facing an issue where my straight line starts animating towards the circle right at the beginning of page load. I am struggling with finding the logic to make the line animate in the opposite direction after the first animation is completed (which is ...

Physically eliminate (and obliterate) a component from keep-alive

Is there a way to access and programmatically unmount a component instance loaded from Vue Route and persisted using <keep-alive> and <component>? I am working on a dynamic tab system where each tab renders a URL which displays its declared com ...

Utilizing dropzone.js for file uploads triggered by clicking with ASP.NET Service

Hello everyone and thank you in advance for your help. I am trying to implement a Dropzone.js Upload box on my webpage where users can drag and drop files into the box and then click a button to upload them to a folder using a backend API. However, I am fa ...

Encountered an issue while processing the firebase get request with the following error message: 'Unauthorized request in Angular'

Here are my rules: Utilizing a Firebase database Calling an API URL from this section https://i.stack.imgur.com/auAmd.png I am attempting to retrieve data from a Firebase API in an Angular application, but I keep encountering an 'Unauthorized reque ...

The date conversion within AngularJS's interpolation is resulting in an incorrect timestamp

Given a timestamp of 1519347000, I am trying to convert it into a date format using interpolation like so: {{$ctrl.myTimestamp | date:'MMM d y, hh:mm'}} The resulting value is Jan 18 1970, 04:02, which is incorrect. The correct date should be F ...

Display Quantity of Current Website Visitors

Similar Question: how to track website visitors using java script or php I am looking to retrieve the current number of viewers on a webpage that has an embedded stream. Is there a method to accomplish this utilizing PHP and AJAX, in order to display ...

Issue Detected at a Precise Line Number - Android Studio

Despite my numerous attempts to modify the specific line in question, including leaving it empty, turning it into a comment, or removing it entirely, the error message persists. I even went as far as deleting the class and creating a new one, but the same ...

The app.use function encountered an error stating "Cannot modify header information - headers already sent"

Within my app.js file, I have the following code snippet: app.use(function(req, res, next){ if(!req.user){ res.redirect('/login_'); } next(); }) Upon reviewing the above code, everything appears to be correct. In my route/index.js fi ...

Update the JavaScript and CSS files following an AJAX request with $.get

I am encountering an issue where my global CSS and JS files contain all the necessary definitions, but when I load new HTML blocks via AJAX $.get, these new elements do not receive the correct CSS/JS definitions. Is there a convenient way to refresh the ...

The implementation of reflux involves creating a shared component, where the data from the final component will overwrite all existing data

Dear friends, I have been facing a problem for a week that I need your help with. I have used React and Reflux to build a common component. I have used props to set different values for each component, but unfortunately, it is not working as expected. T ...

I am encountering an issue where the threejs lighting effects, such as pointlight and ambientlight, are not functioning properly in version "three": "^0.164.1". What could be causing this problem

Embarking on my first threejs project using vite and the threejs library I implemented the following light functions in my JS file: // Emit light evenly in all directions from a specific point in space const pointLight = new Three.PointLight(0xff0000, 1, ...

When trying to make edits, the cursor automatically jumps to the end of the field

In Safari, there is a strange issue occurring with a text field used for emails. When entering text and trying to edit by moving the cursor, new characters are automatically placed at the end of the text. It seems that the problematic code causing this beh ...

Leveraging window.hash and the power of WordPress htaccess

I have a Wordpress website where I am using Ajax to display posts in a specific section. I am currently having Javascript add the hash tag like this: window.location.hash = id; Everything is working as expected. For instance, it changes the URL to www.my ...

Having difficulty accessing any of the links on the webpage

I'm currently utilizing the selenium webdriver to automate a specific webpage. However, I am encountering an issue where my selenium code is unable to identify a certain link, resulting in the following error message. Exception in thread "main" org ...

What is the best way to animate various sprites using distinct buttons in HTML and CSS?

I've been experimenting with animating a sprite by using different onClick button triggers. I encountered an issue where only one of the buttons works correctly in the fiddle. However, in my local file version, the other buttons work but only once and ...

The property 'join' is undefined for null values

I've recently started learning AngularJS, but I'm having trouble figuring out what's causing issues in my code. Despite trying various approaches, the outcome is always incorrect. <!DOCTYPE html> <html lang="en" ng-app="myApp"> ...

Tips for avoiding Blob data and GUIDs from showing up in your browser's title

Currently, my process involves creating a PDF file on our server and displaying it in the browser using javascript as shown below: file = new window.Blob([data], { type: 'application/pdf' }); var fileUrl = URL.createObjectURL(file); var wn ...

Retrieve information from individual XML nodes in a parsed string

When making an Ajax call to retrieve XML data from a different domain using a PHP proxy to bypass cross-origin restrictions, I am unable to extract the values from the XML nodes and display them in my HTML tags. Despite no errors showing up in the browser ...

When clicking on a checkbox's assigned label, Chrome and IE may experience delays in firing the change event

When a user checks a checkbox under a specific condition, I want to display an alert message and then uncheck the checkbox. To achieve this, I am utilizing the click function on the checkbox to internally uncheck it and trigger necessary events. I have a ...