fix attached entities manager and add to default scripts

This commit is contained in:
James B. Pollack 2016-06-03 14:24:07 -07:00
parent f6644ad2bb
commit 9c63a6417e
2 changed files with 44 additions and 42 deletions

View file

@ -21,3 +21,4 @@ Script.load("system/controllers/handControllerPointer.js");
Script.load("system/controllers/squeezeHands.js"); Script.load("system/controllers/squeezeHands.js");
Script.load("system/controllers/grab.js"); Script.load("system/controllers/grab.js");
Script.load("system/dialTone.js"); Script.load("system/dialTone.js");
Script.load("system/attachedEntitiesManager.js");

View file

@ -22,7 +22,7 @@ var MINIMUM_DROP_DISTANCE_FROM_JOINT = 0.8;
var ATTACHED_ENTITY_SEARCH_DISTANCE = 10.0; var ATTACHED_ENTITY_SEARCH_DISTANCE = 10.0;
var ATTACHED_ENTITIES_SETTINGS_KEY = "ATTACHED_ENTITIES"; var ATTACHED_ENTITIES_SETTINGS_KEY = "ATTACHED_ENTITIES";
var DRESSING_ROOM_DISTANCE = 2.0; var DRESSING_ROOM_DISTANCE = 2.0;
var SHOW_TOOL_BAR = true; var SHOW_TOOL_BAR = false;
// tool bar // tool bar
@ -71,12 +71,11 @@ Script.scriptEnding.connect(scriptEnding);
// attached entites // attached entites
function AttachedEntitiesManager() { function AttachedEntitiesManager() {
var clothingLocked = true; var clothingLocked = false;
this.subscribeToMessages = function() { this.subscribeToMessages = function() {
Messages.subscribe('Hifi-Object-Manipulation'); Messages.subscribe('Hifi-Object-Manipulation');
@ -106,7 +105,7 @@ function AttachedEntitiesManager() {
// ignore // ignore
} else if (parsedMessage.action === 'release') { } else if (parsedMessage.action === 'release') {
manager.handleEntityRelease(parsedMessage.grabbedEntity, parsedMessage.joint) manager.handleEntityRelease(parsedMessage.grabbedEntity, parsedMessage.joint)
// manager.saveAttachedEntities(); // manager.saveAttachedEntities();
} else if (parsedMessage.action === 'equip') { } else if (parsedMessage.action === 'equip') {
// manager.saveAttachedEntities(); // manager.saveAttachedEntities();
} else { } else {
@ -156,7 +155,8 @@ function AttachedEntitiesManager() {
var wearProps = Entities.getEntityProperties(grabbedEntity); var wearProps = Entities.getEntityProperties(grabbedEntity);
wearProps.parentID = MyAvatar.sessionUUID; wearProps.parentID = MyAvatar.sessionUUID;
wearProps.parentJointIndex = bestJointIndex; wearProps.parentJointIndex = bestJointIndex;
delete wearProps.localPosition;
delete wearProps.localRotation;
var updatePresets = false; var updatePresets = false;
if (bestJointOffset && bestJointOffset.constructor === Array) { if (bestJointOffset && bestJointOffset.constructor === Array) {
if (!clothingLocked || bestJointOffset.length < 2) { if (!clothingLocked || bestJointOffset.length < 2) {
@ -170,21 +170,23 @@ function AttachedEntitiesManager() {
} }
Entities.deleteEntity(grabbedEntity); Entities.deleteEntity(grabbedEntity);
grabbedEntity = Entities.addEntity(wearProps, true); //the true boolean here after add entity adds it as an 'avatar entity', which can travel with you from server to server.
var newEntity = Entities.addEntity(wearProps, true);
if (updatePresets) { if (updatePresets) {
this.updateRelativeOffsets(grabbedEntity); this.updateRelativeOffsets(newEntity);
} }
} else if (props.parentID != NULL_UUID) { } else if (props.parentID != NULL_UUID) {
// drop the entity and set it to have no parent (not on the avatar), unless it's being equipped in a hand. // drop the entity and set it to have no parent (not on the avatar), unless it's being equipped in a hand.
if (props.parentID === MyAvatar.sessionUUID && if (props.parentID === MyAvatar.sessionUUID &&
(props.parentJointIndex == MyAvatar.getJointIndex("RightHand") || (props.parentJointIndex == MyAvatar.getJointIndex("RightHand") ||
props.parentJointIndex == MyAvatar.getJointIndex("LeftHand"))) { props.parentJointIndex == MyAvatar.getJointIndex("LeftHand"))) {
// this is equipped on a hand -- don't clear the parent. // this is equipped on a hand -- don't clear the parent.
} else { } else {
var wearProps = Entities.getEntityProperties(grabbedEntity); var wearProps = Entities.getEntityProperties(grabbedEntity);
wearProps.parentID = NULL_UUID; wearProps.parentID = NULL_UUID;
wearProps.parentJointIndex = -1; wearProps.parentJointIndex = -1;
delete wearProps.id; delete wearProps.id;
delete wearProps.created; delete wearProps.created;
delete wearProps.age; delete wearProps.age;
@ -198,7 +200,6 @@ function AttachedEntitiesManager() {
delete wearProps.owningAvatarID; delete wearProps.owningAvatarID;
delete wearProps.localPosition; delete wearProps.localPosition;
delete wearProps.localRotation; delete wearProps.localRotation;
Entities.deleteEntity(grabbedEntity); Entities.deleteEntity(grabbedEntity);
Entities.addEntity(wearProps); Entities.addEntity(wearProps);
} }
@ -220,16 +221,16 @@ function AttachedEntitiesManager() {
return false; return false;
} }
this.toggleLocked = function() { // this.toggleLocked = function() {
print("toggleLocked"); // print("toggleLocked");
if (clothingLocked) { // if (clothingLocked) {
clothingLocked = false; // clothingLocked = false;
toolBar.setImageURL(Script.resolvePath("assets/images/unlock.svg"), lockButton); // toolBar.setImageURL(Script.resolvePath("assets/images/unlock.svg"), lockButton);
} else { // } else {
clothingLocked = true; // clothingLocked = true;
toolBar.setImageURL(Script.resolvePath("assets/images/lock.svg"), lockButton); // toolBar.setImageURL(Script.resolvePath("assets/images/lock.svg"), lockButton);
} // }
} // }
// this.saveAttachedEntities = function() { // this.saveAttachedEntities = function() {
// print("--- saving attached entities ---"); // print("--- saving attached entities ---");
@ -246,27 +247,27 @@ function AttachedEntitiesManager() {
// Settings.setValue(ATTACHED_ENTITIES_SETTINGS_KEY, JSON.stringify(saveData)); // Settings.setValue(ATTACHED_ENTITIES_SETTINGS_KEY, JSON.stringify(saveData));
// } // }
this.scrubProperties = function(props) { // this.scrubProperties = function(props) {
var toScrub = ["queryAACube", "position", "rotation", // var toScrub = ["queryAACube", "position", "rotation",
"created", "ageAsText", "naturalDimensions", // "created", "ageAsText", "naturalDimensions",
"naturalPosition", "velocity", "acceleration", // "naturalPosition", "velocity", "acceleration",
"angularVelocity", "boundingBox"]; // "angularVelocity", "boundingBox"];
toScrub.forEach(function(propertyName) { // toScrub.forEach(function(propertyName) {
delete props[propertyName]; // delete props[propertyName];
}); // });
// if the userData has a grabKey, clear old state // // if the userData has a grabKey, clear old state
if ("userData" in props) { // if ("userData" in props) {
try { // try {
parsedUserData = JSON.parse(props.userData); // parsedUserData = JSON.parse(props.userData);
if ("grabKey" in parsedUserData) { // if ("grabKey" in parsedUserData) {
parsedUserData.grabKey.refCount = 0; // parsedUserData.grabKey.refCount = 0;
delete parsedUserData.grabKey["avatarId"]; // delete parsedUserData.grabKey["avatarId"];
props["userData"] = JSON.stringify(parsedUserData); // props["userData"] = JSON.stringify(parsedUserData);
} // }
} catch (e) { // } catch (e) {
} // }
} // }
} // }
// this.loadAttachedEntities = function(grabbedEntity) { // this.loadAttachedEntities = function(grabbedEntity) {
// print("--- loading attached entities ---"); // print("--- loading attached entities ---");
@ -302,4 +303,4 @@ function AttachedEntitiesManager() {
} }
var manager = new AttachedEntitiesManager(); var manager = new AttachedEntitiesManager();
manager.subscribeToMessages(); manager.subscribeToMessages();