Code Monkey home page Code Monkey logo

webgl-geometry's Introduction

WebGL Geometry

This library was originally meant as an auxiliary to an educational project for teaching OpenGL. I figured it would prove useful for those who want to create geometric scenes for educational purposes in an easy way, straight in the browser, without the need for additional dependencies.

Public classes and methods

  • DrawableBlueprint: an abstract standalone primitive, not enclosed within a context, containing basic drawing information;
    • constructor(name[string]: name under which the primitive will be displayed, color[vec3]).
  • Point[extends DrawableBlueprint];
    • constructor(name[string], color[vec3], position[vec3]).
  • Segment[extends DrawableBlueprint];
    • constructor(name[string], color[vec3], p1[Point]: head of segment, p2[Point]: tail of segment);
    • intersect(drawable[DrawableBlueprint], name*[string]: (optional) name of resulting drawable, color*[vec3]: (optional) color of resulting drawable).
  • Arrow[extends Segment]: a segment-like primitive but with an arrowhead on the tail;
  • Vector[extends Arrow]: an arrow-like primitive but with the head always at origin;
    • constructor(name[string], color[vec3], p[Point]: tail of arrow).
  • Triangle[extends DrawableBlueprint];
    • constructor(name[string], color[vec3], p1[Point], p2[Point], p3[Point]);
    • intersect(drawable[DrawableBlueprint], name*[string], color*[vec3]).
  • CoordSystem[extends DrawableBlueprint]: a container of primitives in which you can add other drawables (including other CoordSystems);
    • constructor(name[string], color[array]{[vec3], [vec3], [vec3]}: colors of axes, modelMatrix[mat4]: homogenous transformation applied to each drawables inside this system in transpose form);
    • add(...[DrawableBlueprint varargs]).
  • SpecialDrawableBlueprint: a drawable type that allows loading more complex models in the scene, with known vertex positions, colors, normals, texture information and faces;
    • constructor(positions[Float32Array], normals[Float32Array], colors[Float32Array], texInfo[object literal]{image[Image], coords[Float32Array]}, faces[Uint32Array]).
  • PlyModelLoader: loads .ply model async;
    • constructor(plyInputId[string]: ID of input element where user loads the .ply file, texInputId*[string]: (optional) ID of input element where user loads the texture image, onLoad[Function]: what is executed after the model loads).
  • Scene.
    • constructor(gl[WebGLRenderingContext]: the WebGL drawing context fetched from the canvas element, options[object literal]{unlockRoll[Boolean]: is scene free to rotate around roll axis, depthTest[Boolean]});
    • insert(...[DrawableBlueprint varargs]);
    • render();
    • redraw(): deletes all primitives currently in scene, reinstantiates and redraws them (useful for async operations).

Examples

There are also example scenes in the code, inside the ex_* folders from which you can copy the main.html and main.js files into the main folder and open the html file in your browser for visualisation. The following are screenshots of the scenes:

ex_spdc

Example of single primitive, multiple contexts: the cube-like model is drawn twice, once in the canonical coordinate system and once in a coordinate system with an arbitrary rotation, scaling and translation;

Scene-3

ex_dynmodif

Example of runtime-modified attributes: input sliders have been used to vary the position of points S1 to S12;

Scene

ex_isect

Example of triangle-segment and triangle-triangle intersection;

Scene-2

ex_epipolar

A scene that loads .ply models and uses the features mentioned previously to render a more complex view.

Scene-1

+ Can draw names of drawables
+ Supports shared drawable across multiple contexts
+ Easy screenshot utility (on key 'P')
+ Can modify drawable attributes at runtime
+ Can calculate and draw intersections between drawables
- Low memory footprint and high efficiency

webgl-geometry's People

Contributors

alex-badea avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

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.