Skip to content

Commit

Permalink
Migrate dasboot to webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksanb committed Apr 24, 2017
1 parent 8ff360b commit f461a22
Show file tree
Hide file tree
Showing 27 changed files with 991 additions and 291 deletions.
32 changes: 14 additions & 18 deletions nin/backend/dasbootgen.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
const webpack = require('webpack');
const p = require('path');
const readDir = require('readdir');
const fs = require('fs-promise');


async function dasbootGen(projectPath) {
const dasBootSourceDirectoryPath = p.join(__dirname, '../dasBoot');
const dasBootLibSourceFilePaths = readDir.readSync(
dasBootSourceDirectoryPath,
['lib/*.js'],
readDir.ABSOLUTE_PATHS
).sort();
const dasBootSourceFilePaths = readDir.readSync(
dasBootSourceDirectoryPath,
['*.js'],
readDir.ABSOLUTE_PATHS
).sort();

const dasBootDestinationFilePath = p.join(projectPath, 'gen', 'dasBoot.js');
const allFiles = dasBootLibSourceFilePaths.concat(dasBootSourceFilePaths);
Promise.all(allFiles.map(file => fs.readFile(file)))
.then(files => fs.writeFile(dasBootDestinationFilePath, Buffer.concat(files)));
return new Promise((resolve, reject) => {
webpack({
entry: [
p.join(__dirname, '..', 'dasBoot', 'bootstrap.js')
],
output: {
path: p.join(projectPath, 'gen'),
filename: 'dasBoot.js',
}
}).run(err => {
err ? reject() : resolve();
});
});
}

module.exports = dasbootGen;
1 change: 0 additions & 1 deletion nin/dasBoot/00_NIN.js

This file was deleted.

21 changes: 0 additions & 21 deletions nin/dasBoot/01_Input.js

This file was deleted.

32 changes: 0 additions & 32 deletions nin/dasBoot/01_Node.js

This file was deleted.

21 changes: 0 additions & 21 deletions nin/dasBoot/01_Output.js

This file was deleted.

