TextureControl.cc 68.2 KB
Newer Older
1 2 3
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
Jan Möbius's avatar
Jan Möbius committed
4
 *      Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen      *
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  OpenFlipper is free software: you can redistribute it and/or modify      *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenFlipper is distributed in the hope that it will be useful,           *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
 *   $Revision$                                                         *
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42 43 44 45




46

Jan Möbius's avatar
 
Jan Möbius committed
47 48 49 50 51
#include <QtGui>

#include "TextureControl.hh"

#include <iostream>
52
#include <ACG/GL/GLState.hh>
Jan Möbius's avatar
 
Jan Möbius committed
53 54

#include "OpenFlipper/BasePlugin/PluginFunctions.hh"
Jan Möbius's avatar
Jan Möbius committed
55
#include "OpenFlipper/BasePlugin/PluginFunctionsViewControls.hh"
Jan Möbius's avatar
 
Jan Möbius committed
56 57
#include "OpenFlipper/common/GlobalOptions.hh"

58 59
#include <math.h>

60 61 62
#define TEXTUREDATA "TextureData"


63
 
64

Dirk Wilden's avatar
Dirk Wilden committed
65 66 67 68 69 70
void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _filename , uint _dimension , int _id)
{
  // Get the new object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
    emit log(LOGERR,"Unable to get Object for id " + QString::number(_id) );
71
    return;
Dirk Wilden's avatar
Dirk Wilden committed
72 73 74 75 76 77 78 79 80
  }

  // Get Texture data for this object or create one if it does not exist
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0){
    texData = new TextureData();
    obj->setObjectData(TEXTUREDATA, texData);
  }

81
  if ( texData->textureExists(_textureName) ) {
Dirk Wilden's avatar
Dirk Wilden committed
82 83 84
    emit log(LOGERR,"Trying to add already existing texture " + _textureName + " for object " + QString::number(_id) );
    return;
  }
85 86 87 88 89 90

  // ================================================================================
  // Get the image file
  // ================================================================================

  QImage textureImage;
Dirk Wilden's avatar
 
Dirk Wilden committed
91 92

  if ( !getImage(_filename,textureImage) )
93 94
    emit log(LOGERR, "slotTextureAdded : Cannot load texture '" + _textureName + "'. File not found '" + _filename + "'");

Dirk Wilden's avatar
 
Dirk Wilden committed
95

96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118

  // ================================================================================
  // Add the texture to the texture node and get the corresponding id
  // ================================================================================
  GLuint glName = 0;

  //inform textureNode about the new texture
  if( obj->dataType( DATA_TRIANGLE_MESH ) )
    glName = PluginFunctions::triMeshObject(obj)->textureNode()->add_texture(textureImage);

  if ( obj->dataType( DATA_POLY_MESH ) )
    glName = PluginFunctions::polyMeshObject(obj)->textureNode()->add_texture(textureImage);

  // ================================================================================
  // Store texture information in objects metadata
  // ================================================================================

  if (glName == 0) {
    emit log(LOGERR,"Unable to bind texture!");
    return;
  }

  texData->addTexture(_textureName,_filename,_dimension,glName);
119
  texData->setImage(_textureName,textureImage);
120
  texData->texture(_textureName).disable();
Dirk Wilden's avatar
Dirk Wilden committed
121 122
}

Jan Möbius's avatar
 
Jan Möbius committed
123 124
void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _filename , uint _dimension)
{
125 126 127
  // Add this texture to the list of global textures
  if ( ! globalTextures_.textureExists(_textureName) ) {
    globalTextures_.addTexture(_textureName,_filename,_dimension,0);
128
    globalTextures_.texture(_textureName).disable();
129 130

    QImage textureImage;
Dirk Wilden's avatar
 
Dirk Wilden committed
131 132 133 134

    if ( !getImage(_filename,textureImage) )
      emit log(LOGERR, "Cannot load texture '" + _textureName + "'. File not found '" + _filename + "'");

135 136
    globalTextures_.texture(_textureName).textureImage = textureImage;

137 138 139 140
  } else {
    emit log(LOGERR,"Trying to add already existing global texture " + _textureName );
    return;
  }
141

142
  // Add a new entry to the global Texture menu
Jan Möbius's avatar
 
Jan Möbius committed
143
  QAction* new_texture = new QAction(_textureName, this);
144
  new_texture->setStatusTip(tr("Switch all objects to this Texture ( if available )"));
Jan Möbius's avatar
 
Jan Möbius committed
145 146 147 148 149
  new_texture->setCheckable(true);
  actionGroup_->addAction(new_texture);
  textureMenu_->addAction(new_texture);
  new_texture->setChecked(true);
  textureActions_.push_back(new_texture);
150

151
}
152

153
void TextureControlPlugin::slotMultiTextureAdded( QString _textureGroup , QString _name , QString _filename , int _id , int& _textureId ) {
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
   // Get the new object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
    emit log(LOGERR,"Unable to get Object for id " + QString::number(_id) );
  }

  // Check if we support this kind of data
  if ( !obj->dataType(DATA_TRIANGLE_MESH) && !obj->dataType(DATA_POLY_MESH) ) {
      emit log(LOGERR,"Trying to add textures to object failed because of unsupported object type");
      return;
  }

  // Get Texture data for this object or create one if it does not exist
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0){
    texData = new TextureData();
    obj->setObjectData(TEXTUREDATA, texData);
  }

  if ( !texData->textureExists( _textureGroup ) )
    texData->addMultiTexture( _textureGroup );

  // Add the texture
  slotTextureAdded( _name , _filename , 2 , _id);

  // Get the id of the new texture
  _textureId = -1;
