Code Monkey home page Code Monkey logo

webvr-webpack2-boilerplate's Introduction

webvr-webpack2-boilerplate

A webvr multi-pages project for three.js, es6/7, webpack2 and postcss.

δΈ­ζ–‡

Features

  • webvr: a webvr boilerplate supporting scenes changing
  • three.js: use as the global varriable
  • es6/7: by babel and it's presets and plugins
  • postcss: by postcss-loader
  • webpack2 provides faster compilation

Installation

$ npm install
# or
$ yarn install

Configuration

You can custom your local environment port(default 9000) via webpack/webpack.dev.js.

Run in development

$ npm start

Build for production

$ npm run build

This will generator minified scripts to dist/.

Create webvr page

Here comes the basic script to create a webvr page. See more pages in src/page/*.js .

import VRPage from 'common/js/VRPage';

import ASSET_TEXTURE_BOX from '../assets/texture/box.jpg';
class Index extends VRPage {
	constructor() {
		// webgl renderer container,default is document.body
		super({container:document.querySelector('.webvr-container')});
	}
	start() {
		let geometry = new THREE.CubeGeometry(5,5,5);
		let material = new THREE.MeshBasicMaterial({ 
			map: new THREE.TextureLoader().load(ASSET_TEXTURE_BOX) 
		});
		this.box = new THREE.Mesh(geometry,material);
		this.box.position.set(3,-2,-3);
		// add gaze eventLisenter
		WebVR.Scene.add(this.box);
		this.box.on('gaze',mesh => { // gazeIn trigger
			mesh.scale.set(1.2,1.2,1.2);
		},mesh => { // gazeOut trigger
		});
	}
	loaded() {
        console.log(`${ASSET_TEXTURE_BOX} has been loaded.`);
	}
	update(delta) {
		this.box.rotation.y += 0.05;
	}
}
export default (() => {
	return new Index();
})();

WebVR API from VRCore.js

API type description
WebVR.Scene THREE.Scene global webvr scene
WebVR.Camera THREE.PerspectiveCamera global webvr eyes
WebVR.Renderer THREE.Renderer global webvr renderer
WebVR.forward function load and change the scene
WebVR.CrossHair THREE.Object3d global webvr crosshair

VRPage instance function

name parameter description
start null excute before the first rendering
loaded null excute after all the textures,3d models and audio are loaded
update parameter excute during each rendering

Forward Pages

It is no need to fetch more html,just fetch the script of page when you need to go forward other pages.

WebVR.forward('pageFileName');
/* 2 steps to be excuted in WebVR.forward function
WebVR.cleanPage(); // clear object3d and events in current page
import(`page/${pageFileName}.js`); // fetch and load the next page
*/

Need Help?

Ask questions here.

Any advise?

PR welcome here.

Contributors

YorkChan [email protected]

And thanks to Micooz's project es6-webpack2-boilerplate

License

MIT

webvr-webpack2-boilerplate's People

Contributors

yonechen avatar

Watchers

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