Giter Club home page Giter Club logo

cube-engine's Introduction

Cube Engine

Cube Engine

Cube Engine is an HTML5 3D engine based on canvas, absolutely no OpenGL and thus no 3D acceleration. This is a proof of concept and learning project, but it can be fun to some extent... as long as you have a ludicrously powerful computer.

Demo

Check out the live demo.

World

The world resembles that of Minecraft, a popular voxel-type 3D game based on boxes. You can add and remove everything and anything, different types of nodes are available. The borders are only limited by the size of an integer in Javascript, that means the world is generated dynamically as the player visits new areas. There is no vertical limit, but rendering distance is somewhat limited.

The topography of the world is generated by a pseudo-random function. The underlying system imitates that of Minecraft: the world is made of 16 by 16 by infinity node "chuncks". The pseudo-random function generates a single height value for each chunk and the height values in between are interpolated. Everything under the height value is filled with nodes and everything above is left empty. Depending on the height different types of soil can be found (grass, dirt, sand...).

Contrary to Minecraft the world renderer uses a 2D perlin-noise generator rather than 3D, there are no ores or tunnels underground, no enemies or mobs, no trees or physics. Since the renderer takes all the processing power the features must be limited.

A height map and a frames per second graph can be enabled in the menu.

Rendering

Cube Engine rendering with textures

The rendering is a simple painter's algorithm, everything is drawn from back to front, so nodes close to the camera are drawn over the nodes further away. As canvas doesn't have any 3D rendering capabilities the engine uses very basic 3D rendering techniques. Some optimisation techniques like back-face culling, occlusion culling and frustum culling have been implemented. Octrees aren't adapted to this game and scale, chunks are better suited.

To make things go faster a lower rendering distance can be selected.

Canvas doesn't support textures, so texture implementation must be made from ground up: an affine texture mapping system is used. Rendering with textures makes the game noticeably slower so a simple renderer, that uses plain colors, is also available.

Textures are stored in a png file, the texture placement is exactly the same as Minecraft's, so one could use any current Minecraft texture pack with this game.

Saving

One can locally save a game, this stores all nodes in a 3 by 3 chunk (with the player in the middle chunk) in the browsers local memory or in a file. The data can be loaded locally, but not from a file (for security reasons). To load a world from file the program must be run from a server.

Problems

Corner clipping isn't supported, so being too close to a node will lead to its removal and one will be able to see what's on the other side.

The way Javascript handles floating point numbers makes it difficult to have exact integers, something that the collision system relies on. This was solved by "rounding" the numbers when close to an integer, but it's not a very elegant solution.

Chrome has some trouble rendering in plain color, specifically it's the context.fill() function that doesn't work when called too much it seems.

Firefox doesn't let the browser lock the pointer unless it's in full screen mode, this program should never run in full screen, unless on a super computer.

Licence

Released under the WTFPL.

cube-engine's People

Watchers

James Cloos avatar Heraclio Rios 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.