Coder Social home page Coder Social logo

utea's Introduction

Utea

A toy WebGL 3D Engine (with basic 2D support)

⚠️ Under heavy construction 👷 🚧

Messing around

The examples are currently available at http://cirocosta.github.io/utea/example/. Go check them out!

If you wish to run the project locally:

$ npm install

# start webpack's dev-server
$ npm run start

# now you're ready :D
# go to http://localhost:8080/example/  or http://localhost:8080/webpack-dev-server/


# OR, build the project's examples and start your own
$ npm run build
$ python -m "SimpleHTTPServer"

# server started, now just
# go to http://localhost:8000/example/

If you don't know what npm is all about, check the next session.

Beginners Guide to Install

This project depends on NodeJS for transpilling the code without the need of a browser to run the Javascript transpiller. NPM is the package manager that allows us to distribute only the project's source code without the need of packing all the dependencies together. The development and general dependencies are explicited in ./package.json.

After you've installed NodeJS and NPM then you're able to clone the repo (git clone [email protected]:cirocosta/utea.git) and run that code above. After npm install is executed all of the dependencies will be downloaded. npm run start will run the script to set a webserver and let you dig into the generated code locally at http://locahost:PORT/.

IMPORTANT: npm run start and npm run build will fail in Windows as it exports NODE_ENV variable to set the proper build through export command (which i don't believe is available in windows - not a windows user here).

Samples

LICENSE

GPLv2. See ./LICENSE.

utea's People

Contributors

cirocosta avatar mateuszitelli avatar

Stargazers

Igor APA avatar Raphael Fabeni avatar  avatar Michael Anthony avatar  avatar

Watchers

 avatar James Cloos avatar Michael Anthony avatar  avatar

utea's Issues

Multiple Contexts

So, as i've mentioned in #1 , we should let the user need to grab the WebGLRenderingContext JUST when it needs to, and not everytime to pass to a constructor or something like that (which, more than annoying, is a pretty bad design).

The first idea regarding how to improve this was: let PaintBoard class hold a context (once created) and then bind all the other objects with this context.

But, would this work nice with multiple contexts?


use this issue to make some thoughts explicit

Logo!

I was thinking a bit about a logo for the project this afternoon and the idea that i came up with involves a bunch of work but might result in an amazing thing.

The idea that i have is:

  1. Extract bezier curves descriptions from a truetype font (maybe sending to inkscape and them getting the svg description, or gimp, idk)
  2. Describe a shape for extruding the curves --> let it be in meshgrid
  3. Create a 3D Scene that disposes the text in a cool way
  4. Add a mango to the scene
  5. Render!

This aligns well with one of my particular aims for this project: solving the programming assignment that i have to do for my computer graphics class, which is all about modelling extrude shapes, bsplines and RaGs and then visualizing the result (doing these three things in 3 separate canvases).

mango-logo-idea

Arcball

UPDATE

*SEE #7 *

  • ArcBall focusing on an object
  • ArcBall for Camera movement

Implementation

  1. acquire the position of the mouse as if it is inside our world (unproject and then perform those inverses that takes it from screenspace to worldspace)
  2. generate the ray of the click (point - camera.position, which, parametrically thinking, generates the line: f(t) = camera.pos + t*(point-camera.position).
  3. find the intersection between the ray and the sphere around something (an object or the camera per se)
  4. rotate the corresponding amount.
    • we have an starting vector (when mousedown event triggers) and an ending vector (when mouseup or mousemove triggers)
      • determine the axis of rotation (just take the cross prod between them)
      • determine the angle of rotations (take the dot product and do the inverse math)

Lights

Types

Lamp is an omnidirectional point light source, similar to a light bulb.
Spot is a directional point light source, similar to… a spot!
Area is a source simulating area producing light, as windows, neons, TV screens…
Hemi simulates a very wide and far away light source, like the sky.
Sun simulates a very far away and punctual light source, like the sun.
from http://wiki.blender.org/index.php/Doc:2.4/Manual/Lighting/Lamps

Implementation

I propose implementing first Sun and Spot lights so that we'd have directional and spot lights.

Demo

The demo i propose for a basic scene illustrating the use of spotlights is a three-point lighting system.

Object Hierarchy

Abstract the Renderable to a base class. Let the current renderable inherit from it and then create a separate class that encapsulate a group ou OldRenderables. This will allow us to create 'steps' in the hierarchy, holding transformation matrices properly

Geometry should not hold Buffer objects

Maybe we'd be better off releasing the responsability of holding the indexbuffer from the geometry. This is something that a class that gets to the renderer should hold (like a Renderable or something). We could let geometry only hold a description.

Optimize material data sent to gpu

There's no need to send color data as a float. We could break it into a single uint, for example and creating a 'struct-a-like' (see working with complex data structures)

struct VertexData
{
    vec3 vertex;  // vertex coordinates
    vec2 uv;        // texture coordinate
    uint tid;          // tid for arrays of textures */
    uint color;      // encoded color
};
const FLOAT32_SIZE = new Float32Array().BYTES_PER_ELEMENT;
const UINT16_SIZE = new Uint16Array().BYTES_PER_ELEMENT;

let buffer = new ArrayBuffer(3*FLOAT32_SIZE + 2*FLOAT32_SIZE + 2*UINT16_SIZE);

let vertexView = new Float32Array(buffer, 0, 3);
let uvView = new Float32Array(buffer, 12, 2);
let tidView = new Uint16Array(buffer, 20, 1);
let colorView = new Uint16Array(buffer, 22, 1);

Encoding the rgba values is pretty easy and cheap. Maybe this should work:

uint colorRGB = b << 16 | g << 8 | r;
uint colorRGBA = a << 24 | b << 16 | g << 8 | r;

see http://stackoverflow.com/a/21550921/2178180 as well

Possibility of inconsistency on Positioning

heads up: this is not a priority as it refers to something that we might expose in the future.

We're relying on a prepare method that updates what it needs depending on dirtyness. This can lead to some kind of inconsistency depending on the expectations of the user regarding the internal state of the Body (or base Camera).

For example:

let sprite = new Renderable(...)
sprite.position = [2.0, 0.0, 10.0];
// expects that sprite's modelMatrix is properly set
vec4.transformMat4(ray, sprite.modelMatrix);
// uh oh, actually got an identity as `sprite.prepare()` didn't happened

loop(); 

My solution in simple:

  • remove this prepare method and check for dirtyness in the getters. By doing this we guarantee that when something needs a fresh matrix (as expected) it will get. When we don't need, keep using the internal structure (_modelMatrix, for example, which doesn't have a getter)

Context: when generating a Ray we rely on an updated version of the camera.

Better closed Nurbs

We're only providing clamped closed nurbs (which does not guarantee C^{k-1} continuity). We should provide unclamped ones by repeating k-2 first or last control points while preserving uniform spacing in the knots vector.

Curves

For the next programming assignment (as stated on #4 ) we need to implement a basic curves editor with shape extruding. Two kinds of curves must be supported:

I also suggest a third as it's a very common choice among pen tools:

  • Bezier Curve Redundant. We can easily create bezier curves from BSplines if we allow (and we will) the user specify the knots vector

Extra

noise-reduction: Ramer-Douglas-Peucker and Visvaligam's algorithm

  • Try to take advantage of instancing and glSubBufferData-a-like stuff for perf.

We need to find the derivatives so that we're capable of determining surface normals.
see Implementation of NURBS Curve Derivatives in Engineering Practice

Object Selection

Object selection involves one step that is pretty much the same for any kind of object (ray generation), having then great dissimilarity regarding the intersection test. Ray generation has been implemented on #7 but might need some improvement.

  • Points
    • for a given range of error, verify if we can find the point in the equation of the ray
  • Lines
    • for a given range of error, verify if we can find a point so that the equations match
  • Polyhedron
    • AABB
    • Per-face testing
  • Picking

There are many more tests. Tests will vary on the geometry and the accuracy needed. Maybe these tests could be a method provided by the geometry and be somehow selectable by the user.

Shadows

As an issue was created for lightning (see #17 ), shadows comes next.

Refactor webpack.config

We're almost building the whole project for each new example that is added as an entrypoint. We could take advantage of webpack's 'commons' generation. Explore this alternative later.

todo

Issue adressing some temporary minnor stuff

this shouldn't exist. Separate into specific issues.


Prior to updating and closing there were some annotations regarding how we pass WebGLRenderingContext

Orthographic Camera

We're relying solely on perspective projection. Maybe we can go with a specialized class but i particularly don't like this idea as there's a LOT of things that both of them (perspective .. ) share.

Perhaps going with something like this:

let camera1 = new Camera({
  type: PERSPECTIVE,
  ar: .. , fov: ..., near: ..., far: ...
});

let camera2 = new Camera({
  type: ORTOGRAPHIC,
  lefft, right, bottom, top, near, far
});

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.