overte-HifiExperiments/scripts/system/fingerPaint/content/brushes/dynamicBrushes/dynamicBrushScript.js
Artur Gomes 5c40a6810e Add drawing in Desktop mode.
Remove dynamic rotation and translation brushes since the movement would
be unsynced after a while, resulting in a poor user experience.
Fix restoring last used settings taking to long, which caused the user
to see the values to change after the tablet application was open.
Fix using a different brush after restarting the app, if drawing before
the brush was reset.
2017-08-16 18:28:55 +01:00

34 lines
1.8 KiB
JavaScript

(function() {
Script.include("dynamicBrushesList.js");
var UPDATE_TIME = 33; //run at aproximatelly 30fps
var self = this;
this.preload = function(entityID) {
//print("After adding script 2 : " + JSON.stringify(Entities.getEntityProperties(entityID)));
self.intervalID = Script.setInterval(function() {
if (Vec3.withinEpsilon(MyAvatar.position, Entities.getEntityProperties(entityID).position, 3)) {
var userData = Entities.getEntityProperties(entityID).userData;
//print("UserData: " + userData);
if (userData) {
var userDataObject = JSON.parse(userData);
var animationObject = userDataObject.animations;
//print("Playing animation " + JSON.stringify(animationObject));
var newAnimationObject = null;
if (!userDataObject.timeFromLastAnimation) {
userDataObject.timeFromLastAnimation = Date.now();
}
Object.keys(animationObject).forEach(function(animationName) {
newAnimationObject = animationObject[animationName];
//print("Proto 0001: " + JSON.stringify(newAnimationObject));
newAnimationObject.__proto__ = DynamicBrushesInfo[animationName].proto;
//print("time from last draw " + (Date.now() - userDataObject.animations.timeFromLastDraw));
newAnimationObject.onUpdate(Date.now() - userDataObject.timeFromLastAnimation, entityID);
});
}
}
}, UPDATE_TIME);
};
this.unload = function() {
Script.clearInterval(self.intervalID);
}
});