-
Notifications
You must be signed in to change notification settings - Fork 111
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
change: modify behavior of expressions, interaction between isBinary and override #1489
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3913e81
change: modify behavior of expressions according the recent discussion
0b5vr 5afd3fc
fix: expressions, update isBinary behavior according to the spec
0b5vr abe19fd
test: expressions, update test according to the spec
0b5vr 68a10ad
refactor: trivial unused code cleanup
0b5vr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
190 changes: 190 additions & 0 deletions
190
packages/three-vrm-core/src/expressions/tests/VRMExpression.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
import { VRMExpression } from '../VRMExpression'; | ||
import { VRMExpressionBind } from '../VRMExpressionBind'; | ||
|
||
class VRMExpressionMockBind implements VRMExpressionBind { | ||
public weight = 0.0; | ||
|
||
public applyWeight(weight: number): void { | ||
this.weight += weight; | ||
} | ||
|
||
public clearAppliedWeight(): void { | ||
this.weight = 0.0; | ||
} | ||
} | ||
|
||
describe('VRMExpression', () => { | ||
let expression: VRMExpression; | ||
|
||
beforeEach(() => { | ||
expression = new VRMExpression('aa'); | ||
}); | ||
|
||
describe('outputWeight', () => { | ||
it('returns the weight if the expression is not binary', () => { | ||
expression.weight = 0.64; | ||
expect(expression.outputWeight).toBe(0.64); | ||
}); | ||
|
||
it('returns 0.0 if the expression is binary and the weight is less than 0.5', () => { | ||
expression.isBinary = true; | ||
expression.weight = 0.3; | ||
expect(expression.outputWeight).toBe(0.0); | ||
}); | ||
|
||
it('returns 1.0 if the expression is binary and the weight is more than 0.5', () => { | ||
expression.isBinary = true; | ||
expression.weight = 0.7; | ||
expect(expression.outputWeight).toBe(1.0); | ||
}); | ||
|
||
it('returns 0.0 if the expression is binary and the weight is exactly 0.5', () => { | ||
expression.isBinary = true; | ||
expression.weight = 0.5; | ||
expect(expression.outputWeight).toBe(0.0); | ||
}); | ||
}); | ||
|
||
describe('overrideBlinkAmount', () => { | ||
it('returns 0.0 when the overrideBlink is none', () => { | ||
expression.overrideBlink = 'none'; | ||
expression.weight = 0.75; | ||
expect(expression.overrideBlinkAmount).toBe(0.0); | ||
}); | ||
|
||
it('returns the override amount when the overrideBlink is blend', () => { | ||
expression.overrideBlink = 'blend'; | ||
expression.weight = 0.75; | ||
expect(expression.overrideBlinkAmount).toBe(0.75); | ||
}); | ||
|
||
it('returns 1.0 when the overrideBlink is block and the weight is not zero', () => { | ||
expression.overrideBlink = 'block'; | ||
expression.weight = 0.1; | ||
expect(expression.overrideBlinkAmount).toBe(1.0); | ||
}); | ||
|
||
it('returns 0.0 when the overrideBlink is block and the weight is exactly zero', () => { | ||
expression.overrideBlink = 'block'; | ||
expression.weight = 0.0; | ||
expect(expression.overrideBlinkAmount).toBe(0.0); | ||
}); | ||
|
||
it('returns 0.0 when the expression is binary, the overrideBlink is blend, and the weight is less than 0.5', () => { | ||
expression.overrideBlink = 'blend'; | ||
expression.isBinary = true; | ||
expression.weight = 0.3; | ||
expect(expression.overrideBlinkAmount).toBe(0.0); | ||
}); | ||
|
||
it('returns 1.0 when the expression is binary, the overrideBlink is blend, and the weight is more than 0.5', () => { | ||
expression.overrideBlink = 'blend'; | ||
expression.isBinary = true; | ||
expression.weight = 0.7; | ||
expect(expression.overrideBlinkAmount).toBe(1.0); | ||
}); | ||
|
||
it('returns 0.0 when the expression is binary, the overrideBlink is block, and the weight is less than 0.5', () => { | ||
expression.overrideBlink = 'block'; | ||
expression.isBinary = true; | ||
expression.weight = 0.3; | ||
expect(expression.overrideBlinkAmount).toBe(0.0); | ||
}); | ||
|
||
it('returns 1.0 when the expression is binary, the overrideBlink is block, and the weight is more than 0.5', () => { | ||
expression.overrideBlink = 'block'; | ||
expression.isBinary = true; | ||
expression.weight = 0.7; | ||
expect(expression.overrideBlinkAmount).toBe(1.0); | ||
}); | ||
}); | ||
|
||
describe('applyWeight', () => { | ||
it('applies the weight to the binds', () => { | ||
const bind1 = new VRMExpressionMockBind(); | ||
const bind2 = new VRMExpressionMockBind(); | ||
expression.addBind(bind1); | ||
expression.addBind(bind2); | ||
|
||
expression.weight = 0.64; | ||
expression.applyWeight(); | ||
|
||
expect(bind1.weight).toBe(0.64); | ||
expect(bind2.weight).toBe(0.64); | ||
}); | ||
|
||
it('applies the 0.0 if the expression is binary and the weight is less than 0.5', () => { | ||
expression.isBinary = true; | ||
|
||
const bind = new VRMExpressionMockBind(); | ||
expression.addBind(bind); | ||
|
||
expression.weight = 0.3; | ||
expression.applyWeight(); | ||
|
||
expect(bind.weight).toBe(0.0); | ||
}); | ||
|
||
it('applies the 1.0 if the expression is binary and the weight is more than 0.5', () => { | ||
expression.isBinary = true; | ||
|
||
const bind = new VRMExpressionMockBind(); | ||
expression.addBind(bind); | ||
|
||
expression.weight = 0.7; | ||
expression.applyWeight(); | ||
|
||
expect(bind.weight).toBe(1.0); | ||
}); | ||
|
||
it('applies the 0.0 if the expression is binary and the weight is exactly 0.5', () => { | ||
expression.isBinary = true; | ||
|
||
const bind = new VRMExpressionMockBind(); | ||
expression.addBind(bind); | ||
|
||
expression.weight = 0.5; | ||
expression.applyWeight(); | ||
|
||
expect(bind.weight).toBe(0.0); | ||
}); | ||
|
||
it('applies the weight with the override multiplier', () => { | ||
const bind = new VRMExpressionMockBind(); | ||
expression.addBind(bind); | ||
|
||
expression.weight = 0.75; | ||
expression.applyWeight({ multiplier: 0.5 }); | ||
|
||
expect(bind.weight).toBe(0.375); | ||
}); | ||
|
||
it('applies the 0.0 if the expression is binary and the override multiplier is less than 1.0', () => { | ||
expression.isBinary = true; | ||
|
||
const bind = new VRMExpressionMockBind(); | ||
expression.addBind(bind); | ||
|
||
expression.weight = 0.7; | ||
expression.applyWeight({ multiplier: 0.99 }); | ||
|
||
expect(bind.weight).toBe(0.0); | ||
}); | ||
}); | ||
|
||
describe('clearAppliedWeight', () => { | ||
it('clears the applied weight from the binds', () => { | ||
const bind1 = new VRMExpressionMockBind(); | ||
const bind2 = new VRMExpressionMockBind(); | ||
bind1.applyWeight(0.82); | ||
bind2.applyWeight(0.48); | ||
expression.addBind(bind1); | ||
expression.addBind(bind2); | ||
|
||
expression.clearAppliedWeight(); | ||
|
||
expect(bind1.weight).toBe(0.0); | ||
expect(bind2.weight).toBe(0.0); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
VRMExpressionManager
is only referred from a doc comment