What is the best method for dividing a 3D model into two sections using a plane?

Can anyone provide guidance on splitting a figure into two parts within a plane, similar to the image reference provided?

https://i.sstatic.net/GYEuY.png

I attempted the method outlined in this link without success. I would appreciate any insights on how to successfully divide the figure into two sections. Three JS - How to cut a 3D object with Y plane?

Answer №1

To achieve this, you have two options:

Duplicating and Clipping planes

Begin by enabling local clipping planes to clip a mesh individually without affecting others.

const renderer = new WebGLRenderer()
renderer.localClippingEnabled = true

Next, duplicate the mesh. It's recommended to create an instance of the Mesh, ensuring you have a copy of the shape. Also, remember to clone and assign the material to the copy.

let clonedMesh = yourMesh.clone()
clonedMesh.material = clonedMesh.material.clone()

Create two clipping planes facing in opposite directions and apply one to the original mesh and the other to the clone using the Material. Ensure that the normal points in the direction the clipping plane will maintain visibility.

let localPosition = new Vector3()
let normal = new Vector3(0, 1, 0) // example for +Y

let clipPlane1 = new Plane().setFromNormalAndCoplanarPoint(normal, localPosition)
normal.negate() // reverses the normal
let clipPlane2 = new Plane().setFromNormalAndCoplanarPoint(normal, localPosition)

originalMesh.material.clippingPlanes = [clipPlane1]
clonedMesh.material.clippingPlanes = [clipPlane2]

After rendering, the shapes will clip in different directions, showing only their respective sides. As they are specific to each shape, transformations applied to a shape will be followed by its clipping plane.

Geometry-based segmentation

This is a broad topic and won't delve into details here. The basic concept involves having a plane intersecting your geometry. If a triangle in your geometry crosses the plane, it needs replacement with new triangles aligning their edges on the plane rather than passing through it. This procedure results in two distinct geometry buffers linked to separate Mesh instances.

There may be three.js-compatible tools available for such operations, although I'm not immediately aware of any.

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

Testing multiple regex patterns using jQuery

I am attempting to run multiple regex tests on an input field. Here is the script: $("#search-registration").keyup(function () { var input_data = $('#search-registration').val(); var regexTest = function() { this.withPrefix = /^ ...

The AngularJS UI router is encountering an unexpected error: GET request not recognized

Need help with AngularJS Routing using UI-Router. My index.html file is attempting to load the partial productListView.html using app.js as javascript, but I'm encountering an error: "Unexpected request: GET productListView.html" in the console. Any a ...

The function .click does not function properly when used with an anchor element within a figure tag

In my JavaScript-loaded figure, there is an image description and two buttons. Sometimes the description contains a link with a fig attribute, like this: <a fig="allow" href="#tt5">[1]</a> If the anchor is not in a figure and has a fig attrib ...

How come when I go back through ajax, my markers always seem to land in the top left corner?

If you incorporate a Google Map on a webpage in http://jquerymobile.com, and navigate away from the page before returning, all the markers will relocate to the top left corner. For instance: This is how my jQuery JavaScript code begins: $('.page-m ...

How to make a HTML div background fill the entire page

Is there a way to extend the background in a div so that it adjusts to fit the screen resolution? I also want to include a navigation bar at the top right corner of this div for the intro page. There will be additional content in other divs positioned be ...

Tips for Identifying Different ID Values of HTML Elements with jQuery

Currently, I have two different divs on my webpage, each containing buttons and hidden fields. When I try to pass the value of the hidden field attached to the button in a jQuery function, I encounter an issue where clicking on the second div results in pa ...

Easiest method for implementing event emitter in ES6

Here is the current setup for my event emitter: class Table { set onDiscard(cb) { this._onDiscard = cb; } notifyDiscard(s) { if (this._onDiscard) { this._onDiscard(s); } } } Dealing with multiple events using this method can b ...

Incorrect sequence detected in JQuery animation execution

I'm currently developing a game called 'Pointless', inspired by the popular UK game show of the same name. In the game, there is a countdown that starts at 100 and decreases to display the team's score. I'm attempting to recreate t ...

ng-hide is not functioning to display the form

I'm trying to display a form using ng-if when the "add" button is clicked, but it's not working. I've looked at several examples and tried them all, but none have worked for me. Here is the code I am using: angular.module('myFormApp&ap ...

Strategies for transferring data between JavaScript objects

Looking for a way to map values from one object to another when the keys match. I've tried to assign values using the code additionalData.value =userParams[prop] ? userParams[prop] : '';, but it's resulting in an empty string. Any ideas ...

Firefox compatibility issue caused by jQuery's appendTo function disrupting hyperlink functionality

I've successfully implemented the material design ripple effect using jQuery, which functions well in IE11 and Chrome 46. However, I've encountered an issue in Firefox 39 where applying the effect to links prevents redirection. Upon investigation ...

What causes immediately invoked functions within event handlers to be executed before the event is triggered?

let b = (function maria() { alert("ee"); })(); * this code runs as soon as the page loads * <button onclick="b">Click me</button> * this code only runs when button is clicked * <button onclick="alert('ee')">Click m ...

Confirming the presence of a click event listener for an object that is yet to be instantiated

So, I've been working with jQuery and encountered this scenario: $(document).ready(function(){ $('#btn1').click(function(){ //Adding content to a table $('#items_table tr:last').after('<tr><td> ...

Instructions on converting a SQL expression to Sequelize

Could someone assist with converting this to sequelize? CREATE TABLE "fundraiserUpdates" ( "updateId" SERIAL, "updateFundraiserId" INTEGER NOT NULL, "updateTitle" TEXT NOT NULL, "updateDescription" TEXT NOT NULL, CONSTRAINT "pk_fundraiser ...

Struggling with retrieving the $id variable from the view in both the controller and the database through Ajax

While checking my view, I noticed that the variable $id is visible. However, when I send it through Ajax, it ends up as NULL in the database. The way I'm sending the variable $id from the view using Ajax is like this: $.ajax({ url:'{ ...

Upon successful completion of the Ajax call, refresh the page without causing any blinking

Hey there, I'm facing an issue with my website, I've implemented ajax to fetch data from my API, and upon successful retrieval, I need to reload the page to display the information, However, sometimes the page blinks before reloading, while oth ...

Tips for updating Nodejs' module dependency to a newer version

Currently, my project utilizes the react-cropper library which includes version cropper ^0.10.0. However, I require certain methods from cropper version 0.11.1. To address this issue, I decided to fork the project to my own GitHub repository in order to up ...

Encountering a problem with the scope of child_process in Node

When utilizing the child_process module in Node.js with the fork method, I am able to send data to a specific file and receive a response. However, I am not logging this data to the console after receiving it from the execution process. The code in first. ...

incorporating customer functions into telerik drop down menu renders it immobile

I have been encountering an issue with adding client events to a Telerik dropdown list. Whenever I try to add these client events, the dropdown list becomes static. In other words, it ceases to function as a dropdown list - it no longer responds when click ...

Duplicating a file within the Flask app directory while understanding its designated web route

After creating a web path of a file, I utilized the following code snippet: URL.createObjectURL(event.target.files[0]); Following an ajax call, I sent this link to Python (Flask). I am now interested in learning how to utilize this link to duplicate the ...