181
  _textureId = texData->texture(_name).id();
182

183 184 185
  //hide the texture (its accessible through the multiTexture)
  texData->texture(_name).hidden( true );

186
  QImage textureImage;
Dirk Wilden's avatar
 
Dirk Wilden committed
187 188 189 190

  if ( !getImage(_filename,textureImage) )
    emit log(LOGERR, "Cannot load multiTexture '" + _textureGroup + "'. File not found '" + _filename + "'");

191 192 193 194 195 196 197 198 199 200 201
  texData->texture(_name).textureImage = textureImage;

  // Store the new texture in the list of this textureGroup
  if ( _textureId != -1 ) {
    texData->texture(_textureGroup).multiTextureList << _name ;
  } else {
    emit log(LOGERR,"Error when getting internal id of new multitexture!");
  }

}

Dirk Wilden's avatar
 
Dirk Wilden committed
202
bool TextureControlPlugin::getImage( QString _fileName, QImage& _image ) {
203 204
  QString loadFilename;

205
  if ( _fileName.startsWith("/") || _fileName.startsWith(".") || _fileName.contains(":") )
206 207 208 209 210
    loadFilename = _fileName;
  else
    loadFilename = OpenFlipper::Options::textureDirStr() + QDir::separator() + _fileName;

  if ( !_image.load( loadFilename ) ){
Dirk Wilden's avatar
 
Dirk Wilden committed
211 212
    _image.load(OpenFlipper::Options::textureDirStr() + QDir::separator() + "unknown.png");
    return false;
213 214
  }

Dirk Wilden's avatar
 
Dirk Wilden committed
215
  return true;
216 217 218
}

void TextureControlPlugin::addedEmptyObject( int _id ) {
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
  
  // Get the new object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
    emit log(LOGERR,"Unable to get Object for id " + QString::number(_id) );
    return;
  }
  
  // Check if we support this kind of data
  if ( !obj->dataType(DATA_TRIANGLE_MESH) && !obj->dataType(DATA_POLY_MESH) ) {
    return;
  }
  
  // Get Texture data for this object or create one if it does not exist
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0){
    texData = new TextureData();
    obj->setObjectData(TEXTUREDATA, texData);
  }
  
  // Iterate over all available global textures and add them to the object
  for ( uint i = 0 ; i < globalTextures_.textures().size() ; ++i) {
    
    // ================================================================================
    // Get the image file
    // ================================================================================
    
    QImage textureImage;
    
    if ( !getImage(globalTextures_.textures()[i].filename(),textureImage) )
      emit log(LOGERR, "Cannot load global texture '" + globalTextures_.textures()[i].name() +
      "'. File not found '" + globalTextures_.textures()[i].filename() + "'");
    
    // ================================================================================
    // Add the texture to the texture node and get the corresponding id
    // ================================================================================
    GLuint glName = 0;
    
    //inform textureNode about the new texture
    if( obj->dataType( DATA_TRIANGLE_MESH ) )
      glName = PluginFunctions::triMeshObject(obj)->textureNode()->add_texture(textureImage);
    
    if ( obj->dataType( DATA_POLY_MESH ) )
      glName = PluginFunctions::polyMeshObject(obj)->textureNode()->add_texture(textureImage);
    
    // ================================================================================
    // Store texture information in objects metadata
    // ================================================================================
    if (glName != 0) {
      texData->addTexture(globalTextures_.textures()[i], glName);
      texData->setImage(globalTextures_.textures()[i].name(),textureImage);
    }
    else {
      emit log(LOGERR,"Unable to bind Texture");
      continue;
    }
    
    
    // ================================================================================
    // Update texture mapping in meshNode
    // ================================================================================
    if( obj->dataType( DATA_TRIANGLE_MESH ) ){
      PluginFunctions::triMeshObject(obj)->meshNode()->setTextureMap( 0 );
    }
    
    if ( obj->dataType( DATA_POLY_MESH ) ){
      PluginFunctions::polyMeshObject(obj)->meshNode()->setTextureMap( 0 );
    }
    
  }
Jan Möbius's avatar
 
Jan Möbius committed
289 290
}

291
template< typename MeshT >
Jan Möbius's avatar
Jan Möbius committed
292
void TextureControlPlugin::handleFileOpenTextures( MeshT*& _mesh , int _objectId ) {
293

294 295 296 297 298 299
  // Get the new object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _objectId , obj ) ) {
    return;
  }

300 301 302
  // ================================================================================
  // Create a backup of the original per Vertex texture Coordinates
  // ================================================================================
303
  
304 305 306 307 308 309 310 311 312 313 314 315 316
  if ( _mesh->has_vertex_texcoords2D() ){
  
    OpenMesh::VPropHandleT< typename MeshT::TexCoord2D > oldVertexCoords;
    if ( !_mesh->get_property_handle(oldVertexCoords,"Original Per Vertex Texture Coords") )
      _mesh->add_property(oldVertexCoords,"Original Per Vertex Texture Coords");
    
    for ( TriMesh::VertexIter v_it = _mesh->vertices_begin(); v_it != _mesh->vertices_end(); ++v_it)
      _mesh->property(oldVertexCoords, v_it ) =  _mesh->texcoord2D( v_it );

    slotTextureAdded("Original Per Vertex Texture Coords","unknown.png",2,_objectId);
    slotSetTextureMode("Original Per Vertex Texture Coords","type=vertexbased",_objectId);
  }
  
317 318 319
  // ================================================================================
  // Create a backup of the original per Face texture Coordinates
  // ================================================================================
320
  
