(function() { // // // function setAttachments(attachmentData) { /*var drinkAttachmentData = { Head: { jointName: 'Head', modelUrl: attachmentModel, rotation: { x: 0, y: 0, z: 0 }, scale: scale, soft: false, translation: { x: 0, y: 0.280, z: 0.01 } } };*/ print ('attaching' + JSON.stringify(attachmentData)); var currentAttachments = MyAvatar.getAttachmentsVariant(); var newAttachments = []; newAttachments.push(attachmentData); currentAttachments.forEach(function(attachment) { if (attachment.jointName !== attachmentData.jointName) { newAttachments.push(attachment); } }); MyAvatar.setAttachmentsVariant(newAttachments); } var attachTheModel = function(entityID) { var properties = Entities.getEntityProperties(entityID, ['modelURL', 'dimensions', 'userData']); var attachment = null; try { var attachment = JSON.parse(properties.userData).attachment; } catch (e) { } if (attachment === null || attachment === undefined) { print('Could not find attachment data: bailing.') return; } if (attachment.jointName === undefined) { print('No jointName present: bailing.'); return; } if (attachment.scale === undefined) { attachment.scale = Math.max.apply(Math, [properties.dimensions.x, properties.dimensions.y, properties.dimensions.z]); } if (attachment.modelUrl === undefined) { attachment.modelUrl = properties.modelURL; } setAttachments(attachment); }; this.startNearTrigger = function(entityID, args) { attachTheModel(entityID); }; this.clickReleaseOnEntity = function(entityID, mouseEvent) { attachTheModel(entityID); }; })