egg = loadModel('egg.obj', false, () => {}, () => {})
yolk = loadModel('yolk.obj', false, () => {}, () => {})
createCanvas(600, 600, WEBGL)
setAttributes({ antialias: true })
const eggPieces = [geomToPiece(egg)]
const yolkPieces = [geomToPiece(yolk)]
for (let y = -75; y <= 50; y += 25) {
for (const arr of [eggPieces, yolkPieces]) {
const [left, right] = cutObject(last, createVector(0,y,0), createVector(0,1,0))
eggSlices = eggPieces.map(pieceToGeom)
yolkSlices = yolkPieces.map((faces) => {
const ys = faces.flatMap((pts) => pts.flatMap((pt) => pt.pos.y))
const minY = ys.reduce((acc, next) => min(acc, next))
const maxY = ys.reduce((acc, next) => max(acc, next))
const avgY = (minY + maxY) / 2
return faces.map((pts) => pts.map((pt) => ({
pos: pt.pos.copy().add(0, pt.pos.y < avgY ? -1 : 1, 0),
ambientMaterial('#ede185')
pointLight(100, 100, 100, width/2, -height/2, 100)
pointLight(50, 50, 50, width/3, -height/3, 200)
directionalLight(128, 128, 128, 1, 0, -1)
for (const [arr, setupMaterial] of [[yolkSlices, yolkMat], [eggSlices, eggMat]]) {
arr.forEach((piece, i) => {
const loopProgress = ((t + i * 100) % 5000) / 5000
Ease.easeOutElastic(map(loopProgress, 0.25, 0.5, 0, 1, true)) *
(1 - Ease.easeInOutCubic(map(loopProgress, 0.75, 1, 0, 1, true)))
translate(0, lerp(0, map(i, 0, arr.length-1, -150, 200), mix), 0)