What is the best way to achieve smooth polygons in a Three.js environment?

Here is my Three.js model that I'm working on:

View the unsmoothed part of the model here

To export the model into a JSON file for use in my Three.js application, I used a plug-in from the Unity asset store. However, the plug-in did not export the smoothing groups, resulting in a lower quality appearance of the model.

Does anyone know of a way to smooth everything out within Three.js?

Answer №1

If you want to implement subdivision in your geometry using Three.js, you can make use of the THREE.SubdivisionModifier. Here's how you can do it:

var modifier = new THREE.SubdivisionModifier(divisions);

// Apply the modifier to your geometry (not mesh).
modifier.modify( geometry );

Please note that this functionality is not built into Three.js by default, so you will need to import it separately. You can download it from here.

UPDATE 1: When a JSON file is loaded, it becomes an Object3D, acting as a container with a specific structure:

  • Object3D
  • children (arrays containing meshes representing objects in the scene)
    • Mesh (contains information about the geometry that needs modification).

To modify the "geometry", you have to access it like this:

modifier.modify( mesh.children[0].children[0].geometry );

You'll need to apply the modifier to each model in your scene, for example:

modifier.modify( mesh.children[0].children[0].geometry );
modifier.modify( mesh.children[0].children[1].geometry );
modifier.modify( mesh.children[0].children[2].geometry );

This process involves opening containers within containers until you reach the geometry data. I hope this explanation clarifies the procedure for you :)

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

Extracting a compressed file in node.js to a specific web address location

I am currently developing an application using the express framework that allows users to upload a zip file and view its contents on the website. While I have successfully implemented uploading a single HTML file and displaying it, I am struggling with e ...

Struggling to effectively transfer a callback function within a series of functions

I am currently utilizing the codebird library to make requests to the Twitter API. The responses from these requests are functioning as expected, but I am looking to pass that response along to my route. Below is a segment of my route.js: router.get(&apos ...

Incorporating scripts into AngularJS interface

Here is the content of my view: <headers> <h1>My Page</h1> </headers> <link rel="stylesheet" href="css/some.css"/> <script ng-src="js/my-view-script.js"></script> After loading the view, I noticed that the ...

The function "initiateChat" is being called in the render method, but is not defined on the instance

Check Out This Error Screenshot:- https://i.sstatic.net/27o22.png This is ChatApp.vue Code Snippet:- <template> <div class="chat-app"> <Conversation :contact="selectedContact" :messages="messages"/> <ContactsList :contact ...

Is there a way to assign classes to elements within a sequence based on their index positions?

My goal is to create a list with alternating classes that have a start and end class for each set of items. For example, I currently have the following code: <div class="wrap"> <div class="item-a"></div> <div cl ...

Having trouble with my basic AJAX request; it's not functioning as expected

I am currently diving into the world of Ajax and I've hit a roadblock: 1. HTML : <body> <form> Username: <input type="text" id="username" name="username"/> <input type="submit" id="submit" /> </form> <scrip ...

Clicking on the current div will cause it to display using jQuery

Currently, I am working on an image gallery where I have successfully implemented the functionality to display the current image in the .gallery-container when clicked. However, I am facing an issue with displaying the caption of the current image. Despite ...

Transform an object into an array using JavaScript with the help of Lodash, Azure Functions, and Azure Logic Apps

To achieve the desired result of extracting JSON from a proprietary content management system, transforming it into a CSV, and depositing that CSV in an Office 365 shared drive, a combination of Azure Function and Azure Logic App is utilized. The Node/Java ...

Can you please highlight parts of the text and provide dialogue with additional information?

I am currently enhancing my blog and looking for a way to implement JavaScript functionality that will help highlight specific parts of my text and provide additional information, like: I am currently working on my laptop When the user clicks on "lapto ...

Tips for incorporating a download button into a video player using Plyr JS

I'm using Plyr JS and I am trying to add a download option for each video. Here is what I've done so far to make the download option work: Even though I have included: controlsList="nodownload" <video controls crossorigin playsinline contro ...

Ways to verify the contents of an NPM package

After successfully installing the npm package @mediapipe/camera_utils, I am now curious about how to explore the contents within it. Can someone guide me on how to achieve this? ...

Tips for concealing XHR Requests within a react-based single page application

Is there a way to hide the endpoint visible in Chrome's devtools under the network tab when data is fetched in React? Can server-side rendering solve this issue? ...

While testing my Bootstrap 3 website, I noticed that the hamburger menu was functioning correctly with the local file. However, once I hosted the site on GitHub Pages, the navbar stopped working

I recently created a test site using Bootstrap 3 (). Strangely, the hamburger menu doesn't seem to be working on this site. However, when I open the local file, the hamburger menu functions properly. Can anyone provide any insights or solutions regard ...

Creating a unique diagonal background in a React Native / Expo app

I'm creating a calendar feature for our application that displays availability. For days that have both check-ins and check-outs, happening at 12:00PM, I want to represent the day as half green and half pink, like this: https://i.sstatic.net/s97x7.pn ...

Tips for managing input for objects in Vue when the object hasn't been declared yet?

<input type="text" v-model="object[obj]"> Output: object:{'obj1':value} Desired outcome after input is added: object:{'obj1':{'prop1':value,'prop2':value}} <input type="text" ...

NextJS is throwing an error: The prop `href` in `<Link>` should be a `string` or `object`, but it received `undefined` instead

I've encountered an issue while trying to integrate a header section from a GatsbyJS project into my NextJS project. The error message I'm receiving is: "Error: Failed prop type: The prop href expects a string or object in <Link>, but ...

Retrieve a div element using Ajax from the result of an If statement

I need to extract a specific div from the data returned by an if statement that is formatted as HTML, and then display it within another div. I have been attempting to achieve this using the code below, but so far it has not been successful... Here is my ...

Nested variable declarations within block scoping can result in various types of errors

I'm currently exploring the concept of block scoping in ES6 and encountered an interesting issue that I need help understanding: In my initial test, I attempted the following code snippet and observed the error mentioned within the comments: { c ...

Unusual bounding box behavior observed in three.js

Having an issue with my three.js application. I created a cube and its bounding box, but when trying to access the computed bounding box (helper_bbox.geometry.boundingBox), I found it was returning a value of null, despite being correctly rendered on scr ...

Tips for deleting a preview image before uploading it in ASP.NET using C#

This script allows for image preview functionality, with the ability to remove a specific preview image while keeping the others intact before uploading. <script src="//code.jquery.com/jquery-1.11.2.min.js" type="text/javascript"></script> ...