Author Topic: Wavefront OBJ reader  (Read 9036 times)

0 Members and 1 Guest are viewing this topic.

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2382
  • Gender: Male
    • www.zapsolution.com
Wavefront OBJ reader
« on: July 12, 2012, 07:07:57 PM »
'********************************************************************************
'*                           PowerBASIC translation                             *
'*                              Patrice Terrier                                 *
'*                                                                              *
'*  Special thanks to Larry Charlton who fixed a few bugs in the original C++   *
'*  code, and helped me to understand some of the cryptic syntax being used.    *
'*                                                                              *
'*              In memory of my father who passed on 07-08-2012                 *
'*                                                                              *
'*    First release: 06-30-2012                                                 *
'*  Latest revision: 07-12-2012                                                 *
'*                                                                              *
'********************************************************************************


This demo shows you how to import Alias|Wavefront OBJ and MTL files into your OpenGL applications.
The OBJ file format is one of the most widely supported 3D file formats.
All of the most popular 3D content creation packages includes support for this file format either natively or through third party plugins.

Models are rendered using either the fixed function pipeline or the programmable pipeline.
The fixed function pipeline is used on hardware that only supports OpenGL 1.x.
The programmable pipeline is used on hardware that supports OpenGL 2.0 and higher. The supported GLSL shaders are per fragment Blinn-Phong and normal Mapping.
Both support only a single fixed directional light source shining down the OpenGL default negative z-axis.

Most of the time the per fragment Blinn-Phong shader will be used.
The normal mapping shader will be used only when the OBJ model's MTL file includes a material that has a bump map (specified using the 'map_bump' command).
This demo assumes that any bump map associated with a material will be a normal map. All other bump map formats are not supported.

When the MTL file contains a material with a normal map this demo will generate smooth tangent vectors for the OBJ model.
The smooth tangent vectors are generated by summing the triangle face tangent vectors of adjacent triangle faces and then normalizing the resulting tangent vector.
The bitangent vectors are not generated here. They are calculated in the normal mapping shader's vertex shader.

A minimal file menu is provided to enable OBJ files to be loaded at runtime.
The demo will launch and load the OBJ file.

This demo is completely self contained. The two GLSL shaders are embedded directly into the source code.

Usage:
Left click and drag using the mouse to translate the model.
Middle click and drag using the mouse to zoom in and out of the model.
Right click and drag using the mouse to rotate the model.

ObjReader.zip is a GDImage SDK project with source code.
Model.zip is a subfolder with embedded wavefront obj models to be used with the project.

...
« Last Edit: July 30, 2012, 03:48:00 PM by Patrice Terrier »
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Petr Schreiber

  • Sr. Member
  • ****
  • Posts: 411
Re: Wavefront OBJ reader
« Reply #1 on: July 13, 2012, 08:48:11 AM »
Hi Patrice,

program ran great and smooth on my PC:
Windows 7, Core 2 Duo T6600, 2GB RAM, GeForce G210M

CPU usage 50-80%


Petr

P.S. Please accept my deep condolences to you...
AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2382
  • Gender: Male
    • www.zapsolution.com
Re: Wavefront OBJ reader
« Reply #2 on: July 14, 2012, 12:37:04 PM »
Petr--  thanks for the condolences.

I have updated the first post of this thread with a new version of ObjReader.zip

  • CPU usage has been cut down.
  • New menu option to work in "fixed pipeline" mode
  • New object model R2D2.

By the way i prefer to use "fixed pipeline" than vertex shader, lower CPU foot print and better antialias quality.
However, if you know of some nice vertex shader(s), please be kind enough to post them here.

Before you download this project, be aware that it tooks me two monthes of work to let it work correctly in PB, thus if you use it, don't forget to give the credit where credit is due, and remember that a small "thank you" is also appreciated by those who are regular posters on this forum.

About the attached screen shot:
The R2D2 model makes very obvious the difference between the "fixed pipeline" and the "vertex shader" mode.

Note: The R2D2.obj being rather large, it would take several seconds to load in memory.

...

 

« Last Edit: September 01, 2013, 11:23:48 AM by Patrice Terrier »
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Donald Ping

  • Newbie
  • *
  • Posts: 7
Re: Wavefront OBJ reader
« Reply #3 on: July 14, 2012, 06:00:16 PM »
Nice work Patrice.