321 322 323 324 325 326 327 328 329 330 331 332
  if ( _mesh->has_halfedge_texcoords2D() ){
    
    OpenMesh::HPropHandleT< typename MeshT::TexCoord2D > oldHalfedgeCoords;
    if ( !_mesh->get_property_handle(oldHalfedgeCoords,"Original Per Face Texture Coords") )
      _mesh->add_property(oldHalfedgeCoords,"Original Per Face Texture Coords");
    
    for ( TriMesh::HalfedgeIter he_it = _mesh->halfedges_begin(); he_it != _mesh->halfedges_end(); ++he_it)
      _mesh->property(oldHalfedgeCoords, he_it ) =  _mesh->texcoord2D( he_it );

    slotTextureAdded("Original Per Face Texture Coords","unknown.png",2,_objectId);
    slotSetTextureMode("Original Per Face Texture Coords","type=halfedgebased",_objectId);
  }
333

334 335
}

336
void TextureControlPlugin::fileOpened( int _id ) {
337
  // TODO:: Store original texture coords in a new property!
Jan Möbius's avatar
Jan Möbius committed
338

339 340 341 342
  // Get the new object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
    emit log(LOGERR,"Unable to get Object for id " + QString::number(_id) );
343
    return;
344 345 346 347 348
  }

  // Check if we support this kind of data
  if ( !obj->dataType(DATA_TRIANGLE_MESH) && !obj->dataType(DATA_POLY_MESH) ) {
      return;
349 350
  }

351 352 353
  // Get Texture data for this object or create one if it does not exist
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0){
354 355
    emit log(LOGERR,tr("fileOpened: Unable to get texture object data for id %1.").arg(_id) );
    return;
Jan Möbius's avatar
 
Jan Möbius committed
356
  }
357 358 359 360 361

  // Check if the file contains a texture map, store original textures and handle them before adding global textures
  if( obj->dataType( DATA_TRIANGLE_MESH ) ) {
    TriMesh* mesh = PluginFunctions::triMesh(obj);
    if ( mesh )
Jan Möbius's avatar
Jan Möbius committed
362
      handleFileOpenTextures(mesh,_id);
363 364 365
  } else if ( obj->dataType( DATA_POLY_MESH ) ) {
    PolyMesh* mesh = PluginFunctions::polyMesh(obj);
    if ( mesh )
Jan Möbius's avatar
Jan Möbius committed
366
      handleFileOpenTextures(mesh,_id);
367 368
  }

369 370
}

371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
void TextureControlPlugin::slotTextureChangeImage( QString _textureName , QImage& _image , int _id ) {

  // ================================================================================
  // Get the new object
  // ================================================================================
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
    emit log(LOGERR,"Unable to get Object for id " + QString::number(_id) );
  }

  // ================================================================================
  // Get Texture data for this object
  // ================================================================================
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );

  if ( texData == 0 || ( !texData->textureExists(_textureName))  ) {
    emit log(LOGERR,"Texture does not exist: " + _textureName + " (objectid=" + QString::number(_id) + ")");
    return;
  }

  // ================================================================================
  // Update the image
  // ================================================================================
  Texture& texture = texData->texture(_textureName);
  texture.textureImage = _image;

  // ================================================================================
  // Flag dirty or update
  // ================================================================================

401 402 403 404 405 406 407
  if( obj->dataType( DATA_TRIANGLE_MESH ) ) {
    PluginFunctions::triMeshObject(obj)->textureNode()->set_texture( _image , texData->texture(_textureName).glName());
  } else if ( obj->dataType( DATA_POLY_MESH ) ) {
    PluginFunctions::triMeshObject(obj)->textureNode()->set_texture( _image , texData->texture(_textureName).glName());
  }

  emit updateView();
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437

}

void TextureControlPlugin::slotTextureChangeImage( QString _textureName , QImage& _image ) {

  // ================================================================================
  // Update texture Image for global textures
  // ================================================================================
  if ( ! globalTextures_.textureExists(_textureName) ) {
    emit log(LOGERR,"Global texture does not exist: " + _textureName);
    return;
  }

  // ================================================================================
  // Update the image in the global texture
  // ================================================================================
  Texture& texture = globalTextures_.texture(_textureName);
  texture.textureImage = _image;

  // ================================================================================
  // check if the local textures need to be updated
  // ================================================================================
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it){

    TextureData* texData = dynamic_cast< TextureData* > ( o_it->objectData(TEXTUREDATA) );
    if (texData != 0)
      if ( texData->textureExists(_textureName) ){
        Texture& localTex = texData->texture(_textureName);
        localTex.textureImage = _image;

438 439 440 441 442
          if( o_it->dataType( DATA_TRIANGLE_MESH ) ) {
            PluginFunctions::triMeshObject(o_it)->textureNode()->set_texture( _image , texData->texture(_textureName).glName());
          } else if ( o_it->dataType( DATA_POLY_MESH ) ) {
            PluginFunctions::triMeshObject(o_it)->textureNode()->set_texture( _image , texData->texture(_textureName).glName());
          }
443 444 445
      }
  }

446 447
  emit updateView();

448 449
}

450 451 452 453 454 455 456 457 458 459 460 461 462
void TextureControlPlugin::slotTextureGetImage( QString _textureName, QImage& _image, int _id ){
  
  // Get the object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
    emit log(LOGERR,"Unable to get Object for id " + QString::number(_id) );
  }

  // ================================================================================
  // Get Texture data for current object
  // ================================================================================
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0) {
463
    emit log(LOGERR, tr("slotTextureGetImage: Object has no texture data! Object: %1").arg(_id) );
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
    return;
  }

  // ================================================================================
  // Check for requested Texture
  // ================================================================================
  if ( !texData->textureExists(_textureName) ) {
    emit log(LOGERR, "Texture not available! " + _textureName );
    return;
  }

  if ( texData->texture(_textureName).type() == MULTITEXTURE )
    _image = QImage();
  else
    _image = texData->texture(_textureName).textureImage;
}

