Commit eebbbe23 authored by Jan Möbius's avatar Jan Möbius
Browse files

New texture handling with support for multiple textures per object

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@4650 383ad7c9-94d9-4d36-a494-682f7c89f535
parent e70cfa40
......@@ -452,52 +452,44 @@
void MeshObject< MeshT , objectDataType >::addTexture(QString _name , QImage& _image , int _id )
{
if ( _id == -1 ) {
std::cerr << "This texture has no id from the mesh using next free id!!!!!" << std::endl;
_id = textures_.size();
}
if ( textures_.empty() ) {
std::cerr << "No texture set." << std::endl;
}
for ( uint i = 0 ; i < textures_.size(); ++i ) {
if ( textureNames_[i] == _name ) {
std::cerr << "Texture already exists!! Use setTexture to change a texture. Setting new texture" << std::endl;
std::cerr << "Texture already exists!! Use setTexture to change a texture. Setting new texture anyway" << std::endl;
setTexture( _name, _image );
return;
}
}
if ( _id >= (int)textures_.size() ) {
std::cerr << "Expanded texture index vector." << std::endl;
textures_.resize(_id + 1);
textureNames_.resize(_id + 1);
}
std::cerr << "Adding texture" << std::endl;
textures_[_id] = textureNode_->add_texture(_image) ;
textureNames_[_id] = _name;
meshNode_->set_texture_map(&textures_);
if ( textures_.size() > 1 && !mesh_->has_face_texture_index() ) {
std::cerr << "More than one textures available but no faceindex set. Only first texture will be used." << std::endl;
}
// if ( textures_.size() > 1 && !mesh_->has_face_texture_index() ) {
// std::cerr << "More than one textures available but no faceindex set. Only first texture will be used." << std::endl;
// }
}
template < class MeshT , DataType objectDataType >
void MeshObject< MeshT , objectDataType >::setTexture( QString _name , QImage& _image ) {
std::cerr << _image.size().width() << std::endl;
for ( uint i = 0 ; i < textures_.size(); ++i ) {
if ( textureNames_[i] == _name ) {
std::cerr << "Found Texture, TODO : update" << std::endl;
textureNode_->set_texture(_image,textures_[i]);
return;
}
}
std::cerr << "Texture not found in this object" << std::endl;
addTexture( _name , _image );
}
template < class MeshT , DataType objectDataType >
......@@ -509,6 +501,16 @@
return false;
}
template < class MeshT , DataType objectDataType >
bool MeshObject< MeshT , objectDataType >::enableTexture( QString _name ) {
for ( uint i = 0 ; i < textures_.size(); ++i ) {
if ( textureNames_[i] == _name )
textureNode_->activateTexture(textures_[i]);
return true;
}
return false;
}
// ===============================================================================
// Load/Save
// ===============================================================================
......
......@@ -281,7 +281,9 @@ class DLLEXPORT MeshObject : public BaseObjectData {
*/
void addTexture( QString _name , QImage& _image , int _id = -1);
/** Change an already loaded texture
/** \brief Change an already loaded texture by replacing it with the given image.
*
* If the texture does not exist, a new one will be created.
*
*/
void setTexture( QString _name , QImage& _image );
......@@ -291,6 +293,12 @@ class DLLEXPORT MeshObject : public BaseObjectData {
*/
bool textureExists( QString _name );
/** \brief Enable the given texture
*
* Use this function to enable a specific texture.
*/
bool enableTexture( QString _name );
private:
/** This vector is used to store the available Textures. Each call to addTexture will load
* the texture in the textureNode. The MeshNode will use only the first texture unless
......
......@@ -102,47 +102,38 @@ void TextureControlPlugin::slotTextureUpdated( QString _textureName , int _ident
if ( activeTexture_ != _textureName)
return;
const bool repeat = textures_[textureid].repeat;
QString filename = OpenFlipper::Options::textureDir().absolutePath() +
OpenFlipper::Options::dirSeparator() +
textures_[textureid].filename;
// load to image
QImage textureImage;
if ( !textureImage.load( filename ) )
{
std::cerr << "Cannot load texture " << filename.toStdString() << "\n";
return ;
}
if( object->dataType( DATA_TRIANGLE_MESH ) ) {
TriMesh* mesh = PluginFunctions::triMesh(object);
doUpdateTexture(textureid, *mesh);
PluginFunctions::triMeshObject(object)->textureNode()->set_repeat(repeat);
QString filename = OpenFlipper::Options::textureDir().absolutePath() +
OpenFlipper::Options::dirSeparator() +
textures_[textureid].filename;
// load to image
QImage textureImage;
if ( !textureImage.load( filename ) )
{
std::cerr << "Cannot load texture " << filename.toStdString() << "\n";
return ;
}
PluginFunctions::triMeshObject(object)->textureNode()->set_repeat(textures_[textureid].repeat);
PluginFunctions::triMeshObject(object)->setTexture(_textureName,textureImage);
PluginFunctions::triMeshObject(object)->addTexture(_textureName,textureImage);
//TODO
//textureExists
//enableTexture
}
if ( object->dataType( DATA_POLY_MESH ) ) {
PolyMesh* mesh = PluginFunctions::polyMesh(object);
doUpdateTexture(textureid, *mesh);
PluginFunctions::polyMeshObject(object)->textureNode()->set_repeat(textures_[textureid].repeat);
PluginFunctions::polyMeshObject(object)->setTexture(_textureName,textureImage);
PluginFunctions::polyMeshObject(object)->textureNode()->set_repeat(repeat);
QString filename = OpenFlipper::Options::textureDir().absolutePath() +
OpenFlipper::Options::dirSeparator() +
textures_[textureid].filename;
// load to image
QImage textureImage;
if ( !textureImage.load( filename ) )
{
std::cerr << "Cannot load texture " << filename.toStdString() << "\n";
return ;
}
PluginFunctions::polyMeshObject(object)->addTexture(_textureName,textureImage);
//TODO
//textureExists
//enableTexture
}
emit updateView();
......
Markdown is supported
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