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

123456789101112131415161718192021222324252627282930313233
  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. QString file = device.readAll();
  24. YY_BUFFER_STATE bufferState = wavefront_obj_scan_string(file.toUtf8().constData());
  25. int res = wavefront_objparse();
  26. wavefront_obj_delete_buffer(bufferState);
  27. return res == 0;
  28. }