-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPositionController.js
More file actions
140 lines (102 loc) · 4.08 KB
/
PositionController.js
File metadata and controls
140 lines (102 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* PositionController is dat.GUI graphical user interface controller for control of the position of threejs 3D object
*
* @see {@link https://threejs.org/} about threejs
* @see {@link https://github.com/dataarts/dat.gui} about dat.GUI
*
* @author [Andrej Hristoliubov]{@link https://github.com/anhr}
*
* @copyright 2011 Data Arts Team, Google Creative Lab
*
* @license under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*/
import { controllers } from './dat/dat.gui.module.js';
//import { controllers } from '../../dat.gui/CustomController/build/dat.gui.module.js';
import UpDownController from './UpDownController.js';
class PositionController extends controllers.CustomController {
/**
* dat.GUI graphical user interface for control of the position of threejs 3D object.
* Base class <a href="../../dat.gui/CustomController/src/dat/controllers/CustomController.js" target="_blank">CustomController</a>
* @extends controllers.CustomController.
* @param {Event} onclickController
* @param {object} [options={}] the following options are available:
* @param {object} [options.settings={}] time settings.
* @param {number} [options.settings.offset=0.1] offset.
* @param {number} [options.min=0.1] Minimal offset.
* @param {number} [options.max=10] Maximal offset.
* @param {number} [options.step=0.1] step of offset.
* @param {Function} [options.getLanguageCode=language code of your browser] returns the "primary language" subtag of the version of the browser.
*/
constructor( onclickController, options ) {
options = options || {};
options.settings = options.settings || {};
var settings = options.settings;
if ( options.min === undefined ) options.min = 0.1;
if ( options.max === undefined ) options.max = 10;
if ( settings.offset === undefined ) { settings.offset = 0.1; }
if ( options.step === undefined ) options.step = 0.1;
super( {
offset: settings.offset,
property: function ( customController ) {
//Localization
var lang = {
//Position
offset: 'Offset',
add: 'add',
subtract: 'subtract',
wheelPosition: 'Scroll the mouse wheel to change the position',
};
var _languageCode = options.getLanguageCode === undefined ? 'en'//Default language is English
: options.getLanguageCode();
switch ( _languageCode ) {
case 'ru'://Russian language
//Position
lang.offset = 'Сдвиг';
lang.add = 'добавить';
lang.subtract = 'вычесть';
lang.wheelPosition = 'Прокрутите колесико мыши для изменения позиции';
break;
default://Custom language
if ( ( options.lang === undefined ) || ( options.lang.languageCode != _languageCode ) )
break;
Object.keys( options.lang ).forEach( function ( key ) {
if ( lang[key] === undefined )
return;
lang[key] = options.lang[key];
} );
}
//
var buttons = {}, addButton = UpDownController.addButton;
buttons.Label = addButton( lang.offset, {
title: lang.wheelPosition,
onwheel: function ( delta ) {
var shift = customController.controller.getValue();
onclickController( delta > 0 ? shift : - shift );
}
} );
buttons.in = addButton( '↑', {
title: lang.add,
onclick: function () {
if ( !customController.controller )
console.error('PositionController: addButton ↑ . Invalid customController.controller');
onclickController( customController.controller ? customController.controller.getValue() : 0 );
}
} );
buttons.out = addButton( '↓', {
title: lang.subtract,
onclick: function () {
onclickController( - customController.controller.getValue() );
}
} );
return buttons;
},
}, 'offset', options.min, options.max, options.step );
if ( this.property === undefined )
console.error( 'init() returns ' + this.property );
}
}
export default PositionController;