What is preventing me from creating a perfect circle using the arc() method in Three.js?

While attempting to create a complex shape in Three.js using extruded arcs, I encountered some unexpected behavior. I am unsure if my understanding of the API is lacking, but wasn't this code supposed to generate a full extruded circle with a radius of 100 centered at the origin?

var path = new THREE.Path();

path.moveTo(0, 0);
path.arc(0, 0, 100, 0, Math.PI * 2, false);

var shape = path.toShapes(false, false);

var extrudeSettings = {
    amount : 20,
    steps : 1
};

var geometry = new THREE.ExtrudeGeometry(shape, extrudeSettings);

var mesh = new THREE.Mesh(geometry, material);

Instead of a complete circle, it produces a Pacman-like shape:

For reference, here's the link to the JSFiddle:

http://jsfiddle.net/c8shqzpn/

Answer №1

If you're looking to create a circle shape for extrusion, there are a few important steps to keep in mind.

When drawing an arc, it's crucial to connect the start of the arc to the current point. In order to achieve this in your specific case, you will need to utilize the moveTo() command to establish the starting point on the edge of the circle.

var myCircle = new THREE.Shape();

myCircle.moveTo( circleRadius, 0 );
myCircle.absarc( 0, 0, circleRadius, 0, 2 * Math.PI, false );

This code snippet is compatible with three.js version r.70.

Answer №2

Encountering a similar issue with drawing and extruding 3/4 of a circle, I noticed that a segment was missing when the result (a THREE.Mesh) was added to the screen. By including the line moveTo( x, y ) where x and y represent the starting coordinates of the arc, I was able to resolve the problem. Below is the code snippet I utilized:

var extrudeSettings = {
    bevelEnabled: false,
    steps: 1,
    amount: 2
};

var shape = new THREE.Shape();
var circleRadius = 4;

// THIS LINE SOLVES THE ISSUE 
shape.moveTo( 0, -circleRadius );

shape.absarc( 0, 0, circleRadius, 0, 1.5 * Math.PI, false );
shape.lineTo( 0, 0 );
shape.closePath();

var geometry = shape.extrude( extrudeSettings );

scene.add( new THREE.Mesh( geometry, new THREE.MeshNormalMaterial() ) );

Initially, my mesh appeared as shown here:

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

After implementing

shape.moveTo( 0, -circleRadius );
, the mesh transformed into this:

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

Answer №3

Is it possible to find the solution by multiplying 2.1 with Math.PI instead of 2?

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 it possible to send an array using fetch in JavaScript?