void TextureControlPlugin::slotTextureGetImage( QString _textureName, QImage& _image ){
  
  if ( ! globalTextures_.textureExists(_textureName) ) {
    emit log(LOGERR,"Global texture does not exist: " + _textureName);
    return;
  }

  if ( globalTextures_.texture(_textureName).type() == MULTITEXTURE )
    _image = QImage();
  else
    _image = globalTextures_.texture(_textureName).textureImage;
}

494 495 496 497 498 499 500 501 502 503 504 505 506
void TextureControlPlugin::slotTextureIndex( QString _textureName, int _id, int& _index){
  
  // Get the object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
    emit log(LOGERR,"Unable to get Object for id " + QString::number(_id) );
  }

  // ================================================================================
  // Get Texture data for current object
  // ================================================================================
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0) {
507
    emit log(LOGERR, tr("slotTextureIndex: Object has no texture data! Object: %1").arg(_id) );
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
    return;
  }

  // ================================================================================
  // Check for requested Texture
  // ================================================================================
  if ( !texData->textureExists(_textureName) ) {
    emit log(LOGERR, "Texture not available! " + _textureName );
    return;
  }

  _index = texData->texture(_textureName).id();
}

void TextureControlPlugin::slotTextureName( int _id, int _textureIndex, QString& _textureName){
  
  // Get the object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
    emit log(LOGERR,"Unable to get Object for id " + QString::number(_id) );
  }

  // ================================================================================
  // Get Texture data for current object
  // ================================================================================
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0) {
535
    emit log(LOGERR, tr("slotTextureName: Object has no texture data! Object: %1").arg(_id) );
536 537 538 539 540 541 542 543 544 545 546 547 548 549
    return;
  }

  for (uint i=0; i < texData->textures().size(); i++ )
    if ( (texData->textures()[i]).id() == _textureIndex ){
      _textureName = (texData->textures()[i]).name();
      return;
    }

  emit log(LOGERR, "TextureIndex not available! (" + QString::number(_textureIndex) + ")" );
  _textureName = "NOT_FOUND";
  return;
}

550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
void TextureControlPlugin::slotTextureFilename( int _id, QString _textureName, QString& _textureFilename){
  
  // Get the object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
    emit log(LOGERR,"Unable to get Object for id " + QString::number(_id) );
  }

  // ================================================================================
  // Get Texture data for current object
  // ================================================================================
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0) {
    emit log(LOGERR, tr("slotTextureName: Object has no texture data! Object: %1").arg(_id) );
    return;
  }

  // Search in local textures
  for (uint i=0; i < texData->textures().size(); i++ ) {
      for (int j=0; j < texData->textures()[i].multiTextureList.size(); j++ ) {
          if ( (texData->textures()[i]).name() == _textureName ){
              Texture& tex = texData->texture((texData->textures()[i]).name());
              _textureFilename = tex.filename();
              return;
          } else if ( (texData->textures()[i]).multiTextureList[j] == _textureName ){
              Texture& tex = texData->texture((texData->textures()[i]).multiTextureList[j]);
              _textureFilename = tex.filename();
              return;
          }
      }
  }
  
  _textureFilename = OpenFlipper::Options::textureDir().path() + 
      QDir::separator().toAscii() + (globalTextures_.texture(_textureName)).filename();
  
  QFile f(_textureFilename);
  if(!f.exists()) _textureFilename = "NOT_FOUND";
  
  return;
}

591 592
void TextureControlPlugin::slotGetCurrentTexture( int _id, QString& _textureName ){
  
Dirk Wilden's avatar
Dirk Wilden committed
593 594
  _textureName = "NONE";
  
595 596 597 598 599 600 601 602 603 604
  // Get the object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
    emit log(LOGERR,"Unable to get Object for id " + QString::number(_id) );
  }

  // ================================================================================
  // Get Texture data for current object
  // ================================================================================
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
605 606 607 608 609 610 611 612 613 614 615 616 617
  if (texData == 0) {
    #ifndef NDEBUG
    std::cerr << "slotGetCurrentTexture: No Texture Data! "<< obj->getPerObjectDataMap().size() << std::endl;
    
      // Iterate over all per Object datas and output them
      QMap<QString, PerObjectData*>::const_iterator mapIter = obj->getPerObjectDataMap().begin();  
      while ( mapIter != obj->getPerObjectDataMap().end() ) {
        std::cerr << "Available Texture Data: " << mapIter.key().toStdString() << std::endl;
        
        mapIter++;
      }
    #endif
    
618
    return;
619
  }
620 621
  
  // Iterate over all available textures
622 623
  for ( uint i = 0 ; i < texData->textures().size() ; ++i) {
  
624 625 626
    if ( (texData->textures()[i]).enabled() ){
      _textureName = (texData->textures()[i]).name();
      
627
      if ( (texData->textures()[i]).type() == MULTITEXTURE ) {
628
        return;
629
      }
630
    }
631
  }
632 633 634 635 636 637 638 639 640 641 642 643 644 645
}

