mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 08:14:48 +02:00
Pass model offset from avatar skeletonModel to attached entity
This commit is contained in:
parent
96a97b5938
commit
088f227df2
7 changed files with 69 additions and 22 deletions
|
@ -400,7 +400,7 @@ void Avatar::relayJointDataToChildren() {
|
|||
}
|
||||
}
|
||||
|
||||
modelEntity->setOverrideTransform(_skeletonModel->getTransform());
|
||||
modelEntity->setOverrideTransform(_skeletonModel->getTransform(), _skeletonModel->getOffset());
|
||||
modelEntity->simulateRelayedJoints();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -862,10 +862,10 @@ glm::vec3 RenderableModelEntityItem::getLocalJointTranslation(int index) const {
|
|||
return glm::vec3();
|
||||
}
|
||||
|
||||
void RenderableModelEntityItem::setOverrideTransform(const Transform& transform) {
|
||||
void RenderableModelEntityItem::setOverrideTransform(const Transform& transform, const glm::vec3& offset) {
|
||||
auto model = getModel();
|
||||
if (model) {
|
||||
model->overrideModelTransform(transform);
|
||||
model->overrideModelTransform(transform, offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ public:
|
|||
bool getJointMapCompleted();
|
||||
void setJointMap(std::vector<int> jointMap);
|
||||
int avatarJointIndex(int modelJointIndex);
|
||||
void setOverrideTransform(const Transform& transform);
|
||||
void setOverrideTransform(const Transform& transform, const glm::vec3& offset);
|
||||
|
||||
// these are in the frame of this object (model space)
|
||||
virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override;
|
||||
|
|
|
@ -203,6 +203,7 @@ enum class EntityVersion : PacketVersion {
|
|||
StaticCertJsonVersionOne,
|
||||
OwnershipChallengeFix,
|
||||
ZoneLightInheritModes,
|
||||
ZoneStageRemoved,
|
||||
SoftEntities
|
||||
};
|
||||
|
||||
|
|
|
@ -1369,10 +1369,11 @@ void Model::deleteGeometry() {
|
|||
_collisionGeometry.reset();
|
||||
}
|
||||
|
||||
void Model::overrideModelTransform(const Transform& transform) {
|
||||
void Model::overrideModelTransform(const Transform& transform, const glm::vec3& offset) {
|
||||
_overrideTranslation = transform.getTranslation();
|
||||
_overrideRotation = transform.getRotation();
|
||||
_overrideModelTransform = true;
|
||||
setOffset(offset);
|
||||
}
|
||||
|
||||
AABox Model::getRenderableMeshBound() const {
|
||||
|
|
|
@ -208,7 +208,7 @@ public:
|
|||
|
||||
void setTranslation(const glm::vec3& translation);
|
||||
void setRotation(const glm::quat& rotation);
|
||||
void overrideModelTransform(const Transform& transform);
|
||||
void overrideModelTransform(const Transform& transform, const glm::vec3& offset);
|
||||
void setOverrideTransform(bool override) { _overrideModelTransform = override; };
|
||||
void setTransformNoUpdateRenderItems(const Transform& transform); // temporary HACK
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ ToggleButtonBuddy.prototype.addToggleHandler = function (callback) {
|
|||
};
|
||||
ToggleButtonBuddy.prototype.removeToggleHandler = function (callback) {
|
||||
var index = this.callbacks.indexOf(callback);
|
||||
if (index != -1) {
|
||||
if (index !== -1) {
|
||||
this.callbacks.splice(index, 1);
|
||||
}
|
||||
};
|
||||
|
@ -86,13 +86,23 @@ var coatButton = new ToggleButtonBuddy(buttonPositionX, buttonPositionY, BUTTON_
|
|||
down: "https://s3.amazonaws.com/hifi-public/tony/icons/coat-down.svg"
|
||||
});
|
||||
|
||||
buttonPositionY += BUTTON_HEIGHT + BUTTON_PADDING;
|
||||
var coatButton2 = new ToggleButtonBuddy(buttonPositionX, buttonPositionY, BUTTON_WIDTH, BUTTON_HEIGHT, {
|
||||
up: "https://s3.amazonaws.com/hifi-public/tony/icons/coat-up.svg",
|
||||
down: "https://s3.amazonaws.com/hifi-public/tony/icons/coat-down.svg"
|
||||
});
|
||||
|
||||
var AVATAR_ATTACHMENT = 0;
|
||||
var AVATAR_SOFT_ATTACHMENT = 1;
|
||||
var ENTITY_ATTACHMENT = 2;
|
||||
|
||||
var HAT_ATTACHMENT = {
|
||||
modelURL: "https://s3.amazonaws.com/hifi-public/tony/cowboy-hat.fbx",
|
||||
jointName: "Head",
|
||||
translation: {"x": 0, "y": 0.25, "z": 0.03},
|
||||
rotation: {"x": 0, "y": 0, "z": 0, "w": 1},
|
||||
scale: 0.052,
|
||||
isSoft: false
|
||||
type: AVATAR_ATTACHMENT
|
||||
};
|
||||
|
||||
var COAT_ATTACHMENT = {
|
||||
|
@ -101,7 +111,16 @@ var COAT_ATTACHMENT = {
|
|||
translation: {"x": 0, "y": 0, "z": 0},
|
||||
rotation: {"x": 0, "y": 0, "z": 0, "w": 1},
|
||||
scale: 1,
|
||||
isSoft: true
|
||||
type: AVATAR_SOFT_ATTACHMENT
|
||||
};
|
||||
|
||||
var COAT_ENTITY_ATTACHMENT = {
|
||||
modelURL: "https://hifi-content.s3.amazonaws.com/ozan/dev/clothes/coat/coat_rig.fbx",
|
||||
jointName: "Hips",
|
||||
translation: {"x": 0, "y": 0, "z": 0},
|
||||
rotation: {"x": 0, "y": 0, "z": 0, "w": 1},
|
||||
scale: 1,
|
||||
type: ENTITY_ATTACHMENT
|
||||
};
|
||||
|
||||
hatButton.addToggleHandler(function (isDown) {
|
||||
|
@ -120,28 +139,54 @@ coatButton.addToggleHandler(function (isDown) {
|
|||
}
|
||||
});
|
||||
|
||||
coatButton2.addToggleHandler(function (isDown) {
|
||||
if (isDown) {
|
||||
wearAttachment(COAT_ENTITY_ATTACHMENT);
|
||||
} else {
|
||||
removeAttachment(COAT_ENTITY_ATTACHMENT);
|
||||
}
|
||||
});
|
||||
|
||||
function wearAttachment(attachment) {
|
||||
MyAvatar.attach(attachment.modelURL,
|
||||
attachment.jointName,
|
||||
attachment.translation,
|
||||
attachment.rotation,
|
||||
attachment.scale,
|
||||
attachment.isSoft);
|
||||
if (attachment.type === AVATAR_ATTACHMENT || attachment.type === AVATAR_SOFT_ATTACHMENT) {
|
||||
MyAvatar.attach(attachment.modelURL,
|
||||
attachment.jointName,
|
||||
attachment.translation,
|
||||
attachment.rotation,
|
||||
attachment.scale,
|
||||
(attachment.type === AVATAR_SOFT_ATTACHMENT));
|
||||
} else {
|
||||
attachment.entityID = Entities.addEntity({
|
||||
name: "attachment",
|
||||
type: "Model",
|
||||
modelURL: attachment.modelURL,
|
||||
parentID: MyAvatar.sessionUUID,
|
||||
relayParentJoints: true,
|
||||
position: attachment.position,
|
||||
rotation: attachment.rotation,
|
||||
parentJointIndex: -1
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function removeAttachment(attachment) {
|
||||
var attachments = MyAvatar.attachmentData;
|
||||
var i, l = attachments.length;
|
||||
for (i = 0; i < l; i++) {
|
||||
if (attachments[i].modelURL === attachment.modelURL) {
|
||||
attachments.splice(i, 1);
|
||||
MyAvatar.attachmentData = attachments;
|
||||
break;
|
||||
if (attachment.type === AVATAR_ATTACHMENT || attachment.type === AVATAR_SOFT_ATTACHMENT) {
|
||||
var attachments = MyAvatar.attachmentData;
|
||||
var i, l = attachments.length;
|
||||
for (i = 0; i < l; i++) {
|
||||
if (attachments[i].modelURL === attachment.modelURL) {
|
||||
attachments.splice(i, 1);
|
||||
MyAvatar.attachmentData = attachments;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Entities.deleteEntity(attachment.entityID);
|
||||
}
|
||||
}
|
||||
|
||||
Script.scriptEnding.connect(function() {
|
||||
hatButton.destroy();
|
||||
coatButton.destroy();
|
||||
coatButton2.destroy();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue