@@ -12,7 +12,7 @@ function prep(prototype, Class, ...keys) {
12
12
} ) ;
13
13
}
14
14
15
- function prepare ( Class , { Vec2, Vec3, Vec4 } , keysVec , keysCol ) {
15
+ function prepare ( Class , { Vec2, Vec3, Vec4 } , keysVec , keysCol , indexCol ) {
16
16
const { prototype } = Class ;
17
17
const keys = [ ...keysVec , ...keysCol ] ;
18
18
@@ -34,12 +34,24 @@ function prepare(Class, { Vec2, Vec3, Vec4 }, keysVec, keysCol) {
34
34
35
35
keys . forEach ( ( a ) => keys . forEach ( ( b ) => keys . forEach ( ( c ) => keys . forEach ( ( d ) => prep ( prototype , Vec4 , a , b , c , d ) ) ) ) ) ;
36
36
37
+ indexCol . forEach ( ( index ) => {
38
+ let key = keysVec [ parseInt ( index , 10 ) ] ;
39
+ Object . defineProperty ( prototype , index , {
40
+ get ( ) {
41
+ return this [ key ] ;
42
+ } ,
43
+ set ( value ) {
44
+ this [ key ] = value ;
45
+ return true ;
46
+ }
47
+ } ) ;
48
+ } ) ;
37
49
}
38
50
39
51
export function swizzle ( options ) {
40
52
41
- prepare ( options . Vec2 , options , [ 'x' , 'y' ] , [ 'r' , 'g' ] ) ;
42
- prepare ( options . Vec3 , options , [ 'x' , 'y' , 'z' ] , [ 'r' , 'g' , 'b' ] ) ;
43
- prepare ( options . Vec4 , options , [ 'x' , 'y' , 'z' , 'w' ] , [ 'r' , 'g' , 'b' , 'a' ] ) ;
53
+ prepare ( options . Vec2 , options , [ 'x' , 'y' ] , [ 'r' , 'g' ] , [ '0' , '1' ] ) ;
54
+ prepare ( options . Vec3 , options , [ 'x' , 'y' , 'z' ] , [ 'r' , 'g' , 'b' ] , [ '0' , '1' , '2' ] ) ;
55
+ prepare ( options . Vec4 , options , [ 'x' , 'y' , 'z' , 'w' ] , [ 'r' , 'g' , 'b' , 'a' ] , [ '0' , '1' , '2' , '3' ] ) ;
44
56
45
57
}
0 commit comments