I am attempting to use the fetch function to send an array that has the following structure: {"cards":[[189,2],[211,2],[238,2],[778,2],[985,2],[1008,2],[1073,2],[1171,2],[48886,2],[49161,2],[49164,2],[49184,1],[49356,2],[50372,2],[51722,1],[52422,2]],"her ...

Experiencing difficulties with a callback function while making a jQuery getJSON request via AJAX

Within my utility .js file, there is a method that fetches data using Ajax. The challenge I am facing is that this method does not have prior knowledge of the caller. After the Ajax call completes asynchronously, it needs to send an object back to the cal ...

Unable to launch React Native project on emulator now

Something seems off with my App as it won't start up on my AS Emulator. Everything was running smoothly yesterday, but today it's not working - possibly due to me moving the npm and npm-cache folders, although they are configured correctly with n ...

Margins are added to cards on the right side

Looking for some help to improve the display of three cards in a grid. The card media has a max-width of 345px, but this is causing excessive margin-right space and making the styling look poorly. Any suggestions on how to eliminate this extra margin? If ...

Storing the ID passed from Next.js/Link into Next.js

I'm encountering some issues with the current flow setup. I have a component ArticleList that listens to articles, and upon clicking on it, redirects you to the individual article page. The redirection is done using next/Link, where the id is passed a ...

Which file should I include: npm-shrinkwrap.json, package-lock.json, or yarn.lock?

When shipping a package that is compiled only using tsc (the typescript compiler), I anticipate that consumers will install the necessary dependencies when they use npm or yarn to install my package. I aim to offer flexibility by not enforcing the use of ...

Troubleshooting problem with jwPlayer resizing in Firefox and Opera browsers

<script type="text/javascript" src="js/jwplayer/jwplayer.js"></script> <div id="myElement"">Loading the player...</div> <script type="text/javascript"> jwplayer("myElement").setup({ file: "video/mosk.mp4", ...

Interactive feature on Google Maps information window allowing navigation to page's functions

Working on an Angular2 / Ionic 2 mobile App, I am utilizing the google maps JS API to display markers on a map. Upon clicking a marker, an information window pops up containing text and a button that triggers a function when clicked. If this function simpl ...

Discovering the process of extracting a date from the Date Picker component and displaying it in a table using Material-UI in ReactJS

I am using the Date Picker component from Material-UI for React JS to display selected dates in a table. However, I am encountering an error when trying to show the date object in a table row. Can anyone provide guidance on how to achieve this? import ...

Three.js experiencing issues with FBX animations running erratically

Having trouble with animations on some fbx models. When an animation lasts 20 seconds, the model remains stationary for 19 seconds and then suddenly moves within the last second or so. However, other fbx models animate correctly. The code used to run the a ...

Error alert is triggered when AJAX launch fails, but a successful response is received in the form of an array converted to a

When transferring text data and files from JavaScript to PHP using AJAX with FormData, I also transfer an array as a response from PHP to JavaScript using json_encode() in PHP and JSON.parse() in JavaScript. Although the code appears to be working, the AJA ...

Difficulty in using window.scrollTo within useEffect in reactJS

I'm facing an issue where I am trying to use window.scrollTo on the initial render using the useEffect function. I have stored the vertical offset as an integer in localStorage, but the scrolling is not working and remains at position 0. Problem with ...

The alert function in the Ajax web method is malfunctioning

Every time I try to call the Ajax web method, I keep receiving a 'save error' message. However, the data is successfully saved to the database without any issues. I have checked for errors but couldn't find any. How can I display an alert sa ...

Disable the border and background colors in CloudFlare Turnstile

I have implemented the CloudFlare reCaptcha Turnstile and I am looking to modify the widget by removing the border and background color. I believe this customization can be achieved using CSS or Javascript. Thank you for any assistance! ...

Using Observables to assign values received from API calls to each element during loop iterations

As I loop through using a foreach loop, I need to call functions that will make async API calls and return values to be rendered in the HTML. The first function getCurrentValue() will return the currentTemperatureRef which should then be assigned to recei ...

Validating Two DateTime Pickers as a Group with Javascript in asp.net

How to Ensure Group Validation of Two DateTime Pickers Using JavaScript in ASP.NET ...

Can users' data be securely stored in the session/history using ReactJS?

I recently inherited a React application from a previous developer, and while I'm still getting the hang of how React works, I am surprised to see that user data is being stored in the session history. This raises some concerns for me: const { ...

Mongo: executing queries with both .find() and .update() methods sequentially

I am looking to: Retrieve specific items from collection X; Retrieve other items from X; Make the items from step #1 have the same value as the items from step #2 Make the items from step #2 have the same value as the items from step #1 Essentially, ...

What methods can I use to accomplish the transformation of superimposed images?

Struggling with transforming a content box on my webpage. I have a div containing three overlapping images positioned using Grid, and I want to scale one of them to fill the entire div when scrolled over. While I managed to achieve this effect, I'm un ...

Avoid navigating to the subscribe block when the server sends a response in Angular

When trying to send a request to the server and check the response, I am not seeing any results. The code for sending the request is below: SendVerificationInfo(item: SendVerificationModel): Observable < any > { return this.httpClient.post < any ...