-
Notifications
You must be signed in to change notification settings - Fork 1
BF-23 | ZRobisz guwno #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
d3a36d6
37cc727
a61ad00
f2b525a
919c4e2
7830a50
ae11b0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| import { Controller, OnRender, OnInit } from "@flamework/core"; | ||
| import { Canim, CanimPose, CanimTrack } from "@rbxts/canim"; | ||
| import { OnCharacterAdded } from "./core"; | ||
| import { Viewmodel } from "client/types/items"; | ||
| import { configs, ItemConfig } from "shared/configurations/items"; | ||
| import { RunService } from "@rbxts/services"; | ||
| import getObjectSize from "shared/getObjectSize"; | ||
| import { log } from "shared/log_message"; | ||
| import { Shobnode } from "client/shobnode"; | ||
|
|
||
| Shobnode.setup(); | ||
|
|
||
| export type CanimTracks = CanimPose | CanimTrack; | ||
| interface Tracks { | ||
| viewmodel: { [animationKey in string]: CanimTracks | undefined }; | ||
| character: { [animationKey in string]: CanimTracks | undefined }; | ||
| } | ||
|
|
||
| @Controller({}) | ||
| export class Animation implements OnRender, OnCharacterAdded, OnInit { | ||
| private viewmodelAnimator = new Canim(); | ||
| private characterAnimator = new Canim(); | ||
|
|
||
| private typeLookup: { [animationKey: string]: "Animation" | "Pose" } = {}; | ||
| private tracks: Tracks = { | ||
| viewmodel: {}, | ||
| character: {}, | ||
| }; | ||
|
|
||
| playAnimation = (animationKey: string): CanimTracks | undefined => { | ||
| const animationType = this.typeLookup[animationKey]; | ||
| if (!animationType) { | ||
| throw `Couldn't find type for given animationKey (animationKey: ${animationKey})`; | ||
| } | ||
|
|
||
| print(this.viewmodelAnimator.identified_bones); | ||
| print(this.characterAnimator.identified_bones); | ||
|
|
||
| const viewmodelTrack = | ||
| (animationType === "Animation" ? this.viewmodelAnimator.play_animation(animationKey) : this.viewmodelAnimator.play_pose(animationKey)) || undefined; | ||
| const characterTrack = | ||
| (animationType === "Animation" ? this.characterAnimator.play_animation(animationKey) : this.characterAnimator.play_pose(animationKey)) || undefined; | ||
|
|
||
| return viewmodelTrack; | ||
| }; | ||
|
|
||
| stopAnimation = (animationKey: string): void => { | ||
| this.viewmodelAnimator.stop_animation(animationKey); | ||
| this.characterAnimator.stop_animation(animationKey); | ||
| }; | ||
|
|
||
| getAnimationTrack = ( | ||
| animationKey: string, | ||
| scope: "Character" | "Viewmodel" | "Both" = "Both", | ||
| ): CanimTracks | undefined | [character: CanimTracks | undefined, viewmodel: CanimTracks | undefined] => { | ||
| const characterAnimationTrack = this.tracks.character[animationKey]; | ||
| const viewmodelAnimationTrack = this.tracks.viewmodel[animationKey]; | ||
|
|
||
| if (scope === "Character") return characterAnimationTrack; | ||
| if (scope === "Viewmodel") return viewmodelAnimationTrack; | ||
| if (scope === "Both") return [characterAnimationTrack, viewmodelAnimationTrack]; | ||
| }; | ||
|
|
||
| assignViewmodel = (viewmodel: Viewmodel) => { | ||
| this.viewmodelAnimator.assign_model(viewmodel); | ||
| }; | ||
|
|
||
| onCharacterAdded(character: Model): void { | ||
| this.characterAnimator.assign_model(character); | ||
| } | ||
|
|
||
| onInit(): void { | ||
| const globalChecksum = { | ||
| current: 0, | ||
| target: 0, | ||
| }; | ||
|
|
||
| configs.forEach((itemConfig: ItemConfig, itemName: string) => { | ||
| const amountOfAnimations = getObjectSize(itemConfig.animations); | ||
| globalChecksum.target += amountOfAnimations; | ||
|
|
||
| task.spawn(() => { | ||
| const loadedTracks: { [animationName in string]: { track: CanimTracks; trackType: "Animation" | "Pose"; rebased: boolean } } = {}; | ||
|
|
||
| for (const [animationName, animationProperties] of pairs(itemConfig.animations)) { | ||
| const key = `${itemName}/${animationName}`; | ||
| const id = `rbxassetid://${animationProperties.id}`; | ||
| const animationType = animationProperties.type; | ||
| const priority = animationProperties.priority; | ||
| const looped = animationProperties.looped || false; | ||
| const rebased = animationProperties.rebased ? animationProperties.rebased : true; | ||
| const fadeTime = animationProperties.fadeTime !== undefined ? animationProperties.fadeTime : 0; | ||
| const weights = animationProperties.weights; | ||
|
|
||
| let animation: CanimTrack | CanimPose; | ||
|
|
||
| if (animationType === "Animation") { | ||
| animation = this.viewmodelAnimator.load_animation(key, priority, id); | ||
| this.characterAnimator.load_animation(key, priority, id); | ||
| } else { | ||
| animation = this.viewmodelAnimator.load_pose(key, priority, id); | ||
| this.characterAnimator.load_pose(key, priority, id); | ||
| } | ||
|
|
||
| animation.finished_loading.Wait(); | ||
| globalChecksum.current += 1; | ||
|
|
||
| animation.looped = looped; | ||
| // eslint-disable-next-line camelcase | ||
| animation.fade_time = fadeTime; | ||
|
|
||
| if (weights !== undefined) { | ||
| for (const [bone, weight] of pairs(weights)) { | ||
| animation.bone_weights[bone] = weight; | ||
| } | ||
| } | ||
|
|
||
| loadedTracks[animationName] = { track: animation, trackType: animationType, rebased }; | ||
|
Comment on lines
+95
to
+118
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Configure character tracks the same as viewmodel tracks. Apply this diff: - let animation: CanimTrack | CanimPose;
-
- if (animationType === "Animation") {
- animation = this.viewmodelAnimator.load_animation(key, priority, id);
- this.characterAnimator.load_animation(key, priority, id);
- } else {
- animation = this.viewmodelAnimator.load_pose(key, priority, id);
- this.characterAnimator.load_pose(key, priority, id);
- }
-
- animation.finished_loading.Wait();
+ let viewmodelAnimation: CanimTracks;
+ let characterAnimation: CanimTracks;
+
+ if (animationType === "Animation") {
+ viewmodelAnimation = this.viewmodelAnimator.load_animation(key, priority, id);
+ characterAnimation = this.characterAnimator.load_animation(key, priority, id);
+ } else {
+ viewmodelAnimation = this.viewmodelAnimator.load_pose(key, priority, id);
+ characterAnimation = this.characterAnimator.load_pose(key, priority, id);
+ }
+
+ viewmodelAnimation.finished_loading.Wait();
+ characterAnimation.finished_loading.Wait();
globalChecksum.current += 1;
- animation.looped = looped;
- // eslint-disable-next-line camelcase
- animation.fade_time = fadeTime;
+ viewmodelAnimation.looped = looped;
+ characterAnimation.looped = looped;
+ // eslint-disable-next-line camelcase
+ viewmodelAnimation.fade_time = fadeTime;
+ // eslint-disable-next-line camelcase
+ characterAnimation.fade_time = fadeTime;
if (weights !== undefined) {
for (const [bone, weight] of pairs(weights)) {
- animation.bone_weights[bone] = weight;
+ viewmodelAnimation.bone_weights[bone] = weight;
+ characterAnimation.bone_weights[bone] = weight;
}
}
- loadedTracks[animationName] = { track: animation, trackType: animationType, rebased };
+ loadedTracks[animationName] = { track: viewmodelAnimation, trackType: animationType, rebased };
🤖 Prompt for AI Agents |
||
| this.typeLookup[key] = animationType; | ||
|
|
||
| log("verbose", `(${globalChecksum.current}/${globalChecksum.target}) animation ${animationName} for item ${itemName} sucesfully loaded`); | ||
| } | ||
|
|
||
| // const idle = loadedTracks.idle; | ||
| // if (idle) { | ||
| // const idleTrack = idle.track as CanimPose; | ||
| // for (const [animationName, { track, trackType, rebased }] of pairs(loadedTracks)) { | ||
| // print(`${animationName} rebased: ${rebased}`); | ||
| // if (trackType !== "Animation" || !rebased) continue; | ||
| // // eslint-disable-next-line camelcase | ||
| // (track as CanimTrack).rebase_target = idleTrack; | ||
| // } | ||
| // } | ||
| }); | ||
| }); | ||
|
|
||
| while (globalChecksum.current < globalChecksum.target) RunService.Heartbeat.Wait(); | ||
| } | ||
|
|
||
| onRender(dt: number): void { | ||
| this.viewmodelAnimator.update(dt); | ||
| this.characterAnimator.update(dt); | ||
|
|
||
| Shobnode.display_node(1231251241, new UDim2(0, 0, 0.8, 0), this.viewmodelAnimator.debug); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -3,11 +3,12 @@ import { Camera, Modifier } from "./camera"; | |||
| import { Input } from "./input"; | ||||
| import { UserInputService } from "@rbxts/services"; | ||||
| import { OnCharacterAdded } from "./core"; | ||||
| import { smoothClamp } from "shared/utilities/number_utility"; | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused import. The Apply this diff to remove the unused import: -import { smoothClamp } from "shared/utilities/number_utility";📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||
|
|
||||
| @Controller({}) | ||||
| export class Freelook implements OnStart, OnTick, OnCharacterAdded { | ||||
| static xAxisMax = 1; | ||||
| static yAxisMax = 1; | ||||
| static yAxisMax = 0.4; | ||||
|
|
||||
| private freelookModifier = Modifier.create("freelook", false, 2.5); | ||||
| private freelookActive = false; | ||||
|
|
@@ -30,7 +31,7 @@ export class Freelook implements OnStart, OnTick, OnCharacterAdded { | |||
|
|
||||
| onTick(dt: number): void { | ||||
| if (this.freelookActive) { | ||||
| const mouseDelta = UserInputService.GetMouseDelta().div(300); | ||||
| const mouseDelta = UserInputService.GetMouseDelta().div(270); | ||||
| this.freelookOffset = this.freelookOffset.add(mouseDelta.mul(-1)); | ||||
| } else { | ||||
| this.freelookOffset = this.freelookOffset.Lerp(Vector2.zero, 0.1); | ||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Store running tracks so
getAnimationTrackworks.We never populate
this.tracks, sogetAnimationTrackalways returnsundefined. Persist the tracks when playing and clear them when stopping.Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents