Editing meshes during runtime

So basically I’ve started working on a Minecraft like terrain engine. Just for a fun learning experience of course, I know there are already way too many Minecraft clones out there. Anyways, getting blocks with textures up on the screen was simple enough. Exported a block from Blender, set the texture directly through Python because the exporter I’m using doesn’t entirely work correctly, and then used a couple of for loops to make a 20x20x20 cube of smaller cubes. At this point I realized that I would have to postpone other progress in order to work on optimizations because my frame rate drops down to about 1 fps.

I used the analyze method to check the stats on the render node and realized that there are a total of 16003 nodes being used. I’ve seen around the forums that it’s not recommended to go over about total nodes, so it was apparent that I first needed to solve this issue.

After a quick Google search it seemed to me that the flattenStrong method would solve this problem for me, however I couldn’t figure out how exactly to use this correctly, at least from what I could tell because the number of nodes did not decrease after I used self.render.flattenStrong().

So now I’m thinking that what would help would be to hold the cubes in a single mesh, so that instead of adding a whole cube mesh for each block, I would just add the appropriate vertices to the mesh and set the appropriate textures for those faces.

How much of this would I actually be able to do with Panda3d 1.8.0? I’ve seen around that you can’t directly set the textures of individual faces and that all you can do is set the texture of the mesh as a whole. I’m hoping that’s not the case.

Any help, explanations, suggestions, etc. would be very much appreciated. Oh and sorry for the long read. :slight_smile:

Hmm… I’m not confident in the area that you’re working in, I fear, but a few things occur to me:

In the version using separate cubes, you might be able to cull a great many cubes, both by use of the built-in culling (by creating a spacially-arranged node hierarchy, allowing large clumps to be culled) and perhaps by only showing (via show() and hide()) cubes that are not surrounded by other cubes.

In the version that uses a single mesh, however, you may be able to assign textures by using a single, large texture and assigning UV-coordinates such that the UV coordinates specify a section of the overall image that contains the desired texture.

Finally, you might want to check whether any of your slowdown is on the Python side: if you’re iterating over all of those 20x20x20 (8000) blocks the simple act of iteration might be a significant slowdown, I fear.

Oh, and as to flattenStrong, I may be mistaken, but I seem to recall that it doesn’t extend past egg-file boundaries; you might get it to produce better results if you use the child of the NodePath produced by loader.loadModel rather than that NodePath itself.

Thanks for the quick response! Your culling idea sounds great and I’ll look into incorporating something of the sort. Have I read correctly that Panda3D automatically performs frustum culling, but that I will have to write some sort of occlusion culling methods in myself?

As to the UV coordinates suggestion, that sounds like it would do exactly what I’m looking for, so I’ll just have to do some quick research into how to accomplish that.

At the moment, I don’t have much of anything being done through Python. The only operations it performs are at the beginning to load the blocks up into the game correctly, but after that it should all be being handles by Panda3D, which is C++ right?

What you mentioned referring to flattenStrong would explain why it doesn’t seem to be doing anything. Thank you for the input, it has helped!

It’s my pleasure - I’m glad to have been of aid. :slight_smile:

As to culling, my understanding is that the main burden on you is simply in how you structure your scene, laying out a node-tree that both allows for culling away of large chunks and is not too deep.

That said, you have reminded me that Panda also, I believe, includes an OccluderNode which may be of service to you in culling blocks that are within the frustum but which are nevertheless not likely visible. More information should be in the manual here.