Skip to content

Commit f67ac59

Browse files
committed
Enhance NightStalker model animation handling
- Introduced `NightStalkerAnimationKeys` enum and `nightStalkerAnimationMap` for better organization of animation keys and their corresponding file paths. - Updated `nightStalkerModelMetadata` to utilize the new animation mapping, improving clarity and maintainability. - Adjusted `useModelDebug` to ensure proper handling of debug mode settings. - Removed the `isStatic` property from `IAnimationConfig` to streamline animation configuration.
1 parent c9eef77 commit f67ac59

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

src/config/assets/nightStalkerAssetsMetadata.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
import { AssetKeys, IModelAssetMetadata, IModelConfig } from '@/core/types/assets';
22

3+
// Animation keys for NightStalker
4+
export enum NightStalkerAnimationKeys {
5+
StandingIdle = 'StandingIdle',
6+
// Add more animation keys as needed
7+
}
8+
9+
// Animation key-value mapping for NightStalker
10+
export const nightStalkerAnimationMap: Record<NightStalkerAnimationKeys, string> = {
11+
[NightStalkerAnimationKeys.StandingIdle]:
12+
'/assets/models/NightStalker/animations/NightStalker_Standing_Idle.glb',
13+
// Add more mappings as needed
14+
};
15+
316
export const nightStalkerModelMetadata: IModelAssetMetadata = {
417
key: AssetKeys.NightStalkerModel,
518
type: 'gltf',
@@ -9,15 +22,13 @@ export const nightStalkerModelMetadata: IModelAssetMetadata = {
922
position: [0, 0, 0],
1023
rotation: [0, 0, 0],
1124
offset: [0, 0, 0],
12-
animations: ['/assets/models/NightStalker/animations/NightStalker_Standing_Idle.glb'],
25+
animations: [NightStalkerAnimationKeys.StandingIdle],
1326
animationConfig: {
14-
isStatic: false,
1527
loop: true,
1628
timeScale: 1.0,
1729
clampWhenFinished: false,
1830
blendDuration: 0.5,
1931
crossFadeEnabled: true,
20-
disableAnimations: false,
2132
},
2233
collision: {
2334
enabled: true,
@@ -30,7 +41,7 @@ export const nightStalkerModelMetadata: IModelAssetMetadata = {
3041
layer: 'character',
3142
},
3243
debugMode: {
33-
enabled: true,
44+
enabled: false,
3445
showBoundingBox: true,
3546
showColliders: true,
3647
showWireframe: false,

src/core/configs/model-example.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export const exampleCharacterConfig: IModelConfig = {
1313
initialAnimation: 'Idle',
1414
animations: ['Idle', 'Walk', 'Run', 'Jump'],
1515
animationConfig: {
16-
isStatic: false,
1716
loop: true,
1817
timeScale: 1.0,
1918
clampWhenFinished: false,

src/core/hooks/useModelDebug.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function useModelDebug({ model, config, debug = false }: IUseModelDebugOp
1515
const boxRef = useRef<THREE.Box3>(new THREE.Box3());
1616

1717
// Check if debugMode is enabled
18-
const debugMode = config?.debugMode?.enabled || debug;
18+
const debugMode = config?.debugMode ? config.debugMode.enabled : debug;
1919
const debugSettings = config?.debugMode;
2020
const debugColor = debugSettings?.debugColor
2121
? new THREE.Color(

src/core/types/assets.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export interface IBaseAssetMetadata {
1515

1616
// Animation configuration
1717
export interface IAnimationConfig {
18-
isStatic: boolean; // Whether the model has animations
1918
loop: boolean; // Whether to loop the animation
2019
timeScale: number; // Playback speed (1.0 = normal, 0.5 = half speed, etc.)
2120
clampWhenFinished: boolean; // Hold the last frame when animation completes

src/game/models/NightStalkerModel.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { useEffect, useMemo, useRef } from 'react';
22
import * as THREE from 'three';
33

4-
import { nightStalkerModelMetadata } from '@/config/assets/nightStalkerAssetsMetadata';
4+
import {
5+
NightStalkerAnimationKeys,
6+
nightStalkerAnimationMap,
7+
nightStalkerModelMetadata,
8+
} from '@/config/assets/nightStalkerAssetsMetadata';
59
import { useAnimationFromAsset } from '@/core/hooks/useAnimationFromAsset';
610
import { useAsset } from '@/core/hooks/useAsset';
711
import { useModelDebug } from '@/core/hooks/useModelDebug';
@@ -31,8 +35,11 @@ export function NightStalkerModel({ debug = true, onAnimationsReady }: INightSta
3135
// Memoize animationUrls array to prevent re-renders
3236
const animationSources = useMemo(() => {
3337
if (!modelConfig?.animations) return [];
34-
// Default to 'gltf' type for all animations; adjust if you support more types
35-
return modelConfig.animations.map((anim: string) => ({ url: anim, type: 'gltf' as const }));
38+
// Map animation keys to URLs using the animation map
39+
return modelConfig.animations.map((animKey) => ({
40+
url: nightStalkerAnimationMap[animKey as NightStalkerAnimationKeys],
41+
type: 'gltf' as const,
42+
}));
3643
}, [modelConfig?.animations]);
3744

3845
// Check if model is loaded

0 commit comments

Comments
 (0)