@@ -12,7 +12,7 @@ function prep(prototype, Class, ...keys) {
1212 } ) ;
1313}
1414
15- function prepare ( Class , { Vec2, Vec3, Vec4 } , keysVec , keysCol ) {
15+ function prepare ( Class , { Vec2, Vec3, Vec4 } , keysVec , keysCol , indexCol ) {
1616 const { prototype } = Class ;
1717 const keys = [ ...keysVec , ...keysCol ] ;
1818
@@ -34,12 +34,24 @@ function prepare(Class, { Vec2, Vec3, Vec4 }, keysVec, keysCol) {
3434
3535 keys . forEach ( ( a ) => keys . forEach ( ( b ) => keys . forEach ( ( c ) => keys . forEach ( ( d ) => prep ( prototype , Vec4 , a , b , c , d ) ) ) ) ) ;
3636
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+ } ) ;
3749}
3850
3951export function swizzle ( options ) {
4052
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' ] ) ;
4456
4557}
0 commit comments