generated from dohack-io/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreenshot.js
155 lines (130 loc) · 4.24 KB
/
screenshot.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const Settings = {
targetScale: 10,
positionOffset: {
x: 0,
y: -15,
z: 0
}
}
const init = () => {
document.querySelector("#uploadBtn").addEventListener("change", (e) => { handleFiles(e.target.files) });
document.querySelector("#downloadBtn").addEventListener("click", () => {
const canvas = document.querySelector("#jeeFaceFilterCanvas");
const downloadLink = document.querySelector("#downloadLink");
const name = "KudoDemo";
const filename = name + "_" + Date.now();
if (canvas.msToBlob) {
const blob = canvas.msToBlob();
window.navigator.msSaveBlob(blob, filename);
} else {
downloadLink.href = canvas.toDataURL('image/png');
downloadLink.download = filename;
downloadLink.click();
}
});
}
window.addEventListener('load', function () {
init();
});
const handleFiles = (files) => {
const avatarURL = window.URL.createObjectURL(files[0]);
AVATAR_READY = false;
const light = new THREE.HemisphereLight(0xbbbbff, 0x444422);
light.position.set(0, 1, 0);
THREE.JeelizHelper.Scene.remove(AVATAR.getScene());
AVATAR = new WebVRM(avatarURL, THREE.JeelizHelper.Scene, avatarInit);
}
let AVATAR_READY = false;
let AVATAR;
const createVRM = () => {
AVATAR = new WebVRM("./assets/MonoPub.vrm", THREE.JeelizHelper.Scene, avatarInit);
}
const avatarInit = () => {
AVATAR_READY = true
console.log(AVATAR);
ajast()
}
let ajast = () => {
AVATAR.getScene().rotation.set(0, Math.PI, 0);
initialPose();
//HACK: èªã¿è¾¼ã¿ç›´å¾Œã¯ãƒ¯ãƒ¼ãƒ«ãƒ‰åº§æ¨™ãŒå–ã‚Œãªã„?
setTimeout(() => {
AVATAR.setBoneRotation("head", { x: 0, y: 0, z: 0 });
const avatarScale = AVATAR._skeleton._boneMap.get("leftEye").bone.getWorldPosition().y - AVATAR._skeleton._boneMap.get("hips").bone.getWorldPosition().y;
const scale = Settings.targetScale * 0.5473522283979353 / avatarScale;
console.log("avatarScale" + avatarScale);
console.log("Scale" + scale);
AVATAR.setScale(scale);
//Settings.positionOffset.y = -150 / scale;
}, 100);
//ajast = () => { };
}
const initialPose = () => {
AVATAR.setBoneRotation("rightUpperArm", { z: -Math.PI / 4 });
AVATAR.setBoneRotation("leftUpperArm", { z: Math.PI / 4 });
}
const update = (detectState) => {
if (!AVATAR_READY) return;
avatar = AVATAR.getScene();
const targetPosition = THREE.JeelizHelper.CompositeObjects[0].position;
const targetRotation = THREE.JeelizHelper.CompositeObjects[0].rotation;
const currentRotation = {
x: -targetRotation.x,
y: targetRotation.y,
z: -targetRotation.z
}
const currentPosition = {
x: targetPosition.x + Settings.positionOffset.x,
y: targetPosition.y + Settings.positionOffset.y,
z: targetPosition.z + Settings.positionOffset.z
};
moveGaze(currentRotation);
avatar.position.set(currentPosition.x, currentPosition.y, currentPosition.z);
AVATAR.setBoneRotation("head", currentRotation);
changeEmote(detectState.expressions);
}
const moveGaze = (headRotation) => {
const eyeRotation = {
x: -headRotation.x * 0.5,
y: -headRotation.y * 0.5,
z: 0,
}
AVATAR.setBoneRotation("rightEye", eyeRotation);
AVATAR.setBoneRotation("leftEye", eyeRotation);
}
let emoteState = 0;
let isMouthOpen = false;
const changeEmote = (mouthOpen) => {
if (!isMouthOpen && (mouthOpen >= 0.9)) {
isMouthOpen = true;
emoteState = (emoteState + 1) % 5;
}
else if (isMouthOpen && (mouthOpen <= 0.1)) {
isMouthOpen = false;
}
let expressions = {
"fun": 0,
"angry": 0,
"joy": 0,
"sorrow": 0
}
switch (emoteState) {
case 1:
expressions.fun = 1;
break;
case 2:
expressions.angry = 1;
break;
case 3:
expressions.joy = 1;
break;
case 4:
expressions.sorrow = 1;
break;
default:
break;
}
for (key in expressions) {
AVATAR.setExpression(key, expressions[key]);
}
}