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

Support loading textures through objs

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5745 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 8e45bfe4
......@@ -178,7 +178,7 @@ void TextureControlPlugin::slotMultiTextureAdded( QString _textureGroup , QStrin
void TextureControlPlugin::getImage( QString _fileName, QImage& _image ) {
QString loadFilename;
if ( _fileName.startsWith("/") )
if ( _fileName.startsWith("/") || _fileName.startsWith(".") )
loadFilename = _fileName;
else
loadFilename = OpenFlipper::Options::textureDirStr() + QDir::separator() + _fileName;
......@@ -194,6 +194,44 @@ void TextureControlPlugin::addedEmptyObject( int _id ) {
fileOpened(_id);
}
template< typename MeshT >
void TextureControlPlugin::handleFileOpenTextures( MeshT*& _mesh , int _objectId ) {
// If this property is available we have a mapping between face_index_property and
// available textures stored in the map
OpenMesh::MPropHandleT< std::map< int, std::string > > property;
if ( _mesh->get_property_handle(property,"TextureMapping") ) {
// As internal texture indices might differ from the available ones,
// We have to remap them after loading the textures!
std::map< int,int > newMapping;
// TODO : If only one Texture, use single Texturing mode
if ( true ) {
// Assume multiTexture Mode now and load the Textures
for ( std::map< int, std::string >::iterator texture = _mesh->property(property).begin();
texture != _mesh->property(property).end(); texture++ ) {
int textureId = -1;
slotMultiTextureAdded("OBJ Data",QString(texture->second.c_str()) , QString(texture->second.c_str()), _objectId, textureId );
newMapping[texture->first] = textureId;
}
// Convert the indices stored in the mesh to the actual ones used for rendering
OpenMesh::FPropHandleT< int > newIndexProperty;
if (! _mesh->get_property_handle(newIndexProperty,"TextureControl: OriginalFileIndexMapping") ) {
_mesh->add_property(newIndexProperty,"TextureControl: OriginalFileIndexMapping");
}
for ( TriMesh::FaceIter f_it = _mesh->faces_begin(); f_it != _mesh->faces_end(); ++f_it)
_mesh->property(newIndexProperty, f_it ) = newMapping[_mesh->texture_index( f_it )];
// We use a different property for storing the IndexProperty to prevent overwriting them
slotSetTextureMode("OBJ Data","indexProperty=TextureControl: OriginalFileIndexMapping", _objectId);
std::cerr << "Done" << std::endl;
}
}
}
void TextureControlPlugin::fileOpened( int _id ) {
// TODO:: Store original texture coords in a new property!
......@@ -216,6 +254,17 @@ void TextureControlPlugin::fileOpened( int _id ) {
obj->setObjectData(TEXTUREDATA, texData);
}
// Check if the file contains a texture map and handle it before adding global textures
if( obj->dataType( DATA_TRIANGLE_MESH ) ) {
TriMesh* mesh = PluginFunctions::triMesh(obj);
if ( mesh )
handleFileOpenTextures(mesh,_id);
} else if ( obj->dataType( DATA_POLY_MESH ) ) {
PolyMesh* mesh = PluginFunctions::polyMesh(obj);
if ( mesh )
handleFileOpenTextures(mesh,_id);
}
// Iterate over all available global textures and add them to the object
for ( uint i = 0 ; i < globalTextures_.textures().size() ; ++i) {
......@@ -300,7 +349,7 @@ void TextureControlPlugin::slotTextureUpdated( QString _textureName , int _ident
// If texture is not enabled, mark it as dirty and defer update to visualization update
// ================================================================================
if ( ! texData->texture(_textureName).enabled() ) {
texData->texture(_textureName).dirty = true;
texData->texture(_textureName).setDirty();
return;
}
......@@ -325,7 +374,7 @@ void TextureControlPlugin::slotTextureUpdated( QString _textureName , int _ident
// ================================================================================
// Mark texture as not dirty
// ================================================================================
texData->texture(_textureName).dirty = false;
texData->texture(_textureName).clean();
// ================================================================================
// Enable the right draw mode and update
......@@ -337,7 +386,7 @@ template< typename MeshT >
void TextureControlPlugin::doUpdateTexture ( Texture& _texture, MeshT& _mesh )
{
if ( _texture.type == HALFEDGEBASED ) {
if ( _texture.type() == HALFEDGEBASED ) {
if (_texture.dimension() == 1) {
OpenMesh::HPropHandleT< double > texture;
......@@ -360,7 +409,7 @@ void TextureControlPlugin::doUpdateTexture ( Texture& _texture, MeshT& _mesh )
} else
emit log(LOGERR, "Unsupported Texture Dimension " + QString::number(_texture.dimension() ) );
} else if ( _texture.type == VERTEXBASED ) {
} else if ( _texture.type() == VERTEXBASED ) {
if ( _texture.dimension() == 1 ) {
OpenMesh::VPropHandleT< double > texture;
......@@ -475,7 +524,7 @@ void TextureControlPlugin::slotObjectUpdated(int _identifier)
// Involves adding a interface part to react on draw mode changes
// basic check implemented
for ( uint i = 0; i < texData->textures().size(); ++i ) {
texData->textures()[i].dirty = true;
texData->textures()[i].setDirty();
bool update = false;
for ( int j = 0 ; j < PluginFunctions::viewers() ; ++j ) {
......@@ -542,9 +591,9 @@ void TextureControlPlugin::slotSetTextureMode(QString _textureName ,QString _mod
} else
if ( sectionName == "type" ) {
if (value == "halfedgebased") {
texture.type = HALFEDGEBASED;
texture.type( HALFEDGEBASED );
} else {
texture.type = VERTEXBASED;
texture.type( VERTEXBASED );
}
} else
emit log(LOGERR,"Unknown texture mode : " + sectionName);
......@@ -556,7 +605,7 @@ void TextureControlPlugin::slotSetTextureMode(QString _textureName ,QString _mod
// ================================================================================
// Mark updated texture as dirty
// ================================================================================
texture.dirty = true;
texture.setDirty();
// check if the local textures need to be updated
......@@ -608,8 +657,8 @@ void TextureControlPlugin::slotSetTextureMode(QString _textureName ,QString _mod
changed = true;
}
if ( _mode.contains("type") && (texture.type != localTex.type) ){
localTex.type = texture.type;
if ( _mode.contains("type") && (texture.type() != localTex.type() ) ){
localTex.type( texture.type() );
changed = true;
}
......@@ -618,7 +667,7 @@ void TextureControlPlugin::slotSetTextureMode(QString _textureName ,QString _mod
if ( texData->isEnabled(_textureName) )
emit updateTexture( _textureName, o_it->id() );
else
localTex.dirty = true;
localTex.setDirty();
}
}
}
......@@ -696,12 +745,17 @@ void TextureControlPlugin::slotSetTextureMode(QString _textureName, QString _mod
texture.parameters.scale = StringToBool(value);
changed = true;
}
}else if ( sectionName == "indexProperty" ) {
if ( value != texture.indexMappingProperty() ) {
texture.indexMappingProperty( value );
changed = true;
}
} else if ( sectionName == "type" ) {
if (value == "halfedgebased") {
texture.type = HALFEDGEBASED;
texture.type( HALFEDGEBASED );
changed = true;
} else {
texture.type = VERTEXBASED;
texture.type( VERTEXBASED );
changed = true;
}
} else
......@@ -716,7 +770,7 @@ void TextureControlPlugin::slotSetTextureMode(QString _textureName, QString _mod
if ( texData->isEnabled(_textureName) )
emit updateTexture( _textureName, _id );
else
texture.dirty = true;
texture.setDirty();
}
}
......@@ -780,12 +834,12 @@ void TextureControlPlugin::applyDialogSettings(TextureData* _texData, QString _t
slotTextureUpdated( _textureName , _id );
emit updateView();
}else
_texData->texture( _textureName ).dirty = true;
_texData->texture( _textureName ).setDirty();
} else {
// global texture
_texData->texture( _textureName ).dirty = true;
_texData->texture( _textureName ).setDirty();
Texture& globalTexture = _texData->texture(_textureName);
......@@ -835,7 +889,7 @@ void TextureControlPlugin::applyDialogSettings(TextureData* _texData, QString _t
if ( texData->isEnabled(_textureName) )
slotTextureUpdated( _textureName , o_it->id() );
else
texData->texture( _textureName ).dirty = true;
texData->texture( _textureName ).setDirty();
}
}
}
......@@ -875,7 +929,7 @@ void TextureControlPlugin::doSwitchTexture( QString _textureName , int _id ) {
// ================================================================================
// Enable the given texture exclusively or use multitexture setting
// ================================================================================
bool multiTextureMode = ( texData->texture(_textureName).type == MULTITEXTURE );
bool multiTextureMode = ( texData->texture(_textureName).type() == MULTITEXTURE );
if ( !multiTextureMode ) {
if ( ! texData->enableTexture( _textureName , true ) ) {
emit log(LOGERR, "Failed to enabled Texture " + _textureName );
......@@ -901,7 +955,7 @@ void TextureControlPlugin::doSwitchTexture( QString _textureName , int _id ) {
// which will update the visualization )
// ================================================================================
if ( !multiTextureMode && texData->texture( _textureName).dirty ) {
if ( !multiTextureMode && texData->texture( _textureName).dirty() ) {
// TODO: maybe introduce lock to prevent extra redraws if updating all objects
emit updateTexture( texData->texture( _textureName ).name() , obj->id() );
......@@ -915,9 +969,11 @@ void TextureControlPlugin::doSwitchTexture( QString _textureName , int _id ) {
if (!multiTextureMode) {
doUpdateTexture(texData->texture(_textureName), *PluginFunctions::triMeshObject(obj)->mesh());
PluginFunctions::triMeshObject(obj)->textureNode()->activateTexture( texData->texture( _textureName ).glName() );
PluginFunctions::triMeshObject(obj)->meshNode()->set_index_property_name(0);
PluginFunctions::triMeshObject(obj)->meshNode()->set_texture_map( 0 );
PluginFunctions::triMeshObject(obj)->meshNode()->set_property_map( 0 );
} else {
PluginFunctions::triMeshObject(obj)->meshNode()->set_index_property_name( texData->texture( _textureName ).indexMappingProperty().toStdString() );
PluginFunctions::triMeshObject(obj)->meshNode()->set_texture_map( texData->textureMap() );
PluginFunctions::triMeshObject(obj)->meshNode()->set_property_map( 0 );
}
......@@ -928,9 +984,11 @@ void TextureControlPlugin::doSwitchTexture( QString _textureName , int _id ) {
if (!multiTextureMode) {
doUpdateTexture(texData->texture(_textureName), *PluginFunctions::polyMeshObject(obj)->mesh());
PluginFunctions::polyMeshObject(obj)->textureNode()->activateTexture( texData->texture( _textureName ).glName() );
PluginFunctions::polyMeshObject(obj)->meshNode()->set_index_property_name(0);
PluginFunctions::polyMeshObject(obj)->meshNode()->set_texture_map( 0 );
PluginFunctions::polyMeshObject(obj)->meshNode()->set_property_map( 0 );
} else {
PluginFunctions::polyMeshObject(obj)->meshNode()->set_index_property_name( texData->texture( _textureName ).indexMappingProperty().toStdString() );
PluginFunctions::polyMeshObject(obj)->meshNode()->set_texture_map( texData->textureMap() );
PluginFunctions::polyMeshObject(obj)->meshNode()->set_property_map( 0 );
}
......
......@@ -160,6 +160,10 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me
int _textureid, MeshT& _mesh,
OpenMesh::VPropHandleT< double > _texProp);
/// Handles data stored in new opened files ( e.g. Texture Information )
template< typename MeshT >
void handleFileOpenTextures( MeshT*& _mesh , int _objectId );
//===========================================================================
/** @name 1D Texture copy functions( copy 1D input textures to target texture coordinates and transform values )
* @{ */
......
......@@ -34,14 +34,15 @@
//-----------------------------------------------------------------------------------
Texture::Texture() :
id_(-1),
glName_(0),
name_("No Texture"),
filename_("Invalid"),
id_(-1),
glName_(0),
dimension_(0),
enabled_(false),
dirty(true),
type(UNSET)
dirty_(true),
type_(UNSET),
indexMappingProperty_("f:textureindex")
{
}
......@@ -148,8 +149,8 @@ int TextureData::addTexture(QString _textureName, QString _filename, uint _dimen
tex.filename( _filename );
tex.dimension(_dimension);
tex.enable();
tex.dirty = true;
tex.type = VERTEXBASED;
tex.setDirty();
tex.type( VERTEXBASED );
tex.hidden(false);
// tex.parameters = TexParameters;
......@@ -188,8 +189,8 @@ bool TextureData::addMultiTexture( QString _textureName ) {
tex.id( nextInternalID_++ );
tex.name( _textureName );
tex.filename("MultiTexture");
tex.dirty = true;
tex.type = MULTITEXTURE;
tex.setDirty();
tex.type(MULTITEXTURE);
tex.hidden(false);
textures_.push_back( tex );
......
......@@ -80,63 +80,92 @@ class Texture {
public :
Texture();
void filename( QString _name ) { filename_ = _name; };
QString filename() { return filename_; };
void id( int _id ) { id_ = _id; };
int id() { return id_; };
void glName( GLuint _glName ) { glName_ = _glName; };
GLuint glName() { return glName_; };
void name( QString _name ) { name_ = _name; };
QString name() { return name_; };
void dimension( uint _dimension ) { dimension_ = _dimension; };
uint dimension( ) { return dimension_; };
void enabled( bool _enabled ) { enabled_ = _enabled; };
bool enabled() { return enabled_; };
void hidden( bool _hidden ) { hidden_ = _hidden; };
bool hidden() { return hidden_; };
void enable(){ enabled_ = true; };
void disable(){ enabled_ = false; };
void hidden( bool _hidden ) { hidden_ = _hidden; };
bool hidden() { return hidden_; };
void hide() { hidden_ = true; };
void dirty( bool _dirty ) { dirty_ = _dirty; };
bool dirty() { return dirty_; };
void clean() { dirty_ = false; };
void setDirty() { dirty_ = true; };
// does this texture need an update?
bool dirty;
// Texture Type
uint type;
// Parameters
TexParameters parameters;
void type( uint _type ) { type_ = _type; };
uint type( ) { return type_; };
QImage textureImage;
/// If this is a multiTexture, the list will contain all textures for this multi Texture node.
QStringList multiTextureList;
QString indexMappingProperty() { return indexMappingProperty_; };
void indexMappingProperty( QString _property ) { indexMappingProperty_ = _property; };
/// Parameters of the texture
TexParameters parameters;
/// The image used as the texture
QImage textureImage;
/// If this is a multiTexture, the list will contain all textures for this multi Texture node.
QStringList multiTextureList;
private:
// Filename of the texture
/// Texture Name
QString name_;
/// Filename of the texture
QString filename_;
// Texture id
/// Texture id
int id_;
// glName
/// glName
GLuint glName_;
// Texture Name
QString name_;
// dimension
/// dimension
uint dimension_;
// Status
/// Status
bool enabled_;
/// Hidden flag ( If this texture belongs to a multitexture, it will be hidden in the context menu )
bool hidden_;
/// does this texture need an update?
bool dirty_;
/// Texture Type
uint type_;
/** If this is a multiTexture, indexMappingProperty_ will point to the property storing the mapping
* Defaults to the f:textureindex
*/
QString indexMappingProperty_;
};
class TextureData : public PerObjectData
......
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