void TextureControlPlugin::slotGetSubTextures( int _id, QString _multiTextureName, QStringList& _subTextures ){
  // Get the object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
    emit log(LOGERR,"Unable to get Object for id " + QString::number(_id) );
  }

  // ================================================================================
  // Get Texture data for current object
  // ================================================================================
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0) {
646
    emit log(LOGERR, tr("slotGetSubTextures: Object has no texture data! Object: %1").arg(_id) );
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664
    return;
  }

  // ================================================================================
  // Check for requested Texture
  // ================================================================================
  if ( !texData->textureExists(_multiTextureName) ) {
    emit log(LOGERR, "Texture not available! " + _multiTextureName );
    return;
  }
  
  if ( texData->texture(_multiTextureName).type() == MULTITEXTURE )
    _subTextures = texData->texture(_multiTextureName).multiTextureList;
  else
    _subTextures = QStringList();
}

void TextureControlPlugin::slotTextureUpdated( QString _textureName , int _identifier ){
665

666 667 668 669 670 671
  // ================================================================================
  // Get updated object
  // ================================================================================
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _identifier , obj ) ) {
    emit log(LOGERR,"Unable to get Object for id " + QString::number(_identifier) );
Jan Möbius's avatar
 
Jan Möbius committed
672 673
    return;
  }
674

675 676 677 678
  //skip object if its not a mesh
  if( !obj->dataType( DATA_TRIANGLE_MESH ) && !obj->dataType( DATA_POLY_MESH ) )
    return;

679 680 681 682 683
  // ================================================================================
  // Get objects texture data and verify that texture exists
  // ================================================================================
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0){
684
    emit log(LOGERR,tr("slotTextureUpdated: Texture data not found: Object %1" ).arg(_identifier) );
Jan Möbius's avatar
 
Jan Möbius committed
685
    return;
686
  }
Jan Möbius's avatar
 
Jan Möbius committed
687

688 689 690
  // ================================================================================
  // Check if texture exists
  // ================================================================================
691
  if ( ! texData->textureExists(_textureName) ) {
692
    emit log(LOGERR,"Texture " + _textureName + " not found on object " + QString::number(_identifier) );
693
    return;
694
  }
Jan Möbius's avatar
 
Jan Möbius committed
695

696 697 698
  // ================================================================================
  // If texture is not enabled, mark it as dirty and defer update to visualization update
  // ================================================================================
699
  if ( ! texData->texture(_textureName).enabled() ) {
700
    texData->texture(_textureName).setDirty();
701 702
    return;
  }
Jan Möbius's avatar
 
Jan Möbius committed
703

704
  // ================================================================================
705
  // Enable the texture in texture node
706 707 708 709
  // ================================================================================
  if( obj->dataType( DATA_TRIANGLE_MESH ) ) {
    TriMesh* mesh = PluginFunctions::triMesh(obj);
    doUpdateTexture(texData->texture(_textureName), *mesh);
710 711 712
    // Texture has been bound to that object by slotAddTexture.. directly or by fileOpened from global texture
    // Just activate it
    PluginFunctions::triMeshObject(obj)->textureNode()->activateTexture(texData->texture(_textureName).glName() );
713 714 715 716
    PluginFunctions::triMeshObject(obj)->textureNode()->set_repeat(texData->texture(_textureName).parameters.repeat);
  } else if ( obj->dataType( DATA_POLY_MESH ) ) {
    PolyMesh* mesh = PluginFunctions::polyMesh(obj);
    doUpdateTexture(texData->texture(_textureName), *mesh);
717 718 719
    // Texture has been bound to that object by slotAddTexture.. directly or by fileOpened from global texture
    // Just activate it
    PluginFunctions::polyMeshObject(obj)->textureNode()->activateTexture(texData->texture(_textureName).glName() );
720
    PluginFunctions::polyMeshObject(obj)->textureNode()->set_repeat(texData->texture(_textureName).parameters.repeat);
721
  }
Jan Möbius's avatar
 
Jan Möbius committed
722

723 724 725
  // ================================================================================
  // Mark texture as not dirty
  // ================================================================================
726
  texData->texture(_textureName).clean();
Jan Möbius's avatar
 
Jan Möbius committed
727

728 729 730
  // ================================================================================
  // Enable the right draw mode and update
  // ================================================================================
731
  switchDrawMode( texData->texture( _textureName ).type() );
Jan Möbius's avatar
 
Jan Möbius committed
732 733
}

734 735 736 737 738 739
void TextureControlPlugin::slotUpdateTexture( QString _textureName , int _identifier) {
  if ( _textureName == "Reflection Lines" )
    slotTextureUpdated( _textureName , _identifier );

}

Jan Möbius's avatar
 
Jan Möbius committed
740
template< typename MeshT >
741
void TextureControlPlugin::doUpdateTexture ( Texture& _texture, MeshT& _mesh )
Jan Möbius's avatar
 
