Don't use entity creation library (reduce risk); use remote URL for broadcast image entity URLs

This commit is contained in:
Zach Fox 2019-08-22 13:58:35 -07:00
parent a086d6fe6d
commit 44ac3f3a7a
2 changed files with 33 additions and 180 deletions

View file

@ -1,153 +0,0 @@
//
// entityMaker.js
// Created by Milad Nazeri on 2019-02-19
// Copyright 2019 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// A helper library to make entities
//
Script.require('./objectAssign.js');
function EntityMaker(type) {
this.properties = {};
this.cache = {};
this.id = null;
this.created = null;
this.type = type;
}
// *************************************
// START API
// *************************************
// #region API
// Add properties to the cache / temporary storage
function add(props){
// You can either add an object of props or 2 arguments as key and value
if (arguments.length === 2) {
var property = arguments[0];
var value = arguments[1];
props = {};
props[property] = value;
}
this.properties = Object.assign({}, this.properties, props);
this.cache = Object.assign({}, this.cache, this.properties);
return this;
}
// Sends the current temporary stroage to edit the entity
function sync(){
Entities.editEntity(this.id, this.properties);
this.properties = {};
return this;
}
// Immediately edit the entity with the properties given
function edit(props){
if (arguments.length === 2) {
var property = arguments[0];
var value = arguments[1];
props = {};
props[property] = value;
}
this.properties = Object.assign({}, this.properties, props);
this.cache = Object.assign({}, this.cache, this.properties);
this.sync();
return this;
}
// Get a property either from the cache or by querying the entity directly
function get(propertyKeys, queryEntity){
if (queryEntity && typeof propertyKeys === 'string') {
var propertyValue = Entities.getEntityProperties(this.id, propertyKeys)[propertyKeys];
this.properties[propertyKeys] = propertyValue;
this.cache = Object.assign({}, this.cache, this.properties);
return propertyValue;
}
if (queryEntity && Array.isArray(propertyKeys)) {
var entityProps = Entities.getEntityProperties(this.id, propertyKeys);
for (var prop in entityProps) {
if (propertyKeys.indexOf(prop) === -1) {
delete entityProps[prop];
} else {
this.properties[prop] = entityProps[prop];
}
}
return entityProps;
}
if (Array.isArray(propertyKeys)) {
var recombinedProps = {};
propertyKeys.forEach(function (prop) {
recombinedProps[prop] = this.cache[prop];
}, this);
return recombinedProps;
}
return this.cache[propertyKeys];
}
// Show the entity
function show(){
this.edit({ visible: true });
return this;
}
// Hide the enity
function hide(){
this.edit({ visible: false });
}
// Add an entity if it isn't created
function create(clearPropertiesAfter){
this.id = Entities.addEntity(this.properties, this.type);
if (clearPropertiesAfter) {
this.properties = {};
}
return this;
}
// Delete the entity
function destroy(){
Entities.deleteEntity(this.id);
return this;
}
// #endregion
// *************************************
// END API
// *************************************
EntityMaker.prototype = {
add: add,
sync: sync,
edit: edit,
get: get,
show: show,
hide: hide,
create: create,
destroy: destroy
};
module.exports = EntityMaker;

View file

@ -14,8 +14,6 @@
// *************************************
// #region dependencies
// Custom module for handling entities
var EntityMaker = Script.require("./resources/modules/entityMaker.js");
// Add nice smoothing functions to the animations
var EasingFunctions = Script.require("./resources/modules/easing.js");
@ -23,7 +21,10 @@ var EasingFunctions = Script.require("./resources/modules/easing.js");
// about the emojis
var emojiList = Script.require("./resources/modules/emojiList.js");
var customEmojiList = Script.require("./resources/modules/customEmojiList.js");
var imageURLBase = Script.resolvePath("./resources/images/emojis/512px/");
// The contents of this remote folder must always contain all possible emojis for users of `simplifiedEmoji.js`
var imageURLBase = "https://content.highfidelity.com/Experiences/Releases/simplifiedUI/simplifiedEmote/emojiApp/resources/images/emojis/512px/";
// Uncomment below for local testing
//imageURLBase = Script.resolvePath("./resources/images/emojis/512px/");
// #endregion
@ -125,8 +126,9 @@ function resetEmojis() {
pruneOldAvimojis();
maybeClearPop();
clearCountDownTimerHandler();
if (currentEmoji && currentEmoji.id) {
currentEmoji.destroy();
if (currentEmoji) {
Entities.deleteEntity(currentEmoji);
currentEmoji = false;
selectedEmojiFilename = null;
}
}
@ -179,7 +181,7 @@ function onScaleChanged() {
// what happens when we need to add an emoji over a user
function addEmoji(emojiFilename) {
if (currentEmoji && currentEmoji.id) {
if (currentEmoji) {
resetEmojis();
}
createEmoji(emojiFilename);
@ -190,7 +192,7 @@ function addEmoji(emojiFilename) {
var ABOVE_HEAD = 0.61;
var EMOJI_X_OFFSET = 0.0;
var DEFAULT_EMOJI_SIZE = 0.37;
var currentEmoji = new EntityMaker("avatar");
var currentEmoji = false;
var emojiMaxDimensions = null;
function createEmoji(emojiFilename) {
var emojiPosition;
@ -205,21 +207,21 @@ function createEmoji(emojiFilename) {
0
];
currentEmoji
.add('type', 'Image')
.add('name', 'AVIMOJI')
.add('localPosition', emojiPosition)
.add('dimensions', [0, 0, 0])
.add('parentID', MyAvatar.sessionUUID)
.add('parentJointIndex', MyAvatar.getJointIndex("Head"))
.add('emissive', true)
.add('collisionless', true)
.add('imageURL', imageURL)
.add('billboardMode', "full")
.add('ignorePickIntersection', true)
.add('alpha', 1)
.add('grab', { grabbable: false })
.create();
currentEmoji = Entities.addEntity({
"type": "Image",
"name": "AVIMOJI",
"localPosition": emojiPosition,
"dimensions": [0, 0, 0],
"parentID": MyAvatar.sessionUUID,
"parentJointIndex": MyAvatar.getJointIndex("Head"),
"emissive": true,
"collisionless": true,
"imageURL": imageURL,
"billboardMode": "full",
"ignorePickIntersection": true,
"alpha": 1,
"grab": { "grabbable": false }
}, "avatar");
maybePlayPop("in");
beginCountDownTimer();
@ -339,7 +341,9 @@ function playPopAnimation() {
}
currentPopStep++;
currentEmoji.edit("dimensions", dimensions);
if (currentEmoji) {
Entities.editEntity(currentEmoji, {"dimensions": dimensions});
}
// Handle if it's the end of the animation step
@ -352,12 +356,14 @@ function playPopAnimation() {
Math.max(dimensions.y, emojiMaxDimensions.y),
Math.max(dimensions.z, emojiMaxDimensions.z)
];
currentEmoji.edit("dimensions", dimensions);
if (currentEmoji) {
Entities.editEntity(currentEmoji, {"dimensions": dimensions});
}
} else {
// make sure there is a currentEmoji entity before trying to delete
if (currentEmoji && currentEmoji.id) {
currentEmoji.destroy();
currentEmoji = new EntityMaker("avatar");
if (currentEmoji) {
Entities.deleteEntity(currentEmoji);
currentEmoji = false;
}
finalInPopScale = null;
selectedEmojiFilename = null;