You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wavefrontobj.cpp 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "wavefrontobj.h"
  2. #include <QFile>
  3. #include <QDebug>
  4. #include "lexer-wavefront-obj.h"
  5. #include "parser-wavefront-obj.h"
  6. #include "lexer-wavefront-mtl.h"
  7. #include "parser-wavefront-mtl.h"
  8. WaveFrontObj::WaveFrontObj(QObject *parent) :
  9. QObject(parent)
  10. {
  11. }
  12. QList<QList<WaveFrontObjFaceVertex> > WaveFrontObj::getFaces() const
  13. {
  14. return _faces;
  15. }
  16. QList<Vector3D> WaveFrontObj::getVertexes() const
  17. {
  18. return _vertexes;
  19. }
  20. bool WaveFrontObj::openFile(const QString &filename)
  21. {
  22. QFile f(filename);
  23. if (f.open(QIODevice::ReadOnly)) {
  24. bool res = load(f);
  25. f.close();
  26. return res;
  27. }
  28. _error = "Failed to open file: " + f.errorString();
  29. return false;
  30. }
  31. bool WaveFrontObj::load(QIODevice &device)
  32. {
  33. _error.clear();
  34. QString file = device.readAll();
  35. YY_BUFFER_STATE bufferState = wavefront_obj_scan_string(file.toUtf8().constData());
  36. int res = wavefront_objparse(this);
  37. wavefront_obj_delete_buffer(bufferState);
  38. if (res) {
  39. qDebug() << _error;
  40. return false;
  41. }
  42. else {
  43. return true;
  44. }
  45. }
  46. void WaveFrontObj::addFace(QList<WaveFrontObjFaceVertex> face)
  47. {
  48. _faces.append(face);
  49. }
  50. void WaveFrontObj::addVertex(const Vector3D &vertex)
  51. {
  52. _vertexes.append(vertex);
  53. }
  54. void WaveFrontObj::setError(const QString &error)
  55. {
  56. _error = error;
  57. }