mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
finished equiping locked clone-able entities
This commit is contained in:
parent
4b592687b7
commit
ed52136fc5
2 changed files with 53 additions and 22 deletions
|
@ -15,6 +15,7 @@
|
|||
Script.include("/~/system/libraries/Xform.js");
|
||||
Script.include("/~/system/controllers/controllerDispatcherUtils.js");
|
||||
Script.include("/~/system/libraries/controllers.js");
|
||||
Script.include("/~/system/libraries/cloneEntityUtils.js");
|
||||
|
||||
|
||||
var DEFAULT_SPHERE_MODEL_URL = "http://hifi-content.s3.amazonaws.com/alan/dev/equip-Fresnel-3.fbx";
|
||||
|
@ -321,7 +322,8 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
|
|||
if (props.parentID === NULL_UUID) {
|
||||
hasParent = false;
|
||||
}
|
||||
if (hasParent || props.locked || entityHasActions(hotspot.entityID)) {
|
||||
|
||||
if (hasParent || entityHasActions(hotspot.entityID)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -370,6 +372,16 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
|
|||
return equippableHotspots;
|
||||
};
|
||||
|
||||
this.cloneHotspot = function(props, controllerData) {
|
||||
if (entityIsCloneable(props)) {
|
||||
var worldEntityProps = controllerData.nearbyEntityProperties[this.hand];
|
||||
var cloneID = cloneEntity(props, worldEntityProps);
|
||||
return cloneID
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
this.chooseBestEquipHotspot = function(candidateEntityProps, controllerData) {
|
||||
var equippableHotspots = this.chooseNearEquipHotspots(candidateEntityProps, controllerData);
|
||||
if (equippableHotspots.length > 0) {
|
||||
|
@ -434,11 +446,12 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
|
|||
};
|
||||
|
||||
this.startEquipEntity = function (controllerData) {
|
||||
print("------> starting to equip entity <-------");
|
||||
this.dropGestureReset();
|
||||
this.clearEquipHaptics();
|
||||
Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand);
|
||||
|
||||
var grabbedProperties = Entities.getEntityProperties(this.targetEntityID);
|
||||
|
||||
// if an object is "equipped" and has a predefined offset, use it.
|
||||
var offsets = getAttachPointForHotspotFromSettings(this.grabbedHotspot, this.hand);
|
||||
if (offsets) {
|
||||
|
@ -467,7 +480,19 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
|
|||
localPosition: this.offsetPosition,
|
||||
localRotation: this.offsetRotation
|
||||
};
|
||||
Entities.editEntity(this.targetEntityID, reparentProps);
|
||||
var isClone = false;
|
||||
if (entityIsCloneable(grabbedProperties)) {
|
||||
var cloneID = this.cloneHotspot(grabbedProperties, controllerData);
|
||||
this.targetEntityID = cloneID;
|
||||
Entities.editEntity(this.targetEntityID, reparentProps);
|
||||
isClone = true;
|
||||
} else if (!grabbedProperties.locked) {
|
||||
Entities.editEntity(this.targetEntityID, reparentProps);
|
||||
} else {
|
||||
this.grabbedHotspot = null;
|
||||
this.targetEntityID = null;
|
||||
return;
|
||||
}
|
||||
|
||||
var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID];
|
||||
Entities.callEntityMethod(this.targetEntityID, "startEquip", args);
|
||||
|
@ -477,6 +502,18 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
|
|||
grabbedEntity: this.targetEntityID,
|
||||
joint: this.hand === RIGHT_HAND ? "RightHand" : "LeftHand"
|
||||
}));
|
||||
|
||||
var _this = this;
|
||||
var grabEquipCheck = function() {
|
||||
var args = [_this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID];
|
||||
Entities.callEntityMethod(_this.targetEntityID, "startEquip", args);
|
||||
};
|
||||
|
||||
if (isClone) {
|
||||
// 100 ms seems to be sufficient time to force the check even occur after the object has been initialized.
|
||||
Script.setTimeout(grabEquipCheck, 100);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.endEquipEntity = function () {
|
||||
|
@ -523,6 +560,9 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
|
|||
|
||||
equipHotspotBuddy.update(deltaTime, timestamp, controllerData);
|
||||
|
||||
//if the potentialHotspot is cloneable, clone it and return it
|
||||
// if the potentialHotspot os not cloneable and locked return null
|
||||
|
||||
if (potentialEquipHotspot) {
|
||||
if (this.triggerSmoothedSqueezed() && !this.waitForTriggerRelease) {
|
||||
this.grabbedHotspot = potentialEquipHotspot;
|
||||
|
|
|
@ -39,13 +39,9 @@ entityIsCloneable = function(props) {
|
|||
}
|
||||
|
||||
|
||||
cloneEntity = function(cloneableProps, worldEntityProps) {
|
||||
if (!cloneableProps) {
|
||||
return null;
|
||||
}
|
||||
|
||||
cloneEntity = function(props, worldEntityProps) {
|
||||
// we need all the properties, for this
|
||||
cloneableProps = Entities.getEntityProperties(cloneableProps.id);
|
||||
var cloneableProps = Entities.getEntityProperties(props.id);
|
||||
|
||||
var count = 0;
|
||||
worldEntityProps.forEach(function(itemWE) {
|
||||
|
@ -55,7 +51,6 @@ cloneEntity = function(cloneableProps, worldEntityProps) {
|
|||
});
|
||||
|
||||
var grabInfo = getGrabbableData(cloneableProps);
|
||||
|
||||
var limit = grabInfo.cloneLimit ? grabInfo.cloneLimit : 0;
|
||||
if (count >= limit && limit !== 0) {
|
||||
return null;
|
||||
|
@ -64,23 +59,19 @@ cloneEntity = function(cloneableProps, worldEntityProps) {
|
|||
cloneableProps.name = cloneableProps.name + '-clone-' + cloneableProps.id;
|
||||
var lifetime = grabInfo.cloneLifetime ? grabInfo.cloneLifetime : 300;
|
||||
var dynamic = grabInfo.cloneDynamic ? grabInfo.cloneDynamic : false;
|
||||
var cUserData = Object.assign({}, cloneableProps.userData);
|
||||
var cUserData = Object.assign({}, JSON.parse(cloneableProps.userData));
|
||||
var cProperties = Object.assign({}, cloneableProps);
|
||||
|
||||
try {
|
||||
delete cUserData.grabbableKey.cloneLifetime;
|
||||
delete cUserData.grabbableKey.cloneable;
|
||||
delete cUserData.grabbableKey.cloneDynamic;
|
||||
delete cUserData.grabbableKey.cloneLimit;
|
||||
delete cProperties.id;
|
||||
} catch(e) {
|
||||
}
|
||||
|
||||
delete cUserData.grabbableKey.cloneLifetime;
|
||||
delete cUserData.grabbableKey.cloneable;
|
||||
delete cUserData.grabbableKey.cloneDynamic;
|
||||
delete cUserData.grabbableKey.cloneLimit;
|
||||
delete cProperties.id;
|
||||
|
||||
|
||||
cProperties.dynamic = dynamic;
|
||||
cProperties.locked = false;
|
||||
if (!cUserData.grabbableKey) {
|
||||
cUserData.grabbableKey = {};
|
||||
}
|
||||
cUserData.grabbableKey.triggerable = true;
|
||||
cUserData.grabbableKey.grabbable = true;
|
||||
cProperties.lifetime = lifetime;
|
||||
|
|
Loading…
Reference in a new issue