11import { dof8 , dof8Set } from "./dof8.ts" ;
22
3+ /**
4+ * A float that should be between 0 and 1.
5+ * Where 0 is the start of the animation and 1 is the end.
6+ */
7+ export declare type timeFloat = number ;
8+
9+ /**
10+ * Converts degrees to radians (what THREE.js uses)
11+ * @param degrees degrees input
12+ */
313export function degreesToRadians ( degrees : number ) : number {
414 const pi = Math . PI ;
515 return degrees * ( pi / 180 ) ;
616}
717
18+ /**
19+ * Converts degrees to radians (what THREE.js uses)
20+ * Alias for degreesToRadians function.
21+ * @param degrees degrees input
22+ */
23+ export function d2r ( degrees : number ) : number {
24+ return degreesToRadians ( degrees ) ;
25+ }
26+
27+ /**
28+ * Preforms a fade from transparent to opaque.
29+ * Shorthand for fading in a object at start of animation.
30+ * @param t animation timestamp in ms
31+ * @param duration duration in ms
32+ */
833export function fadeIn ( t : number , duration : number ) : dof8 {
934 const tSub = timeSubset ( t , 0 , duration ) ;
1035 const alpha = linearChange ( tSub , 0 , 1 ) ;
1136 return { alpha } ;
1237}
1338
39+ /**
40+ * Preforms a fade from opaque to transparent.
41+ * Shorthand for fading out a object at the end of animation.
42+ * @param t animation timestamp in ms
43+ * @param duration duration in ms
44+ * @param endPoint the time the animation should end at
45+ */
1446export function fadeOut ( t : number , duration : number , endPoint : number ) : dof8 {
1547 const tSub = timeSubset ( t , ( endPoint - duration ) , endPoint ) ;
1648 const alpha = linearChange ( tSub , 1 , 0 ) ;
@@ -23,7 +55,7 @@ export function fadeOut(t: number, duration: number, endPoint: number): dof8 {
2355 * @param startT timecode for 0
2456 * @param endT timecode for 1
2557 */
26- export function timeSubset ( t : number , startT : number , endT : number ) {
58+ export function timeSubset ( t : number , startT : number , endT : number ) : timeFloat {
2759 const range = endT - startT ;
2860 return ( t - startT ) / range ;
2961}
@@ -32,15 +64,22 @@ export function timeSubset(t: number, startT: number, endT: number){
3264 * Linear change function.
3365 *
3466 * Partially because I'm bad at math and forget the equation snippet.
35- * @param t float from 0 to 1 (0 being start, 1 being end)
67+ * @param t timeFloat
3668 * @param start Starting Value
3769 * @param end Ending Value
3870 */
39- export function linearChange ( t : number , start : number , end : number ) : number {
71+ export function linearChange ( t : timeFloat , start : number , end : number ) : number {
4072 return ( t * ( end - start ) ) + start ;
4173}
4274
43- export function spin ( t : number , start : dof8 , end : dof8 ) : dof8 {
75+ /**
76+ * Spins a object from the starting configuration to the ending configuration.
77+ * Both starting and ending dof8 values must be set for the output to include them.
78+ * @param t timeFloat
79+ * @param start starting set of dof8 values
80+ * @param end ending set of dof8 values
81+ */
82+ export function spin ( t : timeFloat , start : dof8 , end : dof8 ) : dof8 {
4483 const out : dof8 = { } ;
4584 if ( start . X != undefined && end . X != undefined ) {
4685 out . X = linearChange ( t , start . X , end . X ) ;
@@ -104,6 +143,12 @@ function mergeAlpha(a: number | undefined, b: number | undefined): number | unde
104143 }
105144}
106145
146+ /**
147+ * Merges (adds) values of two dof8 records.
148+ * If only one object has data, it will be copied.
149+ * @param a first dof8 object
150+ * @param b second dof8 object
151+ */
107152export function mergeDof8 ( a : dof8 , b : dof8 ) : dof8 {
108153 const output : dof8 = { } ;
109154 output . x = mergeLower ( a . x , b . x ) ;
@@ -117,6 +162,12 @@ export function mergeDof8(a: dof8, b: dof8): dof8 {
117162 return output ;
118163}
119164
165+ /**
166+ * Merges two dof8Sets using the mergeDof8 function.
167+ * If only one object has data, it will be copied.
168+ * @param input dof8Set to merge
169+ * @param offset dof8Set to merge
170+ */
120171export function offsetMerge ( input : dof8Set , offset : dof8Set ) : dof8Set {
121172 const output : dof8Set = { } ;
122173 for ( const r in input ) {
0 commit comments