@@ -7,11 +7,51 @@ class SDUniformElement extends SDBaseElement {
7
7
return parseFloat ( this . getAttribute ( 'x' ) ) ;
8
8
}
9
9
10
- set x ( newX ) {
11
- if ( newX != null ) this . setAttribute ( 'x' , newX ) ;
10
+ set x ( newx ) {
11
+ if ( newx != null ) this . setAttribute ( 'x' , newx ) ;
12
12
else this . removeAttribute ( 'x' ) ;
13
13
}
14
14
15
+ get y ( ) {
16
+ return parseFloat ( this . getAttribute ( 'y' ) ) ;
17
+ }
18
+
19
+ set y ( newy ) {
20
+ if ( newy != null ) this . setAttribute ( 'y' , newy ) ;
21
+ else this . removeAttribute ( 'y' ) ;
22
+ }
23
+
24
+ get z ( ) {
25
+ return parseFloat ( this . getAttribute ( 'z' ) ) ;
26
+ }
27
+
28
+ set z ( newz ) {
29
+ if ( newz != null ) this . setAttribute ( 'z' , newz ) ;
30
+ else this . removeAttribute ( 'z' ) ;
31
+ }
32
+
33
+ get w ( ) {
34
+ return parseFloat ( this . getAttribute ( 'w' ) ) ;
35
+ }
36
+
37
+ set w ( neww ) {
38
+ if ( neww != null ) this . setAttribute ( 'w' , neww ) ;
39
+ else this . removeAttribute ( 'w' ) ;
40
+ }
41
+
42
+ getValue ( ) {
43
+ switch ( this . type ) {
44
+ case 'vec2' :
45
+ return [ this . x , this . y ] ;
46
+ case 'vec3' :
47
+ return [ this . x , this . y , this . z ] ;
48
+ case 'vec4' :
49
+ return [ this . x , this . y , this . z , this . w ] ;
50
+ default :
51
+ return this . x ;
52
+ }
53
+ }
54
+
15
55
get type ( ) {
16
56
return this . getAttribute ( 'type' ) ;
17
57
}
@@ -22,13 +62,17 @@ class SDUniformElement extends SDBaseElement {
22
62
}
23
63
24
64
static get observedAttributes ( ) {
25
- return [ 'x' ] ;
65
+ return [ 'x' , 'y' , 'z' , 'w' ] ;
26
66
}
27
67
28
68
attributeChangedCallback ( name , oldValue , newValue ) {
29
69
switch ( name ) {
30
70
case 'x' :
31
- if ( newValue != null ) this . renderer . setUniform ( this . name , newValue ) ;
71
+ case 'y' :
72
+ case 'z' :
73
+ case 'w' :
74
+ if ( newValue != null )
75
+ this . renderer . setUniform ( this . name , this . getValue ( ) ) ;
32
76
break ;
33
77
}
34
78
}
@@ -40,7 +84,7 @@ class SDUniformElement extends SDBaseElement {
40
84
}
41
85
42
86
this . program = program ;
43
- this . renderer . addUniform ( this . name , this . x , this . type ) ;
87
+ this . renderer . addUniform ( this . name , this . getValue ( ) , this . type ) ;
44
88
}
45
89
}
46
90
0 commit comments