Navigation Menu

Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
netpro2k committed Apr 1, 2016
0 parents commit ba2f306
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
@@ -0,0 +1,3 @@
{
"presets": ["es2015", "stage-1"],
}
11 changes: 11 additions & 0 deletions .eslintrc
@@ -0,0 +1,11 @@
{
"extends": ["standard"],
"parser": "babel-eslint",
"rules": {
"space-before-function-paren": [1, "never"],
"no-unused-vars": 1,
"semi": 1,
"react/prop-types": 0,
"no-multiple-empty-lines": 0
}
}
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
/node_modules
bundle.js
npm-debug.log
Empty file added README.md
Empty file.
10 changes: 10 additions & 0 deletions index.html
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
</head>
<body>
<div class="container"></div>
</body>
<script src="/bundle.js"></script>
</html>
28 changes: 28 additions & 0 deletions package.json
@@ -0,0 +1,28 @@
{
"name": "altspace-webpack-starter",
"version": "1.0.0",
"description": "altspace webpack template",
"main": "index.js",
"private": true,
"scripts": {
"start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --hot --inline",
"build": "NODE_ENV=production webpack -p --progress --profile --colors"
},
"author": "",
"devDependencies": {
"babel-core": "^6.2.1",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.1.18",
"babel-preset-stage-1": "^6.1.18",
"css-loader": "^0.23.1",
"style-loader": "^0.13.0",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.14.0"
},
"dependencies": {
"altspace": "^0.5.3",
"css-wipe": "^4.1.2",
"pleasejs": "^0.4.2",
"three": "^0.73.0"
}
}
69 changes: 69 additions & 0 deletions src/index.js
@@ -0,0 +1,69 @@
import 'css-wipe'
import '../style/base.css'

import THREE from 'three'
import altspace from 'altspace'

import Please from 'pleasejs'

window.THREE = THREE

var CUBE_SCALE = 150;
//can change above value in live-coding, 10-500 works well

var sim = altspace.utilities.Simulation();
var config = { authorId: 'AltspaceVR', appId: 'SpinningCube' };
var sceneSync;

altspace.utilities.sync.connect(config).then(function(connection) {
sceneSync = altspace.utilities.behaviors.SceneSync(connection.instance, {
instantiators: {'Cube': createCube },
ready: ready
});
sim.scene.addBehavior(sceneSync);
});

function createCube() {
var geometry = new THREE.BoxGeometry(1, 1, 1);
var material = new THREE.MeshBasicMaterial({color:'#ffffff'});
var cube = new THREE.Mesh(geometry, material);
cube.scale.multiplyScalar(CUBE_SCALE);
cube.addBehaviors(
altspace.utilities.behaviors.Object3DSync(),
altspace.utilities.behaviors.Spin({speed: 0.0005}),
ChangeColor()
);
sim.scene.add(cube);
return cube;
}

function ready(firstInstance) {
if (firstInstance) {
sceneSync.instantiate('Cube');
}
}

function ChangeColor() {//define a custom behavior
var object3d;
var lastColor;
var colorRef;
function awake(o) {
object3d = o;
var sync = object3d.getBehaviorByType('Object3DSync');//TODO: better way of doing this
colorRef = sync.dataRef.child('color');
colorRef.on('value', function (snapshot) {
var value = snapshot.val();
if (!value) return; //we are first to create the cube, no color set yet
object3d.material.color = new THREE.Color(value);
object3d.material.needsUpdate = true;//currently required in Altspace
});
object3d.addEventListener('cursordown', function() {
var color = Please.make_color()[0];//random color
colorRef.set(color);
});
}
function update(deltaTime) {
/* no updating needed, color changes in Firebase 'value' callback above */
}
return { awake: awake, update: update };
};
Empty file added style/base.css
Empty file.
27 changes: 27 additions & 0 deletions webpack.config.js
@@ -0,0 +1,27 @@
module.exports = {
entry: [
'./src/index.js'
],
output: {
path: __dirname,
publicPath: '/',
filename: 'bundle.js'
},
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loaders: ['babel']
}, {
test: /\.css$/,
loader: 'style!css'
}
]},
resolve: {
extensions: ['', '.js', '.jsx', '.css']
},
devServer: {
historyApiFallback: true,
contentBase: './'
}
}

0 comments on commit ba2f306

Please sign in to comment.