diff --git a/unpublishedScripts/marketplace/audience applause meter/bakedTextMeter.js b/unpublishedScripts/marketplace/audience applause meter/bakedTextMeter.js new file mode 100644 index 0000000000..9dc56620ef --- /dev/null +++ b/unpublishedScripts/marketplace/audience applause meter/bakedTextMeter.js @@ -0,0 +1,82 @@ +// +// 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; //shifiting the scale to 0 - 255 + var xShift = norm / 52; // changing scale from 0-100 to 0-1.9 ish + var normShift = xShift - 0.88; //shifitg local displacement (-0.90) + 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); + +}); diff --git a/unpublishedScripts/marketplace/audience applause meter/meter.js b/unpublishedScripts/marketplace/audience applause meter/meter.js new file mode 100644 index 0000000000..24aed492c0 --- /dev/null +++ b/unpublishedScripts/marketplace/audience applause meter/meter.js @@ -0,0 +1,95 @@ +// +// 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); + JSON.stringify(barProperties) ; + + var colorShift = 2.55 * norm; //shifiting the scale to 0 - 255 + var xShift = norm / 100; // changing scale from 0-100 to 0-1 + var normShift = xShift - .5; //shifitg 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); + +}); diff --git a/unpublishedScripts/marketplace/audience applause meter/models/meter-plastic.fbx b/unpublishedScripts/marketplace/audience applause meter/models/meter-plastic.fbx new file mode 100644 index 0000000000..940ae0d867 Binary files /dev/null and b/unpublishedScripts/marketplace/audience applause meter/models/meter-plastic.fbx differ diff --git a/unpublishedScripts/marketplace/audience applause meter/models/meter-text-entity.fbx b/unpublishedScripts/marketplace/audience applause meter/models/meter-text-entity.fbx new file mode 100644 index 0000000000..fd930d3072 Binary files /dev/null and b/unpublishedScripts/marketplace/audience applause meter/models/meter-text-entity.fbx differ diff --git a/unpublishedScripts/marketplace/audience applause meter/models/meter-wood.fbx b/unpublishedScripts/marketplace/audience applause meter/models/meter-wood.fbx new file mode 100644 index 0000000000..86b87832c4 Binary files /dev/null and b/unpublishedScripts/marketplace/audience applause meter/models/meter-wood.fbx differ diff --git a/unpublishedScripts/marketplace/audience applause meter/rezMeter.js b/unpublishedScripts/marketplace/audience applause meter/rezMeter.js new file mode 100644 index 0000000000..d3fba9ea56 --- /dev/null +++ b/unpublishedScripts/marketplace/audience applause meter/rezMeter.js @@ -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 diff --git a/unpublishedScripts/marketplace/audience applause meter/rezPlasticMeter.js b/unpublishedScripts/marketplace/audience applause meter/rezPlasticMeter.js new file mode 100644 index 0000000000..781585ebf6 --- /dev/null +++ b/unpublishedScripts/marketplace/audience applause meter/rezPlasticMeter.js @@ -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); + + +})(); diff --git a/unpublishedScripts/marketplace/audience applause meter/rezTextEntityMeter.js b/unpublishedScripts/marketplace/audience applause meter/rezTextEntityMeter.js new file mode 100644 index 0000000000..771bdfd3d4 --- /dev/null +++ b/unpublishedScripts/marketplace/audience applause meter/rezTextEntityMeter.js @@ -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.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); + + +})(); diff --git a/unpublishedScripts/marketplace/audience applause meter/rezWoodMeter.js b/unpublishedScripts/marketplace/audience applause meter/rezWoodMeter.js new file mode 100644 index 0000000000..6b11a11d97 --- /dev/null +++ b/unpublishedScripts/marketplace/audience applause meter/rezWoodMeter.js @@ -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-text.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); + + +})(); diff --git a/unpublishedScripts/marketplace/audience applause meter/textEntityMeter.js b/unpublishedScripts/marketplace/audience applause meter/textEntityMeter.js new file mode 100644 index 0000000000..c3d120b727 --- /dev/null +++ b/unpublishedScripts/marketplace/audience applause meter/textEntityMeter.js @@ -0,0 +1,93 @@ +// +// 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; //shifiting the scale to 0 - 255 + var xShift = norm / 52; // changing scale from 0-100 to 0-1.9 ish + var normShift = xShift - 0.88; //shifitg 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); + +}); diff --git a/unpublishedScripts/marketplace/audience applause meter/textures/meter.diffuse.psd b/unpublishedScripts/marketplace/audience applause meter/textures/meter.diffuse.psd new file mode 100644 index 0000000000..07fed10d31 Binary files /dev/null and b/unpublishedScripts/marketplace/audience applause meter/textures/meter.diffuse.psd differ diff --git a/unpublishedScripts/marketplace/audience applause meter/textures/plastic/meter.done.plastic_diffuse.png b/unpublishedScripts/marketplace/audience applause meter/textures/plastic/meter.done.plastic_diffuse.png new file mode 100644 index 0000000000..4e7a3110ab Binary files /dev/null and b/unpublishedScripts/marketplace/audience applause meter/textures/plastic/meter.done.plastic_diffuse.png differ diff --git a/unpublishedScripts/marketplace/audience applause meter/textures/plastic/meter.done.plastic_diffuse_text.png b/unpublishedScripts/marketplace/audience applause meter/textures/plastic/meter.done.plastic_diffuse_text.png new file mode 100644 index 0000000000..402f2ecf3f Binary files /dev/null and b/unpublishedScripts/marketplace/audience applause meter/textures/plastic/meter.done.plastic_diffuse_text.png differ diff --git a/unpublishedScripts/marketplace/audience applause meter/textures/plastic/meter.done.plastic_emissive.png b/unpublishedScripts/marketplace/audience applause meter/textures/plastic/meter.done.plastic_emissive.png new file mode 100644 index 0000000000..cb5ee722f2 Binary files /dev/null and b/unpublishedScripts/marketplace/audience applause meter/textures/plastic/meter.done.plastic_emissive.png differ diff --git a/unpublishedScripts/marketplace/audience applause meter/textures/plastic/meter.done.plastic_normal_map.png b/unpublishedScripts/marketplace/audience applause meter/textures/plastic/meter.done.plastic_normal_map.png new file mode 100644 index 0000000000..c96e377a59 Binary files /dev/null and b/unpublishedScripts/marketplace/audience applause meter/textures/plastic/meter.done.plastic_normal_map.png differ diff --git a/unpublishedScripts/marketplace/audience applause meter/textures/plastic/meter.done.plastic_reflection.png b/unpublishedScripts/marketplace/audience applause meter/textures/plastic/meter.done.plastic_reflection.png new file mode 100644 index 0000000000..a3023ced35 Binary files /dev/null and b/unpublishedScripts/marketplace/audience applause meter/textures/plastic/meter.done.plastic_reflection.png differ diff --git a/unpublishedScripts/marketplace/audience applause meter/textures/plastic/meter.done.plastic_roughness.png b/unpublishedScripts/marketplace/audience applause meter/textures/plastic/meter.done.plastic_roughness.png new file mode 100644 index 0000000000..f9fcc2040f Binary files /dev/null and b/unpublishedScripts/marketplace/audience applause meter/textures/plastic/meter.done.plastic_roughness.png differ diff --git a/unpublishedScripts/marketplace/audience applause meter/textures/wood/meter.done_diffuse.png b/unpublishedScripts/marketplace/audience applause meter/textures/wood/meter.done_diffuse.png new file mode 100644 index 0000000000..8243b4e250 Binary files /dev/null and b/unpublishedScripts/marketplace/audience applause meter/textures/wood/meter.done_diffuse.png differ diff --git a/unpublishedScripts/marketplace/audience applause meter/textures/wood/meter.done_diffuse_text.png b/unpublishedScripts/marketplace/audience applause meter/textures/wood/meter.done_diffuse_text.png new file mode 100644 index 0000000000..b9d32a5bb8 Binary files /dev/null and b/unpublishedScripts/marketplace/audience applause meter/textures/wood/meter.done_diffuse_text.png differ diff --git a/unpublishedScripts/marketplace/audience applause meter/textures/wood/meter.done_emissive.png b/unpublishedScripts/marketplace/audience applause meter/textures/wood/meter.done_emissive.png new file mode 100644 index 0000000000..cb5ee722f2 Binary files /dev/null and b/unpublishedScripts/marketplace/audience applause meter/textures/wood/meter.done_emissive.png differ diff --git a/unpublishedScripts/marketplace/audience applause meter/textures/wood/meter.done_normal_map.png b/unpublishedScripts/marketplace/audience applause meter/textures/wood/meter.done_normal_map.png new file mode 100644 index 0000000000..3029bf60c4 Binary files /dev/null and b/unpublishedScripts/marketplace/audience applause meter/textures/wood/meter.done_normal_map.png differ diff --git a/unpublishedScripts/marketplace/audience applause meter/textures/wood/meter.done_reflection.png b/unpublishedScripts/marketplace/audience applause meter/textures/wood/meter.done_reflection.png new file mode 100644 index 0000000000..a3023ced35 Binary files /dev/null and b/unpublishedScripts/marketplace/audience applause meter/textures/wood/meter.done_reflection.png differ diff --git a/unpublishedScripts/marketplace/audience applause meter/textures/wood/meter.done_roughness.png b/unpublishedScripts/marketplace/audience applause meter/textures/wood/meter.done_roughness.png new file mode 100644 index 0000000000..89d439c404 Binary files /dev/null and b/unpublishedScripts/marketplace/audience applause meter/textures/wood/meter.done_roughness.png differ