Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- rename easing expressions for consitency
- add warning to scene loader when camera path is not specified - add actor/easing - add actor/fit - add actor/setObjectPolarTransform - fix lerp in actor/setObjectAttribute
- Loading branch information
Showing
29 changed files
with
1,175 additions
and
212 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {Vector3, Quaternion, Object3D, Matrix4, MathUtils} from 'three'; | ||
|
||
export interface PolarTransformMatrixParams { | ||
center: Vector3; | ||
longitude: number; | ||
latitude: number; | ||
depth: number; | ||
} | ||
|
||
const POLAR_TRANSFORM_AXIS_VERTICAL = new Vector3(0, 1, 0); | ||
const POLAR_TRANSFORM_AXIS_HORIZONTAL = new Vector3(-1, 0, 0); | ||
|
||
const centerMatrix = new Matrix4(); | ||
const longitudeMatrix = new Matrix4(); | ||
const latitudeMatrix = new Matrix4(); | ||
const depthMatrix = new Matrix4(); | ||
const decomposed = { | ||
t: new Vector3(), | ||
q: new Quaternion(), | ||
s: new Vector3(), | ||
}; | ||
|
||
export class CorePolarTransform { | ||
static matrix(params: PolarTransformMatrixParams, target: Matrix4) { | ||
centerMatrix.identity(); | ||
longitudeMatrix.identity(); | ||
latitudeMatrix.identity(); | ||
depthMatrix.identity(); | ||
centerMatrix.makeTranslation(params.center.x, params.center.y, params.center.z); | ||
longitudeMatrix.makeRotationAxis(POLAR_TRANSFORM_AXIS_VERTICAL, MathUtils.degToRad(params.longitude)); | ||
latitudeMatrix.makeRotationAxis(POLAR_TRANSFORM_AXIS_HORIZONTAL, MathUtils.degToRad(params.latitude)); | ||
depthMatrix.makeTranslation(0, 0, params.depth); | ||
target.copy(centerMatrix).multiply(longitudeMatrix).multiply(latitudeMatrix).multiply(depthMatrix); | ||
} | ||
static applyMatrixToObject(object: Object3D, matrix: Matrix4) { | ||
matrix.decompose(decomposed.t, decomposed.q, decomposed.s); | ||
object.position.copy(decomposed.t); | ||
object.quaternion.copy(decomposed.q); | ||
object.scale.copy(decomposed.s); | ||
object.updateMatrix(); | ||
} | ||
} |
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,57 @@ | ||
import {Vector2Like} from './../../types/GlobalTypes'; | ||
import {CubicBezierCurve, Vector2} from 'three'; | ||
export interface KeyframeData { | ||
pos: number; | ||
value: number; | ||
tan: Vector2Like; | ||
} | ||
export type ChannelData = KeyframeData[]; | ||
export interface ChannelsData { | ||
[Key: string]: ChannelData; | ||
} | ||
|
||
const tmp = new Vector2(); | ||
// const tmp2 = new Vector2(); | ||
export function cubicBezierCurveFromKeyframes(unsortedKeyframes: KeyframeData[]): CubicBezierCurve[] { | ||
const list: CubicBezierCurve[] = []; | ||
if (unsortedKeyframes.length < 2) { | ||
return list; | ||
} | ||
const keyframes = unsortedKeyframes.sort((k1, k2) => k1.pos - k2.pos); | ||
|
||
for (let i = 0; i < keyframes.length - 1; i++) { | ||
const currentKeyframe = keyframes[i]; | ||
const nextKeyframe = keyframes[i + 1]; | ||
// p0 | ||
const p0 = new Vector2(currentKeyframe.pos, currentKeyframe.value); | ||
// p1 | ||
tmp.set(currentKeyframe.tan.x, currentKeyframe.tan.y); | ||
const p1 = new Vector2(currentKeyframe.pos, currentKeyframe.value).add(tmp); | ||
// p2 | ||
tmp.set(nextKeyframe.tan.x, nextKeyframe.tan.y); | ||
const p2 = new Vector2(nextKeyframe.pos, nextKeyframe.value).sub(tmp); | ||
// p3 | ||
const p3 = new Vector2(nextKeyframe.pos, nextKeyframe.value); | ||
// curve | ||
const curve = new CubicBezierCurve(p0, p1, p2, p3); | ||
list.push(curve); | ||
} | ||
return list; | ||
} | ||
|
||
export function getPointFromCurves(t: number, curves: CubicBezierCurve[], target: Vector2) { | ||
let selectedCurve: CubicBezierCurve | undefined; | ||
for (let curve of curves) { | ||
if (t <= curve.v3.x) { | ||
selectedCurve = curve; | ||
break; | ||
} | ||
} | ||
if (selectedCurve == null) { | ||
return 0; | ||
} | ||
const minT = selectedCurve.v0.x; | ||
const maxT = selectedCurve.v3.x; | ||
const remappedT = (t - minT) / (maxT - minT); | ||
selectedCurve.getPoint(remappedT, target); | ||
} |
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
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
Oops, something went wrong.