-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change: VRMAnimation LookAt is now local space quaternion instead of …
…model space translation See: vrm-c/vrm-specification#456 transfer quaternion to VRMLookAt yaw-pitch using VRMLookAtQuaternionProxy (does it look good?)
- Loading branch information
Showing
9 changed files
with
86 additions
and
35 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
Binary file not shown.
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
7 changes: 7 additions & 0 deletions
7
packages/three-vrm-animation/src/VRMAnimationLoaderPluginOptions.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,7 @@ | ||
export interface VRMAnimationLoaderPluginOptions { | ||
/** | ||
* Specify a desired frame rate in case if the animation need to be baked. | ||
* Animation bake occurs when the lookAt target is not a direct child of the root. | ||
*/ | ||
bakeFrameRate?: number; | ||
} |
39 changes: 39 additions & 0 deletions
39
packages/three-vrm-animation/src/VRMLookAtQuaternionProxy.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,39 @@ | ||
import { VRMLookAt } from '@pixiv/three-vrm-core'; | ||
import * as THREE from 'three'; | ||
|
||
const RAD2DEG = 180 / Math.PI; | ||
|
||
const _eulerA = /*@__PURE__*/ new THREE.Euler(); | ||
|
||
export class VRMLookAtQuaternionProxy extends THREE.Object3D { | ||
public readonly vrmLookAt: VRMLookAt; | ||
public override readonly type: string | 'VRMLookAtQuaternionProxy'; | ||
|
||
public constructor(lookAt: VRMLookAt) { | ||
super(); | ||
|
||
this.vrmLookAt = lookAt; | ||
|
||
this.type = 'VRMLookAtQuaternionProxy'; | ||
|
||
// See: https://github.com/mrdoob/three.js/blob/r158/src/core/Object3D.js#L65 | ||
const prevRotationOnChangeCallback = this.rotation._onChangeCallback; | ||
this.rotation._onChange(() => { | ||
prevRotationOnChangeCallback(); | ||
this._applyToLookAt(); | ||
}); | ||
|
||
const prevQuaternionOnChangeCallback = this.quaternion._onChangeCallback; | ||
this.quaternion._onChange(() => { | ||
prevQuaternionOnChangeCallback(); | ||
this._applyToLookAt(); | ||
}); | ||
} | ||
|
||
private _applyToLookAt(): void { | ||
_eulerA.setFromQuaternion(this.quaternion, VRMLookAt.EULER_ORDER); | ||
|
||
this.vrmLookAt.yaw = RAD2DEG * _eulerA.y; | ||
this.vrmLookAt.pitch = RAD2DEG * _eulerA.x; | ||
} | ||
} |
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