mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-25 18:18:47 +02:00
Fixed Clone instancing issues
This commit is contained in:
parent
82236bdcb9
commit
fd1fded276
1 changed files with 36 additions and 23 deletions
|
@ -2417,6 +2417,9 @@ function MyController(hand) {
|
||||||
this.offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, this.offsetRotation)), offset);
|
this.offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, this.offsetRotation)), offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This boolean is used to check if the object that is grabbed has just been cloned
|
||||||
|
// It is only set true, if the object that is grabbed creates a new clone.
|
||||||
|
var isClone = false;
|
||||||
var isPhysical = propsArePhysical(grabbedProperties) ||
|
var isPhysical = propsArePhysical(grabbedProperties) ||
|
||||||
(!this.grabbedIsOverlay && entityHasActions(this.grabbedThingID));
|
(!this.grabbedIsOverlay && entityHasActions(this.grabbedThingID));
|
||||||
if (isPhysical && this.state == STATE_NEAR_GRABBING && grabbedProperties.parentID === NULL_UUID) {
|
if (isPhysical && this.state == STATE_NEAR_GRABBING && grabbedProperties.parentID === NULL_UUID) {
|
||||||
|
@ -2475,6 +2478,7 @@ function MyController(hand) {
|
||||||
var dynamic = grabInfo.cloneDynamic ? grabInfo.cloneDynamic : false;
|
var dynamic = grabInfo.cloneDynamic ? grabInfo.cloneDynamic : false;
|
||||||
var cUserData = Object.assign({}, userData);
|
var cUserData = Object.assign({}, userData);
|
||||||
var cProperties = Object.assign({}, cloneableProps);
|
var cProperties = Object.assign({}, cloneableProps);
|
||||||
|
isClone = true;
|
||||||
|
|
||||||
if (count > limit) {
|
if (count > limit) {
|
||||||
delete cloneableProps;
|
delete cloneableProps;
|
||||||
|
@ -2496,14 +2500,9 @@ function MyController(hand) {
|
||||||
cUserData.grabbableKey.grabbable = true;
|
cUserData.grabbableKey.grabbable = true;
|
||||||
cProperties.lifetime = lifetime;
|
cProperties.lifetime = lifetime;
|
||||||
cProperties.userData = JSON.stringify(cUserData);
|
cProperties.userData = JSON.stringify(cUserData);
|
||||||
this.grabbedThingID = Entities.addEntity(cProperties);
|
var cloneID = Entities.addEntity(cProperties);
|
||||||
grabbedProperties = Entities.getEntityProperties(this.grabbedThingID);
|
this.grabbedThingID = cloneID;
|
||||||
var _this = this;
|
grabbedProperties = Entities.getEntityProperties(cloneID);
|
||||||
|
|
||||||
Script.setTimeout(function () {
|
|
||||||
// This is needed to wait for the grabbed entity to have been instanciated.
|
|
||||||
_this.callEntityMethodOnGrabbed("startEquip");
|
|
||||||
},400);
|
|
||||||
}
|
}
|
||||||
}catch(e) {}
|
}catch(e) {}
|
||||||
}
|
}
|
||||||
|
@ -2518,7 +2517,6 @@ function MyController(hand) {
|
||||||
this.previousParentID[this.grabbedThingID] = grabbedProperties.parentID;
|
this.previousParentID[this.grabbedThingID] = grabbedProperties.parentID;
|
||||||
this.previousParentJointIndex[this.grabbedThingID] = grabbedProperties.parentJointIndex;
|
this.previousParentJointIndex[this.grabbedThingID] = grabbedProperties.parentJointIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({
|
Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({
|
||||||
action: 'equip',
|
action: 'equip',
|
||||||
grabbedEntity: this.grabbedThingID,
|
grabbedEntity: this.grabbedThingID,
|
||||||
|
@ -2534,22 +2532,37 @@ function MyController(hand) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.state == STATE_NEAR_GRABBING) {
|
var _this = this;
|
||||||
this.callEntityMethodOnGrabbed("startNearGrab");
|
/*
|
||||||
} else { // this.state == STATE_HOLD
|
* Setting context for function that is either called via timer or directly, depending if
|
||||||
this.callEntityMethodOnGrabbed("startEquip");
|
* if the object in question is a clone. If it is a clone, we need to make sure that the intial equipment event
|
||||||
|
* is called correctly, as these just freshly created entity may not have completely initialized.
|
||||||
|
*/
|
||||||
|
var grabEquipCheck = function () {
|
||||||
|
if (_this.state == STATE_NEAR_GRABBING) {
|
||||||
|
_this.callEntityMethodOnGrabbed("startNearGrab");
|
||||||
|
} else { // this.state == STATE_HOLD
|
||||||
|
_this.callEntityMethodOnGrabbed("startEquip");
|
||||||
|
}
|
||||||
|
|
||||||
|
_this.currentHandControllerTipPosition =
|
||||||
|
(_this.hand === RIGHT_HAND) ? MyAvatar.rightHandTipPosition : MyAvatar.leftHandTipPosition;
|
||||||
|
_this.currentObjectTime = Date.now();
|
||||||
|
|
||||||
|
_this.currentObjectPosition = grabbedProperties.position;
|
||||||
|
_this.currentObjectRotation = grabbedProperties.rotation;
|
||||||
|
_this.currentVelocity = ZERO_VEC;
|
||||||
|
_this.currentAngularVelocity = ZERO_VEC;
|
||||||
|
|
||||||
|
_this.prevDropDetected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentHandControllerTipPosition =
|
if (isClone) {
|
||||||
(this.hand === RIGHT_HAND) ? MyAvatar.rightHandTipPosition : MyAvatar.leftHandTipPosition;
|
// 100 ms seems to be sufficient time to force the check even occur after the object has been initialized.
|
||||||
this.currentObjectTime = Date.now();
|
Script.setTimeout(grabEquipCheck, 100);
|
||||||
|
} else {
|
||||||
this.currentObjectPosition = grabbedProperties.position;
|
grabEquipCheck();
|
||||||
this.currentObjectRotation = grabbedProperties.rotation;
|
}
|
||||||
this.currentVelocity = ZERO_VEC;
|
|
||||||
this.currentAngularVelocity = ZERO_VEC;
|
|
||||||
|
|
||||||
this.prevDropDetected = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.nearGrabbing = function(deltaTime, timestamp) {
|
this.nearGrabbing = function(deltaTime, timestamp) {
|
||||||
|
|
Loading…
Reference in a new issue