Developing a collection of customized shapes comprised of circular-edged rectangles using the Three.JS

I have been on a quest for some time now. My aim is to replicate this visual element from - the beautifully arranged deck of cards. I know it was created using Three.JS, and my goal is to recreate it exactly as seen in that link.

The challenge I'm currently facing is my lack of experience with JavaScript and 3D-rendered objects. Despite this obstacle, I have chosen to tackle this project as part of my studies and am determined to succeed. Can someone offer their assistance, please?

My current code is a nonsensical mess and belongs in the trash. For this reason, I have not included it here. Apologies for the desperate plea, but I am running out of options.

Answer №1

If you're looking to create a rounded rectangle appearance for your cards, I recommend checking out this example using THREE.Shape.

To make a flat card, you can refer to this live demo.

// Customize dimensions for the card shape
const x = 0;
const y = -0.1;
const width = 1;
const height = 1.2;
const radius = 0.2;

// Define the shape of the card
const shape = new THREE.Shape()
  .moveTo(x, y + radius)
  .lineTo(x, y + height - radius)
  .quadraticCurveTo(x, y + height, x + radius, y + height)
  .lineTo(x + width - radius, y + height)
  .quadraticCurveTo(x + width, y + height, x + width, y + height - radius)
  .lineTo(x + width, y + radius)
  .quadraticCurveTo(x + width, y, x + width - radius, y)
  .lineTo(x + radius, y)
  .quadraticCurveTo(x, y, x, y + radius);

// Create the card mesh
const geometry = new THREE.ShapeGeometry(shape);
const material = new THREE.MeshBasicMaterial({ side: THREE.DoubleSide });
const mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);

For arranging the cards in a grid layout, you can calculate their positions based on size and desired spacing. Obtain the object dimensions with Box3#getSize. This is used in the above demonstration to center the object within the scene.

const size = new THREE.Vector3();
new THREE.Box3().setFromObject(mesh).getSize(size);

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

Using Angular 4's ngModel can result in the transformation of data type from 'number' to 'string'

I am facing an issue with my Angular4 app where data captured from a form is stored in DynamoDB. The problem arises when an input field typed as 'text' is bound to a Typescript 'number' field, which seems to be converting the object val ...

Is there a way to implement request-specific global variables for individual websocket connections in a Node.js application, similar to using res.locals for

Currently, I'm working on creating global variables within the io.use method of the socket.io server-side library. The goal is to have variables that are accessible throughout the entire request lifecycle for websockets. My setup involves using the ex ...

Dealing with the challenges posed by middleware such as cookie access and memory leaks

Utilizing express with cookieParser() where my client possesses the cookie named: App.Debug.SourceMaps. I've crafted a middleware as follows: app.get('/embed/*/scripts/bundle-*.js', function(req, res, next) { if (req.cookies['App ...

I am looking to retrieve the values of checked checkboxes in a MUI multi-select component

I am currently using Material-UI's mui multi select component and I need to determine whether an item is selected or unselected in order to set the correct state value. I have checked the event.target but it does not seem to have a checked attribute. ...

Attempting to eliminate the mouseleave event by utilizing the jQuery off function

I have a set of buttons in an array and I want to remove the event listeners for each button once it has been clicked. Here is my current approach: JavaScript: var currentButton; var selectedButtons = $("#moto-menu a"); function onEnter(){ TweenMax. ...

Selecting the content within a table to easily edit it

I am working on a project where I have a table filled with data fetched from a database. My goal is to allow users to click on a cell in the table, make changes to its content, and then save those changes back to the database. Below is the code snippet I a ...

Sending a JavaScript click event using curl and PHP

Attempting to extract information from a website. The main page contains multiple option buttons along with an ACCEPT and RESET button. When the user selects options and clicks on the ACCEPT button, new content is displayed. I have a question regarding ma ...

Using Javascript to multiply strings

While working on the leetcode problem related to multiplication, I encountered an interesting issue. Given two non-negative integers num1 and num2 represented as strings, the task is to return the product of these two numbers, also in string form. However ...

How to dynamically assign classes to a group of radio buttons based on their current state using ReactJS

I've been attempting to dynamically assign classes to radio buttons, but I'm facing difficulties in doing so. I'm trying to create a switch with radio buttons for "ENABLED, PENDING, DISABLED". Based on the selected radio button, I want to ch ...

A tip for transferring the value of a binding variable to a method within the template when the button is clicked

I am currently exploring the concept of binding between parent and child components using @Input, @Output, and EventEmitter decorators. This is demonstrated in the HTML snippet below: <h1 appItemDetails [item]="currentItem">{{currentItem}}& ...

Updating comment content using Ajax

I am in the process of using Ajax to insert my comment content. However, I seem to be facing some issues with the comment_add.php page. I was hoping someone could review it for me. While I have successfully obtained the streamid as checked in firebug, no ...

Invoke the jQuery document.ready function within a separate jQuery or JavaScript function

Encountering a difficult issue: Attempting to invoke the document.ready() function inside another JavaScript function, but upon doing so, an error message stating "function is not defined" appears. Below is the provided code: This first function serves as ...

javascript for transforming date format

My textfield is set to be a date field with a jQuery datepicker(). The dateFormat() is dd-mm-yy, which works perfectly. However, MySQL requires dates to be in yyyy-mm-dd format. I am wondering if I can convert the date format using PHP or JavaScript before ...

Tips for disabling the default behavior by using preventDefault in JavaScript

I need help with removing the preventDefault() function and submitting the form in the else condition of my code. Does anyone know how to achieve this? if(email.val() != ""){ //check email e.preventDefault(); $.ajax({ ...

What is the most efficient way to transfer a string to a python program using ajax and retrieve a string in return?

I'm experiencing a problem with my ajax request where I am sending an object to a python program using JSON: $.ajax({ url: "http://localhost/cgi-bin/python.cgi", type: "POST", data: JSON.stringify(myobject), dataType: ...

I currently have a set of 6 popovers that all open simultaneously, but I am looking to make them open sequentially, one after

My component generates a div with 6 different experiences, each with its own popover. However, when I click on an experience to open its popover, all 6 popovers appear. How can I assign a unique ID to each popover? This is the code for my experience compo ...

Problem encountered when utilizing the jQuery method .load()

Currently, there is an issue on my website where I am trying to load the content of a PHP file into a <div>. After ruling out any server-side problems, I have come to seek help with this question: Is there anything incorrect in the following code? & ...

Issue with cross-origin in Salesforce reply (Access-Control-Allow-Origin)

While attempting to retrieve records from Salesforce using external local files via JS, I encountered an issue. Although I can see a response in the network tab, the console displayed the following error message: "XMLHttpRequest cannot load . No 'A ...

Using the jQuery function in conjunction with Infinite Ajax Scroll provides a seamless scrolling

Utilizing jQuery for filtering options can enhance the user experience. For instance, selecting the "dead" option displays only rows with the status "dead". However, when implementing infinite Ajax scroll to load new data from the database, the filter sett ...

What causes the scrollbar to move while I am dragging the div downward on the page?

$('#aaa').draggable(); * { margin: 0; padding: 0; } #aaa { width: 800px; height: 800px; position: absolute; background: red; } .wrap { height: 2000px; position: relative; ; } <div class="wrap"> < ...