forked from jeeliz/jeelizWeboji
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
132 lines (108 loc) · 3.66 KB
/
main.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
let _SVGpupilLeft = null, _SVGpupilRight = null, _SVGhead = null;
function move_pupil(SVGpupil, dx, dy){
JeelizWebojiSVGHelper.pos_SVGpath(SVGpupil, dx, dy);
}
function rotate_headZ(rz){
JeelizWebojiSVGHelper.rot_SVGpath(_SVGhead, rz);
}
// entry point:
function main(){
_SVGpupilLeft = document.getElementById('svgPupilLeft');
_SVGpupilRight = document.getElementById('svgPupilRight');
_SVGhead = document.getElementById('svgHead');
JeelizWebojiSVGHelper.init({
canvasId: 'jeelizFaceExpressionsCanvas',
NNCPath: '../../dist/',
hysteresis: 0.02, // bonus score for already selected expression. Against flickering
isMirror: true,
expressions: [ // list of uncorrelated expressions (for example the mouth is uncorrelated with the right eye)
{ // mouth. Inside a group each expression is an exclusive choice
// the key of an expression is its CSS class. the value is the score class
// the chosen expression is the one which has the higher score
/*
All factors are between 0 and 1. names:
smileRight -> closed mouth smile right
smileLeft -> closed mouth smile left
eyeBrowLeftDown -> eyebrow left frowned
eyeBrowRightDown -> eyebrow right frowned
eyeBrowLeftUp -> eyebrow left up (surprised)
eyeBrowRightUp -> eyebrow right up (surprised)
mouthOpen -> mouth open
mouthRound -> mouth round
eyeRightClose -> close right eye
eyeLeftClose -> close left eye
mouthNasty -> mouth nasty (upper lip raised)
*/
svgMouthRound: function(ks){
return 0.7 * ks.mouthRound - 0.1 * ks.mouthOpen - 0.2;
},
svgMouthOpen: function(ks){
return 1.0 * ks.mouthOpen;
},
svgMouthRest:function(ks){
return 0.45;
},
svgMouthNasty: function(ks){
return ks.mouthNasty * 2.0 + 0.2 * ks.mouthOpen;
},
svgSmileLeft: function(ks){
return ks.smileLeft - ks.smileRight;
},
svgSmileRight: function(ks){
return ks.smileRight - ks.smileLeft;
},
svgSmile: function(ks){
return (ks.smileRight + ks.smileLeft);
}
},
{ // left eye
svgEyeLeftOpen: function(ks){
return 1. - ks.eyeLeftClose;
},
svgEyeLeftClose: function(ks){
return 1.5 * ks.eyeLeftClose;
}
},
{ // right eye
svgEyeRightOpen: function(ks){
return 1. - ks.eyeRightClose;
},
svgEyeRightClose: function(ks){
return 1.0 * ks.eyeRightClose;
}
},
{ // left eyebrow
eyeBrowLeftRest: function(ks){
return 0.4;
},
eyeBrowLeftUp: function(ks){
return ks.eyeBrowLeftUp;
},
eyeBrowLeftDown: function(ks){
return 1.0 * ks.eyeBrowLeftDown;
}
},
{ // right eyebrow
eyeBrowRightRest: function(ks){
return 0.4;
},
eyeBrowRightUp: function(ks){
return ks.eyeBrowRightUp;
},
eyeBrowRightDown: function(ks){
return 1.0 * ks.eyeBrowRightDown;
}
}
], //end expressions[]
rotationCallback: function(xyz){
const rx = xyz[0], // head angle: rotation around X (look up/down)
ry = xyz[1], // rotation around Y: look right/left
rz = xyz[2]; // rotation around Z: head bending
const dx = 12*ry, dy = -5+20*rx;
move_pupil(_SVGpupilRight, dx,dy);
move_pupil(_SVGpupilLeft, dx,dy);
rotate_headZ(-rz*150);
}
});
} //end main()
window.addEventListener('load', main);