# Adding granularity to a mesh

Hi there!

I just started with JME and wondered if someone could help me out with a problem I ran into.

I am trying to create a board consisting of corridors/rooms/etc. First I defined a polygon to represent the outer bounds. Then I defined an array of polyongs represting obstacles within the bounds. I sliced up the 2D representation of the polygons by using the Triangulator. Then I added walls to around the outer bounds and obstacles and finally calculated their correct normals for their meshes.

As I am fairly new to programming in 3D, I experimented with the lights and made a strange observation: pointlights illuminate far walls more than walls next to the lightsource. I figured that it must be due to the angles between the normals and the light source. Thus, the normals of a far wall facing the light will almost  be orthongonal to the “rays of light” while the normals of a close wall will not. Likewise the illumination of the floor looks quite odd (see screenshots).

In order to resolve this issue I thought that I need to make the floor and the walls more granular, thus allowing more normals to be affected. Currently a wall (no matter how long) consist of four vertices (and therefore of only four normals). Likewise, the floor’s normals depend on the (arbitrary) triangulation.

So finally here is my question: Is there a (hopefully easy) way to add granularity to a mesh or its triangles? I browsed through the API but couldnt find anything that could be used to slice up triangles or decompose a triangle in smaller (hopefully regular shaped) ones. Due to the fact that my board is generated automatically which should allow arbitrary angles between walls, I cannot simply generate regular tiles.

Slicing up the walls into segments is simple but the problem I have is with the floor.

The only idea I came up with, is to manually slice the triangles of the floor with a regular grid which seems a bit messy to me. Does anyone have an idea how to solve this dilemma?

P.S. I set the cull mode for the front, in case you wondered why some walls seem to be missing.

Have you tried the jmex.subdivide stuff?

Wow, thank you for the quick reply!

It appears that this class is not included in the online API. Downloaded the documentation and there it is.

I’ll look into it… thanks a lot!

edit:

Seems the light is smooth now… guess I have to work on keeping it in shape, though.

Also, I don't know if you have checked the attenuation of the light (point light) that can be used so that far light sources affect your surface less. (They have 3 parameters, constant, linear and square)

Also, there is a nice and cheap way of adding the illusion of granularity, you could use a Bump Mapping effect… check the tests to see some nice examples.

Good luck

Thanks for the hint. But isn't there another way? By increasing granularity I meant to express that I would like to split up the surfaces so that I would have more (more or less evenly distributed) normals. I would not have the problem with a sphere or torus for instance, as the mesh would already be very detailed. A Plane on the other hand is flat and requires very few triangles.

I would think that this is quite a common problem, but maybe I'm going wrong about it. While BumpMapping might solve the problem (I still have to test that out) it seems to be rather a workaround. Or is it actually the "common" way of doing this?

Even with the proper attenuation settings the odd light effects would persist locally. If one looks at my very first screenshot you notice the strange break of illumination in the corridor between the two obstacles (That is where the light source is).

The Subdivide class is neat but seems to be unsuitable for that purpose as it does not keep the "hard" lines. Furthermore I tested it with a triangle as well and the Subdivider bend it for some reason.

So, if I were not to use the bumpmapping trick, would there be another simple way?

I don't think there is a readily available solution for what you want. You can try modify the subdivide algorithm to only add extra vertices without doing any transformations. It's not much, but it's a place to start.