Jan Möbius committed
742
{
743

744
  if ( _texture.type() == HALFEDGEBASED ) {
745
    if (_texture.dimension() == 1) {
Jan Möbius's avatar
 
Jan Möbius committed
746 747

      OpenMesh::HPropHandleT< double > texture;
748 749
      if ( ! _mesh.get_property_handle(texture, _texture.name().toStdString() ) ) {
        emit log(LOGERR,tr("HALFEDGEBASED dimension 1: Unable to get property %1").arg(_texture.name()) );
Jan Möbius's avatar
 
Jan Möbius committed
750 751 752
        return;
      }

753
      copyTexture(_texture, _mesh, texture);
Jan Möbius's avatar
 
Jan Möbius committed
754

755
    } else if ( _texture.dimension() == 2 ) {
Jan Möbius's avatar
 
Jan Möbius committed
756 757

      OpenMesh::HPropHandleT< OpenMesh::Vec2d > texture2D;
758 759
      if ( ! _mesh.get_property_handle( texture2D, _texture.name().toStdString() ) ) {
        emit log(LOGERR,tr("HALFEDGEBASED dimension 2: Unable to get property %1").arg(_texture.name()) );
Jan Möbius's avatar
 
Jan Möbius committed
760 761 762
        return;
      }

763
      copyTexture( _texture, _mesh, texture2D);
Jan Möbius's avatar
 
Jan Möbius committed
764

765
    } else
766
      emit log(LOGERR, "Unsupported Texture Dimension " + QString::number(_texture.dimension() ) );
767
  } else if ( _texture.type() == VERTEXBASED ) {
768
    if ( _texture.dimension() == 1 ) {
Jan Möbius's avatar
 
Jan Möbius committed
769 770

      OpenMesh::VPropHandleT< double > texture;
771 772
      if ( ! _mesh.get_property_handle(texture,_texture.name().toStdString() ) ) {
        emit log(LOGERR,tr("VERTEXBASED dimension 1: Unable to get property %1").arg(_texture.name()) );
773
        return;
Jan Möbius's avatar
 
Jan Möbius committed
774 775
      }

776
        copyTexture(_texture, _mesh, texture);
Jan Möbius's avatar
 
Jan Möbius committed
777

778
      } else if ( _texture.dimension() == 2 ) {
Jan Möbius's avatar
 
Jan Möbius committed
779 780

        OpenMesh::VPropHandleT< OpenMesh::Vec2d >  texture2D;
781 782
        if ( ! _mesh.get_property_handle(texture2D,_texture.name().toStdString() ) ) {
          emit log(LOGERR,tr("VERTEXBASED dimension 2: Unable to get property %1").arg(_texture.name()) );
783
          return;
Jan Möbius's avatar
 
Jan Möbius committed
784 785
        }

786
        copyTexture( _texture, _mesh, texture2D);
Jan Möbius's avatar
 
Jan Möbius committed
787 788

      } /*else if ( textures_[_textureid].dimension == 3 ) {
789

Jan Möbius's avatar
 
Jan Möbius committed
790
        OpenMesh::VPropHandleT< OpenMesh::Vec3d >  scalarField3D;
791 792
        if ( ! _mesh.get_property_handle(scalarField3D,_texture.name) ) {
          emit log(LOGERR,"Unable to get property " + _texture.name );
793
          return;
Jan Möbius's avatar
 
Jan Möbius committed
794
        }
795

Jan Möbius's avatar
 
Jan Möbius committed
796
        copyTexture(_textureid, _mesh, scalarField3D);
797

Jan Möbius's avatar
 
Jan Möbius committed
798
      }*/ else
799
        emit log(LOGERR, "Unsupported Texture Dimension " + QString::number(_texture.dimension() ) );
800

Jan Möbius's avatar
 
Jan Möbius committed
801 802
    } else
      emit log(LOGERR, "Unsupported Texture type");
803

Jan Möbius's avatar
 
Jan Möbius committed
804 805
}

806 807 808 809
void TextureControlPlugin::computeValue(Texture& _texture, double _min, double _max, double& _value) {
   const bool clamp         = _texture.parameters.clamp ;
   const bool center        = _texture.parameters.center;
   const double max_val     = _texture.parameters.max_val;
810
   const double min_val     = _texture.parameters.min_val;
811 812 813 814 815 816
   const bool abs           = _texture.parameters.abs;
   const double clamp_max   = _texture.parameters.clamp_max;
   const double clamp_min   = _texture.parameters.clamp_min;
   const bool scale         = _texture.parameters.scale;
   const double scaleFactor = fabs(_max) + fabs(_min);
   const bool repeat        = _texture.parameters.repeat;
817

Jan Möbius's avatar
 
Jan Möbius committed
818 819 820
   // Use absolute value as requested by plugin
   if ( abs )
      _value = fabs(_value);
821

Jan Möbius's avatar
 
Jan Möbius committed
822 823 824 825 826 827 828
   // Clamp if requested
   if ( clamp ) {
      if ( _value > clamp_max )
         _value = clamp_max;
      if (_value < clamp_min)
         _value = clamp_min;
   }
829

Dirk Wilden's avatar
Dirk Wilden committed
830 831 832 833 834 835 836 837 838 839 840
   // if all texCoords have the same value
   if ( _min == _max ){

      if ( ! repeat )
        _value = 0.0;
      else
        _value = max_val;

     return;
   }

Jan Möbius's avatar
 
Jan Möbius committed
841 842 843
   // if the texture should not be repeated, scale to 0..1
   if ( ! repeat ) {
      if (! center ) {
844
        if ( scale) {
Dirk Wilden's avatar
Dirk Wilden committed
845
          _value /= scaleFactor; //scaleFactor is != 0.0 (otherwise _min==_max)
846
          _value -= _min/scaleFactor;
Jan Möbius's avatar
 
Jan Möbius committed
847 848 849 850
        }
      } else {
         // the values above zero are mapped to 0.5..1 the negative ones to 0.5..0
         if (_value > 0.0) {
Dirk Wilden's avatar
Dirk Wilden committed
851
            _value /= ( _max * 2.0); //_max >= _value > 0.0
Jan Möbius's avatar
 
Jan Möbius committed
852 853
            _value += 0.5;
         } else {
Dirk Wilden's avatar
Dirk Wilden committed
854 855 856 857 858 859
            if ( _min == 0.0 ){
              _value = 0.0;
            } else {
              _value /= ( _min * 2.0);
              _value = 0.5 - _value;
            }
Jan Möbius's avatar
 
Jan Möbius committed
860 861 862 863
         }
      }
   } else {
      _value -= _min;
864 865
      _value *= (max_val - min_val) / (_max - _min);
      _value += min_val;
Jan Möbius's avatar
 
Jan Möbius committed
866 867 868
   }
}

