Slice the edges of the depth on a shape created with ThreeJS ExtrudeGeometry

I have a 3D shape (THREE.Shape) that I created in Threejs using some vertices. I then used ExtrudeGeometry to give it a 3D appearance. Now, I need to add a 45-degree cut to the edges of this shape. However, the challenge lies in cutting the edges of the extruded part of the geometry. Despite my efforts, I have not been able to find a solution for this anywhere. I will do my best to clarify the actual requirement.

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

My goal is to specifically cut the edges of the extrude part rather than the face. Please refer to the image below for better understanding.

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

It's important to note that this is not the face of the shape. The simple shape without the extruded part looks like this:

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

If there is anyone who can assist me in finding a solution to this problem, I would truly appreciate their help in resolving this issue.

Answer №1

Here is a suggestion on how you could approach it:

var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(60, innerWidth / innerHeight, 1, 100);
camera.position.set(0, 0, 20);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(innerWidth, innerHeight);
document.body.appendChild(renderer.domElement);

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

var w = 1;
var h = 3;
var d = 10;

var pts = [
  new THREE.Vector2(-w, h),
  new THREE.Vector2(-w, -h),
  new THREE.Vector2(w, -w),
  new THREE.Vector2(w, w)
]

var shape = new THREE.Shape(pts);
var shapeGeom = new THREE.ExtrudeBufferGeometry(shape, {
  depth: d * 2,
  bevelEnabled: false
});
shapeGeom.center();
shapeGeom.rotateY(-Math.PI * 0.5);

// Making a 45-degree cut
var pos = shapeGeom.getAttribute("position");
var temp = new THREE.Vector3();
for (let i = 0; i < pos.count; i++) {
  temp.fromBufferAttribute(pos, i);
  let signX = Math.sign(temp.x);
  let shift = h - temp.y;
  pos.setX(i, temp.x - (shift * signX));
}
pos.needsUpdate = true;

var shapeMat = new THREE.MeshBasicMaterial({
  color: "aqua",
  wireframe: true
});
var mesh = new THREE.Mesh(shapeGeom, shapeMat);
scene.add(mesh);

renderer.setAnimationLoop(() => {
  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>

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

Is there a way to automatically convert a webpage to a PDF when it is requested?

I'm looking to convert the webpage into a PDF file upon request. Below are the scripts I am using: <script> pdfdoc.fromHTML($('#container').html(), 10, 10, { 'width': 110, ...

Update Calendar Information Without Reloading the Entire Page

Is there a way to automatically refresh a div that includes a FullCalendar Calendar? I'm looking to refresh the div every 30 seconds to check for new data from the database without having to modify the ViewModel or reloading the page. index.html &l ...

What is the best way to incorporate messages across various channels with a Discord bot?

While browsing through the questions of other users, I stumbled upon exactly what I was looking for. My dilemma now is how to make the same bot perform similar tasks on various channels but with different titles, footers, and so on... The primary code sni ...

Guide to incorporating eslint with Next.js in a project that already has an eslint configuration

I recently created a new next.js project within my existing Node.js project, which already has an eslint config set up. Here's how the folder structure looks now: ...

Choose the right Vue.js component for optimal performance

I have a primary element within which there is a secondary element with vue.js 2.0. The issue arises when the secondary element relies on methods from the primary element. Here's an illustration: Vue.component('primary-element', { tem ...

Encountering an error when attempting to access the 'path' property of undefined from a user-defined input file in Bootstrap 4

I'm currently working on a form that includes a custom input group for selecting a local image file. Unfortunately, I am having trouble retrieving the file name in my server code. Despite checking req.body and trying req.file.path, I have been unable ...

Is it necessary to include async/await in a method if there is already an await keyword where it is invoked?

Here are the two methods I have written in Typescript: async getCertURL(pol: string): Promise<string> { return await Api.getData(this.apiUrl + pol + this.certEndpoint, {timeout: 60000}).then( (response) => { return response.data.certUR ...

Flatbuffers does not exist in this context

Currently, I am working on a nodeJs application that involves the use of Google Flat Buffer. After installing flatc on my MacBook Pro, I compiled the schema below: namespace MyAlcoholist; table Drink { drink_type_name: string; drink_company_name: stri ...

Ajax causing unreliable posts

I am facing an issue with sending and receiving data in my mobile application. I currently use the jquery $.post function, but it seems to be quite unreliable. Issue: Occasionally, about 1 out of 10 times, the POST request is sent successfully, but the ca ...

Exploring the capabilities of JavaScript on the iOS platform

Here is the code I've written for my iOS application: webView = [[UIWebView alloc] init]; webView.delegate = self; [webView loadHTMLString:@"<script type=\"text/javascript\" src=\"myFile.js\"></script& ...

Implementing Routes in Express Using Typescript Classes

Seeking assistance in converting a Node.js project that utilizes Express.js. The objective is to achieve something similar to the setup in the App.ts file. In pure Javascript, the solution remains unchanged, except that instead of a class, it involves a mo ...

Steps for implementing AJAX to display a success function and update database results in real-time

I'm struggling with allowing my AJAX call to send data to my PHP file and update the page without a reload. I need the success message to display after approving a user, but their name doesn't move on the page until I refresh. The goal is to app ...

Retrieve information from an Express server using SweetAlert

Hi, I have created a web server using Node.js and Express. When I send a request to ip/test, it returns the text 'test' using res.send('test'). I am trying to fetch this text using sweetalert but I always encounter errors :( Here is t ...

Test fails in Jest - component creation test result is undefined

I am currently working on writing a Jest test to verify the creation of a component in Angular. However, when I execute the test, it returns undefined with the following message: OrderDetailsDeliveryTabComponent › should create expect(received).toBeTru ...

After executing "npm run dev" in Svelte and Vite, a common error message of "HTMLElement is not defined" might appear

Incorporating several web components into my Svelte project led to the appearance of an error message stating HTMLElement is not defined after running npm run dev (which actually translates to vite dev). The complete error message reads as follows: HTMLEl ...

Insert fixed text before or after the input value without altering the value itself

Is it possible to prepend or append additional text to an input value? I am looking to customize the display of a value without altering the actual value itself. For instance, if the value is 1000, I want it to still return 1000 when accessed. <input ...

What is the best way to organize and group messages in JavaScript in order to push them to a subarray?

Having trouble coming up with a name for this question, but here's the issue I'm facing: I currently have an array in PHP containing several entries. Array ( [0] => stdClass Object ( [sender_id] => 0 [me ...

Dynamic class name changes in Angular.js based on JSON object

I am trying to dynamically change the class of an <li> element based on the category value I am getting, but for some reason the class name won't update. Here is the code snippet: <div id="content"> <ul id="container" ng-controller ...

The Meteor method is unable to access the property "quantity" as it is undefined

I encountered an issue with the error message "TypeError: Cannot read property 'quantity' of undefined" while executing a meteor method. Here is the frontend call: Template.listingPage.events({ "submit #add-to-cart": function(e,t){ e.preven ...

Troubleshooting: Dealing with Stack Overflow Error when using setInterval in Vue Programming

I am facing a stack overflow error while creating a timer using Vue, and I'm struggling to understand the root cause. Can someone provide insights on the following code: Here is my template structure: <span class="coundown-number"> { ...