HitOnce With Graphics
by pkin159
HTML
<div>
<button id='hitOnce' class='buttonClass'>Hit Once</button>
<br/>
<button id='hitMany' class='buttonClass'>Hit Many</button>
<br/>
<button id='playScore' class='buttonClass'>Play Score</button>
</div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r70/three.min.js"></script>
<script src="https://dl.dropboxusercontent.com/u/3587259/Code/Threejs/OrbitControls.js"></script>
<script src="https://pkin159.github.io/project/js/dat.gui.min.js"></script>
CSS
#info {
position: absolute;
top: 0px;
width: 100%;
padding: 10px;
text-align: center;
color: #ff0000
}
#gui {
position: absolute;
top: 40px;
left: 20px;
height: 350px;
}
JavaScript
var Stick = function () {
// properties
this.T = 3; // in seconds
this.keys = [];
this.startTime = 0;
this.angle = 0; // for 'text-based' rendering
this.mesh = THREE.Object3D();
this.newMesh = function(){
a = new THREE.Object3D();
var geometry = new THREE.CylinderGeometry(1.4, 1.4, 70, 32);
var material = new THREE.MeshPhongMaterial({
color: 0xffff00
});
var cylinder = new THREE.Mesh(geometry, material);
cylinder.rotation.x = Math.PI / 2;
cylinder.position.set(0, 0, -40);
var geometry1 = new THREE.CylinderGeometry(1.4, 0.8, 20, 32);
var cylinder2 = new THREE.Mesh(geometry1, material);
cylinder2.rotation.x = Math.PI / 2;
cylinder2.position.set(0, 0, -85);
var geometry3 = new THREE.SphereGeometry(1.5, 32, 32);
var sphere = new THREE.Mesh(geometry3, material);
sphere.position.set(0, 0, -95);
a.add(cylinder);
a.add(cylinder2);
a.add(sphere);
this.mesh = a;
};
// methods
this.setT = function (period) {
this.T = period;
};
this.setKeys = function (keys) {
this.keys = keys;
};
this.setMaxKeysValue = function (intensity){
var max = 0, maxi;
for( i = 0; this.keys[i]; i++){
if(this.keys[i].value > max){
max = this.keys[i].value;
maxi = i;
}
}
this.keys[maxi].value = intensity;
}
this.interpolate = function (s) { // normalized time
if (s > 1) // end of cycle
return this.keys[this.keys.length - 1].value;
for (var i = 1; i < this.keys.length; i++) {
if (s < this.keys[i].timeS) break;
}
// between i-1 & i
var vv = this.keys[i - 1].value + (s - this.keys[i - 1].timeS) / (this.keys[i].timeS - this.keys[i - 1].timeS) * (this.keys[i].value - this.keys[i - 1].value);
return vv;
};
this.update = function (time) { // time: elapsedTime
var s = (time -...