• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

Wavefront OBJ reader

Started by Patrice Terrier, July 12, 2012, 07:07:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Patrice Terrier

'********************************************************************************
'*                           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.

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

Petr Schreiber

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

Patrice Terrier

#2
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.

...



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

Donald Ping

Nice work Patrice.

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

Petr Schreiber

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

Patrice Terrier

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

Patrice Terrier

#6
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.



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

Patrice Terrier

#7
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.

...

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

Patrice Terrier

#8
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.

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

Patrice Terrier

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

Patrice Terrier

#10


Note: You must apply the setting shown on the popup menu.
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com