Giter VIP home page Giter VIP logo

hangar's Introduction

Hangar is an HTML5 JavaScript library that can be used to render 3D models in AC3D format (.ac) using WebGL.

The AC3D file format (.ac) is a text file format used to store 3D models by many projects, like FlightGear, an open-source flight simulation, or Torcs, an open-source car racing simulator.

Hangar supports the SGI image file format (.sgi, .rgba, .rgb, .ra, .bw) used for some old models to store textures.

Demo

Flight Gallery is a basic 3D FlightGear model viewer showing library capacities.

Use mouse button and wheel to have some fun!

Video

Flight Gallery

Viewer

To render an .ac file onto a canvas you just must to create an HG.Viewer object and call the show function with the name (url) of the .ac file:

var viewer = new HG.Viewer(canvas);

viewer.show(filename);

File is loaded, parsed and rendered using WebGL, with textures if any, and auto fitted to the canvas size. A default trackball controller is provided, so you can rotate and zoom the rendereed model using the mouse.

You can also use the library to parse individuals files for your own proposals (see bellow).

Some optional parameters can be specified in the call to the viewer:

  • callback: A callback function to be called when the model is fully loaded.
  • texturePath: Texture path (a trailing path separator is mandatory). By default the textures are loaded from the model directory.
  • setup: Camera parameters (disable autofit):
    • eye: A 3D vector with the camera position.
    • poi: A 3D vector with the point of interest.
    • up: A 3D vector with the up direction.
    • fov: A decimal number with the field of view angle.

Examples:

var viewer = new HG.Viewer(canvas);

viewer.show(filename, {callback: onModelLoaded, texturePath: "path/to/textures/"});
var viewer = new HG.Viewer(canvas);

viewer.show(filename, {setup: {eye: [-35.33, 11.98, -23.03], 
                               poi: [2.04, 3.48, 0.00], 
                               up: [-0.28, 0.84, 0.45], 
                               fov: 45} });

Render

Polygon surfaces are tessellated to equivalent triangulated surfaces. Both convex and concave surfaces are allowed.

Degenerated polygons are discarted. That is, polygons with less than three vertices, polygons with collinear coordinates, polygons with vertices not contained in an only one plane, polygons crossing edges, and so on.

Normal vectors are calculated per surface. Smoothed normal vectors are calculated per vertex.

Illumination model is based on the Phong one. Ligths on .ac files are ignored, render always perfomed using one static directional light without attenuation factors.

AC3D

To parse a loaded .ac file you just must to create an AC.File object:

var file = new AC.File(data);

data argument must be a JavaScript String with the content of a valid .ac file.

AC.File objects have the following properties:

  • materials: Collection of AC.Material objects.
  • objects: Collection of AC.Object objects.

AC.Material objects have the following properties:

  • name: Name.
  • diffuse: RGB value as a three dimensional vector.
  • ambient: Ambient color as a three dimensional vector.
  • emissive: Emissive color as a three dimensional vector.
  • shininess: Shininnes value.
  • transparency: Transparency value.

AC.Object objects have the following properties:

  • name: Name.
  • data: Extra data information.
  • texture: Texture file name.
  • textureRepeat: Texture repeat parameters as a two dimensional vector.
  • textureOffset: Texture offset parameters as a two dimensional vector.
  • rotation: Rotation matrix as a nine dimensional vector.
  • translation: Translation vector as a three dimensional vector.
  • crease: Crease angle.
  • url: Url.
  • vertices: Collection of vertices as a plain array of three dimensional vectors.
  • surfaces: Collection of AC.Surface objects.
  • children: Collection of AC.Object.

AC.Surface objects have the following properties:

  • type: Type as an enumerated AC.SurfaceType (POLYGON, LINE_LOOP, LINE_STRIP).
  • isShaded: Flag.
  • isTwoSided: Flag.
  • materialId: Material identificator as an index on the global material collection.
  • indices: Collection of indices as a plain array.
  • uvs: Collection of texture coordinates as a plain array of two dimensional vectors.
  • normal: Normal vector as a three dimensional vector.
  • normals: Collection of smoothed normal vectors per vertex as a plain array of three dimensional vectors.

SGI

To parse a loaded .rgb (.sgi, .rgba, .rb, .bw) file you just must to create one SGI.File object:

var file = new SGI.File(data);