Please accept condolences to you and your family for the lose of your father.

Offline Petr Schreiber

  • Sr. Member
  • ****
  • Posts: 411
Re: Wavefront OBJ reader
« Reply #4 on: July 17, 2012, 09:03:29 AM »
Hi Patrice,

new version runs at 1-3% CPU, great job!


Petr
AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2382
  • Gender: Male
    • www.zapsolution.com
Re: Wavefront OBJ reader
« Reply #5 on: July 17, 2012, 03:34:32 PM »
Donald, Petr,

Thank you.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2382
  • Gender: Male
    • www.zapsolution.com
GDImage_ObjReader is available.
« Reply #6 on: July 21, 2012, 03:35:58 PM »
GDImage_ObjReader.zip has been attached to the first post of this thread.

To appreciate the rendering quality, load the "R2D2.obj" file from the "Model\R2D2" folder, then enable the "Use fixed pipeline" menu option, and switch to full screen mode to manipulate the wavefront object.

Usage:
  • Left click and drag using the mouse to translate the model.
  • Middle click and drag using the mouse to zoom in and out of the model.
  • Right click and drag using the mouse to rotate the model.



...
« Last Edit: July 21, 2012, 04:03:21 PM by Patrice Terrier »
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2382
  • Gender: Male
    • www.zapsolution.com
New version of GDImage_ObjReader.zip
« Reply #7 on: July 23, 2012, 05:23:41 PM »
A new version of GDImage_ObjReader.zip + Pitts_Special.zip have been attached to the first post of this thread.

What is new:
  • Enhanced zooming capabilities.
  • "Swap Vector direction" menu option.
  • New Pitts_Special.zip file.

To try the new features load the "Pitts_Special" model, then turn on "Use fixed pipeline" and enable "Swap Vector direction".

Adjust the camera location with the left mouse button, then you should be able to see something like this:



Try looking inside of the cockpit to see the details.

...

« Last Edit: July 23, 2012, 05:29:13 PM by Patrice Terrier »
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2382
  • Gender: Male
    • www.zapsolution.com
IronMan
« Reply #8 on: July 30, 2012, 04:51:05 PM »
A new version of ObjReader.zip has been attached to the first post of this thread.

In this one i have been working on material and specular effects, and all parameters have been set for virtual reality presentation. The project is provided with a set of new backgrounds to change the visual appearance of the model.

In order to let you see what could be done with this version, i am providing a new model: "IronMan" with my own .MTL file to better match the aspect of the original. Better to switch in "full view" mode, and perform zooming to see all the details on all angles.



The "Model" folder is provided with two models: IronMan and Dragon1

Note: to PC-Soft users,  i plan to make a WD17 version.

...
« Last Edit: March 13, 2014, 05:06:46 PM by Patrice Terrier »
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline maurice_fischer

  • Newbie
  • *
  • Posts: 3
Re: Wavefront OBJ reader
« Reply #9 on: July 31, 2012, 10:47:39 AM »
that's looking very nice, patrice. good work! Thanks. I like such obj works. btw: I am working with lightwave 3d (http://www.newtek.com/products/lightwave.html) and know the obj format very well.

http://www.youtube.com/watch?v=xxNHBQdYi78

bye, maurice
« Last Edit: July 31, 2012, 11:12:01 AM by maurice_fischer »

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2382
  • Gender: Male
    • www.zapsolution.com
Re: Wavefront OBJ reader
« Reply #10 on: July 31, 2012, 03:25:03 PM »
Maurice

I am looking for new OBJ files, to try with the ObjReader project, if you have some good links to free stuff, please be kind enough to post them here.

Thank you.

...


Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2382
  • Gender: Male
    • www.zapsolution.com
Re: Wavefront OBJ reader
« Reply #11 on: August 08, 2013, 10:55:48 AM »
The original C++ project can be found here:

http://www.dhpoware.com/demos/glObjViewer.html

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2382
  • Gender: Male
    • www.zapsolution.com
A6M Zero Mitsubishi
« Reply #12 on: August 30, 2013, 05:04:08 PM »


Note: You must apply the setting shown on the popup menu.
« Last Edit: August 30, 2013, 05:07:45 PM by Patrice Terrier »
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com