Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. [SOLVED] Loading objects from Blender by Qt OpenGL
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Loading objects from Blender by Qt OpenGL

Scheduled Pinned Locked Moved C++ Gurus
5 Posts 3 Posters 3.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 8 Offline
    8 Offline
    8Observer8
    wrote on 21 Dec 2014, 05:59 last edited by
    #1

    Hello

    I have crash in the construction Scene::Scene() https://github.com/8Observer8/ObjLoader_v1_0_0

    You should run my application -> Click "Load" -> Select the file "Plane.observerFormat"

    I think that I cannot fill std::vector like this:

    @
    #include <iostream>
    #include <vector>

    void fill( std::vector<float> &vec1, std::vector<float> &vec2 );
    void show( const std::vector<float> &vec );

    int main()
    {
    std::vector<float> vec1;
    std::vector<float> vec2;
    fill( vec1, vec2 );

    show( vec1 );
    std::cout << "\n";
    show( vec2 );
    
    return 0;
    

    }

    void fill( std::vector<float> &vec1 , std::vector<float> &vec2 )
    {
    vec1.push_back( -0.5f );
    vec1.push_back( 0.5f );
    vec1.push_back( 1.5f );

    vec2.push_back( 0.5f );
    vec2.push_back( 0.5f );
    vec2.push_back( 1.5f );
    

    }

    void show( const std::vector<float> &vec )
    {
    for( unsigned int i = 0; i < vec.size(); ++i )
    {
    std::cout << vec[i] << "/n";
    }
    }
    @

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 21 Dec 2014, 09:46 last edited by Chris Kawa 3 Nov 2015, 00:20
      #2

      This works fine: http://ideone.com/aXGV7Z

      But your real code is different and has an error:

      void Object::initColors( int numOfVertices ) {
          colors.clear();
          colors.resize( numOfVertices * 3 );
      
          for ( unsigned int i = 0, j = 0; i < numOfVertices; ++i ) {
              colors[j++] = 1.0f;
              colors[j++] = 0.0f;
              colors[j++] = 0.0f;
      
              colors[j++] = 0.0f;
              colors[j++] = 1.0f;
              colors[j++] = 0.0f;
      
              colors[j++] = 0.0f;
              colors[j++] = 0.0f;
              colors[j++] = 1.0f;
          }
      }
      

      Size of the vector is 3*N. i iterates from 0 to N and for each i you increment j 9 times, which means j reaches 9 * N, which is waaaay beyond the end of the vector.

      1 Reply Last reply
      0
      • 8 Offline
        8 Offline
        8Observer8
        wrote on 21 Dec 2014, 20:31 last edited by
        #3

        Thank you very much. It works fine. Now I wrote like this:

        @for ( unsigned int i = 0, j = 0; i < numOfVertices / 3; ++i )@

        Source: https://github.com/8Observer8/CubeFromBlender_v1.0.1
        Picture: http://i9.pixs.ru/storage/2/1/3/SquareFrom_3854842_15269213.png

        The file "Cube.observerFormat" must be lie in the "currentPath" folder

        You can load objects from Blender like me

        Copy this script: https://yadi.sk/d/hvmi_wpxdXG5Y
        to C:\Program Files (x86)\Blender Foundation\Blender\2.72\scripts\addons

        Open Blender -> Press Ctrl+Alt+U -> Select "Addons" -> Select "Objects" -> Check "Object: SupPupExporter" -> Close the window "Blender User Preferences" -> Save Project (.blend file) -> Select "Object Mode" -> Click "Object" -> Select "SupPupExporter" -> You can find ".observerFormat" file ( it is where ".blend" lie)

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on 21 Dec 2014, 22:44 last edited by Chris Kawa 3 Nov 2015, 00:22
          #4

          I would argue that this is a lot easier to reason about:

          void Object::initColors( int numOfVertices ) {
              int size = numOfVertices * 3;
              colors.resize(size); //no need to clear if resizing anyway
          
              for (int i = 0; i < size; ) {
                  colors[i++] = 1.0f;
                  colors[i++] = 0.0f;
                  colors[i++] = 0.0f;
          
                  colors[i++] = 0.0f;
                  colors[i++] = 1.0f;
                  colors[i++] = 0.0f;
          
                  colors[i++] = 0.0f;
                  colors[i++] = 0.0f;
                  colors[i++] = 1.0f;
              }
          }
          

          or if you're on c++11:

          void Object::initColors( int numOfVertices ) {
            auto size = numOfVertices * 3;
            colors.resize(size);
          
            std::vector<float> rgb = {1.0f,0.0f,0.0f, 0.0f,1.0f,0.0f, 0.0f,0.0f,1.0f};
            auto i = 0;
            std::generate(colors.begin(), colors.end(), [&]{return rgb[i++ % rgb.size()];});
          }
          
          1 Reply Last reply
          0
          • W Offline
            W Offline
            wickwire
            wrote on 12 Feb 2015, 12:07 last edited by
            #5

            I was able to get the example running on Windows 8.1 by changing the code a little:

            Cube.cpp

            @//#include <GL/gl.h>
            #include <qopengl.h>@

            The Plane.observerFormat model didn't get drawn (and no error messages) but the Cube and some others already generated by me on Blender do work.

            Nice job!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved