• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
carkey

Trying to write a smoothing algorithm for meshes

10 posts in this topic

Hi all,

 

I'm working on a small project and I've got to a point where I want to be able to smooth the meshes I've got.

 

I've had a quick google around and found something called Laplacian Smoothing http://en.wikipedia.org/wiki/Laplacian_smoothing but I'm not really sure how it works.

 

Does anyone have any good resources of what smoothing algorithms are out there, their pros/cons etc?

 

Thanks for your time.

0

Share this post


Link to post
Share on other sites

I've never tried to do mesh smoothing so I'll just try to explain how to implement Laplacian smoothing based on your link:

 

Basically you have to calculate the average position of each vertex and its neighbors, adding them all and dividing by the number of adjacent vertices + 1 (the original vertex itself) . You can use the index buffer to find the neighbors.

 

(I'm assuming you want to apply the algorithm to a triangle list mesh with index buffer)

for(uint i = 0; i < vertices.size(); i++)
{
    uint x = 1;
    std::vector used;
 
    smoothedVertices[i] += vertices[i];
 
    used.push_back(vertices[i]);
 
    for(uint j = 0; j < indices.size(); j++)
    {
        if(indices[j] != i)
            continue;
 
        //add new vertices from this triangle
        uint startTriangleIndex = j - j%3;
 
        for(uint k = 0; k < 3; k++)
        {
            if(!used.contains(vertices[startTriangleIndex+k])) //Dont add the same vertex more than once
            {
                smoothedVertices[i] += vertices[startTriangleIndex+k];
                used.push_back(vertices[startTriangleIndex+k]);
                x++;
            }
      }
 
      smoothedVertices[i] /= x;
}

The code above should work, unless you have duplicate vertices...

Edited by TiagoCosta
1

Share this post


Link to post
Share on other sites

Consider the requirements of your smoothing:

  • What do you consider smooth or not smooth enough?
  • Do you have sharp edges that should be preserved?
  • Do you need to compute sensible texture coordinates to keep the old textures without distortion? This usually means preserving angles (a conformal mapping).
  • Do you care about preserving the volume, area or length of parts of your geometry? For example, lengths determines whether an object can pass through a hole, areas determine the size of shadow and occlusion cones, and volume determines mass and buoyancy in physical simulations.
  • Would you like to preserve mesh structure exactly because it's important and/or to allow the use of simpler algorithms?
  • If not, do you need to collapse redundant or noisy geometry, add vertices to get more rounded shapes and a more regular subdivision, or both?
  • Do you want to limit the distance between the original and smoothed surfaces, or other error measures?
1

Share this post


Link to post
Share on other sites

@TiagoCosta - Thanks for the explanation, that makes sense to me now, I'll have a go at implementing it soon!

 

@LorenzoGatti - It is a very basic project I am working on and so the answer is no to most of those questions:

 

1) I basically want to experiment with different 'amounts' of smoothing, so going as far as smoothing a Cube into a near-sphere to smoothing it only slightly.

2) Not really, as I say in (1) I just want to experiment

3) No, I do not use textures.

4) No

5) No, this is to save the mesh to file so I don't need to preserve the original mesh.

6) I assume I do if I am smoothing it? There is possibly some noisy geom. so it would be nice to be able to smooth this.

7) No.

 

Thanks for your help so far, hopefully those answers will give you more of an idea of what I want to do :)

 

Thanks.

0

Share this post


Link to post
Share on other sites


You can use the index buffer to find the neighbors.

 

Hi TiagoCosta,

 

I was just implementing this and I was wondering about the above assertion. Is this the case? Isn't it possible for vertices I to be surrounded by j, k and l but their indicies are 10, 15, 44, 67? Depending on how the mesh has been created?

 

Everything else makes sense to me, just not this bit about using the indicies to know the neighbors.

 

Thanks for your time.

0

Share this post


Link to post
Share on other sites

Maybe neighbors is the wrong word for it... By neighbors I meant adjacent vertices (if vertex V1 belongs to triangle A and vertices V2/V3 also belong to triangle A, V2/V3 are adjacent to V1). Since triangle lists are organized like this:

 
Indices -    0 1 2 3 4 5 6 7 8
Triangles - |--A--|--B--|--C--|
 
Edited by TiagoCosta
0

Share this post


Link to post
Share on other sites

Ah okay, I see what you mean.

 

So if I had a 2 quad (4 triangle) grid like this:

a - b - c
|\  |\  |
| \ | \ |
|  \|  \|
d - e - f

?

?

?

?

In a triangle list the vertex list would be: {a, b, c, d, e, f}

And the indices list would be: {(0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11)}

 

Even though indices 1 and 5 (if they are both talking about vertex 'e') are exactly the same?

 

I think my mesh is constructed differently so that there would be no redundant indices and instead of {(0, 1, 2), (3, 4, 5), ... } it is {(0, 1, 2), (0, 3, 1), ...}

 

Does that make sense? Because triangles 1 and 2 share the vertices 'a' and 'e', they both use the same index? Or am I thinking about this all wrong? (Is that what you call a 'triangle strip'?)

 

If I do currently have my mesh setup the wrong way, is there a way to do the algorithm on this sort of mesh or should I think about converting it into a triangle list?

 

Thanks again for all the help so far smile.png

Edited by carkey
0

Share this post


Link to post
Share on other sites

So if I had a 2 quad (4 triangle) grid like this:

a - b - c
|\  |\  |
| \ | \ |
|  \|  \|
d - e - f

?

In a triangle list the vertex list would be: {a, b, c, d, e, f}

And the indices list would be: {(0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11)}

 

(0,1,2) isn't a triangle. 

 

The indices list would be {(0,1,4), (0,4,3), (1,2,5), (1,5,4)}

 

Ex: Since vertex b belongs to 3 triangles some of vertices on those triangles are the same.

Triangles that vertex b is part of:

a-b-e

b-c-f

b-f-e

 

As you can see vertices f and e appear twice so you have to keep a list of vertices already used to prevent using a vertex twice.

 

The example above demonstrates the case where there are duplicate vertex indices in the indices list but no duplicate vertices in the vertex list.

0

Share this post


Link to post
Share on other sites

Ah okay, I see what you mean now.

 

The only thing I'm not quite understanding now is that the k for-loop uses the condition k < 2, should this be k < 3? Because say for vertex 0, j = 0, startTriangleIndex = 0, and then the loop only runs k = 0 and k = 1. k = 0 will not be used because that is our current vertex and it's already been added to the used vector and so then we'll only be averaging with k = 1 (vertices[0 + 1]), but what about vertices[2]?

 

Thanks for all the help so far, and hopefully I'll have some results soon to show :)

0

Share this post


Link to post
Share on other sites

The only thing I'm not quite understanding now is that the k for-loop uses the condition k < 2, should this be k < 3?

 

Yes it should. I fixed my first reply.

0

Share this post


Link to post
Share on other sites

 

The only thing I'm not quite understanding now is that the k for-loop uses the condition k < 2, should this be k < 3?

 

Yes it should. I fixed my first reply.

 

 

Ah okay cool thanks, I'll give this another go because this makes sense to me now :)

 

Thanks for all the help and really quick responses!

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0