-
-
Notifications
You must be signed in to change notification settings - Fork 310
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
Update controller loader to enhance stateMachine and fix crossfade bug when dest state has no clip #2228
Update controller loader to enhance stateMachine and fix crossfade bug when dest state has no clip #2228
Conversation
Caution Review failedThe pull request is closed. WalkthroughThe recent updates enhance the animation module and the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
Outside diff range, codebase verification and nitpick comments (1)
packages/loader/src/AnimatorControllerLoader.ts (1)
Line range hint
28-107
: Review ofload
method inAnimatorControllerLoader
.
- Data Handling: The method correctly deconstructs and uses the
data
object to create and configureAnimatorController
instances. The handling of layers, states, and transitions appears logically correct.- Promises Handling: The use of promises to asynchronously load clips and resolve them once all are loaded is appropriate. However, the use of
//@ts-ignore
should be avoided if possible. Proper typing or error handling should be implemented instead.- Error Handling: The
catch(reject)
at the end is a good practice to handle potential errors in the promise chain.Consider adding more detailed comments explaining the logic, especially how transitions and states are mapped and managed.
- //@ts-ignore + // TODO: Properly type or handle the potential error here.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- packages/core/src/animation/Animator.ts (5 hunks)
- packages/core/src/animation/index.ts (1 hunks)
- packages/loader/src/AnimatorControllerLoader.ts (4 hunks)
Files skipped from review due to trivial changes (1)
- packages/core/src/animation/index.ts
Additional comments not posted (3)
packages/loader/src/AnimatorControllerLoader.ts (2)
10-15
: Imports and dependencies are correctly added.The new imports for
AnimatorState
,AnimatorConditionMode
,AnimatorControllerParameterValueType
,WrapMode
, andAnimatorControllerParameter
are correctly added and are necessary for the new features in theAnimatorControllerLoader
.
137-167
: Definition of interfacesIStateData
,ITransitionData
, andIConditionData
.The interfaces are well-defined and provide a clear structure for the data expected by the
AnimatorControllerLoader
. These interfaces will help ensure that the data used throughout the loader is consistent and correctly typed.
- Optional Properties: Ensure that the optional properties in these interfaces (
id
inIStateData
andITransitionData
,threshold
inIConditionData
) are truly optional and handled appropriately in the code.- Documentation: Consider adding comments to these interfaces to explain the purpose of each property, especially for those that might not be immediately obvious to other developers or future maintainers.
packages/core/src/animation/Animator.ts (1)
1167-1174
: Review of changes to_applyTransition
method.The method now returns a boolean indicating the success of the transition application. This is a significant change as it affects the control flow within the
Animator
class.
- Correctness: The method now checks if the transition is an exit transition and always returns
true
in that case, which seems logical. For other cases, it returns the result of_prepareCrossFadeByTransition
, which should be verified to ensure it handles all possible states correctly.- Impact on Control Flow: This change in return type should be carefully tested to ensure that it integrates well with the rest of the class and does not introduce unintended side effects.
Consider adding unit tests to cover various scenarios of transitions, especially testing the new boolean return value in different contexts.
Verification successful
Verification of
_applyTransition
method changes:The boolean return value of the
_applyTransition
method is correctly integrated and utilized in the control flow within theAnimator
class. The return value is used in conditional statements to determine subsequent actions, ensuring logical control flow.
- Correctness: The method correctly checks if the transition is an exit transition and returns
true
in that case. For other cases, it returns the result of_prepareCrossFadeByTransition
.- Impact on Control Flow: The return value is appropriately used to control the flow, as seen in the conditional checks and subsequent actions.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify integration of the new boolean return value in different scenarios. # Test: Search for usage of `_applyTransition` method. Expect: Proper handling of the return value. rg --type typescript -A 5 $'_applyTransition'Length of output: 79
Script:
#!/bin/bash # Description: Verify integration of the new boolean return value in different scenarios. # Test: Search for usage of `_applyTransition` method. Expect: Proper handling of the return value. rg --type ts -A 5 _applyTransitionLength of output: 4005
private _createTransition(transitionData: ITransitionData, destinationState: AnimatorState): AnimatorStateTransition { | ||
const transition = new AnimatorStateTransition(); | ||
transition.duration = transitionData.duration; | ||
transition.offset = transitionData.offset; | ||
transition.exitTime = transitionData.exitTime; | ||
transition.solo = transitionData.solo; | ||
transition.mute = transitionData.mute; | ||
// @ts-ignore | ||
transition._isExit = transitionData.isExit; | ||
transition.destinationState = destinationState; | ||
transitionData.conditions.forEach((conditionData) => { | ||
transition.addCondition(conditionData.mode, conditionData.parameterName, conditionData.threshold); | ||
}); | ||
return transition; | ||
} |
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.
Review of _createTransition
private method.
This method correctly creates and configures AnimatorStateTransition
instances based on the provided transitionData
. The handling of conditions is robust, ensuring that all conditions are added to the transition.
- Typing Issues: The use of
//@ts-ignore
should be addressed. If the TypeScript compiler emits errors, consider refining the type definitions or handling the potential issues explicitly. - Complexity: The method is straightforward and maintains a low complexity, which is good for maintainability.
- //@ts-ignore
+ // TODO: Address TypeScript typing issues here.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
private _createTransition(transitionData: ITransitionData, destinationState: AnimatorState): AnimatorStateTransition { | |
const transition = new AnimatorStateTransition(); | |
transition.duration = transitionData.duration; | |
transition.offset = transitionData.offset; | |
transition.exitTime = transitionData.exitTime; | |
transition.solo = transitionData.solo; | |
transition.mute = transitionData.mute; | |
// @ts-ignore | |
transition._isExit = transitionData.isExit; | |
transition.destinationState = destinationState; | |
transitionData.conditions.forEach((conditionData) => { | |
transition.addCondition(conditionData.mode, conditionData.parameterName, conditionData.threshold); | |
}); | |
return transition; | |
} | |
private _createTransition(transitionData: ITransitionData, destinationState: AnimatorState): AnimatorStateTransition { | |
const transition = new AnimatorStateTransition(); | |
transition.duration = transitionData.duration; | |
transition.offset = transitionData.offset; | |
transition.exitTime = transitionData.exitTime; | |
transition.solo = transitionData.solo; | |
transition.mute = transitionData.mute; | |
// TODO: Address TypeScript typing issues here. | |
transition._isExit = transitionData.isExit; | |
transition.destinationState = destinationState; | |
transitionData.conditions.forEach((conditionData) => { | |
transition.addCondition(conditionData.mode, conditionData.parameterName, conditionData.threshold); | |
}); | |
return transition; | |
} |
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- packages/loader/src/AnimatorControllerLoader.ts (4 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/loader/src/AnimatorControllerLoader.ts
4cb5b08
to
b49e319
Compare
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.
Caution
Inline review comments failed to post
Actionable comments posted: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- packages/loader/src/AnimatorControllerLoader.ts (4 hunks)
- packages/loader/src/gltf/parser/GLTFSceneParser.ts (1 hunks)
Additional context used
Biome
packages/loader/src/AnimatorControllerLoader.ts
[error] 129-129: This is an unexpected use of the debugger statement.
Unsafe fix: Remove debugger statement
(lint/suspicious/noDebugger)
Additional comments not posted (11)
packages/loader/src/AnimatorControllerLoader.ts (11)
11-15
: LGTM! New imports are necessary for the changes.The new imports for
AnimatorState
,AnimatorConditionMode
,AnimatorControllerParameterValueType
,WrapMode
, andAnimatorControllerParameter
are appropriate and necessary for the modifications in the file.
28-29
: Ensure correct handling ofdata
object.The destructuring of
data
to extractlayers
andparameters
is correct. Ensure that thedata
object always contains these properties.
36-39
: Efficient state and transition management.The introduction of
statesMap
andtransitionsMap
for efficient state and transition management is a good practice.
40-56
: Correct handling of state data.The handling of state data, including properties like
id
,name
,speed
,wrapMode
, etc., is correct. Ensure that all properties are always present in thestateData
object.
56-56
: Ensure script classes are available.The addition of state machine scripts using
Loader.getClass(script)
is correct. Ensure that the script classes are available and correctly loaded.
75-78
: Efficient transition creation.The creation of transitions using the
_createTransition
method and storing them intransitionsMap
is efficient and correct.
80-84
: Correctly adding transitions to states.The addition of transitions to states using
statesMap
andtransitionsMap
is correct. Ensure that all transition IDs are valid and present intransitionsMap
.
88-92
: Correct handling of entry transitions.The handling of entry transitions using the
_createTransition
method is correct. Ensure that all entry transition data is valid.
94-98
: Correct handling of any transitions.The handling of any transitions using the
_createTransition
method is correct. Ensure that all any transition data is valid.
102-107
: Correct handling of parameters.The handling of parameters, including creating instances of
AnimatorControllerParameter
and adding them to theanimatorController
, is correct. Ensure that all parameter data is valid.
138-163
: LGTM! New interfaces enhance type safety and clarity.The new interfaces
IStateData
,ITransitionData
, andIConditionData
are well-defined and improve the type safety and clarity of the code.
Comments failed to post (2)
packages/loader/src/AnimatorControllerLoader.ts
120-135: Address TypeScript typing issues and remove debugger statement.
The
_createTransition
method correctly creates and configuresAnimatorStateTransition
instances. However, the use of//@ts-ignore
should be addressed, and thedebugger
statement should be removed.- // @ts-ignore - transition._isExit = transitionData.isExit; - debugger; + // TODO: Address TypeScript typing issues here. + transition._isExit = transitionData.isExit;Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.private _createTransition(transitionData: ITransitionData, destinationState: AnimatorState): AnimatorStateTransition { const transition = new AnimatorStateTransition(); transition.duration = transitionData.duration; transition.offset = transitionData.offset; transition.exitTime = transitionData.exitTime; transition.solo = transitionData.solo; transition.mute = transitionData.mute; // TODO: Address TypeScript typing issues here. transition._isExit = transitionData.isExit; transition.destinationState = destinationState; transitionData.conditions.forEach((conditionData) => { transition.addCondition(conditionData.mode, conditionData.parameterName, conditionData.threshold); }); return transition; }
Tools
Biome
[error] 129-129: This is an unexpected use of the debugger statement.
Unsafe fix: Remove debugger statement
(lint/suspicious/noDebugger)
packages/loader/src/gltf/parser/GLTFSceneParser.ts
37-38: Address TypeScript typing issues and remove
//@ts-ignore
.The new line of code marks
sceneRoot
as a template usingglTFResource
. The use of//@ts-ignore
should be addressed to ensure type safety.- // @ts-ignore - sceneRoot._markAsTemplate(glTFResource); + // TODO: Address TypeScript typing issues here. + (sceneRoot as any)._markAsTemplate(glTFResource);Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.// TODO: Address TypeScript typing issues here. (sceneRoot as any)._markAsTemplate(glTFResource);
b49e319
to
5505473
Compare
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
What is the current behavior? (You can also link to an open issue here)
What is the new behavior (if this is a feature change)?
Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
Other information:
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
_applyTransition
method to return a boolean, improving method reliability and control flow.Documentation