From 9eab8a73ca694a53dcbb4597ee08916df1154008 Mon Sep 17 00:00:00 2001 From: Florian <45694132+flo-bit@users.noreply.github.com> Date: Sun, 9 Feb 2025 02:50:23 +0100 Subject: [PATCH] add some emotions --- src/lib/Creature.svelte | 85 +++++++++++------ src/lib/Pane.svelte | 179 +++++++++++++++++++++++++++++------ src/lib/Scene.svelte | 20 +++- src/lib/face/curve.ts | 46 ++++++--- src/lib/face/eye.ts | 134 +++++++++++++------------- src/lib/face/face.ts | 77 +++++---------- src/lib/face/math-helper.ts | 8 ++ src/lib/state.svelte.ts | 182 +++++++++++++++++++++++++++++++++++- src/routes/+page.svelte | 52 +++++++++++ 9 files changed, 575 insertions(+), 208 deletions(-) diff --git a/src/lib/Creature.svelte b/src/lib/Creature.svelte index bf36aed..3c574b1 100644 --- a/src/lib/Creature.svelte +++ b/src/lib/Creature.svelte @@ -39,7 +39,7 @@ let mouse = new THREE.Vector2(); function jump() { - ySpeed = 5; + if (rootBone?.position.y <= -1) ySpeed = 5; } let primaryColors: THREE.TSL.ShaderNodeObject>[] = []; @@ -66,7 +66,9 @@ let total = 12; for (let i = 0; i < total; i++) { - const material = new THREE.MeshStandardNodeMaterial(); + const material = new THREE.MeshStandardNodeMaterial({ + side: THREE.DoubleSide + }); // move vertices along normal to make each shell slightly bigger than the last material.positionNode = positionGeometry @@ -166,7 +168,7 @@ onMount(async () => { addEventListeners(); - await createTextures(); + await createTextures(); const loader = new GLTFLoader(); @@ -201,7 +203,7 @@ rootBone.position.y = Math.max(rootBone.position.y, -1) + position[1]; rootBone.position.z = position[2]; - ySpeed -= 10 * dt; + ySpeed -= 20 * dt; } if (!face) return; @@ -217,31 +219,56 @@ if (options.hasChanged) { console.log('updating creature'); - face.eyebrowLeft.options.set('curve', options.leftEyebrow.curve); - face.eyebrowLeft.options.set('stroke', options.leftEyebrow.stroke); - face.eyebrowLeft.options.set('width', options.leftEyebrow.width); - face.eyebrowLeft.options.set('x', options.leftEyebrow.x); - face.eyebrowLeft.options.set('y', options.leftEyebrow.y); - face.eyebrowLeft.options.set('angle', options.leftEyebrow.angle); - - face.eyebrowRight.options.set('curve', options.rightEyebrow.curve); - face.eyebrowRight.options.set('stroke', options.rightEyebrow.stroke); - face.eyebrowRight.options.set('width', options.rightEyebrow.width); - face.eyebrowRight.options.set('x', options.rightEyebrow.x); - face.eyebrowRight.options.set('y', options.rightEyebrow.y); - face.eyebrowRight.options.set('angle', options.rightEyebrow.angle); - - face.mouth.options.set('curve', options.mouth.curve); - face.mouth.options.set('stroke', options.mouth.stroke); - face.mouth.options.set('width', options.mouth.width); - face.mouth.options.set('x', options.mouth.x); - face.mouth.options.set('y', options.mouth.y); - - face.furMouth.options.set('curve', options.mouth.curve); - face.furMouth.options.set('stroke', options.mouth.stroke); - face.furMouth.options.set('width', options.mouth.width); - face.furMouth.options.set('x', options.mouth.x); - face.furMouth.options.set('y', options.mouth.y); + if (options.currentEmotion) { + const emotion: Record = options.emotions[options.currentEmotion]; + + for (const key in emotion) { + const option = emotion[key]; + + for (const optionKey in option) { + const optionValue = option[optionKey]; + + options[key][optionKey] = optionValue; + } + } + options.currentEmotion = ''; + } + + const colorEyebrowLeft = new THREE.Color(options.leftEyebrow.color); + face.eyebrowLeft.options.setMultiple({ + ...options.leftEyebrow, + colorRed: colorEyebrowLeft.r * 256, + colorGreen: colorEyebrowLeft.g * 256, + colorBlue: colorEyebrowLeft.b * 256 + }); + + const colorEyebrowRight = new THREE.Color(options.rightEyebrow.color); + face.eyebrowRight.options.setMultiple({ + ...options.rightEyebrow, + colorRed: colorEyebrowRight.r * 256, + colorGreen: colorEyebrowRight.g * 256, + colorBlue: colorEyebrowRight.b * 256 + }); + + const colorMouth = new THREE.Color(options.mouth.color); + face.mouth.options.setMultiple({ + ...options.mouth, + colorRed: colorMouth.r * 256, + colorGreen: colorMouth.g * 256, + colorBlue: colorMouth.b * 256 + }); + + face.leftEye.options.setMultiple({ + ...options.leftEye, + }); + + face.rightEye.options.setMultiple({ + ...options.rightEye, + }); + + face.furMouth.options.setMultiple({ + ...options.mouth, + }); face.updateBackground(options.colors.primary); diff --git a/src/lib/Pane.svelte b/src/lib/Pane.svelte index b3159ed..7c5be78 100644 --- a/src/lib/Pane.svelte +++ b/src/lib/Pane.svelte @@ -5,12 +5,34 @@ Folder, Color, ThemeUtils, + Button, + Text, + Separator } from 'svelte-tweakpane-ui'; import { options } from './state.svelte'; + import { onMount } from 'svelte'; function change() { options.hasChanged = true; } + + function saveEmotions() { + localStorage.setItem('emotions', JSON.stringify(options.emotions)); + } + + onMount(() => { + const emotions = localStorage.getItem('emotions'); + if (emotions) { + options.emotions = { + ...options.emotions, + ...JSON.parse(emotions) + }; + + console.log(emotions) + } + }); + + let newEmotion = '';
- + @@ -61,20 +77,30 @@ max={100} on:change={change} /> + + + - + + + + + + + + + + + + + + + + + + + + + + @@ -131,11 +227,36 @@ - + + {#each Object.keys(options.emotions) as emotion} +
diff --git a/src/lib/Scene.svelte b/src/lib/Scene.svelte index 6b4a101..1e7dc94 100644 --- a/src/lib/Scene.svelte +++ b/src/lib/Scene.svelte @@ -11,12 +11,26 @@ var stats = new Stats(); + let distance = 5; + onMount(() => { renderer.toneMapping = CineonToneMapping; scene.environmentIntensity = 0.2; + if (window.innerWidth < 768) { + distance = 8; + } + stats.showPanel(0); document.body.appendChild(stats.dom); + + window.addEventListener('resize', () => { + if (window.innerWidth < 768) { + distance = 8; + } else { + distance = 5; + } + }); }); const { renderStage } = useThrelte(); @@ -36,16 +50,12 @@ ); - + - - diff --git a/src/lib/face/curve.ts b/src/lib/face/curve.ts index e8bb2ed..adcf1c5 100644 --- a/src/lib/face/curve.ts +++ b/src/lib/face/curve.ts @@ -7,20 +7,21 @@ export type CurveOptions = { width: number; curve: number; - color: PIXI.ColorSource; + colorRed: number; + colorGreen: number; + colorBlue: number; x: number; y: number; angle: number; + sharpness: number; }; export default class Curve { graphics: PIXI.Graphics; - color: PIXI.ColorSource = 0x515151; - - options: AnimatedProperties>; + options: AnimatedProperties; constructor(opts: Partial) { this.options = new AnimatedProperties({ @@ -30,10 +31,13 @@ export default class Curve { curve: opts?.curve ?? 10, x: opts?.x ?? 0, y: opts?.y ?? 0, - angle: opts?.angle ?? 0 + angle: opts?.angle ?? 0, + sharpness: opts?.sharpness ?? 0, + colorRed: opts?.colorRed ?? 20, + colorGreen: opts?.colorGreen ?? 20, + colorBlue: opts?.colorBlue ?? 20 }); this.graphics = new PIXI.Graphics(); - this.color = opts?.color ?? 0x212121; this.draw(); } @@ -46,17 +50,29 @@ export default class Curve { const x = this.options.get('x'); const y = this.options.get('y'); const angle = this.options.get('angle'); + const sharpness = this.options.get('sharpness'); + const color = new PIXI.Color({ + r: this.options.get('colorRed'), + g: this.options.get('colorGreen'), + b: this.options.get('colorBlue') + }); this.graphics.clear(); - this.graphics - .moveTo((-width / 2) * scale, 0) - .quadraticCurveTo(0, curve * scale, (width / 2) * scale, 0, -10) - .stroke({ - color: this.color, - width: stroke * scale, - cap: 'round' - }); - + if (sharpness > 0.5) { + this.graphics + .moveTo((-width / 2) * scale, 0) + .lineTo(0, curve * scale) + .lineTo((width / 2) * scale, 0); + } else { + this.graphics + .moveTo((-width / 2) * scale, 0) + .quadraticCurveTo(0, curve * scale, (width / 2) * scale, 0); + } + this.graphics.stroke({ + color: color, + width: stroke * scale, + cap: 'round' + }); this.graphics.angle = angle; this.graphics.position.set(x * scale, y * scale); } diff --git a/src/lib/face/eye.ts b/src/lib/face/eye.ts index 477b1a4..e87661d 100644 --- a/src/lib/face/eye.ts +++ b/src/lib/face/eye.ts @@ -1,43 +1,22 @@ -import * as PIXI from "pixi.js"; -import { AnimatedProperty, degreesToRadians } from './math-helper'; +import * as PIXI from 'pixi.js'; +import { AnimatedProperties, AnimatedProperty, degreesToRadians } from './math-helper'; export type EyeOptions = { - container: PIXI.Container; + x: number; + y: number; - x: number; - y: number; + sizeX: number; + sizeY: number; - eyeColor: PIXI.ColorSource; - pupilColor: PIXI.ColorSource; - highlightColor: PIXI.ColorSource; - - size: number; - - eyebrow: Partial<{ - length: number; - - width: number; - - y: number; - x: number; - - curve: number; - - color: PIXI.ColorSource; - }>; - - blinkStart: number; - blinkTimer: number; + pupilSizeX: number; + pupilSizeY: number; }; export default class Eye { - eyeContainer: PIXI.Container; - container: PIXI.Container; base?: PIXI.Graphics; pupil?: PIXI.Graphics; - highlight?: PIXI.Sprite; mask?: PIXI.Graphics; @@ -53,64 +32,69 @@ export default class Eye { dx: number = 0; dy: number = 0; - size: number = 1; - targetX: number = 0; targetY: number = 0; - constructor(opts: Partial) { - this.container = new PIXI.Container(); + options: AnimatedProperties; - this.eyeContainer = new PIXI.Container(); + furMask?: PIXI.Graphics; - this.container.position.set(opts.x ?? 0, opts.y ?? 0); + constructor(opts: Partial) { + this.options = new AnimatedProperties({ + x: opts.x ?? 0, + y: opts.y ?? 0, + sizeX: opts.sizeX ?? 50, + sizeY: opts.sizeY ?? 50, + pupilSizeX: opts.pupilSizeX ?? (opts.sizeX ?? 50) * 0.5, + pupilSizeY: opts.pupilSizeY ?? (opts.sizeY ?? 50) * 0.5 + }); - this.size = opts.size ?? 1; + this.container = new PIXI.Container(); - if (opts.blinkStart) { - this.blinkTimer = opts.blinkStart; - } - if (opts.blinkTimer) { - this.blinkTimer = opts.blinkTimer; - } + this.container.position.set(this.options.get('x'), this.options.get('y')); this._x = new AnimatedProperty(); this._y = new AnimatedProperty(); - this.container.addChild(this.eyeContainer); + this.base = new PIXI.Graphics(); + this.container.addChild(this.base); - if (opts.container) opts.container.addChild(this.container); + this.pupil = new PIXI.Graphics(); + this.container.addChild(this.pupil); + this.mask = new PIXI.Graphics(); + this.container.addChild(this.mask); + this.container.mask = this.mask; - this.base = new PIXI.Graphics() - .ellipse(0, 0, this.size, this.size * 0.9) - .fill(opts.eyeColor ?? 0xffffff); - this.base.alpha = 1; - this.eyeContainer.addChild(this.base); + this.furMask = new PIXI.Graphics(); + this.furMask.blendMode = 'erase'; + this.furMask.x = this.options.get('x'); + this.furMask.y = this.options.get('y'); - this.pupil = new PIXI.Graphics() - .circle(0, 0, this.size * 0.6) - .fill(opts.pupilColor ?? 0x000000) - .circle(this.size * 0.3, this.size * 0.3, 0.2 * this.size) - .fill({ color: 0xffffff, alpha: 0.7 }); - this.eyeContainer.addChild(this.pupil); + this.draw(); + } + + draw() { + if (!this.base || !this.pupil || !this.mask || !this.furMask) return; + const sizeX = this.options.get('sizeX'); + const sizeY = this.options.get('sizeY'); - this.mask = new PIXI.Graphics().ellipse(0, 0, this.size, this.size * 0.9).fill(0xffffff); - this.eyeContainer.addChild(this.mask); - this.eyeContainer.mask = this.mask; + const pupilSizeX = this.options.get('pupilSizeX'); + const pupilSizeY = this.options.get('pupilSizeY'); - const eyebrowWidth = opts?.eyebrow?.width ?? 2; - const eyebrowCurve = opts?.eyebrow?.curve ?? 0.2; + this.mask.clear(); + this.mask.ellipse(0, 0, sizeX, sizeY).fill(0xffffff); - const eyebrow = new PIXI.Graphics() - .moveTo((-eyebrowWidth / 2) * this.size, 0) - .quadraticCurveTo(0, eyebrowCurve * this.size, (eyebrowWidth / 2) * this.size, 0) - .stroke({ - color: opts.eyebrow?.color ?? 0, - width: opts.eyebrow?.width ?? this.size * 0.2 - }); - eyebrow.position.set(opts.eyebrow?.x ?? 0, (opts.eyebrow?.y ?? 0.9) * this.size); + this.base.clear(); + this.base.ellipse(0, 0, sizeX, sizeY).fill(0xffffff); - // this.container.addChild(eyebrow); + this.pupil.clear(); + this.pupil.ellipse(0, 0, pupilSizeX, pupilSizeY).fill(0x000000); + this.pupil + .circle(pupilSizeX * 0.5, pupilSizeY * 0.5, 0.2 * sizeX) + .fill({ color: 0xffffff, alpha: 0.7 }); + + this.furMask.clear(); + this.furMask.ellipse(0, 0, sizeX, sizeY).fill({ color: '#ffffff' }); } lookInDirection(direction: number) { @@ -120,8 +104,8 @@ export default class Eye { } lookAt(x: number, y: number) { - this._x.set(x * this.size * 0.3); - this._y.set(y * this.size * 0.3); + this._x.set(x * this.options.get('sizeX') * 0.3); + this._y.set(y * this.options.get('sizeY') * 0.3); } rotate(angle: number) { @@ -140,6 +124,14 @@ export default class Eye { this.pupil?.position.set(this._x.value, this._y.value); } + if (this.options.update(deltaTime)) { + this.container.position.set(this.options.get('x'), this.options.get('y')); + + this.furMask?.position.set(this.options.get('x'), this.options.get('y')); + + this.draw(); + } + if (this.mask) { // Blink animation this.blinkTimer += deltaTime; diff --git a/src/lib/face/face.ts b/src/lib/face/face.ts index d38458d..7f56805 100644 --- a/src/lib/face/face.ts +++ b/src/lib/face/face.ts @@ -1,6 +1,7 @@ -import { Application, Container, Graphics } from 'pixi.js'; +import { Application, Color, Container, Graphics } from 'pixi.js'; import Eye from './eye'; import Curve from './curve'; +import { options } from '$lib/state.svelte'; export async function createFace({ width = 512, @@ -23,19 +24,10 @@ export async function createFace({ eyebrowRight: Curve; furMouth: Curve; }> { - const xScale = 0.4 * scale; + const xScale = 0.45 * scale; const yScale = 1.5 * scale; const faceApp = new Application(); - const mouthSettings = { - x: 0, - y: -130, - stroke: 20, - color: 0, - width: 100, - curve: -40 - }; - await faceApp.init({ width, height, @@ -45,7 +37,7 @@ export async function createFace({ const background = new Graphics(); background.rect(0, 0, width, height); background.fill({ color: '#be185d' }); - background.alpha = 0.7; + background.alpha = 0.5; faceApp.stage.addChild(background); const container = new Container(); @@ -54,22 +46,20 @@ export async function createFace({ container.scale.set(xScale, yScale); faceApp.stage.addChild(container); - const rightEye = new Eye({ - x: 75, - y: 0, - size: 50 - }); + const rightEye = new Eye(options.rightEye); - const leftEye = new Eye({ - x: -75, - y: 0, - size: 50 - }); + const leftEye = new Eye(options.leftEye); container.addChild(rightEye.container); container.addChild(leftEye.container); - const mouth = new Curve(mouthSettings); + const mouthColor = new Color(options.mouth.color); + const mouth = new Curve({ + ...options.mouth, + colorRed: mouthColor.red * 256, + colorGreen: mouthColor.green * 256, + colorBlue: mouthColor.blue * 256 + }); container.addChild(mouth.graphics); const furApp = new Application(); @@ -107,45 +97,20 @@ export async function createFace({ furContainer.addChild(circle); } - const eyeMaskLeft = new Graphics(); - eyeMaskLeft.circle(0, 0, 50); - eyeMaskLeft.x = -75; - eyeMaskLeft.y = 0; - eyeMaskLeft.blendMode = 'erase'; - eyeMaskLeft.fill({ color: '#ffffff' }); - furContainer.addChild(eyeMaskLeft); - - const eyeMaskRight = new Graphics(); - eyeMaskRight.circle(0, 0, 50); - eyeMaskRight.x = 75; - eyeMaskRight.y = 0; - eyeMaskRight.blendMode = 'erase'; - eyeMaskRight.fill({ color: '#ffffff' }); - furContainer.addChild(eyeMaskRight); - - const eyebrowLeft = new Curve({ - x: 75, - y: 80, - width: 100, - curve: 20, - stroke: 10 - }); + if (leftEye.furMask && rightEye.furMask) { + furContainer.addChild(leftEye.furMask); + furContainer.addChild(rightEye.furMask); + } + + const eyebrowLeft = new Curve(options.leftEyebrow); eyebrowLeft.graphics.alpha = 0.5; furContainer.addChild(eyebrowLeft.graphics); - const eyebrowRight = new Curve({ - x: -75, - y: 80, - width: 100, - curve: 20, - stroke: 10 - }); + const eyebrowRight = new Curve(options.rightEyebrow); eyebrowRight.graphics.alpha = 0.5; furContainer.addChild(eyebrowRight.graphics); - const furMouth = new Curve({ - ...mouthSettings - }); + const furMouth = new Curve(options.mouth); furMouth.graphics.blendMode = 'erase'; furContainer.addChild(furMouth.graphics); diff --git a/src/lib/face/math-helper.ts b/src/lib/face/math-helper.ts index 6782e2d..3ec6804 100644 --- a/src/lib/face/math-helper.ts +++ b/src/lib/face/math-helper.ts @@ -193,6 +193,14 @@ export class AnimatedProperties> { this.properties[key].set(value); } + setMultiple(values: Partial) { + for (const key in values) { + if (values[key] !== undefined && this.properties[key]) { + this.properties[key].set(values[key]); + } + } + } + // Update all animated values update(dt: number): boolean { let anyUpdated = false; diff --git a/src/lib/state.svelte.ts b/src/lib/state.svelte.ts index 108b288..d91147e 100644 --- a/src/lib/state.svelte.ts +++ b/src/lib/state.svelte.ts @@ -1,12 +1,15 @@ export const options = $state({ hasChanged: false, + leftEyebrow: { x: 75, y: 80, width: 100, curve: 20, stroke: 10, - angle: 0 + angle: 0, + sharpness: 0, + color: '#515151' }, rightEyebrow: { x: -75, @@ -14,16 +17,189 @@ export const options = $state({ width: 100, curve: 20, stroke: 10, - angle: 0 + angle: 0, + sharpness: 0, + color: '#515151' }, mouth: { x: 0, y: -130, stroke: 20, - color: 0, + color: '#000000', width: 100, curve: -40 }, + leftEye: { + x: 75, + y: 0, + sizeX: 50, + sizeY: 50, + pupilSizeX: 20, + pupilSizeY: 20 + }, + rightEye: { + x: -75, + y: 0, + sizeX: 50, + sizeY: 50, + pupilSizeX: 20, + pupilSizeY: 20 + }, + + currentEmotion: '', + + emotions: { + base: { + leftEyebrow: { + x: 75, + y: 80, + width: 100, + curve: 20, + stroke: 10, + angle: 0, + sharpness: 0, + color: '#515151' + }, + rightEyebrow: { + x: -75, + y: 80, + width: 100, + curve: 20, + stroke: 10, + angle: 0, + sharpness: 0, + color: '#515151' + }, + mouth: { x: 0, y: -130, stroke: 20, color: '#000000', width: 100, curve: -40 }, + leftEye: { x: 75, y: 0, sizeX: 50, sizeY: 50, pupilSizeX: 20, pupilSizeY: 20 }, + rightEye: { x: -75, y: 0, sizeX: 50, sizeY: 50, pupilSizeX: 20, pupilSizeY: 20 } + }, + scared: { + leftEyebrow: { + x: 110, + y: 80, + width: 70, + curve: -20, + stroke: 10, + angle: -18, + sharpness: 0, + color: '#515151' + }, + rightEyebrow: { + x: -110, + y: 80, + width: 70, + curve: -20, + stroke: 10, + angle: 18, + sharpness: 0, + color: '#515151' + }, + mouth: { x: 0, y: -130, stroke: 30, color: '#000000', width: 150, curve: 40 }, + leftEye: { x: 75, y: 0, sizeX: 50, sizeY: 40, pupilSizeX: 20, pupilSizeY: 20 }, + rightEye: { x: -75, y: 0, sizeX: 50, sizeY: 40, pupilSizeX: 20, pupilSizeY: 20 } + }, + surprised: { + leftEyebrow: { + x: 90, + y: 120, + width: 100, + curve: 100, + stroke: 15, + angle: -10, + sharpness: 0, + color: '#515151' + }, + rightEyebrow: { + x: -90, + y: 120, + width: 100, + curve: 100, + stroke: 15, + angle: 10, + sharpness: 0, + color: '#515151' + }, + mouth: { x: 0, y: -160, stroke: 100, color: '#000000', width: 40, curve: -5 }, + leftEye: { x: 75, y: 0, sizeX: 70, sizeY: 70, pupilSizeX: 30, pupilSizeY: 30 }, + rightEye: { x: -75, y: 0, sizeX: 70, sizeY: 70, pupilSizeX: 30, pupilSizeY: 30 } + }, + angry: { + leftEyebrow: { + x: 75, + y: 80, + width: 50, + curve: -10, + stroke: 10, + angle: 30, + sharpness: 0, + color: '#515151' + }, + rightEyebrow: { + x: -75, + y: 80, + width: 50, + curve: -10, + stroke: 10, + angle: -30, + sharpness: 0, + color: '#515151' + }, + mouth: { x: 0, y: -130, stroke: 20, color: '#000000', width: 70, curve: 0 }, + leftEye: { x: 75, y: -20, sizeX: 50, sizeY: 40, pupilSizeX: 20, pupilSizeY: 20 }, + rightEye: { x: -75, y: -20, sizeX: 50, sizeY: 40, pupilSizeX: 20, pupilSizeY: 20 } + }, + sad: { + leftEyebrow: { + x: 75, + y: 80, + width: 100, + curve: -20, + stroke: 10, + angle: -10, + sharpness: 0, + color: '#515151' + }, + rightEyebrow: { + x: -75, + y: 80, + width: 100, + curve: -20, + stroke: 10, + angle: 10, + sharpness: 0, + color: '#515151' + }, + mouth: { x: 0, y: -130, stroke: 20, color: '#000000', width: 100, curve: 20 }, + leftEye: { x: 75, y: 0, sizeX: 60, sizeY: 60, pupilSizeX: 25, pupilSizeY: 25 }, + rightEye: { x: -75, y: 0, sizeX: 60, sizeY: 60, pupilSizeX: 25, pupilSizeY: 25 } + }, + excited: { + leftEyebrow: { + x: 75, + y: 100, + width: 100, + curve: 40, + stroke: 10, + angle: 0, + sharpness: 0, + color: '#515151' + }, + rightEyebrow: { + x: -75, + y: 100, + width: 100, + curve: 40, + stroke: 10, + angle: 0, + sharpness: 0, + color: '#515151' + }, + mouth: { x: 0, y: -130, stroke: 40, color: '#000000', width: 150, curve: -80 }, + leftEye: { x: 75, y: 0, sizeX: 50, sizeY: 60, pupilSizeX: 25, pupilSizeY: 25 }, + rightEye: { x: -75, y: 0, sizeX: 50, sizeY: 60, pupilSizeX: 25, pupilSizeY: 25 } + } + }, colors: { primary: '#ec4899', secondary: '#fb923c' diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 1f237d9..6d706e0 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -8,6 +8,7 @@ import { fromStore } from 'svelte/store'; import { useProgress } from '@threlte/extras'; import { onMount } from 'svelte'; + import { options } from '$lib/state.svelte'; const { progress } = useProgress(); const p = fromStore(progress); const tweenedProgress = Tween.of(() => p.current, { @@ -20,11 +21,33 @@ onMount(() => { window.addEventListener('keydown', (e) => { + // check if e.srcElement is text input + if (e.srcElement instanceof HTMLInputElement) { + return; + } + if (e.key === 's') { showSettings = !showSettings; } }); }); + + let currentEmotion = $state('base'); + + function setEmotion(emotion: string) { + currentEmotion = emotion; + options.currentEmotion = emotion; + options.hasChanged = true; + } + + let emotions: Record = { + base: '🙂', + scared: '😧', + excited: '😄', + sad: '🙁', + angry: '😠', + surprised: '😲' + };
@@ -63,3 +86,32 @@
{/if} + +
+
+ made by flo-bit + for + 3js journey #016 +
+ +
+ {#each Object.keys(emotions) as emotion} + + {/each} +
+
-- knotmirror 0.0.1