mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 21:36:47 +02:00
made the script work with the provided assets.
This commit is contained in:
parent
d805f75d55
commit
01855c0d9c
4 changed files with 127 additions and 0 deletions
|
@ -0,0 +1,84 @@
|
||||||
|
//
|
||||||
|
// Created by Alan-Michael Moody on 5/2/2017
|
||||||
|
//
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
var pivotID, needleID;
|
||||||
|
|
||||||
|
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 === "pivot") {
|
||||||
|
pivotID = childZero.id;
|
||||||
|
needleID = childOne.id;
|
||||||
|
} else {
|
||||||
|
pivotID = childOne.id;
|
||||||
|
needleID = 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);
|
||||||
|
|
||||||
|
// 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.editEntity(pivotID, {
|
||||||
|
localRotation: Quat.fromPitchYawRollDegrees(0, 0, scaledDegrees)
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Script.setInterval(function () {
|
||||||
|
scanEngine();
|
||||||
|
}, SCAN_RATE);
|
||||||
|
|
||||||
|
});
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,43 @@
|
||||||
|
//
|
||||||
|
// 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/applauseOmeterTextured.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})
|
||||||
|
},
|
||||||
|
pivot:{
|
||||||
|
type:'Sphere',
|
||||||
|
parentID: '',
|
||||||
|
userData: '{"name":"pivot"}',
|
||||||
|
dimensions: {x: .05, y: .05, z: .05},
|
||||||
|
lifetime: '3600',
|
||||||
|
position: Vec3.sum(pos, {x: 0, y: 3.385, z: 0.2})
|
||||||
|
},
|
||||||
|
needle: {
|
||||||
|
type: 'Model',
|
||||||
|
modelURL:'https://binaryrelay.com/files/public-docs/hifi/meter/applauseOmeterNeedleTextured.fbx',
|
||||||
|
parentID: '',
|
||||||
|
userData: '{"name":"needle"}',
|
||||||
|
dimensions: {x: .286, y: 1.12, z: .07},
|
||||||
|
lifetime: '3600',
|
||||||
|
position: Vec3.sum(pos, {x: 0, y: 3.85, z: 0.2})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
meter.pivot.parentID = Entities.addEntity(meter.stand);
|
||||||
|
meter.needle.parentID = Entities.addEntity(meter.pivot);
|
||||||
|
Entities.addEntity(meter.needle);
|
||||||
|
|
||||||
|
|
||||||
|
})();
|
Loading…
Reference in a new issue