A webvr multi-pages project for three.js, es6/7, webpack2 and postcss.
- 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
$ npm install
# or
$ yarn install
You can custom your local environment port(default 9000) via webpack/webpack.dev.js
.
$ npm start
$ npm run build
This will generator minified scripts to dist/
.
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();
})();
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 |
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 |
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
*/
Ask questions here.
PR welcome here.
YorkChan [email protected]
And thanks to Micooz's project es6-webpack2-boilerplate
MIT