feat: Enhance asset and human event handling with animation and loop capabilities

This commit is contained in:
2025-07-02 17:31:17 +05:30
parent 2f0acbda3c
commit 424df54ff7
8 changed files with 192 additions and 170 deletions

View File

@@ -22,7 +22,8 @@ interface AssetsStore {
// Animation controls
setAnimations: (modelUuid: string, animations: string[]) => void;
setCurrentAnimation: (modelUuid: string, current: string, isPlaying: boolean) => void;
setCurrentAnimation: (modelUuid: string, current: string, isisPlaying: boolean, loopAnimation: boolean) => void;
resetAnimation: (modelUuid: string) => void;
addAnimation: (modelUuid: string, animation: string) => void;
removeAnimation: (modelUuid: string, animation: string) => void;
@@ -149,18 +150,28 @@ export const createAssetStore = () => {
if (asset) {
asset.animations = animations;
if (!asset.animationState) {
asset.animationState = { current: '', playing: false };
asset.animationState = { current: '', isPlaying: false, loopAnimation: true };
}
}
});
},
setCurrentAnimation: (modelUuid, current, isPlaying) => {
setCurrentAnimation: (modelUuid, current, isisPlaying, loopAnimation) => {
set((state) => {
const asset = state.assets.find(a => a.modelUuid === modelUuid);
if (asset?.animationState) {
asset.animationState.current = current;
asset.animationState.playing = isPlaying;
asset.animationState.isPlaying = isisPlaying;
asset.animationState.loopAnimation = loopAnimation;
}
});
},
resetAnimation: (modelUuid) => {
set((state) => {
const asset = state.assets.find(a => a.modelUuid === modelUuid);
if (asset?.animationState) {
asset.animationState = { current: '', isPlaying: false, loopAnimation: true };
}
});
},
@@ -184,7 +195,7 @@ export const createAssetStore = () => {
if (asset?.animations) {
asset.animations = asset.animations.filter(a => a !== animation);
if (asset.animationState?.current === animation) {
asset.animationState.playing = false;
asset.animationState.isPlaying = false;
asset.animationState.current = '';
}
}

View File

@@ -15,6 +15,7 @@ interface BuilderState {
// Floor Asset
selectedFloorAsset: Object3D | null;
loopAnimation: boolean;
// Wall Settings
selectedWall: Object3D | null;
@@ -64,6 +65,7 @@ interface BuilderState {
// Setters - Floor Asset
setSelectedFloorAsset: (asset: Object3D | null) => void;
setLoopAnimation: (loop: boolean) => void;
// Setters - Wall
setSelectedWall: (wall: Object3D | null) => void;
@@ -118,6 +120,7 @@ export const useBuilderStore = create<BuilderState>()(
deletableWallAsset: null,
selectedFloorAsset: null,
loopAnimation: true,
selectedWall: null,
wallThickness: 0.5,
@@ -197,6 +200,12 @@ export const useBuilderStore = create<BuilderState>()(
});
},
setLoopAnimation(loopAnimation: boolean) {
set((state) => {
state.loopAnimation = loopAnimation;
});
},
// === Setters: Wall ===
setSelectedWall: (wall: Object3D | null) => {