Refactor code for consistency and readability
- Updated import statements to use consistent formatting across files. - Adjusted method definitions and class constructors for uniform spacing and style. - Simplified promise handling and error messages in state handlers. - Enhanced state transition logic in various state handlers. - Improved quirk animation handling in WaitStateHandler. - Streamlined animation loading and caching mechanisms in AnimationLoader. - Updated Vite configuration for aliasing.
This commit is contained in:
@ -9,16 +9,16 @@
|
||||
* @class
|
||||
*/
|
||||
export class AnimationLoader {
|
||||
/**
|
||||
/**
|
||||
* Load an animation by name
|
||||
* @abstract
|
||||
* @param {string} _name - The animation name to load (unused in base class)
|
||||
* @returns {Promise<THREE.AnimationClip>} The loaded animation clip
|
||||
* @throws {Error} Must be implemented by subclasses
|
||||
*/
|
||||
async loadAnimation(_name) {
|
||||
throw new Error('loadAnimation method must be implemented by subclasses');
|
||||
}
|
||||
async loadAnimation (_name) {
|
||||
throw new Error('loadAnimation method must be implemented by subclasses')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -27,68 +27,68 @@ export class AnimationLoader {
|
||||
* @extends AnimationLoader
|
||||
*/
|
||||
export class GLTFAnimationLoader extends AnimationLoader {
|
||||
/**
|
||||
/**
|
||||
* Create a GLTF animation loader
|
||||
* @param {THREE.GLTFLoader} gltfLoader - The Three.js GLTF loader instance
|
||||
*/
|
||||
constructor(gltfLoader) {
|
||||
super();
|
||||
constructor (gltfLoader) {
|
||||
super()
|
||||
|
||||
/**
|
||||
/**
|
||||
* The Three.js GLTF loader
|
||||
* @type {THREE.GLTFLoader}
|
||||
*/
|
||||
this.gltfLoader = gltfLoader;
|
||||
this.gltfLoader = gltfLoader
|
||||
|
||||
/**
|
||||
/**
|
||||
* Cache for loaded animations
|
||||
* @type {Map<string, THREE.AnimationClip>}
|
||||
*/
|
||||
this.animationCache = new Map();
|
||||
}
|
||||
this.animationCache = new Map()
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Load an animation from GLTF by name
|
||||
* @param {string} name - The animation name to load
|
||||
* @returns {Promise<THREE.AnimationClip>} The loaded animation clip
|
||||
* @throws {Error} If animation is not found
|
||||
*/
|
||||
async loadAnimation(name) {
|
||||
if (this.animationCache.has(name)) {
|
||||
return this.animationCache.get(name);
|
||||
}
|
||||
|
||||
// In a real implementation, this would load from GLTF files
|
||||
// For now, we'll assume animations are already loaded in the model
|
||||
throw new Error(`Animation '${name}' not found. Implement GLTF loading logic.`);
|
||||
async loadAnimation (name) {
|
||||
if (this.animationCache.has(name)) {
|
||||
return this.animationCache.get(name)
|
||||
}
|
||||
|
||||
/**
|
||||
// In a real implementation, this would load from GLTF files
|
||||
// For now, we'll assume animations are already loaded in the model
|
||||
throw new Error(`Animation '${name}' not found. Implement GLTF loading logic.`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Preload animations from a GLTF model
|
||||
* @param {Object} gltfModel - The loaded GLTF model
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async preloadAnimations(gltfModel) {
|
||||
if (gltfModel.animations) {
|
||||
for (const animation of gltfModel.animations) {
|
||||
this.animationCache.set(animation.name, animation);
|
||||
}
|
||||
}
|
||||
async preloadAnimations (gltfModel) {
|
||||
if (gltfModel.animations) {
|
||||
for (const animation of gltfModel.animations) {
|
||||
this.animationCache.set(animation.name, animation)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Clear the animation cache
|
||||
* @returns {void}
|
||||
*/
|
||||
clearCache() {
|
||||
this.animationCache.clear();
|
||||
}
|
||||
clearCache () {
|
||||
this.animationCache.clear()
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get all cached animation names
|
||||
* @returns {string[]} Array of cached animation names
|
||||
*/
|
||||
getCachedAnimationNames() {
|
||||
return Array.from(this.animationCache.keys());
|
||||
}
|
||||
getCachedAnimationNames () {
|
||||
return Array.from(this.animationCache.keys())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user