@elizaos/app-core 2.0.0-alpha.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +2 -0
- package/LICENSE +21 -0
- package/dist/App.d.ts +5 -0
- package/dist/App.d.ts.map +1 -0
- package/dist/App.js +198 -0
- package/dist/actions/character.d.ts +27 -0
- package/dist/actions/character.d.ts.map +1 -0
- package/dist/actions/character.js +97 -0
- package/dist/actions/chat-helpers.d.ts +47 -0
- package/dist/actions/chat-helpers.d.ts.map +1 -0
- package/dist/actions/chat-helpers.js +79 -0
- package/dist/actions/cloud.d.ts +17 -0
- package/dist/actions/cloud.d.ts.map +1 -0
- package/dist/actions/cloud.js +43 -0
- package/dist/actions/index.d.ts +12 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +11 -0
- package/dist/actions/lifecycle.d.ts +43 -0
- package/dist/actions/lifecycle.d.ts.map +1 -0
- package/dist/actions/lifecycle.js +118 -0
- package/dist/actions/onboarding.d.ts +12 -0
- package/dist/actions/onboarding.d.ts.map +1 -0
- package/dist/actions/onboarding.js +28 -0
- package/dist/actions/triggers.d.ts +23 -0
- package/dist/actions/triggers.d.ts.map +1 -0
- package/dist/actions/triggers.js +148 -0
- package/dist/api/client.d.ts +2823 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +2392 -0
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +1 -0
- package/dist/autonomy/index.d.ts +48 -0
- package/dist/autonomy/index.d.ts.map +1 -0
- package/dist/autonomy/index.js +330 -0
- package/dist/bridge/capacitor-bridge.d.ts +153 -0
- package/dist/bridge/capacitor-bridge.d.ts.map +1 -0
- package/dist/bridge/capacitor-bridge.js +193 -0
- package/dist/bridge/electrobun-rpc.d.ts +19 -0
- package/dist/bridge/electrobun-rpc.d.ts.map +1 -0
- package/dist/bridge/electrobun-rpc.js +27 -0
- package/dist/bridge/electrobun-runtime.d.ts +3 -0
- package/dist/bridge/electrobun-runtime.d.ts.map +1 -0
- package/dist/bridge/electrobun-runtime.js +17 -0
- package/dist/bridge/index.d.ts +6 -0
- package/dist/bridge/index.d.ts.map +1 -0
- package/dist/bridge/index.js +5 -0
- package/dist/bridge/native-plugins.d.ts +82 -0
- package/dist/bridge/native-plugins.d.ts.map +1 -0
- package/dist/bridge/native-plugins.js +39 -0
- package/dist/bridge/plugin-bridge.d.ts +116 -0
- package/dist/bridge/plugin-bridge.d.ts.map +1 -0
- package/dist/bridge/plugin-bridge.js +203 -0
- package/dist/bridge/storage-bridge.d.ts +39 -0
- package/dist/bridge/storage-bridge.d.ts.map +1 -0
- package/dist/bridge/storage-bridge.js +135 -0
- package/dist/chat/index.d.ts +57 -0
- package/dist/chat/index.d.ts.map +1 -0
- package/dist/chat/index.js +161 -0
- package/dist/coding/index.d.ts +25 -0
- package/dist/coding/index.d.ts.map +1 -0
- package/dist/coding/index.js +25 -0
- package/dist/components/AdvancedPageView.d.ts +17 -0
- package/dist/components/AdvancedPageView.d.ts.map +1 -0
- package/dist/components/AdvancedPageView.js +137 -0
- package/dist/components/AgentActivityBox.d.ts +7 -0
- package/dist/components/AgentActivityBox.d.ts.map +1 -0
- package/dist/components/AgentActivityBox.js +25 -0
- package/dist/components/ApiKeyConfig.d.ts +26 -0
- package/dist/components/ApiKeyConfig.d.ts.map +1 -0
- package/dist/components/ApiKeyConfig.js +121 -0
- package/dist/components/AppsPageView.d.ts +7 -0
- package/dist/components/AppsPageView.d.ts.map +1 -0
- package/dist/components/AppsPageView.js +31 -0
- package/dist/components/AppsView.d.ts +8 -0
- package/dist/components/AppsView.d.ts.map +1 -0
- package/dist/components/AppsView.js +149 -0
- package/dist/components/AvatarLoader.d.ts +9 -0
- package/dist/components/AvatarLoader.d.ts.map +1 -0
- package/dist/components/AvatarLoader.js +45 -0
- package/dist/components/AvatarSelector.d.ts +23 -0
- package/dist/components/AvatarSelector.d.ts.map +1 -0
- package/dist/components/AvatarSelector.js +105 -0
- package/dist/components/BscTradePanel.d.ts +22 -0
- package/dist/components/BscTradePanel.d.ts.map +1 -0
- package/dist/components/BscTradePanel.js +221 -0
- package/dist/components/BugReportModal.d.ts +2 -0
- package/dist/components/BugReportModal.d.ts.map +1 -0
- package/dist/components/BugReportModal.js +218 -0
- package/dist/components/CharacterView.d.ts +8 -0
- package/dist/components/CharacterView.d.ts.map +1 -0
- package/dist/components/CharacterView.js +703 -0
- package/dist/components/ChatAvatar.d.ts +8 -0
- package/dist/components/ChatAvatar.d.ts.map +1 -0
- package/dist/components/ChatAvatar.js +89 -0
- package/dist/components/ChatComposer.d.ts +37 -0
- package/dist/components/ChatComposer.d.ts.map +1 -0
- package/dist/components/ChatComposer.js +136 -0
- package/dist/components/ChatMessage.d.ts +24 -0
- package/dist/components/ChatMessage.d.ts.map +1 -0
- package/dist/components/ChatMessage.js +167 -0
- package/dist/components/ChatModalView.d.ts +10 -0
- package/dist/components/ChatModalView.d.ts.map +1 -0
- package/dist/components/ChatModalView.js +57 -0
- package/dist/components/ChatView.d.ts +14 -0
- package/dist/components/ChatView.d.ts.map +1 -0
- package/dist/components/ChatView.js +511 -0
- package/dist/components/CloudSourceControls.d.ts +13 -0
- package/dist/components/CloudSourceControls.d.ts.map +1 -0
- package/dist/components/CloudSourceControls.js +14 -0
- package/dist/components/CodingAgentSettingsSection.d.ts +2 -0
- package/dist/components/CodingAgentSettingsSection.d.ts.map +1 -0
- package/dist/components/CodingAgentSettingsSection.js +268 -0
- package/dist/components/CommandPalette.d.ts +2 -0
- package/dist/components/CommandPalette.d.ts.map +1 -0
- package/dist/components/CommandPalette.js +181 -0
- package/dist/components/CompanionSceneHost.d.ts +15 -0
- package/dist/components/CompanionSceneHost.d.ts.map +1 -0
- package/dist/components/CompanionSceneHost.js +343 -0
- package/dist/components/CompanionShell.d.ts +17 -0
- package/dist/components/CompanionShell.d.ts.map +1 -0
- package/dist/components/CompanionShell.js +15 -0
- package/dist/components/CompanionView.d.ts +2 -0
- package/dist/components/CompanionView.d.ts.map +1 -0
- package/dist/components/CompanionView.js +22 -0
- package/dist/components/ConfigPageView.d.ts +11 -0
- package/dist/components/ConfigPageView.d.ts.map +1 -0
- package/dist/components/ConfigPageView.js +275 -0
- package/dist/components/ConfigSaveFooter.d.ts +8 -0
- package/dist/components/ConfigSaveFooter.d.ts.map +1 -0
- package/dist/components/ConfigSaveFooter.js +10 -0
- package/dist/components/ConfirmModal.d.ts +61 -0
- package/dist/components/ConfirmModal.d.ts.map +1 -0
- package/dist/components/ConfirmModal.js +164 -0
- package/dist/components/ConnectionFailedBanner.d.ts +6 -0
- package/dist/components/ConnectionFailedBanner.d.ts.map +1 -0
- package/dist/components/ConnectionFailedBanner.js +22 -0
- package/dist/components/ConnectorsPageView.d.ts +7 -0
- package/dist/components/ConnectorsPageView.d.ts.map +1 -0
- package/dist/components/ConnectorsPageView.js +8 -0
- package/dist/components/ConversationsSidebar.d.ts +9 -0
- package/dist/components/ConversationsSidebar.d.ts.map +1 -0
- package/dist/components/ConversationsSidebar.js +116 -0
- package/dist/components/CustomActionEditor.d.ts +10 -0
- package/dist/components/CustomActionEditor.d.ts.map +1 -0
- package/dist/components/CustomActionEditor.js +578 -0
- package/dist/components/CustomActionsPanel.d.ts +9 -0
- package/dist/components/CustomActionsPanel.d.ts.map +1 -0
- package/dist/components/CustomActionsPanel.js +107 -0
- package/dist/components/CustomActionsView.d.ts +2 -0
- package/dist/components/CustomActionsView.d.ts.map +1 -0
- package/dist/components/CustomActionsView.js +134 -0
- package/dist/components/DatabasePageView.d.ts +5 -0
- package/dist/components/DatabasePageView.d.ts.map +1 -0
- package/dist/components/DatabasePageView.js +28 -0
- package/dist/components/DatabaseView.d.ts +9 -0
- package/dist/components/DatabaseView.d.ts.map +1 -0
- package/dist/components/DatabaseView.js +311 -0
- package/dist/components/ElizaCloudDashboard.d.ts +2 -0
- package/dist/components/ElizaCloudDashboard.d.ts.map +1 -0
- package/dist/components/ElizaCloudDashboard.js +657 -0
- package/dist/components/EmotePicker.d.ts +2 -0
- package/dist/components/EmotePicker.d.ts.map +1 -0
- package/dist/components/EmotePicker.js +343 -0
- package/dist/components/ErrorBoundary.d.ts +22 -0
- package/dist/components/ErrorBoundary.d.ts.map +1 -0
- package/dist/components/ErrorBoundary.js +31 -0
- package/dist/components/FineTuningView.d.ts +2 -0
- package/dist/components/FineTuningView.d.ts.map +1 -0
- package/dist/components/FineTuningView.js +433 -0
- package/dist/components/GameView.d.ts +11 -0
- package/dist/components/GameView.d.ts.map +1 -0
- package/dist/components/GameView.js +295 -0
- package/dist/components/GameViewOverlay.d.ts +8 -0
- package/dist/components/GameViewOverlay.d.ts.map +1 -0
- package/dist/components/GameViewOverlay.js +70 -0
- package/dist/components/GlobalEmoteOverlay.d.ts +2 -0
- package/dist/components/GlobalEmoteOverlay.d.ts.map +1 -0
- package/dist/components/GlobalEmoteOverlay.js +112 -0
- package/dist/components/Header.d.ts +8 -0
- package/dist/components/Header.d.ts.map +1 -0
- package/dist/components/Header.js +121 -0
- package/dist/components/HeartbeatsView.d.ts +2 -0
- package/dist/components/HeartbeatsView.d.ts.map +1 -0
- package/dist/components/HeartbeatsView.js +378 -0
- package/dist/components/InventoryView.d.ts +10 -0
- package/dist/components/InventoryView.d.ts.map +1 -0
- package/dist/components/InventoryView.js +162 -0
- package/dist/components/KnowledgeView.d.ts +20 -0
- package/dist/components/KnowledgeView.d.ts.map +1 -0
- package/dist/components/KnowledgeView.js +480 -0
- package/dist/components/LanguageDropdown.d.ts +30 -0
- package/dist/components/LanguageDropdown.d.ts.map +1 -0
- package/dist/components/LanguageDropdown.js +98 -0
- package/dist/components/LifoMonitorPanel.d.ts +21 -0
- package/dist/components/LifoMonitorPanel.d.ts.map +1 -0
- package/dist/components/LifoMonitorPanel.js +24 -0
- package/dist/components/LifoSandboxView.d.ts +5 -0
- package/dist/components/LifoSandboxView.d.ts.map +1 -0
- package/dist/components/LifoSandboxView.js +333 -0
- package/dist/components/LoadingScreen.d.ts +13 -0
- package/dist/components/LoadingScreen.d.ts.map +1 -0
- package/dist/components/LoadingScreen.js +39 -0
- package/dist/components/LogsPageView.d.ts +2 -0
- package/dist/components/LogsPageView.d.ts.map +1 -0
- package/dist/components/LogsPageView.js +7 -0
- package/dist/components/LogsView.d.ts +5 -0
- package/dist/components/LogsView.d.ts.map +1 -0
- package/dist/components/LogsView.js +71 -0
- package/dist/components/MediaGalleryView.d.ts +9 -0
- package/dist/components/MediaGalleryView.d.ts.map +1 -0
- package/dist/components/MediaGalleryView.js +236 -0
- package/dist/components/MediaSettingsSection.d.ts +11 -0
- package/dist/components/MediaSettingsSection.d.ts.map +1 -0
- package/dist/components/MediaSettingsSection.js +329 -0
- package/dist/components/MessageContent.d.ts +51 -0
- package/dist/components/MessageContent.d.ts.map +1 -0
- package/dist/components/MessageContent.js +553 -0
- package/dist/components/OnboardingWizard.d.ts +2 -0
- package/dist/components/OnboardingWizard.d.ts.map +1 -0
- package/dist/components/OnboardingWizard.js +59 -0
- package/dist/components/PairingView.d.ts +5 -0
- package/dist/components/PairingView.d.ts.map +1 -0
- package/dist/components/PairingView.js +28 -0
- package/dist/components/PermissionsSection.d.ts +20 -0
- package/dist/components/PermissionsSection.d.ts.map +1 -0
- package/dist/components/PermissionsSection.js +368 -0
- package/dist/components/PluginsPageView.d.ts +5 -0
- package/dist/components/PluginsPageView.d.ts.map +1 -0
- package/dist/components/PluginsPageView.js +8 -0
- package/dist/components/PluginsView.d.ts +21 -0
- package/dist/components/PluginsView.d.ts.map +1 -0
- package/dist/components/PluginsView.js +1531 -0
- package/dist/components/ProviderSwitcher.d.ts +42 -0
- package/dist/components/ProviderSwitcher.d.ts.map +1 -0
- package/dist/components/ProviderSwitcher.js +480 -0
- package/dist/components/RestartBanner.d.ts +2 -0
- package/dist/components/RestartBanner.d.ts.map +1 -0
- package/dist/components/RestartBanner.js +36 -0
- package/dist/components/RuntimeView.d.ts +10 -0
- package/dist/components/RuntimeView.d.ts.map +1 -0
- package/dist/components/RuntimeView.js +165 -0
- package/dist/components/SaveCommandModal.d.ts +12 -0
- package/dist/components/SaveCommandModal.d.ts.map +1 -0
- package/dist/components/SaveCommandModal.js +84 -0
- package/dist/components/SecretsView.d.ts +9 -0
- package/dist/components/SecretsView.d.ts.map +1 -0
- package/dist/components/SecretsView.js +249 -0
- package/dist/components/SettingsView.d.ts +9 -0
- package/dist/components/SettingsView.d.ts.map +1 -0
- package/dist/components/SettingsView.js +230 -0
- package/dist/components/ShellOverlays.d.ts +8 -0
- package/dist/components/ShellOverlays.d.ts.map +1 -0
- package/dist/components/ShellOverlays.js +10 -0
- package/dist/components/ShortcutsOverlay.d.ts +2 -0
- package/dist/components/ShortcutsOverlay.d.ts.map +1 -0
- package/dist/components/ShortcutsOverlay.js +79 -0
- package/dist/components/SkillsView.d.ts +11 -0
- package/dist/components/SkillsView.d.ts.map +1 -0
- package/dist/components/SkillsView.js +358 -0
- package/dist/components/StartupFailureView.d.ts +8 -0
- package/dist/components/StartupFailureView.d.ts.map +1 -0
- package/dist/components/StartupFailureView.js +15 -0
- package/dist/components/StreamView.d.ts +16 -0
- package/dist/components/StreamView.d.ts.map +1 -0
- package/dist/components/StreamView.js +300 -0
- package/dist/components/StripeEmbeddedCheckout.d.ts +24 -0
- package/dist/components/StripeEmbeddedCheckout.d.ts.map +1 -0
- package/dist/components/StripeEmbeddedCheckout.js +101 -0
- package/dist/components/SubscriptionStatus.d.ts +22 -0
- package/dist/components/SubscriptionStatus.d.ts.map +1 -0
- package/dist/components/SubscriptionStatus.js +301 -0
- package/dist/components/SystemWarningBanner.d.ts +6 -0
- package/dist/components/SystemWarningBanner.d.ts.map +1 -0
- package/dist/components/SystemWarningBanner.js +46 -0
- package/dist/components/ThemeToggle.d.ts +21 -0
- package/dist/components/ThemeToggle.d.ts.map +1 -0
- package/dist/components/ThemeToggle.js +24 -0
- package/dist/components/TrajectoriesView.d.ts +12 -0
- package/dist/components/TrajectoriesView.d.ts.map +1 -0
- package/dist/components/TrajectoriesView.js +183 -0
- package/dist/components/TrajectoryDetailView.d.ts +13 -0
- package/dist/components/TrajectoryDetailView.d.ts.map +1 -0
- package/dist/components/TrajectoryDetailView.js +112 -0
- package/dist/components/TriggersView.d.ts +2 -0
- package/dist/components/TriggersView.d.ts.map +1 -0
- package/dist/components/TriggersView.js +1 -0
- package/dist/components/VectorBrowserView.d.ts +10 -0
- package/dist/components/VectorBrowserView.d.ts.map +1 -0
- package/dist/components/VectorBrowserView.js +997 -0
- package/dist/components/VoiceConfigView.d.ts +11 -0
- package/dist/components/VoiceConfigView.d.ts.map +1 -0
- package/dist/components/VoiceConfigView.js +329 -0
- package/dist/components/VrmStage.d.ts +21 -0
- package/dist/components/VrmStage.d.ts.map +1 -0
- package/dist/components/VrmStage.js +252 -0
- package/dist/components/WhatsAppQrOverlay.d.ts +8 -0
- package/dist/components/WhatsAppQrOverlay.d.ts.map +1 -0
- package/dist/components/WhatsAppQrOverlay.js +63 -0
- package/dist/components/apps/AppDetailPane.d.ts +15 -0
- package/dist/components/apps/AppDetailPane.d.ts.map +1 -0
- package/dist/components/apps/AppDetailPane.js +13 -0
- package/dist/components/apps/AppsCatalogGrid.d.ts +20 -0
- package/dist/components/apps/AppsCatalogGrid.d.ts.map +1 -0
- package/dist/components/apps/AppsCatalogGrid.js +18 -0
- package/dist/components/apps/extensions/HyperscapeAppDetailPanel.d.ts +3 -0
- package/dist/components/apps/extensions/HyperscapeAppDetailPanel.d.ts.map +1 -0
- package/dist/components/apps/extensions/HyperscapeAppDetailPanel.js +253 -0
- package/dist/components/apps/extensions/registry.d.ts +4 -0
- package/dist/components/apps/extensions/registry.d.ts.map +1 -0
- package/dist/components/apps/extensions/registry.js +10 -0
- package/dist/components/apps/extensions/types.d.ts +7 -0
- package/dist/components/apps/extensions/types.d.ts.map +1 -0
- package/dist/components/apps/extensions/types.js +1 -0
- package/dist/components/apps/helpers.d.ts +7 -0
- package/dist/components/apps/helpers.d.ts.map +1 -0
- package/dist/components/apps/helpers.js +46 -0
- package/dist/components/avatar/VrmAnimationLoader.d.ts +30 -0
- package/dist/components/avatar/VrmAnimationLoader.d.ts.map +1 -0
- package/dist/components/avatar/VrmAnimationLoader.js +99 -0
- package/dist/components/avatar/VrmBlinkController.d.ts +37 -0
- package/dist/components/avatar/VrmBlinkController.d.ts.map +1 -0
- package/dist/components/avatar/VrmBlinkController.js +98 -0
- package/dist/components/avatar/VrmCameraManager.d.ts +57 -0
- package/dist/components/avatar/VrmCameraManager.d.ts.map +1 -0
- package/dist/components/avatar/VrmCameraManager.js +277 -0
- package/dist/components/avatar/VrmEngine.d.ts +229 -0
- package/dist/components/avatar/VrmEngine.d.ts.map +1 -0
- package/dist/components/avatar/VrmEngine.js +1950 -0
- package/dist/components/avatar/VrmFootShadow.d.ts +18 -0
- package/dist/components/avatar/VrmFootShadow.d.ts.map +1 -0
- package/dist/components/avatar/VrmFootShadow.js +83 -0
- package/dist/components/avatar/VrmViewer.d.ts +45 -0
- package/dist/components/avatar/VrmViewer.d.ts.map +1 -0
- package/dist/components/avatar/VrmViewer.js +341 -0
- package/dist/components/avatar/mixamoVRMRigMap.d.ts +3 -0
- package/dist/components/avatar/mixamoVRMRigMap.d.ts.map +1 -0
- package/dist/components/avatar/mixamoVRMRigMap.js +56 -0
- package/dist/components/avatar/retargetMixamoFbxToVrm.d.ts +9 -0
- package/dist/components/avatar/retargetMixamoFbxToVrm.d.ts.map +1 -0
- package/dist/components/avatar/retargetMixamoFbxToVrm.js +88 -0
- package/dist/components/avatar/retargetMixamoGltfToVrm.d.ts +11 -0
- package/dist/components/avatar/retargetMixamoGltfToVrm.d.ts.map +1 -0
- package/dist/components/avatar/retargetMixamoGltfToVrm.js +80 -0
- package/dist/components/chainConfig.d.ts +84 -0
- package/dist/components/chainConfig.d.ts.map +1 -0
- package/dist/components/chainConfig.js +268 -0
- package/dist/components/companion/CompanionHeader.d.ts +15 -0
- package/dist/components/companion/CompanionHeader.d.ts.map +1 -0
- package/dist/components/companion/CompanionHeader.js +7 -0
- package/dist/components/companion/CompanionSceneHost.d.ts +2 -0
- package/dist/components/companion/CompanionSceneHost.d.ts.map +1 -0
- package/dist/components/companion/CompanionSceneHost.js +1 -0
- package/dist/components/companion/VrmStage.d.ts +3 -0
- package/dist/components/companion/VrmStage.d.ts.map +1 -0
- package/dist/components/companion/VrmStage.js +1 -0
- package/dist/components/companion/walletUtils.d.ts +95 -0
- package/dist/components/companion/walletUtils.d.ts.map +1 -0
- package/dist/components/companion/walletUtils.js +167 -0
- package/dist/components/companion-shell-styles.d.ts +38 -0
- package/dist/components/companion-shell-styles.d.ts.map +1 -0
- package/dist/components/companion-shell-styles.js +248 -0
- package/dist/components/confirm-delete-control.d.ts +16 -0
- package/dist/components/confirm-delete-control.d.ts.map +1 -0
- package/dist/components/confirm-delete-control.js +12 -0
- package/dist/components/conversations/ConversationListItem.d.ts +31 -0
- package/dist/components/conversations/ConversationListItem.d.ts.map +1 -0
- package/dist/components/conversations/ConversationListItem.js +52 -0
- package/dist/components/conversations/conversation-utils.d.ts +9 -0
- package/dist/components/conversations/conversation-utils.d.ts.map +1 -0
- package/dist/components/conversations/conversation-utils.js +138 -0
- package/dist/components/format.d.ts +54 -0
- package/dist/components/format.d.ts.map +1 -0
- package/dist/components/format.js +82 -0
- package/dist/components/index.d.ts +93 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +92 -0
- package/dist/components/inventory/CopyableAddress.d.ts +8 -0
- package/dist/components/inventory/CopyableAddress.d.ts.map +1 -0
- package/dist/components/inventory/CopyableAddress.js +18 -0
- package/dist/components/inventory/InventoryToolbar.d.ts +25 -0
- package/dist/components/inventory/InventoryToolbar.d.ts.map +1 -0
- package/dist/components/inventory/InventoryToolbar.js +28 -0
- package/dist/components/inventory/NftGrid.d.ts +13 -0
- package/dist/components/inventory/NftGrid.d.ts.map +1 -0
- package/dist/components/inventory/NftGrid.js +29 -0
- package/dist/components/inventory/TokenLogo.d.ts +12 -0
- package/dist/components/inventory/TokenLogo.d.ts.map +1 -0
- package/dist/components/inventory/TokenLogo.js +33 -0
- package/dist/components/inventory/TokensTable.d.ts +24 -0
- package/dist/components/inventory/TokensTable.d.ts.map +1 -0
- package/dist/components/inventory/TokensTable.js +26 -0
- package/dist/components/inventory/constants.d.ts +52 -0
- package/dist/components/inventory/constants.d.ts.map +1 -0
- package/dist/components/inventory/constants.js +121 -0
- package/dist/components/inventory/index.d.ts +9 -0
- package/dist/components/inventory/index.d.ts.map +1 -0
- package/dist/components/inventory/index.js +8 -0
- package/dist/components/inventory/media-url.d.ts +6 -0
- package/dist/components/inventory/media-url.d.ts.map +1 -0
- package/dist/components/inventory/media-url.js +28 -0
- package/dist/components/inventory/useInventoryData.d.ts +53 -0
- package/dist/components/inventory/useInventoryData.d.ts.map +1 -0
- package/dist/components/inventory/useInventoryData.js +332 -0
- package/dist/components/knowledge-upload-image.d.ts +27 -0
- package/dist/components/knowledge-upload-image.d.ts.map +1 -0
- package/dist/components/knowledge-upload-image.js +146 -0
- package/dist/components/labels.d.ts +6 -0
- package/dist/components/labels.d.ts.map +1 -0
- package/dist/components/labels.js +40 -0
- package/dist/components/onboarding/ActivateStep.d.ts +2 -0
- package/dist/components/onboarding/ActivateStep.d.ts.map +1 -0
- package/dist/components/onboarding/ActivateStep.js +6 -0
- package/dist/components/onboarding/ConnectionStep.d.ts +2 -0
- package/dist/components/onboarding/ConnectionStep.d.ts.map +1 -0
- package/dist/components/onboarding/ConnectionStep.js +552 -0
- package/dist/components/onboarding/OnboardingPanel.d.ts +9 -0
- package/dist/components/onboarding/OnboardingPanel.d.ts.map +1 -0
- package/dist/components/onboarding/OnboardingPanel.js +24 -0
- package/dist/components/onboarding/OnboardingStepNav.d.ts +2 -0
- package/dist/components/onboarding/OnboardingStepNav.d.ts.map +1 -0
- package/dist/components/onboarding/OnboardingStepNav.js +14 -0
- package/dist/components/onboarding/PermissionsStep.d.ts +2 -0
- package/dist/components/onboarding/PermissionsStep.d.ts.map +1 -0
- package/dist/components/onboarding/PermissionsStep.js +7 -0
- package/dist/components/onboarding/RpcStep.d.ts +2 -0
- package/dist/components/onboarding/RpcStep.d.ts.map +1 -0
- package/dist/components/onboarding/RpcStep.js +125 -0
- package/dist/components/onboarding/WakeUpStep.d.ts +2 -0
- package/dist/components/onboarding/WakeUpStep.d.ts.map +1 -0
- package/dist/components/onboarding/WakeUpStep.js +82 -0
- package/dist/components/permissions/PermissionIcon.d.ts +4 -0
- package/dist/components/permissions/PermissionIcon.d.ts.map +1 -0
- package/dist/components/permissions/PermissionIcon.js +12 -0
- package/dist/components/permissions/StreamingPermissions.d.ts +20 -0
- package/dist/components/permissions/StreamingPermissions.d.ts.map +1 -0
- package/dist/components/permissions/StreamingPermissions.js +173 -0
- package/dist/components/plugins/showcase-data.d.ts +7 -0
- package/dist/components/plugins/showcase-data.d.ts.map +1 -0
- package/dist/components/plugins/showcase-data.js +464 -0
- package/dist/components/shared/ShellHeaderControls.d.ts +27 -0
- package/dist/components/shared/ShellHeaderControls.d.ts.map +1 -0
- package/dist/components/shared/ShellHeaderControls.js +60 -0
- package/dist/components/skeletons.d.ts +17 -0
- package/dist/components/skeletons.d.ts.map +1 -0
- package/dist/components/skeletons.js +22 -0
- package/dist/components/stream/ActivityFeed.d.ts +5 -0
- package/dist/components/stream/ActivityFeed.d.ts.map +1 -0
- package/dist/components/stream/ActivityFeed.js +57 -0
- package/dist/components/stream/AvatarPip.d.ts +5 -0
- package/dist/components/stream/AvatarPip.d.ts.map +1 -0
- package/dist/components/stream/AvatarPip.js +6 -0
- package/dist/components/stream/ChatContent.d.ts +6 -0
- package/dist/components/stream/ChatContent.d.ts.map +1 -0
- package/dist/components/stream/ChatContent.js +69 -0
- package/dist/components/stream/ChatTicker.d.ts +5 -0
- package/dist/components/stream/ChatTicker.d.ts.map +1 -0
- package/dist/components/stream/ChatTicker.js +34 -0
- package/dist/components/stream/IdleContent.d.ts +5 -0
- package/dist/components/stream/IdleContent.d.ts.map +1 -0
- package/dist/components/stream/IdleContent.js +17 -0
- package/dist/components/stream/StatusBar.d.ts +36 -0
- package/dist/components/stream/StatusBar.d.ts.map +1 -0
- package/dist/components/stream/StatusBar.js +140 -0
- package/dist/components/stream/StreamSettings.d.ts +33 -0
- package/dist/components/stream/StreamSettings.d.ts.map +1 -0
- package/dist/components/stream/StreamSettings.js +99 -0
- package/dist/components/stream/StreamTerminal.d.ts +2 -0
- package/dist/components/stream/StreamTerminal.d.ts.map +1 -0
- package/dist/components/stream/StreamTerminal.js +52 -0
- package/dist/components/stream/StreamVoiceConfig.d.ts +10 -0
- package/dist/components/stream/StreamVoiceConfig.d.ts.map +1 -0
- package/dist/components/stream/StreamVoiceConfig.js +88 -0
- package/dist/components/stream/helpers.d.ts +32 -0
- package/dist/components/stream/helpers.d.ts.map +1 -0
- package/dist/components/stream/helpers.js +110 -0
- package/dist/components/stream/overlays/OverlayLayer.d.ts +20 -0
- package/dist/components/stream/overlays/OverlayLayer.d.ts.map +1 -0
- package/dist/components/stream/overlays/OverlayLayer.js +24 -0
- package/dist/components/stream/overlays/built-in/ActionTickerWidget.d.ts +8 -0
- package/dist/components/stream/overlays/built-in/ActionTickerWidget.d.ts.map +1 -0
- package/dist/components/stream/overlays/built-in/ActionTickerWidget.js +44 -0
- package/dist/components/stream/overlays/built-in/AlertPopupWidget.d.ts +7 -0
- package/dist/components/stream/overlays/built-in/AlertPopupWidget.d.ts.map +1 -0
- package/dist/components/stream/overlays/built-in/AlertPopupWidget.js +62 -0
- package/dist/components/stream/overlays/built-in/BrandingWidget.d.ts +7 -0
- package/dist/components/stream/overlays/built-in/BrandingWidget.d.ts.map +1 -0
- package/dist/components/stream/overlays/built-in/BrandingWidget.js +36 -0
- package/dist/components/stream/overlays/built-in/CustomHtmlWidget.d.ts +26 -0
- package/dist/components/stream/overlays/built-in/CustomHtmlWidget.d.ts.map +1 -0
- package/dist/components/stream/overlays/built-in/CustomHtmlWidget.js +78 -0
- package/dist/components/stream/overlays/built-in/PeonGlassWidget.d.ts +11 -0
- package/dist/components/stream/overlays/built-in/PeonGlassWidget.d.ts.map +1 -0
- package/dist/components/stream/overlays/built-in/PeonGlassWidget.js +188 -0
- package/dist/components/stream/overlays/built-in/PeonHudWidget.d.ts +10 -0
- package/dist/components/stream/overlays/built-in/PeonHudWidget.d.ts.map +1 -0
- package/dist/components/stream/overlays/built-in/PeonHudWidget.js +168 -0
- package/dist/components/stream/overlays/built-in/PeonSakuraWidget.d.ts +11 -0
- package/dist/components/stream/overlays/built-in/PeonSakuraWidget.d.ts.map +1 -0
- package/dist/components/stream/overlays/built-in/PeonSakuraWidget.js +213 -0
- package/dist/components/stream/overlays/built-in/ThoughtBubbleWidget.d.ts +8 -0
- package/dist/components/stream/overlays/built-in/ThoughtBubbleWidget.d.ts.map +1 -0
- package/dist/components/stream/overlays/built-in/ThoughtBubbleWidget.js +59 -0
- package/dist/components/stream/overlays/built-in/ViewerCountWidget.d.ts +7 -0
- package/dist/components/stream/overlays/built-in/ViewerCountWidget.d.ts.map +1 -0
- package/dist/components/stream/overlays/built-in/ViewerCountWidget.js +34 -0
- package/dist/components/stream/overlays/built-in/index.d.ts +13 -0
- package/dist/components/stream/overlays/built-in/index.d.ts.map +1 -0
- package/dist/components/stream/overlays/built-in/index.js +12 -0
- package/dist/components/stream/overlays/registry.d.ts +11 -0
- package/dist/components/stream/overlays/registry.d.ts.map +1 -0
- package/dist/components/stream/overlays/registry.js +16 -0
- package/dist/components/stream/overlays/types.d.ts +67 -0
- package/dist/components/stream/overlays/types.d.ts.map +1 -0
- package/dist/components/stream/overlays/types.js +7 -0
- package/dist/components/stream/overlays/useOverlayLayout.d.ts +27 -0
- package/dist/components/stream/overlays/useOverlayLayout.d.ts.map +1 -0
- package/dist/components/stream/overlays/useOverlayLayout.js +162 -0
- package/dist/components/trajectory-format.d.ts +6 -0
- package/dist/components/trajectory-format.d.ts.map +1 -0
- package/dist/components/trajectory-format.js +43 -0
- package/dist/components/ui-badges.d.ts +23 -0
- package/dist/components/ui-badges.d.ts.map +1 -0
- package/dist/components/ui-badges.js +38 -0
- package/dist/components/ui-switch.d.ts +14 -0
- package/dist/components/ui-switch.d.ts.map +1 -0
- package/dist/components/ui-switch.js +15 -0
- package/dist/components/vector-browser-three.d.ts +4 -0
- package/dist/components/vector-browser-three.d.ts.map +1 -0
- package/dist/components/vector-browser-three.js +19 -0
- package/dist/config/config-catalog.d.ts +376 -0
- package/dist/config/config-catalog.d.ts.map +1 -0
- package/dist/config/config-catalog.js +724 -0
- package/dist/config/config-field.d.ts +68 -0
- package/dist/config/config-field.d.ts.map +1 -0
- package/dist/config/config-field.js +821 -0
- package/dist/config/config-renderer.d.ts +176 -0
- package/dist/config/config-renderer.d.ts.map +1 -0
- package/dist/config/config-renderer.js +403 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +4 -0
- package/dist/config/ui-renderer.d.ts +26 -0
- package/dist/config/ui-renderer.d.ts.map +1 -0
- package/dist/config/ui-renderer.js +815 -0
- package/dist/config/ui-spec.d.ts +164 -0
- package/dist/config/ui-spec.d.ts.map +1 -0
- package/dist/config/ui-spec.js +13 -0
- package/dist/events/index.d.ts +42 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +41 -0
- package/dist/hooks/index.d.ts +14 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +13 -0
- package/dist/hooks/useBugReport.d.ts +14 -0
- package/dist/hooks/useBugReport.d.ts.map +1 -0
- package/dist/hooks/useBugReport.js +18 -0
- package/dist/hooks/useCanvasWindow.d.ts +38 -0
- package/dist/hooks/useCanvasWindow.d.ts.map +1 -0
- package/dist/hooks/useCanvasWindow.js +273 -0
- package/dist/hooks/useChatAvatarVoice.d.ts +10 -0
- package/dist/hooks/useChatAvatarVoice.d.ts.map +1 -0
- package/dist/hooks/useChatAvatarVoice.js +71 -0
- package/dist/hooks/useContextMenu.d.ts +17 -0
- package/dist/hooks/useContextMenu.d.ts.map +1 -0
- package/dist/hooks/useContextMenu.js +100 -0
- package/dist/hooks/useKeyboardShortcuts.d.ts +17 -0
- package/dist/hooks/useKeyboardShortcuts.d.ts.map +1 -0
- package/dist/hooks/useKeyboardShortcuts.js +67 -0
- package/dist/hooks/useLifoSync.d.ts +18 -0
- package/dist/hooks/useLifoSync.d.ts.map +1 -0
- package/dist/hooks/useLifoSync.js +113 -0
- package/dist/hooks/useMemoryMonitor.d.ts +87 -0
- package/dist/hooks/useMemoryMonitor.d.ts.map +1 -0
- package/dist/hooks/useMemoryMonitor.js +210 -0
- package/dist/hooks/useRenderGuard.d.ts +17 -0
- package/dist/hooks/useRenderGuard.d.ts.map +1 -0
- package/dist/hooks/useRenderGuard.js +36 -0
- package/dist/hooks/useRetakeCapture.d.ts +12 -0
- package/dist/hooks/useRetakeCapture.d.ts.map +1 -0
- package/dist/hooks/useRetakeCapture.js +59 -0
- package/dist/hooks/useStreamPopoutNavigation.d.ts +3 -0
- package/dist/hooks/useStreamPopoutNavigation.d.ts.map +1 -0
- package/dist/hooks/useStreamPopoutNavigation.js +17 -0
- package/dist/hooks/useTimeout.d.ts +11 -0
- package/dist/hooks/useTimeout.d.ts.map +1 -0
- package/dist/hooks/useTimeout.js +32 -0
- package/dist/hooks/useVoiceChat.d.ts +129 -0
- package/dist/hooks/useVoiceChat.d.ts.map +1 -0
- package/dist/hooks/useVoiceChat.js +1071 -0
- package/dist/hooks/useWhatsAppPairing.d.ts +11 -0
- package/dist/hooks/useWhatsAppPairing.d.ts.map +1 -0
- package/dist/hooks/useWhatsAppPairing.js +95 -0
- package/dist/i18n/index.d.ts +7 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +53 -0
- package/dist/i18n/locales/en.json +1196 -0
- package/dist/i18n/locales/es.json +1196 -0
- package/dist/i18n/locales/ko.json +1196 -0
- package/dist/i18n/locales/pt.json +1196 -0
- package/dist/i18n/locales/zh-CN.json +1196 -0
- package/dist/i18n/messages.d.ts +6 -0
- package/dist/i18n/messages.d.ts.map +1 -0
- package/dist/i18n/messages.js +14 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/navigation/index.d.ts +27 -0
- package/dist/navigation/index.d.ts.map +1 -0
- package/dist/navigation/index.js +230 -0
- package/dist/package.json +161 -0
- package/dist/platform/browser-launch.d.ts +2 -0
- package/dist/platform/browser-launch.d.ts.map +1 -0
- package/dist/platform/browser-launch.js +109 -0
- package/dist/platform/index.d.ts +64 -0
- package/dist/platform/index.d.ts.map +1 -0
- package/dist/platform/index.js +155 -0
- package/dist/platform/init.d.ts +40 -0
- package/dist/platform/init.d.ts.map +1 -0
- package/dist/platform/init.js +158 -0
- package/dist/providers/index.d.ts +13 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +72 -0
- package/dist/state/AppContext.d.ts +11 -0
- package/dist/state/AppContext.d.ts.map +1 -0
- package/dist/state/AppContext.js +4496 -0
- package/dist/state/index.d.ts +7 -0
- package/dist/state/index.d.ts.map +1 -0
- package/dist/state/index.js +6 -0
- package/dist/state/internal.d.ts +6 -0
- package/dist/state/internal.d.ts.map +1 -0
- package/dist/state/internal.js +5 -0
- package/dist/state/parsers.d.ts +26 -0
- package/dist/state/parsers.d.ts.map +1 -0
- package/dist/state/parsers.js +255 -0
- package/dist/state/persistence.d.ts +36 -0
- package/dist/state/persistence.d.ts.map +1 -0
- package/dist/state/persistence.js +254 -0
- package/dist/state/types.d.ts +402 -0
- package/dist/state/types.d.ts.map +1 -0
- package/dist/state/types.js +70 -0
- package/dist/state/ui-preferences.d.ts +3 -0
- package/dist/state/ui-preferences.d.ts.map +1 -0
- package/dist/state/ui-preferences.js +1 -0
- package/dist/state/useApp.d.ts +4 -0
- package/dist/state/useApp.d.ts.map +1 -0
- package/dist/state/useApp.js +22 -0
- package/dist/state/vrm.d.ts +19 -0
- package/dist/state/vrm.d.ts.map +1 -0
- package/dist/state/vrm.js +65 -0
- package/dist/stories/AppMockProvider.d.ts +15 -0
- package/dist/stories/AppMockProvider.d.ts.map +1 -0
- package/dist/stories/AppMockProvider.js +14 -0
- package/dist/styles/anime.css +6324 -0
- package/dist/styles/base.css +196 -0
- package/dist/styles/onboarding-game.css +716 -0
- package/dist/styles/styles.css +2085 -0
- package/dist/styles/xterm.css +241 -0
- package/dist/types/index.d.ts +657 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/asset-url.d.ts +26 -0
- package/dist/utils/asset-url.d.ts.map +1 -0
- package/dist/utils/asset-url.js +99 -0
- package/dist/utils/assistant-text.d.ts +2 -0
- package/dist/utils/assistant-text.d.ts.map +1 -0
- package/dist/utils/assistant-text.js +161 -0
- package/dist/utils/clipboard.d.ts +2 -0
- package/dist/utils/clipboard.d.ts.map +1 -0
- package/dist/utils/clipboard.js +38 -0
- package/dist/utils/desktop-dialogs.d.ts +19 -0
- package/dist/utils/desktop-dialogs.d.ts.map +1 -0
- package/dist/utils/desktop-dialogs.js +50 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/number-parsing.d.ts +44 -0
- package/dist/utils/number-parsing.d.ts.map +1 -0
- package/dist/utils/number-parsing.js +56 -0
- package/dist/utils/openExternalUrl.d.ts +2 -0
- package/dist/utils/openExternalUrl.d.ts.map +1 -0
- package/dist/utils/openExternalUrl.js +17 -0
- package/dist/utils/spoken-text.d.ts +2 -0
- package/dist/utils/spoken-text.d.ts.map +1 -0
- package/dist/utils/spoken-text.js +56 -0
- package/dist/utils/streaming-text.d.ts +3 -0
- package/dist/utils/streaming-text.d.ts.map +1 -0
- package/dist/utils/streaming-text.js +87 -0
- package/dist/voice/index.d.ts +2 -0
- package/dist/voice/index.d.ts.map +1 -0
- package/dist/voice/index.js +1 -0
- package/dist/voice/types.d.ts +25 -0
- package/dist/voice/types.d.ts.map +1 -0
- package/dist/voice/types.js +166 -0
- package/package.json +86 -0
- package/src/App.tsx +469 -0
- package/src/actions/character.ts +113 -0
- package/src/actions/chat-helpers.ts +100 -0
- package/src/actions/cloud.ts +59 -0
- package/src/actions/index.ts +12 -0
- package/src/actions/lifecycle.ts +175 -0
- package/src/actions/onboarding.ts +46 -0
- package/src/actions/triggers.ts +190 -0
- package/src/ambient.d.ts +16 -0
- package/src/api/client.ts +5616 -0
- package/src/api/index.ts +1 -0
- package/src/autonomy/index.ts +477 -0
- package/src/bridge/capacitor-bridge.ts +295 -0
- package/src/bridge/electrobun-rpc.ts +58 -0
- package/src/bridge/electrobun-runtime.ts +28 -0
- package/src/bridge/index.ts +5 -0
- package/src/bridge/native-plugins.ts +134 -0
- package/src/bridge/plugin-bridge.ts +352 -0
- package/src/bridge/storage-bridge.ts +162 -0
- package/src/chat/index.ts +251 -0
- package/src/coding/index.ts +43 -0
- package/src/components/AdvancedPageView.tsx +362 -0
- package/src/components/AgentActivityBox.tsx +49 -0
- package/src/components/ApiKeyConfig.tsx +224 -0
- package/src/components/AppsPageView.tsx +52 -0
- package/src/components/AppsView.tsx +293 -0
- package/src/components/AvatarLoader.tsx +86 -0
- package/src/components/AvatarSelector.tsx +223 -0
- package/src/components/BscTradePanel.tsx +549 -0
- package/src/components/BugReportModal.tsx +499 -0
- package/src/components/CharacterView.tsx +1623 -0
- package/src/components/ChatAvatar.test.ts +96 -0
- package/src/components/ChatAvatar.tsx +147 -0
- package/src/components/ChatComposer.tsx +330 -0
- package/src/components/ChatMessage.tsx +448 -0
- package/src/components/ChatModalView.test.tsx +118 -0
- package/src/components/ChatModalView.tsx +125 -0
- package/src/components/ChatView.tsx +999 -0
- package/src/components/CloudSourceControls.tsx +80 -0
- package/src/components/CodingAgentSettingsSection.tsx +536 -0
- package/src/components/CommandPalette.tsx +284 -0
- package/src/components/CompanionSceneHost.tsx +498 -0
- package/src/components/CompanionShell.tsx +31 -0
- package/src/components/CompanionView.tsx +109 -0
- package/src/components/ConfigPageView.tsx +722 -0
- package/src/components/ConfigSaveFooter.tsx +41 -0
- package/src/components/ConfirmModal.tsx +379 -0
- package/src/components/ConnectionFailedBanner.tsx +91 -0
- package/src/components/ConnectorsPageView.tsx +13 -0
- package/src/components/ConversationsSidebar.tsx +279 -0
- package/src/components/CustomActionEditor.tsx +1125 -0
- package/src/components/CustomActionsPanel.tsx +288 -0
- package/src/components/CustomActionsView.tsx +322 -0
- package/src/components/DatabasePageView.tsx +55 -0
- package/src/components/DatabaseView.tsx +814 -0
- package/src/components/ElizaCloudDashboard.tsx +1696 -0
- package/src/components/EmotePicker.tsx +529 -0
- package/src/components/ErrorBoundary.tsx +76 -0
- package/src/components/FineTuningView.tsx +1080 -0
- package/src/components/GameView.tsx +551 -0
- package/src/components/GameViewOverlay.tsx +133 -0
- package/src/components/GlobalEmoteOverlay.tsx +152 -0
- package/src/components/Header.test.tsx +413 -0
- package/src/components/Header.tsx +400 -0
- package/src/components/HeartbeatsView.tsx +1002 -0
- package/src/components/InventoryView.tsx +372 -0
- package/src/components/KnowledgeView.tsx +1128 -0
- package/src/components/LanguageDropdown.tsx +187 -0
- package/src/components/LifoMonitorPanel.tsx +196 -0
- package/src/components/LifoSandboxView.tsx +499 -0
- package/src/components/LoadingScreen.tsx +77 -0
- package/src/components/LogsPageView.tsx +17 -0
- package/src/components/LogsView.tsx +239 -0
- package/src/components/MediaGalleryView.tsx +432 -0
- package/src/components/MediaSettingsSection.tsx +893 -0
- package/src/components/MessageContent.tsx +815 -0
- package/src/components/OnboardingWizard.test.tsx +107 -0
- package/src/components/OnboardingWizard.tsx +186 -0
- package/src/components/PairingView.tsx +110 -0
- package/src/components/PermissionsSection.tsx +818 -0
- package/src/components/PluginsPageView.tsx +9 -0
- package/src/components/PluginsView.tsx +3152 -0
- package/src/components/ProviderSwitcher.tsx +874 -0
- package/src/components/RestartBanner.tsx +76 -0
- package/src/components/RuntimeView.tsx +460 -0
- package/src/components/SaveCommandModal.tsx +211 -0
- package/src/components/SecretsView.tsx +569 -0
- package/src/components/SettingsView.tsx +825 -0
- package/src/components/ShellOverlays.tsx +41 -0
- package/src/components/ShortcutsOverlay.tsx +155 -0
- package/src/components/SkillsView.tsx +1435 -0
- package/src/components/StartupFailureView.tsx +63 -0
- package/src/components/StreamView.tsx +483 -0
- package/src/components/StripeEmbeddedCheckout.tsx +155 -0
- package/src/components/SubscriptionStatus.tsx +634 -0
- package/src/components/SystemWarningBanner.tsx +71 -0
- package/src/components/ThemeToggle.tsx +100 -0
- package/src/components/TrajectoriesView.tsx +526 -0
- package/src/components/TrajectoryDetailView.tsx +426 -0
- package/src/components/TriggersView.tsx +1 -0
- package/src/components/VectorBrowserView.tsx +1633 -0
- package/src/components/VoiceConfigView.tsx +674 -0
- package/src/components/VrmStage.test.ts +219 -0
- package/src/components/VrmStage.tsx +432 -0
- package/src/components/WhatsAppQrOverlay.tsx +230 -0
- package/src/components/__tests__/chainConfig.test.ts +220 -0
- package/src/components/apps/AppDetailPane.tsx +242 -0
- package/src/components/apps/AppsCatalogGrid.tsx +137 -0
- package/src/components/apps/extensions/HyperscapeAppDetailPanel.tsx +577 -0
- package/src/components/apps/extensions/registry.ts +16 -0
- package/src/components/apps/extensions/types.ts +9 -0
- package/src/components/apps/helpers.ts +44 -0
- package/src/components/avatar/VrmAnimationLoader.test.ts +164 -0
- package/src/components/avatar/VrmAnimationLoader.ts +151 -0
- package/src/components/avatar/VrmBlinkController.ts +118 -0
- package/src/components/avatar/VrmCameraManager.ts +407 -0
- package/src/components/avatar/VrmEngine.ts +2678 -0
- package/src/components/avatar/VrmFootShadow.ts +96 -0
- package/src/components/avatar/VrmViewer.tsx +421 -0
- package/src/components/avatar/__tests__/VrmCameraManager.test.ts +168 -0
- package/src/components/avatar/__tests__/VrmEngine.test.ts +1574 -0
- package/src/components/avatar/mixamoVRMRigMap.ts +62 -0
- package/src/components/avatar/retargetMixamoFbxToVrm.ts +144 -0
- package/src/components/avatar/retargetMixamoGltfToVrm.ts +119 -0
- package/src/components/chainConfig.ts +380 -0
- package/src/components/companion/CompanionHeader.tsx +47 -0
- package/src/components/companion/CompanionSceneHost.tsx +5 -0
- package/src/components/companion/VrmStage.tsx +2 -0
- package/src/components/companion/__tests__/walletUtils.test.ts +742 -0
- package/src/components/companion/walletUtils.ts +290 -0
- package/src/components/companion-shell-styles.test.ts +146 -0
- package/src/components/companion-shell-styles.ts +270 -0
- package/src/components/confirm-delete-control.tsx +69 -0
- package/src/components/conversations/ConversationListItem.tsx +185 -0
- package/src/components/conversations/conversation-utils.ts +151 -0
- package/src/components/format.ts +131 -0
- package/src/components/index.ts +92 -0
- package/src/components/inventory/CopyableAddress.tsx +41 -0
- package/src/components/inventory/InventoryToolbar.tsx +142 -0
- package/src/components/inventory/NftGrid.tsx +99 -0
- package/src/components/inventory/TokenLogo.tsx +71 -0
- package/src/components/inventory/TokensTable.tsx +216 -0
- package/src/components/inventory/constants.ts +170 -0
- package/src/components/inventory/index.ts +29 -0
- package/src/components/inventory/media-url.test.ts +38 -0
- package/src/components/inventory/media-url.ts +36 -0
- package/src/components/inventory/useInventoryData.ts +460 -0
- package/src/components/knowledge-upload-image.ts +215 -0
- package/src/components/labels.ts +46 -0
- package/src/components/onboarding/ActivateStep.tsx +30 -0
- package/src/components/onboarding/ConnectionStep.tsx +1530 -0
- package/src/components/onboarding/OnboardingPanel.tsx +39 -0
- package/src/components/onboarding/OnboardingStepNav.tsx +31 -0
- package/src/components/onboarding/PermissionsStep.tsx +20 -0
- package/src/components/onboarding/RpcStep.tsx +402 -0
- package/src/components/onboarding/WakeUpStep.tsx +184 -0
- package/src/components/permissions/PermissionIcon.tsx +25 -0
- package/src/components/permissions/StreamingPermissions.tsx +376 -0
- package/src/components/plugins/showcase-data.ts +481 -0
- package/src/components/shared/ShellHeaderControls.tsx +193 -0
- package/src/components/skeletons.tsx +88 -0
- package/src/components/stream/ActivityFeed.tsx +113 -0
- package/src/components/stream/AvatarPip.tsx +10 -0
- package/src/components/stream/ChatContent.tsx +126 -0
- package/src/components/stream/ChatTicker.tsx +55 -0
- package/src/components/stream/IdleContent.tsx +73 -0
- package/src/components/stream/StatusBar.tsx +469 -0
- package/src/components/stream/StreamSettings.tsx +506 -0
- package/src/components/stream/StreamTerminal.tsx +94 -0
- package/src/components/stream/StreamVoiceConfig.tsx +160 -0
- package/src/components/stream/helpers.ts +134 -0
- package/src/components/stream/overlays/OverlayLayer.tsx +75 -0
- package/src/components/stream/overlays/built-in/ActionTickerWidget.tsx +64 -0
- package/src/components/stream/overlays/built-in/AlertPopupWidget.tsx +87 -0
- package/src/components/stream/overlays/built-in/BrandingWidget.tsx +51 -0
- package/src/components/stream/overlays/built-in/CustomHtmlWidget.tsx +105 -0
- package/src/components/stream/overlays/built-in/PeonGlassWidget.tsx +265 -0
- package/src/components/stream/overlays/built-in/PeonHudWidget.tsx +247 -0
- package/src/components/stream/overlays/built-in/PeonSakuraWidget.tsx +278 -0
- package/src/components/stream/overlays/built-in/ThoughtBubbleWidget.tsx +77 -0
- package/src/components/stream/overlays/built-in/ViewerCountWidget.tsx +46 -0
- package/src/components/stream/overlays/built-in/index.ts +13 -0
- package/src/components/stream/overlays/registry.ts +22 -0
- package/src/components/stream/overlays/types.ts +90 -0
- package/src/components/stream/overlays/useOverlayLayout.ts +218 -0
- package/src/components/trajectory-format.ts +50 -0
- package/src/components/ui-badges.tsx +109 -0
- package/src/components/ui-switch.tsx +57 -0
- package/src/components/vector-browser-three.ts +27 -0
- package/src/config/config-catalog.ts +1092 -0
- package/src/config/config-field.tsx +1900 -0
- package/src/config/config-renderer.tsx +730 -0
- package/src/config/index.ts +11 -0
- package/src/config/ui-renderer.tsx +1751 -0
- package/src/config/ui-spec.ts +256 -0
- package/src/events/index.ts +89 -0
- package/src/hooks/index.ts +13 -0
- package/src/hooks/useBugReport.tsx +43 -0
- package/src/hooks/useCanvasWindow.ts +372 -0
- package/src/hooks/useChatAvatarVoice.ts +111 -0
- package/src/hooks/useContextMenu.ts +127 -0
- package/src/hooks/useKeyboardShortcuts.ts +86 -0
- package/src/hooks/useLifoSync.ts +143 -0
- package/src/hooks/useMemoryMonitor.ts +335 -0
- package/src/hooks/useRenderGuard.ts +43 -0
- package/src/hooks/useRetakeCapture.ts +67 -0
- package/src/hooks/useStreamPopoutNavigation.ts +27 -0
- package/src/hooks/useTimeout.ts +37 -0
- package/src/hooks/useVoiceChat.ts +1443 -0
- package/src/hooks/useWhatsAppPairing.ts +123 -0
- package/src/i18n/index.ts +76 -0
- package/src/i18n/locales/en.json +1196 -0
- package/src/i18n/locales/es.json +1196 -0
- package/src/i18n/locales/ko.json +1196 -0
- package/src/i18n/locales/pt.json +1196 -0
- package/src/i18n/locales/zh-CN.json +1196 -0
- package/src/i18n/messages.ts +21 -0
- package/src/index.ts +6 -0
- package/src/navigation/index.ts +282 -0
- package/src/navigation.test.ts +189 -0
- package/src/platform/browser-launch.test.ts +94 -0
- package/src/platform/browser-launch.ts +149 -0
- package/src/platform/index.ts +261 -0
- package/src/platform/init.ts +236 -0
- package/src/providers/index.ts +82 -0
- package/src/state/AppContext.tsx +5737 -0
- package/src/state/index.ts +6 -0
- package/src/state/internal.ts +77 -0
- package/src/state/parsers.test.ts +124 -0
- package/src/state/parsers.ts +309 -0
- package/src/state/persistence.ts +278 -0
- package/src/state/types.ts +694 -0
- package/src/state/ui-preferences.ts +3 -0
- package/src/state/useApp.ts +23 -0
- package/src/state/vrm.ts +76 -0
- package/src/stories/AppMockProvider.tsx +32 -0
- package/src/stories/ChatEmptyState.stories.tsx +27 -0
- package/src/stories/ChatMessage.stories.tsx +115 -0
- package/src/stories/CompanionHeader.stories.tsx +74 -0
- package/src/stories/CompanionView.stories.tsx +33 -0
- package/src/stories/ConversationListItem.stories.tsx +102 -0
- package/src/stories/TypingIndicator.stories.tsx +28 -0
- package/src/styles/anime.css +6324 -0
- package/src/styles/base.css +196 -0
- package/src/styles/onboarding-game.css +716 -0
- package/src/styles/styles.css +2085 -0
- package/src/styles/xterm.css +241 -0
- package/src/types/index.ts +715 -0
- package/src/types/react-test-renderer.d.ts +45 -0
- package/src/utils/asset-url.ts +110 -0
- package/src/utils/assistant-text.ts +172 -0
- package/src/utils/clipboard.ts +41 -0
- package/src/utils/desktop-dialogs.ts +80 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/number-parsing.ts +125 -0
- package/src/utils/openExternalUrl.ts +20 -0
- package/src/utils/spoken-text.ts +65 -0
- package/src/utils/streaming-text.ts +120 -0
- package/src/voice/index.ts +1 -0
- package/src/voice/types.ts +197 -0
- package/test/app/AppContext.pty-sessions.test.tsx +143 -0
- package/test/app/MessageContent.test.tsx +326 -0
- package/test/app/PermissionsOnboarding.test.tsx +216 -0
- package/test/app/PermissionsSection.test.tsx +186 -0
- package/test/app/advanced-trajectory-fine-tuning.e2e.test.ts +397 -0
- package/test/app/agent-activity-box.test.tsx +132 -0
- package/test/app/agent-transfer-lock.test.ts +274 -0
- package/test/app/api-client-electron-fallback.test.ts +139 -0
- package/test/app/api-client-timeout.test.ts +75 -0
- package/test/app/api-client-ws.test.ts +98 -0
- package/test/app/api-client.ws-max-reconnect.test.ts +139 -0
- package/test/app/api-client.ws-reconnect.test.ts +157 -0
- package/test/app/app-context-autonomy-events.test.ts +478 -0
- package/test/app/apps-page-view.test.ts +114 -0
- package/test/app/apps-view.test.ts +769 -0
- package/test/app/autonomous-workflows.e2e.test.ts +765 -0
- package/test/app/autonomy-events.test.ts +150 -0
- package/test/app/avatar-selector.test.tsx +52 -0
- package/test/app/bsc-trade-panel.test.tsx +134 -0
- package/test/app/bug-report-modal.test.tsx +353 -0
- package/test/app/character-customization.e2e.test.ts +1168 -0
- package/test/app/chat-advanced-features.e2e.test.ts +706 -0
- package/test/app/chat-composer.test.tsx +181 -0
- package/test/app/chat-language-header.test.ts +64 -0
- package/test/app/chat-message.test.tsx +222 -0
- package/test/app/chat-modal-view.test.tsx +191 -0
- package/test/app/chat-routine-filter.test.ts +96 -0
- package/test/app/chat-send-lock.test.ts +1302 -0
- package/test/app/chat-stream-api-client.test.tsx +390 -0
- package/test/app/chat-view-game-modal.test.tsx +661 -0
- package/test/app/chat-view.test.tsx +877 -0
- package/test/app/cloud-api.e2e.test.ts +258 -0
- package/test/app/cloud-login-flow.e2e.test.ts +494 -0
- package/test/app/cloud-login-lock.test.ts +411 -0
- package/test/app/command-palette.test.tsx +184 -0
- package/test/app/command-registry.test.ts +75 -0
- package/test/app/companion-greeting-wave.test.tsx +443 -0
- package/test/app/companion-stale-conversation.test.tsx +424 -0
- package/test/app/companion-view.test.tsx +686 -0
- package/test/app/confirm-delete-control.test.ts +79 -0
- package/test/app/confirm-modal.test.tsx +219 -0
- package/test/app/connectors-ui.e2e.test.ts +508 -0
- package/test/app/conversations-sidebar-game-modal.test.tsx +260 -0
- package/test/app/conversations-sidebar.test.tsx +160 -0
- package/test/app/custom-actions-smoke.test.ts +387 -0
- package/test/app/custom-avatar-api-client.test.ts +207 -0
- package/test/app/desktop-utils.test.ts +145 -0
- package/test/app/electrobun-rpc-bridge.test.ts +83 -0
- package/test/app/events.test.ts +88 -0
- package/test/app/export-import-flows.e2e.test.ts +700 -0
- package/test/app/fine-tuning-view.test.ts +471 -0
- package/test/app/game-view-auth-session.test.tsx +186 -0
- package/test/app/game-view.test.ts +444 -0
- package/test/app/global-emote-overlay.test.tsx +106 -0
- package/test/app/header-status.test.tsx +149 -0
- package/test/app/i18n.test.ts +152 -0
- package/test/app/inventory-bsc-view.test.ts +908 -0
- package/test/app/knowledge-ui.e2e.test.ts +762 -0
- package/test/app/knowledge-upload-helpers.test.ts +124 -0
- package/test/app/lifecycle-lock.test.ts +267 -0
- package/test/app/lifo-popout-utils.test.ts +208 -0
- package/test/app/lifo-safe-endpoint.test.ts +34 -0
- package/test/app/loading-screen.test.tsx +45 -0
- package/test/app/memory-monitor.test.ts +332 -0
- package/test/app/navigation.test.tsx +29 -0
- package/test/app/onboarding-finish-lock.test.ts +500 -0
- package/test/app/onboarding-language.test.tsx +161 -0
- package/test/app/onboarding-steps.test.tsx +371 -0
- package/test/app/open-external-url.test.ts +65 -0
- package/test/app/pages-navigation-smoke.e2e.test.ts +633 -0
- package/test/app/pairing-lock.test.ts +260 -0
- package/test/app/pairing-view.test.tsx +74 -0
- package/test/app/permissions-section.test.ts +432 -0
- package/test/app/plugin-bridge.test.ts +109 -0
- package/test/app/plugins-ui.e2e.test.ts +605 -0
- package/test/app/plugins-view-game-modal.test.tsx +650 -0
- package/test/app/plugins-view-toggle-restart.test.ts +129 -0
- package/test/app/provider-dropdown-default.test.tsx +164 -0
- package/test/app/restart-banner.test.tsx +197 -0
- package/test/app/retake-capture.test.ts +84 -0
- package/test/app/sandbox-api-client.test.ts +108 -0
- package/test/app/save-command-modal.test.tsx +109 -0
- package/test/app/secrets-view.test.tsx +92 -0
- package/test/app/settings-control-styles.test.tsx +142 -0
- package/test/app/settings-reset.e2e.test.ts +728 -0
- package/test/app/settings-sections.e2e.test.ts +614 -0
- package/test/app/shared-format.test.ts +44 -0
- package/test/app/shared-switch.test.ts +69 -0
- package/test/app/shell-mode-switching.e2e.test.ts +829 -0
- package/test/app/shell-mode-tab-memory.test.tsx +283 -0
- package/test/app/shell-overlays.test.tsx +50 -0
- package/test/app/shortcuts-overlay.test.tsx +111 -0
- package/test/app/sse-interruption.test.ts +122 -0
- package/test/app/startup-asset-missing.e2e.test.ts +126 -0
- package/test/app/startup-backend-missing.e2e.test.ts +118 -0
- package/test/app/startup-chat.e2e.test.ts +305 -0
- package/test/app/startup-conversation-restore.test.tsx +344 -0
- package/test/app/startup-failure-view.test.tsx +103 -0
- package/test/app/startup-onboarding.e2e.test.ts +612 -0
- package/test/app/startup-timeout.test.tsx +80 -0
- package/test/app/startup-token-401.e2e.test.ts +103 -0
- package/test/app/stream-helpers.test.ts +46 -0
- package/test/app/stream-popout-navigation.test.tsx +41 -0
- package/test/app/stream-status-bar.test.tsx +89 -0
- package/test/app/theme-toggle.test.tsx +33 -0
- package/test/app/training-api-client.test.ts +128 -0
- package/test/app/trajectories-view.test.tsx +220 -0
- package/test/app/triggers-api-client.test.ts +77 -0
- package/test/app/triggers-navigation.test.ts +118 -0
- package/test/app/triggers-view.e2e.test.ts +674 -0
- package/test/app/update-channel-lock.test.ts +259 -0
- package/test/app/vector-browser.async-cleanup.test.tsx +367 -0
- package/test/app/vector-browser.e2e.test.ts +653 -0
- package/test/app/vrm-stage.test.tsx +351 -0
- package/test/app/vrm-viewer.test.tsx +298 -0
- package/test/app/wallet-api-save-lock.test.ts +277 -0
- package/test/app/wallet-hooks.test.ts +405 -0
- package/test/app/wallet-ui-flows.e2e.test.ts +556 -0
- package/test/avatar/asset-url.test.ts +90 -0
- package/test/avatar/avatar-selector.test.ts +173 -0
- package/test/avatar/mixamo-vrm-rig-map.test.ts +111 -0
- package/test/avatar/voice-chat-streaming-text.test.ts +96 -0
- package/test/avatar/voice-chat.test.ts +391 -0
- package/test/ui/command-palette-commands.test.ts +57 -0
- package/test/ui/ui-renderer.test.ts +39 -0
- package/tsconfig.build.json +19 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,2678 @@
|
|
|
1
|
+
import { resolveAppAssetUrl } from "@elizaos/app-core/utils";
|
|
2
|
+
import {
|
|
3
|
+
MToonMaterialLoaderPlugin,
|
|
4
|
+
type VRM,
|
|
5
|
+
VRMLoaderPlugin,
|
|
6
|
+
VRMUtils,
|
|
7
|
+
} from "@pixiv/three-vrm";
|
|
8
|
+
import type {
|
|
9
|
+
SparkRenderer as SparkRendererType,
|
|
10
|
+
SplatMesh as SparkSplatMesh,
|
|
11
|
+
} from "@sparkjsdev/spark";
|
|
12
|
+
import * as THREE from "three";
|
|
13
|
+
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
|
14
|
+
import { MeshoptDecoder } from "three/examples/jsm/libs/meshopt_decoder.module.js";
|
|
15
|
+
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader.js";
|
|
16
|
+
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
17
|
+
import {
|
|
18
|
+
type AnimationLoaderContext,
|
|
19
|
+
loadEmoteClip,
|
|
20
|
+
loadIdleClip,
|
|
21
|
+
} from "./VrmAnimationLoader";
|
|
22
|
+
import { VrmBlinkController } from "./VrmBlinkController";
|
|
23
|
+
import {
|
|
24
|
+
type CameraAnimationConfig,
|
|
25
|
+
type CameraProfile,
|
|
26
|
+
type InteractionMode,
|
|
27
|
+
VrmCameraManager,
|
|
28
|
+
} from "./VrmCameraManager";
|
|
29
|
+
|
|
30
|
+
export type { CameraAnimationConfig, CameraProfile, InteractionMode };
|
|
31
|
+
|
|
32
|
+
export type VrmEngineState = {
|
|
33
|
+
vrmLoaded: boolean;
|
|
34
|
+
vrmName: string | null;
|
|
35
|
+
loadError: string | null;
|
|
36
|
+
idlePlaying: boolean;
|
|
37
|
+
idleTime: number;
|
|
38
|
+
idleTracks: number;
|
|
39
|
+
revealStarted: boolean;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type DebugVector3 = {
|
|
43
|
+
x: number;
|
|
44
|
+
y: number;
|
|
45
|
+
z: number;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
type DebugBounds = {
|
|
49
|
+
min: DebugVector3;
|
|
50
|
+
max: DebugVector3;
|
|
51
|
+
center: DebugVector3;
|
|
52
|
+
size: DebugVector3;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type VrmEngineDebugInfo = {
|
|
56
|
+
initialized: boolean;
|
|
57
|
+
rendererBackend: RendererBackend;
|
|
58
|
+
cameraProfile: CameraProfile;
|
|
59
|
+
worldUrl: string | null;
|
|
60
|
+
sceneChildren: string[];
|
|
61
|
+
camera: {
|
|
62
|
+
parentName: string | null;
|
|
63
|
+
position: DebugVector3 | null;
|
|
64
|
+
rotation: DebugVector3 | null;
|
|
65
|
+
fov: number | null;
|
|
66
|
+
lookAtTarget: DebugVector3;
|
|
67
|
+
};
|
|
68
|
+
avatar: {
|
|
69
|
+
loaded: boolean;
|
|
70
|
+
ready: boolean;
|
|
71
|
+
parentName: string | null;
|
|
72
|
+
position: DebugVector3 | null;
|
|
73
|
+
scale: DebugVector3 | null;
|
|
74
|
+
bounds: DebugBounds | null;
|
|
75
|
+
};
|
|
76
|
+
world: {
|
|
77
|
+
loaded: boolean;
|
|
78
|
+
parentName: string | null;
|
|
79
|
+
position: DebugVector3 | null;
|
|
80
|
+
scale: DebugVector3 | null;
|
|
81
|
+
bounds: DebugBounds | null;
|
|
82
|
+
rawBounds: DebugBounds | null;
|
|
83
|
+
};
|
|
84
|
+
spark: {
|
|
85
|
+
attached: boolean;
|
|
86
|
+
parentName: string | null;
|
|
87
|
+
renderOrder: number | null;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
type UpdateCallback = () => void;
|
|
92
|
+
type RendererBackend = "webgl" | "webgpu";
|
|
93
|
+
type RendererPreference = "auto" | "webgl";
|
|
94
|
+
type AnimationMixerFinishedEvent = {
|
|
95
|
+
type: "finished";
|
|
96
|
+
action: THREE.AnimationAction;
|
|
97
|
+
direction: number;
|
|
98
|
+
};
|
|
99
|
+
type ElectrobunRuntimeWindow = Window & {
|
|
100
|
+
__electrobunWindowId?: number;
|
|
101
|
+
__electrobunWebviewId?: number;
|
|
102
|
+
};
|
|
103
|
+
type RendererLike = Pick<
|
|
104
|
+
THREE.WebGLRenderer,
|
|
105
|
+
| "dispose"
|
|
106
|
+
| "domElement"
|
|
107
|
+
| "render"
|
|
108
|
+
| "setClearColor"
|
|
109
|
+
| "setPixelRatio"
|
|
110
|
+
| "setSize"
|
|
111
|
+
> & {
|
|
112
|
+
forceContextLoss?: () => void;
|
|
113
|
+
outputColorSpace?: string;
|
|
114
|
+
shadowMap?: {
|
|
115
|
+
enabled: boolean;
|
|
116
|
+
type: THREE.ShadowMapType;
|
|
117
|
+
};
|
|
118
|
+
toneMapping?: THREE.ToneMapping;
|
|
119
|
+
toneMappingExposure?: number;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
type TeleportFallbackShader = {
|
|
123
|
+
uniforms: {
|
|
124
|
+
uTeleportProgress: { value: number };
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
type WorldRevealController = {
|
|
129
|
+
mesh: SparkSplatMesh;
|
|
130
|
+
progressUniform: { value: number };
|
|
131
|
+
mode: "reveal" | "hide";
|
|
132
|
+
radius: number;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
type WorldRevealState = {
|
|
136
|
+
controller: WorldRevealController;
|
|
137
|
+
incoming: WorldRevealController;
|
|
138
|
+
outgoing: WorldRevealController | null;
|
|
139
|
+
progress: number;
|
|
140
|
+
duration: number;
|
|
141
|
+
waitingForVrm: boolean;
|
|
142
|
+
syncToTeleport: boolean;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
type TeleportSparkleParticle = {
|
|
146
|
+
sprite: THREE.Sprite;
|
|
147
|
+
material: THREE.SpriteMaterial;
|
|
148
|
+
baseAngle: number;
|
|
149
|
+
baseRadius: number;
|
|
150
|
+
height: number;
|
|
151
|
+
start: number;
|
|
152
|
+
duration: number;
|
|
153
|
+
spin: number;
|
|
154
|
+
wobble: number;
|
|
155
|
+
wobbleSpeed: number;
|
|
156
|
+
baseSize: number;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
type TeleportSparkleSystem = {
|
|
160
|
+
group: THREE.Group;
|
|
161
|
+
particles: TeleportSparkleParticle[];
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const DEFAULT_CAMERA_ANIMATION: CameraAnimationConfig = {
|
|
165
|
+
enabled: false,
|
|
166
|
+
swayAmplitude: 0.06,
|
|
167
|
+
bobAmplitude: 0.03,
|
|
168
|
+
rotationAmplitude: 0.01,
|
|
169
|
+
speed: 0.8,
|
|
170
|
+
};
|
|
171
|
+
const CAMERA_PROFILE_TRANSITION_DURATION_SECONDS = 0.8;
|
|
172
|
+
const AVATAR_SWITCH_CAMERA_TRANSITION_DURATION_SECONDS = 3;
|
|
173
|
+
const COMPANION_WORLD_SCALE = 2.5;
|
|
174
|
+
const COMPANION_DARK_WORLD_FLOOR_OFFSET_Y = -0.95;
|
|
175
|
+
const COMPANION_LIGHT_WORLD_FLOOR_OFFSET_Y = -0.35;
|
|
176
|
+
const COMPANION_WORLD_REVEAL_DURATION = 5.4;
|
|
177
|
+
const COMPANION_WORLD_REVEAL_EDGE = 0.28;
|
|
178
|
+
const COMPANION_WORLD_REVEAL_EASE_EXPONENT = 2;
|
|
179
|
+
const COMPANION_WORLD_REVEAL_START_OFFSET = 0.7;
|
|
180
|
+
const TELEPORT_DISSOLVE_START_Y = -1.2;
|
|
181
|
+
const TELEPORT_DISSOLVE_END_Y = 1.0;
|
|
182
|
+
const TELEPORT_SPARKLE_PARTICLE_COUNT = 28;
|
|
183
|
+
const TELEPORT_SPARKLE_RING_RADIUS = 0.52;
|
|
184
|
+
const TELEPORT_SPARKLE_MIN_SIZE = 0.055;
|
|
185
|
+
const TELEPORT_SPARKLE_MAX_SIZE = 0.13;
|
|
186
|
+
const COMPANION_DOF_APERTURE_SIZE = 0.028;
|
|
187
|
+
const COMPANION_DOF_NEAR_ZOOM_APERTURE_FACTOR = 0.4;
|
|
188
|
+
const COMPANION_ZOOM_NEAR_FACTOR = 0.25;
|
|
189
|
+
const COMPANION_ZOOM_MIN_RADIUS = 1.2;
|
|
190
|
+
const SPARK_CLIP_XY = 1.08;
|
|
191
|
+
const SPARK_MAX_STD_DEV = 2.35;
|
|
192
|
+
const SPARK_MAX_STD_DEV_NEAR = 1.9;
|
|
193
|
+
const SPARK_MIN_ALPHA = 0.0016;
|
|
194
|
+
const SPARK_MIN_ALPHA_NEAR = 0.0024;
|
|
195
|
+
const SPARK_SORT_DISTANCE = 0.035;
|
|
196
|
+
const SPARK_SORT_DISTANCE_NEAR = 0.05;
|
|
197
|
+
const SPARK_MAX_PIXEL_RADIUS = 96;
|
|
198
|
+
const SPARK_MAX_PIXEL_RADIUS_NEAR = 28;
|
|
199
|
+
const MAX_RENDERER_PIXEL_RATIO = 2;
|
|
200
|
+
const AVATAR_RENDERER_OVERRIDE_KEY = "milady.avatarRenderer";
|
|
201
|
+
const KNOWN_VRM_WEBGPU_WARNING =
|
|
202
|
+
'TSL: "transformedNormalView" is deprecated. Use "normalView" instead.';
|
|
203
|
+
|
|
204
|
+
let knownVrmWebGpuWarningFilterRefs = 0;
|
|
205
|
+
let releaseKnownVrmWebGpuWarningFilterGlobal: (() => void) | null = null;
|
|
206
|
+
let sharedDracoLoader: DRACOLoader | null = null;
|
|
207
|
+
let teleportSparkleTexture: THREE.CanvasTexture | null = null;
|
|
208
|
+
const DRACO_DECODER_PATH = resolveAppAssetUrl("vrm-decoders/draco/");
|
|
209
|
+
|
|
210
|
+
function getRendererPixelRatio(sparkOptimized = false): number {
|
|
211
|
+
if (typeof window === "undefined") return 1;
|
|
212
|
+
if (sparkOptimized) return 1;
|
|
213
|
+
return Math.min(
|
|
214
|
+
Math.max(window.devicePixelRatio || 1, 1),
|
|
215
|
+
MAX_RENDERER_PIXEL_RATIO,
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function isElectrobunAvatarRuntime(): boolean {
|
|
220
|
+
if (typeof window === "undefined") return false;
|
|
221
|
+
const runtimeWindow = window as ElectrobunRuntimeWindow;
|
|
222
|
+
return (
|
|
223
|
+
typeof runtimeWindow.__electrobunWindowId === "number" ||
|
|
224
|
+
typeof runtimeWindow.__electrobunWebviewId === "number"
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function getPreferredAvatarRendererBackend(): RendererBackend {
|
|
229
|
+
if (typeof window === "undefined") return "webgl";
|
|
230
|
+
const override = (() => {
|
|
231
|
+
try {
|
|
232
|
+
return window.localStorage.getItem(AVATAR_RENDERER_OVERRIDE_KEY);
|
|
233
|
+
} catch {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
})();
|
|
237
|
+
const normalizedOverride = override?.trim().toLowerCase();
|
|
238
|
+
if (normalizedOverride === "webgpu" || normalizedOverride === "webgl") {
|
|
239
|
+
return normalizedOverride;
|
|
240
|
+
}
|
|
241
|
+
return isElectrobunAvatarRuntime() ? "webgpu" : "webgl";
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function installKnownVrmWebGpuWarningFilter(): () => void {
|
|
245
|
+
knownVrmWebGpuWarningFilterRefs += 1;
|
|
246
|
+
|
|
247
|
+
if (!releaseKnownVrmWebGpuWarningFilterGlobal) {
|
|
248
|
+
const originalWarn = console.warn.bind(console);
|
|
249
|
+
console.warn = (...args: Parameters<typeof console.warn>) => {
|
|
250
|
+
if (
|
|
251
|
+
typeof args[0] === "string" &&
|
|
252
|
+
args[0].includes(KNOWN_VRM_WEBGPU_WARNING)
|
|
253
|
+
) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
originalWarn(...args);
|
|
257
|
+
};
|
|
258
|
+
releaseKnownVrmWebGpuWarningFilterGlobal = () => {
|
|
259
|
+
knownVrmWebGpuWarningFilterRefs = Math.max(
|
|
260
|
+
0,
|
|
261
|
+
knownVrmWebGpuWarningFilterRefs - 1,
|
|
262
|
+
);
|
|
263
|
+
if (knownVrmWebGpuWarningFilterRefs === 0) {
|
|
264
|
+
console.warn = originalWarn;
|
|
265
|
+
releaseKnownVrmWebGpuWarningFilterGlobal = null;
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return () => {
|
|
271
|
+
releaseKnownVrmWebGpuWarningFilterGlobal?.();
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function getSharedDracoLoader(): DRACOLoader {
|
|
276
|
+
if (!sharedDracoLoader) {
|
|
277
|
+
sharedDracoLoader = new DRACOLoader();
|
|
278
|
+
sharedDracoLoader.setDecoderConfig({ type: "wasm" });
|
|
279
|
+
sharedDracoLoader.setDecoderPath(DRACO_DECODER_PATH);
|
|
280
|
+
sharedDracoLoader.preload();
|
|
281
|
+
}
|
|
282
|
+
return sharedDracoLoader;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function configureVrmGltfLoader(loader: GLTFLoader): void {
|
|
286
|
+
loader.setMeshoptDecoder(MeshoptDecoder);
|
|
287
|
+
loader.setDRACOLoader(getSharedDracoLoader());
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function getTeleportSparkleTexture(): THREE.CanvasTexture {
|
|
291
|
+
if (teleportSparkleTexture) return teleportSparkleTexture;
|
|
292
|
+
const canvas = document.createElement("canvas");
|
|
293
|
+
canvas.width = 128;
|
|
294
|
+
canvas.height = 128;
|
|
295
|
+
const context = canvas.getContext("2d");
|
|
296
|
+
if (!context) {
|
|
297
|
+
teleportSparkleTexture = new THREE.CanvasTexture(canvas);
|
|
298
|
+
return teleportSparkleTexture;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const gradient = context.createRadialGradient(64, 64, 6, 64, 64, 64);
|
|
302
|
+
gradient.addColorStop(0.0, "rgba(255,255,255,1)");
|
|
303
|
+
gradient.addColorStop(0.2, "rgba(190,245,255,0.95)");
|
|
304
|
+
gradient.addColorStop(0.55, "rgba(112,214,255,0.48)");
|
|
305
|
+
gradient.addColorStop(1.0, "rgba(112,214,255,0)");
|
|
306
|
+
context.fillStyle = gradient;
|
|
307
|
+
context.fillRect(0, 0, 128, 128);
|
|
308
|
+
|
|
309
|
+
teleportSparkleTexture = new THREE.CanvasTexture(canvas);
|
|
310
|
+
teleportSparkleTexture.needsUpdate = true;
|
|
311
|
+
return teleportSparkleTexture;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function quantileSorted(values: number[], percentile: number): number {
|
|
315
|
+
if (values.length === 0) return 0;
|
|
316
|
+
const index = Math.min(
|
|
317
|
+
values.length - 1,
|
|
318
|
+
Math.max(0, Math.floor((values.length - 1) * percentile)),
|
|
319
|
+
);
|
|
320
|
+
return values[index] ?? 0;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function getRobustPackedSplatAnchor(splatSource: {
|
|
324
|
+
numSplats?: number;
|
|
325
|
+
forEachSplat: SparkSplatMesh["forEachSplat"];
|
|
326
|
+
}): THREE.Vector3 {
|
|
327
|
+
const maxSamples = 4096;
|
|
328
|
+
const xSamples: number[] = [];
|
|
329
|
+
const ySamples: number[] = [];
|
|
330
|
+
const zSamples: number[] = [];
|
|
331
|
+
const splatCount = splatSource.numSplats ?? maxSamples;
|
|
332
|
+
const sampleStep =
|
|
333
|
+
splatCount > maxSamples
|
|
334
|
+
? Math.max(1, Math.floor(splatCount / maxSamples))
|
|
335
|
+
: 1;
|
|
336
|
+
|
|
337
|
+
splatSource.forEachSplat((index, center) => {
|
|
338
|
+
if (sampleStep > 1 && index % sampleStep !== 0) return;
|
|
339
|
+
xSamples.push(center.x);
|
|
340
|
+
ySamples.push(center.y);
|
|
341
|
+
zSamples.push(center.z);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
if (xSamples.length === 0) {
|
|
345
|
+
return new THREE.Vector3(0, 0, 0);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
xSamples.sort((a, b) => a - b);
|
|
349
|
+
ySamples.sort((a, b) => a - b);
|
|
350
|
+
zSamples.sort((a, b) => a - b);
|
|
351
|
+
|
|
352
|
+
return new THREE.Vector3(
|
|
353
|
+
quantileSorted(xSamples, 0.5),
|
|
354
|
+
quantileSorted(ySamples, 0.05),
|
|
355
|
+
quantileSorted(zSamples, 0.5),
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function getRobustSplatAnchor(splat: SparkSplatMesh): THREE.Vector3 {
|
|
360
|
+
return getRobustPackedSplatAnchor({
|
|
361
|
+
numSplats: (
|
|
362
|
+
splat as unknown as {
|
|
363
|
+
packedSplats?: { numSplats?: number };
|
|
364
|
+
}
|
|
365
|
+
).packedSplats?.numSplats,
|
|
366
|
+
forEachSplat: splat.forEachSplat.bind(splat),
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function getRobustPackedSplatRadialExtent(
|
|
371
|
+
splatSource: {
|
|
372
|
+
numSplats?: number;
|
|
373
|
+
forEachSplat: SparkSplatMesh["forEachSplat"];
|
|
374
|
+
},
|
|
375
|
+
anchor: THREE.Vector3,
|
|
376
|
+
): number {
|
|
377
|
+
const maxSamples = 4096;
|
|
378
|
+
const radialSamples: number[] = [];
|
|
379
|
+
const splatCount = splatSource.numSplats ?? maxSamples;
|
|
380
|
+
const sampleStep =
|
|
381
|
+
splatCount > maxSamples
|
|
382
|
+
? Math.max(1, Math.floor(splatCount / maxSamples))
|
|
383
|
+
: 1;
|
|
384
|
+
|
|
385
|
+
splatSource.forEachSplat((index, center) => {
|
|
386
|
+
if (sampleStep > 1 && index % sampleStep !== 0) return;
|
|
387
|
+
radialSamples.push(Math.hypot(center.x - anchor.x, center.z - anchor.z));
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
if (radialSamples.length === 0) {
|
|
391
|
+
return 1;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
radialSamples.sort((a, b) => a - b);
|
|
395
|
+
return Math.max(1, quantileSorted(radialSamples, 0.985));
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function getRobustSplatRadialExtent(
|
|
399
|
+
splat: SparkSplatMesh,
|
|
400
|
+
anchor: THREE.Vector3,
|
|
401
|
+
): number {
|
|
402
|
+
return getRobustPackedSplatRadialExtent(
|
|
403
|
+
{
|
|
404
|
+
numSplats: (
|
|
405
|
+
splat as unknown as {
|
|
406
|
+
packedSplats?: { numSplats?: number };
|
|
407
|
+
}
|
|
408
|
+
).packedSplats?.numSplats,
|
|
409
|
+
forEachSplat: splat.forEachSplat.bind(splat),
|
|
410
|
+
},
|
|
411
|
+
anchor,
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function getCompanionWorldFloorOffsetY(url: string): number {
|
|
416
|
+
const normalizedUrl = url.toLowerCase();
|
|
417
|
+
return normalizedUrl.includes("night") ||
|
|
418
|
+
normalizedUrl.includes("dark") ||
|
|
419
|
+
normalizedUrl.includes("lunarpunk")
|
|
420
|
+
? COMPANION_DARK_WORLD_FLOOR_OFFSET_Y
|
|
421
|
+
: COMPANION_LIGHT_WORLD_FLOOR_OFFSET_Y;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function isGzipBuffer(buffer: ArrayBuffer): boolean {
|
|
425
|
+
if (buffer.byteLength < 2) return false;
|
|
426
|
+
const bytes = new Uint8Array(buffer, 0, 2);
|
|
427
|
+
return bytes[0] === 0x1f && bytes[1] === 0x8b;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
async function decompressGzipBuffer(buffer: ArrayBuffer): Promise<ArrayBuffer> {
|
|
431
|
+
if (typeof DecompressionStream !== "function") {
|
|
432
|
+
throw new Error(
|
|
433
|
+
"This runtime does not support gzip-compressed VRM assets.",
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
const stream = new Blob([buffer])
|
|
437
|
+
.stream()
|
|
438
|
+
.pipeThrough(new DecompressionStream("gzip"));
|
|
439
|
+
return await new Response(stream).arrayBuffer();
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
async function loadGltfAsset(
|
|
443
|
+
loader: GLTFLoader,
|
|
444
|
+
url: string,
|
|
445
|
+
): Promise<Awaited<ReturnType<GLTFLoader["loadAsync"]>>> {
|
|
446
|
+
const response = await fetch(url);
|
|
447
|
+
if (!response.ok) {
|
|
448
|
+
throw new Error(`Failed to fetch VRM asset: ${response.status}`);
|
|
449
|
+
}
|
|
450
|
+
let buffer = await response.arrayBuffer();
|
|
451
|
+
if (!isGzipBuffer(buffer)) {
|
|
452
|
+
return await loader.loadAsync(url);
|
|
453
|
+
}
|
|
454
|
+
buffer = await decompressGzipBuffer(buffer);
|
|
455
|
+
const objectUrl = URL.createObjectURL(
|
|
456
|
+
new Blob([buffer], { type: "model/gltf-binary" }),
|
|
457
|
+
);
|
|
458
|
+
try {
|
|
459
|
+
return await loader.loadAsync(objectUrl);
|
|
460
|
+
} finally {
|
|
461
|
+
URL.revokeObjectURL(objectUrl);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Create the best available renderer for the current platform.
|
|
467
|
+
* Electrobun's CEF desktop shell expects WebGPU for the avatar stage, while the
|
|
468
|
+
* browser dev shell stays on WebGL by default to avoid upstream TSL noise.
|
|
469
|
+
* A localStorage override can force either backend for debugging.
|
|
470
|
+
* THREE.WebGPURenderer is async-init and requires await renderer.init().
|
|
471
|
+
*/
|
|
472
|
+
async function createRenderer(
|
|
473
|
+
canvas: HTMLCanvasElement,
|
|
474
|
+
preference: RendererPreference = "auto",
|
|
475
|
+
sparkOptimized = false,
|
|
476
|
+
): Promise<{ backend: RendererBackend; renderer: RendererLike }> {
|
|
477
|
+
if (
|
|
478
|
+
preference !== "webgl" &&
|
|
479
|
+
getPreferredAvatarRendererBackend() === "webgpu" &&
|
|
480
|
+
typeof navigator !== "undefined" &&
|
|
481
|
+
navigator.gpu
|
|
482
|
+
) {
|
|
483
|
+
try {
|
|
484
|
+
const { WebGPURenderer } = await import("three/webgpu");
|
|
485
|
+
const renderer = new WebGPURenderer({
|
|
486
|
+
canvas,
|
|
487
|
+
alpha: true,
|
|
488
|
+
antialias: !sparkOptimized,
|
|
489
|
+
}) as unknown as RendererLike & { init?: () => Promise<unknown> };
|
|
490
|
+
await renderer.init?.();
|
|
491
|
+
console.info("[VrmEngine] Using WebGPURenderer");
|
|
492
|
+
return { backend: "webgpu", renderer };
|
|
493
|
+
} catch (err) {
|
|
494
|
+
console.warn(
|
|
495
|
+
"[VrmEngine] WebGPURenderer failed, falling back to WebGL:",
|
|
496
|
+
err,
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
const renderer = new THREE.WebGLRenderer({
|
|
501
|
+
canvas,
|
|
502
|
+
alpha: true,
|
|
503
|
+
antialias: !sparkOptimized,
|
|
504
|
+
powerPreference: sparkOptimized ? "high-performance" : "default",
|
|
505
|
+
}) as unknown as RendererLike;
|
|
506
|
+
console.info("[VrmEngine] Using WebGLRenderer");
|
|
507
|
+
return { backend: "webgl", renderer };
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
export class VrmEngine {
|
|
511
|
+
private static sparkModulePromise: Promise<
|
|
512
|
+
typeof import("@sparkjsdev/spark")
|
|
513
|
+
> | null = null;
|
|
514
|
+
private renderer: RendererLike | null = null;
|
|
515
|
+
private rendererBackend: RendererBackend = "webgl";
|
|
516
|
+
private rendererPreference: RendererPreference = "auto";
|
|
517
|
+
private scene: THREE.Scene | null = null;
|
|
518
|
+
private avatarRoot: THREE.Group | null = null;
|
|
519
|
+
private camera: THREE.PerspectiveCamera | null = null;
|
|
520
|
+
private clock = new THREE.Clock();
|
|
521
|
+
private vrm: VRM | null = null;
|
|
522
|
+
private mixer: THREE.AnimationMixer | null = null;
|
|
523
|
+
private idleAction: THREE.AnimationAction | null = null;
|
|
524
|
+
private idleLoadPromise: Promise<THREE.AnimationAction | null> | null = null;
|
|
525
|
+
private animationFrameId: number | null = null;
|
|
526
|
+
private onUpdate: UpdateCallback | null = null;
|
|
527
|
+
private initialized = false;
|
|
528
|
+
private loadingAborted = false;
|
|
529
|
+
private vrmLoadRequestId = 0;
|
|
530
|
+
private vrmReady = false;
|
|
531
|
+
private lastLoadError: string | null = null;
|
|
532
|
+
private teleportProgress = 1.0;
|
|
533
|
+
private teleportProgressUniform: { value: number } | null = null;
|
|
534
|
+
private teleportDissolvedMaterials: THREE.Material[] = [];
|
|
535
|
+
private teleportFallbackShaders: TeleportFallbackShader[] = [];
|
|
536
|
+
private teleportSparkles: TeleportSparkleSystem | null = null;
|
|
537
|
+
private revealStarted = false;
|
|
538
|
+
private mouthValue = 0;
|
|
539
|
+
private mouthSmoothed = 0;
|
|
540
|
+
private vrmName: string | null = null;
|
|
541
|
+
private lookAtTarget = new THREE.Vector3(0, 0.5, 0);
|
|
542
|
+
private readonly idleGlbUrl = resolveAppAssetUrl("animations/idle.glb.gz");
|
|
543
|
+
private cameraAnimation: CameraAnimationConfig = {
|
|
544
|
+
...DEFAULT_CAMERA_ANIMATION,
|
|
545
|
+
};
|
|
546
|
+
private baseCameraPosition = new THREE.Vector3();
|
|
547
|
+
private elapsedTime = 0;
|
|
548
|
+
private speaking = false;
|
|
549
|
+
private speakingStartTime = 0;
|
|
550
|
+
private readonly blinkController = new VrmBlinkController();
|
|
551
|
+
private readonly cameraManager = new VrmCameraManager();
|
|
552
|
+
private emoteAction: THREE.AnimationAction | null = null;
|
|
553
|
+
private emoteTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
554
|
+
private emoteCompletionCleanup: (() => void) | null = null;
|
|
555
|
+
private emoteClipCache = new Map<string, THREE.AnimationClip>();
|
|
556
|
+
private emoteRequestId = 0;
|
|
557
|
+
private controls: OrbitControls | null = null;
|
|
558
|
+
private paused = false;
|
|
559
|
+
private interactionEnabled = false;
|
|
560
|
+
private interactionMode: InteractionMode = "free";
|
|
561
|
+
private cameraProfile: CameraProfile = "chat";
|
|
562
|
+
private worldUrl: string | null = null;
|
|
563
|
+
private worldMesh: SparkSplatMesh | null = null;
|
|
564
|
+
private worldReveal: WorldRevealState | null = null;
|
|
565
|
+
private sparkRenderer: SparkRendererType | null = null;
|
|
566
|
+
private worldLoadRequestId = 0;
|
|
567
|
+
private pointerParallaxEnabled = false;
|
|
568
|
+
private pointerParallaxTarget = new THREE.Vector2();
|
|
569
|
+
private pointerParallaxCurrent = new THREE.Vector2();
|
|
570
|
+
private pointerParallaxPosition = new THREE.Vector3();
|
|
571
|
+
private pointerParallaxLookAt = new THREE.Vector3();
|
|
572
|
+
private dragOrbitTarget = new THREE.Vector2();
|
|
573
|
+
private dragOrbitCurrent = new THREE.Vector2();
|
|
574
|
+
private companionZoomTarget = 0;
|
|
575
|
+
private companionZoomCurrent = 0;
|
|
576
|
+
private avatarLookTarget: THREE.Group | null = null;
|
|
577
|
+
private headLookTarget = new THREE.Vector2();
|
|
578
|
+
private headLookCurrent = new THREE.Vector2();
|
|
579
|
+
|
|
580
|
+
private clearEmoteTimeout(): void {
|
|
581
|
+
if (this.emoteTimeout !== null) {
|
|
582
|
+
clearTimeout(this.emoteTimeout);
|
|
583
|
+
this.emoteTimeout = null;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
private clearEmoteCompletionCleanup(): void {
|
|
588
|
+
this.emoteCompletionCleanup?.();
|
|
589
|
+
this.emoteCompletionCleanup = null;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
private clearPendingEmoteCompletion(): void {
|
|
593
|
+
this.clearEmoteTimeout();
|
|
594
|
+
this.clearEmoteCompletionCleanup();
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
private watchOneShotEmoteCompletion(
|
|
598
|
+
mixer: THREE.AnimationMixer,
|
|
599
|
+
action: THREE.AnimationAction,
|
|
600
|
+
requestId: number,
|
|
601
|
+
fallbackDurationSeconds: number,
|
|
602
|
+
): void {
|
|
603
|
+
const handleFinished = (event: AnimationMixerFinishedEvent): void => {
|
|
604
|
+
if (event.action !== action) return;
|
|
605
|
+
if (this.emoteRequestId !== requestId || this.emoteAction !== action) {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
this.stopEmote();
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
mixer.addEventListener("finished", handleFinished);
|
|
612
|
+
this.emoteCompletionCleanup = () => {
|
|
613
|
+
mixer.removeEventListener("finished", handleFinished);
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
const safeDuration =
|
|
617
|
+
Number.isFinite(fallbackDurationSeconds) && fallbackDurationSeconds > 0
|
|
618
|
+
? fallbackDurationSeconds
|
|
619
|
+
: 3;
|
|
620
|
+
|
|
621
|
+
// Keep a timer fallback in case the mixer completion event is missed.
|
|
622
|
+
this.emoteTimeout = setTimeout(
|
|
623
|
+
() => {
|
|
624
|
+
if (this.emoteRequestId !== requestId || this.emoteAction !== action) {
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
this.stopEmote();
|
|
628
|
+
},
|
|
629
|
+
Math.max(0.25, safeDuration + 0.1) * 1000,
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
private activateAction(action: THREE.AnimationAction): void {
|
|
634
|
+
action.enabled = true;
|
|
635
|
+
action.paused = false;
|
|
636
|
+
action.setEffectiveTimeScale(1);
|
|
637
|
+
action.setEffectiveWeight(1);
|
|
638
|
+
action.play();
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
private playActionWithBlend(
|
|
642
|
+
action: THREE.AnimationAction,
|
|
643
|
+
fromAction: THREE.AnimationAction | null,
|
|
644
|
+
fadeDuration: number,
|
|
645
|
+
): void {
|
|
646
|
+
action.reset();
|
|
647
|
+
this.activateAction(action);
|
|
648
|
+
if (fromAction && fromAction !== action) {
|
|
649
|
+
this.activateAction(fromAction);
|
|
650
|
+
action.crossFadeFrom(fromAction, fadeDuration, false);
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
action.fadeIn(fadeDuration);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
private async ensureIdleAction(
|
|
657
|
+
vrm: VRM,
|
|
658
|
+
mixer: THREE.AnimationMixer,
|
|
659
|
+
): Promise<THREE.AnimationAction | null> {
|
|
660
|
+
if (this.idleAction) return this.idleAction;
|
|
661
|
+
if (this.idleLoadPromise) return this.idleLoadPromise;
|
|
662
|
+
|
|
663
|
+
this.idleLoadPromise = (async () => {
|
|
664
|
+
const clip = await loadIdleClip(
|
|
665
|
+
vrm,
|
|
666
|
+
this.idleGlbUrl,
|
|
667
|
+
this.animationLoaderContext,
|
|
668
|
+
);
|
|
669
|
+
if (!clip || this.loadingAborted || this.vrm !== vrm) {
|
|
670
|
+
return null;
|
|
671
|
+
}
|
|
672
|
+
const activeMixer = this.mixer ?? mixer;
|
|
673
|
+
if (!activeMixer || this.vrm !== vrm) {
|
|
674
|
+
return null;
|
|
675
|
+
}
|
|
676
|
+
const action = activeMixer.clipAction(clip);
|
|
677
|
+
action.reset();
|
|
678
|
+
action.setLoop(THREE.LoopRepeat, Infinity);
|
|
679
|
+
action.timeScale = 1.0;
|
|
680
|
+
this.idleAction = action;
|
|
681
|
+
activeMixer.update(1 / 60);
|
|
682
|
+
return action;
|
|
683
|
+
})().finally(() => {
|
|
684
|
+
this.idleLoadPromise = null;
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
return this.idleLoadPromise;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
private restoreIdleAfterEmote(
|
|
691
|
+
activeEmote: THREE.AnimationAction | null,
|
|
692
|
+
fadeDuration: number,
|
|
693
|
+
vrm: VRM,
|
|
694
|
+
mixer: THREE.AnimationMixer,
|
|
695
|
+
): void {
|
|
696
|
+
void this.ensureIdleAction(vrm, mixer).then((idleAction) => {
|
|
697
|
+
if (!idleAction || this.loadingAborted || this.vrm !== vrm) {
|
|
698
|
+
activeEmote?.fadeOut(fadeDuration);
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
this.activateAction(idleAction);
|
|
702
|
+
if (activeEmote && activeEmote !== idleAction) {
|
|
703
|
+
idleAction.crossFadeFrom(activeEmote, fadeDuration, false);
|
|
704
|
+
} else {
|
|
705
|
+
idleAction.fadeIn(fadeDuration);
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
private avatarLookRig: {
|
|
710
|
+
headBone: THREE.Object3D | null;
|
|
711
|
+
neckBone: THREE.Object3D | null;
|
|
712
|
+
spineBone: THREE.Object3D | null;
|
|
713
|
+
} = {
|
|
714
|
+
headBone: null,
|
|
715
|
+
neckBone: null,
|
|
716
|
+
spineBone: null,
|
|
717
|
+
};
|
|
718
|
+
private readonly tempCameraOrbitOffset = new THREE.Vector3();
|
|
719
|
+
private readonly tempCameraSpherical = new THREE.Spherical();
|
|
720
|
+
private readonly tempAvatarLookTarget = new THREE.Vector3();
|
|
721
|
+
private readonly tempAvatarLocalTarget = new THREE.Vector3();
|
|
722
|
+
private readonly tempAvatarLocalAnchor = new THREE.Vector3();
|
|
723
|
+
private readonly tempAvatarHeadWorld = new THREE.Vector3();
|
|
724
|
+
private readyPromise: Promise<void> = Promise.resolve();
|
|
725
|
+
private resolveReady: (() => void) | null = null;
|
|
726
|
+
private rejectReady: ((error?: unknown) => void) | null = null;
|
|
727
|
+
private releaseKnownWebGpuWarningFilter: (() => void) | null = null;
|
|
728
|
+
|
|
729
|
+
// Transition state
|
|
730
|
+
private isCameraTransitioning = false;
|
|
731
|
+
private transitionStartFov = 0;
|
|
732
|
+
private transitionTargetFov = 0;
|
|
733
|
+
private transitionStartPos = new THREE.Vector3();
|
|
734
|
+
private transitionTargetPos = new THREE.Vector3();
|
|
735
|
+
private transitionStartLookAt = new THREE.Vector3();
|
|
736
|
+
private transitionTargetLookAt = new THREE.Vector3();
|
|
737
|
+
private transitionProgress = 0;
|
|
738
|
+
private transitionDuration = CAMERA_PROFILE_TRANSITION_DURATION_SECONDS;
|
|
739
|
+
|
|
740
|
+
private handleControlStart = (): void => {
|
|
741
|
+
if (!this.interactionEnabled) return;
|
|
742
|
+
};
|
|
743
|
+
private handleControlEnd = (): void => {
|
|
744
|
+
if (!this.interactionEnabled) return;
|
|
745
|
+
if (this.camera) {
|
|
746
|
+
this.baseCameraPosition.copy(this.camera.position);
|
|
747
|
+
}
|
|
748
|
+
if (this.controls) {
|
|
749
|
+
this.lookAtTarget.copy(this.controls.target);
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
private scheduleNextFrame(): void {
|
|
754
|
+
if (!this.initialized || this.paused || this.animationFrameId !== null) {
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
this.animationFrameId = requestAnimationFrame(() => {
|
|
758
|
+
this.animationFrameId = null;
|
|
759
|
+
this.loop();
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
private stopLoop(): void {
|
|
764
|
+
if (this.animationFrameId !== null) {
|
|
765
|
+
cancelAnimationFrame(this.animationFrameId);
|
|
766
|
+
this.animationFrameId = null;
|
|
767
|
+
}
|
|
768
|
+
this.clock.stop();
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
private resumeLoop(): void {
|
|
772
|
+
if (!this.initialized || this.paused) return;
|
|
773
|
+
this.clock.start();
|
|
774
|
+
this.scheduleNextFrame();
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
private async loadSparkModule(): Promise<typeof import("@sparkjsdev/spark")> {
|
|
778
|
+
if (!VrmEngine.sparkModulePromise) {
|
|
779
|
+
VrmEngine.sparkModulePromise = import("@sparkjsdev/spark");
|
|
780
|
+
}
|
|
781
|
+
return VrmEngine.sparkModulePromise;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
private async ensureSparkRenderer(): Promise<void> {
|
|
785
|
+
if (this.sparkRenderer || this.rendererBackend !== "webgl") return;
|
|
786
|
+
if (!this.scene || !this.renderer) return;
|
|
787
|
+
|
|
788
|
+
const { SparkRenderer } = await this.loadSparkModule();
|
|
789
|
+
const sparkRenderer = new SparkRenderer({
|
|
790
|
+
renderer: this.renderer as THREE.WebGLRenderer,
|
|
791
|
+
apertureAngle: 0.0,
|
|
792
|
+
focalDistance: 5.0,
|
|
793
|
+
originDistance: 1,
|
|
794
|
+
clipXY: SPARK_CLIP_XY,
|
|
795
|
+
maxStdDev: SPARK_MAX_STD_DEV,
|
|
796
|
+
maxPixelRadius: SPARK_MAX_PIXEL_RADIUS,
|
|
797
|
+
minAlpha: SPARK_MIN_ALPHA,
|
|
798
|
+
view: {
|
|
799
|
+
depthBias: 1,
|
|
800
|
+
sortDistance: SPARK_SORT_DISTANCE,
|
|
801
|
+
sortRadial: true,
|
|
802
|
+
sort360: false,
|
|
803
|
+
},
|
|
804
|
+
});
|
|
805
|
+
sparkRenderer.renderOrder = 9998;
|
|
806
|
+
this.scene.add(sparkRenderer);
|
|
807
|
+
this.sparkRenderer = sparkRenderer;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
private updateSparkPerformanceProfile(): void {
|
|
811
|
+
const sparkRenderer = this.sparkRenderer;
|
|
812
|
+
if (!sparkRenderer) return;
|
|
813
|
+
if (!this.worldMesh) {
|
|
814
|
+
sparkRenderer.maxPixelRadius = SPARK_MAX_PIXEL_RADIUS;
|
|
815
|
+
sparkRenderer.maxStdDev = SPARK_MAX_STD_DEV;
|
|
816
|
+
sparkRenderer.minAlpha = SPARK_MIN_ALPHA;
|
|
817
|
+
sparkRenderer.clipXY = SPARK_CLIP_XY;
|
|
818
|
+
sparkRenderer.defaultView.sortDistance = SPARK_SORT_DISTANCE;
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
const isCompanionProfile =
|
|
822
|
+
this.cameraProfile === "companion" ||
|
|
823
|
+
this.cameraProfile === "companion_close";
|
|
824
|
+
const closeZoomFactor = isCompanionProfile
|
|
825
|
+
? THREE.MathUtils.smoothstep(this.companionZoomCurrent, 0.3, 1)
|
|
826
|
+
: 0;
|
|
827
|
+
|
|
828
|
+
sparkRenderer.maxPixelRadius = THREE.MathUtils.lerp(
|
|
829
|
+
SPARK_MAX_PIXEL_RADIUS,
|
|
830
|
+
SPARK_MAX_PIXEL_RADIUS_NEAR,
|
|
831
|
+
closeZoomFactor,
|
|
832
|
+
);
|
|
833
|
+
sparkRenderer.maxStdDev = THREE.MathUtils.lerp(
|
|
834
|
+
SPARK_MAX_STD_DEV,
|
|
835
|
+
SPARK_MAX_STD_DEV_NEAR,
|
|
836
|
+
closeZoomFactor,
|
|
837
|
+
);
|
|
838
|
+
sparkRenderer.minAlpha = THREE.MathUtils.lerp(
|
|
839
|
+
SPARK_MIN_ALPHA,
|
|
840
|
+
SPARK_MIN_ALPHA_NEAR,
|
|
841
|
+
closeZoomFactor,
|
|
842
|
+
);
|
|
843
|
+
sparkRenderer.clipXY = THREE.MathUtils.lerp(
|
|
844
|
+
SPARK_CLIP_XY,
|
|
845
|
+
1.03,
|
|
846
|
+
closeZoomFactor,
|
|
847
|
+
);
|
|
848
|
+
sparkRenderer.defaultView.sortDistance = THREE.MathUtils.lerp(
|
|
849
|
+
SPARK_SORT_DISTANCE,
|
|
850
|
+
SPARK_SORT_DISTANCE_NEAR,
|
|
851
|
+
closeZoomFactor,
|
|
852
|
+
);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
private createWorldRevealController(
|
|
856
|
+
spark: typeof import("@sparkjsdev/spark"),
|
|
857
|
+
mesh: SparkSplatMesh,
|
|
858
|
+
reveal: { origin: THREE.Vector3; radius: number },
|
|
859
|
+
mode: "reveal" | "hide",
|
|
860
|
+
): WorldRevealController | null {
|
|
861
|
+
const dyno = (
|
|
862
|
+
"dyno" in spark ? Reflect.get(spark as object, "dyno") : undefined
|
|
863
|
+
) as
|
|
864
|
+
| {
|
|
865
|
+
Gsplat: unknown;
|
|
866
|
+
dynoBlock: (
|
|
867
|
+
inTypes: Record<string, unknown>,
|
|
868
|
+
outTypes: Record<string, unknown>,
|
|
869
|
+
construct: (
|
|
870
|
+
inputs: Record<string, unknown>,
|
|
871
|
+
) => Record<string, unknown>,
|
|
872
|
+
) => unknown;
|
|
873
|
+
dynoFloat: (value?: number, key?: string) => { value: number };
|
|
874
|
+
dynoVec3: (
|
|
875
|
+
value?: THREE.Vector3,
|
|
876
|
+
key?: string,
|
|
877
|
+
) => { value: THREE.Vector3 };
|
|
878
|
+
dynoConst: (type: string, value: number) => unknown;
|
|
879
|
+
splitGsplat: (gsplat: unknown) => {
|
|
880
|
+
outputs: {
|
|
881
|
+
center: unknown;
|
|
882
|
+
scales: unknown;
|
|
883
|
+
rgb: unknown;
|
|
884
|
+
opacity: unknown;
|
|
885
|
+
};
|
|
886
|
+
};
|
|
887
|
+
combineGsplat: (value: Record<string, unknown>) => unknown;
|
|
888
|
+
add: (a: unknown, b: unknown) => unknown;
|
|
889
|
+
sub: (a: unknown, b: unknown) => unknown;
|
|
890
|
+
mul: (a: unknown, b: unknown) => unknown;
|
|
891
|
+
div: (a: unknown, b: unknown) => unknown;
|
|
892
|
+
abs: (a: unknown) => unknown;
|
|
893
|
+
clamp: (a: unknown, min: unknown, max: unknown) => unknown;
|
|
894
|
+
max: (a: unknown, b: unknown) => unknown;
|
|
895
|
+
mix: (a: unknown, b: unknown, t: unknown) => unknown;
|
|
896
|
+
smoothstep: (edge0: unknown, edge1: unknown, x: unknown) => unknown;
|
|
897
|
+
pow: (a: unknown, b: unknown) => unknown;
|
|
898
|
+
length: (a: unknown) => unknown;
|
|
899
|
+
swizzle: (a: unknown, select: string) => unknown;
|
|
900
|
+
}
|
|
901
|
+
| undefined;
|
|
902
|
+
if (
|
|
903
|
+
!dyno?.Gsplat ||
|
|
904
|
+
!dyno.dynoBlock ||
|
|
905
|
+
!dyno.dynoFloat ||
|
|
906
|
+
!dyno.dynoVec3 ||
|
|
907
|
+
!dyno.dynoConst ||
|
|
908
|
+
!dyno.splitGsplat ||
|
|
909
|
+
!dyno.combineGsplat ||
|
|
910
|
+
!dyno.add ||
|
|
911
|
+
!dyno.sub ||
|
|
912
|
+
!dyno.mul ||
|
|
913
|
+
!dyno.div ||
|
|
914
|
+
!dyno.abs ||
|
|
915
|
+
!dyno.clamp ||
|
|
916
|
+
!dyno.max ||
|
|
917
|
+
!dyno.mix ||
|
|
918
|
+
!dyno.smoothstep ||
|
|
919
|
+
!dyno.pow ||
|
|
920
|
+
!dyno.length ||
|
|
921
|
+
!dyno.swizzle
|
|
922
|
+
) {
|
|
923
|
+
return null;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
const originUniform = dyno.dynoVec3(reveal.origin, "uWorldRevealOrigin");
|
|
927
|
+
const resolvedRadius = Math.max(
|
|
928
|
+
reveal.radius,
|
|
929
|
+
COMPANION_WORLD_REVEAL_EDGE * 2,
|
|
930
|
+
);
|
|
931
|
+
const radiusUniform = dyno.dynoFloat(resolvedRadius, "uWorldRevealRadius");
|
|
932
|
+
const edgeUniform = dyno.dynoFloat(
|
|
933
|
+
COMPANION_WORLD_REVEAL_EDGE,
|
|
934
|
+
"uWorldRevealEdge",
|
|
935
|
+
);
|
|
936
|
+
const progressUniform = dyno.dynoFloat(0, "uWorldRevealProgress");
|
|
937
|
+
const wireScaleUniform = dyno.dynoVec3(
|
|
938
|
+
new THREE.Vector3(0.004, 0.004, 0.004),
|
|
939
|
+
"uWorldRevealWireScale",
|
|
940
|
+
);
|
|
941
|
+
const wireAlphaUniform = dyno.dynoFloat(0.42, "uWorldRevealWireAlpha");
|
|
942
|
+
const wireBoostUniform = dyno.dynoFloat(0.3, "uWorldRevealWireBoost");
|
|
943
|
+
const zero = dyno.dynoConst("float", 0);
|
|
944
|
+
const one = dyno.dynoConst("float", 1);
|
|
945
|
+
const two = dyno.dynoConst("float", 2);
|
|
946
|
+
const startOffset = dyno.dynoConst(
|
|
947
|
+
"float",
|
|
948
|
+
-COMPANION_WORLD_REVEAL_START_OFFSET,
|
|
949
|
+
);
|
|
950
|
+
|
|
951
|
+
const modifier = dyno.dynoBlock(
|
|
952
|
+
{ gsplat: dyno.Gsplat },
|
|
953
|
+
{ gsplat: dyno.Gsplat },
|
|
954
|
+
({ gsplat }) => {
|
|
955
|
+
if (!gsplat) {
|
|
956
|
+
throw new Error("Missing gsplat input for world reveal");
|
|
957
|
+
}
|
|
958
|
+
const { center, scales, rgb, opacity } =
|
|
959
|
+
dyno.splitGsplat(gsplat).outputs;
|
|
960
|
+
const radialDistance = dyno.length(
|
|
961
|
+
dyno.swizzle(dyno.sub(center, originUniform), "xz"),
|
|
962
|
+
);
|
|
963
|
+
const currentRadius = dyno.add(
|
|
964
|
+
dyno.mul(radiusUniform, progressUniform),
|
|
965
|
+
startOffset,
|
|
966
|
+
);
|
|
967
|
+
const bodyMask = dyno.sub(
|
|
968
|
+
one,
|
|
969
|
+
dyno.smoothstep(
|
|
970
|
+
dyno.sub(currentRadius, edgeUniform),
|
|
971
|
+
dyno.add(currentRadius, edgeUniform),
|
|
972
|
+
radialDistance,
|
|
973
|
+
),
|
|
974
|
+
);
|
|
975
|
+
const ringDistance = dyno.abs(dyno.sub(radialDistance, currentRadius));
|
|
976
|
+
const ringMask = dyno.pow(
|
|
977
|
+
dyno.sub(
|
|
978
|
+
one,
|
|
979
|
+
dyno.smoothstep(zero, dyno.mul(edgeUniform, two), ringDistance),
|
|
980
|
+
),
|
|
981
|
+
two,
|
|
982
|
+
);
|
|
983
|
+
const visibleMask =
|
|
984
|
+
mode === "hide" ? dyno.sub(one, bodyMask) : bodyMask;
|
|
985
|
+
const wireFactor = dyno.clamp(
|
|
986
|
+
dyno.max(visibleMask, dyno.mul(ringMask, wireAlphaUniform)),
|
|
987
|
+
zero,
|
|
988
|
+
one,
|
|
989
|
+
);
|
|
990
|
+
const brightenedRgb = dyno.mul(
|
|
991
|
+
rgb,
|
|
992
|
+
dyno.add(one, dyno.mul(ringMask, wireBoostUniform)),
|
|
993
|
+
);
|
|
994
|
+
return {
|
|
995
|
+
gsplat: dyno.combineGsplat({
|
|
996
|
+
gsplat,
|
|
997
|
+
scales: dyno.mix(wireScaleUniform, scales, wireFactor),
|
|
998
|
+
rgb: dyno.mix(brightenedRgb, rgb, visibleMask),
|
|
999
|
+
opacity: dyno.mul(opacity, wireFactor),
|
|
1000
|
+
}),
|
|
1001
|
+
};
|
|
1002
|
+
},
|
|
1003
|
+
);
|
|
1004
|
+
|
|
1005
|
+
mesh.objectModifier = modifier as SparkSplatMesh["objectModifier"];
|
|
1006
|
+
this.refreshSplatMesh(mesh);
|
|
1007
|
+
|
|
1008
|
+
return {
|
|
1009
|
+
mesh,
|
|
1010
|
+
progressUniform,
|
|
1011
|
+
mode,
|
|
1012
|
+
radius: resolvedRadius,
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
private refreshSplatMesh(mesh: SparkSplatMesh): void {
|
|
1017
|
+
mesh.updateGenerator();
|
|
1018
|
+
const refreshableMesh = mesh as SparkSplatMesh & {
|
|
1019
|
+
updateVersion?: () => void;
|
|
1020
|
+
};
|
|
1021
|
+
refreshableMesh.updateVersion?.();
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
private setWorldRevealProgress(
|
|
1025
|
+
controller: WorldRevealController,
|
|
1026
|
+
progress: number,
|
|
1027
|
+
): void {
|
|
1028
|
+
controller.progressUniform.value = THREE.MathUtils.clamp(progress, 0, 1);
|
|
1029
|
+
const refreshableMesh = controller.mesh as SparkSplatMesh & {
|
|
1030
|
+
updateVersion?: () => void;
|
|
1031
|
+
};
|
|
1032
|
+
refreshableMesh.updateVersion?.();
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
private queueWorldReveal(
|
|
1036
|
+
incoming: WorldRevealController,
|
|
1037
|
+
options: {
|
|
1038
|
+
outgoing?: WorldRevealController | null;
|
|
1039
|
+
duration?: number;
|
|
1040
|
+
waitingForVrm?: boolean;
|
|
1041
|
+
syncToTeleport?: boolean;
|
|
1042
|
+
initialProgress?: number;
|
|
1043
|
+
} = {},
|
|
1044
|
+
): void {
|
|
1045
|
+
const reveal: WorldRevealState = {
|
|
1046
|
+
controller: incoming,
|
|
1047
|
+
incoming,
|
|
1048
|
+
outgoing: options.outgoing ?? null,
|
|
1049
|
+
progress: THREE.MathUtils.clamp(options.initialProgress ?? 0, 0, 1),
|
|
1050
|
+
duration: options.duration ?? COMPANION_WORLD_REVEAL_DURATION,
|
|
1051
|
+
waitingForVrm: options.waitingForVrm ?? false,
|
|
1052
|
+
syncToTeleport: options.syncToTeleport ?? false,
|
|
1053
|
+
};
|
|
1054
|
+
incoming.mesh.opacity = 1;
|
|
1055
|
+
if (reveal.outgoing) {
|
|
1056
|
+
reveal.outgoing.mesh.opacity = 1;
|
|
1057
|
+
}
|
|
1058
|
+
this.worldReveal = reveal;
|
|
1059
|
+
this.setWorldRevealProgress(incoming, reveal.progress);
|
|
1060
|
+
if (reveal.outgoing) {
|
|
1061
|
+
this.setWorldRevealProgress(reveal.outgoing, reveal.progress);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
private disposeSplatMesh(mesh: SparkSplatMesh | null): void {
|
|
1066
|
+
if (!mesh) return;
|
|
1067
|
+
mesh.parent?.remove(mesh);
|
|
1068
|
+
mesh.dispose();
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
private completeWorldReveal(reveal: WorldRevealState): void {
|
|
1072
|
+
this.setWorldRevealProgress(reveal.incoming, 1);
|
|
1073
|
+
reveal.incoming.mesh.opacity = 1;
|
|
1074
|
+
reveal.incoming.mesh.objectModifier = undefined;
|
|
1075
|
+
this.refreshSplatMesh(reveal.incoming.mesh);
|
|
1076
|
+
if (reveal.outgoing) {
|
|
1077
|
+
reveal.outgoing.mesh.objectModifier = undefined;
|
|
1078
|
+
this.disposeSplatMesh(reveal.outgoing.mesh);
|
|
1079
|
+
}
|
|
1080
|
+
if (this.worldReveal === reveal) {
|
|
1081
|
+
this.worldReveal = null;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
private cancelWorldReveal(): void {
|
|
1086
|
+
if (!this.worldReveal) return;
|
|
1087
|
+
this.completeWorldReveal(this.worldReveal);
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
private startPendingWorldReveal(syncToTeleport: boolean): void {
|
|
1091
|
+
const reveal = this.worldReveal;
|
|
1092
|
+
if (!reveal || !reveal.waitingForVrm) return;
|
|
1093
|
+
reveal.waitingForVrm = false;
|
|
1094
|
+
reveal.syncToTeleport = syncToTeleport;
|
|
1095
|
+
reveal.progress = syncToTeleport ? this.teleportProgress : 0;
|
|
1096
|
+
this.setWorldRevealProgress(reveal.incoming, reveal.progress);
|
|
1097
|
+
if (reveal.outgoing) {
|
|
1098
|
+
this.setWorldRevealProgress(reveal.outgoing, reveal.progress);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
private updateWorldReveal(stableDelta: number): void {
|
|
1103
|
+
const reveal = this.worldReveal;
|
|
1104
|
+
if (!reveal || reveal.waitingForVrm) return;
|
|
1105
|
+
const avatarRevealActive =
|
|
1106
|
+
this.revealStarted && this.teleportProgress < 0.999;
|
|
1107
|
+
|
|
1108
|
+
const nextProgress =
|
|
1109
|
+
reveal.syncToTeleport && avatarRevealActive
|
|
1110
|
+
? this.teleportProgress
|
|
1111
|
+
: Math.min(1, reveal.progress + stableDelta / reveal.duration);
|
|
1112
|
+
const appliedProgress =
|
|
1113
|
+
reveal.syncToTeleport && avatarRevealActive
|
|
1114
|
+
? nextProgress
|
|
1115
|
+
: nextProgress ** COMPANION_WORLD_REVEAL_EASE_EXPONENT;
|
|
1116
|
+
|
|
1117
|
+
reveal.progress = nextProgress;
|
|
1118
|
+
this.setWorldRevealProgress(reveal.incoming, appliedProgress);
|
|
1119
|
+
if (reveal.outgoing) {
|
|
1120
|
+
this.setWorldRevealProgress(reveal.outgoing, appliedProgress);
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
if (nextProgress >= 1) {
|
|
1124
|
+
this.completeWorldReveal(reveal);
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
private updateSparkDepthOfField(camera: THREE.PerspectiveCamera): void {
|
|
1129
|
+
const sparkRenderer = this.sparkRenderer;
|
|
1130
|
+
if (!sparkRenderer) return;
|
|
1131
|
+
if (!this.worldMesh) {
|
|
1132
|
+
sparkRenderer.apertureAngle = 0;
|
|
1133
|
+
return;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
const focalDistance = Math.max(
|
|
1137
|
+
0.5,
|
|
1138
|
+
camera.position.distanceTo(this.pointerParallaxLookAt),
|
|
1139
|
+
);
|
|
1140
|
+
const isCompanionProfile =
|
|
1141
|
+
this.cameraProfile === "companion" ||
|
|
1142
|
+
this.cameraProfile === "companion_close";
|
|
1143
|
+
const closeZoomFactor = isCompanionProfile
|
|
1144
|
+
? THREE.MathUtils.smoothstep(this.companionZoomCurrent, 0.3, 1)
|
|
1145
|
+
: 0;
|
|
1146
|
+
const apertureSize = THREE.MathUtils.lerp(
|
|
1147
|
+
COMPANION_DOF_APERTURE_SIZE,
|
|
1148
|
+
COMPANION_DOF_APERTURE_SIZE * COMPANION_DOF_NEAR_ZOOM_APERTURE_FACTOR,
|
|
1149
|
+
closeZoomFactor,
|
|
1150
|
+
);
|
|
1151
|
+
sparkRenderer.focalDistance = focalDistance;
|
|
1152
|
+
sparkRenderer.apertureAngle =
|
|
1153
|
+
2 * Math.atan((0.5 * apertureSize) / sparkRenderer.focalDistance);
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
private applyCompanionZoom(
|
|
1157
|
+
camera: THREE.PerspectiveCamera,
|
|
1158
|
+
stableDelta: number,
|
|
1159
|
+
): void {
|
|
1160
|
+
const isCompanionProfile =
|
|
1161
|
+
this.cameraProfile === "companion" ||
|
|
1162
|
+
this.cameraProfile === "companion_close";
|
|
1163
|
+
const follow = Math.min(1, stableDelta * 10);
|
|
1164
|
+
const targetZoom = isCompanionProfile ? this.companionZoomTarget : 0;
|
|
1165
|
+
this.companionZoomCurrent = THREE.MathUtils.lerp(
|
|
1166
|
+
this.companionZoomCurrent,
|
|
1167
|
+
targetZoom,
|
|
1168
|
+
follow,
|
|
1169
|
+
);
|
|
1170
|
+
if (this.companionZoomCurrent < 1e-4) return;
|
|
1171
|
+
|
|
1172
|
+
const baseRadius = this.baseCameraPosition.distanceTo(this.lookAtTarget);
|
|
1173
|
+
if (!Number.isFinite(baseRadius) || baseRadius < 1e-4) return;
|
|
1174
|
+
|
|
1175
|
+
const orbitOffset = this.tempCameraOrbitOffset
|
|
1176
|
+
.copy(camera.position)
|
|
1177
|
+
.sub(this.lookAtTarget);
|
|
1178
|
+
if (orbitOffset.lengthSq() < 1e-6) return;
|
|
1179
|
+
|
|
1180
|
+
const spherical = this.tempCameraSpherical.setFromVector3(orbitOffset);
|
|
1181
|
+
const nearRadius = Math.max(
|
|
1182
|
+
COMPANION_ZOOM_MIN_RADIUS,
|
|
1183
|
+
baseRadius * COMPANION_ZOOM_NEAR_FACTOR,
|
|
1184
|
+
);
|
|
1185
|
+
spherical.radius = THREE.MathUtils.lerp(
|
|
1186
|
+
baseRadius,
|
|
1187
|
+
nearRadius,
|
|
1188
|
+
this.companionZoomCurrent,
|
|
1189
|
+
);
|
|
1190
|
+
camera.position
|
|
1191
|
+
.copy(this.lookAtTarget)
|
|
1192
|
+
.add(orbitOffset.setFromSpherical(spherical));
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
private configureAvatarLookTracking(vrm: VRM): void {
|
|
1196
|
+
const target = this.avatarLookTarget;
|
|
1197
|
+
if (target) {
|
|
1198
|
+
target.position.set(0, 1.5, 2);
|
|
1199
|
+
target.updateMatrixWorld(true);
|
|
1200
|
+
}
|
|
1201
|
+
if (vrm.lookAt && target) {
|
|
1202
|
+
vrm.lookAt.autoUpdate = true;
|
|
1203
|
+
vrm.lookAt.target = target;
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
const headBone = vrm.humanoid?.getRawBoneNode("head") ?? null;
|
|
1207
|
+
const neckBone = vrm.humanoid?.getRawBoneNode("neck") ?? null;
|
|
1208
|
+
const spineBone =
|
|
1209
|
+
vrm.humanoid?.getRawBoneNode("upperChest") ??
|
|
1210
|
+
vrm.humanoid?.getRawBoneNode("chest") ??
|
|
1211
|
+
vrm.humanoid?.getRawBoneNode("spine") ??
|
|
1212
|
+
null;
|
|
1213
|
+
|
|
1214
|
+
this.avatarLookRig = {
|
|
1215
|
+
headBone,
|
|
1216
|
+
neckBone,
|
|
1217
|
+
spineBone,
|
|
1218
|
+
};
|
|
1219
|
+
this.headLookTarget.set(0, 0);
|
|
1220
|
+
this.headLookCurrent.set(0, 0);
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
private updateAvatarLookTarget(
|
|
1224
|
+
camera: THREE.PerspectiveCamera,
|
|
1225
|
+
stableDelta: number,
|
|
1226
|
+
): void {
|
|
1227
|
+
const target = this.avatarLookTarget;
|
|
1228
|
+
if (!target) return;
|
|
1229
|
+
this.tempAvatarLookTarget.copy(camera.position);
|
|
1230
|
+
const follow = Math.min(1, stableDelta * 24);
|
|
1231
|
+
target.position.lerp(this.tempAvatarLookTarget, follow);
|
|
1232
|
+
target.updateMatrixWorld(true);
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
private refreshAvatarEyeTracking(): void {
|
|
1236
|
+
const vrm = this.vrm;
|
|
1237
|
+
if (!vrm?.lookAt || !this.avatarLookTarget) return;
|
|
1238
|
+
vrm.lookAt.update(0);
|
|
1239
|
+
vrm.expressionManager?.update();
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
private applyAvatarHeadTracking(
|
|
1243
|
+
camera: THREE.PerspectiveCamera,
|
|
1244
|
+
stableDelta: number,
|
|
1245
|
+
): void {
|
|
1246
|
+
const vrm = this.vrm;
|
|
1247
|
+
const { headBone, neckBone, spineBone } = this.avatarLookRig;
|
|
1248
|
+
if (!vrm || !headBone) return;
|
|
1249
|
+
const headParent = headBone.parent;
|
|
1250
|
+
if (!headParent || typeof headParent.worldToLocal !== "function") return;
|
|
1251
|
+
if (
|
|
1252
|
+
typeof THREE.Euler !== "function" ||
|
|
1253
|
+
typeof THREE.Quaternion !== "function" ||
|
|
1254
|
+
typeof headBone.quaternion.clone !== "function"
|
|
1255
|
+
) {
|
|
1256
|
+
return;
|
|
1257
|
+
}
|
|
1258
|
+
const lookAtState = vrm.lookAt as
|
|
1259
|
+
| ({ _yaw?: number; _pitch?: number } & object)
|
|
1260
|
+
| null
|
|
1261
|
+
| undefined;
|
|
1262
|
+
const lookAtYawDegrees = lookAtState?._yaw;
|
|
1263
|
+
const lookAtPitchDegrees = lookAtState?._pitch;
|
|
1264
|
+
|
|
1265
|
+
if (
|
|
1266
|
+
Number.isFinite(lookAtYawDegrees) &&
|
|
1267
|
+
Number.isFinite(lookAtPitchDegrees)
|
|
1268
|
+
) {
|
|
1269
|
+
this.headLookTarget.set(
|
|
1270
|
+
THREE.MathUtils.clamp(
|
|
1271
|
+
THREE.MathUtils.degToRad(lookAtYawDegrees || 0),
|
|
1272
|
+
-0.55,
|
|
1273
|
+
0.55,
|
|
1274
|
+
),
|
|
1275
|
+
THREE.MathUtils.clamp(
|
|
1276
|
+
THREE.MathUtils.degToRad(lookAtPitchDegrees || 0),
|
|
1277
|
+
-0.3,
|
|
1278
|
+
0.24,
|
|
1279
|
+
),
|
|
1280
|
+
);
|
|
1281
|
+
} else {
|
|
1282
|
+
headBone.getWorldPosition(this.tempAvatarHeadWorld);
|
|
1283
|
+
this.tempAvatarLocalTarget.copy(camera.position);
|
|
1284
|
+
this.tempAvatarLocalTarget.y -= 0.04;
|
|
1285
|
+
headParent.worldToLocal(this.tempAvatarLocalTarget);
|
|
1286
|
+
headParent.worldToLocal(
|
|
1287
|
+
this.tempAvatarLocalAnchor.copy(this.tempAvatarHeadWorld),
|
|
1288
|
+
);
|
|
1289
|
+
this.tempAvatarLocalTarget.sub(this.tempAvatarLocalAnchor);
|
|
1290
|
+
|
|
1291
|
+
const planarDistance = Math.max(
|
|
1292
|
+
1e-4,
|
|
1293
|
+
Math.hypot(this.tempAvatarLocalTarget.x, this.tempAvatarLocalTarget.z),
|
|
1294
|
+
);
|
|
1295
|
+
this.headLookTarget.set(
|
|
1296
|
+
THREE.MathUtils.clamp(
|
|
1297
|
+
Math.atan2(
|
|
1298
|
+
-this.tempAvatarLocalTarget.x,
|
|
1299
|
+
Math.max(-this.tempAvatarLocalTarget.z, 1e-4),
|
|
1300
|
+
),
|
|
1301
|
+
-0.55,
|
|
1302
|
+
0.55,
|
|
1303
|
+
),
|
|
1304
|
+
THREE.MathUtils.clamp(
|
|
1305
|
+
Math.atan2(this.tempAvatarLocalTarget.y, planarDistance),
|
|
1306
|
+
-0.3,
|
|
1307
|
+
0.24,
|
|
1308
|
+
),
|
|
1309
|
+
);
|
|
1310
|
+
}
|
|
1311
|
+
this.headLookCurrent.lerp(
|
|
1312
|
+
this.headLookTarget,
|
|
1313
|
+
Math.min(1, stableDelta * 4.5),
|
|
1314
|
+
);
|
|
1315
|
+
|
|
1316
|
+
const applyTrackedBone = (
|
|
1317
|
+
bone: THREE.Object3D | null,
|
|
1318
|
+
yawWeight: number,
|
|
1319
|
+
pitchWeight: number,
|
|
1320
|
+
) => {
|
|
1321
|
+
if (
|
|
1322
|
+
!bone ||
|
|
1323
|
+
!bone.quaternion ||
|
|
1324
|
+
typeof bone.quaternion.clone !== "function"
|
|
1325
|
+
) {
|
|
1326
|
+
return;
|
|
1327
|
+
}
|
|
1328
|
+
const offsetEuler = new THREE.Euler(
|
|
1329
|
+
this.headLookCurrent.y * pitchWeight,
|
|
1330
|
+
this.headLookCurrent.x * yawWeight,
|
|
1331
|
+
0,
|
|
1332
|
+
"YXZ",
|
|
1333
|
+
);
|
|
1334
|
+
const offsetQuaternion = new THREE.Quaternion().setFromEuler(offsetEuler);
|
|
1335
|
+
const animatedPose = bone.quaternion.clone();
|
|
1336
|
+
bone.quaternion.copy(animatedPose).multiply(offsetQuaternion);
|
|
1337
|
+
};
|
|
1338
|
+
|
|
1339
|
+
applyTrackedBone(spineBone, 0.12, 0.06);
|
|
1340
|
+
applyTrackedBone(neckBone, 0.3, 0.18);
|
|
1341
|
+
applyTrackedBone(headBone, 0.52, 0.28);
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
private toDebugVector3(vector: THREE.Vector3 | null): DebugVector3 | null {
|
|
1345
|
+
if (!vector) return null;
|
|
1346
|
+
return {
|
|
1347
|
+
x: Number(vector.x.toFixed(4)),
|
|
1348
|
+
y: Number(vector.y.toFixed(4)),
|
|
1349
|
+
z: Number(vector.z.toFixed(4)),
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
private toDebugBounds(object: THREE.Object3D | null): DebugBounds | null {
|
|
1354
|
+
if (!object) return null;
|
|
1355
|
+
const bounds = new THREE.Box3().setFromObject(object);
|
|
1356
|
+
if (bounds.isEmpty()) return null;
|
|
1357
|
+
return this.toDebugBoundsFromBox(bounds);
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
private toDebugBoundsFromBox(bounds: THREE.Box3 | null): DebugBounds | null {
|
|
1361
|
+
if (!bounds || bounds.isEmpty()) return null;
|
|
1362
|
+
const center = bounds.getCenter(new THREE.Vector3());
|
|
1363
|
+
const size = bounds.getSize(new THREE.Vector3());
|
|
1364
|
+
const min = this.toDebugVector3(bounds.min.clone());
|
|
1365
|
+
const max = this.toDebugVector3(bounds.max.clone());
|
|
1366
|
+
const centerVector = this.toDebugVector3(center);
|
|
1367
|
+
const sizeVector = this.toDebugVector3(size);
|
|
1368
|
+
if (!min || !max || !centerVector || !sizeVector) return null;
|
|
1369
|
+
return {
|
|
1370
|
+
min,
|
|
1371
|
+
max,
|
|
1372
|
+
center: centerVector,
|
|
1373
|
+
size: sizeVector,
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
getDebugInfo(): VrmEngineDebugInfo {
|
|
1378
|
+
this.scene?.updateMatrixWorld(true);
|
|
1379
|
+
this.vrm?.scene.updateMatrixWorld(true);
|
|
1380
|
+
this.worldMesh?.updateMatrixWorld(true);
|
|
1381
|
+
|
|
1382
|
+
const cameraRotation = this.camera
|
|
1383
|
+
? new THREE.Vector3(
|
|
1384
|
+
this.camera.rotation.x,
|
|
1385
|
+
this.camera.rotation.y,
|
|
1386
|
+
this.camera.rotation.z,
|
|
1387
|
+
)
|
|
1388
|
+
: null;
|
|
1389
|
+
const lookAtTarget =
|
|
1390
|
+
this.toDebugVector3(this.lookAtTarget) ??
|
|
1391
|
+
({ x: 0, y: 0, z: 0 } satisfies DebugVector3);
|
|
1392
|
+
|
|
1393
|
+
return {
|
|
1394
|
+
initialized: this.initialized,
|
|
1395
|
+
rendererBackend: this.rendererBackend,
|
|
1396
|
+
cameraProfile: this.cameraProfile,
|
|
1397
|
+
worldUrl: this.worldUrl,
|
|
1398
|
+
sceneChildren:
|
|
1399
|
+
this.scene?.children.map((child) => child.name || child.type) ?? [],
|
|
1400
|
+
camera: {
|
|
1401
|
+
parentName: this.camera?.parent?.name ?? null,
|
|
1402
|
+
position: this.toDebugVector3(this.camera?.position ?? null),
|
|
1403
|
+
rotation: this.toDebugVector3(cameraRotation),
|
|
1404
|
+
fov: this.camera?.fov ?? null,
|
|
1405
|
+
lookAtTarget,
|
|
1406
|
+
},
|
|
1407
|
+
avatar: {
|
|
1408
|
+
loaded: this.vrm !== null,
|
|
1409
|
+
ready: this.vrmReady,
|
|
1410
|
+
parentName: this.vrm?.scene.parent?.name ?? null,
|
|
1411
|
+
position: this.toDebugVector3(this.vrm?.scene.position ?? null),
|
|
1412
|
+
scale: this.toDebugVector3(this.vrm?.scene.scale ?? null),
|
|
1413
|
+
bounds: this.toDebugBounds(this.vrm?.scene ?? null),
|
|
1414
|
+
},
|
|
1415
|
+
world: {
|
|
1416
|
+
loaded: this.worldMesh !== null,
|
|
1417
|
+
parentName: this.worldMesh?.parent?.name ?? null,
|
|
1418
|
+
position: this.toDebugVector3(this.worldMesh?.position ?? null),
|
|
1419
|
+
scale: this.toDebugVector3(this.worldMesh?.scale ?? null),
|
|
1420
|
+
bounds: this.toDebugBounds(this.worldMesh ?? null),
|
|
1421
|
+
rawBounds: this.worldMesh
|
|
1422
|
+
? this.toDebugBoundsFromBox(this.worldMesh.getBoundingBox(true))
|
|
1423
|
+
: null,
|
|
1424
|
+
},
|
|
1425
|
+
spark: {
|
|
1426
|
+
attached: this.sparkRenderer !== null,
|
|
1427
|
+
parentName: this.sparkRenderer?.parent?.name ?? null,
|
|
1428
|
+
renderOrder: this.sparkRenderer?.renderOrder ?? null,
|
|
1429
|
+
},
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
setDebugAvatarVisible(visible: boolean): void {
|
|
1434
|
+
if (!this.vrm) return;
|
|
1435
|
+
this.vrm.scene.visible = visible;
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
setDebugWorldPosition(x: number, y: number, z: number): void {
|
|
1439
|
+
if (!this.worldMesh) return;
|
|
1440
|
+
this.worldMesh.position.set(x, y, z);
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
setDebugWorldQuaternion(x: number, y: number, z: number, w: number): void {
|
|
1444
|
+
if (!this.worldMesh) return;
|
|
1445
|
+
this.worldMesh.quaternion.set(x, y, z, w);
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
setDebugCamera(position: THREE.Vector3, target: THREE.Vector3): void {
|
|
1449
|
+
if (!this.camera) return;
|
|
1450
|
+
this.isCameraTransitioning = false;
|
|
1451
|
+
this.camera.position.copy(position);
|
|
1452
|
+
this.baseCameraPosition.copy(position);
|
|
1453
|
+
this.lookAtTarget.copy(target);
|
|
1454
|
+
this.controls?.target.copy(target);
|
|
1455
|
+
this.controls?.update();
|
|
1456
|
+
this.camera.lookAt(target);
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
private startCameraTransition(
|
|
1460
|
+
startPos: THREE.Vector3,
|
|
1461
|
+
startLookAt: THREE.Vector3,
|
|
1462
|
+
startFov: number,
|
|
1463
|
+
targetPos: THREE.Vector3,
|
|
1464
|
+
targetLookAt: THREE.Vector3,
|
|
1465
|
+
targetFov: number,
|
|
1466
|
+
durationSeconds: number,
|
|
1467
|
+
): void {
|
|
1468
|
+
if (!this.camera) return;
|
|
1469
|
+
|
|
1470
|
+
this.transitionStartFov = startFov;
|
|
1471
|
+
this.transitionTargetFov = targetFov;
|
|
1472
|
+
this.transitionStartPos.copy(startPos);
|
|
1473
|
+
this.transitionTargetPos.copy(targetPos);
|
|
1474
|
+
this.transitionStartLookAt.copy(startLookAt);
|
|
1475
|
+
this.transitionTargetLookAt.copy(targetLookAt);
|
|
1476
|
+
this.transitionDuration = Math.max(0.01, durationSeconds);
|
|
1477
|
+
|
|
1478
|
+
this.camera.fov = startFov;
|
|
1479
|
+
this.camera.position.copy(startPos);
|
|
1480
|
+
this.camera.updateProjectionMatrix();
|
|
1481
|
+
this.baseCameraPosition.copy(startPos);
|
|
1482
|
+
this.lookAtTarget.copy(startLookAt);
|
|
1483
|
+
if (this.controls) {
|
|
1484
|
+
this.controls.target.copy(startLookAt);
|
|
1485
|
+
this.controls.update();
|
|
1486
|
+
}
|
|
1487
|
+
this.camera.lookAt(startLookAt);
|
|
1488
|
+
this.isCameraTransitioning = true;
|
|
1489
|
+
this.transitionProgress = 0;
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
private transitionCameraToFramedAvatar(
|
|
1493
|
+
vrm: VRM,
|
|
1494
|
+
durationSeconds: number,
|
|
1495
|
+
): void {
|
|
1496
|
+
if (!this.camera) return;
|
|
1497
|
+
|
|
1498
|
+
const startPos = new THREE.Vector3().copy(this.camera.position);
|
|
1499
|
+
const startLookAt = new THREE.Vector3().copy(this.lookAtTarget);
|
|
1500
|
+
const startFov = this.camera.fov;
|
|
1501
|
+
const targetLookAt = new THREE.Vector3();
|
|
1502
|
+
const targetPos = new THREE.Vector3();
|
|
1503
|
+
|
|
1504
|
+
this.cameraManager.centerAndFrame(
|
|
1505
|
+
vrm,
|
|
1506
|
+
this.camera,
|
|
1507
|
+
this.controls,
|
|
1508
|
+
this.cameraProfile,
|
|
1509
|
+
targetLookAt,
|
|
1510
|
+
targetPos,
|
|
1511
|
+
(c) => this.cameraManager.applyInteractionMode(c, this.interactionMode),
|
|
1512
|
+
);
|
|
1513
|
+
|
|
1514
|
+
this.startCameraTransition(
|
|
1515
|
+
startPos,
|
|
1516
|
+
startLookAt,
|
|
1517
|
+
startFov,
|
|
1518
|
+
targetPos,
|
|
1519
|
+
targetLookAt,
|
|
1520
|
+
this.camera.fov,
|
|
1521
|
+
durationSeconds,
|
|
1522
|
+
);
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
whenReady(): Promise<void> {
|
|
1526
|
+
return this.readyPromise;
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
private resetReadyPromise(): void {
|
|
1530
|
+
this.readyPromise = new Promise<void>((resolve, reject) => {
|
|
1531
|
+
this.resolveReady = resolve;
|
|
1532
|
+
this.rejectReady = reject;
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
private settleReady(error?: unknown): void {
|
|
1537
|
+
if (error) {
|
|
1538
|
+
this.rejectReady?.(error);
|
|
1539
|
+
} else {
|
|
1540
|
+
this.resolveReady?.();
|
|
1541
|
+
}
|
|
1542
|
+
this.resolveReady = null;
|
|
1543
|
+
this.rejectReady = null;
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
setup(
|
|
1547
|
+
canvas: HTMLCanvasElement,
|
|
1548
|
+
onUpdate: UpdateCallback,
|
|
1549
|
+
options?: {
|
|
1550
|
+
rendererPreference?: RendererPreference;
|
|
1551
|
+
sparkOptimized?: boolean;
|
|
1552
|
+
},
|
|
1553
|
+
): void {
|
|
1554
|
+
if (this.initialized && this.renderer?.domElement === canvas) {
|
|
1555
|
+
this.onUpdate = onUpdate;
|
|
1556
|
+
return;
|
|
1557
|
+
}
|
|
1558
|
+
if (this.initialized) this.dispose();
|
|
1559
|
+
this.onUpdate = onUpdate;
|
|
1560
|
+
this.loadingAborted = false;
|
|
1561
|
+
this.rendererPreference = options?.rendererPreference ?? "auto";
|
|
1562
|
+
this.resetReadyPromise();
|
|
1563
|
+
// Async renderer creation: tries WebGPU, falls back to WebGL.
|
|
1564
|
+
// setup() remains synchronous for callers; the loop starts after init resolves.
|
|
1565
|
+
void (async () => {
|
|
1566
|
+
try {
|
|
1567
|
+
const { backend, renderer } = await createRenderer(
|
|
1568
|
+
canvas,
|
|
1569
|
+
this.rendererPreference,
|
|
1570
|
+
options?.sparkOptimized ?? false,
|
|
1571
|
+
);
|
|
1572
|
+
const releaseKnownWebGpuWarningFilter =
|
|
1573
|
+
backend === "webgpu" ? installKnownVrmWebGpuWarningFilter() : null;
|
|
1574
|
+
// Guard: if dispose() was called while we were awaiting, abort.
|
|
1575
|
+
if (this.loadingAborted) {
|
|
1576
|
+
releaseKnownWebGpuWarningFilter?.();
|
|
1577
|
+
renderer.dispose();
|
|
1578
|
+
this.settleReady();
|
|
1579
|
+
return;
|
|
1580
|
+
}
|
|
1581
|
+
this.releaseKnownWebGpuWarningFilter = releaseKnownWebGpuWarningFilter;
|
|
1582
|
+
renderer.setPixelRatio(
|
|
1583
|
+
getRendererPixelRatio(options?.sparkOptimized ?? false),
|
|
1584
|
+
);
|
|
1585
|
+
renderer.setClearColor(0x000000, 0);
|
|
1586
|
+
if (backend === "webgl") {
|
|
1587
|
+
const webglRenderer = renderer as THREE.WebGLRenderer;
|
|
1588
|
+
webglRenderer.shadowMap.enabled = true;
|
|
1589
|
+
webglRenderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
|
1590
|
+
webglRenderer.toneMapping = THREE.NoToneMapping;
|
|
1591
|
+
webglRenderer.toneMappingExposure = 1.0;
|
|
1592
|
+
webglRenderer.outputColorSpace = THREE.SRGBColorSpace;
|
|
1593
|
+
}
|
|
1594
|
+
this.renderer = renderer;
|
|
1595
|
+
this.rendererBackend = backend;
|
|
1596
|
+
const scene = new THREE.Scene();
|
|
1597
|
+
this.scene = scene;
|
|
1598
|
+
const avatarRoot = new THREE.Group();
|
|
1599
|
+
avatarRoot.name = "AvatarRoot";
|
|
1600
|
+
scene.add(avatarRoot);
|
|
1601
|
+
this.avatarRoot = avatarRoot;
|
|
1602
|
+
const avatarLookTarget = new THREE.Group();
|
|
1603
|
+
avatarLookTarget.name = "AvatarLookTarget";
|
|
1604
|
+
scene.add(avatarLookTarget);
|
|
1605
|
+
this.avatarLookTarget = avatarLookTarget;
|
|
1606
|
+
const cameraRig = new THREE.Group();
|
|
1607
|
+
cameraRig.name = "AvatarCameraRig";
|
|
1608
|
+
scene.add(cameraRig);
|
|
1609
|
+
const camera = new THREE.PerspectiveCamera(30, 1, 0.1, 20);
|
|
1610
|
+
camera.position.set(0, 1.2, 5.0);
|
|
1611
|
+
cameraRig.add(camera);
|
|
1612
|
+
this.camera = camera;
|
|
1613
|
+
const controls = new OrbitControls(camera, renderer.domElement);
|
|
1614
|
+
controls.enableDamping = false;
|
|
1615
|
+
controls.target.copy(this.lookAtTarget);
|
|
1616
|
+
controls.addEventListener("start", this.handleControlStart);
|
|
1617
|
+
controls.addEventListener("end", this.handleControlEnd);
|
|
1618
|
+
this.cameraManager.applyInteractionMode(controls, this.interactionMode);
|
|
1619
|
+
controls.update();
|
|
1620
|
+
this.controls = controls;
|
|
1621
|
+
this.setInteractionEnabled(this.interactionEnabled);
|
|
1622
|
+
const ambient = new THREE.AmbientLight(0xffffff, 0.8);
|
|
1623
|
+
scene.add(ambient);
|
|
1624
|
+
const keyLight = new THREE.DirectionalLight(0xffffff, 1.2);
|
|
1625
|
+
keyLight.position.set(1, 1, 1).normalize();
|
|
1626
|
+
keyLight.castShadow = true;
|
|
1627
|
+
keyLight.shadow.mapSize.setScalar(1024);
|
|
1628
|
+
scene.add(keyLight);
|
|
1629
|
+
const fillLight = new THREE.DirectionalLight(0xffffff, 0.4);
|
|
1630
|
+
fillLight.position.set(-1, 0.5, -1).normalize();
|
|
1631
|
+
scene.add(fillLight);
|
|
1632
|
+
this.resize(canvas.clientWidth, canvas.clientHeight);
|
|
1633
|
+
this.initialized = true;
|
|
1634
|
+
this.resumeLoop();
|
|
1635
|
+
this.settleReady();
|
|
1636
|
+
} catch (error) {
|
|
1637
|
+
this.initialized = false;
|
|
1638
|
+
this.releaseKnownWebGpuWarningFilter?.();
|
|
1639
|
+
this.releaseKnownWebGpuWarningFilter = null;
|
|
1640
|
+
this.renderer = null;
|
|
1641
|
+
this.rendererBackend = "webgl";
|
|
1642
|
+
this.scene = null;
|
|
1643
|
+
this.camera = null;
|
|
1644
|
+
this.controls = null;
|
|
1645
|
+
console.error("[VrmEngine] Failed to initialize renderer:", error);
|
|
1646
|
+
this.settleReady(error);
|
|
1647
|
+
}
|
|
1648
|
+
})();
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
isInitialized(): boolean {
|
|
1652
|
+
return this.initialized && this.renderer !== null;
|
|
1653
|
+
}
|
|
1654
|
+
dispose(): void {
|
|
1655
|
+
this.loadingAborted = true;
|
|
1656
|
+
this.initialized = false;
|
|
1657
|
+
this.settleReady();
|
|
1658
|
+
this.releaseKnownWebGpuWarningFilter?.();
|
|
1659
|
+
this.releaseKnownWebGpuWarningFilter = null;
|
|
1660
|
+
if (this.animationFrameId !== null) {
|
|
1661
|
+
cancelAnimationFrame(this.animationFrameId);
|
|
1662
|
+
this.animationFrameId = null;
|
|
1663
|
+
}
|
|
1664
|
+
if (this.vrm?.scene.parent) {
|
|
1665
|
+
this.vrm.scene.parent.remove(this.vrm.scene);
|
|
1666
|
+
VRMUtils.deepDispose(this.vrm.scene);
|
|
1667
|
+
}
|
|
1668
|
+
if (this.controls) {
|
|
1669
|
+
this.controls.removeEventListener("start", this.handleControlStart);
|
|
1670
|
+
this.controls.removeEventListener("end", this.handleControlEnd);
|
|
1671
|
+
this.controls.dispose();
|
|
1672
|
+
this.controls = null;
|
|
1673
|
+
}
|
|
1674
|
+
this.vrm = null;
|
|
1675
|
+
this.vrmReady = false;
|
|
1676
|
+
this.vrmName = null;
|
|
1677
|
+
this.lastLoadError = null;
|
|
1678
|
+
this.mixer = null;
|
|
1679
|
+
this.idleAction = null;
|
|
1680
|
+
this.idleLoadPromise = null;
|
|
1681
|
+
this.clearPendingEmoteCompletion();
|
|
1682
|
+
this.emoteAction = null;
|
|
1683
|
+
this.emoteClipCache.clear();
|
|
1684
|
+
this.teleportProgress = 1.0;
|
|
1685
|
+
this.cleanupTeleportDissolve();
|
|
1686
|
+
this.cleanupTeleportSparkles();
|
|
1687
|
+
this.disposeWorld();
|
|
1688
|
+
this.avatarLookTarget?.parent?.remove(this.avatarLookTarget);
|
|
1689
|
+
this.avatarLookTarget = null;
|
|
1690
|
+
this.avatarLookRig = {
|
|
1691
|
+
headBone: null,
|
|
1692
|
+
neckBone: null,
|
|
1693
|
+
spineBone: null,
|
|
1694
|
+
};
|
|
1695
|
+
this.headLookTarget.set(0, 0);
|
|
1696
|
+
this.headLookCurrent.set(0, 0);
|
|
1697
|
+
if (this.sparkRenderer) {
|
|
1698
|
+
this.sparkRenderer.apertureAngle = 0;
|
|
1699
|
+
this.sparkRenderer.removeFromParent();
|
|
1700
|
+
this.sparkRenderer = null;
|
|
1701
|
+
}
|
|
1702
|
+
if (this.renderer) {
|
|
1703
|
+
this.renderer.dispose();
|
|
1704
|
+
}
|
|
1705
|
+
this.renderer = null;
|
|
1706
|
+
this.rendererBackend = "webgl";
|
|
1707
|
+
this.scene = null;
|
|
1708
|
+
this.avatarRoot = null;
|
|
1709
|
+
this.camera = null;
|
|
1710
|
+
this.onUpdate = null;
|
|
1711
|
+
this.paused = false;
|
|
1712
|
+
}
|
|
1713
|
+
setPaused(paused: boolean): void {
|
|
1714
|
+
if (this.paused === paused) return;
|
|
1715
|
+
this.paused = paused;
|
|
1716
|
+
if (paused) {
|
|
1717
|
+
this.stopLoop();
|
|
1718
|
+
return;
|
|
1719
|
+
}
|
|
1720
|
+
this.resumeLoop();
|
|
1721
|
+
}
|
|
1722
|
+
setInteractionEnabled(enabled: boolean): void {
|
|
1723
|
+
this.interactionEnabled = enabled;
|
|
1724
|
+
if (this.controls) {
|
|
1725
|
+
this.controls.enabled = enabled;
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
setInteractionMode(mode: InteractionMode): void {
|
|
1729
|
+
this.interactionMode = mode;
|
|
1730
|
+
if (this.controls) {
|
|
1731
|
+
this.cameraManager.applyInteractionMode(this.controls, mode);
|
|
1732
|
+
this.controls.update();
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
setCameraProfile(profile: CameraProfile): void {
|
|
1736
|
+
if (this.cameraProfile === profile) return;
|
|
1737
|
+
|
|
1738
|
+
if (this.camera) {
|
|
1739
|
+
const startFov = this.camera.fov;
|
|
1740
|
+
const startPos = new THREE.Vector3().copy(this.camera.position);
|
|
1741
|
+
const startLookAt = new THREE.Vector3().copy(this.lookAtTarget);
|
|
1742
|
+
|
|
1743
|
+
this.cameraProfile = profile;
|
|
1744
|
+
|
|
1745
|
+
const targetLookAt = new THREE.Vector3().copy(this.lookAtTarget);
|
|
1746
|
+
const targetPos = new THREE.Vector3().copy(this.camera.position);
|
|
1747
|
+
|
|
1748
|
+
if (this.vrm) {
|
|
1749
|
+
this.cameraManager.centerAndFrame(
|
|
1750
|
+
this.vrm,
|
|
1751
|
+
this.camera,
|
|
1752
|
+
this.controls,
|
|
1753
|
+
this.cameraProfile,
|
|
1754
|
+
targetLookAt,
|
|
1755
|
+
targetPos,
|
|
1756
|
+
(c) =>
|
|
1757
|
+
this.cameraManager.applyInteractionMode(c, this.interactionMode),
|
|
1758
|
+
);
|
|
1759
|
+
} else {
|
|
1760
|
+
this.cameraManager.applyCameraProfileToCamera(
|
|
1761
|
+
this.camera,
|
|
1762
|
+
this.controls,
|
|
1763
|
+
this.cameraProfile,
|
|
1764
|
+
);
|
|
1765
|
+
targetPos.copy(this.camera.position);
|
|
1766
|
+
if (this.controls) {
|
|
1767
|
+
targetLookAt.copy(this.controls.target);
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
this.startCameraTransition(
|
|
1772
|
+
startPos,
|
|
1773
|
+
startLookAt,
|
|
1774
|
+
startFov,
|
|
1775
|
+
targetPos,
|
|
1776
|
+
targetLookAt,
|
|
1777
|
+
this.camera.fov,
|
|
1778
|
+
CAMERA_PROFILE_TRANSITION_DURATION_SECONDS,
|
|
1779
|
+
);
|
|
1780
|
+
} else {
|
|
1781
|
+
this.cameraProfile = profile;
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
resize(width: number, height: number): void {
|
|
1785
|
+
if (!this.renderer || !this.camera) return;
|
|
1786
|
+
if (width <= 0 || height <= 0) return;
|
|
1787
|
+
const aspect = width / height;
|
|
1788
|
+
if (!Number.isFinite(aspect) || aspect <= 0) return;
|
|
1789
|
+
this.renderer.setSize(width, height, false);
|
|
1790
|
+
this.camera.aspect = aspect;
|
|
1791
|
+
this.camera.updateProjectionMatrix();
|
|
1792
|
+
}
|
|
1793
|
+
getState(): VrmEngineState {
|
|
1794
|
+
const idlePlaying = this.idleAction?.isRunning() ?? false;
|
|
1795
|
+
return {
|
|
1796
|
+
vrmLoaded: this.vrm !== null && this.vrmReady,
|
|
1797
|
+
vrmName: this.vrmName,
|
|
1798
|
+
loadError: this.lastLoadError,
|
|
1799
|
+
idlePlaying,
|
|
1800
|
+
idleTime: this.idleAction?.time ?? 0,
|
|
1801
|
+
idleTracks: this.idleAction?.getClip()?.tracks.length ?? 0,
|
|
1802
|
+
revealStarted: this.revealStarted,
|
|
1803
|
+
};
|
|
1804
|
+
}
|
|
1805
|
+
setMouthOpen(value: number): void {
|
|
1806
|
+
this.mouthValue = Math.max(0, Math.min(1, value));
|
|
1807
|
+
}
|
|
1808
|
+
setSpeaking(speaking: boolean): void {
|
|
1809
|
+
if (speaking && !this.speaking) {
|
|
1810
|
+
this.speakingStartTime = this.elapsedTime;
|
|
1811
|
+
}
|
|
1812
|
+
this.speaking = speaking;
|
|
1813
|
+
}
|
|
1814
|
+
setCameraAnimation(config: Partial<CameraAnimationConfig>): void {
|
|
1815
|
+
this.cameraAnimation = { ...this.cameraAnimation, ...config };
|
|
1816
|
+
}
|
|
1817
|
+
setPointerParallaxEnabled(enabled: boolean): void {
|
|
1818
|
+
this.pointerParallaxEnabled = enabled;
|
|
1819
|
+
if (!enabled) {
|
|
1820
|
+
this.pointerParallaxTarget.set(0, 0);
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
setPointerParallaxTarget(x: number, y: number): void {
|
|
1824
|
+
this.pointerParallaxTarget.set(
|
|
1825
|
+
THREE.MathUtils.clamp(x, -1, 1),
|
|
1826
|
+
THREE.MathUtils.clamp(y, -1, 1),
|
|
1827
|
+
);
|
|
1828
|
+
}
|
|
1829
|
+
resetPointerParallax(): void {
|
|
1830
|
+
this.pointerParallaxTarget.set(0, 0);
|
|
1831
|
+
}
|
|
1832
|
+
setDragOrbitTarget(yaw: number, pitch: number): void {
|
|
1833
|
+
this.dragOrbitTarget.set(
|
|
1834
|
+
THREE.MathUtils.clamp(yaw, -0.6, 0.6),
|
|
1835
|
+
THREE.MathUtils.clamp(pitch, -0.35, 0.35),
|
|
1836
|
+
);
|
|
1837
|
+
}
|
|
1838
|
+
resetDragOrbit(): void {
|
|
1839
|
+
this.dragOrbitTarget.set(0, 0);
|
|
1840
|
+
}
|
|
1841
|
+
setCompanionZoomNormalized(value: number): void {
|
|
1842
|
+
this.companionZoomTarget = THREE.MathUtils.clamp(value, 0, 1);
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
async setWorldUrl(url: string | null): Promise<void> {
|
|
1846
|
+
await this.whenReady();
|
|
1847
|
+
if (!this.scene) return;
|
|
1848
|
+
const normalizedUrl = url?.trim() ? url : null;
|
|
1849
|
+
if (this.worldUrl === normalizedUrl && this.worldMesh) return;
|
|
1850
|
+
|
|
1851
|
+
const requestId = ++this.worldLoadRequestId;
|
|
1852
|
+
this.worldUrl = normalizedUrl;
|
|
1853
|
+
this.cancelWorldReveal();
|
|
1854
|
+
const outgoingWorld = this.worldMesh;
|
|
1855
|
+
if (!normalizedUrl) {
|
|
1856
|
+
this.disposeWorld();
|
|
1857
|
+
return;
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
await this.ensureSparkRenderer();
|
|
1861
|
+
const spark = await this.loadSparkModule();
|
|
1862
|
+
const { SplatMesh } = spark;
|
|
1863
|
+
let worldAnchor = new THREE.Vector3(0, 0, 0);
|
|
1864
|
+
let worldRevealRadius = 1;
|
|
1865
|
+
const splat = new SplatMesh({
|
|
1866
|
+
url: normalizedUrl,
|
|
1867
|
+
constructSplats: (packedSplats) => {
|
|
1868
|
+
worldAnchor = getRobustPackedSplatAnchor(packedSplats);
|
|
1869
|
+
worldRevealRadius = getRobustPackedSplatRadialExtent(
|
|
1870
|
+
packedSplats,
|
|
1871
|
+
worldAnchor,
|
|
1872
|
+
);
|
|
1873
|
+
},
|
|
1874
|
+
});
|
|
1875
|
+
splat.frustumCulled = false;
|
|
1876
|
+
splat.quaternion.identity();
|
|
1877
|
+
splat.position.set(0, 0, 0);
|
|
1878
|
+
splat.scale.setScalar(COMPANION_WORLD_SCALE);
|
|
1879
|
+
this.scene.add(splat);
|
|
1880
|
+
|
|
1881
|
+
await splat.initialized;
|
|
1882
|
+
|
|
1883
|
+
if (
|
|
1884
|
+
this.loadingAborted ||
|
|
1885
|
+
!this.scene ||
|
|
1886
|
+
requestId !== this.worldLoadRequestId
|
|
1887
|
+
) {
|
|
1888
|
+
splat.parent?.remove(splat);
|
|
1889
|
+
splat.dispose();
|
|
1890
|
+
return;
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
const worldCenterBottom =
|
|
1894
|
+
worldAnchor.lengthSq() > 0 ? worldAnchor : getRobustSplatAnchor(splat);
|
|
1895
|
+
const worldFloorOffsetY = getCompanionWorldFloorOffsetY(normalizedUrl);
|
|
1896
|
+
splat.position.set(
|
|
1897
|
+
-worldCenterBottom.x * COMPANION_WORLD_SCALE,
|
|
1898
|
+
-worldCenterBottom.y * COMPANION_WORLD_SCALE + worldFloorOffsetY,
|
|
1899
|
+
-worldCenterBottom.z * COMPANION_WORLD_SCALE,
|
|
1900
|
+
);
|
|
1901
|
+
const syncToTeleport = this.revealStarted && this.teleportProgress < 0.999;
|
|
1902
|
+
const waitingForVrm = !outgoingWorld && !this.vrmReady;
|
|
1903
|
+
const incomingRevealRadius = Math.max(
|
|
1904
|
+
worldRevealRadius * COMPANION_WORLD_SCALE,
|
|
1905
|
+
getRobustSplatRadialExtent(splat, worldCenterBottom) *
|
|
1906
|
+
COMPANION_WORLD_SCALE,
|
|
1907
|
+
);
|
|
1908
|
+
let outgoingAnchor: THREE.Vector3 | null = null;
|
|
1909
|
+
let sharedRevealRadius = incomingRevealRadius;
|
|
1910
|
+
if (outgoingWorld && !waitingForVrm) {
|
|
1911
|
+
outgoingAnchor = getRobustSplatAnchor(outgoingWorld);
|
|
1912
|
+
sharedRevealRadius = Math.max(
|
|
1913
|
+
sharedRevealRadius,
|
|
1914
|
+
getRobustSplatRadialExtent(outgoingWorld, outgoingAnchor) *
|
|
1915
|
+
COMPANION_WORLD_SCALE,
|
|
1916
|
+
);
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
const worldReveal = this.createWorldRevealController(
|
|
1920
|
+
spark,
|
|
1921
|
+
splat,
|
|
1922
|
+
{
|
|
1923
|
+
origin: worldCenterBottom,
|
|
1924
|
+
radius: sharedRevealRadius,
|
|
1925
|
+
},
|
|
1926
|
+
"reveal",
|
|
1927
|
+
);
|
|
1928
|
+
this.worldMesh = splat;
|
|
1929
|
+
if (worldReveal) {
|
|
1930
|
+
let outgoingReveal: WorldRevealController | null = null;
|
|
1931
|
+
if (outgoingWorld && outgoingAnchor && !waitingForVrm) {
|
|
1932
|
+
outgoingReveal = this.createWorldRevealController(
|
|
1933
|
+
spark,
|
|
1934
|
+
outgoingWorld,
|
|
1935
|
+
{
|
|
1936
|
+
origin: outgoingAnchor,
|
|
1937
|
+
radius: sharedRevealRadius,
|
|
1938
|
+
},
|
|
1939
|
+
"hide",
|
|
1940
|
+
);
|
|
1941
|
+
if (!outgoingReveal) {
|
|
1942
|
+
this.disposeSplatMesh(outgoingWorld);
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
this.queueWorldReveal(worldReveal, {
|
|
1946
|
+
outgoing: outgoingReveal,
|
|
1947
|
+
duration: COMPANION_WORLD_REVEAL_DURATION,
|
|
1948
|
+
waitingForVrm,
|
|
1949
|
+
syncToTeleport,
|
|
1950
|
+
initialProgress: syncToTeleport ? this.teleportProgress : 0,
|
|
1951
|
+
});
|
|
1952
|
+
} else {
|
|
1953
|
+
this.disposeSplatMesh(outgoingWorld);
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
async playEmote(
|
|
1957
|
+
path: string,
|
|
1958
|
+
duration: number,
|
|
1959
|
+
loop: boolean,
|
|
1960
|
+
): Promise<void> {
|
|
1961
|
+
const vrm = this.vrm;
|
|
1962
|
+
const mixer = this.mixer;
|
|
1963
|
+
if (!vrm || !mixer) return;
|
|
1964
|
+
this.clearPendingEmoteCompletion();
|
|
1965
|
+
this.emoteRequestId++;
|
|
1966
|
+
const requestId = this.emoteRequestId;
|
|
1967
|
+
const currentAction = this.emoteAction;
|
|
1968
|
+
const blendSource = currentAction ?? this.idleAction;
|
|
1969
|
+
const clip = await this.loadEmoteClipCached(path, vrm);
|
|
1970
|
+
if (!clip || this.vrm !== vrm || this.mixer !== mixer) return;
|
|
1971
|
+
if (this.emoteRequestId !== requestId) return;
|
|
1972
|
+
const action = mixer.clipAction(clip);
|
|
1973
|
+
action.setLoop(
|
|
1974
|
+
loop ? THREE.LoopRepeat : THREE.LoopOnce,
|
|
1975
|
+
loop ? Infinity : 1,
|
|
1976
|
+
);
|
|
1977
|
+
action.clampWhenFinished = !loop;
|
|
1978
|
+
const fadeDuration = 0.4;
|
|
1979
|
+
this.playActionWithBlend(action, blendSource, fadeDuration);
|
|
1980
|
+
this.emoteAction = action;
|
|
1981
|
+
if (!loop) {
|
|
1982
|
+
const clipDuration =
|
|
1983
|
+
Number.isFinite(duration) && duration > 0 ? duration : clip.duration;
|
|
1984
|
+
this.watchOneShotEmoteCompletion(mixer, action, requestId, clipDuration);
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
stopEmote(): void {
|
|
1988
|
+
this.clearPendingEmoteCompletion();
|
|
1989
|
+
const fadeDuration = 0.4;
|
|
1990
|
+
const activeEmote = this.emoteAction;
|
|
1991
|
+
this.emoteAction = null;
|
|
1992
|
+
if (this.idleAction) {
|
|
1993
|
+
this.activateAction(this.idleAction);
|
|
1994
|
+
if (activeEmote && activeEmote !== this.idleAction) {
|
|
1995
|
+
this.idleAction.crossFadeFrom(activeEmote, fadeDuration, false);
|
|
1996
|
+
} else {
|
|
1997
|
+
this.idleAction.fadeIn(fadeDuration);
|
|
1998
|
+
}
|
|
1999
|
+
return;
|
|
2000
|
+
}
|
|
2001
|
+
if (this.vrm && this.mixer) {
|
|
2002
|
+
this.restoreIdleAfterEmote(
|
|
2003
|
+
activeEmote,
|
|
2004
|
+
fadeDuration,
|
|
2005
|
+
this.vrm,
|
|
2006
|
+
this.mixer,
|
|
2007
|
+
);
|
|
2008
|
+
return;
|
|
2009
|
+
}
|
|
2010
|
+
activeEmote?.fadeOut(fadeDuration);
|
|
2011
|
+
}
|
|
2012
|
+
async loadVrmFromUrl(url: string, name?: string): Promise<void> {
|
|
2013
|
+
await this.whenReady();
|
|
2014
|
+
if (!this.scene) throw new Error("VrmEngine not initialized");
|
|
2015
|
+
if (!this.camera) throw new Error("VrmEngine not initialized");
|
|
2016
|
+
if (this.loadingAborted) return;
|
|
2017
|
+
const requestId = ++this.vrmLoadRequestId;
|
|
2018
|
+
const hadPreviousVrm = this.vrm !== null;
|
|
2019
|
+
if (this.vrm) {
|
|
2020
|
+
this.vrm.scene.parent?.remove(this.vrm.scene);
|
|
2021
|
+
VRMUtils.deepDispose(this.vrm.scene);
|
|
2022
|
+
this.vrm = null;
|
|
2023
|
+
this.vrmReady = false;
|
|
2024
|
+
this.vrmName = null;
|
|
2025
|
+
this.mixer = null;
|
|
2026
|
+
this.idleAction = null;
|
|
2027
|
+
this.idleLoadPromise = null;
|
|
2028
|
+
this.revealStarted = false;
|
|
2029
|
+
this.cleanupTeleportSparkles();
|
|
2030
|
+
this.stopEmote();
|
|
2031
|
+
this.emoteClipCache.clear();
|
|
2032
|
+
}
|
|
2033
|
+
this.lastLoadError = null;
|
|
2034
|
+
const loader = new GLTFLoader();
|
|
2035
|
+
configureVrmGltfLoader(loader);
|
|
2036
|
+
const webGpuNodes =
|
|
2037
|
+
this.rendererBackend === "webgpu"
|
|
2038
|
+
? await import("@pixiv/three-vrm/nodes")
|
|
2039
|
+
: null;
|
|
2040
|
+
loader.register((parser) => {
|
|
2041
|
+
if (webGpuNodes) {
|
|
2042
|
+
const mtoonMaterialPlugin = new MToonMaterialLoaderPlugin(parser, {
|
|
2043
|
+
materialType: webGpuNodes.MToonNodeMaterial,
|
|
2044
|
+
});
|
|
2045
|
+
return new VRMLoaderPlugin(parser, { mtoonMaterialPlugin });
|
|
2046
|
+
}
|
|
2047
|
+
return new VRMLoaderPlugin(parser);
|
|
2048
|
+
});
|
|
2049
|
+
let gltf: Awaited<ReturnType<GLTFLoader["loadAsync"]>>;
|
|
2050
|
+
try {
|
|
2051
|
+
gltf = await loadGltfAsset(loader, url);
|
|
2052
|
+
} catch (error) {
|
|
2053
|
+
if (!this.loadingAborted && requestId === this.vrmLoadRequestId) {
|
|
2054
|
+
this.lastLoadError =
|
|
2055
|
+
error instanceof Error ? error.message : String(error);
|
|
2056
|
+
this.onUpdate?.();
|
|
2057
|
+
}
|
|
2058
|
+
throw error;
|
|
2059
|
+
}
|
|
2060
|
+
if (
|
|
2061
|
+
this.loadingAborted ||
|
|
2062
|
+
!this.scene ||
|
|
2063
|
+
requestId !== this.vrmLoadRequestId
|
|
2064
|
+
) {
|
|
2065
|
+
const staleVrm = gltf.userData.vrm as VRM | undefined;
|
|
2066
|
+
if (staleVrm) VRMUtils.deepDispose(staleVrm.scene);
|
|
2067
|
+
return;
|
|
2068
|
+
}
|
|
2069
|
+
const vrm = gltf.userData.vrm as VRM | undefined;
|
|
2070
|
+
if (!vrm) throw new Error("Loaded asset is not a VRM");
|
|
2071
|
+
VRMUtils.removeUnnecessaryVertices(vrm.scene);
|
|
2072
|
+
if (this.camera) {
|
|
2073
|
+
if (hadPreviousVrm) {
|
|
2074
|
+
this.transitionCameraToFramedAvatar(
|
|
2075
|
+
vrm,
|
|
2076
|
+
AVATAR_SWITCH_CAMERA_TRANSITION_DURATION_SECONDS,
|
|
2077
|
+
);
|
|
2078
|
+
} else {
|
|
2079
|
+
this.cameraManager.centerAndFrame(
|
|
2080
|
+
vrm,
|
|
2081
|
+
this.camera,
|
|
2082
|
+
this.controls,
|
|
2083
|
+
this.cameraProfile,
|
|
2084
|
+
this.lookAtTarget,
|
|
2085
|
+
this.baseCameraPosition,
|
|
2086
|
+
(c) =>
|
|
2087
|
+
this.cameraManager.applyInteractionMode(c, this.interactionMode),
|
|
2088
|
+
);
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
try {
|
|
2092
|
+
VRMUtils.rotateVRM0(vrm);
|
|
2093
|
+
} catch {
|
|
2094
|
+
/* optional in some versions */
|
|
2095
|
+
}
|
|
2096
|
+
this.cameraManager.ensureFacingCamera(vrm, this.camera);
|
|
2097
|
+
this.configureAvatarLookTracking(vrm);
|
|
2098
|
+
if (
|
|
2099
|
+
this.loadingAborted ||
|
|
2100
|
+
!this.scene ||
|
|
2101
|
+
requestId !== this.vrmLoadRequestId
|
|
2102
|
+
) {
|
|
2103
|
+
VRMUtils.deepDispose(vrm.scene);
|
|
2104
|
+
return;
|
|
2105
|
+
}
|
|
2106
|
+
vrm.scene.visible = false;
|
|
2107
|
+
vrm.scene.traverse((obj) => {
|
|
2108
|
+
obj.frustumCulled = false;
|
|
2109
|
+
});
|
|
2110
|
+
const avatarParent = this.avatarRoot ?? this.scene;
|
|
2111
|
+
avatarParent.add(vrm.scene);
|
|
2112
|
+
this.vrm = vrm;
|
|
2113
|
+
this.vrmName = name ?? null;
|
|
2114
|
+
this.lastLoadError = null;
|
|
2115
|
+
vrm.springBoneManager?.reset?.();
|
|
2116
|
+
this.blinkController.reset();
|
|
2117
|
+
|
|
2118
|
+
try {
|
|
2119
|
+
await this.loadAndPlayIdle(vrm);
|
|
2120
|
+
if (!this.loadingAborted && this.vrm === vrm) {
|
|
2121
|
+
this.vrmReady = true;
|
|
2122
|
+
await this.playTeleportReveal(vrm);
|
|
2123
|
+
vrm.scene.visible = true;
|
|
2124
|
+
this.startPendingWorldReveal(true);
|
|
2125
|
+
}
|
|
2126
|
+
} catch {
|
|
2127
|
+
if (!this.loadingAborted && this.vrm === vrm) {
|
|
2128
|
+
this.vrmReady = true;
|
|
2129
|
+
vrm.scene.visible = true;
|
|
2130
|
+
this.startPendingWorldReveal(false);
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
private async playTeleportReveal(vrm: VRM): Promise<void> {
|
|
2136
|
+
this.teleportProgress = 0.0;
|
|
2137
|
+
this.revealStarted = true;
|
|
2138
|
+
this.cleanupTeleportDissolve();
|
|
2139
|
+
this.startTeleportSparkles(vrm);
|
|
2140
|
+
let appliedNodeDissolve = false;
|
|
2141
|
+
|
|
2142
|
+
try {
|
|
2143
|
+
const tsl = await import("three/tsl");
|
|
2144
|
+
|
|
2145
|
+
const uProgress = tsl.uniform(0.0);
|
|
2146
|
+
this.teleportProgressUniform = uProgress;
|
|
2147
|
+
|
|
2148
|
+
vrm.scene.traverse((obj: THREE.Object3D) => {
|
|
2149
|
+
if (!(obj instanceof THREE.Mesh)) return;
|
|
2150
|
+
const mats = Array.isArray(obj.material)
|
|
2151
|
+
? obj.material
|
|
2152
|
+
: [obj.material];
|
|
2153
|
+
for (const mat of mats) {
|
|
2154
|
+
if (!mat.isNodeMaterial || mat.userData._dissolveApplied) continue;
|
|
2155
|
+
appliedNodeDissolve = true;
|
|
2156
|
+
mat.userData._dissolveApplied = true;
|
|
2157
|
+
mat.userData._origOpacityNode = mat.opacityNode ?? null;
|
|
2158
|
+
// biome-ignore lint/suspicious/noExplicitAny: Three.js NodeMaterial emissiveNode is not in public types
|
|
2159
|
+
mat.userData._origEmissiveNode = (mat as any).emissiveNode ?? null;
|
|
2160
|
+
mat.userData._origAlphaTest = mat.alphaTest;
|
|
2161
|
+
|
|
2162
|
+
// World-space Y from TSL
|
|
2163
|
+
const worldY = tsl.positionWorld.y;
|
|
2164
|
+
|
|
2165
|
+
// Sweep threshold starts 1m lower than before.
|
|
2166
|
+
const threshold = uProgress
|
|
2167
|
+
.mul(TELEPORT_DISSOLVE_END_Y - TELEPORT_DISSOLVE_START_Y)
|
|
2168
|
+
.add(TELEPORT_DISSOLVE_START_Y);
|
|
2169
|
+
|
|
2170
|
+
// Distance above dissolve line
|
|
2171
|
+
const diff = worldY.sub(threshold);
|
|
2172
|
+
|
|
2173
|
+
// Dither noise using a hash of world position
|
|
2174
|
+
const noiseCoord = tsl.vec2(
|
|
2175
|
+
worldY.mul(40.0),
|
|
2176
|
+
tsl.positionWorld.x.add(tsl.positionWorld.z).mul(30.0),
|
|
2177
|
+
);
|
|
2178
|
+
const noise = tsl.fract(
|
|
2179
|
+
tsl
|
|
2180
|
+
.sin(tsl.dot(noiseCoord, tsl.vec2(12.9898, 78.233)))
|
|
2181
|
+
.mul(43758.5453),
|
|
2182
|
+
);
|
|
2183
|
+
|
|
2184
|
+
// Ratio: 0 = fully visible, 1 = fully hidden (wider zone = 0.3)
|
|
2185
|
+
const ratio = diff.div(0.3).clamp(0.0, 1.0);
|
|
2186
|
+
|
|
2187
|
+
// Dithered alpha: visible when noise >= ratio
|
|
2188
|
+
const dissolveAlpha = tsl.step(ratio, noise);
|
|
2189
|
+
|
|
2190
|
+
// --- Holographic glow at the dissolve edge ---
|
|
2191
|
+
// Glow is strongest right at the dissolve boundary
|
|
2192
|
+
const edgeDist = diff.abs();
|
|
2193
|
+
const glowWidth = tsl.float(0.15);
|
|
2194
|
+
const glowIntensity = tsl
|
|
2195
|
+
.float(1.0)
|
|
2196
|
+
.sub(edgeDist.div(glowWidth).clamp(0.0, 1.0));
|
|
2197
|
+
// Holographic color: cyan-magenta shift based on world position
|
|
2198
|
+
const hueShift = tsl.fract(worldY.mul(3.0).add(uProgress.mul(2.0)));
|
|
2199
|
+
const holoR = tsl
|
|
2200
|
+
.smoothstep(tsl.float(0.3), tsl.float(0.7), hueShift)
|
|
2201
|
+
.mul(0.8)
|
|
2202
|
+
.add(0.2);
|
|
2203
|
+
const holoG = tsl.float(0.9);
|
|
2204
|
+
const holoB = tsl
|
|
2205
|
+
.smoothstep(tsl.float(0.7), tsl.float(0.3), hueShift)
|
|
2206
|
+
.mul(0.8)
|
|
2207
|
+
.add(0.2);
|
|
2208
|
+
const holoColor = tsl.vec3(holoR, holoG, holoB);
|
|
2209
|
+
|
|
2210
|
+
// Only show glow when dissolve is active and fragment is visible
|
|
2211
|
+
const glowActive = tsl
|
|
2212
|
+
.step(tsl.float(0.001), uProgress)
|
|
2213
|
+
.mul(tsl.float(1.0).sub(tsl.step(tsl.float(0.999), uProgress)));
|
|
2214
|
+
const emissiveBoost = holoColor.mul(
|
|
2215
|
+
glowIntensity.mul(3.0).mul(glowActive).mul(dissolveAlpha),
|
|
2216
|
+
);
|
|
2217
|
+
|
|
2218
|
+
// Compose with existing nodes
|
|
2219
|
+
const origOpacity = mat.opacityNode;
|
|
2220
|
+
mat.opacityNode = origOpacity
|
|
2221
|
+
? origOpacity.mul(dissolveAlpha)
|
|
2222
|
+
: dissolveAlpha;
|
|
2223
|
+
|
|
2224
|
+
// biome-ignore lint/suspicious/noExplicitAny: Three.js NodeMaterial emissiveNode is not in public types
|
|
2225
|
+
const origEmissive = (mat as any).emissiveNode;
|
|
2226
|
+
// biome-ignore lint/suspicious/noExplicitAny: Three.js NodeMaterial emissiveNode is not in public types
|
|
2227
|
+
(mat as any).emissiveNode = origEmissive
|
|
2228
|
+
? origEmissive.add(emissiveBoost)
|
|
2229
|
+
: emissiveBoost;
|
|
2230
|
+
|
|
2231
|
+
mat.alphaTest = 0.01;
|
|
2232
|
+
mat.transparent = true;
|
|
2233
|
+
mat.needsUpdate = true;
|
|
2234
|
+
this.teleportDissolvedMaterials.push(mat);
|
|
2235
|
+
}
|
|
2236
|
+
});
|
|
2237
|
+
} catch (err) {
|
|
2238
|
+
console.warn(
|
|
2239
|
+
"[VrmEngine] TSL dissolve unavailable, showing instantly:",
|
|
2240
|
+
err,
|
|
2241
|
+
);
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2244
|
+
if (!appliedNodeDissolve) {
|
|
2245
|
+
this.applyTeleportFallbackDissolve(vrm);
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
|
|
2249
|
+
private applyTeleportFallbackDissolve(vrm: VRM): void {
|
|
2250
|
+
vrm.scene.traverse((obj: THREE.Object3D) => {
|
|
2251
|
+
if (!(obj instanceof THREE.Mesh)) return;
|
|
2252
|
+
const mats = Array.isArray(obj.material) ? obj.material : [obj.material];
|
|
2253
|
+
for (const mat of mats) {
|
|
2254
|
+
if (mat.userData._dissolveApplied) continue;
|
|
2255
|
+
mat.userData._dissolveApplied = true;
|
|
2256
|
+
mat.userData._origTransparent = mat.transparent;
|
|
2257
|
+
mat.userData._origAlphaTest = mat.alphaTest;
|
|
2258
|
+
mat.userData._origOnBeforeCompile = mat.onBeforeCompile;
|
|
2259
|
+
mat.userData._origCustomProgramCacheKey = mat.customProgramCacheKey;
|
|
2260
|
+
|
|
2261
|
+
const shaderRef: TeleportFallbackShader = {
|
|
2262
|
+
uniforms: { uTeleportProgress: { value: this.teleportProgress } },
|
|
2263
|
+
};
|
|
2264
|
+
this.teleportFallbackShaders.push(shaderRef);
|
|
2265
|
+
|
|
2266
|
+
mat.transparent = true;
|
|
2267
|
+
mat.alphaTest = Math.max(mat.alphaTest ?? 0, 0.01);
|
|
2268
|
+
mat.onBeforeCompile = (
|
|
2269
|
+
shader: Parameters<THREE.Material["onBeforeCompile"]>[0],
|
|
2270
|
+
) => {
|
|
2271
|
+
shader.uniforms.uTeleportProgress =
|
|
2272
|
+
shaderRef.uniforms.uTeleportProgress;
|
|
2273
|
+
shader.vertexShader = `
|
|
2274
|
+
varying vec3 vTeleportWorldPosition;
|
|
2275
|
+
${shader.vertexShader}
|
|
2276
|
+
`.replace(
|
|
2277
|
+
"#include <worldpos_vertex>",
|
|
2278
|
+
`#include <worldpos_vertex>
|
|
2279
|
+
vTeleportWorldPosition = worldPosition.xyz;`,
|
|
2280
|
+
);
|
|
2281
|
+
shader.fragmentShader = `
|
|
2282
|
+
uniform float uTeleportProgress;
|
|
2283
|
+
varying vec3 vTeleportWorldPosition;
|
|
2284
|
+
float teleportNoiseHash(vec2 p) {
|
|
2285
|
+
return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453);
|
|
2286
|
+
}
|
|
2287
|
+
${shader.fragmentShader}
|
|
2288
|
+
`.replace(
|
|
2289
|
+
"#include <alphatest_fragment>",
|
|
2290
|
+
`float teleportThreshold = mix(${TELEPORT_DISSOLVE_START_Y.toFixed(1)}, ${TELEPORT_DISSOLVE_END_Y.toFixed(1)}, uTeleportProgress);
|
|
2291
|
+
float teleportDiff = vTeleportWorldPosition.y - teleportThreshold;
|
|
2292
|
+
float teleportRatio = clamp(teleportDiff / 0.3, 0.0, 1.0);
|
|
2293
|
+
float teleportNoise = teleportNoiseHash(vec2(
|
|
2294
|
+
vTeleportWorldPosition.y * 40.0,
|
|
2295
|
+
(vTeleportWorldPosition.x + vTeleportWorldPosition.z) * 30.0
|
|
2296
|
+
));
|
|
2297
|
+
if (teleportNoise < teleportRatio) discard;
|
|
2298
|
+
#include <alphatest_fragment>`,
|
|
2299
|
+
);
|
|
2300
|
+
|
|
2301
|
+
const originalOnBeforeCompile = mat.userData._origOnBeforeCompile;
|
|
2302
|
+
if (typeof originalOnBeforeCompile === "function") {
|
|
2303
|
+
originalOnBeforeCompile(shader, this.renderer as never);
|
|
2304
|
+
}
|
|
2305
|
+
};
|
|
2306
|
+
mat.customProgramCacheKey = () =>
|
|
2307
|
+
`${mat.type}:teleport-dissolve-fallback`;
|
|
2308
|
+
mat.needsUpdate = true;
|
|
2309
|
+
this.teleportDissolvedMaterials.push(mat);
|
|
2310
|
+
}
|
|
2311
|
+
});
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
private startTeleportSparkles(vrm: VRM): void {
|
|
2315
|
+
const parent = this.avatarRoot ?? this.scene;
|
|
2316
|
+
if (!parent) return;
|
|
2317
|
+
|
|
2318
|
+
this.cleanupTeleportSparkles();
|
|
2319
|
+
|
|
2320
|
+
const bounds = new THREE.Box3().setFromObject(vrm.scene);
|
|
2321
|
+
const center = bounds.getCenter(new THREE.Vector3());
|
|
2322
|
+
const size = bounds.getSize(new THREE.Vector3());
|
|
2323
|
+
const sparkleGroup = new THREE.Group();
|
|
2324
|
+
sparkleGroup.position.set(center.x, bounds.min.y + 0.06, center.z);
|
|
2325
|
+
parent.add(sparkleGroup);
|
|
2326
|
+
|
|
2327
|
+
const texture = getTeleportSparkleTexture();
|
|
2328
|
+
const particleHeight = THREE.MathUtils.clamp(size.y * 0.82, 0.95, 1.75);
|
|
2329
|
+
const particles: TeleportSparkleParticle[] = [];
|
|
2330
|
+
|
|
2331
|
+
for (let index = 0; index < TELEPORT_SPARKLE_PARTICLE_COUNT; index += 1) {
|
|
2332
|
+
const hue = 0.52 + Math.random() * 0.08;
|
|
2333
|
+
const material = new THREE.SpriteMaterial({
|
|
2334
|
+
map: texture,
|
|
2335
|
+
color: new THREE.Color().setHSL(hue, 0.85, 0.72),
|
|
2336
|
+
transparent: true,
|
|
2337
|
+
opacity: 0,
|
|
2338
|
+
depthWrite: false,
|
|
2339
|
+
blending: THREE.AdditiveBlending,
|
|
2340
|
+
});
|
|
2341
|
+
const sprite = new THREE.Sprite(material);
|
|
2342
|
+
sprite.visible = false;
|
|
2343
|
+
sparkleGroup.add(sprite);
|
|
2344
|
+
|
|
2345
|
+
const duration = 0.3 + Math.random() * 0.32;
|
|
2346
|
+
const maxStart = Math.max(0.02, 0.92 - duration);
|
|
2347
|
+
particles.push({
|
|
2348
|
+
sprite,
|
|
2349
|
+
material,
|
|
2350
|
+
baseAngle:
|
|
2351
|
+
(index / TELEPORT_SPARKLE_PARTICLE_COUNT) * Math.PI * 2 +
|
|
2352
|
+
(Math.random() - 0.5) * 0.55,
|
|
2353
|
+
baseRadius:
|
|
2354
|
+
(0.18 + Math.random() * 0.82) * TELEPORT_SPARKLE_RING_RADIUS,
|
|
2355
|
+
height: particleHeight * (0.55 + Math.random() * 0.55),
|
|
2356
|
+
start: Math.random() * maxStart,
|
|
2357
|
+
duration,
|
|
2358
|
+
spin: (1.8 + Math.random() * 3.6) * (Math.random() > 0.5 ? 1 : -1),
|
|
2359
|
+
wobble: 0.02 + Math.random() * 0.08,
|
|
2360
|
+
wobbleSpeed: 8 + Math.random() * 12,
|
|
2361
|
+
baseSize:
|
|
2362
|
+
TELEPORT_SPARKLE_MIN_SIZE +
|
|
2363
|
+
Math.random() *
|
|
2364
|
+
(TELEPORT_SPARKLE_MAX_SIZE - TELEPORT_SPARKLE_MIN_SIZE),
|
|
2365
|
+
});
|
|
2366
|
+
}
|
|
2367
|
+
|
|
2368
|
+
this.teleportSparkles = {
|
|
2369
|
+
group: sparkleGroup,
|
|
2370
|
+
particles,
|
|
2371
|
+
};
|
|
2372
|
+
this.updateTeleportSparkles();
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2375
|
+
private updateTeleportSparkles(): void {
|
|
2376
|
+
const system = this.teleportSparkles;
|
|
2377
|
+
if (!system) return;
|
|
2378
|
+
|
|
2379
|
+
const progress = THREE.MathUtils.clamp(this.teleportProgress, 0, 1);
|
|
2380
|
+
let anyVisible = false;
|
|
2381
|
+
|
|
2382
|
+
for (const particle of system.particles) {
|
|
2383
|
+
const localProgress = THREE.MathUtils.clamp(
|
|
2384
|
+
(progress - particle.start) / particle.duration,
|
|
2385
|
+
0,
|
|
2386
|
+
1,
|
|
2387
|
+
);
|
|
2388
|
+
|
|
2389
|
+
if (localProgress <= 0 || localProgress >= 1) {
|
|
2390
|
+
particle.material.opacity = 0;
|
|
2391
|
+
particle.sprite.visible = false;
|
|
2392
|
+
continue;
|
|
2393
|
+
}
|
|
2394
|
+
|
|
2395
|
+
anyVisible = true;
|
|
2396
|
+
const rise = 1 - (1 - localProgress) ** 2;
|
|
2397
|
+
const angle = particle.baseAngle + progress * Math.PI * 2 * particle.spin;
|
|
2398
|
+
const wobblePhase = progress * particle.wobbleSpeed + particle.baseAngle;
|
|
2399
|
+
const wobbleOffset = Math.sin(wobblePhase) * particle.wobble;
|
|
2400
|
+
const radial = particle.baseRadius * (1 - 0.48 * rise);
|
|
2401
|
+
const x = Math.cos(angle) * radial + wobbleOffset;
|
|
2402
|
+
const z =
|
|
2403
|
+
Math.sin(angle) * radial + Math.cos(wobblePhase) * particle.wobble;
|
|
2404
|
+
const y =
|
|
2405
|
+
0.08 +
|
|
2406
|
+
particle.height * rise +
|
|
2407
|
+
Math.sin(progress * 10 + particle.baseAngle * 3) * 0.04;
|
|
2408
|
+
const opacity =
|
|
2409
|
+
Math.sin(localProgress * Math.PI) *
|
|
2410
|
+
(0.72 + 0.28 * Math.sin(progress * 22 + particle.baseAngle * 5));
|
|
2411
|
+
const scale = particle.baseSize * (0.7 + (1 - localProgress) * 1.15);
|
|
2412
|
+
|
|
2413
|
+
particle.sprite.visible = opacity > 0.01;
|
|
2414
|
+
particle.sprite.position.set(x, y, z);
|
|
2415
|
+
particle.sprite.scale.setScalar(scale);
|
|
2416
|
+
particle.material.opacity = opacity;
|
|
2417
|
+
}
|
|
2418
|
+
|
|
2419
|
+
if (!anyVisible && progress >= 1) {
|
|
2420
|
+
this.cleanupTeleportSparkles();
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
private cleanupTeleportDissolve(): void {
|
|
2425
|
+
for (const mat of this.teleportDissolvedMaterials) {
|
|
2426
|
+
if (mat.userData._dissolveApplied) {
|
|
2427
|
+
if (mat.userData._origOpacityNode !== undefined) {
|
|
2428
|
+
(mat as unknown as Record<string, unknown>).opacityNode =
|
|
2429
|
+
mat.userData._origOpacityNode ?? null;
|
|
2430
|
+
}
|
|
2431
|
+
if (mat.userData._origEmissiveNode !== undefined) {
|
|
2432
|
+
(mat as unknown as Record<string, unknown>).emissiveNode =
|
|
2433
|
+
mat.userData._origEmissiveNode ?? null;
|
|
2434
|
+
}
|
|
2435
|
+
mat.alphaTest = mat.userData._origAlphaTest ?? 0;
|
|
2436
|
+
mat.transparent = mat.userData._origTransparent ?? mat.transparent;
|
|
2437
|
+
mat.onBeforeCompile =
|
|
2438
|
+
mat.userData._origOnBeforeCompile ?? mat.onBeforeCompile;
|
|
2439
|
+
mat.customProgramCacheKey =
|
|
2440
|
+
mat.userData._origCustomProgramCacheKey ?? mat.customProgramCacheKey;
|
|
2441
|
+
delete mat.userData._dissolveApplied;
|
|
2442
|
+
delete mat.userData._origOpacityNode;
|
|
2443
|
+
delete mat.userData._origEmissiveNode;
|
|
2444
|
+
delete mat.userData._origAlphaTest;
|
|
2445
|
+
delete mat.userData._origTransparent;
|
|
2446
|
+
delete mat.userData._origOnBeforeCompile;
|
|
2447
|
+
delete mat.userData._origCustomProgramCacheKey;
|
|
2448
|
+
mat.needsUpdate = true;
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
this.teleportDissolvedMaterials = [];
|
|
2452
|
+
this.teleportProgressUniform = null;
|
|
2453
|
+
this.teleportFallbackShaders = [];
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
private cleanupTeleportSparkles(): void {
|
|
2457
|
+
if (!this.teleportSparkles) return;
|
|
2458
|
+
for (const particle of this.teleportSparkles.particles) {
|
|
2459
|
+
particle.sprite.parent?.remove(particle.sprite);
|
|
2460
|
+
particle.material.dispose();
|
|
2461
|
+
}
|
|
2462
|
+
this.teleportSparkles.group.parent?.remove(this.teleportSparkles.group);
|
|
2463
|
+
this.teleportSparkles = null;
|
|
2464
|
+
}
|
|
2465
|
+
private get animationLoaderContext(): AnimationLoaderContext {
|
|
2466
|
+
return {
|
|
2467
|
+
isAborted: () => this.loadingAborted,
|
|
2468
|
+
isCurrentVrm: (vrm: VRM) => this.vrm === vrm,
|
|
2469
|
+
};
|
|
2470
|
+
}
|
|
2471
|
+
private loop(): void {
|
|
2472
|
+
if (this.paused) return;
|
|
2473
|
+
this.scheduleNextFrame();
|
|
2474
|
+
const renderer = this.renderer;
|
|
2475
|
+
const scene = this.scene;
|
|
2476
|
+
const camera = this.camera;
|
|
2477
|
+
if (!renderer || !scene || !camera) return;
|
|
2478
|
+
const rawDelta = this.clock.getDelta();
|
|
2479
|
+
const stableDelta = Math.min(rawDelta, 1 / 30);
|
|
2480
|
+
this.elapsedTime += rawDelta;
|
|
2481
|
+
this.mixer?.update(rawDelta);
|
|
2482
|
+
if (this.vrm) {
|
|
2483
|
+
if (this.teleportProgress < 1.0) {
|
|
2484
|
+
this.teleportProgress += stableDelta * 2.0; // ~0.5 seconds duration
|
|
2485
|
+
if (this.teleportProgress > 1.0) this.teleportProgress = 1.0;
|
|
2486
|
+
|
|
2487
|
+
if (this.teleportProgressUniform) {
|
|
2488
|
+
this.teleportProgressUniform.value = this.teleportProgress;
|
|
2489
|
+
}
|
|
2490
|
+
for (const shader of this.teleportFallbackShaders) {
|
|
2491
|
+
shader.uniforms.uTeleportProgress.value = this.teleportProgress;
|
|
2492
|
+
}
|
|
2493
|
+
|
|
2494
|
+
if (this.teleportProgress >= 1.0) {
|
|
2495
|
+
this.cleanupTeleportDissolve();
|
|
2496
|
+
this.cleanupTeleportSparkles();
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
this.updateTeleportSparkles();
|
|
2500
|
+
|
|
2501
|
+
this.applyMouthToVrm(this.vrm);
|
|
2502
|
+
const blinkValue = this.blinkController.update(rawDelta);
|
|
2503
|
+
this.vrm.expressionManager?.setValue("blink", blinkValue);
|
|
2504
|
+
}
|
|
2505
|
+
this.updateWorldReveal(stableDelta);
|
|
2506
|
+
|
|
2507
|
+
// Process camera transition
|
|
2508
|
+
if (this.isCameraTransitioning) {
|
|
2509
|
+
this.transitionProgress += stableDelta / this.transitionDuration;
|
|
2510
|
+
let finished = false;
|
|
2511
|
+
if (this.transitionProgress >= 1.0) {
|
|
2512
|
+
this.transitionProgress = 1.0;
|
|
2513
|
+
this.isCameraTransitioning = false;
|
|
2514
|
+
finished = true;
|
|
2515
|
+
}
|
|
2516
|
+
|
|
2517
|
+
// Smooth step easing
|
|
2518
|
+
const t = this.transitionProgress;
|
|
2519
|
+
const ease = t * t * (3.0 - 2.0 * t);
|
|
2520
|
+
|
|
2521
|
+
camera.position.lerpVectors(
|
|
2522
|
+
this.transitionStartPos,
|
|
2523
|
+
this.transitionTargetPos,
|
|
2524
|
+
ease,
|
|
2525
|
+
);
|
|
2526
|
+
this.baseCameraPosition.copy(camera.position);
|
|
2527
|
+
|
|
2528
|
+
this.lookAtTarget.lerpVectors(
|
|
2529
|
+
this.transitionStartLookAt,
|
|
2530
|
+
this.transitionTargetLookAt,
|
|
2531
|
+
ease,
|
|
2532
|
+
);
|
|
2533
|
+
|
|
2534
|
+
camera.fov = THREE.MathUtils.lerp(
|
|
2535
|
+
this.transitionStartFov,
|
|
2536
|
+
this.transitionTargetFov,
|
|
2537
|
+
ease,
|
|
2538
|
+
);
|
|
2539
|
+
camera.updateProjectionMatrix();
|
|
2540
|
+
|
|
2541
|
+
if (this.controls) {
|
|
2542
|
+
this.controls.target.copy(this.lookAtTarget);
|
|
2543
|
+
if (finished) {
|
|
2544
|
+
this.controls.update(); // Sync once at the very end when bounds match
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
const manualCameraActive = this.interactionEnabled;
|
|
2550
|
+
if (
|
|
2551
|
+
!manualCameraActive &&
|
|
2552
|
+
this.cameraAnimation.enabled &&
|
|
2553
|
+
this.baseCameraPosition.length() > 0 &&
|
|
2554
|
+
!this.isCameraTransitioning
|
|
2555
|
+
) {
|
|
2556
|
+
this.cameraManager.applyCameraMotion(
|
|
2557
|
+
camera,
|
|
2558
|
+
this.baseCameraPosition,
|
|
2559
|
+
this.lookAtTarget,
|
|
2560
|
+
this.cameraAnimation,
|
|
2561
|
+
this.elapsedTime,
|
|
2562
|
+
);
|
|
2563
|
+
}
|
|
2564
|
+
const dragOrbitFollow = Math.min(1, stableDelta * 9);
|
|
2565
|
+
this.dragOrbitCurrent.lerp(this.dragOrbitTarget, dragOrbitFollow);
|
|
2566
|
+
if (
|
|
2567
|
+
this.dragOrbitCurrent.lengthSq() > 1e-6 &&
|
|
2568
|
+
this.baseCameraPosition.lengthSq() > 1e-6
|
|
2569
|
+
) {
|
|
2570
|
+
const orbitOffset = this.tempCameraOrbitOffset
|
|
2571
|
+
.copy(camera.position)
|
|
2572
|
+
.sub(this.lookAtTarget);
|
|
2573
|
+
if (orbitOffset.lengthSq() > 1e-6) {
|
|
2574
|
+
const spherical = this.tempCameraSpherical.setFromVector3(orbitOffset);
|
|
2575
|
+
spherical.theta += this.dragOrbitCurrent.x;
|
|
2576
|
+
spherical.phi = THREE.MathUtils.clamp(
|
|
2577
|
+
spherical.phi + this.dragOrbitCurrent.y,
|
|
2578
|
+
0.2,
|
|
2579
|
+
Math.PI - 0.2,
|
|
2580
|
+
);
|
|
2581
|
+
orbitOffset.setFromSpherical(spherical);
|
|
2582
|
+
camera.position.copy(this.lookAtTarget).add(orbitOffset);
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
this.applyCompanionZoom(camera, stableDelta);
|
|
2586
|
+
this.updateSparkPerformanceProfile();
|
|
2587
|
+
if (this.pointerParallaxEnabled) {
|
|
2588
|
+
const follow = Math.min(1, stableDelta * 7.5);
|
|
2589
|
+
this.pointerParallaxCurrent.lerp(this.pointerParallaxTarget, follow);
|
|
2590
|
+
this.pointerParallaxPosition.set(
|
|
2591
|
+
this.pointerParallaxCurrent.x * 0.18,
|
|
2592
|
+
this.pointerParallaxCurrent.y * 0.12,
|
|
2593
|
+
0,
|
|
2594
|
+
);
|
|
2595
|
+
camera.position.add(this.pointerParallaxPosition);
|
|
2596
|
+
this.pointerParallaxLookAt
|
|
2597
|
+
.copy(this.lookAtTarget)
|
|
2598
|
+
.add(
|
|
2599
|
+
new THREE.Vector3(
|
|
2600
|
+
this.pointerParallaxCurrent.x * 0.08,
|
|
2601
|
+
this.pointerParallaxCurrent.y * 0.05,
|
|
2602
|
+
0,
|
|
2603
|
+
),
|
|
2604
|
+
);
|
|
2605
|
+
} else {
|
|
2606
|
+
this.pointerParallaxCurrent.lerp(this.pointerParallaxTarget, 0.12);
|
|
2607
|
+
this.pointerParallaxLookAt.copy(this.lookAtTarget);
|
|
2608
|
+
}
|
|
2609
|
+
if (this.controls) {
|
|
2610
|
+
if (manualCameraActive && !this.isCameraTransitioning) {
|
|
2611
|
+
this.controls.update();
|
|
2612
|
+
this.lookAtTarget.copy(this.controls.target);
|
|
2613
|
+
} else if (!this.isCameraTransitioning) {
|
|
2614
|
+
this.controls.target.copy(this.lookAtTarget);
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
if (!manualCameraActive || this.isCameraTransitioning) {
|
|
2618
|
+
camera.lookAt(this.pointerParallaxLookAt);
|
|
2619
|
+
}
|
|
2620
|
+
if (this.vrm) {
|
|
2621
|
+
this.updateAvatarLookTarget(camera, stableDelta);
|
|
2622
|
+
this.vrm.update(stableDelta);
|
|
2623
|
+
this.applyAvatarHeadTracking(camera, stableDelta);
|
|
2624
|
+
this.refreshAvatarEyeTracking();
|
|
2625
|
+
}
|
|
2626
|
+
this.updateSparkDepthOfField(camera);
|
|
2627
|
+
renderer.render(scene, camera);
|
|
2628
|
+
this.onUpdate?.();
|
|
2629
|
+
}
|
|
2630
|
+
private disposeWorld(): void {
|
|
2631
|
+
if (this.sparkRenderer) {
|
|
2632
|
+
this.sparkRenderer.apertureAngle = 0;
|
|
2633
|
+
}
|
|
2634
|
+
this.cancelWorldReveal();
|
|
2635
|
+
this.disposeSplatMesh(this.worldMesh);
|
|
2636
|
+
this.worldMesh = null;
|
|
2637
|
+
}
|
|
2638
|
+
private async loadAndPlayIdle(vrm: VRM): Promise<void> {
|
|
2639
|
+
if (this.loadingAborted) return;
|
|
2640
|
+
const mixer = this.mixer ?? new THREE.AnimationMixer(vrm.scene);
|
|
2641
|
+
this.mixer = mixer;
|
|
2642
|
+
const action = await this.ensureIdleAction(vrm, mixer);
|
|
2643
|
+
if (!action) return;
|
|
2644
|
+
action.fadeIn(0.25);
|
|
2645
|
+
action.play();
|
|
2646
|
+
mixer.update(1 / 60);
|
|
2647
|
+
}
|
|
2648
|
+
private async loadEmoteClipCached(
|
|
2649
|
+
path: string,
|
|
2650
|
+
vrm: VRM,
|
|
2651
|
+
): Promise<THREE.AnimationClip | null> {
|
|
2652
|
+
const cached = this.emoteClipCache.get(path);
|
|
2653
|
+
if (cached) return cached;
|
|
2654
|
+
const clip = await loadEmoteClip(path, vrm, this.animationLoaderContext);
|
|
2655
|
+
if (clip) {
|
|
2656
|
+
this.emoteClipCache.set(path, clip);
|
|
2657
|
+
}
|
|
2658
|
+
return clip;
|
|
2659
|
+
}
|
|
2660
|
+
private applyMouthToVrm(vrm: VRM): void {
|
|
2661
|
+
const manager = vrm.expressionManager;
|
|
2662
|
+
if (!manager) return;
|
|
2663
|
+
let target: number;
|
|
2664
|
+
if (this.speaking) {
|
|
2665
|
+
const elapsed = this.elapsedTime - this.speakingStartTime;
|
|
2666
|
+
const base = Math.sin(elapsed * 12) * 0.3 + 0.4;
|
|
2667
|
+
const detail = Math.sin(elapsed * 18.7) * 0.15;
|
|
2668
|
+
const slow = Math.sin(elapsed * 4.2) * 0.1;
|
|
2669
|
+
target = Math.max(0, Math.min(1, base + detail + slow));
|
|
2670
|
+
} else {
|
|
2671
|
+
target = this.mouthValue;
|
|
2672
|
+
}
|
|
2673
|
+
const next = Math.max(0, Math.min(1, target));
|
|
2674
|
+
const alpha = next > this.mouthSmoothed ? 0.3 : 0.2;
|
|
2675
|
+
this.mouthSmoothed = this.mouthSmoothed * (1 - alpha) + next * alpha;
|
|
2676
|
+
manager.setValue("aa", this.mouthSmoothed);
|
|
2677
|
+
}
|
|
2678
|
+
}
|