moving mesh in GE - material does not change


I have a simple plane with lots of vertexes inside and a material on top. If I pull one vertex down in the 3D view and then start the GE I can see the nice shading of the plane around the “hole”.

Now if I do the exact same thing directly in the GE with a simple python script, the vertex is still pulled down (I can read its coordinates in the console), but the plane still looks flat, no shading, no “hole”.

What am I missing? Do I need some sort of refresh of the scene?

Thank you!!!

The BGE mesh model does not deal with vertices as Blender does. It only knows faces. Each face has 3 or 4 vertices. Vertices are not shared with other faces (as it is in Blender).

You need to move all vertices of the faces next to the vertex you meant. Otherwise you deform only one face.

Beside that: Make sure you use the Game Engine API not the Blender API.

ffrige: normals are not recomputed when you move a vertex. You will have to set it manually for the vertex, which will involve a bit of math. Hope that helps!

Hello and thanks for all the replies!

@Monster: yes, I am using the GE API, and actually all my vertices are shared between faces. I am in the lucky case in which all the conditions are true (same color, position, normals,…). I can verify this by looping all the existing vertices and counting the ones at a single worldposition: I only get one vertex. And that’s the one I pull down vertically along the Z-axis.

The solution is actually, as jplur correctly suggested, to manually set all the normal of the surrounding verteces. The single vertex that moves down does not modify its normal, but all the surrounding ones do. I’ll have to work out the math and set them manually. However, this is going to be a ton of work! Plus, how do I find the index of all the surrounding verteces? I’m thinking of testing all the polygons, find the ones containing the dropping vertex and from those extract all the remaining verteces. Quite a bit of looping and thinking…

Is there an easier way to do this? It’s just a simple silly plane… imagine a soft surface and then drop an invisible small ball on it. It will make a small cavity inside. How can I show this quickly in the GE?

Thanks again!

A common method is to do that at game start and build a dictionary of vertices. The key should uniquely define the “shared” Blender vertex, the value should be a list of the vertices from the several faces.
Later you can access this dictionary and you get all involved vertices without looping through the mesh again.

Does that help?

Well, apparently I do not even need a dictionary, I can simply calculate the index, since the GE assigns consecutive indexes to consecutive vertices. That’s much easier and it works well, except for the first two rows of the plane, which are a bit different but can be compensated easily in the formula. The hard part is calculating the normals…

Now I thought of a different way, which looks promising. Instead of modifying the normals I just assign a different color to the vertex that moves down. I make the color darker proportionally to the depth. Very deep holes will be almost black and all the surrounding faces are automatically shaded accordingly. This sorts of simulates real shades and is much easier to implement because it requires no calculations at all…

You could record an animation of yourself “pulling down” that vertex (using shape keys), and play it with BGE (Shape Action -> play).

You could do the “pulling down” using a proportional edit falloff - what you may be trying to achieve could get more “visible”.

I hope your “game” setup (lights, game settings) can Render(with BGE) a “Set Smooth”(have you used this property(button) on your plane?) UV Sphere so you can see it smoothly, but can’t show you the vertex in the way you want it to, right?

Have you tried both Multitexture Materials and GLSL mode to see if your mesh still looks “bad” ?

Hmm, using animations is impossible, I think, I have >300000 vertexes in my plane, cannot animate so many…

I tried all possible falloffs, nothing is visible. After all, if the normals are not recomputed, it does not matter what falloff is selected.

I also tried all modes of texturing, nothing changes. I’ll keep the current solution based on vertex colors, it’s the best so far.

Thanks all for the good tips.