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 1001B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "wavefrontobj.h"
  2. #include <QFile>
  3. #include <QDebug>
  4. #include "lexer-wavefront-obj.h"
  5. #include "parser-wavefront-obj.h"
  6. WaveFrontObj::WaveFrontObj(QObject *parent) :
  7. QObject(parent)
  8. {
  9. }
  10. bool WaveFrontObj::openFile(const QString &filename)
  11. {
  12. QFile f(filename);
  13. if (f.open(QIODevice::ReadOnly)) {
  14. bool res = load(f);
  15. f.close();
  16. return res;
  17. }
  18. _error = "Failed to open file: " + f.errorString();
  19. return false;
  20. }
  21. bool WaveFrontObj::load(QIODevice &device)
  22. {
  23. _error.clear();
  24. QString file = device.readAll();
  25. YY_BUFFER_STATE bufferState = wavefront_obj_scan_string(file.toUtf8().constData());
  26. WaveFrontObjData data;
  27. int res = wavefront_objparse(&data);
  28. wavefront_obj_delete_buffer(bufferState);
  29. if (res) {
  30. _error = "Parse error: " + data._error;
  31. qDebug() << _error;
  32. }
  33. else {
  34. qDebug() << "faces:" << data._faces.size() << "vertexes" << data._vertexes.size();
  35. }
  36. return res == 0;
  37. }