-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOptions.js
More file actions
2192 lines (1616 loc) · 70.3 KB
/
Options.js
File metadata and controls
2192 lines (1616 loc) · 70.3 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* options of the canvas
*
* @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
*/
/*
//При выполнении npm run build получаю ошибку
//(babel plugin) ReferenceError: Unknown plugin "external-helpers" specified in "base" at 1, attempted to resolve relative to "D:\\My documents\\MyProjects\\webgl\\three.js\\GitHub\\three.js\\dev\\examples\\jsm"
//import { WEBGL } from '../../three.js/dev/examples/jsm/WebGL.js';
import { WEBGL } from './WebGL.js';
//for testing open FireFox and read https://support.biodigital.com/hc/en-us/articles/218322977-How-to-turn-on-WebGL-in-my-browser#h_01EJW3MGDF7KH3PH6TG2DE13H6
if ( WEBGL.isWebGLAvailable() === false ) {
document.body.appendChild( WEBGL.getWebGLErrorMessage() );
alert( WEBGL.getWebGLErrorMessage().innerHTML );
}
*/
import ColorPicker from './colorpicker/colorpicker.js';
import three from './three.js'
//для создания пустого cookie который ничего не запоминает
import Cookie from './cookieNodeJS/cookie.js';
import cookie from './cookieNodeJS/cookie.js';
import { getLanguageCode } from './lang.js';
import Player from './player/player.js';
import StereoEffect from './StereoEffect/StereoEffect.js';
import { createController } from './controller.js'
var boCreateControllers;
class Options {
/**
* Options of the canvas
* @param {Object} options See the <b>options</b> parameter of the <a href="../../myThree/jsdoc/module-MyThree-MyThree.html" target="_blank">MyThree</a> class.
*/
constructor( options ) {
const _this = this;
options = options || {};
if ( options.boOptions )
return options;//duplucate new Options
var lang;
if ( options.a === undefined ) options.a = 1;
if ( options.b === undefined ) options.b = 0;
/**
* set the <b>scales.w</b> key of the <b>options</b>
* @param {Object} options
* @param {string} [options.scales.w.name="W"] axis name.
* @param {number} [options.scales.w.min=0] Minimum range of the <a href="../../colorpicker/jsdoc/index.html" target="_blank">color palette</a> index.
* @param {number} [options.scales.w.max=1] Maximum range of the <a href="../../colorpicker/jsdoc/index.html" target="_blank">color palette</a> index.
*/
this.setW = function ( optionsCur ) {
optionsCur = optionsCur || options;
const axisName = 'w';
optionsCur.scales = optionsCur.scales || {};
const scale = optionsCur.scales.w;
if ( !optionsCur.palette )
_this.setPalette();// optionsCur );
//максимальное значение шкалы w по умолчанию беру из THREE.Vector4
//потому что в противном случае неверно будет отображаться цвет точки, заданной как THREE.Vector4()
// scale.max = scale.max === undefined ? new three.THREE.Vector4().w : scale.max;
}
options.scales = options.scales || {};
const boCreateScale = !options.scales.x && !options.scales.y && !options.scales.z;
function setScale( axisName ) {
//Не надо создавать ось потому что иначе будут создавться контролы для осей, которые не хочет видеть пользователь и будет рмсоватся пунктирная линия к не существующей оси если пользователь нажал на точку
if ( boCreateScale )
options.scales[axisName] = options.scales[axisName] || {};
if ( !options.scales[axisName] )
return;
/*
options.scales[axisName].name = options.scales[axisName].name || axisName;
options.scales[axisName].min = options.scales[axisName].min === undefined ? -1 : options.scales[axisName].min;
options.scales[axisName].max = options.scales[axisName].max === undefined ? 1 : options.scales[axisName].max;
*/
}
setScale( 'x' );
setScale( 'y' );
setScale( 'z' );
// options.scales.setW = function () { _this.setW(); }
options.point = options.point || {};
if (options.point.size === undefined) options.point.size = 5.0;
options.point.sizePointsMaterial = options.point.sizePointsMaterial || 100.0;
/**
* set the <b>palette</b> key of the <b>options</b>.
* See <a href="../../colorpicker/jsdoc/module-ColorPicker-ColorPicker.html#palette" target="_blank">color palette</a>.
* @param {ColorPicker.palette} [palette] new palette.
*/
this.setPalette = function ( palette ) {
if ( palette ) options.palette = palette;
else if ( !options.palette ) options.palette = new ColorPicker.palette();
}
/**
* Create [OrbitControls]{@link https://threejs.org/docs/index.html#examples/en/controls/OrbitControls}
* @param {THREE.PerspectiveCamera} camera [PerspectiveCamera]{@link https://threejs.org/docs/index.html#api/en/cameras/PerspectiveCamera}. Use the <b>camera</b> key if you want control cameras focus.
* @param {THREE.WebGLRenderer} renderer [THREE.WebGLRenderer]{@link https://threejs.org/docs/index.html#api/en/renderers/WebGLRenderer}.
* @param {THREE.Scene} scene [THREE.Scene]{@link https://threejs.org/docs/index.html?q=sce#api/en/scenes/Scene}.
*/
this.createOrbitControls = function ( camera, renderer, scene ) {
if ( options.orbitControls === false )
return;
const settings = options.orbitControls || {};
_this.orbitControls = new three.OrbitControls( camera, renderer.domElement );
if ( settings.enableRotate !== undefined ) _this.orbitControls.enableRotate = settings.enableRotate;
if ( settings.target )
_this.orbitControls.target.copy(settings.target);
else _this.orbitControls.target.copy( scene.position).multiply( new three.THREE.Vector3().copy( scene.scale ).addScalar( 1 ) );
_this.orbitControls.saveState();//For reset of the orbitControls settings in the CameraGui and OrbitControlsGui
_this.orbitControls.update();
if ( _this.frustumPoints )
_this.orbitControls.addEventListener( 'change', function () { _this.frustumPoints.onChangeControls(); } );
}
/**
* Reset <a href="../../Player/jsdoc" target="_blank">Player</a> and restore [camera]{@link https://threejs.org/docs/index.html#api/en/cameras/PerspectiveCamera} position.
* @param {THREE.PerspectiveCamera} camera [PerspectiveCamera]{@link https://threejs.org/docs/index.html#api/en/cameras/PerspectiveCamera}.
* @param {THREE.Scene} scene [THREE.Scene]{@link https://threejs.org/docs/index.html?q=sce#api/en/scenes/Scene}.
*/
this.restoreSceneController = function ( camera, scene ) {
if ( !three.dat || ( options.dat === false ) )//options.dat.dat
return;
//Localization
const lang = {
defaultButton: 'Default',
defaultTitle: 'Reset player and restore camera position.',
};
switch ( this.getLanguageCode() ) {
case 'ru'://Russian language
lang.defaultButton = 'Восстановить';
lang.defaultTitle = 'Восстановить положение камеры и проигрывателя.';
break;
}
const scenePosition = new three.THREE.Vector3().copy( scene.position ),
cameraPosition = new three.THREE.Vector3().copy( camera.position ),
target = options.orbitControls != false ? new three.THREE.Vector3().copy( options.orbitControls.target ) : undefined;
three.dat.controllerNameAndTitle( options.dat.gui.add( {
defaultF: function ( value ) {
if ( options.player ) options.player.selectScene( options.playerOptions.selectSceneIndex );
camera.position.copy( cameraPosition );
scene.position.copy( scenePosition );
if ( options.orbitControls !== false ) {
// options.orbitControls.target = new three.THREE.Vector3();
options.orbitControls.target.copy( target );
options.orbitControls.object.position.copy( camera.position );
options.orbitControls.update();
}
},
}, 'defaultF' ), lang.defaultButton, lang.defaultTitle );
}
Object.defineProperties( this, {
/**
* getter and setter
* <pre>
*
* playerOptions = {
*
* min: 0,// Minimum range of the axis.
* max: 1,// Maximum range of the axis.
* marks: 10,// Ticks count of the playing. Number of scenes of 3D objects animation.
* //Have effect for <b>max</b> is not Infinity.
* dt: 0.1,// Step of the animation. Have effect only if <b>max</b> is infinity.
* repeat: false,// true - Infinitely repeating 3D objects animation.
* interval: 1,// Ticks per seconds.
* zoomMultiplier: 1.1,// zoom multiplier of the time.
* offset: 0.1,// offset of the time.
* name: "",// name of the time.
*
* }
* </pre>
* @param {number} [playerOptions=0] Minimum range of the axis.
*/
playerOptions: {
get: function () {
options.playerOptions = options.playerOptions || {};
const playerOptions = options.playerOptions;
playerOptions.min = playerOptions.min || 0;
if ( playerOptions.max === Infinity ) playerOptions.max = null;//Заменяю Infinity на null потому что из cockie Infinity читается как null
if ( playerOptions.max !== null ) {
if ( playerOptions.max === undefined ) playerOptions.max = 1;
playerOptions.marks = playerOptions.marks || 10;//2;
} else playerOptions.marks = null;
if ( playerOptions.max === null ) playerOptions.dt = playerOptions.dt || 0.1;
else playerOptions.dt = ( playerOptions.max - playerOptions.min ) / ( playerOptions.marks - 1 );
playerOptions.repeat = playerOptions.repeat || false;
playerOptions.interval = playerOptions.interval != undefined ? playerOptions.interval : 1;
playerOptions.zoomMultiplier = playerOptions.zoomMultiplier || 1.1;
playerOptions.offset = playerOptions.offset || 0.1;
playerOptions.name = playerOptions.name || '';
if ( !playerOptions.cameraTarget ) {
const cameraTarget = new Player.cameraTarget();
Object.defineProperties( playerOptions, {
cameraTarget: {
get: function () {
return cameraTarget;
},
}
} );
}
return options.playerOptions;
},
set: function ( playerOptions ) { options.playerOptions = playerOptions; },
},
/**
* getter
* <pre>
* See <b>options.a</b> parameter of the <a href="../../player/jsdoc/module-Player-Player.execFunc.html" target="_blank">Player.execFunc</a>.
* </pre>
**/
a: {
get: function () { return options.a; }
},
/**
* getter
* <pre>
* See <b>options.b</b> parameter of the <a href="../../player/jsdoc/module-Player-Player.execFunc.html" target="_blank">Player.execFunc</a>.
* </pre>
**/
b: {
get: function () { return options.b; }
},
/**
* getter and setter
* <pre>
* See the <b>options.dat</b> parameter of the <a href="../../myThree/jsdoc/module-MyThree-MyThree.html" target="_blank">MyThree</a> class.
* dat = {
*
* gui: new [dat.GUI()]{@link https://github.com/dataarts/dat.gui} instance,
* undefined - do not use dat-gui JavaScript Controller Library. [dat.gui]{@link https://github.com/dataarts/dat.gui}.
* cookie: false,// do not save to cookie all user settings
* cookieName:,// Name of the cookie.
* axesHelperGui: false,// - do not adds a <a href="../../AxesHelper/jsdoc/module-AxesHelperGui.html" target="_blank">AxesHelperGui</a> into [dat.gui]{@link https://github.com/dataarts/dat.gui}.
* stereoEffectsGui: false,// - do not adds <a href="../../StereoEffect/jsdoc/module-StereoEffect-StereoEffect.html#gui" target="_blank">Stereo Effects folder</a> into [dat.gui]{@link https://github.com/dataarts/dat.gui}.
* folderPoint: false,// - do not adds <a href="../../jsdoc/folderPoint/FolderPoint.html" target="_blank">Point settings folder</a> into [dat.gui]{@link https://github.com/dataarts/dat.gui}.
* playerGui: true,// - adds a <a href="../../player/jsdoc/module-Player.html#~Player.gui" target="_blank">Player controllers</a> into [dat.gui]{@link https://github.com/dataarts/dat.gui}.
* guiSelectPoint: true,// - displays the <a href="../../guiSelectPoint/jsdoc/module-GuiSelectPoint.html" target="_blank">Select Point</a>. [dat.gui]{@link https://github.com/dataarts/dat.gui} based graphical user interface for select a point from the mesh.
* guiFrustumPoints: true,// - Adds <a href="../../FrustumPoints/jsdoc/FrustumPoints.html#gui" target="_blank">Frustum Points folder</a> into [dat.gui]{@link https://github.com/dataarts/dat.gui}.
* cameraGui: true,// - Adds <a href="../../jsdoc/CameraGui/module-CameraGui-CameraGui.html" target="_blank">Camera folder</a> into [dat.gui]{@link https://github.com/dataarts/dat.gui}.
* moveScene: true,// - displays the <a href="../../jsdoc/MoveGroupGui/index.html" target="_blank">move group gui</a>.
* spriteTextGui: true,// - displays the <a href="../../SpriteText/jsdoc/module-SpriteTextGui.html" target="_blank">SpriteTextGui</a>.
*
* }
* </pre>
**/
dat: {
get: function () {
class Dat{
/* *
* dat options
* @param {dat} dat [dat]{@link https://github.com/dataarts/dat.gui}
*/
constructor( dat ) {
dat = dat || {};
if ( dat.boDat )
return dat;//duplucate new Options
function guiParent() {
//без elMyGuiContainer не будет скроллинга gui
const elMyGuiContainer = document.createElement( 'div' );
dat.parent.appendChild( elMyGuiContainer );
elMyGuiContainer.appendChild( dat.gui.domElement );
elMyGuiContainer.style.position = 'absolute';//оставляем gui в пределах canvas
elMyGuiContainer.style.top = '0px';
elMyGuiContainer.style.right = '0px';
}
Object.defineProperties( this, {
/* *
* getter
* <pre>
* returns true if <b>dat</b> was converted by <b>new Dat( options );</b>
* </pre>
**/
boDat: {
get: function () { return true; },
},
/* *
* getter and setter
* <pre>
* [dat]{@link https://github.com/dataarts/dat.gui}
* </pre>
**/
dat: {
get: function () {
console.warn('get dat depreacated. Use three.dat = dat.');
return three.dat;
},
set: function ( dat ) {
console.warn('Set dat depreacated. Use three.dat = dat.');
if (
dat.dat &&
( dat.dat.constructor.name === dat.constructor.name ) &&
( dat.dat.constructor.name !== 'Object' )
)
console.error( 'duplicate dat.' );
dat.dat = dat;
}
},
/* *
* getter
* <pre>
* Name of the cookie.
* </pre>
**/
cookieName : {
get: function () { return dat.cookieName ; },
},
/* *
* getter
* <pre>
* [dat.GUI()]{@link https://github.com/dataarts/dat.gui} instance.
* </pre>
**/
gui: {
get: function () {
if ( !dat.gui && three.dat ) {
//если сделать autoPlace: false то не будет скроллинга для gui
dat.gui = new three.dat.GUI();// options.dat.parent ? { autoPlace: false, } : undefined );
if ( options.dat.parent ) {
guiParent();
}
}
return dat.gui;
},
},
cookie: {
get: function () { return dat.cookie; },
set: function ( cookie ) { dat.cookie = cookie; },
},
guiSelectPoint: {
get: function () { return dat.guiSelectPoint; },
set: function ( guiSelectPoint ) { dat.guiSelectPoint = guiSelectPoint; },
},
cameraGui: {
get: function () { return dat.cameraGui; },
set: function ( cameraGui ) { dat.cameraGui = cameraGui; },
},
playerGui: {
get: function () { return dat.playerGui; },
},
orbitControlsGui: {
get: function () { return dat.orbitControlsGui; },
},
axesHelperGui: {
get: function () { return dat.axesHelperGui; },
},
playController: {
get: function () { return dat.playController; },
},
stereoEffectsGui: {
get: function () { return dat.playController; },
},
moveScene: {
get: function () { return dat.moveScene; },
},
spriteTextGui: {
get: function () { return dat.spriteTextGui; },
},
folderPoint: {
get: function () { return dat.folderPoint; },
set: function ( folderPoint ) { dat.folderPoint = folderPoint; },
},
pointLightGui: {
get: function () { return dat.pointLightGui; },
},
parent: {
get: function () { return dat.parent; },
},
} );
//For debugging. Find a hidden keys
for ( var propertyName in dat ) {
if ( this[propertyName] === undefined ) console.error( 'Dat: dat.' + propertyName + ' key is hidden' );
}
}
}
if ( options.dat === false )
return options.dat;
options.dat = new Dat( options.dat );
if ( options.dat.gui ) {
//debug
setTimeout( function () {
const className = options.dat.gui.domElement.className;
var guiCount = 0;
options.dat.gui.domElement.parentElement.childNodes.forEach( function ( node ) {
if ( node.className === className ) guiCount++;
} );
if ( guiCount > 1 )
console.error( 'Options: duplicate dat.GUI' );
}, 0 );
options.dat.gui.domElement.addEventListener( 'mouseenter', function ( event ) { options.dat.mouseenter = true; } );
options.dat.gui.domElement.addEventListener( 'mouseleave', function ( event ) { options.dat.mouseenter = false; } );
}
if ( options.dat.cookie === false ) options.dat.cookie = new Cookie.defaultCookie();
else if ( options.dat.cookie === undefined ) options.dat.cookie = cookie;
options.dat.getCookieName = function ( cookieName = '' ) {
const name = options.dat.cookieName ||
( options.elContainer ?
typeof options.elContainer === "object" ?
options.elContainer.id :
typeof options.elContainer === "string" ?
options.elContainer :
'' :
'' );
return cookieName + ( ( cookieName !== '' ) && ( name !== '' ) ? '_' : '' ) + name;
}
//axesHelperGui: false,
//playerGui: false,
//guiSelectPoint: false,
//moveScene: false,
//cameraGui: false,
//stereoEffectsGui: false,
//spriteTextGui: false,
//folderPoint: false,
return options.dat;
},
set: function ( dat ) { options.dat = dat; },
},
/**
* getter
* <pre>
* Your custom getLanguageCode() function.
* returns the "primary language" subtag of the language version of the browser.
* Examples: "en" - English language, "ru" Russian.
* See the "Syntax" paragraph of RFC 4646 {@link https://tools.ietf.org/html/rfc4646#section-2.1|rfc4646 2.1 Syntax} for details.
* Default returns the language code of your browser.
* </pre>
**/
getLanguageCode: {
get: function () {
if ( typeof options.getLanguageCode === "string" )
return function () {
return options.getLanguageCode;
}
return options.getLanguageCode || getLanguageCode;
}
},
/**
* getter and setter
* <pre>
* See <b>options.scales</b> parameter of the <a href="../../myThree/jsdoc/module-MyThree-MyThree.html" target="_blank">MyThree</a> class.
* </pre>
**/
scales: {
get: function () {
class Scales {
/* *
* scales
* @param {object} scales
*/
constructor( scales ) {
class Scale {
/* *
* scale
* @param {object} scales
* @param {string} axisName. 'x' or 'y' or 'z'
*/
constructor( scales, axisName ) {
let scale = scales[axisName];
// scale = scale || {};
this.isAxis = function () {
if ( !scales || ( !scales.x && !scales.y && !scales.z ) || scale ) return true;
return false;
}
const setScale = (callBack) => {
if ( !scale ) {
scales[axisName] = {};
scale = scales[axisName];
}
callBack();
scale.step = Math.abs( options.scales.w.min - options.scales.w.max ) / 100;
if ( options.guiSelectPoint) options.guiSelectPoint.setAxisControl( 'w', scale );
}
Object.defineProperties( this, {
/* *
* getter
* <pre>
* returns true if <b>scale</b> was converted by <b>new Scale( scale );</b>
* </pre>
**/
boScale: { get: function () { return true; }, },
/*
isChangeColor : {
get: () => { return scale ? scale.isChangeColor : undefined; },
set: ( isChangeColor ) => { scale.isChangeColor = isChangeColor; },
},
*/
isColor : {
get: () => { return scale ? scale.isColor : undefined; },
set: ( isColor ) => { scale.isColor = isColor; },
},
min: {
get: () => {
if ( !scale || ( scale.min === undefined ) ) return axisName === 'w' ? 0 : -1;
return scale.min;
},
set: ( min ) => { setScale( () => { scale.min = min; }); },
},
max: {
get: function () {
//максимальное значение шкалы w по умолчанию беру из THREE.Vector4
//потому что в противном случае неверно будет отображаться цвет точки, заданной как THREE.Vector4()
if ( !scale || ( scale.max === undefined ) ) return axisName === 'w' ? new three.THREE.Vector4().w : 1;
return scale.max;
},
set: ( max ) => { setScale( () => { scale.max = max; }); },
},
name: {
get: function () {
if ( !scale || ( scale.name === undefined ) ) return axisName;
return scale.name;
},
set: function ( name ) {
if ( scale ) {
scale.name = name;
if ( options.guiSelectPoint ) options.guiSelectPoint.setAxisName( axisName, name );
}
},
},
marks: {
get: function () {
if ( !scale ) return undefined;
if ( !scale.marks ) scale.marks = 3;
return scale.marks;
},
// set: function ( marks ) { scale.marks = marks; },
},
zoomMultiplier: {
get: () => {
if ( !scale ) return undefined;
if ( !scale.zoomMultiplier ) scale.zoomMultiplier = 1.1;
return scale.zoomMultiplier;
},
set: ( zoomMultiplier ) => { setScale( () => { scale.zoomMultiplier = zoomMultiplier; }); },
},
offset: {
get: () => {
if ( !scale ) return undefined;
if ( !scale.offset ) scale.offset = 0.1;
return scale.offset;
},
set: ( offset ) => { setScale( () => { scale.offset = offset; }); },
},
} );
//For debugging. Find a hidden keys
/*Uncompatible with http://localhost/anhr/commonNodeJS/master/HyperSphere/Examples/randomArc.html
for ( var propertyName in scale ) {
if ( this[propertyName] === undefined ) console.error( 'Options.Scales: scale.' + propertyName + ' key is hidden' );
}
*/
}
}
const scalesObject = {
x: new Scale( options.scales, 'x' ),
y: new Scale( options.scales, 'y' ),
z: new Scale( options.scales, 'z' ),
w: new Scale( options.scales, 'w' ),
}
Object.defineProperties( this, {
/* *
* getter
* <pre>
* returns true if <b>scales</b> was converted by <b>new Scales( scales );</b>
* </pre>
**/
boScales: {
get: function () { return true; },
},
x: {
get: function () { return scalesObject.x; },
set: function ( x ) {
if ( x === undefined ) {
delete scales.x;
delete scalesObject.x;
scalesObject.x = new Scale( scales, 'x' );
} else scales.x = x;
if ( options.guiSelectPoint ) options.guiSelectPoint.updateScale( 'x' );
},
},
y: {
get: function () { return scalesObject.y; },
set: function ( y ) {
if ( y === undefined ) {
delete scales.y;
delete scalesObject.y;
scalesObject.y = new Scale( scales, 'y' );
} else scales.y = y;
if ( options.guiSelectPoint ) options.guiSelectPoint.updateScale( 'y' );
},
},
z: {
get: function () { return scalesObject.z; },
set: function ( z ) {
if ( z === undefined ) {
delete scales.z;
delete scalesObject.z;
scalesObject.z = new Scale( scales, 'z' );
} else scales.z = z;
if ( options.guiSelectPoint ) options.guiSelectPoint.updateScale( 'z' );
},
},
w: {
get: function () { return scalesObject.w; },
set: function ( w ) { scales.w = w; },
},
/* *
* getter
* <pre>
* setW
* </pre>
**/
setW: {
get: function () {
/*
if ( !scales.setW ) scales.setW = _this.setW;
return scales.setW;
*/
return _this.setW;
},
},
/* *
* getter and setter
* <pre>
* true - displays the label and scale of the axes.
* </pre>
**/
display: {
get: function () {
if ( scales.display === undefined ) scales.display = true;
return scales.display;
},
set: function ( display ) { scales.display = display; },
},
/* *
* getter and setter
* <pre>
* options of the text of the marks of AxesHelper
* </pre>
**/
text: {
get: function () {
if ( scales.text === undefined ) scales.text = {};
return scales.text;
},
set: function ( text ) { scales.text = text; },
},
/* *
* getter and setter
* <pre>
* Position of the axes intersection
* </pre>
**/
posAxesIntersection: {
get: function () { return scales.posAxesIntersection; },
set: function ( posAxesIntersection ) { scales.posAxesIntersection = posAxesIntersection; },
},
} );
//For debugging. Find a hidden keys
for ( var propertyName in scales ) {
if ( this[propertyName] === undefined ) console.error( 'Options: scales.' + propertyName + ' key is hidden' );
}
}
}
if ( !options.scales.boScales )
options.scales = new Scales( options.scales );
return options.scales;
},
set: function ( scales ) { options.scales = scales; }
},
/**
* getter
* <pre>
* Points сolor.
* See <b>options.palette</b> parameter of the <a href="../../myThree/jsdoc/module-MyThree-MyThree.html" target="_blank">MyThree</a> class.
* </pre>
**/
palette: {
get: function () {
if ( options.palette === undefined ) options.palette = true;
switch ( typeof options.palette ) {
case 'number':
options.palette = new ColorPicker.palette( { palette: options.palette } );
break;
case 'boolean':
if ( options.palette )
options.palette = new ColorPicker.palette();// { palette: ColorPicker.paletteIndexes.BGYW } );
break;
case 'string':
const color = new three.THREE.Color(options.palette);
options.palette = new ColorPicker.palette( { palette: [{ percent: 0, r: color.r * 255, g: color.g * 255, b: color.b * 255, },] } );
break;
default: {
//Это условие не выполняется корректро если использовать myThree.module.js или myThree.module.min.js вместо myThree.js
//if ( options.palette instanceof ColorPicker.palette === false )
if ( Array.isArray( options.palette ) )
options.palette = new ColorPicker.palette( { palette: options.palette } );//Custom palette
else if ( !options.palette.isPalette() )
console.error( 'MyThree: invalid typeof options.palette: ' + typeof options.palette );
}
}
return options.palette;
},
},
/**
* getter
* <pre>
* returns true if <b>options</b> was converted by <b>new Options( options );</b>
* </pre>
**/
boOptions: {
get: function () { return true;/*options.boOptions;*/ },
},
/**
* getter
* <pre>
* returns {
*
* size = 5.0; point size
* sizePointsMaterial = 100.0; The <b>size</b> property of the parameters of the [THREE.PointsMaterial]{@link https://threejs.org/docs/index.html?q=PointsMaterial#api/en/materials/PointsMaterial}.
*
* }
* </pre>
**/
point: {
get: function () {
return {
get size() { return options.point.size; },
set size( size ) {
if ( options.point.size === size ) return;
options.point.size = size;