Add basic code to allow automatic generation of nodes.txt file
parent
b0d8924a6a
commit
621a8937af
|
@ -0,0 +1,47 @@
|
|||
local function nd_get_tiles(nd)
|
||||
local tiles
|
||||
if nd.tiles then
|
||||
tiles = nd.tiles
|
||||
elseif nd.tile_images then
|
||||
tiles = nd.tile_images
|
||||
end
|
||||
--if type(tiles) == 'table' then
|
||||
-- tiles = tiles.name
|
||||
--end
|
||||
if tiles == nil then
|
||||
tiles = {}
|
||||
end
|
||||
return tiles
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("dump", {
|
||||
params = "",
|
||||
description = "",
|
||||
func = function(plname, param)
|
||||
local n = 0
|
||||
local out, err = io.open('nodes.pre.txt', 'wb')
|
||||
if not out then
|
||||
return minetest.chat_send_player(plname, 'io.open: ' .. err)
|
||||
end
|
||||
for nn, nd in pairs(minetest.registered_nodes) do
|
||||
if nd.drawtype == nil or nd.drawtype == "normal" then
|
||||
local tiles = nd_get_tiles(nd)
|
||||
local texprefix = nn:gsub(":", "__")
|
||||
--[[
|
||||
for i, t in ipairs(tiles) do
|
||||
minetest.generateAndSaveTexture(t, texprefix .. i .. ".png")
|
||||
end
|
||||
--]]
|
||||
if #tiles == 1 then
|
||||
out:write(nn .. " cube - - - texture=" .. texprefix .. ".png " .. texprefix .. ".png\n")
|
||||
minetest.generateAndSaveTexture(tiles[1], texprefix .. ".png")
|
||||
n = n + 1
|
||||
else
|
||||
-- TODO
|
||||
end
|
||||
end
|
||||
end
|
||||
out:close()
|
||||
minetest.chat_send_player(plname, n .. " nodes dumped.")
|
||||
end,
|
||||
})
|
|
@ -0,0 +1,114 @@
|
|||
From e6e2c06760597fd712fe2cc7c56751bcb6a0036c Mon Sep 17 00:00:00 2001
|
||||
From: sfan5 <sfan5@live.de>
|
||||
Date: Fri, 3 Oct 2014 11:24:16 +0200
|
||||
Subject: [PATCH] Add minetest.generateAndSaveTexture
|
||||
|
||||
---
|
||||
src/game.cpp | 5 +++++
|
||||
src/script/lua_api/l_util.cpp | 18 ++++++++++++++++++
|
||||
src/script/lua_api/l_util.h | 3 +++
|
||||
src/tile.h | 1 +
|
||||
4 files changed, 27 insertions(+)
|
||||
|
||||
diff --git a/src/game.cpp b/src/game.cpp
|
||||
index a8f6bc9..f4ef64f 100644
|
||||
--- a/src/game.cpp
|
||||
+++ b/src/game.cpp
|
||||
@@ -1119,6 +1119,9 @@ static void updateChat(Client& client, f32 dtime, bool show_debug,
|
||||
show_chat && recent_chat_count != 0 && !show_profiler);
|
||||
}
|
||||
|
||||
+IWritableTextureSource *g_tsrc;
|
||||
+video::IVideoDriver *g_driver;
|
||||
+
|
||||
/******************************************************************************/
|
||||
void the_game(bool &kill, bool random_input, InputHandler *input,
|
||||
IrrlichtDevice *device, gui::IGUIFont* font, std::string map_dir,
|
||||
@@ -1130,6 +1133,7 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
|
||||
{
|
||||
GUIFormSpecMenu* current_formspec = 0;
|
||||
video::IVideoDriver* driver = device->getVideoDriver();
|
||||
+ g_driver = driver;
|
||||
scene::ISceneManager* smgr = device->getSceneManager();
|
||||
|
||||
// Calculate text height using the font
|
||||
@@ -1147,6 +1151,7 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
|
||||
|
||||
// Create texture source
|
||||
IWritableTextureSource *tsrc = createTextureSource(device);
|
||||
+ g_tsrc = tsrc;
|
||||
|
||||
// Create shader source
|
||||
IWritableShaderSource *shsrc = createShaderSource(device);
|
||||
diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp
|
||||
index eb6c183..91fe581 100644
|
||||
--- a/src/script/lua_api/l_util.cpp
|
||||
+++ b/src/script/lua_api/l_util.cpp
|
||||
@@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "tool.h"
|
||||
#include "filesys.h"
|
||||
#include "settings.h"
|
||||
+#include "tile.h"
|
||||
#include "main.h" //required for g_settings, g_settings_path
|
||||
|
||||
// debug(...)
|
||||
@@ -320,6 +321,21 @@ int ModApiUtil::l_decompress(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
+extern IWritableTextureSource *g_tsrc;
|
||||
+extern irr::video::IVideoDriver *g_driver;
|
||||
+
|
||||
+// generateAndSaveTexture(texture_name, out_filename)
|
||||
+int ModApiUtil::l_generateAndSaveTexture(lua_State *L)
|
||||
+{
|
||||
+ std::string texname = luaL_checkstring(L, 1);
|
||||
+ std::string outfile = luaL_checkstring(L, 2);
|
||||
+
|
||||
+ irr::video::IImage *img = g_tsrc->generateImage(texname);
|
||||
+ g_driver->writeImageToFile(img, outfile.c_str());
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
void ModApiUtil::Initialize(lua_State *L, int top)
|
||||
{
|
||||
API_FCT(debug);
|
||||
@@ -345,6 +361,8 @@ void ModApiUtil::Initialize(lua_State *L, int top)
|
||||
|
||||
API_FCT(compress);
|
||||
API_FCT(decompress);
|
||||
+
|
||||
+ API_FCT(generateAndSaveTexture);
|
||||
}
|
||||
|
||||
void ModApiUtil::InitializeAsync(AsyncEngine& engine)
|
||||
diff --git a/src/script/lua_api/l_util.h b/src/script/lua_api/l_util.h
|
||||
index e824323..d656171 100644
|
||||
--- a/src/script/lua_api/l_util.h
|
||||
+++ b/src/script/lua_api/l_util.h
|
||||
@@ -87,6 +87,9 @@ class ModApiUtil : public ModApiBase {
|
||||
// decompress(data, method, ...)
|
||||
static int l_decompress(lua_State *L);
|
||||
|
||||
+ // generateAndSaveTexture(texture_name, out_filename)
|
||||
+ static int l_generateAndSaveTexture(lua_State *L);
|
||||
+
|
||||
public:
|
||||
static void Initialize(lua_State *L, int top);
|
||||
|
||||
diff --git a/src/tile.h b/src/tile.h
|
||||
index 78aaef0..7bd0b60 100644
|
||||
--- a/src/tile.h
|
||||
+++ b/src/tile.h
|
||||
@@ -123,6 +123,7 @@ class IWritableTextureSource : public ITextureSource
|
||||
virtual bool isKnownSourceImage(const std::string &name)=0;
|
||||
virtual video::ITexture* generateTextureFromMesh(
|
||||
const TextureFromMeshParams ¶ms)=0;
|
||||
+ virtual video::IImage* generateImage(const std::string &name)=0;
|
||||
|
||||
virtual void processQueue()=0;
|
||||
virtual void insertSourceImage(const std::string &name, video::IImage *img)=0;
|
||||
--
|
||||
2.1.2
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
from PIL import Image
|
||||
|
||||
def avg2(a, b):
|
||||
return int((a + b) / 2.0)
|
||||
|
||||
def avg2t3i0(a, b):
|
||||
return tuple(avg2(t[0], t[1]) for t in zip(a[:3], b[:3]))
|
||||
|
||||
def avgcolor(name):
|
||||
inp = Image.open(name)
|
||||
inp = inp.convert('RGBA')
|
||||
ind = inp.load()
|
||||
avgc = -1
|
||||
for x in range(inp.size[0]):
|
||||
for y in range(inp.size[1]):
|
||||
pxl = ind[x, y]
|
||||
if pxl[3] < 128:
|
||||
continue
|
||||
if avgc == -1:
|
||||
avgc = pxl[:3]
|
||||
else:
|
||||
avgc = avg2t3i0(avgc, pxl)
|
||||
if avgc == -1:
|
||||
return "0 0 0"
|
||||
else:
|
||||
return "%d %d %d" % avgc
|
||||
|
||||
if len(sys.argv) <= 2:
|
||||
print("Usage: %s <in> <out>" % sys.argv[0])
|
||||
else:
|
||||
fin = open(sys.argv[1], "r")
|
||||
fout = open(sys.argv[2], "w")
|
||||
for line in fin:
|
||||
line = line[:-1] # cut off the \n
|
||||
# nodename modelname r g b params texture
|
||||
# ^ ^ ^ ^^^^^^^
|
||||
a = line.split(" ")
|
||||
fout.write("%s %s %s %s\n" % (a[0], a[1], avgcolor(a[6]), a[5]))
|
||||
fin.close()
|
||||
fout.close()
|
||||
|
||||
|
Loading…
Reference in New Issue