How to make a 3D rounded corner cube using Three.js

Can a customized cube with rounded edges be constructed using three.js and subsequently textured with an image?

Answer №1

Utilize the RoundedBoxGeometry available in the three.js example library.

const geometry = new RoundedBoxGeometry( 10, 10, 10, 6, 2 );

To incorporate it into your project, follow this import pattern:

import { RoundedBoxGeometry } from './threejs/examples/jsm/geometries/RoundedBoxGeometry.js';

Using version r.131 of three.js

Answer №3

A decade has passed, and we now find ourselves in the roaring 20s.

It seems like the modern solution to this problem is here: https://www.npmjs.com/package/three-rounded-box

In 2016, someone on Three.js github created a rounded rectangle geometry:

https://github.com/mrdoob/three.js/issues/8402

Another approach from 2017 involves using extrude and a custom geometry:

This shape example showcases various shapes with rounded corners, including a cube/box:

https://threejs.org/examples/webgl_geometry_shapes.html

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

Uib-tabset - update triggered by successful HTTP response

I am implementing a modal box with tabs. The first tab allows users to select items and assign them to a user when they click the "Next" button. Upon successful assignment, the next tab automatically displays the configuration for those items. If there is ...

Tips for applying stroke and shadow effects specifically when the mouse is moving over a canvas:

How can we create a shadow and stroke effect for circles drawn using HTML canvas only during mouse hover? I have two circles and would like to add a shadow and stroke effect when the mouse hovers over them. However, the issue is that once the mouse moves ...

Is it possible to load Javascript using AJAX with jQuery?

So I have this JavaScript code that I insert into a webpage using the following: <script type="text/javascript" src="http://ext.nicovideo.jp/thumb_watch/sm13154955?w=640&h=395"></script> It basically places an object/embed code into the w ...

Is there a way to link my search state to the URL and synchronize it with the next.js router?

I have been exploring the react instant search example found at const generateURL = state => `?${qs.stringify(state)}`; const convertSearchStateToUrl = searchState => searchState ? generateURL(searchState) : ''; const urlToSearchState ...

Having trouble including a module in React using the package.json "exports" feature

I encountered an issue while trying to incorporate a (typescript) package into a (typescript) React project. The problem lies in the fact that this particular module utilizes the exports property in the package.json file to determine what can be imported f ...

Tips for properly utilizing the collapse feature

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popp ...

What is the significance of storing a JSON Web Token (JWT) in memory, and what is the process of accomplishing this

Learning about JWTs has been quite the journey. People keep emphasizing not to store it in cookies or local storage, which makes sense. But hearing that I should store it in memory just leaves me scratching my head. Imagine making a fetch request with Jav ...

Obtain the script contents using either jQuery.getScript or jQuery.ajax while specifying the dataType as script

As per the jQuery documentation, when dataType: 'script' is set in $.ajax, it evaluates the response as JavaScript and returns it as plain text. However, despite getting the evaluation process to work correctly, I encounter an issue where in ...

Create a solid CylinderGeometry without any hollow parts

I am working on creating a pie chart using three.js and decided to use the CylinderGeometry. However, I encountered an issue while attempting to animate my pie chart. I would like for each segment of the pie chart to slide out when clicked on. The main p ...

Guide to integrating google-map-react with Next.js

I can't seem to figure out what's causing the issue. I'm attempting to utilize google-map-react in my Next.js application. I followed the example provided on their npm page almost exactly. Here is the code snippet: import React from "re ...

Problem detected in id modification

My JavaScript function is triggered with an onChange event, which works fine when there's only one. <input class="form-control" type="text" onchange="opert(<?php echo $fetch["id_prod"] ?>,1)" id="name" value="<?php echo $fetch["name_prod" ...

Tips for personalizing the close dialog feature in ngDialog

I am working on implementing a unique custom close dialog feature for the close button of ngDialog. Based on specific requirements, in certain scenarios (particularly those involving a form), I need to display an additional ngDialog confirmation popup tha ...

Is there a way to raise an exception from within an AJAX request and a function simultaneously?

Consider the scenario of having a jQuery AJAX call within a function as shown below: function executePageMethod(methodName, parameters) { var currentUrl = window.location.href; $.ajax({ type: "POST", url: currentUrl + "/" + method ...

Rotating an Object3D in Three.js using an axis rotation technique

I am attempting to change the orientation of a mesh that has been loaded into an Object3D using OBJMTLLoader. var obj = new THREE.Object3D(); // loading process... obj.rotation.y += 0.1; //executed within the update function This method works correctly ...

The function .click() fails to execute upon page load, yet it functions successfully when utilized in the console

This is the code I am using: <script> document.getElementById("test").click(); </script> When I try to trigger the click(); function on page load, it doesn't work. However, when I execute it in the console on Firefox, it works ...

Combine the given name with the initial of their surname

Recently, I've been working with the Chakra UI Avatar component and ran into an issue. When attempting to display both first and last name initials, only the first name initial is showing. This problem arises when trying use user data retrieved from a ...

Angular.js and D3 - The Perfect Combination for Dynamic Data Visualization!

Having some trouble creating a chart with angular.js. The chart is not appearing on the page when using rout.js, but it works fine without it. Here's my code: var myapp = angular.module('myapp', ['angularCharts']); function D3 ...

Filtering Dropdown List in AngularJS with a Text Input Field and a Submit Button for Filtering Option Values

After exploring , I discovered a feature that enables users to type in a text box and filter results in a pseudo-dropdown. My goal is to enhance this functionality or come up with a better approach for users to type and filter select box options, ultimate ...

The essential guide to coding Javascript/Ajax in conjunction with Chart.js

I have successfully implemented a controller action in my MVC project that generates a JSON record with the required components. The challenge I am facing now is integrating this data into a pie chart using chart.js. The pie chart should display the counts ...

What is the best way to utilize Google Maps autocomplete while filtering addresses by county and city?

Currently, I am working on a project that requires integration of the Google Maps autocomplete address API. In the registration form, I need to collect the user's address in three separate input fields: Country: ______________ City: _______________ ...