-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex2.html
2226 lines (1964 loc) · 102 KB
/
index2.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document Title</title>
<!-- Font Awesome CDN -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
#clock {
color: green;
display: inline-block;
}
body {
font-family: 'Arial', sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 10px;
}
.form-style {
background: white;
padding: 10px;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
max-width: 400px;
margin: 10px auto;
}
.form-group {
margin-bottom: 10px;
}
.form-group label {
display: block;
margin-bottom: 3px;
}
.form-group input {
width: 90%;
padding: 5px;
border: 1px solid #ccc;
border-radius: 4px;
}
.form-actions {
text-align: right;
}
.btn {
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
.btn.login {
background-color: #007bff;
color: white;
}
.btn.signup {
background-color: #28a745;
color: white;
margin-left: 10px;
}
/* Extra styles for placeholders */
::placeholder {
color: #bbb;
}
#filecontent {
display: none;
}
#saveFileChanges {
display: none;
}
#contents,
#info {
display: inline-block;
max-width: 500px;
overflow-wrap: break-word;
}
textarea {
width: 40%;
margin-bottom: 10px;
}
.button {
background-color: #007bff;
border: none;
color: white;
padding: 2px 10px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 11px;
border-radius: 3px;
cursor: pointer;
margin-right: 1px;
}
.button:hover {
background-color: #0056b3;
}
.home-button {
display: inline-block;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 50%;
width: 30px;
height: 30px;
font-size: 15px;
text-align: center;
line-height: 30px;
text-decoration: none;
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.5);
}
.home-button:hover {
background-color: #0056b3;
}
canvas {
width: 100vw;
height: 100vh;
display: none;
}
#canvas2 {
position: absolute;
display: none;
}
#ui {
width: 200px;
}
.container {
position: relative;
z-index: 2;
}
#overlay {
position: absolute;
left: 0px;
top: 0px;
background-color: rgba(247, 247, 247, 0.941);
color: rgb(10, 9, 9);
font-family: monospace;
padding: 1em;
border-radius: 0.5em;
border: 1px solid rgba(255, 0, 0, 0.425);
overflow: hidden;
/* text-shadow: 0px 0px 5px white, 0px 0px 5px white, 0px 0px 5px white, 0px 0px 5px white; */
}
#control-buttons {
position: fixed;
bottom: 20px;
left: 10%;
transform: translateX(-50%);
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr;
gap: 10px;
width: 120px;
text-align: center;
align-items: center;
z-index: 1;
}
.direction-btn {
width: 40px;
height: 40px;
font-size: 20px;
border: none;
border-radius: 50%;
background-color: #007BFF;
color: white;
display: flex;
align-items: center;
justify-content: center;
user-select: none;
touch-action: manipulation;
/* Improves responsiveness for touch by disabling double-tap zoom */
}
.direction-btn.forward {
grid-column: 2 / 3;
grid-row: 1 / 2;
}
.direction-btn.left {
grid-column: 1 / 2;
grid-row: 2 / 3;
}
.direction-btn.right {
grid-column: 3 / 4;
grid-row: 2 / 3;
}
.direction-btn.backward {
grid-column: 2 / 3;
grid-row: 3 / 4;
}
.LogInfo {
padding: 0 5px;
display: none;
overflow: hidden;
transition: max-height 0.2s ease-out;
background-color: #f1f1f1;
margin-top: 0;
}
.collapsible {
background-color: #777;
color: white;
cursor: pointer;
padding: 5px;
width: 90%;
border: none;
text-align: left;
outline: none;
font-size: 10px;
margin-bottom: 0;
}
.collapsible:hover {
background-color: #555;
}
#textinput {
border: 1px solid #ccc;
padding: 10px;
min-height: 100px;
max-width: 500px;
/* 최대 너비 설정 */
word-wrap: break-word;
/* 긴 단어도 줄바꿈 */
overflow-wrap: break-word;
/* 긴 단어 줄바꿈 호환성 */
margin-bottom: 10px;
}
#tools {
margin-bottom: 10px;
display: flex;
align-items: center;
justify-content: space-between;
}
#tools button {
background: none;
border: none;
cursor: pointer;
}
#tools svg {
fill: #333;
width: 24px;
height: 24px;
}
#htmlView {
display: none;
white-space: pre-wrap;
background-color: #f4f4f4;
border: 1px solid #ccc;
padding: 10px;
}
#resizeHandle {
width: 10px;
height: 10px;
background-color: darkblue;
position: absolute;
bottom: 0;
right: 0;
cursor: nwse-resize;
/* 대각선 화살표 커서 */
}
</style>
</head>
<body onload="start()">
<button id="toggleButton" onclick="toggleContainer()">Minimize</button>
<div class="container">
<div id="content" style="display: block;">
<canvas id="canvas"></canvas>
<div id="overlay">
<div id="resizeHandle"></div>
<a href="#" class="home-button" onclick="home()"><i class="fas fa-home"></i></a>
<label for="colorPicker2">색상:</label>
<input type="color" id="colorPicker2">
<label for="opacityRange">투명도:</label>
<input type="range" id="opacityRange" min="0" max="100" value="100"><br>
<div id="clock"></div><br />
<form id="loginForm" class="form-style">
<div class="form-group">
<label for="username">Username:</label>
<input type="text" id="username" name="username" placeholder="Enter your username" required>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" id="password" name="password" placeholder="Enter your password" required>
</div>
<div class="form-actions">
<button type="submit" class="btn login">Login</button>
<button type="button" id="showSignUpForm" class="btn signup">Sign Up</button>
</div>
</form>
<form id="signupForm" class="form-style" action="/signup" method="POST"
onsubmit="return validatePassword()" style="display: none;">
<div class="form-group">
<label for="newUsername">Username:</label>
<input type="text" id="newUsername" name="username" placeholder="Choose a username" required>
<button type="button" id="checkDuplicate">Check Duplicate</button>
<span id="usernameValidationMessage"></span>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Your email address" required>
</div>
<div class="form-group">
<label for="newPassword">Password:</label>
<input type="password" id="newPassword" name="password" placeholder="Create a password"
required>
</div>
<div class="form-group">
<label for="confirmPassword">Confirm Password:</label>
<input type="password" id="confirmPassword" placeholder="Confirm your password" required>
</div>
<div class="form-actions">
<button type="submit" class="btn signup" id="signupButton" disabled>Sign Up</button>
</div>
</form>
<div id="contents"></div><br />
<!-- <textarea id="textinput" placeholder="Enter text..."></textarea><br /> -->
<div id="tools">
<button onclick="applyStyle('bold')"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round" class="feather feather-bold">
<text x="3" y="18" font-size="16" font-weight="bold">B</text>
</svg></button>
<button onclick="applyStyle('underline')"><svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24" fill="black" width="24px" height="24px">
<path d="M0 0h24v24H0z" fill="none" />
<path
d="M12 17c3.31 0 6-2.69 6-6V3h-3v8c0 1.66-1.34 3-3 3s-3-1.34-3-3V3H6v8c0 3.31 2.69 6 6 6zm-6 2v2h12v-2H6z" />
</svg></button>
<button onclick="applyStyle('italic')"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
fill="black" width="24px" height="24px">
<path d="M0 0h24v24H0z" fill="none" />
<path d="M10 4v3h2.21l-3.42 8H6v3h8v-3h-2.21l3.42-8H18V4z" />
</svg> </button>
<button onclick="applyStyle('strikeThrough')">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1" stroke-linecap="round" stroke-linejoin="round"
class="feather feather-strikethrough">
<text x="3" y="18" font-size="16" text-decoration="line-through">가</text>
</svg>
</button>
<button onclick="changeColor()"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
fill="none" stroke="red" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"
class="feather feather-strikethrough">
<text x="3" y="18" font-size="16" fill="red">A</text>
</svg>
</button>
<button onclick="changeFontSize()"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
fill="black" width="24px" height="24px">
<path d="M0 0h24v24H0z" fill="none" />
<path d="M4 4v3h4v12h3V7h4V4zm10 7v2h9v-2zm0 7h9v-2h-9z" />
</svg>
</button>
<input type="color" id="colorPicker">
<input type="number" id="fontSizePicker" value="3" min="1" max="7">
<button onclick="applyStyle('insertUnorderedList')"><svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24" fill="black" width="24px" height="24px">
<path d="M0 0h24v24H0V0z" fill="none" />
<path
d="M4 10.5c0 .83.67 1.5 1.5 1.5S7 11.33 7 10.5 6.33 9 5.5 9 4 9.67 4 10.5zM4 6.5C4 7.33 4.67 8 5.5 8S7 7.33 7 6.5 6.33 5 5.5 5 4 5.67 4 6.5zM4 14.5c0 .83.67 1.5 1.5 1.5s1.5-.67 1.5-1.5-.67-1.5-1.5-1.5S4 13.67 4 14.5zM9 6h11v2H9zM9 10h11v2H9zM9 14h11v2H9z" />
</svg>
</button>
<button onclick="applyStyle('insertOrderedList')"> <svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1"
stroke-linecap="round" stroke-linejoin="round" class="feather feather-strikethrough">
<text x="3" y="18" font-size="16">1.\r\n2.\r\n3.</text>
</svg>
</button>
<button onclick="applyStyle('justifyLeft')"><svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24" fill="black" width="24px" height="24px">
<path d="M0 0h24v24H0V0z" fill="none" />
<path d="M3 3h18v2H3zM3 8h12v2H3zM3 13h18v2H3zM3 18h12v2H3z" />
</svg>
</button>
<button onclick="applyStyle('justifyCenter')"><svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24" fill="black" width="24px" height="24px">
<path d="M0 0h24v24H0z" fill="none" />
<path d="M3 3h18v2H3zM5 8h14v2H5zM3 13h18v2H3zM5 18h14v2H5z" />
</svg>
</button>
<button onclick="applyStyle('justifyRight')"><svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24" fill="black" width="24px" height="24px">
<path d="M0 0h24v24H0z" fill="none" />
<path d="M3 3h18v2H3zM3 8h18v2H3zM3 13h18v2H3zM3 18h18v2H3z" />
</svg>
</button>
<button onclick="insertLink()"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
fill="black" width="24px" height="24px">
<path d="M0 0h24v24H0z" fill="none" />
<path
d="M3.9 12c0 1.16.94 2.1 2.1 2.1h4V10H6c-1.16 0-2.1.94-2.1 2.1zM20.1 12c0-1.16-.94-2.1-2.1-2.1h-4v4.2h4c1.16 0 2.1-.94 2.1-2.1zM15 12c0 .55-.45 1-1 1s-1-.45-1-1 .45-1 1-1 1 .45 1 1zM8 14h2v-4H8v4zm10 0h2v-4h-2v4z" />
</svg>
</button>
<button onclick="toggleHTMLView()"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
fill="black" width="24px" height="24px">
<path d="M0 0h24v24H0V0z" fill="none" />
<path
d="M13 12h7v1.5h-7zM5 7h5v1.5H5zM13 16h7v1.5h-7zM5 11h5v1.5H5zM13 8h7v1.5h-7zM5 15h5v1.5H5z" />
</svg>
</button>
</div>
<div id="textinput" contenteditable="true">
Start typing here or paste your styled text...
</div>
<div id="htmlView"></div>
<button class="button" id="Button_Enter"
onclick="sendTextToServer(document.getElementById('textinput').innerHTML)">Enter</button> <!-- innerHTML로 보내야 함!! -->
<button class="button" id="Button_Review" onclick="sendTextToServer('98')">Review</button>
<button class="button" id="Button_Copy" onclick="sendTextToServer('99')">Copy</button>
<button class="button" id="Button_Paste" onclick="sendTextToServer('100')">Paste</button>
<button class="button" id="Button_Save" onclick="sendTextToServer('save')">Save</button>
<button class="button" id="Button_Paste" onclick="sendTextToServer('backUp')">backUp</button>
<button class="button" id="Button_ch+" onclick="sendTextToServer('ch+')">ch+</button>
<button class="button" id="Button_ch-" onclick="sendTextToServer('ch-')">ch-</button><br />
<p id="info2"></p>
<p class="collapsible">Log</p>
<p class="LogInfo" id="Log"> </p>
<p class="collapsible">Info</p>
<p class="LogInfo" id="info"> </p> <br />
<textarea id="fileContent" rows="1"></textarea><br />
<button id="saveFileChanges" onclick="saveFileChanges()">Save Changes</button>
<div>coordinates: <span id="readout"></span></div>
<canvas id="canvas2" width="150" height="150"></canvas>
<p id="deviceInfo"></p>
</div>
</div>
</div>
<div id="control-buttons">
<button id="moveForward" class="direction-btn forward">▲</button>
<button id="moveLeft" class="direction-btn left">◀</button>
<button id="moveRight" class="direction-btn right">▶</button>
<button id="moveBackward" class="direction-btn backward">▼</button>
</div>
<!--
for most samples webgl-utils only provides shader compiling/linking and
canvas resizing because why clutter the examples with code that's the same in every sample.
See https://webglfundamentals.org/webgl/lessons/webgl-boilerplate.html
and https://webglfundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html
for webgl-utils, m3, m4, and webgl-lessons-ui.
-->
<script src="https://webgl2fundamentals.org/webgl/resources/webgl-lessons-ui.js"></script>
<script src="https://webgl2fundamentals.org/webgl/resources/twgl-full.min.js"></script>
<script src="https://webgl2fundamentals.org/webgl/resources/m4.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/gl-matrix-min.js"></script>
<script src="https://webgl2fundamentals.org/webgl/resources/flattened-primitives.js"></script>
<script src="https://unpkg.com/[email protected]/build/three.min.js"></script>
<!-- stats.js -->
<script>
// stats.js - http://github.com/mrdoob/stats.js
(function (f, e) { "object" === typeof exports && "undefined" !== typeof module ? module.exports = e() : "function" === typeof define && define.amd ? define(e) : f.Stats = e() })(this, function () {
var f = function () {
function e(a) { c.appendChild(a.dom); return a } function u(a) { for (var d = 0; d < c.children.length; d++)c.children[d].style.display = d === a ? "block" : "none"; l = a } var l = 0, c = document.createElement("div"); c.style.cssText = "position:fixed;top:0;right:0;cursor:pointer;opacity:0.9;z-index:10000"; c.addEventListener("click", function (a) {
a.preventDefault();
u(++l % c.children.length)
}, !1); var k = (performance || Date).now(), g = k, a = 0, r = e(new f.Panel("FPS", "#0ff", "#002")), h = e(new f.Panel("MS", "#0f0", "#020")); if (self.performance && self.performance.memory) var t = e(new f.Panel("MB", "#f08", "#201")); u(0); return {
REVISION: 16, dom: c, addPanel: e, showPanel: u, begin: function () { k = (performance || Date).now() }, end: function () {
a++; var c = (performance || Date).now(); h.update(c - k, 200); if (c > g + 1E3 && (r.update(1E3 * a / (c - g), 100), g = c, a = 0, t)) {
var d = performance.memory; t.update(d.usedJSHeapSize /
1048576, d.jsHeapSizeLimit / 1048576)
} return c
}, update: function () { k = this.end() }, domElement: c, setMode: u
}
}; f.Panel = function (e, f, l) {
var c = Infinity, k = 0, g = Math.round, a = g(window.devicePixelRatio || 1), r = 80 * a, h = 48 * a, t = 3 * a, v = 2 * a, d = 3 * a, m = 15 * a, n = 74 * a, p = 30 * a, q = document.createElement("canvas"); q.width = r; q.height = h; q.style.cssText = "width:80px;height:48px"; var b = q.getContext("2d"); b.font = "bold " + 9 * a + "px Helvetica,Arial,sans-serif"; b.textBaseline = "top"; b.fillStyle = l; b.fillRect(0, 0, r, h); b.fillStyle = f; b.fillText(e, t, v);
b.fillRect(d, m, n, p); b.fillStyle = l; b.globalAlpha = .9; b.fillRect(d, m, n, p); return { dom: q, update: function (h, w) { c = Math.min(c, h); k = Math.max(k, h); b.fillStyle = l; b.globalAlpha = 1; b.fillRect(0, 0, r, m); b.fillStyle = f; b.fillText(g(h) + " " + e + " (" + g(c) + "-" + g(k) + ")", t, v); b.drawImage(q, d + a, m, n - a, p, d, m, n - a, p); b.fillRect(d + n - a, m, a, p); b.fillStyle = l; b.globalAlpha = .9; b.fillRect(d + n - a, m, a, g((1 - h / w) * p)) } }
}; return f
});
var colorPicker2 = document.getElementById('colorPicker2');
var opacityRange = document.getElementById('opacityRange');
var div = document.getElementById('overlay');
function updateBackgroundColor() {
var color = colorPicker2.value;
var opacity = opacityRange.value / 100;
div.style.backgroundColor = `rgba(${parseInt(color.slice(1, 3), 16)}, ${parseInt(color.slice(3, 5), 16)}, ${parseInt(color.slice(5, 7), 16)}, ${opacity})`;
}
colorPicker2.addEventListener('input', updateBackgroundColor);
opacityRange.addEventListener('input', updateBackgroundColor);
let resizableDiv = document.getElementById('overlay');
let resizeHandle = document.getElementById('resizeHandle');
resizeHandle.addEventListener('mousedown', function (e) {
e.preventDefault(); // 텍스트 선택 방지
window.addEventListener('mousemove', resize, false);
window.addEventListener('mouseup', stopResize, false);
});
function resize(e) {
resizableDiv.style.width = e.clientX - resizableDiv.offsetLeft + 'px';
resizableDiv.style.height = e.clientY - resizableDiv.offsetTop + 'px';
}
function stopResize() {
window.removeEventListener('mousemove', resize, false);
window.removeEventListener('mouseup', stopResize, false);
}
</script>
<script>
function toggleContainer() {
var contentDiv = document.getElementById("content");
var toggleBtn = document.getElementById("toggleButton");
if (contentDiv.style.display === "none") {
contentDiv.style.display = "block";
toggleBtn.innerText = "Minimize";
} else {
contentDiv.style.display = "none";
toggleBtn.innerText = "Restore";
}
}
function detectDeviceType() {
const ua = navigator.userAgent;
if (/mobile/i.test(ua)) {
return 'Mobile';
} else if (/tablet|ipad/i.test(ua)) {
return 'Tablet';
} else {
return 'Desktop';
}
}
const deviceType = detectDeviceType();
document.getElementById('deviceInfo').innerHTML = `접속한 디바이스 타입: ${deviceType}`;
// import * as THREE from 'three';
// Set up the scene, camera, and renderer
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1600);
camera.position.y = 30;
camera.position.z = 10;
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x111111); // Light grey background color
renderer.shadowMap.enabled = true; // 그림자 맵 활성화
document.body.appendChild(renderer.domElement);
// Stats 설정
const stats = new Stats();
document.body.appendChild(stats.dom);
// 키 입력 및 마우스 상태 관리
//let isDragging = false;
let previousMouseX = 0, previousMouseY = 0;
let rotationSpeed = 0.005;
// Add ambient light
const ambientLight = new THREE.AmbientLight(0xffffff, 0.05); // Soft white light
scene.add(ambientLight);
// const sunLight = new THREE.Vector3(0, 20, -100);
// // Add directional light
// const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
// directionalLight.position.set(0, 20, -100);
// directionalLight.castShadow = true; // 그림자 발생 설정
// directionalLight.shadow.mapSize.width = 1024; // 그림자 해상도
// directionalLight.shadow.mapSize.height = 1024;
// directionalLight.shadow.camera.near = 0.5;
// directionalLight.shadow.camera.far = 130;
// scene.add(directionalLight);
// PointLight로 태양 구현
const sunLight = new THREE.PointLight(0xffffff, 4000, 1600, 2);
const sunPosition = new THREE.Vector3(0, 20, -20); // 태양을 원점에서 x축으로 10 단위 이동
sunLight.position.copy(sunPosition); // 태양의 위치
sunLight.castShadow = true; // 그림자 생성 활성화
scene.add(sunLight);
// 태양 구현: 빛을 내는 구
const sunGeometry = new THREE.SphereGeometry(4, 32, 32);
const sunMaterial = new THREE.MeshBasicMaterial({ color: 0xffff00 }); // 빛을 내므로 그림자 필요 없음
const sunSphere = new THREE.Mesh(sunGeometry, sunMaterial);
sunSphere.position.copy(sunPosition);
scene.add(sunSphere);
// 중력 및 운동 변수
//const gravity = -0.02; // 중력 상수
var gravity = new THREE.Vector3(); // 중력 벡터
let cameraVelocity = new THREE.Vector3(); // 이동 속도 벡터
let onGround = true; // 접지 확인
window.addEventListener('resize', onWindowResize);
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
// 키보드 이벤트 리스너
const keys = {};
const keyActions = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', ' '];
const directions = {
'moveForward': 'ArrowUp',
'moveBackward': 'ArrowDown',
'moveLeft': 'ArrowLeft',
'moveRight': 'ArrowRight'
};
function setKeyState(key, state) {
const inputTextArea = document.getElementById('textinput');
if (keyActions.includes(key) && document.activeElement !== inputTextArea) {
event.preventDefault();
keys[key] = state;
if (key === ' ' && state === true && onGround) { //'Space' key is set as ' ';
console.log("key = " + key + ", state = " + state + ", onGround = " + onGround);
performJump();
}
}
}
function performJump() {
// 중력의 반대 방향으로 점프 초기화
const jumpDirection = gravity.clone().negate().normalize(); // 중력의 반대 방향 벡터
const jumpSpeed = 1; // 점프 속도, 이 값을 조절하여 점프 높이 변경 가능
cameraVelocity.copy(jumpDirection.multiplyScalar(jumpSpeed));
onGround = false; // 접지 상태 해제
}
document.addEventListener('keydown', (event) => setKeyState(event.key, true));
document.addEventListener('keyup', (event) => setKeyState(event.key, false));
Object.entries(directions).forEach(([buttonId, keyName]) => {
const button = document.getElementById(buttonId);
button.addEventListener('touchstart', (event) => setKeyState(keyName, true));
button.addEventListener('touchend', (event) => setKeyState(keyName, false));
});
const planetSizeFactor = 16;
const planets = [
{ name: "Mercury", color: 0xaaaaaa, size: 0.4 * planetSizeFactor, distance: 10 * planetSizeFactor, speed: 0.04, mass: 0.5 },
{ name: "Venus", color: 0xffdd99, size: 0.9 * planetSizeFactor, distance: 15 * planetSizeFactor, speed: 0.03, mass: 0.8 },
{ name: "Earth", color: 0x2233ff, size: 1 * planetSizeFactor, distance: 20 * planetSizeFactor, speed: 0.01, mass: 1 },
{ name: "Mars", color: 0xff4422, size: 0.6 * planetSizeFactor, distance: 30 * planetSizeFactor, speed: 0.018, mass: 0.7 },
{ name: "Jupiter", color: 0x884411, size: 2.4 * planetSizeFactor, distance: 40 * planetSizeFactor, speed: 0.01, mass: 2.5 },
{ name: "Saturn", color: 0xffee33, size: 2 * planetSizeFactor, distance: 50 * planetSizeFactor, speed: 0.009, mass: 2 }
];
function createPlanet(planet) {
const geometry = new THREE.SphereGeometry(planet.size, 32, 32);
const material = new THREE.MeshPhongMaterial({ color: planet.color });
const mesh = new THREE.Mesh(geometry, material);
mesh.position.x = sunPosition.x + planet.distance; // 태양 위치를 기준으로 행성의 초기 위치 설정
mesh.position.y = sunPosition.y;
scene.add(mesh);
// 궤도 생성
const orbitGeometry = new THREE.RingGeometry(planet.distance - 0.1, planet.distance + 0.1, 64, 1);
const orbitMaterial = new THREE.MeshBasicMaterial({ color: 0x888888, side: THREE.DoubleSide });
const orbit = new THREE.Mesh(orbitGeometry, orbitMaterial);
orbit.position.copy(sunPosition);
orbit.rotation.x = Math.PI / 2;
scene.add(orbit);
return { mesh, name: planet.name, speed: planet.speed, distance: planet.distance, mass: planet.mass, radius: planet.size };
}
const planetObjects = planets.map(createPlanet);
function getEarthPosition() {
const earth = planetObjects.find(planet => planet.name === "Earth");
return earth ? earth.mesh.position.clone() : null;
}
function getPlanetMass(planets, planetName) {
// planets 배열을 순회하여 일치하는 이름의 행성을 찾습니다.
const planet = planets.find(p => p.name === planetName);
// 행성이 발견되면 질량을 반환합니다.
if (planet) {
return planet.mass;
} else {
// 일치하는 행성이 없는 경우, 오류 메시지를 반환하거나 null을 반환할 수 있습니다.
console.log("Planet not found");
return null;
}
}
// 행성 초기화 시 위치와 속도 벡터 추가
const gravitationalConstant = 0.5; // 물리학에서 사용하는 중력 상수 (예제에서는 다르게 조정할 수 있음)
const sunMass = 1000; // 태양 질량, 적절히 조정 필요
// 달 생성
const moonGeometry = new THREE.SphereGeometry(1, 32, 32);
const moonMaterial = new THREE.MeshPhongMaterial({ color: 0x888888 });
const moon = new THREE.Mesh(moonGeometry, moonMaterial);
var earthPosition = getEarthPosition();
moon.position.x = earthPosition.x + 5; // 지구에서 약 384,400 km 떨어진 거리에 설정
moon.position.y = earthPosition.y;
moon.position.z = earthPosition.z;
//moon.position.set(5, 20, -10);
scene.add(moon);
const moonMass = 0.5;
const earthMass = getPlanetMass(planets, "Earth");
const moonSpeed = Math.sqrt(gravitationalConstant * earthMass / 5); // 달의 초기 공전 속도
const moonVelocity = new THREE.Vector3(0, 0, moonSpeed);
// 마우스 이벤트 리스너
let lastX, lastY, isDragging = false;
function handleStart(x, y) {
isDragging = true;
lastX = x;
lastY = y;
}
function handleMove(x, y) {
if (!isDragging) return;
const deltaX = x - lastX;
const deltaY = y - lastY;
// 카메라의 현재 전방향과 오른쪽 방향을 구합니다.
const cameraDirection = new THREE.Vector3();
camera.getWorldDirection(cameraDirection);
const cameraRight = new THREE.Vector3().crossVectors(camera.up, cameraDirection).normalize();
// 마우스 움직임에 따라 회전 축을 설정합니다.
const angleX = deltaX * 0.005; // 좌우 이동
const angleY = deltaY * 0.005; // 상하 이동
const quaternionX = new THREE.Quaternion().setFromAxisAngle(camera.up, -angleX); // 카메라 오른쪽 축
const quaternionY = new THREE.Quaternion().setFromAxisAngle(cameraRight, angleY); // 카메라 전방향 축
camera.quaternion.multiplyQuaternions(quaternionX, camera.quaternion);
camera.quaternion.multiplyQuaternions(quaternionY, camera.quaternion);
lastX = x;
lastY = y;
//camera.updateProjectionMatrix();
}
function handleEnd() {
isDragging = false;
}
// 마우스 이벤트
document.addEventListener('mousedown', (event) => {
handleStart(event.clientX, event.clientY);
});
document.addEventListener('mousemove', (event) => {
handleMove(event.clientX, event.clientY);
});
document.addEventListener('mouseup', handleEnd);
// 터치 이벤트
document.addEventListener('touchstart', (event) => {
const touch = event.touches[0];
handleStart(touch.clientX, touch.clientY);
}, { passive: false });
document.addEventListener('touchmove', (event) => {
const touch = event.touches[0];
handleMove(touch.clientX, touch.clientY);
event.preventDefault(); // 스크롤 방지
}, { passive: false });
document.addEventListener('touchend', handleEnd);
// 충돌을 감지하는 함수
function checkCollision(cameraPosition, direction, distance) {
const raycaster = new THREE.Raycaster(cameraPosition, direction);
const intersects = raycaster.intersectObjects(scene.children.filter(obj => obj !== gridHelper), true); // 격자를 제외한 모든 객체와 충돌 검사
if (intersects.length > 0) {
console.log(intersects[0].distance);
}
if (intersects.length > 0 && intersects[0].distance < distance) {
// 충돌 발생
return true;
}
// 충돌 없음
return false;
}
// 카메라 이동 업데이트
function updateCamera() {
const speed = 0.1;
const direction = new THREE.Vector3();
// 현재 카메라의 방향을 기준으로 전진, 후진 벡터 계산
camera.getWorldDirection(direction);
// 새로운 카메라 위치 계산
const newPosition = camera.position.clone();
if (keys['ArrowUp']) newPosition.addScaledVector(direction, speed);
if (keys['ArrowDown']) newPosition.addScaledVector(direction, -speed);
// 좌우 이동을 위해 원래 벡터에 대해 오른쪽 방향으로 90도 회전
var direction2 = direction;
direction.crossVectors(camera.up, direction).normalize();
var rightDirection = direction;
if (keys['ArrowLeft']) newPosition.addScaledVector(direction, speed);
if (keys['ArrowRight']) newPosition.addScaledVector(direction, -speed);
// 충돌 검사
const collisionDistance = 1; // 충돌을 감지할 거리
const directionDifference = newPosition.clone().sub(camera.position);
const forwardCollision = checkCollision(camera.position, directionDifference, collisionDistance);
if (!forwardCollision) {
// 충돌이 발생하지 않으면 카메라 위치 업데이트
camera.position.copy(newPosition);
}
// if (keys['Space'] && onGround) {
// velocityY = 0.4; // 점프 초기 속도 설정
// onGround = false; // 공중에 떠있음
// }
camera.updateProjectionMatrix();
}
// Create a cube
const cubeGeometry = new THREE.BoxGeometry(0.5, 0.5, 0.5);
const cubeMaterial = new THREE.MeshPhongMaterial({ color: 0x00ff00 }); // Green cube
const cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
cube.position.y = 1;
cube.castShadow = true; // 그림자 생성 설정
cube.receiveShadow = false;
scene.add(cube);
const textureLoader = new THREE.TextureLoader();
function createFloor(width, height, color, position) {
const geometry = new THREE.PlaneGeometry(width, height);
const material = new THREE.MeshPhongMaterial({ color: color, side: THREE.DoubleSide });
const floor = new THREE.Mesh(geometry, material);
floor.rotation.x = -Math.PI / 2; // Rotate the plane to be horizontal
floor.position.copy(position);
floor.receiveShadow = true;
scene.add(floor);
}
//createFloor(200, 200, 0x778899, new THREE.Vector3(0, 0, 0));
createFloor(2, 20, 0x556677, new THREE.Vector3(1, 0.02, 0));
// 격자 무늬를 추가할 GridHelper 생성
const gridSize = 200; // 격자의 전체 크기
const gridSpacing = 1; // 격자의 간격
const gridHelper = new THREE.GridHelper(gridSize, gridSize / gridSpacing, 0x666666, 0x666666); // 첫 번째 매개변수는 전체 크기, 두 번째 매개변수는 격자 개수, 세 번째 매개변수는 격자 색상, 네 번째 매개변수는 선 색상
gridHelper.position.y = 0.01; // 바닥 평면과 겹치지 않도록 약간 띄웁니다.
scene.add(gridHelper);
function createBox(width, height, depth, color, position) {
const geometry = new THREE.BoxGeometry(width, height, depth);
const material = new THREE.MeshPhongMaterial({ color: color });
const box = new THREE.Mesh(geometry, material);
box.position.copy(position);
box.castShadow = true;
box.receiveShadow = true;
scene.add(box);
}
createBox(10, 4, 0.1, 0xeeeeee, new THREE.Vector3(-5, 2, -10));
createBox(8, 4, 0.1, 0xeeeeee, new THREE.Vector3(6, 2, -10));
createBox(20, 1, 0.1, 0xeeeeee, new THREE.Vector3(0, 4.5, -10));
// 텍스처 링크
const woodTextureURL = 'https://cdn.pixabay.com/photo/2017/02/07/09/02/wood-2045379_1280.jpg'; // 여기에 실제 텍스처 링크를 입력하세요
// 텍스처 로드
const woodTexture = textureLoader.load(woodTextureURL);
// 문
const doorGeometry = new THREE.BoxGeometry(2, 4, 0.1);
const doorMaterial = new THREE.MeshPhongMaterial({ map: woodTexture });
const door = new THREE.Mesh(doorGeometry, doorMaterial);
door.geometry.translate(1, 0, 0);
door.position.set(0, 2, -10);
// 문의 기하학적 중심을 하단 모서리로 이동
scene.add(door);
// 문 손잡이
const handleGeometry = new THREE.CylinderGeometry(0.1, 0.1, 0.5, 32);
const handleMaterial = new THREE.MeshBasicMaterial({ color: 0x8b4513 });
const handle = new THREE.Mesh(handleGeometry, handleMaterial);
handle.position.set(1.8, 0, 0);
// 문에 손잡이를 붙이기
door.add(handle);
// 문의 초기 상태 설정
let doorIsOpen = false;
const doorOpenAngle = Math.PI / 2; // 문이 90도까지 열리도록 설정
const doorSpeed = 0.03; // 문 열리는 속도
const starsGeometry = new THREE.BufferGeometry();
const starCount = 10000;
const positions = new Float32Array(starCount * 3);
const colors = new Float32Array(starCount * 3); // 각 별의 색상
const radius = 1500;
const sizes = new Float32Array(starCount); // 크기 배열
function generateTemperature() {
// 모든 별의 온도를 흰색이 나타나는 범위인 6000K ~ 10000K로 고정
const temperature = 4000 + Math.random() * 20000; // 6000K에서 10000K 사이의 균일 분포
//const temperature = 8000; // 6000K에서 10000K 사이의 균일 분포
return temperature;
}
function planck(T, lambda) {
const h = 6.62607015e-34; // Planck constant (Joule second)
const c = 2.998e8; // Speed of light (meters per second)
const k = 1.380649e-23; // Boltzmann constant (Joule per kelvin)
const exponent = (h * c) / (lambda * k * T);
const density = (8 * Math.PI * h * c) / (Math.pow(lambda, 5) * (Math.exp(exponent) - 1));
return density;
}
function temperatureToColor(T) {
const wavelengths = { red: 700e-9, green: 546.1e-9, blue: 435.8e-9 }; // Wavelengths in meters
const scale = { red: 255 * 12.0e-8, green: 255 * 2.0e-9, blue: 255 * 8.25e-7 }; // Scale factors for color intensities
//const scale = { red: 1e-13, green: 1.5e-13, blue: 2.5e-13 }; // Adjusted scale factors for color intensities
let rgb = { red: 0, green: 0, blue: 0 };
for (const color in wavelengths) {
const intensity = planck(T, wavelengths[color]);
rgb[color] = Math.round(Math.max(0, Math.min(255, intensity * scale[color])));
}
return new THREE.Color(rgb.red, rgb.green, rgb.blue);
}
for (let i = 0; i < starCount; i++) {
const theta = Math.random() * 2 * Math.PI;
const phi = Math.acos(2 * Math.random() - 1);
const x = radius * Math.sin(phi) * Math.cos(theta);
const y = radius * Math.sin(phi) * Math.sin(theta);
const z = radius * Math.cos(phi);
positions[i * 3] = x;
positions[i * 3 + 1] = y;
positions[i * 3 + 2] = z;
const temperature = generateTemperature();
const color = temperatureToColor(temperature);
colors[i * 3] = color.r;
colors[i * 3 + 1] = color.g;
colors[i * 3 + 2] = color.b;
sizes[i] = Math.random() * 3 + 0.4; // 별 크기를 0.4에서 2.0까지 랜덤 설정
}
starsGeometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
starsGeometry.setAttribute('color', new THREE.BufferAttribute(colors, 3));
starsGeometry.setAttribute('size', new THREE.BufferAttribute(sizes, 1));
const starsMaterial = new THREE.ShaderMaterial({
verticeshader: `
attribute float size;
attribute vec3 color;