Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ VisualModelImpl::VisualModelImpl() //const std::string &name, std::string filena
, d_vertPosIdx (initData (&d_vertPosIdx, "vertPosIdx", "If vertices have multiple normals/texcoords stores vertices position indices"))
, d_vertNormIdx (initData (&d_vertNormIdx, "vertNormIdx", "If vertices have multiple normals/texcoords stores vertices normal indices"))
, d_fileMesh (initData (&d_fileMesh, "filename", " Path to an ogl model"))
, d_texturename (initData (&d_texturename, "texturename", "Name of the Texture"))
, d_texturename (initData (&d_texturename, "texturename", "Full path of the texture file"))
, d_translation (initData (&d_translation, Vec3Real(), "translation", "Initial Translation of the object"))
, d_rotation (initData (&d_rotation, Vec3Real(), "rotation", "Initial Rotation of the object"))
, d_scale (initData (&d_scale, Vec3Real(1.0, 1.0, 1.0), "scale3d", "Initial Scale of the object"))
Expand Down Expand Up @@ -224,7 +224,15 @@ void VisualModelImpl::doDrawVisual(const core::visual::VisualParams* vparams)
if (m_textureChanged)
{
deleteTextures();
loadTexture(d_texturename.getFullPath());
std::string textureFilename = d_texturename.getFullPath();
if (sofa::helper::system::DataRepository.findFile(textureFilename))
{
loadTexture(d_texturename.getFullPath());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
loadTexture(d_texturename.getFullPath());
loadTexture(textureFilename);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findFile return false when it is a full path, so this check is indeed wrong

if (SetDirectory::IsAbsolute(filename)) return false; // absolute file path

}
Comment thread
fredroy marked this conversation as resolved.
Comment thread
epernod marked this conversation as resolved.
else
{
msg_error() << "Texture " << textureFilename << " cannot be loaded";
}
m_textureChanged = false;
}
initVisual(vparams);
Expand Down Expand Up @@ -491,7 +499,7 @@ bool VisualModelImpl::load(const std::string& filename, const std::string& loade
const bool textureLoaded = loadTexture(textureName);
if(!textureLoaded)
{
msg_error()<<"Texture "<<textureName<<" cannot be loaded";
msg_error() << "Texture " << textureName << " cannot be loaded";
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ OglModel::OglModel()
, blendEquation( initData(&blendEquation, "blendEquation", "if alpha blending is enabled this specifies how source and destination colors are combined") )
, sourceFactor( initData(&sourceFactor, "sfactor", "if alpha blending is enabled this specifies how the red, green, blue, and alpha source blending factors are computed") )
, destFactor( initData(&destFactor, "dfactor", "if alpha blending is enabled this specifies how the red, green, blue, and alpha destination blending factors are computed") )
, m_tex(nullptr)
, vbo(0), iboEdges(0), iboTriangles(0), iboQuads(0)
, VBOGenDone(false), initDone(false), useEdges(false), useTriangles(false), useQuads(false), canUsePatches(false)
, oldVerticesSize(0), oldNormalsSize(0), oldTexCoordsSize(0), oldTangentsSize(0), oldBitangentsSize(0), oldEdgesSize(0), oldTrianglesSize(0), oldQuadsSize(0)
Expand Down Expand Up @@ -90,8 +89,7 @@ void OglModel::deleteTextures()
{
if (m_tex != nullptr)
{
delete m_tex;
m_tex = nullptr;
m_tex.reset(nullptr);
}

for (unsigned int i = 0 ; i < textures.size() ; i++)
Expand Down Expand Up @@ -595,7 +593,8 @@ bool OglModel::loadTexture(const std::string& filename)
helper::io::Image *img = helper::io::Image::Create(filename);
if (!img)
return false;
m_tex = new sofa::gl::Texture(img, true, true, false, d_srgbTexturing.getValue());

m_tex = std::make_unique<sofa::gl::Texture>(img, true, true, false, d_srgbTexturing.getValue());
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class SOFA_GL_COMPONENT_RENDERING3D_API OglModel : public sofa::component::visua
Data<sofa::helper::OptionsGroup> destFactor; ///< if alpha blending is enabled this specifies how the red, green, blue, and alpha destination blending factors are computed
GLenum blendEq, sfactor, dfactor;

sofa::gl::Texture *m_tex; //this texture is used only if a texture name is specified in the scn
std::unique_ptr<sofa::gl::Texture> m_tex; //this texture is used only if a texture name is specified in the scn
GLuint vbo, iboEdges, iboTriangles, iboQuads;
bool VBOGenDone, initDone, useEdges, useTriangles, useQuads, canUsePatches;
size_t oldVerticesSize, oldNormalsSize, oldTexCoordsSize, oldTangentsSize, oldBitangentsSize, oldEdgesSize, oldTrianglesSize, oldQuadsSize;
Expand Down Expand Up @@ -123,7 +123,7 @@ class SOFA_GL_COMPONENT_RENDERING3D_API OglModel : public sofa::component::visua
bool isUseTriangles() { return useTriangles; }
bool isUseQuads() { return useQuads; }

sofa::gl::Texture* getTex() const { return m_tex; }
sofa::gl::Texture* getTex() const { return m_tex.get(); }
GLuint getVbo() { return vbo; }
GLuint getIboEdges() { return iboEdges; }
GLuint getIboTriangles() { return iboTriangles; }
Expand Down
Loading