869
void TextureControlPlugin::slotObjectUpdated(int _identifier, const UpdateType _type)
870 871 872 873
{  
    if( !_type.contains(UPDATE_ALL) && !_type.contains(UPDATE_GEOMETRY) && !_type.contains(UPDATE_TOPOLOGY) )
        return;
    
874 875 876 877 878
  // ================================================================================
  // Get updated object
  // ================================================================================
  if ( _identifier == -1 )
    return;
879

880
  BaseObjectData* obj;
881
  if (! PluginFunctions::getObject(  _identifier , obj ) )
882 883
    return;

884 885 886 887
  //skip object if its not a mesh
  if( !obj->dataType( DATA_TRIANGLE_MESH ) && !obj->dataType( DATA_POLY_MESH ) )
    return;

888 889 890 891 892 893 894 895 896 897 898 899 900
  // ================================================================================
  // Get objects texture data and verify that texture exists
  // ================================================================================
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
  if (texData == 0){
    return;
  }

  // ================================================================================
  // Set all textures to dirty
  // ================================================================================
  // TODO : if not in the texture rendering mode, do not emit update
  // Involves adding a interface part to react on draw mode changes
901
  // basic check implemented
902
  for ( uint i = 0; i < texData->textures().size(); ++i ) {
903
    texData->textures()[i].setDirty();
904 905 906 907 908 909 910

    bool update = false;
    for ( int j = 0 ; j < PluginFunctions::viewers() ; ++j ) {
       update |= ( PluginFunctions::drawMode(j) == ACG::SceneGraph::DrawModes::SOLID_TEXTURED );
       update |= ( PluginFunctions::drawMode(j) == ACG::SceneGraph::DrawModes::SOLID_TEXTURED_SHADED );
    }

911
    if ( update && texData->textures()[i].enabled() )
912
      emit updateTexture( texData->textures()[i].name() , _identifier );
913
  }
914

Jan Möbius's avatar
 
Jan Möbius committed
915 916 917
}

void TextureControlPlugin::slotUpdateAllTextures( ) {
918 919 920 921 922 923
  std::cerr << "slotUpdateAllTextures: not implemented yet ... might be removed" << std::endl;
  // TODO : Check
//    // Force an update of all textures which are available for the updated object
//    for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it)
//       for ( uint i = 0 ; i < textures_.size() ; ++i )
//          emit updateTexture( textures_[i].name , o_it->id() );
Jan Möbius's avatar
 
Jan Möbius committed
924 925
}

926
bool TextureControlPlugin::parseMode( QString _mode, Texture& _texture ) {
927

928
  bool changed = false;
929

930 931 932 933 934 935
  int i = 0;
  QString nextString = _mode.section(',',i,i);
  while ( nextString != "" ) {
    QString sectionName = nextString.section('=',0,0);
    QString value = nextString.section('=',1,1);

936 937 938
    // Cleanup representation
    value       = value.trimmed();
    sectionName = sectionName.trimmed();
Jan Möbius's avatar
Jan Möbius committed
939
    sectionName = sectionName.toLower();
940

941
    if ( sectionName == "clamp" ) {
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960
      if ( StringToBool(value) != _texture.parameters.clamp ) {
        _texture.parameters.clamp = StringToBool(value);
        changed = true;
      }
    } else if ( sectionName == "clamp_max" ) {
      if (value.toDouble() != _texture.parameters.clamp_max){
        _texture.parameters.clamp_max = value.toDouble();
        changed = true;
      }
    } else if ( sectionName == "clamp_min" ) {
      if (value.toDouble() != _texture.parameters.clamp_min){
        _texture.parameters.clamp_min = value.toDouble();
        changed = true;
      }
    } else if ( sectionName == "max_val" ) {
      if (value.toDouble() != _texture.parameters.max_val){
        _texture.parameters.max_val = value.toDouble();
        changed = true;
      }
961 962 963 964 965
    } else if ( sectionName == "min_val" ) {
      if (value.toDouble() != _texture.parameters.min_val){
        _texture.parameters.min_val = value.toDouble();
        changed = true;
      }
966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
    } else if ( sectionName == "repeat" ) {
      if ( StringToBool(value) != _texture.parameters.repeat ) {
        _texture.parameters.repeat = StringToBool(value);
        changed = true;
      }
    } else if ( sectionName == "center" ) {
      if ( StringToBool(value) != _texture.parameters.center ) {
        _texture.parameters.center = StringToBool(value);
        changed = true;
      }
    } else if ( sectionName == "scale" ) {
      if ( StringToBool(value) != _texture.parameters.scale ) {
        _texture.parameters.scale = StringToBool(value);
        changed = true;
      }
Jan Möbius's avatar
Jan Möbius committed
981
    }else if ( sectionName == "indexproperty" ) {
982 983 984 985
      if ( value != _texture.indexMappingProperty() ) {
        _texture.indexMappingProperty( value );
        changed = true;
      }
986 987 988 989 990
    }else if ( sectionName == "visiblename" ) {
      if ( value != _texture.visibleName() ) {
        _texture.visibleName( value );
        changed = true;
      }
991 992 993 994 995 996 997
    } else if ( sectionName == "type" ) {
        if ( ( value == "halfedgebased" ) && ( _texture.type() != HALFEDGEBASED ) ) {
          _texture.type( HALFEDGEBASED );
          changed = true;
        } else if ( (value == "vertexbased") && (_texture.type() != HALFEDGEBASED)  ) {
          _texture.type( VERTEXBASED );
          changed = true;
Jan Möbius's avatar
Jan Möbius committed
998 999 1000
        }  else if ( (value == "environmentmap") && (_texture.type() != ENVIRONMENT)  ) {
          _texture.type( ENVIRONMENT );
          changed = true;
1001 1002
        } else {
          emit log(LOGERR,"Unknown texture type : " + value + " for texture: " + _texture.name() );
1003 1004 1005
        }
    } else
      emit log(LOGERR,"Unknown texture mode : " + sectionName);
1006

1007 1008 1009
    ++i;
    nextString = _mode.section(',',i,i);
  }
1010

1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
  return changed;
}

