-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* NewGenAnim * Fix/Optimize simple directional blending * Class transition by type (#29) * Transition & Gradient transition (#30) * The default ExitCondition should be 1.0 * Do correct graph eval * Fix PoseSubgraph connect() signature order (#31) * Graph defaults test (#32) * Conditions (#33) * Trigger (#34) * Transition should only be considered when satemachine exited (#35) * Add layer.name (#36) * Fix some behaviours; add API to query poses and transition (#37) Fix single frame exit condition behaviours; Fix pose -> subgraph behaviours * Support self transition; refactor sub state machine implementation (#38) * Temp * Flat whole layer statemachine * Add test for test reset triggers * Allow self transition * Self transition test * Fix deserialize (#39) * update animgraph template (#40) * The inheritance of any state (#41) * StateMachine events (#42) * Fix state machine events; Allow multiple transitions between two nodes (#43) * Transition priority test (#44) * Optimize variable bind (#45) * Fix variable bind errors (#46) * Expose blend algorithm to editor (#47) * Cont (#48) * update animgraph template (#49) * update animgraph template * update animgraph template * Pose speed (#50) * blend tree add EditorExtendable data (#51) * Correct pose blend duration (#52) * Export some types (#53) * animation pose EditorExtendable (#54) (cherry picked from commit d5dd5f3) * Implement clone() (#55) * Fix trigger condition serialization (#56) * Add variable type: integer (#57) * Optimize 0 weight case (#58) * Relative duration (#59) * update_hdr_skybox (#9230) * Rename.. (#60) * Optimize animation blend item export (#61) * Fix Type (#62) * modify aniamtion graph template data (#63) * modify aniamtion graph template data * add animation graph component template * Fix serialize issue (#64) * Optimize (#65) * Remove MotionState.startRatio, loop (#66) * Update (#67) * Fix circular reference (#68) * CR (#69) * Fix exit time greater than 1 (#70) Co-authored-by: 黄森斌 <arsen2010@126.com> Co-authored-by: linshunjun <49218738+linshunjun@users.noreply.github.com>
- Loading branch information
1 parent
f54c8f5
commit 8488972
Showing
73 changed files
with
6,072 additions
and
6 deletions.
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
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
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
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
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,110 @@ | ||
|
||
import { assertIsTrue } from '../../data/utils/asserts'; | ||
import { Quat } from '../../math/quat'; | ||
import { clamp } from '../../math/utils'; | ||
import { Vec3 } from '../../math/vec3'; | ||
import { Node } from '../../scene-graph/node'; | ||
|
||
const THETA_ERROR = 0.001; | ||
const DUMP_BIAS = 1.0; | ||
|
||
enum IterationResult { | ||
UNFINISHED, | ||
DONE, | ||
INTERRUPTED, | ||
} | ||
|
||
/** | ||
* The Cyclic Coordinate Descent algorithm. | ||
* @param links The links(limbs). | ||
* @param target Target position. | ||
* @param maxIterations Max iterations. | ||
* @param forward True if use forward iteration(base to leaf), otherwise use backward iteration(leaf to base). | ||
*/ | ||
export function ccdIK( | ||
links: Node[], | ||
target: Vec3, | ||
epsilon: number, | ||
maxIterations: number, | ||
forward: boolean, | ||
) { | ||
const nLinks = links.length; | ||
if (nLinks < 2) { | ||
return; | ||
} | ||
|
||
const u = new Vec3(); // Vector from end factor to current link | ||
const v = new Vec3(); // Vector from target to current link | ||
const axis = new Vec3(); // Intermediate var | ||
const correctiveRot = new Quat(); | ||
const currentPos = new Vec3(); | ||
const currentRot = new Quat(); | ||
const endFactorPos = new Vec3(); | ||
|
||
const iEndFactor = links.length - 1; | ||
const endFactor = links[iEndFactor]; | ||
if (forward) { | ||
for (let iteration = 0; iteration < maxIterations; ++iteration) { | ||
// Won't run in infinite loop since we have `nLinks >= 2` | ||
for (let iLink = 0; iLink < iEndFactor; ++iLink) { | ||
const result = correct(iLink); | ||
if (result === IterationResult.INTERRUPTED) { | ||
break; | ||
} else if (result === IterationResult.DONE) { | ||
return; | ||
} | ||
} | ||
} | ||
} else { | ||
for (let iteration = 0; iteration < maxIterations; ++iteration) { | ||
// Won't run in infinite loop since we have `nLinks >= 2` | ||
for (let iLink = iEndFactor - 1; iLink >= 0; --iLink) { | ||
const result = correct(iLink); | ||
if (result === IterationResult.INTERRUPTED) { | ||
break; | ||
} else if (result === IterationResult.DONE) { | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
|
||
function correct (linkIndex: number): IterationResult { | ||
const current = links[linkIndex]; | ||
|
||
current.getWorldPosition(currentPos); | ||
endFactor.getWorldPosition(endFactorPos); | ||
|
||
Vec3.subtract(u, endFactorPos, currentPos); | ||
Vec3.normalize(u, u); | ||
Vec3.subtract(v, target, currentPos); | ||
Vec3.normalize(v, v); | ||
|
||
// TODO: what if axis is zero? | ||
Vec3.cross(axis, u, v); | ||
Vec3.normalize(axis, axis); | ||
|
||
const cosTheta = Vec3.dot(u, v); | ||
const theta = Math.acos(cosTheta) * DUMP_BIAS; | ||
|
||
// Refresh hierarchy | ||
Quat.fromAxisAngle(correctiveRot, axis, theta); | ||
current.getWorldRotation(currentRot); | ||
Quat.multiply(currentRot, correctiveRot, currentRot); | ||
current.setWorldRotation(currentRot); | ||
endFactor.getWorldPosition(endFactorPos); | ||
|
||
// Try | ||
const distance = Vec3.distance(endFactorPos, target); | ||
if (distance < epsilon) { | ||
return IterationResult.DONE; | ||
} | ||
|
||
// If the link’s corrective rotations exceeds the tolerance-redo other links. | ||
if (theta > THETA_ERROR) { | ||
return IterationResult.INTERRUPTED; | ||
} | ||
|
||
return IterationResult.UNFINISHED; | ||
} | ||
} |
168 changes: 168 additions & 0 deletions
168
cocos/core/animation/marionette/__tmp__/get-demo-graphs.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,168 @@ | ||
import { GraphDescription } from './graph-description'; | ||
import { AnimationGraph } from '../animation-graph'; | ||
import { createGraphFromDescription } from './graph-from-description'; | ||
|
||
export function __getDemoGraphs () { | ||
return Object.entries(graphDescMap).reduce((result, [name, graphDesc]) => { | ||
result[name] = createGraphFromDescription(graphDesc); | ||
return result; | ||
}, {} as Record<string, AnimationGraph>); | ||
} | ||
|
||
const graphDescMap: Record<string, GraphDescription> = { | ||
'any-transition': { | ||
layers: [{ | ||
graph: { | ||
type: 'state-machine', | ||
nodes: [{ | ||
name: 'Node1', | ||
type: 'animation', | ||
}], | ||
anyTransitions: [{ | ||
to: 0, | ||
}], | ||
}, | ||
}], | ||
}, | ||
|
||
vars: { | ||
vars: [ | ||
{ name: 'foo', value: 1.0 }, | ||
{ name: 'bar', value: false }, | ||
], | ||
layers: [{ | ||
graph: { | ||
type: 'state-machine', | ||
nodes: [{ | ||
name: 'Node1', | ||
type: 'animation', | ||
}, { | ||
name: 'Node2', | ||
type: 'animation', | ||
}], | ||
anyTransitions: [{ | ||
to: 0, | ||
}], | ||
transitions: [{ | ||
from: 0, | ||
to: 1, | ||
conditions: [{ | ||
type: 'binary', | ||
lhs: 'foo', | ||
operator: 'EQUAL', | ||
rhs: 2.0, | ||
}], | ||
}], | ||
}, | ||
}], | ||
}, | ||
|
||
'pose-blend-requires-numbers': { | ||
vars: [{ | ||
name: 'v', | ||
value: false, | ||
}], | ||
layers: [{ | ||
graph: { | ||
type: 'state-machine', | ||
nodes: [{ | ||
name: 'Node1', | ||
type: 'animation', | ||
motion: { | ||
type: 'blend', | ||
children: [{ type: 'clip' }, { type: 'clip' }], | ||
blender: { | ||
type: '1d', | ||
thresholds: [0.0, 1.0], | ||
value: { | ||
name: 'v', | ||
value: 0, | ||
}, | ||
}, | ||
}, | ||
}], | ||
}, | ||
}], | ||
}, | ||
|
||
'successive-satisfaction': { | ||
layers: [{ | ||
graph: { | ||
type: 'state-machine', | ||
nodes: [{ | ||
name: 'Node1', | ||
type: 'animation', | ||
}, { | ||
name: 'Node2', | ||
type: 'animation', | ||
}], | ||
entryTransitions: [{ | ||
to: 0, | ||
}], | ||
transitions: [{ | ||
from: 0, | ||
to: 1, | ||
}], | ||
}, | ||
}], | ||
}, | ||
|
||
'unspecified-condition': { | ||
layers: [{ | ||
graph: { | ||
type: 'state-machine', | ||
nodes: [{ | ||
name: 'asd', | ||
type: 'animation', | ||
}], | ||
entryTransitions: [{ | ||
to: 0, | ||
}], | ||
}, | ||
}], | ||
}, | ||
|
||
'variable-not-found-in-condition': { | ||
layers: [{ | ||
graph: { | ||
type: 'state-machine', | ||
nodes: [{ | ||
type: 'animation', | ||
name: 'Node1', | ||
}], | ||
entryTransitions: [{ | ||
to: 0, | ||
conditions: [{ | ||
type: 'unary', | ||
operator: 'TRUTHY', | ||
operand: { name: 'asd', value: 0.0 }, | ||
}], | ||
}], | ||
}, | ||
}], | ||
}, | ||
|
||
'variable-not-found-in-pose-blend': { | ||
layers: [{ | ||
graph: { | ||
type: 'state-machine', | ||
nodes: [{ | ||
name: 'Node1', | ||
type: 'animation', | ||
motion: { | ||
type: 'blend', | ||
children: [{ type: 'clip' }, { type: 'clip' }], | ||
blender: { | ||
type: '1d', | ||
thresholds: [0.0, 1.0], | ||
value: { | ||
name: 'asd', | ||
value: 0, | ||
}, | ||
}, | ||
}, | ||
}], | ||
}, | ||
}], | ||
}, | ||
}; |
Oops, something went wrong.