Skip to content

Commit

Permalink
perf(stage-web): pause render when settings open (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
LemonNekoGH authored Feb 25, 2025
1 parent 0a28e0c commit 856c78f
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 4 deletions.
10 changes: 9 additions & 1 deletion apps/stage-web/src/components/Layouts/MobileInteractiveArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import { useI18n } from 'vue-i18n'
import MobileChatHistory from '../Widgets/MobileChatHistory.vue'
import MobileSettings from '../Widgets/MobileSettings.vue'
const emit = defineEmits<{
(e: 'settingsOpen', open: boolean): void
}>()
const messageInput = ref('')
const listening = ref(false)
Expand Down Expand Up @@ -69,6 +73,10 @@ function handleTranscription(_buffer: Float32Array<ArrayBufferLike>) {
// selectedAudioDevice.value = found
// }
function handleSettingsOpen(open: boolean) {
emit('settingsOpen', open)
}
watch(isAudioInputOn, async (value) => {
if (value === 'false') {
destroy()
Expand Down Expand Up @@ -100,7 +108,7 @@ onMounted(() => {
@submit="handleSend"
/>
</div>
<DrawerRoot should-scale-background>
<DrawerRoot should-scale-background @update:open="handleSettingsOpen">
<DrawerTrigger
class="px-4 py-2.5"
border="solid 2 pink-100 dark:pink-400/20"
Expand Down
10 changes: 8 additions & 2 deletions apps/stage-web/src/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { WidgetStage } from '@proj-airi/stage-ui/components'
import { useDark } from '@vueuse/core'
import { ref } from 'vue'
import Cross from '../components/Backgrounds/Cross.vue'
import AnimatedBackground from '../components/Layouts/AnimatedBackground.vue'
Expand All @@ -10,6 +11,11 @@ import MobileHeader from '../components/Layouts/MobileHeader.vue'
import MobileInteractiveArea from '../components/Layouts/MobileInteractiveArea.vue'
const dark = useDark()
const paused = ref(false)
function handleSettingsOpen(open: boolean) {
paused.value = open
}
</script>

<template>
Expand All @@ -23,9 +29,9 @@ const dark = useDark()
</div>
<!-- page -->
<div relative flex="~ 1 row gap-y-0 gap-x-2 <md:col">
<WidgetStage flex-1 min-w="1/2" />
<WidgetStage flex-1 min-w="1/2" :paused="paused" />
<InteractiveArea class="flex <md:hidden" flex-1 max-w="500px" min-w="30%" />
<MobileInteractiveArea class="hidden <md:block" mx2 mb2 />
<MobileInteractiveArea class="hidden <md:block" mx2 mb2 @settings-open="handleSettingsOpen" />
</div>
</div>
</AnimatedBackground>
Expand Down
5 changes: 5 additions & 0 deletions packages/stage-ui/src/components/Live2D/Model.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ const props = withDefaults(defineProps<{
width: number
height: number
motion?: string
paused: boolean
}>(), {
mouthOpenSize: 0,
})
const pixiApp = toRef(() => props.app)
const paused = toRef(() => props.paused)
const model = ref<Live2DModel>()
const initialModelWidth = ref<number>(0)
const initialModelHeight = ref<number>(0)
Expand Down Expand Up @@ -141,6 +143,9 @@ watch(model, updateDropShadowFilter)
watch(mouthOpenSize, value => getCoreModel().setParameterValueById('ParamMouthOpenY', value))
watch(pixiApp, initLive2DPixiStage)
watch(() => props.motion, () => props.motion && setMotion(props.motion))
watch(paused, (value) => {
value ? pixiApp.value?.stop() : pixiApp.value?.start()
})
onMounted(updateDropShadowFilter)
onUnmounted(() => model.value && pixiApp.value?.stage.removeChild(model.value))
Expand Down
3 changes: 2 additions & 1 deletion packages/stage-ui/src/components/Scenes/Live2D.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import TransitionVertical from '../TransitionVertical.vue'
withDefaults(defineProps<{
model: string
paused: boolean
mouthOpenSize?: number
}>(), {
mouthOpenSize: 0,
Expand All @@ -29,7 +30,7 @@ const show = ref(false)
<template>
<Screen v-slot="{ width, height }" relative>
<Live2DCanvas v-slot="{ app }" :width="width" :height="height">
<Live2DModel :app="app" :model="model" :mouth-open-size="mouthOpenSize" :width="width" :height="height" :motion="motion" />
<Live2DModel :app="app" :model="model" :mouth-open-size="mouthOpenSize" :width="width" :height="height" :motion="motion" :paused="paused" />
</Live2DCanvas>
<div absolute bottom="3" right="3">
<div flex="~ row" cursor-pointer>
Expand Down
2 changes: 2 additions & 0 deletions packages/stage-ui/src/components/Scenes/VRM.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import VRMModel from '../VRM/Model.vue'
const props = defineProps<{
model: string
idleAnimation: string
paused: boolean
}>()
const emit = defineEmits<{
Expand Down Expand Up @@ -51,6 +52,7 @@ defineExpose({
:model="props.model"
:idle-animation="props.idleAnimation"
:position="[vrmModelPositionX, vrmModelPositionY, vrmModelPositionZ]"
:paused="props.paused"
@load-model-progress="(val) => emit('loadModelProgress', val)"
@error="(val) => emit('error', val)"
/>
Expand Down
7 changes: 7 additions & 0 deletions packages/stage-ui/src/components/VRM/Model.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const props = defineProps<{
idleAnimation: string
loadAnimations?: string[]
position: [number, number, number]
paused: boolean
}>()
const emit = defineEmits<{
Expand Down Expand Up @@ -96,6 +97,12 @@ defineExpose({
vrmEmote.value?.setEmotionWithResetAfter(expression, 1000)
},
})
const { pause, resume } = useLoop()
watch(() => props.paused, (value) => {
value ? pause() : resume()
})
</script>

<template>
Expand Down
8 changes: 8 additions & 0 deletions packages/stage-ui/src/components/Widgets/Stage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ import VRMScene from '../Scenes/VRM.vue'
import '../../utils/live2d-zip-loader'
withDefaults(defineProps<{
paused?: boolean
}>(), {
paused: false,
})
const vrmViewerRef = ref<{ setExpression: (expression: string) => void }>()
const motion = ref('')
Expand Down Expand Up @@ -212,13 +218,15 @@ onMounted(() => {
:mouth-open-size="mouthOpenSize"
model="./assets/live2d/models/hiyori_pro_zh.zip"
min-w="50% <lg:full" min-h="100 sm:100" h-full w-full flex-1
:paused="paused"
/>
<VRMScene
v-else-if="stageView === '3d'"
ref="vrmViewerRef"
model="/assets/vrm/models/AvatarSample-B/AvatarSample_B.vrm"
idle-animation="/assets/vrm/animations/idle_loop.vrma"
min-w="50% <lg:full" min-h="100 sm:100" h-full w-full flex-1
:paused="paused"
@error="console.error"
/>
</div>
Expand Down

0 comments on commit 856c78f

Please sign in to comment.