50 changes: 26 additions & 24 deletions nin/dasBoot/BEATBEAN.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
(function() {
var framesPerBEAT;
var framesPerBEAT;
window.BEAN = 0;
window.BEAT = false;

initBeatBean = function() {
BEAN = 0;
BEAT = false;
const initBeatBean = function() {
window.BEAN = 0;
window.BEAT = false;

var BEATsPerMinute = PROJECT.music.bpm * PROJECT.music.subdivision;
var BEATsPerSecond = BEATsPerMinute / 60;
var framesPerSecond = 60;
framesPerBEAT = framesPerSecond / BEATsPerSecond;
var BEATsPerMinute = PROJECT.music.bpm * PROJECT.music.subdivision;
var BEATsPerSecond = BEATsPerMinute / 60;
var framesPerSecond = 60;
framesPerBEAT = framesPerSecond / BEATsPerSecond;

BEAN_FOR_FRAME = function(frame) {
return (frame + 1.5) / framesPerBEAT | 0;
};

FRAME_FOR_BEAN = function(bean) {
return (bean * framesPerBEAT - 0.5) | 0;
};
window.BEAN_FOR_FRAME = function(frame) {
return (frame + 1.5) / framesPerBEAT | 0;
};

updateBeatBean = function(frame) {
BEAT = false;
if ((((frame + 1.5) / framesPerBEAT) | 0) >
((frame + 0.5) / framesPerBEAT) | 0) {
BEAT = true;
}
BEAN = (frame + 1.5) / framesPerBEAT | 0;
window.FRAME_FOR_BEAN = function(bean) {
return (bean * framesPerBEAT - 0.5) | 0;
};
})();
};

const updateBeatBean = function(frame) {
window.BEAT = false;
if ((((frame + 1.5) / framesPerBEAT) | 0) >
((frame + 0.5) / framesPerBEAT) | 0) {
window.BEAT = true;
}
window.BEAN = (frame + 1.5) / framesPerBEAT | 0;
};

module.exports = {initBeatBean, updateBeatBean};
2 changes: 2 additions & 0 deletions nin/dasBoot/CameraController.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,5 @@ CameraController.prototype.updateCamera = function(frame) {
//this.visualization.position.add(amount);
}
};

module.exports = CameraController;
2 changes: 2 additions & 0 deletions nin/dasBoot/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,5 @@ Loader.start = function(onprogress, oncomplete) {
Loader.nextLoader.start(onprogress, oncomplete);
Loader.nextLoader = new Loader();
};

module.exports = Loader;
3 changes: 2 additions & 1 deletion nin/dasBoot/NodeManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class NodeManager {

constructor() {
this.nodes = {};
this.graphChangeListeners = [];
Expand Down Expand Up @@ -116,3 +115,5 @@ class NodeManager {
refresh() {
}
}

module.exports = NodeManager;
2 changes: 2 additions & 0 deletions nin/dasBoot/PathController.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,5 @@ PathControllerVisualizer.prototype.generateVisualization = function(spline) {

this.generateJoinSegments();
};

module.exports = PathController;
2 changes: 2 additions & 0 deletions nin/dasBoot/Random.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ function Random(seed){
return result + 0.5;
}
}

module.exports = Random;
53 changes: 24 additions & 29 deletions nin/dasBoot/RootNode.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
(function(NIN) {
'use strict';
class RootNode extends NIN.Node {
constructor(id, options) {
super(id, {
inputs: {screen: new NIN.TextureInput()}
});

class RootNode extends NIN.Node {
constructor(id, options) {
super(id, {
inputs: {screen: new NIN.TextureInput()}
});

this.camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
this.scene = new THREE.Scene();
this.quad = new THREE.Mesh(new THREE.PlaneBufferGeometry(2, 2), null);
this.scene.add(this.quad);
this.material = new THREE.MeshBasicMaterial();
}
this.camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
this.scene = new THREE.Scene();
this.quad = new THREE.Mesh(new THREE.PlaneBufferGeometry(2, 2), null);
this.scene.add(this.quad);
this.material = new THREE.MeshBasicMaterial();
}

render(renderer) {
if(renderer.overrideToScreenTexture) {
this.quad.material = new THREE.MeshBasicMaterial({
map: renderer.overrideToScreenTexture
});
} else {
var A = this.inputs.screen.getValue();
this.quad.material = new THREE.MeshBasicMaterial({
map: A
});
}
renderer.render(this.scene, this.camera);
render(renderer) {
if(renderer.overrideToScreenTexture) {
this.quad.material = new THREE.MeshBasicMaterial({
map: renderer.overrideToScreenTexture
});
} else {
var A = this.inputs.screen.getValue();
this.quad.material = new THREE.MeshBasicMaterial({
map: A
});
}
renderer.render(this.scene, this.camera);
}
}

NIN.RootNode = RootNode;
})(this.NIN);

module.exports = RootNode;
86 changes: 41 additions & 45 deletions nin/dasBoot/ShaderNode.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,43 @@
(function(NIN) {
'use strict';

class ShaderNode extends NIN.Node {
constructor(id, options) {
super(id, {
inputs: options.inputs,
outputs: {
render: new NIN.TextureOutput()
}
});

this.scene = new THREE.Scene();
this.camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 100);
this.renderTarget = new THREE.WebGLRenderTarget(640, 360, {
minFilter: THREE.LinearFilter,
magFilter: THREE.LinearFilter,
format: THREE.RGBFormat
});

const shader = typeof options.shader === 'string'
? SHADERS[options.shader] : options.shader;

this.quad = new THREE.Mesh(
new THREE.PlaneBufferGeometry(2, 2),
new THREE.ShaderMaterial(shader).clone());
this.uniforms = this.quad.material.uniforms;

this.scene.add(this.quad);
this.resize();
}

update() {
}

resize() {
this.renderTarget.setSize(16 * GU, 9 * GU);
}

render(renderer) {
renderer.render(this.scene, this.camera, this.renderTarget, true);
this.outputs.render.setValue(this.renderTarget.texture);
}
class ShaderNode extends NIN.Node {
constructor(id, options) {
super(id, {
inputs: options.inputs,
outputs: {
render: new NIN.TextureOutput()
}
});

this.scene = new THREE.Scene();
this.camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 100);
this.renderTarget = new THREE.WebGLRenderTarget(640, 360, {
minFilter: THREE.LinearFilter,
magFilter: THREE.LinearFilter,
format: THREE.RGBFormat
});

const shader = typeof options.shader === 'string'
? SHADERS[options.shader] : options.shader;

this.quad = new THREE.Mesh(
new THREE.PlaneBufferGeometry(2, 2),
new THREE.ShaderMaterial(shader).clone());
this.uniforms = this.quad.material.uniforms;

this.scene.add(this.quad);
this.resize();
}

NIN.ShaderNode = ShaderNode;
})(this.NIN);
update() {
}

resize() {
this.renderTarget.setSize(16 * GU, 9 * GU);
}

render(renderer) {
renderer.render(this.scene, this.camera, this.renderTarget, true);
this.outputs.render.setValue(this.renderTarget.texture);
}
}

module.exports = ShaderNode;
Loading

0 comments on commit f461a22

Please sign in to comment.