@@ -19,35 +19,81 @@ import { GUI, controllers } from '../../dat.gui';
19
19
*
20
20
* @extends dat.controllers.CustomController
21
21
*
22
+ * @param {Object } object The object to be manipulated
23
+ * @param {string } property The name of the property to be manipulated
22
24
* @param {number } a
23
25
* @param {number } b
24
26
*/
25
27
export class KnobController extends controllers . CustomController {
26
- constructor ( a , b ) {
27
- super ( function ( controller ) {
28
+ constructor ( object , property , a , b ) {
29
+ super ( object , property ) ;
28
30
29
- var button = document . createElement ( 'span' ) ;
30
- button . innerHTML = 'Knob Controller' ;
31
- button . title = 'Please press knob' ;
32
- button . style . cursor = 'pointer' ;
33
- button . style . margin = '0px 2px' ;
34
- button . onclick = function ( value ) {
31
+ // ... set up options if needed
35
32
36
- alert ( 'Knob Controller ' + ( knobController . a + knobController . b ) ) ;
33
+ const _this = this ;
37
34
38
- }
39
- controller . domElement . appendChild ( button ) ;
35
+ //input element
36
+ this . __input = document . createElement ( 'input' ) ;
37
+ this . __input . setAttribute ( 'type' , 'number' ) ;
38
+ this . __input . style . width = '40%' ;
39
+ this . updateDisplay ( ) ;
40
+ this . domElement . appendChild ( this . __input ) ;
40
41
41
- } ) ;
42
- this . a = a ;
43
- this . b = b ;
44
- var knobController = this ;
42
+ //button element
43
+ var button = document . createElement ( 'input' ) ;
44
+ button . setAttribute ( 'type' , 'button' ) ;
45
+ button . value = 'Set ' + property ;
46
+ button . style . width = '50%' ;
47
+ button . onclick = function ( e ) {
48
+ object [ property ] = a + b ;
49
+ _this . updateDisplay ( ) ;
50
+ }
51
+ this . domElement . appendChild ( button ) ;
52
+ }
45
53
54
+ updateDisplay ( ) {
55
+ this . __input . value = this . getValue ( ) ;
46
56
}
47
57
}
48
58
59
+ /**
60
+ * @class Example of subtype of CustomController class.
61
+ * Periodically changes the selected 3D object.
62
+ * Adds NumberControllerSlider controller into PlayController for changing of the rate of changing of 3D obects per second.
63
+ *
64
+ * @extends dat.controllers.CustomController
65
+ *
66
+ * @param {Function } init Returns an object with elements for adding into "property-name" class element.
67
+ */
49
68
export class PlayController extends controllers . CustomController {
50
- constructor ( init ) {
51
- super ( init ) ;
69
+ constructor ( init ) {
70
+ super ( {
71
+
72
+ playRate : 1 , //Default play rate is 1 changes per second
73
+ property : init ,
74
+
75
+ } , 'playRate' , 1 , 25 , 1 ) ;
76
+ // this.property = init();
77
+ if ( this . property === undefined )
78
+ console . error ( 'init() returns ' + this . property ) ;
79
+ }
80
+ }
81
+
82
+ /**
83
+ * @class Example of subtype of CustomController class.
84
+ * Selects previous or next 3D object
85
+ *
86
+ * @extends dat.controllers.CustomController
87
+ *
88
+ * @param {Function } init Returns an object with elements for adding into "property-name" class element.
89
+ */
90
+ export class PrevAndNextController extends controllers . CustomController {
91
+ constructor ( init ) {
92
+ super ( {
93
+ property : init ,
94
+ } ) ;
95
+ // this.property = init();
96
+ if ( this . property === undefined )
97
+ console . error ( ' init() returns ' + this . property ) ;
52
98
}
53
99
}
0 commit comments