From 0a020dbcc848ae2debec664846e08bd097d70320 Mon Sep 17 00:00:00 2001 From: MirceaKitsune Date: Tue, 23 Oct 2012 20:03:06 +0300 Subject: [PATCH] Properly read the mesh from LUA. Players can now be set to meshes using the following test script: function switch_player_visual() prop = { mesh="player.obj", texture="player.png", visual="mesh", } for _, obj in pairs(minetest.get_connected_players()) do obj:set_properties(prop) end minetest.after(1.0, switch_player_visual) end minetest.after(1.0, switch_player_visual) --- src/content_cao.cpp | 20 ++++++++++++-------- src/content_sao.cpp | 5 ++--- src/object_properties.cpp | 8 ++++++++ src/scriptapi.cpp | 3 +++ 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/content_cao.cpp b/src/content_cao.cpp index e177fa15..985f3cbb 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -802,14 +802,18 @@ public: else if(m_prop.visual == "mesh"){ infostream<<"GenericCAO::addToScene(): mesh"<getMesh(m_prop.mesh.c_str()); - m_animated_meshnode = smgr->addAnimatedMeshSceneNode(mesh, NULL); - mesh->drop(); - - m_animated_meshnode->setScale(v3f(m_prop.visual_size.X, - m_prop.visual_size.Y, - m_prop.visual_size.X)); - u8 li = m_last_light; - setMeshColor(m_animated_meshnode->getMesh(), video::SColor(255,li,li,li)); + if(mesh) + { + m_animated_meshnode = smgr->addAnimatedMeshSceneNode(mesh, NULL); + + m_animated_meshnode->setScale(v3f(m_prop.visual_size.X, + m_prop.visual_size.Y, + m_prop.visual_size.X)); + u8 li = m_last_light; + setMeshColor(m_animated_meshnode->getMesh(), video::SColor(255,li,li,li)); + } + else + errorstream<<"GenericCAO::addToScene(): Could not load mesh "<(-1/3.,-1.0,-1/3., 1/3.,1.0,1/3.); // start of default appearance, this should be overwritten by LUA - m_prop.visual = "upright-sprite"; + m_prop.visual = "upright_sprite"; m_prop.visual_size = v2f(1, 2); m_prop.textures.clear(); m_prop.textures.push_back("player.png"); m_prop.textures.push_back("player_back.png"); m_prop.spritediv = v2s16(1,1); // end of default appearance - m_prop.is_visible = (getHP() != 0); + m_prop.is_visible = (getHP() != 0); // TODO: Use a death animation instead for mesh players m_prop.makes_footstep_sound = true; } @@ -1138,7 +1138,6 @@ void PlayerSAO::disconnected() } } - std::string PlayerSAO::getPropertyPacket() { m_prop.is_visible = (getHP() != 0); diff --git a/src/object_properties.cpp b/src/object_properties.cpp index e67b78b5..3a36addc 100644 --- a/src/object_properties.cpp +++ b/src/object_properties.cpp @@ -30,6 +30,8 @@ ObjectProperties::ObjectProperties(): weight(5), collisionbox(-0.5,-0.5,-0.5, 0.5,0.5,0.5), visual("sprite"), + mesh(""), + texture(""), visual_size(1,1), spritediv(1,1), initial_sprite_basepos(0,0), @@ -48,6 +50,8 @@ std::string ObjectProperties::dump() os<<", weight="<visual); + + getstringfield(L, -1, "mesh", prop->mesh); + getstringfield(L, -1, "texture", prop->texture); lua_getfield(L, -1, "visual_size"); if(lua_istable(L, -1))