Smooth Laplacian causing faces to disconnect

I've been working on implementing Laplacian smoothing using JavaScript and Three.js, but I'm encountering some unexpected issues. When I hover and smooth over the meshes, instead of achieving a smooth effect, the faces are becoming disconnected and shrinking in size. What could be causing this issue with my code?

Check out this image showing the output of the mesh after smoothing. The white circle represents the brush, and the 'indices' array contains all the indices under the brush.

indices.forEach( index => {

    if (params.brush === 'smooth') {

      for (let i = 0; i < 3; i++) {

        const currentVector = new THREE.Vector3().fromBufferAttribute(posAttr, index);
        const nbI = neighborMap.get(index); // Retrieve neighbors of the current vertex
        if (!nbI || nbI.size === 0) return; // Skip if there are no neighbors

        const nbIAr = Array.from(nbI); // Convert neighbor Set to array

        // Initialize average position to zero
        const avgPos = new THREE.Vector3();
        const neighborCount = nbIAr.length;

        // Calculate the average position of the neighboring vertices
        nbIAr.forEach(neighborIndex => {
          const neighborPos = new THREE.Vector3().fromBufferAttribute(posAttr, neighborIndex);
          avgPos.add(neighborPos); // Accumulate neighbor positions
        });

        avgPos.divideScalar(neighborCount); // Compute the average


        // Compute the Laplacian (difference between average and current position)
        const laplacian = new THREE.Vector3().subVectors(avgPos, currentVector);



        // Update the vertex position by moving it toward the average
        const lamdaValue = 0.005
        currentVector.addScaledVector(laplacian, lamdaValue); // λ

        tempVec.copy(currentVector);

      }
    }

    posAttr.setXYZ(index, tempVec.x, tempVec.y, tempVec.z);
    normalAttr.setXYZ(index, 0, 0, 0);

  });

I tried increasing the value of lambda, but it ended up moving the vertex too far away,

Answer №1

My recent challenge involved encountering problems with faces disconnecting and shrinking while performing smoothing operations. This issue stemmed from my utilization of

BufferGeometryUtils.mergeVertices
in the context of Three.js when I was loading an STL file. Given that STL files lack index data, this function endeavors to create indices. Regrettably, the resultant index data does not align well with the Laplacian smoothing procedure, leading to distortions in the mesh.

The realization dawned on me when I opted to load a PLY file instead, which inherently includes index information. Upon working with the PLY file, the Laplacian smoothing operated precisely as intended.

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

The error message "TypeError: undefined is not a function when trying to access a resource

I searched online before asking here, but couldn't find a solution. I'm attempting to call a REST service using ngResource, but my app UI isn't launching due to an error: 05-13 02:16:08.011 2402-2402/com.app.mvalt I/chromium: [INFO:CONSOLE ...

A guide on displaying a JSON object using the ng-repeat directive

Looking to create a dynamic treeview menu with angularJS? Wondering how to achieve the desired results using a controller ($scope.results) and JSON data? Check out the code snippet below for an example of how to structure your treeview: <ul> < ...

Angular and JavaScript Performing Slide-Up Animation

Currently, I am working on creating a menu using Angular and JavaScript. My goal is to have this menu toggle between showing and hiding when a button is clicked. If you would like to view the code that I have written so far, you can check out the demo her ...

How to delete vertices and their properties from a BufferGeometry using Three.js

In my Three.js project, I have a large collection of point cloud forms grouped together in a single Points object for efficient rendering using BufferGeometry in WebGLRenderer. The program allows users to interactively select a form from the point cloud, w ...

Exploring and deciphering the intricacies of the underlying technology

Apologies if this question seems misplaced, but as a complete beginner, I'm a bit lost. Let's consider this website as an example: I'm trying to uncover the libraries and technologies employed in the background to learn more and replicate ...

Oops! The specified vue-router route name cannot be found

