62 lines
2.1 KiB
JavaScript
62 lines
2.1 KiB
JavaScript
// Script written by Thoys, mainly for fun , feel free to use it for anything
|
|
(function() {
|
|
function setAttachments(attachmentModel, joint, scale) {
|
|
var drinkAttachmentData = {
|
|
LeftHand: {
|
|
jointName: 'LeftHand',
|
|
modelUrl: attachmentModel,
|
|
rotation: {
|
|
x: 12,
|
|
y: 0,
|
|
z: 75
|
|
},
|
|
scale: scale,
|
|
soft: false,
|
|
translation: {
|
|
x: 0,
|
|
y: 0.08,
|
|
z: 0.06
|
|
}
|
|
},
|
|
RightHand: {
|
|
jointName: 'RightHand',
|
|
modelUrl: attachmentModel,
|
|
rotation: {
|
|
x: 12,
|
|
y: 0,
|
|
z: 255
|
|
},
|
|
scale: scale,
|
|
soft: false,
|
|
translation: {
|
|
x: 0,
|
|
y: 0.08,
|
|
z: 0.06
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
var currentAttachments = MyAvatar.getAttachmentsVariant();
|
|
var newAttachments = [];
|
|
newAttachments.push(drinkAttachmentData[joint]);
|
|
currentAttachments.forEach(function(attachment) {
|
|
if (attachment.jointName !== drinkAttachmentData[joint].jointName) {
|
|
newAttachments.push(attachment);
|
|
}
|
|
});
|
|
MyAvatar.setAttachmentsVariant(newAttachments);
|
|
}
|
|
|
|
var attachTheModel = function(entityID, jointName) {
|
|
var properties = Entities.getEntityProperties(entityID, ['modelURL', 'dimensions']);
|
|
setAttachments(properties.modelURL, jointName, Math.max.apply(Math, [properties.dimensions.x, properties.dimensions.y, properties.dimensions.z]));
|
|
};
|
|
|
|
this.startNearTrigger = function(entityID, args) {
|
|
attachTheModel(entityID, args[0] == 'left' ? 'LeftHand' : 'RightHand');
|
|
};
|
|
this.clickReleaseOnEntity = function(entityID, mouseEvent) {
|
|
attachTheModel(entityID, mouseEvent.isLeftButton ? 'LeftHand' : 'RightHand');
|
|
};
|
|
})
|