# Can anyone explain the instructions, in an order, to have a smooth mesh?

What if we have an ArrayList of vertices, colors and indices (everything to have a mesh) and we want to have the mesh smoothened? What instructions do we need to follow?
Obviously we will need normals of the faces. How do we find them? Where do we attach them to? How to implement them and what comes after?

If there would be examples, such as the example of ‘TestCustomMesh.java’, or instructions (like a pseudo code or articles to follow to understand the essence of getting a smoothened mesh from a mesh), it would be significantly beneficial for me and the members of this valuable forum.

Regards

There is no “one way”. It all depends on which way the normals point. Generally, for a smooth mesh, all of the triangle vertexes that share the same location will also share the same normal. Depending on where the mesh comes from, you may already have this information. If not then you can calculate it as an average of the shared triangles’ normals.

Calculating a triangle’s normal is pretty easy. Google will probably give you a million hits, I guess.

After calculating normals or getting them calculated?

@Sarpp-Daltabann said: After calculating normals or getting them calculated?

I don’t understand the question.

If we calculated the normals, what is the next step?

Apply them to the mesh.

I read the webpage may be 100 times and there is nothing to do about smoothening on this webpage. Setting the buffers with normals does not make any change. May be I should use a shaded asset???

@sgold said: Apply them to the mesh.

Well how?

[java]mesh.setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normalsArray));[/java]

does not make any change. May be the reason is:

Whether if really it is or not, there is not any tutorial on this pretty forum about how to smoothen a mesh object.
I have calculated the normals correct but the next step is unknown???

Then I need to write something else instead of “Common/MatDefs/Misc/Unshaded.j3md” inside the line:

Is not it? What should I write there? Just deleting the “Un” of word “Unshaded”? Then, will the mesh look like it is smooth with its buffered normal vectors?

TestCustomMesh uses unshaded implementation. I could not find any shaded and smooth tutorial-like mesh generation code. If I could find, I would not make any of you tired of reading my problemsss… I will design and upload a smoothening tutorial if you help me on steps of making a mesh object smoothened.

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_material

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_material

Why can anyone not understand what I ask? Is it not clear? I want advices, or instructions to follow to smoothen a mesh object. I do not need any source of light.

I CREATED A MESH OBJECT AND FILLED IT WITH VERTICES AND INDICES BY HELP OF A “for loop”. NOW, WHAT I NEED IS WRITING A METHOD SUCH AS: [java]smoothen(Mesh mesh)[/java] WHICH RETURNS A VIEWABLE SMOOTHENED Mesh OBJ. THEN I CAN SHOW IT ON JME3.

IF YOU DO NOT HAVE ANY USEFUL IDEA EXCEPT WEBPAGES THAT CONTAINS NOTHING TO SMOOTHEN A MESH OBJECT, DO NOT REFER IT.

I am at the end of the stage of constructing normals of the faces of the mesh obj.
Namely, I have set the vertice buffer, indice buffer and the normal buffer of the mesh. Even I can move the meshed 2D surfaces with help of [java]Timer[/java]. But as expected, it is not smooth. Any methodologies or advices rather than reading unrelated pages?

Here is a method to create shaded material that’s all one color:
[java]
/**
* Create a shiny lit material with a specified uniform color.
*
* @param assetManager (not null)
* @param color (not null)
* @return new instance
*/
public static Material createShinyMaterial(AssetManager assetManager,
ColorRGBA color) {
Validate.nonNull(assetManager, “asset manager”);
Validate.nonNull(color, “color”);

``````    Material material = new Material(assetManager, shadedMaterialAssetPath);
material.setBoolean("UseMaterialColors", true);
material.setColor("Ambient", color);
material.setColor("Diffuse", color);
material.setColor("Specular", ColorRGBA.White);
material.setFloat("Shininess", 1f);

return material;
}
``````

[/java]

To apply the normals to an existing mesh you do indeed need to do something like
[java]
mesh.setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normalsArray));
[/java]

Keep in mind that the normalsArray should be indexed by vertex id.

1 Like
@Sarpp-Daltabann said: Why can anyone not understand what I ask? Is it not clear? I want advices, or instructions to follow to smoothen a mesh object. I do not need any source of light.

Because the question as written makes no sense. What does “smooth mesh” mean without a source of light?

Maybe you need to explain what you mean by “smooth mesh” because apparently it is different than the standard definition.

@pspeed said: Because the question as written makes no sense. What does "smooth mesh" mean without a source of light?

Maybe you need to explain what you mean by “smooth mesh” because apparently it is different than the standard definition.

So what you say is smooth mesh cannot be done without a source of light, is not it? Well that is a start.
What I have is a spherical mesh with corners(vertices and indices implemented). I also calculated the normals. Then what do I need to do to smoothen this sample mesh? After adding a source of light?

@Sarpp-Daltabann said: So what you say is smooth mesh cannot be done without a source of light, is not it? Well that is a start. The screen shot below is what I have with samples of vertices and indices set. I also calculated the normals. Then what do I need to do to smoothen this sample mesh? After adding a source of light?

None of us can see the picture because it’s on your desktop. You need to upload it somewhere like imgur for us to be able to see it.

1 Like

The screenshots above are without a light source but adding a light source of white does the same work. I just want to smoothen the corners of the mesh above…with normals, light source and anything else required…

I just added the vertices below and the 3D world is created by loops to set the indice and color buffers. If you have sample vertices as the way I have below, I can create your 3D world too…