Skip to content

Commit

Permalink
GUIScene: Clear depth buffer + replace deprecated clearZBuffer calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Patrick Guerrero committed Mar 16, 2021
1 parent 66b5c08 commit 285ba74
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
3 changes: 2 additions & 1 deletion doc/lua_api.txt
Expand Up @@ -2299,7 +2299,7 @@ Elements
* `frame duration`: Milliseconds between each frame. `0` means the frames don't advance.
* `frame start` (Optional): The index of the frame to start on. Default `1`.

### `model[<X>,<Y>;<W>,<H>;<name>;<mesh>;<textures>;<rotation X,Y>;<continuous>;<mouse control>;<frame loop range>]`
### `model[<X>,<Y>;<W>,<H>;<name>;<mesh>;<textures>;<rotation X,Y>;<continuous>;<mouse control>;<frame loop range>;<animation speed>]`

* Show a mesh model.
* `name`: Element name that can be used for styling
Expand All @@ -2313,6 +2313,7 @@ Elements
* `frame loop range` (Optional): Range of the animation frames.
* Defaults to the full range of all available frames.
* Syntax: `<begin>,<end>`
* `animation speed` (Optional): Sets the animation speed. Default 0 FPS.

### `item_image[<X>,<Y>;<W>,<H>;<item name>]`

Expand Down
2 changes: 1 addition & 1 deletion src/client/camera.cpp
Expand Up @@ -664,7 +664,7 @@ void Camera::wield(const ItemStack &item)
void Camera::drawWieldedTool(irr::core::matrix4* translation)
{
// Clear Z buffer so that the wielded tool stays in front of world geometry
m_wieldmgr->getVideoDriver()->clearZBuffer();
m_wieldmgr->getVideoDriver()->clearBuffers(video::ECBF_DEPTH);

// Draw the wielded node (in a separate scene manager)
scene::ICameraSceneNode* cam = m_wieldmgr->getActiveCamera();
Expand Down
2 changes: 1 addition & 1 deletion src/client/hud.cpp
Expand Up @@ -950,7 +950,7 @@ void drawItemStack(

if (imesh && imesh->mesh) {
scene::IMesh *mesh = imesh->mesh;
driver->clearZBuffer();
driver->clearBuffers(video::ECBF_DEPTH);
s32 delta = 0;
if (rotation_kind < IT_ROT_NONE) {
MeshTimeInfo &ti = rotation_time_infos[rotation_kind];
Expand Down
2 changes: 1 addition & 1 deletion src/client/render/anaglyph.cpp
Expand Up @@ -40,7 +40,7 @@ void RenderingCoreAnaglyph::setupMaterial(int color_mask)
void RenderingCoreAnaglyph::useEye(bool right)
{
RenderingCoreStereo::useEye(right);
driver->clearZBuffer();
driver->clearBuffers(video::ECBF_DEPTH);
setupMaterial(right ? video::ECP_GREEN | video::ECP_BLUE : video::ECP_RED);
}

Expand Down
4 changes: 3 additions & 1 deletion src/gui/guiFormSpecMenu.cpp
Expand Up @@ -2746,7 +2746,7 @@ void GUIFormSpecMenu::parseModel(parserData *data, const std::string &element)
{
std::vector<std::string> parts = split(element, ';');

if (parts.size() < 5 || (parts.size() > 9 &&
if (parts.size() < 5 || (parts.size() > 10 &&
m_formspec_version <= FORMSPEC_API_VERSION)) {
errorstream << "Invalid model element (" << parts.size() << "): '" << element
<< "'" << std::endl;
Expand All @@ -2766,6 +2766,7 @@ void GUIFormSpecMenu::parseModel(parserData *data, const std::string &element)
bool inf_rotation = is_yes(parts[6]);
bool mousectrl = is_yes(parts[7]) || parts[7].empty(); // default true
std::vector<std::string> frame_loop = split(parts[8], ',');
std::string speed = unescape_string(parts[9]);

MY_CHECKPOS("model", 0);
MY_CHECKGEOM("model", 1);
Expand Down Expand Up @@ -2825,6 +2826,7 @@ void GUIFormSpecMenu::parseModel(parserData *data, const std::string &element)
}

e->setFrameLoop(frame_loop_begin, frame_loop_end);
e->setAnimationSpeed(stof(speed));

auto style = getStyleForElement("model", spec.fname);
e->setStyles(style);
Expand Down
15 changes: 12 additions & 3 deletions src/gui/guiScene.cpp
Expand Up @@ -34,9 +34,6 @@ GUIScene::GUIScene(gui::IGUIEnvironment *env, scene::ISceneManager *smgr,
m_cam = m_smgr->addCameraSceneNode(0, v3f(0.f, 0.f, -100.f), v3f(0.f));
m_cam->setFOV(30.f * core::DEGTORAD);

scene::ILightSceneNode *light = m_smgr->addLightSceneNode(m_cam);
light->setRadius(1000.f);

m_smgr->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true);
}

Expand All @@ -60,6 +57,7 @@ scene::IAnimatedMeshSceneNode *GUIScene::setMesh(scene::IAnimatedMesh *mesh)
m_mesh = m_smgr->addAnimatedMeshSceneNode(mesh);
m_mesh->setPosition(-m_mesh->getBoundingBox().getCenter());
m_mesh->animateJoints();

return m_mesh;
}

Expand All @@ -73,10 +71,13 @@ void GUIScene::setTexture(u32 idx, video::ITexture *texture)
material.setFlag(video::EMF_FOG_ENABLE, true);
material.setFlag(video::EMF_BILINEAR_FILTER, false);
material.setFlag(video::EMF_BACK_FACE_CULLING, false);
material.setFlag(video::EMF_ZWRITE_ENABLE, true);
}

void GUIScene::draw()
{
m_driver->clearBuffers(video::ECBF_DEPTH);

// Control rotation speed based on time
u64 new_time = porting::getTimeMs();
u64 dtime_ms = 0;
Expand Down Expand Up @@ -161,6 +162,14 @@ void GUIScene::setFrameLoop(s32 begin, s32 end)
m_mesh->setFrameLoop(begin, end);
}

/**
* Sets the animation speed (FPS) for the mesh
*/
void GUIScene::setAnimationSpeed(f32 speed)
{
m_mesh->setAnimationSpeed(speed);
}

/* Camera control functions */

inline void GUIScene::calcOptimalDistance()
Expand Down
1 change: 1 addition & 0 deletions src/gui/guiScene.h
Expand Up @@ -37,6 +37,7 @@ class GUIScene : public gui::IGUIElement
void setTexture(u32 idx, video::ITexture *texture);
void setBackgroundColor(const video::SColor &color) noexcept { m_bgcolor = color; };
void setFrameLoop(s32 begin, s32 end);
void setAnimationSpeed(f32 speed);
void enableMouseControl(bool enable) noexcept { m_mouse_ctrl = enable; };
void setRotation(v2f rot) noexcept { m_custom_rot = rot; };
void enableContinuousRotation(bool enable) noexcept { m_inf_rot = enable; };
Expand Down

0 comments on commit 285ba74

Please sign in to comment.