Creating smooth surface from vertices and normals

Hello all,

New to the engine and this forum. I’m building a 3D file-type parser and I’ve found both the SDK and forum to be great resources, so thank you.

I’m stuck on trying to get the vertices’ normals to define the curvature of the mesh around the object. Currently when I define the vertices and indexes connecting them these are displayed as direct lines between the points. This is great for some files; however, when normals are defined I’d need the direction to head immediately perpendicular to the normal from the vertex, curving eventually to coincide with the connected vertex perpendicular to its normal.

This is perhaps best illustrated with this image: http://www.opengl-tutorial.org/wp-content/uploads/2011/05/goodsmooth.png

Currently I’m able to get the blue line; however, I’d like the red line.

Is any built in functionality that might be useful for this? I’d appreciate any suggestions.

Thanks and best,
Will

There is no red line. Smoothness is simulated by normals by interpolation when using the lighting material.

Your post indicates that you already have normals… so why not just use them? Something about your question or your approach or your end result is unclear.

If you want to display smooth models, the vertexes and normals are enough.

Thank you for your response pspeed.

I am trying to use the normals; please see the code below:

[java] Vector3f [] newVertices = new Vector3f[mIndices.size()];
Vector3f[] newNormals = new Vector3f[mIndices.size()];

	ArrayList<Integer> indices = new ArrayList<Integer>();

	setFinalVertices(mIndices, indices, vertices, newVertices, normals, newNormals);

	int[] indexes = new int[indices.size()];
            
	for(int i=0; i<indices.size();i++){
		indexes[i] = indices.get(i);
	}
           
	mesh.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(newVertices));
	//mesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
	mesh.setBuffer(VertexBuffer.Type.Index, 3, BufferUtils.createIntBuffer(indexes));
            mesh.setBuffer(VertexBuffer.Type.Normal, 3, BufferUtils.createFloatBuffer(newNormals));

	mesh.updateBound();

	Geometry geo = new Geometry("OurMesh", mesh); // using our custom mesh object
	mat = new Material(assetManager, //"Common/MatDefs/Misc/ShowNormals.j3md");
			//"Common/MatDefs/Misc/Unshaded.j3md");
                    "Common/MatDefs/Light/Lighting.j3md");
            
            //
            
            mat.setBoolean("UseMaterialColors", true);
            mat.setColor("Diffuse", ColorRGBA.Blue);
            mat.setColor("Ambient", ColorRGBA.Red); //Using white here, but shouldn’t matter that much
            mat.setColor("Diffuse", ColorRGBA.White);
            mat.setColor("Specular", ColorRGBA.Yellow); //Using yellow for example
            mat.setBoolean("VertexLighting", true);
            
            DirectionalLight light=new DirectionalLight();
            light.setDirection(new Vector3f(-1, 0, -1).normalizeLocal());
            light.setColor(ColorRGBA.White);
            getRootNode().addLight(light);
            
            DirectionalLight light2=new DirectionalLight();
            light.setDirection(new Vector3f(1, 0, 1).normalizeLocal());
            light.setColor(ColorRGBA.White);
            getRootNode().addLight(light);

            AmbientLight ambient = new AmbientLight();
            ambient.setColor(ColorRGBA.White/*.mult(0.5f)*/);
            getRootNode().addLight(ambient);[/java] 

However, at present this is rendering as this

image

The lighting looks good which makes me think the normals are alright; however, the edges are still sharp instead of smooth. Is there any way to change this?

Thanks,
Will

The only way to fix that is to add a lot more triangles.

What is it that you actually want to do? Are you trying to make a sphere?

Yes, ideally that shape should be a sphere - I know I could get it to look better adding more vertices, but I was hoping there was some function to accomplish this with just a sparse field of vertices and normals. Maybe this is impossible.