p5.disableFriendlyErrors = true;
myFont = loadFont('Roboto-Black.ttf');
blendMesh = loadModel('normal.obj');
normalMesh = loadModel('normal.obj');
hairMesh = loadModel('hair.obj');
browsMesh = loadModel('brows.obj');
eyesMesh = loadModel('eyes.obj');
pupilsMesh = loadModel('pupils.obj');
leftMesh = loadModel('left.obj');
rightMesh = loadModel('right.obj');
upMesh = loadModel('up.obj');
downMesh = loadModel('down.obj');
canvas = createCanvas(windowWidth, windowHeight, WEBGL);
background(160, 200, 255);
if (mouseX > posX) mouseX-=acc;
if (mouseX < posX) mouseX+=acc;
if (mouseY > posY) mouseY-=acc;
if (mouseY < posY) mouseY+=acc;
text("Move your mouse around\nPress space to toggle edges", 0, height / 2 - 50);
ambientMaterial(220, 100, 100);
function refreshMeshes() {
blendMesh._edgesToVertices();
canvas.createBuffers(gid, blendMesh);
blendMesh.dirtyFlags['vertexNormals'] = true;
blendMesh.dirtyFlags['lineVertices'] = true;
blendMesh.dirtyFlags['vertices'] = true;
function displayMeshes() {
ambientMaterial(255, 150, 130);
ambientMaterial(120, 100, 90);
ambientMaterial(255, 255, 255);
ambientMaterial(0, 0, 0);
function addDelta(otherMesh, blendValue, vertIndex) {
let deltaX = otherMesh.vertices[vertIndex].x - normalMesh.vertices[vertIndex].x;
let deltaY = otherMesh.vertices[vertIndex].y - normalMesh.vertices[vertIndex].y;
let deltaZ = otherMesh.vertices[vertIndex].z - normalMesh.vertices[vertIndex].z;
blendMesh.vertices[vertIndex].x += deltaX * blendValue;
blendMesh.vertices[vertIndex].y += deltaY * blendValue;
blendMesh.vertices[vertIndex].z += deltaZ * blendValue;
function blendMeshToTargets() {
let yawTargetMesh = null;
if (mouseX < width / 2) {
yawTargetMesh = rightMesh;
yawBlendVal = map(mouseX, 0, width / 2, exaggerate, 0);
yawTargetMesh = leftMesh;
yawBlendVal = map(mouseX, width / 2, width, 0, exaggerate);
let pitchTargetMesh = null;
if (mouseY < height / 2) {
pitchTargetMesh = upMesh;
pitchBlendVal = map(mouseY, 0, height / 2, exaggerate, 0);
pitchTargetMesh = downMesh;
pitchBlendVal = map(mouseY, height / 2, height, 0, exaggerate);
for (let i = 0; i < blendMesh.vertices.length; i++) {
blendMesh.vertices[i].x = normalMesh.vertices[i].x;
blendMesh.vertices[i].y = normalMesh.vertices[i].y;
blendMesh.vertices[i].z = normalMesh.vertices[i].z;
addDelta(yawTargetMesh, yawBlendVal, i);
addDelta(pitchTargetMesh, pitchBlendVal, i);
save("img_" + month() + '-' + day() + '_' + hour() + '-' + minute() + '-' + second() + ".jpg");