-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathrendertest.js
More file actions
156 lines (127 loc) · 5.02 KB
/
Copy pathrendertest.js
File metadata and controls
156 lines (127 loc) · 5.02 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { observeElement } from '../../core/observer.js';
import { callRobloxApiJson } from '../../core/api.js';
import {
RegisterWrappers,
RBXRenderer,
Instance,
HumanoidDescriptionWrapper,
RBX,
Outfit,
API,
FLAGS,
AnimatorWrapper
} from 'roavatar-renderer';
// This script is kinad outdated
FLAGS.ASSETS_PATH = chrome.runtime.getURL("assets/rbxasset/");
FLAGS.USE_WORKERS = false;
let currentRig = null;
let lastFrameTime = Date.now() / 1000;
let animationRequestId = null;
async function playEmote(emoteAssetId, loop = true) {
if (!currentRig) return;
const humanoid = currentRig.FindFirstChildOfClass("Humanoid");
const animator = humanoid?.FindFirstChildOfClass("Animator");
if (animator) {
const animatorW = new AnimatorWrapper(animator);
const animName = `emote.${emoteAssetId}`;
console.log(`Playing Emote ID: ${emoteAssetId}`);
await animatorW.loadAvatarAnimation(BigInt(emoteAssetId), true, loop);
animatorW.playAnimation(animName);
}
}
async function renderAvatarPage(contentDiv) {
if (window.location.pathname.toLowerCase() !== '/render') return;
if (animationRequestId) cancelAnimationFrame(animationRequestId);
contentDiv.innerHTML = '';
contentDiv.style.display = 'flex';
contentDiv.style.flexDirection = 'column';
contentDiv.style.alignItems = 'center';
contentDiv.style.gap = '15px';
const viewport = document.createElement('div');
viewport.style.width = '512px';
viewport.style.height = '512px';
contentDiv.appendChild(viewport);
const emoteBar = document.createElement('div');
emoteBar.style.display = 'flex';
emoteBar.style.gap = '8px';
emoteBar.style.flexWrap = 'wrap';
emoteBar.style.justifyContent = 'center';
emoteBar.style.maxWidth = '600px';
contentDiv.appendChild(emoteBar);
try {
RegisterWrappers();
RBXRenderer.fullSetup();
viewport.appendChild(RBXRenderer.getRendererDom());
const userId = "447170745";
const avatarData = await callRobloxApiJson({
subdomain: 'avatar',
endpoint: `/v2/avatar/users/${userId}/avatar`,
method: 'GET'
});
const outfit = new Outfit();
outfit.fromJson(avatarData);
const rigType = avatarData.playerAvatarType;
const rigUrl = chrome.runtime.getURL(`assets/Rig${rigType}.rbxm`);
const rigResult = await API.Asset.GetRBX(rigUrl, undefined);
if (rigResult instanceof RBX) {
if (currentRig) currentRig.Destroy();
currentRig = rigResult.generateTree().GetChildren()[0];
RBXRenderer.addInstance(currentRig, null);
}
const hrp = new Instance("HumanoidDescription");
const hrpWrapper = new HumanoidDescriptionWrapper(hrp);
hrpWrapper.fromOutfit(outfit);
const humanoid = currentRig?.FindFirstChildOfClass("Humanoid");
if (humanoid) {
await hrpWrapper.applyDescription(humanoid);
RBXRenderer.addInstance(currentRig, null);
if (avatarData.emotes && avatarData.emotes.length > 0) {
avatarData.emotes.forEach(emote => {
const btn = document.createElement('button');
btn.innerText = emote.assetName;
btn.style.padding = '10px 15px';
btn.style.background = '#393b3d';
btn.style.color = 'white';
btn.style.border = '1px solid #555';
btn.style.borderRadius = '5px';
btn.style.cursor = 'pointer';
btn.style.fontSize = '12px';
btn.onclick = () => playEmote(emote.assetId, true);
emoteBar.appendChild(btn);
});
playEmote(avatarData.emotes[0].assetId, false);
}
startAnimationLoop();
}
} catch (err) {
console.error("Avatar Render Error:", err);
}
}
function startAnimationLoop() {
const animate = () => {
if (currentRig) {
const humanoid = currentRig.FindFirstChildOfClass("Humanoid");
const animator = humanoid?.FindFirstChildOfClass("Animator");
if (animator) {
const currentTime = Date.now() / 1000;
const deltaTime = currentTime - lastFrameTime;
lastFrameTime = currentTime;
const animatorW = new AnimatorWrapper(animator);
animatorW.renderAnimation(deltaTime);
RBXRenderer.addInstance(currentRig, null);
}
}
animationRequestId = requestAnimationFrame(animate);
};
lastFrameTime = Date.now() / 1000;
animate();
}
export function init() {
chrome.storage.local.get('eastereggslinksEnabled', async (result) => {
if (result.eastereggslinksEnabled) {
observeElement('.content#content', (cDiv) => {
renderAvatarPage(cDiv);
});
}
});
}