/** * @fileoverview Simple usage example for Node.js environment * @author Owen Animation System */ import { OwenSystemFactory, States } from '../src/index.js'; /** * Simple example of using Owen Animation System * This example shows how to use the system without a browser environment */ class SimpleOwenExample { constructor() { this.owenSystem = null; } /** * Initialize the Owen system with a mock model * @returns {Promise} */ async init() { try { // Create a mock GLTF model for demonstration const mockModel = this.createMockModel(); // Create the Owen system this.owenSystem = await OwenSystemFactory.createBasicOwenSystem(mockModel); console.log('āœ… Owen Animation System initialized successfully!'); console.log('šŸ“Š System Info:'); console.log(` Available States: ${this.owenSystem.getAvailableStates().join(', ')}`); console.log(` Current State: ${this.owenSystem.getCurrentState()}`); // Run some example interactions await this.runExamples(); } catch (error) { console.error('āŒ Failed to initialize Owen system:', error.message); } } /** * Create a mock 3D model for demonstration purposes * @returns {Object} Mock model object */ createMockModel() { return { animations: [ { name: 'wait_idle_L' }, { name: 'wait_quirk1_Q' }, { name: 'wait_quirk2_Q' }, { name: 'react_idle_L' }, { name: 'react_angry_Q' }, { name: 'react_happy_Q' }, { name: 'type_idle_L' }, { name: 'type_angry_L' }, { name: 'sleep_idle_L' }, { name: 'wait_2react_T' }, { name: 'react_2type_T' }, { name: 'type_2wait_T' }, { name: 'wait_2sleep_T' }, { name: 'sleep_2wait_T' } ], scene: {}, userData: {} }; } /** * Run example interactions with the Owen system * @returns {Promise} */ async runExamples() { console.log('\nšŸŽ¬ Running example interactions...\n'); // Example 1: Basic state transitions console.log('šŸ“ Example 1: Manual state transitions'); await this.demonstrateStateTransitions(); // Example 2: Message handling console.log('\nšŸ“ Example 2: Message handling with emotions'); await this.demonstrateMessageHandling(); // Example 3: System update loop console.log('\nšŸ“ Example 3: System update simulation'); this.demonstrateUpdateLoop(); console.log('\n✨ All examples completed!'); } /** * Demonstrate manual state transitions * @returns {Promise} */ async demonstrateStateTransitions() { const states = [ States.REACT, States.TYPE, States.WAIT, States.SLEEP ]; for (const state of states) { console.log(`šŸ”„ Transitioning to ${state.toUpperCase()} state...`); await this.owenSystem.transitionTo(state); console.log(` āœ“ Current state: ${this.owenSystem.getCurrentState()}`); console.log(` āœ“ Available transitions: ${this.owenSystem.getAvailableTransitions().join(', ')}`); // Simulate some time passing await this.sleep(500); } } /** * Demonstrate message handling with emotional responses * @returns {Promise} */ async demonstrateMessageHandling() { const messages = [ { text: 'Hello Owen!', expected: 'neutral response' }, { text: 'This is urgent!', expected: 'angry/urgent response' }, { text: 'Great work!', expected: 'happy response' }, { text: 'There\'s an error in the system', expected: 'shocked response' }, { text: 'I\'m feeling sad today', expected: 'sad response' } ]; for (const message of messages) { console.log(`šŸ’¬ Sending message: "${message.text}"`); console.log(` Expected: ${message.expected}`); await this.owenSystem.handleUserMessage(message.text); console.log(` āœ“ Current state after message: ${this.owenSystem.getCurrentState()}`); await this.sleep(300); } } /** * Demonstrate the system update loop * @returns {void} */ demonstrateUpdateLoop() { console.log('ā±ļø Simulating update loop for 3 seconds...'); let iterations = 0; const startTime = Date.now(); const updateLoop = () => { const deltaTime = 16.67; // ~60 FPS this.owenSystem.update(deltaTime); iterations++; if (Date.now() - startTime < 3000) { setTimeout(updateLoop, 16); } else { console.log(` āœ“ Completed ${iterations} update iterations`); console.log(` āœ“ Final state: ${this.owenSystem.getCurrentState()}`); } }; updateLoop(); } /** * Simple sleep utility for demonstrations * @param {number} ms - Milliseconds to sleep * @returns {Promise} */ sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } } // Run the example if this file is executed directly if (import.meta.url === `file://${process.argv[ 1 ]}`) { console.log('šŸš€ Starting Owen Animation System Example\n'); const example = new SimpleOwenExample(); example.init() .then(() => { console.log('\nšŸŽ‰ Example completed successfully!'); console.log('šŸ’” Try modifying this example or check out the browser demo in examples/index.html'); }) .catch(error => { console.error('\nšŸ’„ Example failed:', error); }); } export default SimpleOwenExample;