data argument must be a JavaScript ArrayBuffer with the content of a valid .rgb file.

SGI.File objects have the following properties:

  • header: File Header as a SGI.Header object.
  • img: Image data as a SGI.Image object.

SGI.Header objects have the following properties:

  • storage: Storage format as an enumerated SGI.Storage (VERBATIM, RLE).
  • xsize: Image width.
  • ysize: Image height.
  • zsize: Number of image channels.

Original header attributes magic, bpc, dimension, pixmin, pixman, imagename and colormap are ignored. Always taken 8 bits per channel.

SGI.Image objects have the following properties:

  • width: Image width.
  • height: Image height.
  • data: Uncompressed image data as a plain Uint8Array with four channels (RGBA).

Original vertical image orientation is flip backed and always four channel are returned.

Dependencies

gl-matrix is used to operate with vectors, matrices and quaternions.

hangar's People

Contributors

jcmellado avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

a-drew combat1964

hangar's Issues

Faces with number of vertices greater or equal than 5 don't display properly

Hi,

The AC3D parser has some difficulties reading faces with at least 5 vertices.
It is fixed in the following commit:

https://sourceforge.net/p/flightgear/sceneryweb/ci/455cb19e0290fef1c238c5641520d40a3b17e00e/

To sum up:

  • First issue was normal computation which use only 3 vertices instead of all of them. The fix was to add all of them (like OSG AC3D reader do).
  • Then there is a small mistake in the convexe hull extracting (see triangulator.js).

Can you add these fixes?
Thank you for your work!

Regards,
Julien

Callback parameter must be optional

If the callback parameter is omitted, an exception is throwed:
"Uncaught TypeError: Property 'callback' of object #<Object> is not a function"

Original issue reported on code.google.com by [email protected] on 31 Aug 2012 at 8:17

translation and rotation are not inherited by children as expected

What steps will reproduce the problem?
1. create a ac3d file with a loc and or rot entry in a parent
2. add kids to that parent and add loc or rot entries to each
3. see screenshots and sample ac file attached

What is the expected output? What do you see instead?
The kids would inherit the loc of the parent.
The kid's rot would be applied locally to the kids, then the parent's rot would 
be applied to the parent and kids as a unit. Not to the parent and then the 
kids separately.

What version of the product are you using? On what operating system?
using the trunk version from svn.

Please provide any additional information below.
This issue (if my interpretation is correct) may have gone unnoticed because 
many models have the transforms normalised on export which removes all the loc 
and rot elements.
I have attached one ac file that exhibits the issue and two screenshots, one 
from hangar and one from flightgear each rendering the attached ac file.

Original issue reported on code.google.com by [email protected] on 24 Jul 2013 at 6:42

Attachments:

failure to render on the canvas on some browsers

What steps will reproduce the problem?
1. osX 10.5 chrome and Firefox 
2. Open the demo page: 
http://inmensia.com/files/hangar/flight-gallery/index.html
3. Or anothr page using this library to render an ac3d file.


What is the expected output? What do you see instead?

On the demo page the grey overlay continues to cover the page and the following 
error is thrown:
Uncaught TypeError: Cannot read property 'canvas' of null index.html:169
HG.Renderer.resizeindex.html:169
HG.Viewer.onResizeindex.html:188
(anonymous function)

What version of the product are you using? On what operating system?
This was observed in fresh checkout of trunk on the 23rd of June 2013.

Please provide any additional information below.
Exactly the same conditions on a more recent version of osX and using chrome 
shows no issues at all and the models render correctly.

Original issue reported on code.google.com by [email protected] on 23 Jun 2013 at 8:29

Not displayed with Firefox 27

Hi, I am Julien from the FlightGear scenery team 
(http://scenemodels.flightgear.org). We are using your wonderful libray but 
recently, we had some problem with it.

There was a JS bug when displaying with Firefox 27, on Linux.


I successfully solve it by changing in renderer.js (line 24)

this.gl = canvas.getContext("experimental-webgl", {alpha:false} ); 

to 

this.gl = canvas.getContext("experimental-webgl", {alpha:false} ) || 
canvas.getContext("webgl", {alpha:false} );

Hope this can help you.

Cheers,
Julien

Original issue reported on code.google.com by [email protected] on 9 Feb 2014 at 2:53

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.