mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 22:28:37 +02:00
automatically save adjustments to offset of equipped items
This commit is contained in:
parent
1b52d700a0
commit
e4ef3ae869
2 changed files with 27 additions and 20 deletions
|
@ -116,6 +116,7 @@ function AttachedEntitiesManager() {
|
||||||
manager.checkIfWearable(parsedMessage.grabbedEntity, parsedMessage.joint)
|
manager.checkIfWearable(parsedMessage.grabbedEntity, parsedMessage.joint)
|
||||||
// manager.saveAttachedEntities();
|
// manager.saveAttachedEntities();
|
||||||
} else if (parsedMessage.action === 'shared-release') {
|
} else if (parsedMessage.action === 'shared-release') {
|
||||||
|
manager.updateRelativeOffsets(parsedMessage.grabbedEntity);
|
||||||
// manager.saveAttachedEntities();
|
// manager.saveAttachedEntities();
|
||||||
} else if (parsedMessage.action === 'equip') {
|
} else if (parsedMessage.action === 'equip') {
|
||||||
// manager.saveAttachedEntities();
|
// manager.saveAttachedEntities();
|
||||||
|
@ -173,11 +174,12 @@ function AttachedEntitiesManager() {
|
||||||
parentJointIndex: bestJointIndex
|
parentJointIndex: bestJointIndex
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!this.avatarIsInDressingRoom() &&
|
if (bestJointOffset && bestJointOffset.constructor === Array && bestJointOffset.length > 1) {
|
||||||
bestJointOffset && bestJointOffset.constructor === Array && bestJointOffset.length > 1) {
|
if (!this.avatarIsInDressingRoom()) {
|
||||||
// don't snap the entity to the preferred position if the avatar is in the dressing room.
|
// don't snap the entity to the preferred position if the avatar is in the dressing room.
|
||||||
wearProps.localPosition = bestJointOffset[0];
|
wearProps.localPosition = bestJointOffset[0];
|
||||||
wearProps.localRotation = bestJointOffset[1];
|
wearProps.localRotation = bestJointOffset[1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Entities.editEntity(grabbedEntity, wearProps);
|
Entities.editEntity(grabbedEntity, wearProps);
|
||||||
} else if (props.parentID != NULL_UUID) {
|
} else if (props.parentID != NULL_UUID) {
|
||||||
|
@ -189,12 +191,19 @@ function AttachedEntitiesManager() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateRelativeOffsets = function(entityID, props) {
|
this.updateRelativeOffsets = function(entityID) {
|
||||||
// save the preferred (current) relative position and rotation into the user-data of the entity
|
// save the preferred (current) relative position and rotation into the user-data of the entity
|
||||||
var wearableData = getEntityCustomData('wearable', entityID, DEFAULT_WEARABLE_DATA);
|
var props = Entities.getEntityProperties(entityID);
|
||||||
var currentJointName = MyAvatar.getJointNames()[props.parentJointIndex];
|
if (props.parentID == MyAvatar.sessionUUID) {
|
||||||
wearableData.joints[currentJointName] = [props.localPosition, props.localRotation];
|
grabData = getEntityCustomData('grabKey', entityID, {});
|
||||||
setEntityCustomData('wearable', entityID, wearableData);
|
grabbableData = getEntityCustomData('grabbableKey', entityID, {});
|
||||||
|
var wearableData = getEntityCustomData('wearable', entityID, DEFAULT_WEARABLE_DATA);
|
||||||
|
var currentJointName = MyAvatar.getJointNames()[props.parentJointIndex];
|
||||||
|
wearableData.joints[currentJointName] = [props.localPosition, props.localRotation];
|
||||||
|
setEntityCustomData('wearable', entityID, wearableData);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.saveAttachedEntities = function() {
|
this.saveAttachedEntities = function() {
|
||||||
|
@ -203,12 +212,8 @@ function AttachedEntitiesManager() {
|
||||||
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];
|
||||||
var props = Entities.getEntityProperties(entityID);
|
if (this.updateRelativeOffsets(entityID)) {
|
||||||
if (props.parentID == MyAvatar.sessionUUID) {
|
var props = Entities.getEntityProperties(entityID); // refresh, because updateRelativeOffsets changed them
|
||||||
grabData = getEntityCustomData('grabKey', entityID, {});
|
|
||||||
grabbableData = getEntityCustomData('grabbableKey', entityID, {});
|
|
||||||
this.updateRelativeOffsets(entityID, props);
|
|
||||||
props = Entities.getEntityProperties(entityID); // refresh, because updateRelativeOffsets changed them
|
|
||||||
this.scrubProperties(props);
|
this.scrubProperties(props);
|
||||||
saveData.push(props);
|
saveData.push(props);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1217,10 +1217,12 @@ function MyController(hand) {
|
||||||
|
|
||||||
this.hasPresetOffsets = function() {
|
this.hasPresetOffsets = function() {
|
||||||
var wearableData = getEntityCustomData('wearable', this.grabbedEntity, {joints: {}});
|
var wearableData = getEntityCustomData('wearable', this.grabbedEntity, {joints: {}});
|
||||||
var allowedJoints = wearableData.joints;
|
if ("joints" in wearableData) {
|
||||||
var handJointName = this.hand === RIGHT_HAND ? "RightHand" : "LeftHand";
|
var allowedJoints = wearableData.joints;
|
||||||
if (handJointName in allowedJoints) {
|
var handJointName = this.hand === RIGHT_HAND ? "RightHand" : "LeftHand";
|
||||||
return true;
|
if (handJointName in allowedJoints) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue