client, ext/graphics3d: Loading of textures (not tested)
This commit is contained in:
parent
4301546f2e
commit
b17ff040d7
@ -29,6 +29,7 @@ M.safe.Scene = polybox.wrap_class("Scene", {
|
||||
|
||||
M.safe.ScenePrimitive = polybox.wrap_class("ScenePrimitive", {
|
||||
constructor = function(type, v1, v2, v3, v4, v5)
|
||||
polybox.check_enum(type, {ScenePrimitive.TYPE_BOX, ScenePrimitive.TYPE_PLANE})
|
||||
polybox.check_type(v1, {"number", "nil"})
|
||||
polybox.check_type(v2, {"number", "nil"})
|
||||
polybox.check_type(v3, {"number", "nil"})
|
||||
@ -44,7 +45,8 @@ M.safe.ScenePrimitive = polybox.wrap_class("ScenePrimitive", {
|
||||
loadTexture = function(safe, texture_name)
|
||||
unsafe = polybox.check_type(safe, "ScenePrimitive")
|
||||
polybox.check_type(texture_name, "string")
|
||||
unsafe:loadTexture("foo")
|
||||
local path = __buildat_get_file_path(texture_name)
|
||||
unsafe:loadTexture(path)
|
||||
end,
|
||||
setPosition = function(safe, x, y, z)
|
||||
unsafe = polybox.check_type(safe, "ScenePrimitive")
|
||||
|
@ -278,6 +278,7 @@ struct CApp: public Polycode::EventHandler, public App
|
||||
}
|
||||
DEF_BUILDAT_FUNC(send_packet);
|
||||
DEF_BUILDAT_FUNC(get_file_content)
|
||||
DEF_BUILDAT_FUNC(get_file_path)
|
||||
DEF_BUILDAT_FUNC(get_path)
|
||||
DEF_BUILDAT_FUNC(pcall)
|
||||
|
||||
@ -354,6 +355,29 @@ struct CApp: public Polycode::EventHandler, public App
|
||||
}
|
||||
}
|
||||
|
||||
// get_file_path(name: string) -> path, hash
|
||||
static int l_get_file_path(lua_State *L)
|
||||
{
|
||||
size_t name_len = 0;
|
||||
const char *name_c = lua_tolstring(L, 1, &name_len);
|
||||
ss_ name(name_c, name_len);
|
||||
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, "__buildat_app");
|
||||
CApp *self = (CApp*)lua_touserdata(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
try {
|
||||
ss_ hash;
|
||||
ss_ path = self->m_state->get_file_path(name, &hash);
|
||||
lua_pushlstring(L, path.c_str(), path.size());
|
||||
lua_pushlstring(L, hash.c_str(), hash.size());
|
||||
return 1;
|
||||
} catch(std::exception &e){
|
||||
log_w(MODULE, "Exception in get_file_path: %s", e.what());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// get_file_content(name: string)
|
||||
static int l_get_file_content(lua_State *L)
|
||||
{
|
||||
|
@ -66,7 +66,7 @@ struct CState: public State
|
||||
});
|
||||
}
|
||||
|
||||
ss_ get_file_content(const ss_ &name)
|
||||
ss_ get_file_path(const ss_ &name, ss_ *dst_file_hash)
|
||||
{
|
||||
auto it = m_file_hashes.find(name);
|
||||
if(it == m_file_hashes.end())
|
||||
@ -74,6 +74,15 @@ struct CState: public State
|
||||
const ss_ &file_hash = it->second;
|
||||
ss_ file_hash_hex = interface::sha1::hex(file_hash);
|
||||
ss_ path = m_cache_path+"/"+file_hash_hex;
|
||||
if(dst_file_hash != nullptr)
|
||||
*dst_file_hash = file_hash;
|
||||
return path;
|
||||
}
|
||||
|
||||
ss_ get_file_content(const ss_ &name)
|
||||
{
|
||||
ss_ file_hash;
|
||||
ss_ path = get_file_path(name, &file_hash);
|
||||
std::ifstream f(path);
|
||||
if(!f.good())
|
||||
throw Exception(ss_()+"Could not open file: "+path);
|
||||
|
@ -18,6 +18,7 @@ namespace client
|
||||
virtual void update() = 0;
|
||||
virtual bool connect(const ss_ &address, const ss_ &port) = 0;
|
||||
virtual void send_packet(const ss_ &name, const ss_ &data) = 0;
|
||||
virtual ss_ get_file_path(const ss_ &name, ss_ *dst_file_hash = NULL) = 0;
|
||||
virtual ss_ get_file_content(const ss_ &name) = 0;
|
||||
};
|
||||
|
||||
|
@ -21,11 +21,11 @@ local g3d = require("buildat/extension/graphics3d")
|
||||
|
||||
scene = g3d.Scene(g3d.Scene.SCENE_3D)
|
||||
ground = g3d.ScenePrimitive(g3d.ScenePrimitive.TYPE_PLANE, 5,5)
|
||||
ground:loadTexture("Resources/green_texture.png")
|
||||
ground:loadTexture("test1/green_texture.png")
|
||||
scene:addEntity(ground)
|
||||
|
||||
box = g3d.ScenePrimitive(g3d.ScenePrimitive.TYPE_BOX, 1,1,1)
|
||||
box:loadTexture("Resources/pink_texture.png")
|
||||
box:loadTexture("test1/pink_texture.png")
|
||||
box:setPosition(0.0, 0.5, 0.0)
|
||||
scene:addEntity(box)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user