My issue involves a vue component with a method that includes a router push attempting to navigate to another vue component: GetAnimal.vue: ... this.$router.push({ name: "/viewanimal", }); ... The routing mapping is set up like this: router.js: { ...

To successfully handle this file type in Next.js, make sure you have the necessary loader configured as no loaders are currently set up to process this specific file

I encountered an issue when trying to load an image from a local directory in my Next.js application Failed to compile ./pages/components/image.png 1:0 Module parse failed: Unexpected character '' (1:0) You may need an appropriate loader to hand ...

"Creating a Hyperlink that Navigates to Specific Content Within a

I have a situation where I am trying to link to sections on the page contained within collapsed fieldsets. My goal is that when a user clicks on this link, the page should scroll down and automatically expand the fieldset to display the content inside. E ...

Ensure that each Javascript function call in MVC 4 waits for the previous one to complete before executing

I am trying to run two JavaScript functions, but the second function needs to wait for the first function to finish. View: <button id="DefinirEstab" class="btn btn-success btn-lg" data-toggle="modal" data-target="#myModal" onclick="saveContrato(); Cou ...

Is there a specific side effect that warrants creating a new Subscription?

Recently, I had a discussion on Stack Overflow regarding RxJS and the best approach for handling subscriptions in a reactive application. The debate was whether it's better to create a subscription for each specific side effect or minimize subscriptio ...

Import JSON Data into Angular-nvD3 Chart (AngularJS)

I am seeking help to load encoded JSON Data retrieved from a database via queries into an Angular-nvD3 graph. I am unsure about the best approach to achieve this task. The encoded JSON data is fetched using API queries from a database table called PRODUCT ...

Are the properties Object3D.matrixWorldAutoUpdate present in three.js?

Upon reviewing the APIs of three js, I came across the Object3D.matrixWorldAutoUpdate property in the documentation here. It states: .matrixWorldAutoUpdate : Boolean By default, it is set to true. If enabled, the renderer will check each frame if the objec ...

Assign a unique HTML attribute to a child element within a Material-UI component

Currently, I am trying to include the custom HTML5 attribute "data-metrics" in the span element within the ListItemText Material UI component. However, I am facing some difficulty achieving this as per the specifications outlined in the Component API Docum ...

What is the relationship between $.when, apply(), and $.done() within the scope of this function?

I recently received this function from a helpful SO user that allows for returning a variable number of jQuery $.get() requests. The initial part seems pretty straightforward, but I am struggling to understand how $.when(), apply(), and $.done() are inte ...

Validation is not being enforced for the input field labeled as 'name' in the form

Can anyone assist me with a form validation issue I'm encountering while working on my project? The validation is functioning correctly for email and institution fields, but it seems to be ignoring the name field. Any suggestions or help would be grea ...

I am encountering a problem with my Vuex getter where it is sending an Array with a length of 0, but when expanded in the console,

Currently, I'm utilizing Vuex to interact with a Django API in order to fetch count data. state: { DailyCycleDate: [] }, getters: { DailyCycleDate : state => { console.log('Getter') console.log('Length of Array: &apo ...

Configuring Multer destination dynamically using FormData values in Node.js

I have a scenario where I need to send a file along with some data values using an XMLHttpRequest (xhr) to a Node.js server running Express. To handle multipart data, I am utilizing Multer as bodyParser does not work in this case. router.post("/submit", f ...

Tips for utilizing useQuery when props change using Apollo:

I am currently facing a challenge with my BooksList component where I need to pass props down to the BooksDetails component only when a title is clicked. I am trying to figure out how to utilize an Apollo hook to query only on prop changes. I have been ex ...

Creating a dynamic multidimensional array or object in AngularJS: tips and tricks

Below is the code snippet where I am attempting to dynamically construct an associative array in angularJs: $scope.details = {"profilesFound": [ "https: //twitter.com/alexandreagular", "https: //twitter.com/?profile_id=46130006", "https: //f ...

Tips for updating parameters that are defined in a controller within a promise

Currently, I am developing a single page application using Angular and TypeScript. I am facing an issue with updating the parameter value (_isShowFirst) of the controller inside a promise function. It seems like nothing is recognized within the promise blo ...