satoshinm / NetCraft

Web-based fork of fogleman/Craft ⛺
https://satoshinm.github.io/NetCraft/
MIT License
57 stars 13 forks source link

[Textures] Allow dropping resource pack .zip files, automatically construct texture atlases .png #113

Open satoshinm opened 7 years ago

satoshinm commented 7 years ago

With https://github.com/satoshinm/NetCraft/pull/93 you can now drag-and-drop a .png texture file from your desktop to the app, but it has to be in a texture atlas structure, like this: https://github.com/satoshinm/NetCraft/blob/master/textures/texture.png

In addition, it would be useful to allow dropping some kind of "texture pack" files, .zip format, and construct the atlas from it. Also perhaps allow this texture pack to be specified on the server-side build and use it automatically instead of the provided built-in textures.

satoshinm commented 7 years ago

Until zips are supported, what about changing to use similar texture offsets as the texture packs in https://github.com/satoshinm/NetCraft/pull/117? To save some time copying & pasting at different locations and allow the packs to be dragged-and-dropped into the app to set as the texture atlas easily. But Craft has a couple more textures in its texture.png: the player head cubes, 16 more colored blocks (why?), and 4 more flowers. Move the player heads somewhere else, to another texture?

satoshinm commented 7 years ago

Instead of a separate texture with all the complications that entails, what about enlarging the main texture from 256x256 to something larger, and using a different part of it? http://webglstats.com/webgl/parameter/MAX_TEXTURE_SIZE says 100% of WebGL supports 2048x2048 and 99% supports 4096x4096.


512x512 at 16x16 each = 32x32 = 1024 possible textures to use, should be enough for now (previous limit was 16x16=256, limited to 256 blocks, but see https://github.com/satoshinm/NetCraft/issues/55 Increase block ID range from 8-bit to 16-bit. More than blocks, also items, separate textures.)

satoshinm commented 7 years ago

Reading zip files: consider miniz, https://github.com/richgel999/miniz - a single C file amalgamation, zlib-replacement, no other dependencies. Curiously, it also includes a png writer. Note that Craft already includes lodepng, which has its own zlib decompressor. And there are emscripten ports for the full-featured libpng, zlib, and zlib/contrib contains minizip - but try to stay with the lightweight libraries instead, if possible, and avoid redundancies. There only needs to be one zlib decompressor. Can miniz replace lodepng, too? update: partly yes, lodepng can use miniz's zlib, saving some space: https://github.com/satoshinm/NetCraft/pull/126 Optimize lodepng to use miniz, not its own zlib update 2: done, can now read .zip files

satoshinm commented 7 years ago

stb_rect_pack? "rectangle packing - Useful for e.g. packing rectangular textures into an atlas."

satoshinm commented 7 years ago

Watch this space: https://github.com/webbukkit/DynmapBlockScan "Tool to scan post-1.8 MC blocks and JSON model data to automatically generate Dynmap models"