Verified Commit d1c97f1a authored by Flavien BRIDAULT-LOUCHEZ's avatar Flavien BRIDAULT-LOUCHEZ
Browse files

fix(viz): set texture unit state after changing a material template

parent 92fca270
......@@ -581,8 +581,7 @@ void Mesh::updateMesh(const data::PointList::csptr& _pointList)
std::pair<bool, std::vector<R2VBRenderable*> > Mesh::updateR2VB(
const data::Mesh::sptr& _mesh,
::Ogre::SceneManager& _sceneMgr,
const std::string& _materialName,
bool
const std::string& _materialName
)
{
//------------------------------------------
......
......@@ -87,8 +87,7 @@ public:
VIZ_SCENE3D_API std::pair<bool, std::vector<R2VBRenderable*> > updateR2VB(
const data::Mesh::sptr& _mesh,
::Ogre::SceneManager& _sceneMgr,
const std::string& _materialName,
bool _hasTexture
const std::string& _materialName
);
/// Updates the vertices position
......
......@@ -346,6 +346,12 @@ void SMaterial::updateField(data::Object::FieldsContainerType _fields)
const auto material = m_materialData.lock();
data::String::csptr string = data::String::dynamicCast(elt.second);
if(string->value() == m_materialTemplateName)
{
// Avoid useless update if this is the same template material
continue;
}
this->setMaterialTemplateName(string->getValue());
m_materialFw->setTemplate(m_materialTemplateName);
......@@ -357,6 +363,14 @@ void SMaterial::updateField(data::Object::FieldsContainerType _fields)
}
this->createShaderParameterAdaptors();
this->updating();
// When resetting the material template, all techniques and passes will be destroyed,
// so we need to reset the texture unit states
::Ogre::TexturePtr currentTexture = m_texAdaptor->getTexture();
if(currentTexture)
{
m_materialFw->setDiffuseTexture(currentTexture);
}
}
}
}
......
......@@ -328,8 +328,7 @@ void SMesh::updateMesh(const data::Mesh::sptr& _mesh)
auto r2vbRenderables = m_meshGeometry->updateR2VB(
_mesh,
*sceneMgr,
m_materialAdaptor->getMaterialName(),
m_materialAdaptor->hasDiffuseTexture()
m_materialAdaptor->getMaterialName()
);
for(auto renderable : r2vbRenderables.second)
{
......@@ -407,7 +406,12 @@ adaptor::SMaterial::sptr SMesh::createMaterialService(
const std::string mtlName = meshName + "_" + materialAdaptor->getID() + _materialSuffix;
materialAdaptor->setMaterialName(mtlName);
materialAdaptor->setTextureName(m_textureName);
if(_materialSuffix.empty())
{
// We know that we are in the case of a R2VB material, so no need to set the diffuse texture (no FP...)
materialAdaptor->setTextureName(m_textureName);
}
materialAdaptor->setShadingMode(m_shadingMode);
return materialAdaptor;
......@@ -489,8 +493,7 @@ void SMesh::modifyVertices()
m_meshGeometry->updateR2VB(
mesh.get_shared(),
*sceneMgr,
m_materialAdaptor->getMaterialName(),
m_materialAdaptor->hasDiffuseTexture()
m_materialAdaptor->getMaterialName()
);
// Necessary to update the bounding box in the adaptor
......
......@@ -116,7 +116,7 @@ void SMeshList::starting()
textureAdaptor->setLayerID(m_layerID);
textureAdaptor->setRenderService(this->getRenderService());
textureAdaptor->setInput(image, "image", true);
textureAdaptor->setInput(image, "image", false);
textureAdaptor->configure(textureConfig);
textureAdaptor->start();
......@@ -211,12 +211,9 @@ void SMeshList::add()
instance.m_isEnabled = true;
// update the transform
const sight::viz::scene3d::IAdaptor::sptr textureAdp = instance.m_texture;
{
// set current image
const auto image = textureAdp->getInput<data::Image>("image").lock();
const auto image = textureAdp->getInput<data::Image>("image").lock();
const auto textureInput = m_texture.lock();
if(m_generateAlpha && textureInput->getType() == core::tools::Type::s_UINT8
......@@ -224,7 +221,6 @@ void SMeshList::add()
|| textureInput->getNumberOfComponents() == 1))
{
// transform the image into RGBA with a transparent texture
if(textureInput->getAllocatedSizeInBytes() * 4 != instance.m_image->getAllocatedSizeInBytes())
{
instance.m_image->copyInformation(textureInput.get_shared());
......
......@@ -118,11 +118,11 @@ private:
/// Stores all services and data needed to add a new mesh.
struct MeshInstance
{
data::Matrix4::sptr m_matrix {nullptr};
data::Image::sptr m_image {nullptr};
sight::viz::scene3d::IAdaptor::sptr m_transform {nullptr};
sight::viz::scene3d::IAdaptor::sptr m_mesh {nullptr};
sight::viz::scene3d::IAdaptor::sptr m_texture {nullptr};
data::Matrix4::sptr m_matrix;
data::Image::sptr m_image;
sight::viz::scene3d::IAdaptor::sptr m_transform;
sight::viz::scene3d::IAdaptor::sptr m_mesh;
sight::viz::scene3d::IAdaptor::sptr m_texture;
bool m_isEnabled {false}; ///< set to true when the instance has been added once
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment