mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 19:21:16 +02:00
update attachedEntitiesManager to work better with avatarEntities
This commit is contained in:
parent
3876a8037c
commit
880b52aad2
1 changed files with 55 additions and 49 deletions
|
@ -117,10 +117,11 @@ function AttachedEntitiesManager() {
|
||||||
this.handleEntityRelease = function(grabbedEntity, releasedFromJoint) {
|
this.handleEntityRelease = function(grabbedEntity, releasedFromJoint) {
|
||||||
// if this is still equipped, just rewrite the position information.
|
// if this is still equipped, just rewrite the position information.
|
||||||
var grabData = getEntityCustomData('grabKey', grabbedEntity, {});
|
var grabData = getEntityCustomData('grabKey', grabbedEntity, {});
|
||||||
if ("refCount" in grabData && grabData.refCount > 0) {
|
// if ("refCount" in grabData && grabData.refCount > 0) {
|
||||||
manager.updateRelativeOffsets(grabbedEntity);
|
// // for adjusting things in your other hand
|
||||||
return;
|
// manager.updateRelativeOffsets(grabbedEntity);
|
||||||
}
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
var allowedJoints = getEntityCustomData('wearable', grabbedEntity, DEFAULT_WEARABLE_DATA).joints;
|
var allowedJoints = getEntityCustomData('wearable', grabbedEntity, DEFAULT_WEARABLE_DATA).joints;
|
||||||
|
|
||||||
|
@ -156,9 +157,11 @@ function AttachedEntitiesManager() {
|
||||||
wearProps.parentID = MyAvatar.sessionUUID;
|
wearProps.parentID = MyAvatar.sessionUUID;
|
||||||
wearProps.parentJointIndex = bestJointIndex;
|
wearProps.parentJointIndex = bestJointIndex;
|
||||||
|
|
||||||
|
var updatePresets = false;
|
||||||
if (bestJointOffset && bestJointOffset.constructor === Array) {
|
if (bestJointOffset && bestJointOffset.constructor === Array) {
|
||||||
if (!clothingLocked || bestJointOffset.length < 2) {
|
if (!clothingLocked || bestJointOffset.length < 2) {
|
||||||
this.updateRelativeOffsets(grabbedEntity);
|
// we're unlocked or this thing didn't have a preset position, so update it
|
||||||
|
updatePresets = true;
|
||||||
} else {
|
} else {
|
||||||
// don't snap the entity to the preferred position if unlocked
|
// don't snap the entity to the preferred position if unlocked
|
||||||
wearProps.localPosition = bestJointOffset[0];
|
wearProps.localPosition = bestJointOffset[0];
|
||||||
|
@ -167,7 +170,10 @@ function AttachedEntitiesManager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Entities.deleteEntity(grabbedEntity);
|
Entities.deleteEntity(grabbedEntity);
|
||||||
Entities.addEntity(wearProps, true);
|
grabbedEntity = Entities.addEntity(wearProps, true);
|
||||||
|
if (updatePresets) {
|
||||||
|
this.updateRelativeOffsets(grabbedEntity);
|
||||||
|
}
|
||||||
} 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 &&
|
||||||
|
@ -225,20 +231,20 @@ function AttachedEntitiesManager() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.saveAttachedEntities = function() {
|
// this.saveAttachedEntities = function() {
|
||||||
print("--- saving attached entities ---");
|
// print("--- saving attached entities ---");
|
||||||
saveData = [];
|
// saveData = [];
|
||||||
var nearbyEntities = Entities.findEntities(MyAvatar.position, ATTACHED_ENTITY_SEARCH_DISTANCE);
|
// var nearbyEntities = Entities.findEntities(MyAvatar.position, ATTACHED_ENTITY_SEARCH_DISTANCE);
|
||||||
for (i = 0; i < nearbyEntities.length; i++) {
|
// for (i = 0; i < nearbyEntities.length; i++) {
|
||||||
var entityID = nearbyEntities[i];
|
// var entityID = nearbyEntities[i];
|
||||||
if (this.updateRelativeOffsets(entityID)) {
|
// if (this.updateRelativeOffsets(entityID)) {
|
||||||
var props = Entities.getEntityProperties(entityID); // refresh, because updateRelativeOffsets changed them
|
// var props = Entities.getEntityProperties(entityID); // refresh, because updateRelativeOffsets changed them
|
||||||
this.scrubProperties(props);
|
// this.scrubProperties(props);
|
||||||
saveData.push(props);
|
// saveData.push(props);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
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",
|
||||||
|
@ -262,37 +268,37 @@ function AttachedEntitiesManager() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loadAttachedEntities = function(grabbedEntity) {
|
// this.loadAttachedEntities = function(grabbedEntity) {
|
||||||
print("--- loading attached entities ---");
|
// print("--- loading attached entities ---");
|
||||||
jsonAttachmentData = Settings.getValue(ATTACHED_ENTITIES_SETTINGS_KEY);
|
// jsonAttachmentData = Settings.getValue(ATTACHED_ENTITIES_SETTINGS_KEY);
|
||||||
var loadData = [];
|
// var loadData = [];
|
||||||
try {
|
// try {
|
||||||
loadData = JSON.parse(jsonAttachmentData);
|
// loadData = JSON.parse(jsonAttachmentData);
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
print('error parsing saved attachment data');
|
// print('error parsing saved attachment data');
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
for (i = 0; i < loadData.length; i ++) {
|
// for (i = 0; i < loadData.length; i ++) {
|
||||||
var savedProps = loadData[ i ];
|
// var savedProps = loadData[ i ];
|
||||||
var currentProps = Entities.getEntityProperties(savedProps.id);
|
// var currentProps = Entities.getEntityProperties(savedProps.id);
|
||||||
if (currentProps.id == savedProps.id &&
|
// if (currentProps.id == savedProps.id &&
|
||||||
// TODO -- also check that parentJointIndex matches?
|
// // TODO -- also check that parentJointIndex matches?
|
||||||
currentProps.parentID == MyAvatar.sessionUUID) {
|
// currentProps.parentID == MyAvatar.sessionUUID) {
|
||||||
// entity is already in-world. TODO -- patch it up?
|
// // entity is already in-world. TODO -- patch it up?
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
this.scrubProperties(savedProps);
|
// this.scrubProperties(savedProps);
|
||||||
delete savedProps["id"];
|
// delete savedProps["id"];
|
||||||
savedProps.parentID = MyAvatar.sessionUUID; // this will change between sessions
|
// savedProps.parentID = MyAvatar.sessionUUID; // this will change between sessions
|
||||||
var loadedEntityID = Entities.addEntity(savedProps, true);
|
// var loadedEntityID = Entities.addEntity(savedProps, true);
|
||||||
|
|
||||||
Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({
|
// Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({
|
||||||
action: 'loaded',
|
// action: 'loaded',
|
||||||
grabbedEntity: loadedEntityID
|
// grabbedEntity: loadedEntityID
|
||||||
}));
|
// }));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
var manager = new AttachedEntitiesManager();
|
var manager = new AttachedEntitiesManager();
|
||||||
|
|
Loading…
Reference in a new issue