void TextureControlPlugin::slotSetTextureMode(QString _textureName ,QString _mode) {

  // ================================================================================
  // Update texture settings for global textures
  // ================================================================================
  if ( ! globalTextures_.textureExists(_textureName) ) {
    emit log(LOGERR,"Global texture does not exist: " + _textureName);
    return;
  }

  // ================================================================================
  // Parse parameters and update them in the texture data
  // ================================================================================
  Texture& texture = globalTextures_.texture(_textureName);

  // Parse the mode settings
  parseMode(_mode,texture);
Jan Möbius's avatar
Jan Möbius committed
1031
  _mode = _mode.toLower();
1032

1033 1034 1035
  // ================================================================================
  // Mark updated texture as dirty
  // ================================================================================
1036
  texture.setDirty();
1037

1038

Dirk Wilden's avatar
Dirk Wilden committed
1039 1040 1041 1042
  // check if the local textures need to be updated
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it){

    TextureData* texData = dynamic_cast< TextureData* > ( o_it->objectData(TEXTUREDATA) );
1043

Dirk Wilden's avatar
Dirk Wilden committed
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071
    if (texData != 0){

      if ( texData->textureExists(_textureName) ){

        Texture& localTex = texData->texture(_textureName);

        //check if something changed
        bool changed = false;

        if ( _mode.contains("clamp") && (texture.parameters.clamp != localTex.parameters.clamp) ){
          localTex.parameters.clamp = texture.parameters.clamp;
          changed = true;
        }

        if ( _mode.contains("clamp_max") && (texture.parameters.clamp_max != localTex.parameters.clamp_max) ){
          localTex.parameters.clamp_max = texture.parameters.clamp_max;
          changed = true;
        }

        if ( _mode.contains("clamp_min") && (texture.parameters.clamp_min != localTex.parameters.clamp_min) ){
          localTex.parameters.clamp_min = texture.parameters.clamp_min;
          changed = true;
        }

        if ( _mode.contains("max_val") && (texture.parameters.max_val != localTex.parameters.max_val) ){
          localTex.parameters.max_val = texture.parameters.max_val;
          changed = true;
        }
1072 1073 1074 1075 1076
        
        if ( _mode.contains("min_val") && (texture.parameters.min_val != localTex.parameters.min_val) ){
          localTex.parameters.min_val = texture.parameters.min_val;
          changed = true;
        }
Dirk Wilden's avatar
Dirk Wilden committed
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092

        if ( _mode.contains("repeat") && (texture.parameters.repeat != localTex.parameters.repeat) ){
          localTex.parameters.repeat = texture.parameters.repeat;
          changed = true;
        }

        if ( _mode.contains("center") && (texture.parameters.center != localTex.parameters.center) ){
          localTex.parameters.center = texture.parameters.center;
          changed = true;
        }

        if ( _mode.contains("scale") && (texture.parameters.scale != localTex.parameters.scale) ){
          localTex.parameters.scale = texture.parameters.scale;
          changed = true;
        }

1093 1094
        if ( _mode.contains("type") && (texture.type() != localTex.type() ) ){
          localTex.type( texture.type() );
Dirk Wilden's avatar
Dirk Wilden committed
1095 1096 1097
          changed = true;
        }

1098 1099 1100 1101 1102
        if ( _mode.contains("visiblename") && (texture.visibleName() != localTex.visibleName() ) ){
          localTex.visibleName( texture.visibleName() );
          changed = true;
        }

Dirk Wilden's avatar
Dirk Wilden committed
1103 1104 1105 1106 1107
        //only update if the texture is enabled
        if (changed){
          if ( texData->isEnabled(_textureName) )
            emit updateTexture( _textureName, o_it->id() );
          else
1108
            localTex.setDirty();
Dirk Wilden's avatar
Dirk Wilden committed
1109 1110 1111 1112
        }
      }
    }
  }
Jan Möbius's avatar
 
Jan Möbius committed
1113 1114
}

Dirk Wilden's avatar
Dirk Wilden committed
1115 1116 1117 1118 1119 1120 1121
bool TextureControlPlugin::StringToBool(QString _value){
  if (_value == "false")
    return false;
  else
    return true;
}

Dirk Wilden's avatar
Dirk Wilden committed
1122
void TextureControlPlugin::slotSetTextureMode(QString _textureName, QString _mode, int _id) {
Dirk Wilden's avatar
Dirk Wilden committed
1123

Dirk Wilden's avatar
Dirk Wilden committed
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
  // Get the new object
  BaseObjectData* obj;
  if (! PluginFunctions::getObject(  _id , obj ) ) {
    emit log(LOGERR,"Unable to get Object for id " + QString::number(_id) );
  }

  // Get Texture data for this object
  TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );

  if ( texData == 0 || ( !texData->textureExists(_textureName))  ) {
    emit log(LOGERR,"Texture does not exist: " + _textureName + " (object=" + QString::number(_id) + ")");
    return;
  }

  // ================================================================================
  // Parse parameters and update them in the texture data
  // ================================================================================
  Texture& texture = texData->texture(_textureName);

Jan Möbius's avatar
Jan Möbius committed
1143

1144
  bool changed = parseMode(_mode,texture);