Commit 4eb42874 authored by Jan Möbius's avatar Jan Möbius

Fixed some texture related issues (They were loaded but not displayed)

parent 48cbdd97
......@@ -411,13 +411,14 @@ void FileOBJPlugin::createAllGroupObjects(OBJImporter& _importer) {
if (OpenFlipper::Options::gui() && loadOptions_ != 0) {
if (!loadFaceColor_->isChecked())
_importer.objectOptions()[ i ] |= OBJImporter::FORCE_NOCOLOR;
_importer.setOption(OBJImporter::FORCE_NOCOLOR, i);
if (!loadNormals_->isChecked())
_importer.objectOptions()[ i ] |= OBJImporter::FORCE_NONORMALS;
_importer.setOption(OBJImporter::FORCE_NONORMALS, i);
if (!loadTexCoords_->isChecked() || !loadTextures_->isChecked())
_importer.objectOptions()[ i ] |= OBJImporter::FORCE_NOTEXTURES;
_importer.setOption(OBJImporter::FORCE_NOTEXTURES, i);
}
}
}
......@@ -532,9 +533,9 @@ void FileOBJPlugin::addTextures(OBJImporter& _importer, int _objectID ){
QString fullName = _importer.path() + QDir::separator() + options.join(" ");
QFileInfo info(fullName);
if ( info.exists() )
if ( info.exists() ) {
emit addMultiTexture("OBJ Data", info.baseName().trimmed(), fullName, object->id(), textureId );
else {
} else {
emit log(LOGWARN, tr("Unable to load texture image %1").arg( QString(material.map_Kd().c_str()) ) );
addMultiTexture("OBJ Data","Unknown Texture image " + QString::number(textureId), "unknown.png", object->id(), textureId );
}
......@@ -731,9 +732,12 @@ void FileOBJPlugin::readOBJFile(QByteArray& _bufferedFile, QString _filename, OB
Material& mat = _importer.materials()[matname.toStdString()];
if ( mat.has_Texture() ){
//add object if not already there
_importer.useMaterial( matname.toStdString() );
}
}
}
else if (mode == NONE && keyWrd == QLatin1String("v"))
......@@ -1096,7 +1100,7 @@ void FileOBJPlugin::readOBJFile(QByteArray& _bufferedFile, QString _filename, OB
// end
else if (mode == CURVE && keyWrd == QLatin1String("end")){
if ( _importer.isCurve( _importer.currentObject() ) ){
if ( _importer.isCurve( _importer.currentGroup() ) ){
// set up the spline curve
_importer.currentCurve()->set_degree( _importer.degreeU() );
_importer.currentCurve()->autocompute_knotvector(false);
......@@ -1224,7 +1228,7 @@ void FileOBJPlugin::readOBJFile(QByteArray& _bufferedFile, QString _filename, OB
// end
else if (mode == SURFACE && keyWrd == QLatin1String("end")){
if ( _importer.isSurface( _importer.currentObject() ) ){
if ( _importer.isSurface( _importer.currentGroup() ) ){
// remove first 4 entries since they are the first and last knot (for both direction)
cpIndices.erase(cpIndices.begin());
......@@ -1268,10 +1272,9 @@ void FileOBJPlugin::readOBJFile(QByteArray& _bufferedFile, QString _filename, OB
#endif
}
//checks, if an object with a specified type was added. if not, point cloud was read
bool isType = faceCount != 0;
#ifdef ENABLE_BSPLINECURVE_SUPPORT
isType = isType || curveCount != 0;
#endif
......@@ -1287,6 +1290,7 @@ void FileOBJPlugin::readOBJFile(QByteArray& _bufferedFile, QString _filename, OB
if (!inGroup)
_importer.setCurrentGroup(0);
}
}
///check file types and read general info like vertices
......@@ -1734,12 +1738,11 @@ void FileOBJPlugin::checkTypes(QByteArray& _bufferedFile, QString _filename, OBJ
for (unsigned int i = 0; i < _importer.n_vertices(); ++i)
_importer.useVertex(i);
} else {
unsigned int currentOptions = _importer.objectOptions()[_importer.currentObject()];
// this is only a triangle mesh if the object is not a curve and not a surface
// also ignore if it is set to NONE
if (!(currentOptions & OBJImporter::CURVE) &&
!(currentOptions & OBJImporter::SURFACE) &&
(currentOptions != OBJImporter::NONE))
if (!(_importer.isCurve(_importer.currentGroup())) &&
!(_importer.isSurface(_importer.currentGroup())) &&
(_importer.isNone(_importer.currentGroup())) )
_importer.setObjectOptions(OBJImporter::TRIMESH);
}
}
......@@ -1854,7 +1857,7 @@ int FileOBJPlugin::loadObject(QString _filename) {
importer.addGroup( QFileInfo(_filename).fileName() );
//check if something was found
if ( importer.objectOptions().empty() && objIDs.empty() ){
if ( importer.noOptions() && objIDs.empty() ){
forceTriangleMesh_ = false;
forcePolyMesh_ = false;
......@@ -1862,7 +1865,7 @@ int FileOBJPlugin::loadObject(QString _filename) {
return -1;
}
//then parse the obj
//then parse the obj
readOBJFile( bufferedFile, _filename, importer );
// finish up
......@@ -1877,8 +1880,6 @@ int FileOBJPlugin::loadObject(QString _filename) {
pluginExists( "datacontrol", dataControlExists );
if ( dataControlExists ){
std::vector<OBJImporter::ObjectOptions> options = importer.objectOptions();
#if defined ENABLE_BSPLINECURVE_SUPPORT || defined ENABLE_BSPLINESURFACE_SUPPORT
std::map<int, QString> groupNames;
#endif
......@@ -1894,14 +1895,14 @@ int FileOBJPlugin::loadObject(QString _filename) {
std::vector<int> surfaceIds;
int lastSurfaceParent = -2;
#endif
for(unsigned int i = 0; i < importer.objectCount(); i++) {
for(unsigned int i = 0; i < importer.groupCount(); i++) {
// skip the object if it has no option
// this can happen if the object only included other objects
if (options[i] != NONE) {
if ( !importer.isNone(i) ) {
BaseObject* obj = importer.object(i);
if(obj) {
#ifdef ENABLE_BSPLINECURVE_SUPPORT
if (options[i] & OBJImporter::CURVE) {
if ( importer.isCurve(i) ) {
// store the parent group name for later grouping
groupNames[obj->id()] = importer.groupName(importer.getCurveParentId(i));
......@@ -1938,7 +1939,7 @@ int FileOBJPlugin::loadObject(QString _filename) {
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
if (options[i] & OBJImporter::SURFACE) {
if ( importer.isSurface(i)) {
// store the parent group name for later grouping
groupNames[obj->id()] = importer.groupName(importer.getSurfaceParentId(i));
......@@ -1972,7 +1973,7 @@ int FileOBJPlugin::loadObject(QString _filename) {
}
#endif
if ( (options[i] & OBJImporter::TRIMESH) || (options[i] & OBJImporter::POLYMESH) )
if ( (importer.isTriangleMesh(i) || importer.isPolyMesh(i) ) )
objIDs.push_back( obj->id() );
} else {
std::cerr << "Object is NULL!" << std::endl;
......@@ -2016,8 +2017,8 @@ int FileOBJPlugin::loadObject(QString _filename) {
}
}
//check all new objects
for(unsigned int i=0; i < importer.objectCount(); i++){
//check all new objects which are created for each group
for(unsigned int i=0; i < importer.groupCount(); i++){
BaseObject* object = importer.object(i);
if(object == NULL) continue;
......@@ -2059,6 +2060,7 @@ int FileOBJPlugin::loadObject(QString _filename) {
}
#endif
//textures
if ( importer.hasTexture(i) && !importer.hasOption( i, OBJImporter::FORCE_NOTEXTURES ) ){
......
This diff is collapsed.
......@@ -134,8 +134,15 @@ class OBJImporter
/// add an object
void setObject( BaseObject* _object, int _groupId );
/// get id of the active object
int currentObject();
/**\brief Get the id of the current group
*
* OBJ files can contain groups which are handled inside OpenFlipper as separate Objects.
* When loading a file, the importer has to keep track of the current group and store a state
* for each group with its properties (materials) )
*
* @return Id of the current group
*/
int currentGroup();
/// get a pointer to the active polyMesh
PolyMesh* currentPolyMesh();
......@@ -201,16 +208,29 @@ class OBJImporter
bool isPolyMesh(int _objectID);
bool isCurve(int _objectID);
bool isSurface(int _objectID);
bool isNone(int _objectID);
/// Set Object Option
void setOption( ObjectOptionsE _option);
/// Set Object Option
void setOption( ObjectOptionsE _option, int _groupId);
/// Global Properties
unsigned int n_vertices();
unsigned int n_normals();
unsigned int n_texCoords();
unsigned int objectCount();
/** \brief Number of groups currently stored in the importer
*
* As OBJ files can contain several groups, we need to store information per group.
*
* @return Number of groups currently found by the importer
*/
unsigned int groupCount();
/// return object with given index
BaseObject* object(int _objectID );
/// return object for the given group
BaseObject* object(int _groupId );
/// return all loaded materials
MaterialList& materials();
......@@ -233,8 +253,8 @@ class OBJImporter
/// containing info about the meshType
void setObjectOptions(ObjectOptions _options);
/// Object Options for all objects
std::vector< ObjectOptions >& objectOptions();
/// Return true if the importer has no options stored
bool noOptions();
/// check if object with given id has given option
bool hasOption( unsigned int _id, ObjectOptions _option );
......@@ -258,7 +278,7 @@ class OBJImporter
void finish();
private:
bool vertexListIsManifold(const std::vector<PolyMesh::VertexHandle>& _vertices) const;
// general data
......
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