SSCSM: Scriptable mapblock meshgen
Problem
There are various requests for paramtype2 / drawtypes (#17608, #17608, #16463, #16451, #17209, and many more older and/or closed ones). Most of them are not sufficiently general. Implementing enough drawtypes – or some complex data-driven "drawtype system" – to cover every need is not realistic and makes meshgen more of a mess. By my rough estimate, implementing and discussing all the requests would also end up taking much more time than implementing the feature proposed here, while resulting in a less powerful API that is more game-like, less engine-like, and more work to maintain.
(I've mentioned bits and pieces of the idea here in various paramtype2 issues and other places before, but I think it's worth collecting in an issue.)
Solutions
Add an API to SSCSM that takes a mapblock and returns a mesh to apply on top of the mesh Luanti generated. Say an overridable function core.generate_mapblock_mesh_overlay(vmanip) end.
Modders can then mark nodes drawtype = "airlike" to implement custom visuals for them.
Ideally, the vmanip can be manipulated before Luanti's meshgen runs, so modders can filter any nodes they want to meshgen themselves and then hand the rest to Luanti.
Perhaps also with a special return mesh, true or so if the meshgen entirely replaces Luanti's meshgen for a mapblock.
We might also want to expose Luanti's meshgen to Lua as a function from vmanip to mesh userdata.
Alternatives
- Add paramtypes which hit a sweet spot between ease of implementation and general usefulness.
- I think #15650 falls in this category.
- Remove SSCSM from the equation: Bad idea. Even after compression, the resulting meshes will likely be at least an order of magnitude larger than the original mapblocks.
- Hacks involving dynamic media and/or entities: Generally poor performance (again too much network traffic), and too much work for the mod developer.
Additional context
Depends on:
- Rudimentary Lua bindings for Irrlicht meshes. There should be a
Meshuserdata type. It should be possible to construct aMeshfrom a list ofMeshBuffers; it should be possible to construct aMeshBufferfrom vertices (positions, normals, texcoords, colors), indices, and a material (texture name, material properties like backface culling). - Exposing VoxelManip to SSCSM so the mapblock that needs meshgen can be read efficiently to begin with.
For good throughput, we will need async SSCSM envs (roughly analogeously to async mapgen envs on the server), and potentially "ndarray" Lua helpers (trying to represent and manipulate vertex data, e.g. positions, idiomatically as "tables of tables (vectors)" will not be efficient).
For proper custom drawtypes, the 8 bits of param2 also just suck, and meta is not efficient enough for anything that is dense. For that we'd need some form of #16125.
Quite a few interesting things would become possible for modders beyond new drawtypes, e.g. a limited form of mod-side LOD or node lighting would be possible.
Source: luanti-org/luanti