diff --git a/applications/attach-avatar-app/assets/Halo.fbx b/applications/attach-avatar-app/assets/Halo.fbx new file mode 100644 index 0000000..19263b1 Binary files /dev/null and b/applications/attach-avatar-app/assets/Halo.fbx differ diff --git a/applications/attach-avatar-app/assets/account-child-circle.png b/applications/attach-avatar-app/assets/account-child-circle.png new file mode 100644 index 0000000..0c1194c Binary files /dev/null and b/applications/attach-avatar-app/assets/account-child-circle.png differ diff --git a/applications/attach-avatar-app/assets/account-child-circle.svg b/applications/attach-avatar-app/assets/account-child-circle.svg new file mode 100644 index 0000000..6476108 --- /dev/null +++ b/applications/attach-avatar-app/assets/account-child-circle.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/applications/attach-avatar-app/attachAvatarApp.js b/applications/attach-avatar-app/attachAvatarApp.js new file mode 100644 index 0000000..5c732f0 --- /dev/null +++ b/applications/attach-avatar-app/attachAvatarApp.js @@ -0,0 +1,81 @@ +/* globals Vec3, Quat, Uuid, Camera, MyAvatar, Entities, Overlays, Script, Tablet, AvatarList, AvatarManager, Picks, PickType require ScriptDiscoveryService */ +// +// attachAvatarApp.js +// +// Created by KasenVR on 2 August 2020. +// Copyright 2020 Vircadia contributors. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var APP_NAME = "Avatar Attach App"; +var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); + +var accountChildIcon = 'data:image/svg+xml;utf8,';; + +var button = tablet.addButton({ + text: "ATTACH", + icon: accountChildIcon.replace('black', 'white'), + activeIcon: accountChildIcon +}); + +Script.scriptEnding.connect(function(){ + tablet.removeButton(button); + button = null; +}); + +button.clicked.connect(togglePlatform); +var platformID; + +function togglePlatform() { + + function getNearbyAvatars(origin, sessionUUIDs) { + + var cleanAvatars = sessionUUIDs.filter(function (id) { + if (id == null) { + return false; + } + + var idString = id.toString(); + + if (idString.indexOf(MyAvatar.sessionUUID) === -1) { + return true; + } else { + return false; + } + }); + + return cleanAvatars.map(function(id) { + var avi = AvatarList.getAvatar(id); + avi.$distance = Vec3.distance(origin, avi.position); + return avi; + }).sort(function(a, b) { + return a.$distance < b.$distance ? -1 : a.$distance > b.$distance ? 1 : 0; + }); + + }; + + var nearest = getNearbyAvatars(MyAvatar.position, AvatarList.getAvatarIdentifiers())[0]; + var platformScale = { x: 0.604 * MyAvatar.scale, y: 0.036 * MyAvatar.scale, z: 0.604 * MyAvatar.scale }; + + if(platformID) { + Entities.deleteEntity(platformID); + platformID = null; + MyAvatar.setParentID("null"); + } else if (nearest != null) { + platformID = Entities.addEntity({ + type: "Model", + modelURL: Script.resolvePath("./assets/Halo.fbx"), + position: MyAvatar.position, + rotation: Quat.IDENTITY, + dimensions: platformScale, + collisionMask: 8, + collisionless: false, + shapeType: "box", + parentID: nearest.sessionUUID, + parentJointIndex: 0, + }, "avatar"); // Make it a client entity! We want it to show up/load in other worlds without rez rights. + MyAvatar.setParentID(platformID); + } +} diff --git a/applications/metadata.js b/applications/metadata.js index 449c78a..0087842 100644 --- a/applications/metadata.js +++ b/applications/metadata.js @@ -80,5 +80,14 @@ var metadata = { "applications": [ "icon": "nametags/assets/nametags-i.svg", "caption": "NAMETAGS" }, + { + "isActive": true, + "directory": "attach-avatar-app", + "name": "Attach Avatar", + "description": "Attaches your avatar to another avatar via a collisionless platform.", + "jsfile": "attach-avatar-app/attachAvatarApp.js", + "icon": "attach-avatar-app/assets/account-child-circle.png", + "caption": "ATCH AVI" + } ] };