-
Notifications
You must be signed in to change notification settings - Fork 0
/
live-ready-player-me.js
132 lines (106 loc) · 3.89 KB
/
live-ready-player-me.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
"use strict";
//
// live-ready-player-me.js
//
// Created by Alezia Kurdis, March 1st, 2022.
// Copyright 2022, Overte e.V.
//
// Ready-player-me application. (Wolfe3D avatar provider). In-world live version.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function() {
var jsMainFileName = "live-ready-player-me.js";
var ROOT = Script.resolvePath('').split(jsMainFileName)[0];
var APP_URL = ROOT + "ready-player-me-live.html";
var overlayWebWindow = new OverlayWebWindow({
title: "Ready Player Me",
source: "about:blank",
width: 1280,
height: 720,
visible: false
});
var uuid = "com.overte.readyPlayerMe.live";
function emitEvent(key, value) {
overlayWebWindow.emitScriptEvent(
JSON.stringify({ "uuid": uuid, "key": key, "value": value })
);
}
overlayWebWindow.webEventReceived.connect(function (jsonStr) {
var data = null;
try {
data = JSON.parse(jsonStr);
} catch (err) {
return;
}
if (!data.uuid && !data.key) return;
if (data.uuid.indexOf(uuid) == -1) return;
switch (data.key) {
case "displayName":
var displayName = MyAvatar.displayName ? MyAvatar.displayName : "Avatar";
emitEvent("displayName", displayName);
break;
case "finish":
MyAvatar.useFullAvatarURL(data.value.avatarUrl + "?version=" + Math.floor(Math.random() * 65000) );
if (data.value.bookmarkName !== "") {
AvatarBookmarks.addBookmark(data.value.bookmarkName);
}
setActive(false);
}
});
function setActive(active) {
overlayWebWindow.setURL(Script.resolvePath("ready-player-me-live.html") + "?1");
overlayWebWindow.setVisible(active);
}
//Event to trigger here:
//setActive(!button.getProperties().isActive);
overlayWebWindow.closed.connect(function () {
setActive(false);
});
var MAX_CLICKABLE_DISTANCE_M = 10;
var appScriptUrl = ROOT + "app-ready-player-me.js";
// Constructor
var _this = null;
function clickableUI() {
_this = this;
this.entityID = null;
}
// Entity methods
clickableUI.prototype = {
preload: function (id) {
_this.entityID = id;
HMD.displayModeChanged.connect(this.displayModeChangedCallback);
},
displayModeChangedCallback: function() {
if (_this && _this.entityID) {
//Nothing
}
},
mousePressOnEntity: function (entityID, event) {
if (event.isPrimaryButton &&
Vec3.distance(MyAvatar.position, Entities.getEntityProperties(_this.entityID, ["position"]).position) <= MAX_CLICKABLE_DISTANCE_M) {
if (!overlayWebWindow.visible){
setActive(true);
}
var running = false;
var runningScripts = ScriptDiscoveryService.getRunning();
for (var i = 0; i < runningScripts.length; i++) {
if (runningScripts[i].url === appScriptUrl) {
running = true;
break;
}
}
if (!running) {
ScriptDiscoveryService.loadScript(appScriptUrl, true, false, false, true, false);
} else {
//print("Already running!");
}
}
},
unload: function () {
HMD.displayModeChanged.disconnect(this.displayModeChangedCallback);
}
};
return new clickableUI();
});