How can I create a three-dimensional circle using Circle Geometry in Three.js?

Looking to extrude a quarter Circle Geometry in Three.js?

To create the quarter circle, you can use the following code:

var circle = new THREE.Mesh( 
    new THREE.CircleGeometry( 25, 32, 0, Math.PI/2 ), 
    new THREE.MeshBasicMaterial({ color: 0xffffff, side: THREE.DoubleSide })
);
scene.add( circle );

However, if you want to extrude it instead of just displaying it as a plane, you can explore using THREE.ExtrudeGeometry. It's worth investigating whether this will suit your needs or not.

Answer №1

Here's a demonstration showcasing how to create an extruded shape, specifically a triangle along a straight line. This process aligns with the primary function of the Shape class. Check it out here

// Defining a 2D triangular shape
// The Shape() class facilitates the drawing of 2D shapes
var triangleShape = new THREE.Shape();
triangleShape.moveTo(-2, -2);
triangleShape.lineTo(0, 2);
triangleShape.lineTo(2, -2);
triangleShape.lineTo(-2, -2);

// Generating a new geometry by extruding the triangleShape
// 'amount' denotes the extrusion distance, 'bevelEnabled: false' disables beveling
var extrudedGeometry = new THREE.ExtrudeGeometry(triangleShape, { amount: 5, bevelEnabled: false });

// Utilizing a Mesh to give context to the geometry
var extrudedMesh = new THREE.Mesh(extrudedGeometry, new THREE.MeshPhongMaterial({ color: 0xff0000 }));
scene.add(extrudedMesh);

The essential points to grasp:

  • A 2D shape can encompass any form drawable via the Shape class.
  • ExtrudeGeometry() easily projects along a linear path using the amount parameter while deactivating bevelEnabled. For intricate extrusion paths, consider exploring SplineCurve3.
  • ExtrudeGeometry() produces raw geometry, constituting an array of Vector3 points. Its potential is realized upon integration with Mesh and Material components.

Dive deeper into THREE.js documentation for further insights:

Learn about Shape on THREE.js documentation

Explore ExtrudeGeometry in THREE.js documentation

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

What is the best way to apply the TableRow style in material-ui / mui to make it similar to TableHead?

Trying to implement TableHead styling on TableRow but encountering a warning: validateDOMNesting(...) cannot be a child of. How can this be fixed without triggering a warning message? CollapisbleTableRow.js import React, { Fragment, useCallback } from &ap ...

Tips for maintaining focus on an editable div using jQuery

Is there a way to prevent an editable div from becoming unfocused when clicking on a formatting bar created using jQuery? I've been trying to implement this feature but can't seem to figure it out. Any advice would be greatly appreciated. Many th ...

Using jQuery to update the CSS background of a selected element among multiple elements sharing the same class

I am currently developing a basic jQuery script that will enable the background color of the clicked element to change. Below is the code I have so far: <dt> <input id="p_method_banktransfer" value="banktransfer" type="radio" name="payment[metho ...

Vue watchers capturing original value prior to any updates

When working with Vue.js, we can easily access the value after modification within watchers using the following syntax: watch: function(valueAfterModification){ // ...... } But what about getting the value before it's modified? PS: The official ...

Retrieving Hyperlinks from JavaScript Object for Integration with D3-Created Table

Issue: I'm facing a problem where the HTML link extracted from an Associative Array is treated as a string instead of being applied as a clickable link in the browser. For a detailed visual example and code snippet, visit: http://example.com/code Da ...

Is using selectors a more effective way to retrieve computed data compared to using class methods?

When using react, redux, and reselect in a project, is it preferable to move all computable data from class methods to selectors and avoid mixing the use of both? Are there different concepts behind these approaches? class DocsListView { getOutdatedDocs ...

Guide to swapping images based on conditions using Angular JS

I am trying to display an image based on data received from an API response instead of text. If the value is true, I want to show an access symbol. If the value is false, I want to show a deny symbol. However, when attempting this, I am only getting th ...

What are the possible arguments for the event type onInput?

While diving into the world of html / javascript / vue, I stumbled upon the following code snippet. <input type="text" onInput="doAction(event);"> <script> var mesdata = { message: 'type your m ...

Imagine a scenario where clicking on an image causes it to be rotated or

Could use some assistance figuring out what's missing here. I've added a random photo from Wiki, similar in size to the images I'll be working with. The images will vary in size, but I want them to always remain visible within the browser w ...

AngularJS: The best practices for passing $scope variables to functions

Exploring the TodoMVC application has been a great way for me to enhance my skills with AngularJS. While delving into the index.html file, I stumbled upon lines 14-16 which contain the following code: <form id="todo-form" ng-submit="addTodo()"> ...

Leverage a nearby module with a local dependency

My current challenge involves integrating a local library into my project. I have been following two tutorials: how to create a library and how to consume a local library. Despite having a well-structured sample library with package.json and index.ts, I am ...

What is the process to modify the font color on a webpage using a button?

I need some help figuring out how to change the font color on my website when someone clicks a button. I already have the background functionality working, but I can't seem to get the text color to change. This is the code I have so far: <div cl ...

I've encountered some issues with importing pagination from modules after installing SwiperJs

Having some issues with importing pagination from modules in SwiperJs for my nextjs project. The error message "Module not found: Package path ./modules is not exported from package" keeps popping up. I have tried updating the module to the latest version ...

Using javascript code to encode images to base64 and save the output to a text file

How can I modify the code below: <p id="demo"></p> <script> var openFile = function(event) { var input = event.target; var reader = new FileReader(); reader.onload = function(){ var dataURL = read ...

Using Javascript, access the 'second child' element by referencing the 'first child' element within a shared 'parent element'

// Retrieve the child_2 element using core javascript let parent = document.querySelector('.child_1').closest('.parent'); let child_2 = parent.querySelector('.child_2'); How can I achieve the same functionality as the jQuery ...

When downloading files that I uploaded to Google Drive using React Native, I noticed that the file size is not consistent with the original file

Greetings Everyone! I am aiming to transfer the database (RealmJS) that is currently stored on my device storage to Google Drive using Google Drive API V3. To accomplish this, I have already installed various node modules such as react-native-fs and @reac ...

Exploring Rxjs through fundamental queries

Currently, I am working on a small application using Angular 2 and have installed Rxjs 5. However, I have encountered various ways of importing the Rxjs library in tutorials. The code mentioned in the Angular 2 documentation is not functioning properly i ...

Assistance with designing in JavaScript and Python

Currently, I have a setup where my external website is extracting data from an iframe within our internal company intranet using Javascript. The extraction process is successful, but now I am faced with the challenge of accessing this harvested data in ord ...

Getting EdgesHelper to align properly with Mesh in Three.js

Within a dynamic scene, multiple mesh objects (specifically cubes) have been included. A unique EdgeHelper has been generated for each cube to track its movements and rotations. Whenever a particular cube mesh is selected, I am aiming to alter the color o ...