Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Objex  (Read 3096 times)

0 Members and 1 Guest are viewing this topic.

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Objex
« on: August 06, 2014, 08:12:42 pm »
Updated to v0.2.0

I decided that I was going to have a look into OpenGL and looked at the SFML example and tweaked it to get a feel of how it works.
Then, I realised that I would want to be loading those objects from a file rather than storing them in the source code and considered saving them out and reloading them.
I then realised that I could just attempt to import existing formats of 3D objects and found .OBJ to be the easiest to get documentation for, and is so widely used, so I got side-tracked and created a class to help.

This class loads .OBJ files and converts them into vertex array of GLfloats, ready to pass to OpenGL.

It imports geometry vertices, texture vertices, and normal vertices but only geometry has been tested. This is because I am new to OpenGL and have yet to figure out lighting and texturing. Because of this, it creates a colour array of GLfloats (ready to pass to OpenGL) where each triangle is a random colour.

Feel free to use it in tests and things. As I mentioned earlier, I only really made it to make my 3D investigations a bit more interesting, and I didn't see the point in using an existing library for it when I could create it myself and learn in the process.

I would not consider it "complete" but it does the job of importing objects fine (for me). I was going to continue with importing textures etc. but I can't test if it's doing what it's supposed to be doing :P

I added the ability to manipulate the object too, so it now stores it twice - once in (sort of) .obj format, and once in GL format. You use the class to manipulate the obj version, then refresh the gl version from the obj version. This requires complete recreation of the GL version so it's quite slow for complicated objects.

Feel free to comment on my code. I'm no expert at C++ or SFML, nor especially OpenGL, so any tips would be appreciated. It's not designed to catch all errors in usage so it should be used properly. I will probably add more user-error security later.

Objex on GitHub

Here's a video of a test using a cow model from the internet:
« Last Edit: September 30, 2014, 10:49:42 pm by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Objex
« Reply #1 on: August 06, 2014, 09:30:12 pm »
Added video and a link to the site where the model is from.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

MadMartin

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: Objex
« Reply #2 on: August 06, 2014, 10:57:57 pm »
Someone once said that -- as an computer graphics developer -- a milestone in your career is when you wrote your own OBJ loader  ;)


Just one comment: Why are you using that much std::vectors<>, filled with redundant data? Just use std::getline for reading a line from the file and directly parse it. If you want to cache the lines first, just parse them after you read all lines to memory. IMHO there is no point in using an additional stage of vectors before the real(!) parsing takes place.

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Objex
« Reply #3 on: August 06, 2014, 11:03:40 pm »
I've never heard of that thing about obj loaders! Hehe, thanks  :)

I created it a small step at a time to make sure that each little part worked. I agree with you that there are too many redundant vectors and I intend to reduce the passes to remove the need for them. I just needed to make sure it worked so I could work on the OpenGL part, rather than worrying too much about the loader.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Objex
« Reply #4 on: August 07, 2014, 04:59:53 pm »
Decided I didn't like leaving it like that so I fixed it to stop use of so many redundant vectors. Even moved the raw lines vector into the function so that it is completely destroyed after use.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Objex
« Reply #5 on: September 30, 2014, 10:54:11 pm »
Updated to v0.2.0.
Relative indices for vertices can now be imported and a bug that meant the texture vertices where incorrect has been fixed.

Considering updating this to import materials but since I don't know enough OpenGL to actually display anything with textures or normals, I can't really test anything  :(
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything