Giter VIP home page Giter VIP logo

electron-threejs-example's Introduction

Three.js for native application thanks to electron

This post is a example of three.js game as native application. The idea came from @Nazariglez in this tweet, a nice guy, be sure to check it out! I loved the idea and tried to reproduce it. You can use that to easily write 3d games with ease of three.js coding and still have the same controls you can get with a native application.

So first what is electron ? This is the new name of atom-shell. It is the 'plateform' under which atom editor is running. It is has been introduced in this post on atom blog. It is a very new way to build native application. Under the hood, electron is running chromium and node.js. To get more information, checkout electron's homepage. It short, it is an easy way to write desktop apps with web technology.

Now Let's see how we can mix with three.js :)

How To Code It

Before having a three.js native apps, we need first to install electron, checkout the repository README.md. It is straightforward, just a plain npm command.

npm install electron-prebuilt -g

just follow electron's quick start and you will get something running in 10min at the most.

Then to add three.js, just replace their index.html by a webpage doing 3d with webgl. As electron running chromium, it supports WebGL, WebAudio or WebRTC without issue. You got a lot of freedom. In our case, i simply took an example from three.js examples/ called webgl_buffergeometry_uint

How To Make This Page Transparent

To make our demo appears nicer, we can try to make the window background transparent and not display the window frame. This will give a nice floating effect to the 3d.

TODO include a screenshot

To do the same, first modify electron main.js like this.

//mainWindow = new BrowserWindow({width: 800, height: 600});
mainWindow = new BrowserWindow({width: 800, height: 600, transparent: true, frame: false});

Second, be sure to make the body background transparent with css.

body {
  background-color: rgba(0,0,0,0);
}

Then tell three.js to stay transparent too. Just set alpha and the clear color.

renderer = new THREE.WebGLRenderer( { antialias: false, alpha : true } );
renderer.setClearColor(0x000000, 0);

Now everything is transparent and you can see the 3d floating on top :)

electron-threejs-example's People

Contributors

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