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

Updates to MeshObject for futere texture support

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@4611 383ad7c9-94d9-4d36-a494-682f7c89f535
parent c3a00866
......@@ -449,29 +449,59 @@
template < class MeshT , DataType objectDataType >
void MeshObject< MeshT , objectDataType >::addTexture(QImage& _image , int _id )
void MeshObject< MeshT , objectDataType >::addTexture(QString _name , QImage& _image , int _id )
{
if ( _id == -1 )
std::cerr << "This texture has no id from the mesh!!!!!" << std::endl;
if ( textures_.empty() ) {
std::cerr << "No texture set." << std::endl;
}
for ( uint i = 0 ; i < textures_.size(); ++i ) {
if ( textures_[i].first == _name ) {
std::cerr << "Texture already exists!! Use setTexture to change a texture. Setting new texture" << std::endl;
setTexture( _name, _image );
return;
}
}
if ( _id >= textures_.size() ) {
std::cerr << "Expanded texture index vector." << std::endl;
textures_.resize(_id + 1,0);
textures_.resize(_id + 1);
}
std::cerr << "Add texture" << std::endl;
textures_[_id] = textureNode_->add_texture(_image);
std::cerr << "Adding texture" << std::endl;
textures_[_id] = std::pair< QString , GLuint >( _name, textureNode_->add_texture(_image) );
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;
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 ) {
for ( uint i = 0 ; i < textures_.size(); ++i ) {
if ( textures_[i].first == _name ) {
std::cerr << "Found Texture, TODO : update" << std::endl;
return;
}
}
std::cerr << "Texture not found in this object" << std::endl;
}
template < class MeshT , DataType objectDataType >
bool MeshObject< MeshT , objectDataType >::textureExists( QString _name ) {
for ( uint i = 0 ; i < textures_.size(); ++i ) {
if ( textures_[i].first == _name )
return true;
}
return false;
}
// ===============================================================================
// Load/Save
......
......@@ -275,16 +275,29 @@ class DLLEXPORT MeshObject : public BaseObjectData {
/** Add a texture to the object.
* @param _image Image to use as texture
* @param _id Id of the texture in the texture_index property of the mesh
* @param _id Id of the texture in the texture_index property of the mesh ( if available
* otherwise -1)
* @param _name Name of the texture. Required to access the texture
*/
void addTexture( QImage& _image , int _id );
void addTexture( QString _name , QImage& _image , int _id = -1);
/** Change an already loaded texture
*
*/
void setTexture( QString _name , QImage& _image );
/** Checks if a texture already exists
*
*/
bool textureExists( 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
* the mesh has requested a face_index_texture with request_face_texture_index. Additionally
* request_halfedge_texcoords2D has to be used to set per face texture coordinates.
*/
std::vector< GLuint > textures_;
std::vector< std::pair< QString , GLuint > > textures_;
/** @} */
//===========================================================================
......
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