|
@ -0,0 +1,70 @@
|
|||
//
|
||||
// Created by Alan-Michael Moody on 5/2/2017
|
||||
//
|
||||
|
||||
(function () {
|
||||
var thisEntityID;
|
||||
|
||||
this.preload = function (entityID) {
|
||||
thisEntityID = entityID;
|
||||
};
|
||||
|
||||
var SCAN_RATE = 100; //ms
|
||||
var REFERENCE_FRAME_COUNT = 30;
|
||||
var MAX_AUDIO_THRESHOLD = 16000;
|
||||
|
||||
var framePool = [];
|
||||
|
||||
function scanEngine() {
|
||||
var avatarLoudnessPool = [];
|
||||
|
||||
function average(a) {
|
||||
var sum = 0;
|
||||
var total = a.length;
|
||||
for (var i = 0; i < total; i++) {
|
||||
sum += a[i];
|
||||
}
|
||||
return Math.round(sum / total);
|
||||
}
|
||||
|
||||
function audioClamp(input) {
|
||||
if (input > MAX_AUDIO_THRESHOLD) return MAX_AUDIO_THRESHOLD;
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
var avatars = AvatarList.getAvatarIdentifiers();
|
||||
avatars.forEach(function (id) {
|
||||
var avatar = AvatarList.getAvatar(id);
|
||||
avatarLoudnessPool.push(audioClamp(Math.round(avatar.audioLoudness)));
|
||||
|
||||
});
|
||||
|
||||
|
||||
framePool.push(average(avatarLoudnessPool));
|
||||
if (framePool.length >= REFERENCE_FRAME_COUNT) {
|
||||
framePool.shift();
|
||||
}
|
||||
|
||||
function normalizedAverage(a) {
|
||||
a = a.map(function (v) {
|
||||
return Math.round(( 100 / MAX_AUDIO_THRESHOLD ) * v);
|
||||
});
|
||||
return average(a);
|
||||
}
|
||||
|
||||
var norm = normalizedAverage(framePool);
|
||||
|
||||
// we have a range of 55 to -53 degrees for the needle
|
||||
|
||||
var scaledDegrees = (norm / -.94) + 54.5; // shifting scale from 100 to 55 to -53 ish its more like -51 ;
|
||||
|
||||
Entities.setAbsoluteJointRotationInObjectFrame(thisEntityID, 0, Quat.fromPitchYawRollDegrees(0, 0, scaledDegrees));
|
||||
|
||||
}
|
||||
|
||||
Script.setInterval(function () {
|
||||
scanEngine();
|
||||
}, SCAN_RATE);
|
||||
|
||||
});
|
|
@ -0,0 +1,79 @@
|
|||
//
|
||||
// Created by Alan-Michael Moody on 4/17/2017
|
||||
//
|
||||
|
||||
(function () {
|
||||
var barID;
|
||||
|
||||
this.preload = function (entityID) {
|
||||
var children = Entities.getChildrenIDs(entityID);
|
||||
var childZero = Entities.getEntityProperties(children[0]);
|
||||
barID = childZero.id;
|
||||
};
|
||||
|
||||
var SCAN_RATE = 100; //ms
|
||||
var REFERENCE_FRAME_COUNT = 30;
|
||||
var MAX_AUDIO_THRESHOLD = 16000;
|
||||
|
||||
var framePool = [];
|
||||
|
||||
function scanEngine() {
|
||||
var avatarLoudnessPool = [];
|
||||
|
||||
function average(a) {
|
||||
var sum = 0;
|
||||
var total = a.length;
|
||||
for (var i = 0; i < total; i++) {
|
||||
sum += a[i];
|
||||
}
|
||||
return Math.round(sum / total);
|
||||
}
|
||||
|
||||
function audioClamp(input) {
|
||||
if (input > MAX_AUDIO_THRESHOLD) return MAX_AUDIO_THRESHOLD;
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
var avatars = AvatarList.getAvatarIdentifiers();
|
||||
avatars.forEach(function (id) {
|
||||
var avatar = AvatarList.getAvatar(id);
|
||||
avatarLoudnessPool.push(audioClamp(Math.round(avatar.audioLoudness)));
|
||||
});
|
||||
|
||||
|
||||
framePool.push(average(avatarLoudnessPool));
|
||||
if (framePool.length >= REFERENCE_FRAME_COUNT) {
|
||||
framePool.shift();
|
||||
}
|
||||
|
||||
function normalizedAverage(a) {
|
||||
a = a.map(function (v) {
|
||||
return Math.round(( 100 / MAX_AUDIO_THRESHOLD ) * v);
|
||||
});
|
||||
return average(a);
|
||||
}
|
||||
|
||||
var norm = normalizedAverage(framePool);
|
||||
|
||||
|
||||
var barProperties = Entities.getEntityProperties(barID);
|
||||
|
||||
var colorShift = 2.55 * norm; //shifting the scale to 0 - 255
|
||||
var xShift = norm / 52; // changing scale from 0-100 to 0-1.9 ish
|
||||
var normShift = xShift - 0.88; //shifting local displacement (-0.88)
|
||||
var halfShift = xShift / 2;
|
||||
Entities.editEntity(barID, {
|
||||
dimensions: {x: xShift, y: barProperties.dimensions.y, z: barProperties.dimensions.z},
|
||||
localPosition: {x: normShift - (halfShift), y: -0.0625, z: -0.015},
|
||||
color: {red: colorShift, green: barProperties.color.green, blue: barProperties.color.blue}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
Script.setInterval(function () {
|
||||
scanEngine();
|
||||
}, SCAN_RATE);
|
||||
|
||||
});
|
|
@ -0,0 +1,92 @@
|
|||
//
|
||||
// Created by Alan-Michael Moody on 4/17/2017
|
||||
//
|
||||
|
||||
(function () {
|
||||
var barID, textID;
|
||||
|
||||
this.preload = function (entityID) {
|
||||
|
||||
var children = Entities.getChildrenIDs(entityID);
|
||||
var childZero = Entities.getEntityProperties(children[0]);
|
||||
var childOne = Entities.getEntityProperties(children[1]);
|
||||
var childZeroUserData = JSON.parse(Entities.getEntityProperties(children[0]).userData);
|
||||
|
||||
if (childZeroUserData.name === "bar") {
|
||||
barID = childZero.id;
|
||||
textID = childOne.id;
|
||||
} else {
|
||||
barID = childOne.id;
|
||||
textID = childZero.id;
|
||||
}
|
||||
};
|
||||
|
||||
var SCAN_RATE = 100; //ms
|
||||
var REFERENCE_FRAME_COUNT = 30;
|
||||
var MAX_AUDIO_THRESHOLD = 16000;
|
||||
|
||||
var framePool = [];
|
||||
|
||||
function scanEngine() {
|
||||
var avatarLoudnessPool = [];
|
||||
|
||||
function average(a) {
|
||||
var sum = 0;
|
||||
var total = a.length;
|
||||
for (var i = 0; i < total; i++) {
|
||||
sum += a[i];
|
||||
}
|
||||
return Math.round(sum / total);
|
||||
}
|
||||
|
||||
function audioClamp(input) {
|
||||
if (input > MAX_AUDIO_THRESHOLD) return MAX_AUDIO_THRESHOLD;
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
var avatars = AvatarList.getAvatarIdentifiers();
|
||||
avatars.forEach(function (id) {
|
||||
var avatar = AvatarList.getAvatar(id);
|
||||
avatarLoudnessPool.push(audioClamp(Math.round(avatar.audioLoudness)));
|
||||
|
||||
});
|
||||
|
||||
|
||||
framePool.push(average(avatarLoudnessPool));
|
||||
if (framePool.length >= REFERENCE_FRAME_COUNT) {
|
||||
framePool.shift();
|
||||
}
|
||||
|
||||
function normalizedAverage(a) {
|
||||
a = a.map(function (v) {
|
||||
return Math.round(( 100 / MAX_AUDIO_THRESHOLD ) * v);
|
||||
});
|
||||
return average(a);
|
||||
}
|
||||
|
||||
var norm = normalizedAverage(framePool);
|
||||
|
||||
Entities.editEntity(textID, {text: "Loudness: % " + norm});
|
||||
|
||||
var barProperties = Entities.getEntityProperties(barID);
|
||||
|
||||
|
||||
var colorShift = 2.55 * norm; //shifting the scale to 0 - 255
|
||||
var xShift = norm / 100; // changing scale from 0-100 to 0-1
|
||||
var normShift = xShift - .5; //shifting scale form 0-1 to -.5 to .5
|
||||
var halfShift = xShift / 2 ;
|
||||
Entities.editEntity(barID, {
|
||||
dimensions: {x: xShift, y: barProperties.dimensions.y, z: barProperties.dimensions.z},
|
||||
localPosition: {x: normShift - (halfShift), y: 0, z: 0.1},
|
||||
color: {red: colorShift, green: barProperties.color.green, blue: barProperties.color.blue}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
Script.setInterval(function () {
|
||||
scanEngine();
|
||||
}, SCAN_RATE);
|
||||
|
||||
});
|
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// Created by Alan-Michael Moody on 5/2/2017
|
||||
//
|
||||
|
||||
'use strict';
|
||||
|
||||
(function () {
|
||||
var pos = Vec3.sum(MyAvatar.position, Quat.getFront(MyAvatar.orientation));
|
||||
|
||||
var meter = {
|
||||
stand: {
|
||||
type: 'Model',
|
||||
modelURL: 'https://binaryrelay.com/files/public-docs/hifi/meter/applauseOmeter.fbx',
|
||||
lifetime: '3600',
|
||||
script: 'https://binaryrelay.com/files/public-docs/hifi/meter/applauseOmeter.js',
|
||||
position: Vec3.sum(pos, {x: 0, y: 2.0, z: 0})
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
Entities.addEntity(meter.stand);
|
||||
|
||||
})();
|
|
@ -0,0 +1,67 @@
|
|||
//
|
||||
// Created by Alan-Michael Moody on 4/17/2017
|
||||
//
|
||||
|
||||
"use strict";
|
||||
|
||||
(function () { // BEGIN LOCAL_SCOPE
|
||||
var pos = Vec3.sum(MyAvatar.position, Quat.getFront(MyAvatar.orientation));
|
||||
|
||||
var graph = {
|
||||
background: {
|
||||
type: "Box",
|
||||
dimensions: {x: 1, y: 1, z: .1},
|
||||
color: {
|
||||
red: 128,
|
||||
green: 128,
|
||||
blue: 128
|
||||
},
|
||||
lifetime: "3600",
|
||||
script: "https://binaryrelay.com/files/public-docs/hifi/meter/basic/meter.js",
|
||||
position: pos
|
||||
},
|
||||
bar: {
|
||||
type: "Box",
|
||||
parentID: "",
|
||||
userData: '{"name":"bar"}',
|
||||
dimensions: {x: .05, y: .25, z: .1},
|
||||
color: {
|
||||
red: 0,
|
||||
green: 0,
|
||||
blue: 0
|
||||
},
|
||||
lifetime: "3600",
|
||||
position: Vec3.sum(pos, {x: -0.495, y: 0, z: 0.1})
|
||||
},
|
||||
displayText: {
|
||||
type: "Text",
|
||||
parentID: "",
|
||||
userData: '{"name":"displayText"}',
|
||||
text: "Loudness: % ",
|
||||
textColor: {
|
||||
red: 0,
|
||||
green: 0,
|
||||
blue: 0
|
||||
},
|
||||
backgroundColor: {
|
||||
red: 128,
|
||||
green: 128,
|
||||
blue: 128
|
||||
},
|
||||
visible: 0.5,
|
||||
dimensions: {x: 0.70, y: 0.15, z: 0.1},
|
||||
lifetime: "3600",
|
||||
position: Vec3.sum(pos, {x: 0, y: 0.4, z: 0.06})
|
||||
}
|
||||
};
|
||||
|
||||
var background = Entities.addEntity(graph.background);
|
||||
|
||||
graph.bar.parentID = background;
|
||||
graph.displayText.parentID = background;
|
||||
|
||||
var bar = Entities.addEntity(graph.bar);
|
||||
var displayText = Entities.addEntity(graph.displayText);
|
||||
|
||||
|
||||
})(); // END LOCAL_SCOPE
|
|
@ -0,0 +1,43 @@
|
|||
//
|
||||
// Created by Alan-Michael Moody on 4/17/2017
|
||||
//
|
||||
|
||||
"use strict";
|
||||
|
||||
(function () {
|
||||
var pos = Vec3.sum(MyAvatar.position, Quat.getFront(MyAvatar.orientation));
|
||||
|
||||
var graph = {
|
||||
background: {
|
||||
type: "Model",
|
||||
modelURL: "https://binaryrelay.com/files/public-docs/hifi/meter/plastic/meter-plastic.fbx",
|
||||
color: {
|
||||
red: 128,
|
||||
green: 128,
|
||||
blue: 128
|
||||
},
|
||||
lifetime: "3600",
|
||||
script: "https://binaryrelay.com/files/public-docs/hifi/meter/plastic/meter.js",
|
||||
position: pos
|
||||
},
|
||||
bar: {
|
||||
type: "Box",
|
||||
parentID: "",
|
||||
userData: '{"name":"bar"}',
|
||||
dimensions: {x: .05, y: .245, z: .07},
|
||||
color: {
|
||||
red: 0,
|
||||
green: 0,
|
||||
blue: 0
|
||||
},
|
||||
lifetime: "3600",
|
||||
position: Vec3.sum(pos, {x: -0.90, y: 0, z: -0.15})
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
graph.bar.parentID = Entities.addEntity(graph.background);
|
||||
Entities.addEntity(graph.bar);
|
||||
|
||||
|
||||
})();
|
|
@ -0,0 +1,67 @@
|
|||
//
|
||||
// Created by Alan-Michael Moody on 4/17/2017
|
||||
//
|
||||
|
||||
"use strict";
|
||||
|
||||
(function () {
|
||||
var pos = Vec3.sum(MyAvatar.position, Quat.getFront(MyAvatar.orientation));
|
||||
|
||||
var graph = {
|
||||
background: {
|
||||
type: "Model",
|
||||
modelURL: "https://binaryrelay.com/files/public-docs/hifi/meter/text-entity/meter-text-entity.fbx",
|
||||
color: {
|
||||
red: 128,
|
||||
green: 128,
|
||||
blue: 128
|
||||
},
|
||||
lifetime: "3600",
|
||||
script: "https://binaryrelay.com/files/public-docs/hifi/meter/text-entity/meter.js",
|
||||
position: pos
|
||||
},
|
||||
bar: {
|
||||
type: "Box",
|
||||
parentID: "",
|
||||
userData: '{"name":"bar"}',
|
||||
dimensions: {x: .05, y: .245, z: .07},
|
||||
color: {
|
||||
red: 0,
|
||||
green: 0,
|
||||
blue: 0
|
||||
},
|
||||
lifetime: "3600",
|
||||
position: Vec3.sum(pos, {x: -0.88, y: 0, z: -0.15})
|
||||
},
|
||||
displayText: {
|
||||
type: "Text",
|
||||
parentID: "",
|
||||
userData: '{"name":"displayText"}',
|
||||
text: "Make Some Noise:",
|
||||
textColor: {
|
||||
red: 0,
|
||||
green: 0,
|
||||
blue: 0
|
||||
},
|
||||
backgroundColor: {
|
||||
red: 255,
|
||||
green: 255,
|
||||
blue: 255
|
||||
},
|
||||
dimensions: {x: .82, y: 0.115, z: 0.15},
|
||||
lifetime: "3600",
|
||||
lineHeight: .08,
|
||||
position: Vec3.sum(pos, {x: -0.2, y: 0.175, z: -0.035})
|
||||
}
|
||||
};
|
||||
|
||||
var background = Entities.addEntity(graph.background);
|
||||
|
||||
graph.bar.parentID = background;
|
||||
graph.displayText.parentID = background;
|
||||
|
||||
var bar = Entities.addEntity(graph.bar);
|
||||
var displayText = Entities.addEntity(graph.displayText);
|
||||
|
||||
|
||||
})();
|
|
@ -0,0 +1,42 @@
|
|||
//
|
||||
// Created by Alan-Michael Moody on 4/17/2017
|
||||
//
|
||||
|
||||
"use strict";
|
||||
|
||||
(function () {
|
||||
var pos = Vec3.sum(MyAvatar.position, Quat.getFront(MyAvatar.orientation));
|
||||
|
||||
var graph = {
|
||||
background: {
|
||||
type: "Model",
|
||||
modelURL: "https://binaryrelay.com/files/public-docs/hifi/meter/wood/meter-wood.fbx",
|
||||
color: {
|
||||
red: 128,
|
||||
green: 128,
|
||||
blue: 128
|
||||
},
|
||||
lifetime: "3600",
|
||||
script: "https://binaryrelay.com/files/public-docs/hifi/meter/wood/meter.js",
|
||||
position: pos
|
||||
},
|
||||
bar: {
|
||||
type: "Box",
|
||||
parentID: "",
|
||||
userData: '{"name":"bar"}',
|
||||
dimensions: {x: .05, y: .245, z: .07},
|
||||
color: {
|
||||
red: 0,
|
||||
green: 0,
|
||||
blue: 0
|
||||
},
|
||||
lifetime: "3600",
|
||||
position: Vec3.sum(pos, {x: -0.88, y: 0, z: -0.15})
|
||||
}
|
||||
};
|
||||
|
||||
graph.bar.parentID = Entities.addEntity(graph.background);
|
||||
Entities.addEntity(graph.bar);
|
||||
|
||||
|
||||
})();
|
|
@ -0,0 +1,89 @@
|
|||
//
|
||||
// Created by Alan-Michael Moody on 4/17/2017
|
||||
//
|
||||
|
||||
(function () {
|
||||
var barID, textID, originalText;
|
||||
|
||||
this.preload = function (entityID) {
|
||||
|
||||
var children = Entities.getChildrenIDs(entityID);
|
||||
var childZero = Entities.getEntityProperties(children[0]);
|
||||
var childOne = Entities.getEntityProperties(children[1]);
|
||||
var childZeroUserData = JSON.parse(Entities.getEntityProperties(children[0]).userData);
|
||||
|
||||
if (childZeroUserData.name === "bar") {
|
||||
barID = childZero.id;
|
||||
textID = childOne.id;
|
||||
originalText = childOne.text
|
||||
} else {
|
||||
barID = childOne.id;
|
||||
textID = childZero.id;
|
||||
originalText = childZero.text;
|
||||
}
|
||||
};
|
||||
|
||||
var SCAN_RATE = 100; //ms
|
||||
var REFERENCE_FRAME_COUNT = 30;
|
||||
var MAX_AUDIO_THRESHOLD = 16000;
|
||||
|
||||
var framePool = [];
|
||||
|
||||
function scanEngine() {
|
||||
var avatarLoudnessPool = [];
|
||||
|
||||
function average(a) {
|
||||
var sum = 0;
|
||||
var total = a.length;
|
||||
for (var i = 0; i < total; i++) {
|
||||
sum += a[i];
|
||||
}
|
||||
return Math.round(sum / total);
|
||||
}
|
||||
|
||||
function audioClamp(input) {
|
||||
if (input > MAX_AUDIO_THRESHOLD) return MAX_AUDIO_THRESHOLD;
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
var avatars = AvatarList.getAvatarIdentifiers();
|
||||
avatars.forEach(function (id) {
|
||||
var avatar = AvatarList.getAvatar(id);
|
||||
avatarLoudnessPool.push(audioClamp(Math.round(avatar.audioLoudness)));
|
||||
});
|
||||
|
||||
|
||||
framePool.push(average(avatarLoudnessPool));
|
||||
if (framePool.length >= REFERENCE_FRAME_COUNT) {
|
||||
framePool.shift();
|
||||
}
|
||||
|
||||
function normalizedAverage(a) {
|
||||
a = a.map(function (v) {
|
||||
return Math.round(( 100 / MAX_AUDIO_THRESHOLD ) * v);
|
||||
});
|
||||
return average(a);
|
||||
}
|
||||
|
||||
var norm = normalizedAverage(framePool);
|
||||
Entities.editEntity(textID, {text: originalText + " % " + norm});
|
||||
|
||||
var barProperties = Entities.getEntityProperties(barID);
|
||||
|
||||
var colorShift = 2.55 * norm; //shifting the scale to 0 - 255
|
||||
var xShift = norm / 52; // changing scale from 0-100 to 0-1.9 ish
|
||||
var normShift = xShift - 0.88; //shifting local displacement (-0.88)
|
||||
var halfShift = xShift / 2;
|
||||
Entities.editEntity(barID, {
|
||||
dimensions: {x: xShift, y: barProperties.dimensions.y, z: barProperties.dimensions.z},
|
||||
localPosition: {x: normShift - ( halfShift ), y: -0.0625, z: -0.015},
|
||||
color: {red: colorShift, green: barProperties.color.green, blue: barProperties.color.blue}
|
||||
});
|
||||
}
|
||||
|
||||
Script.setInterval(function () {
|
||||
scanEngine();
|
||||
}, SCAN_RATE);
|
||||
|
||||
});
|
After Width: | Height: | Size: 399 KiB |
After Width: | Height: | Size: 410 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 2.1 MiB |
After Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 1.2 MiB |
After Width: | Height: | Size: 1.4 MiB |
After Width: | Height: | Size: 1.4 MiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 651 KiB |
After Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 528 KiB |