diff --git a/data/textures/hatch_steel.png b/data/textures/hatch_steel.png index 9c0a0e2..220f008 100644 Binary files a/data/textures/hatch_steel.png and b/data/textures/hatch_steel.png differ diff --git a/data/textures/hatch_steel_w.png b/data/textures/hatch_steel_w.png index 9c0a0e2..dc4649a 100644 Binary files a/data/textures/hatch_steel_w.png and b/data/textures/hatch_steel_w.png differ diff --git a/src/camera.cpp b/src/camera.cpp index 31edb1b..65c6b7b 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -37,6 +37,8 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control): m_wieldmgr(NULL), m_wieldnode(NULL), + m_wieldnode_baserotation(-100, 110, -100), + m_wieldnode_baseposition(45, -35, 65), m_draw_control(draw_control), m_viewing_range_min(5.0), @@ -268,8 +270,8 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize) m_cameranode->setFarValue(m_viewing_range_max * BS * 10); // Position the wielded item - v3f wield_position = v3f(45, -35, 65); - v3f wield_rotation = v3f(-100, 110, -100); + v3f wield_position = m_wieldnode_baseposition; + v3f wield_rotation = m_wieldnode_baserotation; if (m_digging_button != -1) { f32 digfrac = m_digging_anim; @@ -453,25 +455,29 @@ void Camera::wield(const InventoryItem* item) { if (item != NULL) { - bool isCube = false; + bool haveWield = false; + m_wieldnode_baserotation = v3f(-100, 110, -100); + m_wieldnode_baseposition = v3f(45, -35, 65); // Try to make a MaterialItem cube. - if (std::string(item->getName()) == "MaterialItem") - { + if (std::string(item->getName()) == "MaterialItem") { // A block-type material MaterialItem* mat_item = (MaterialItem*) item; content_t content = mat_item->getMaterial(); - if (content_features(content).solidness || content_features(content).visual_solidness) - { + if (content_features(content).solidness || content_features(content).visual_solidness) { m_wieldnode->setCube(content_features(content).tiles); m_wieldnode->setScale(v3f(30)); - isCube = true; + haveWield = true; + }else if (content_features(content).draw_type == CDT_NODEBOX && content_features(content).wield_nodebox == true) { + m_wieldnode->setNodeBox(content); + m_wieldnode->setScale(v3f(30)); + m_wieldnode_baserotation = v3f(-10, 10, -10); + haveWield = true; } } // If that failed, make an extruded sprite. - if (!isCube) - { + if (!haveWield) { m_wieldnode->setSprite(item->getImageRaw()); m_wieldnode->setScale(v3f(40)); } @@ -481,7 +487,12 @@ void Camera::wield(const InventoryItem* item) else { // Bare hands - m_wieldnode->setVisible(false); + m_wieldnode->setArm(); + m_wieldnode_baserotation = v3f(-30, 130, 0); + m_wieldnode_baseposition = v3f(45, -35, 45); + //m_wieldnode->setSprite(g_texturesource->getTextureRaw("hand.png")); + //m_wieldnode->setScale(v3f(40,40,100)); + m_wieldnode->setVisible(true); } } @@ -573,8 +584,10 @@ void ExtrudedSpriteSceneNode::setSprite(video::ITexture* texture) void ExtrudedSpriteSceneNode::setCube(const TileSpec tiles[6]) { const v3f cube_scale(1.0, 1.0, 1.0); - if (m_cubemesh == NULL) - m_cubemesh = createCubeMesh(cube_scale); + if (m_cubemesh) + m_cubemesh->drop(); + + m_cubemesh = createCubeMesh(cube_scale); m_meshnode->setMesh(m_cubemesh); m_meshnode->setScale(v3f(1)); @@ -599,6 +612,89 @@ void ExtrudedSpriteSceneNode::setCube(const TileSpec tiles[6]) updateLight(m_light); } +void ExtrudedSpriteSceneNode::setNodeBox(content_t c) +{ + const v3f cube_scale(1.0, 1.0, 1.0); + if (m_cubemesh) + m_cubemesh->drop(); + + m_cubemesh = createNodeBoxMesh(content_features(c).nodeboxes,cube_scale); + + for (u16 i=0; i < content_features(c).nodeboxes.size(); i++) { + for (int t=0; t<6; t++) { + video::ITexture* atlas = content_features(c).tiles[t].texture.atlas; + v2f pos = content_features(c).tiles[t].texture.pos; + v2f size = content_features(c).tiles[t].texture.size; + video::SMaterial& material = m_cubemesh->getMeshBuffer((i*6)+t)->getMaterial(); + material.setFlag(video::EMF_LIGHTING, false); + material.setFlag(video::EMF_BILINEAR_FILTER, false); + content_features(c).tiles[i].applyMaterialOptions(material); + material.setTexture(0, atlas); + material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y); + material.getTextureMatrix(0).setTextureScale(size.X, size.Y); + } + } + + m_meshnode->setMesh(m_cubemesh); + m_meshnode->setScale(v3f(1)); + + m_meshnode->setVisible(true); + m_is_cube = true; + updateLight(m_light); +} + +void ExtrudedSpriteSceneNode::setArm() +{ + const v3f cube_scale(0.3, 1.0, 0.3); + if (m_cubemesh) + m_cubemesh->drop(); + + m_cubemesh = createCubeMesh(cube_scale); + + m_meshnode->setMesh(m_cubemesh); + m_meshnode->setScale(v3f(1)); + + // Get the tile texture and atlas transformation + std::string tex; + if (getTexturePath("player.png") != "") { + tex = "player.png^[forcesingle"; + }else{ + tex = "character.png^[forcesingle"; + } + video::ITexture* atlas = g_texturesource->getTextureRaw(tex); + v2f pos(0.625,0.5); + v2f size(0.0625,-0.0625); + + // Set material flags and texture + video::SMaterial& material = m_meshnode->getMaterial(0); + material.setFlag(video::EMF_LIGHTING, false); + material.setFlag(video::EMF_BILINEAR_FILTER, false); + material.MaterialType = video::EMT_SOLID; + material.BackfaceCulling = true; + material.setTexture(0, atlas); + material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y); + material.getTextureMatrix(0).setTextureScale(size.X, size.Y); + + for (int i = 1; i < 6; ++i) { + // Get the tile texture and atlas transformation + v2f pos(0.625,1); + v2f size(0.0625,-0.375); + + // Set material flags and texture + video::SMaterial& material = m_meshnode->getMaterial(i); + material.setFlag(video::EMF_LIGHTING, false); + material.setFlag(video::EMF_BILINEAR_FILTER, false); + material.MaterialType = video::EMT_SOLID; + material.BackfaceCulling = true; + material.setTexture(0, atlas); + material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y); + material.getTextureMatrix(0).setTextureScale(size.X, size.Y); + } + m_meshnode->setVisible(true); + m_is_cube = true; + updateLight(m_light); +} + void ExtrudedSpriteSceneNode::updateLight(u8 light) { m_light = light; diff --git a/src/camera.h b/src/camera.h index 0959bda..2d214fb 100644 --- a/src/camera.h +++ b/src/camera.h @@ -135,6 +135,8 @@ private: scene::ISceneManager* m_wieldmgr; ExtrudedSpriteSceneNode* m_wieldnode; + v3f m_wieldnode_baserotation; + v3f m_wieldnode_baseposition; // draw control MapDrawControl& m_draw_control; @@ -204,6 +206,8 @@ public: void setSprite(video::ITexture* texture); void setCube(const TileSpec tiles[6]); + void setNodeBox(content_t c); + void setArm(); f32 getSpriteThickness() const { return m_thickness; } void setSpriteThickness(f32 thickness); diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp index 66e4093..906ad64 100644 --- a/src/content_mapnode.cpp +++ b/src/content_mapnode.cpp @@ -1720,6 +1720,7 @@ void content_mapnode_init() f->setTexture(3,"door_wood_b.png^^[transformFX"); f->setTexture(4,"door_wood_b.png^^[transformFX"); f->setInventoryTexture("door_wood_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -1735,6 +1736,7 @@ void content_mapnode_init() f->setTexture(3,"door_wood_t.png^^[transformFX"); f->setTexture(4,"door_wood_t.png^^[transformFX"); f->setInventoryTexture("door_wood_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -1751,6 +1753,7 @@ void content_mapnode_init() f->setTexture(3,"door_steel_b.png^^[transformFX"); f->setTexture(4,"door_steel_b.png^^[transformFX"); f->setInventoryTexture("door_steel_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -1768,6 +1771,7 @@ void content_mapnode_init() f->setTexture(3,"door_steel_t.png^^[transformFX"); f->setTexture(4,"door_steel_t.png^^[transformFX"); f->setInventoryTexture("door_steel_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -1786,6 +1790,7 @@ void content_mapnode_init() f->setTexture(3,"door_wood_wb.png^[transformFX"); f->setTexture(4,"door_wood_wb.png^[transformFX"); f->setInventoryTexture("door_wood_w_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -1801,6 +1806,7 @@ void content_mapnode_init() f->setTexture(3,"door_wood_wt.png^[transformFX"); f->setTexture(4,"door_wood_wt.png^[transformFX"); f->setInventoryTexture("door_wood_w_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -1817,6 +1823,7 @@ void content_mapnode_init() f->setTexture(3,"door_steel_wb.png^[transformFX"); f->setTexture(4,"door_steel_wb.png^[transformFX"); f->setInventoryTexture("door_steel_w_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -1834,6 +1841,7 @@ void content_mapnode_init() f->setTexture(3,"door_steel_wt.png^[transformFX"); f->setTexture(4,"door_steel_wt.png^[transformFX"); f->setInventoryTexture("door_steel_w_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -1853,6 +1861,7 @@ void content_mapnode_init() f->setTexture(3,"door_wood_b.png"); f->setTexture(4,"door_wood_b.png"); f->setInventoryTexture("door_wood_inv.png^[transformFX"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -1868,6 +1877,7 @@ void content_mapnode_init() f->setTexture(3,"door_wood_t.png"); f->setTexture(4,"door_wood_t.png"); f->setInventoryTexture("door_wood_inv.png^[transformFX"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -1884,6 +1894,7 @@ void content_mapnode_init() f->setTexture(3,"door_steel_b.png"); f->setTexture(4,"door_steel_b.png"); f->setInventoryTexture("door_steel_inv.png^[transformFX"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -1901,6 +1912,7 @@ void content_mapnode_init() f->setTexture(3,"door_steel_t.png"); f->setTexture(4,"door_steel_t.png"); f->setInventoryTexture("door_steel_inv.png^[transformFX"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -1919,6 +1931,7 @@ void content_mapnode_init() f->setTexture(3,"door_wood_wb.png"); f->setTexture(4,"door_wood_wb.png"); f->setInventoryTexture("door_wood_w_inv.png^[transformFX"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -1934,6 +1947,7 @@ void content_mapnode_init() f->setTexture(3,"door_wood_wt.png"); f->setTexture(4,"door_wood_wt.png"); f->setInventoryTexture("door_wood_w_inv.png^[transformFX"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -1950,6 +1964,7 @@ void content_mapnode_init() f->setTexture(3,"door_steel_wb.png"); f->setTexture(4,"door_steel_wb.png"); f->setInventoryTexture("door_steel_w_inv.png^[transformFX"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -1967,6 +1982,7 @@ void content_mapnode_init() f->setTexture(3,"door_steel_wt.png"); f->setTexture(4,"door_steel_wt.png"); f->setInventoryTexture("door_steel_w_inv.png^[transformFX"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -1984,6 +2000,7 @@ void content_mapnode_init() f->setAllTextures("door_wood_b.png"); f->setTexture(3,"door_wood_b.png^[transformFX"); f->setInventoryTexture("door_wood_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -1997,6 +2014,7 @@ void content_mapnode_init() f->setAllTextures("door_wood_t.png"); f->setTexture(3,"door_wood_t.png^[transformFX"); f->setInventoryTexture("door_wood_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -2011,6 +2029,7 @@ void content_mapnode_init() f->setAllTextures("door_steel_b.png"); f->setTexture(3,"door_steel_b.png^[transformFX"); f->setInventoryTexture("door_steel_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -2026,6 +2045,7 @@ void content_mapnode_init() f->setAllTextures("door_steel_t.png"); f->setTexture(3,"door_steel_t.png^[transformFX"); f->setInventoryTexture("door_steel_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -2042,6 +2062,7 @@ void content_mapnode_init() f->setAllTextures("door_wood_wb.png"); f->setTexture(3,"door_wood_wb.png^[transformFX"); f->setInventoryTexture("door_wood_w_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -2055,6 +2076,7 @@ void content_mapnode_init() f->setAllTextures("door_wood_wt.png"); f->setTexture(3,"door_wood_wt.png^[transformFX"); f->setInventoryTexture("door_wood_w_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -2069,6 +2091,7 @@ void content_mapnode_init() f->setAllTextures("door_steel_wb.png"); f->setTexture(3,"door_steel_wb.png^[transformFX"); f->setInventoryTexture("door_steel_w_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -2084,6 +2107,7 @@ void content_mapnode_init() f->setAllTextures("door_steel_wt.png"); f->setTexture(3,"door_steel_wt.png^[transformFX"); f->setInventoryTexture("door_steel_w_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -2103,6 +2127,7 @@ void content_mapnode_init() f->setTexture(4,"door_wood_b.png^[transformFX"); f->setTexture(5,"door_wood_b.png^[transformFX"); f->setInventoryTexture("door_wood_inv.png^[transformFX"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -2118,6 +2143,7 @@ void content_mapnode_init() f->setTexture(4,"door_wood_t.png^[transformFX"); f->setTexture(5,"door_wood_t.png^[transformFX"); f->setInventoryTexture("door_wood_inv.png^[transformFX"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -2135,6 +2161,7 @@ void content_mapnode_init() f->setTexture(4,"door_steel_b.png^[transformFX"); f->setTexture(5,"door_steel_b.png^[transformFX"); f->setInventoryTexture("door_steel_inv.png^[transformFX"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -2152,6 +2179,7 @@ void content_mapnode_init() f->setTexture(4,"door_steel_t.png^[transformFX"); f->setTexture(5,"door_steel_t.png^[transformFX"); f->setInventoryTexture("door_steel_inv.png^[transformFX"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -2170,6 +2198,7 @@ void content_mapnode_init() f->setTexture(4,"door_wood_wb.png^[transformFX"); f->setTexture(5,"door_wood_wb.png^[transformFX"); f->setInventoryTexture("door_wood_w_inv.png^[transformFX"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -2185,6 +2214,7 @@ void content_mapnode_init() f->setTexture(4,"door_wood_wt.png^[transformFX"); f->setTexture(5,"door_wood_wt.png^[transformFX"); f->setInventoryTexture("door_wood_w_inv.png^[transformFX"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -2201,6 +2231,7 @@ void content_mapnode_init() f->setTexture(4,"door_steel_wb.png^[transformFX"); f->setTexture(5,"door_steel_wb.png^[transformFX"); f->setInventoryTexture("door_steel_w_inv.png^[transformFX"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -2218,6 +2249,7 @@ void content_mapnode_init() f->setTexture(4,"door_steel_wt.png^[transformFX"); f->setTexture(5,"door_steel_wt.png^[transformFX"); f->setInventoryTexture("door_steel_w_inv.png^[transformFX"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -2235,6 +2267,7 @@ void content_mapnode_init() f->setAllTextures("hatch_wood.png"); f->rotate_tile_with_nodebox = true; f->setInventoryTexture("hatch_wood_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -2249,6 +2282,7 @@ void content_mapnode_init() f->setAllTextures("hatch_steel.png"); f->rotate_tile_with_nodebox = true; f->setInventoryTexture("hatch_steel_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -2264,6 +2298,7 @@ void content_mapnode_init() f->setAllTextures("hatch_wood_w.png"); f->rotate_tile_with_nodebox = true; f->setInventoryTexture("hatch_wood_w_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -2278,6 +2313,7 @@ void content_mapnode_init() f->setAllTextures("hatch_steel_w.png"); f->rotate_tile_with_nodebox = true; f->setInventoryTexture("hatch_steel_w_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->is_ground_content = true; @@ -2296,6 +2332,7 @@ void content_mapnode_init() f->setTexture(3,"hatch_wood.png^[transformR90"); f->rotate_tile_with_nodebox = true; f->setInventoryTexture("hatch_wood_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->climbable = true; @@ -2313,6 +2350,7 @@ void content_mapnode_init() f->setTexture(3,"hatch_steel.png^[transformR90"); f->rotate_tile_with_nodebox = true; f->setInventoryTexture("hatch_steel_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->climbable = true; @@ -2331,6 +2369,7 @@ void content_mapnode_init() f->setTexture(3,"hatch_wood.png^[transformR90"); f->rotate_tile_with_nodebox = true; f->setInventoryTexture("hatch_wood_w_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->climbable = true; @@ -2348,6 +2387,7 @@ void content_mapnode_init() f->setTexture(3,"hatch_steel.png^[transformR90"); f->rotate_tile_with_nodebox = true; f->setInventoryTexture("hatch_steel_w_inv.png"); + f->wield_nodebox = false; f->draw_type = CDT_NODEBOX; f->solidness = 0; // drawn separately, makes no faces f->climbable = true; diff --git a/src/mapnode.h b/src/mapnode.h index e0307ae..ee6e7eb 100644 --- a/src/mapnode.h +++ b/src/mapnode.h @@ -147,6 +147,7 @@ struct ContentFeatures #endif bool rotate_tile_with_nodebox; + bool wield_nodebox; std::string description; std::vector nodeboxes; @@ -234,6 +235,7 @@ struct ContentFeatures special_atlas = NULL; #endif rotate_tile_with_nodebox = false; + wield_nodebox = true; description = std::string(""); nodeboxes.clear(); nodeboxes.push_back(core::aabbox3d(