Is there a way to trim the current shapes in three.js?

I have created a shape similar to this using Box Geometry at the following link: https://jsfiddle.net/cdu96z3c/. I am looking to achieve a design like the image below by properly utilizing v.x and v.z, while maintaining the current corrugation and properties of the shape:

https://i.sstatic.net/7vlwg.jpg

var geom = new THREE.BoxGeometry(50,-.1,150,1,1,150 * 10); 
geom.vertices.forEach(function(v){
    x_val = Math.abs(v.z);
    if((x_val % 9) < 0.75 || (x_val % 9) > 8.25){
      var m = parseInt(x_val/9) *9;
      var l = 0.75 - (m - x_val);
      v.y =  v.y + 0.75 * Math.sin(l* Math.PI/1.5);
    }
    else if(x_val % 3 < 0.25 || (x_val % 3) > 2.75){
      var m = parseInt(x_val/3) * 3;
      var l = 0.25 - (m - x_val);
      v.y =  v.y + 0.25 * Math.sin(l * Math.PI / 0.5);
    }
});`

Answer №1

When you transform your iron sheet into a corrugated form, you unlock its potential for further deformation. The following demonstration illustrates this concept:

var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.set(50, 100, 100);
var renderer = new THREE.WebGLRenderer({
  antialias: true
});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

var controls = new THREE.OrbitControls(camera, renderer.domElement);

scene.add(new THREE.AxesHelper(10));

// Directional lights setup
for (let xCoord of [-1, 1]) {
  for (let yCoord of [-1, 1]) {
    for (let zCoord of [-1, 1]) {
      let directionalLight = new THREE.DirectionalLight(0xffffff, 0.2);
      directionalLight.castShadow = true;
      directionalLight.position.set(xCoord, yCoord, zCoord);
      scene.add(directionalLight);
    }
  }
}

scene.add(new THREE.AmbientLight(0xffffff, .5));

// Creating a corrugated mesh
var geom = new THREE.BoxGeometry(
          150,
          0.1,
          50,
          150 * 10,
          1,
          1
          );

geom.vertices.forEach(function(v){
 let x_val = Math.abs(v.x);
if((x_val % 9) < 0.75 || (x_val % 9) > 8.25){
          var m = parseInt(x_val/9) *9;
          var l = 0.75 - (m - x_val);
          v.y =  v.y + 0.75 * Math.sin(l* Math.PI/1.5);
        }
        else if(x_val % 3 < 0.25 || (x_val % 3) > 2.75){
          var m = parseInt(x_val/3) * 3;
          var l = 0.25 - (m - x_val);
          v.y =  v.y + 0.25 * Math.sin(l * Math.PI / 0.5);
        }
});
geom.computeFaceNormals();
geom.computeVertexNormals();

var corrugated = new THREE.Mesh(geom, new THREE.MeshLambertMaterial({color: "silver"}));
scene.add(corrugated);

btnCut.addEventListener("click", function(){
  
  let cutLength = 125;
  let leftLimit = (cutLength - (geom.parameters.width * 0.5)) * -1;
  
  var marker = new THREE.Mesh(new THREE.SphereGeometry(1, 4, 2), new THREE.MeshBasicMaterial({color: 'red'}));
  marker.position.set(leftLimit, 0, geom.parameters.depth * 0.5);
  scene.add(marker);
  
  geom.vertices.forEach(v => {
    v.x = v.x < leftLimit ? leftLimit : v.x;
  });
  geom.vertices.forEach(v => {
    let zSign = Math.sign(v.z);
    if (v.z < 0) {
    v.z = -(v.x - leftLimit) * Math.tan(THREE.Math.degToRad(60)) + geom.parameters.depth * 0.5;
    v.z = Math.abs(v.z) > geom.parameters.depth * 0.5 ? geom.parameters.depth * 0.5 * zSign : v.z;
    }
  });
  geom.verticesNeedUpdate = true;
}, false);

render();
function render(){
  requestAnimationFrame(render);
  renderer.render(scene, camera);
}
body{
  overflow: hidden;
  margin: 0;
}
    <script src="https://threejs.org/build/three.min.js"></script>
    <script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
    <button id="btnCut" style="position: absolute;">Cut</button>

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

Struggling to iterate through the children of a variable with the help of express-handlebars?

Currently, I am in the process of developing an application using Javascript along with express, express-handlebars, and MySQL. One of my main tasks is to establish a route that follows the pattern '/viewowner/:ID/scoreboards/:year' where ID sig ...

Even after dynamically removing the class from the element, the Click event can still be detected

My buttons have a design like this: <a class="h-modal-btn branch-modal-btn"> Buy Now </a> The issue arises when I need to remove certain classes and add attributes to these buttons based on the query string in the URL. Skipping ahead ...

While iterating over the key with a variable in a loop, only one property is displayed consistently instead of four different

Currently, I am working on creating an address book using JavaScript. The problem I am facing is that the properties of my objects are not providing me with the necessary information. I need 4 different properties instead of 4 loops with the same property. ...

What is the best way to efficiently set up a scrolling text ticker for repeated use?

I am currently utilizing GreenSock/TweenMax for the creation of scrolling text, inspired by the design seen on this webpage: If you're interested in learning more about Greensock and its capabilities, take a look at their documentation here: While I ...

Unable to click on the icon when modifying Mui Text Field

Utilizing the MUI Text Field component, I have successfully added a select prop to transform it into a dropdown list with values and an icon. However, I encountered an issue while attempting to change the default dropdown icon to a custom one from Figma. D ...

Could not locate the express.js file

Currently in the process of learning express/node.js, but struggling to locate the page at localhost:3000/info You can view screenshots of my code below ...

Is there a way to successfully include an apostrophe in a URL?

I am currently utilizing Node.js: var s = 'Who\'s that girl?'; var url = 'http://graph.facebook.com/?text=' + encodeURIComponent(s); request(url, POST, ...) This method is not functioning as expected! Facebook seems to be c ...

Creating an Account with Firebase

I've created a function called signup in my web project that uses JavaScript to add a user to my Firebase database. The function works fine, but I'm encountering an issue when I try to redirect to another page at the end of the function - the use ...

A guide on utilizing Socket.io to efficiently transfer data to a specific client within a designated chat room

Can someone please advise on the correct way to send data to a specific client in a specific room using socket io? The code snippet I have been trying is: I am using the following command: socket.to(socket.id).emit('change', {data}) However, i ...

Ensuring that an md-radio-group is a required field in Angular Material

Currently, I am working on a project using Angular Material where I need to enforce a required radio group. This means that the user must select a radio button before being able to submit the form. The form should be considered invalid if no radio button i ...

Error message stating 'compression is not defined' encountered while attempting to deploy a Node.js application on Heroku

Why is Heroku indicating that compression is undefined? Strangely, when I manually set process.env.NODE_ENV = 'production' and run the app with node server, everything works perfectly... Error log can be found here: https://gist.github.com/anony ...

Shall we Combine JavaScript Files with Import and Require Statements?

Apologies for the vague description, I am trying to be concise while acknowledging my limited understanding and potential incorrect assumptions. I currently have a website that consists of one large HTML file with scripts defined in-line within <script ...

It appears that the use of "window.location" is causing the ajax post

I'm facing an issue with sending data to PHP using AJAX and redirecting to the PHP file. It seems that when I redirect to the PHP file, the data sent through AJAX is not being received. My goal is to have a button click trigger the sending of data to ...

Loading Animation for Pages and Tables

I'm experiencing a choppy and sudden transition when switching between two pages that contain tables populated using ng-repeat. Upon loading, the footer is positioned halfway up the page below the table heading until the table loads and the layout adj ...

How to retrieve items from a DynamoDB table where the fields array is not empty using JavaScript FilterExpression

Can anyone help me with filtering this sample dynamodb table to only return items where either the "old" or "new" array is not empty? In the example below, it should retrieve the items with id "2" and "3". Table: field name = item [ { id: "1", p ...

Enable the Chrome extension to interact with the RESTAPI

As I develop a Chrome extension and Rest API, my current focus is on their integration. However, I have some security concerns that need to be addressed. The purpose of the extension is to retrieve data from the API. This data is not personalized for any ...

What is the best way to pass a JSON object from R to Plumber in a format that JavaScript can interpret as an array instead of

My goal is to receive a JSON raw response from R Plumber and then utilize it in Angular. However, I am encountering an issue where the JavaScript Framework is interpreting it as a string instead of recognizing it as JSON format. "[{\"id&bsol ...

Challenges in creating an alternative path in ExpressJS

I am currently working on a website for my studies. I decided to use nodejs/Express, as the technology is free. The first route /home was successful, but I am having trouble creating more routes. https://i.sstatic.net/6oseq.png Although I thought I had a ...

Guide for Sending a Textnode from One Page to a Different Page within a Specific Id Element through PHP

firstpage.html : <body> <?php $text = $_POST['text']; ?> <p style = "color:red; " id = "getext"><?php echo $text; ?></p> </body> secondpage.php : <body> <?php $text = $_POST['text']; ?> ...

Using express.js to transfer an uploaded image to Amazon S3

Currently, I am faced with an issue of passing an image uploaded from a react application through express to a managed s3 bucket. The s3 bucket is created and managed by the platform/host I am using, which also generates upload and access urls for me. So f ...