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.

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_meshes

@kwando said: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_meshes

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:

[java]myMaterial = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);[/java]

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???

Smooth shading implies shading. Unshaded implies no shading.

@pspeed said: Smooth shading implies shading. Unshaded implies no shading.

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

[java]myMaterial = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);[/java]

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.

Please re-read the hello world tutorials, especially this one:

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

@wezrule said: Please re-read the hello world tutorials, especially this one:

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?

To create a shaded material, start with the “Common/MatDefs/Light/Lighting.j3md” material definitions.

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…

[java]verticeList.add(new Vector3f(0,0,0));
verticeList.add(new Vector3f(1,0,0));
verticeList.add(new Vector3f(2,0,0));
verticeList.add(new Vector3f(0,1,0));
verticeList.add(new Vector3f(1,1,0));
verticeList.add(new Vector3f(2,1,0));
verticeList.add(new Vector3f(0,2,0));
verticeList.add(new Vector3f(1,2,0));
verticeList.add(new Vector3f(2,2,0));
verticeList.add(new Vector3f(3,0,1));
verticeList.add(new Vector3f(3,1,1));
verticeList.add(new Vector3f(3,2,1));
verticeList.add(new Vector3f(4,2,2));
verticeList.add(new Vector3f(4,1,2));
verticeList.add(new Vector3f(4,0,2));
verticeList.add(new Vector3f(4,2,3));
verticeList.add(new Vector3f(4,1,3));
verticeList.add(new Vector3f(4,0,3));
verticeList.add(new Vector3f(4,2,4));
verticeList.add(new Vector3f(4,1,4));
verticeList.add(new Vector3f(4,0,4));
verticeList.add(new Vector3f(3,0,5));
verticeList.add(new Vector3f(3,1,5));
verticeList.add(new Vector3f(3,2,5));
verticeList.add(new Vector3f(2,0,6));
verticeList.add(new Vector3f(2,1,6));
verticeList.add(new Vector3f(2,2,6));
verticeList.add(new Vector3f(1,0,6));
verticeList.add(new Vector3f(1,1,6));
verticeList.add(new Vector3f(1,2,6));
verticeList.add(new Vector3f(0,0,6));
verticeList.add(new Vector3f(0,1,6));
verticeList.add(new Vector3f(0,2,6));
verticeList.add(new Vector3f(-1,0,5));
verticeList.add(new Vector3f(-1,1,5));
verticeList.add(new Vector3f(-1,2,5));
verticeList.add(new Vector3f(-2,0,4));
verticeList.add(new Vector3f(-2,1,4));
verticeList.add(new Vector3f(-2,2,4));
verticeList.add(new Vector3f(-2,0,3));
verticeList.add(new Vector3f(-2,1,3));
verticeList.add(new Vector3f(-2,2,3));
verticeList.add(new Vector3f(-2,2,2));
verticeList.add(new Vector3f(-2,1,2));
verticeList.add(new Vector3f(-2,0,2));
verticeList.add(new Vector3f(-1,2,1));
verticeList.add(new Vector3f(-1,1,1));
verticeList.add(new Vector3f(-1,0,1));
verticeList.add(new Vector3f(0,3,1));
verticeList.add(new Vector3f(1,3,1));
verticeList.add(new Vector3f(2,3,1));
verticeList.add(new Vector3f(0,4,2));
verticeList.add(new Vector3f(1,4,2));
verticeList.add(new Vector3f(2,4,2));
verticeList.add(new Vector3f(0,4,3));
verticeList.add(new Vector3f(1,4,3));
verticeList.add(new Vector3f(2,4,3));
verticeList.add(new Vector3f(0,4,4));
verticeList.add(new Vector3f(1,4,4));
verticeList.add(new Vector3f(2,4,4));
verticeList.add(new Vector3f(0,3,5));
verticeList.add(new Vector3f(1,3,5));
verticeList.add(new Vector3f(2,3,5));
verticeList.add(new Vector3f(0,2,6));
verticeList.add(new Vector3f(1,2,6));
verticeList.add(new Vector3f(2,2,6));
verticeList.add(new Vector3f(-1,3,2));
verticeList.add(new Vector3f(-1,3,3));
verticeList.add(new Vector3f(-1,3,4));
verticeList.add(new Vector3f(3,3,2));
verticeList.add(new Vector3f(3,3,3));
verticeList.add(new Vector3f(3,3,4));
verticeList.add(new Vector3f(-1,5,2));
verticeList.add(new Vector3f(-1,5,3));
verticeList.add(new Vector3f(-1,5,4));
verticeList.add(new Vector3f(3,5,2));
verticeList.add(new Vector3f(3,5,3));
verticeList.add(new Vector3f(3,5,4));
verticeList.add(new Vector3f(0,5,5));
verticeList.add(new Vector3f(1,5,5));
verticeList.add(new Vector3f(2,5,5));
verticeList.add(new Vector3f(0,5,1));
verticeList.add(new Vector3f(1,5,1));
verticeList.add(new Vector3f(2,5,1));
verticeList.add(new Vector3f(0,-2,2));
verticeList.add(new Vector3f(1,-2,2));
verticeList.add(new Vector3f(2,-2,2));
verticeList.add(new Vector3f(0,-2,3));
verticeList.add(new Vector3f(1,-2,3));
verticeList.add(new Vector3f(2,-2,3));
verticeList.add(new Vector3f(0,-2,4));
verticeList.add(new Vector3f(1,-2,4));
verticeList.add(new Vector3f(2,-2,4));
verticeList.add(new Vector3f(3,5,1));
verticeList.add(new Vector3f(3,5,5));
verticeList.add(new Vector3f(-1,5,1));
verticeList.add(new Vector3f(-1,5,5)); [/java]