-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
987 lines (867 loc) · 48.4 KB
/
index.html
File metadata and controls
987 lines (867 loc) · 48.4 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
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="アノテーション参考ツール">
<meta name="theme-color" content="#3498db">
<meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="0">
<title>アノテーション参考ツール</title>
<link rel="icon" type="image/png" href="./Logo.png">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Serif+JP:wght@400;600;700&family=Playfair+Display:wght@600;700&display=swap" rel="stylesheet">
<script>
// 毎回最新版の index.html を読み込むためのバージョン確認
(function () {
const VERSION = '2026-01-27-001';
const PARAM_KEY = 'v';
const url = new URL(window.location.href);
// URL のバージョンが異なる場合は付け直して再読み込み
if (url.searchParams.get(PARAM_KEY) !== VERSION) {
url.searchParams.set(PARAM_KEY, VERSION);
window.location.replace(url.toString());
return;
}
// 古い Service Worker やキャッシュを除去
if ('serviceWorker' in navigator) {
navigator.serviceWorker.getRegistrations().then((regs) => regs.forEach((r) => r.unregister()));
if (window.caches) {
caches.keys().then((keys) => keys.forEach((key) => caches.delete(key)));
}
}
})();
</script>
<style>
:root { --panel-scale: 1; }
body { margin: 0; background: radial-gradient(circle at 20% 20%, #fdf5e6 0%, #f2e6cf 40%, #e7d7bd 100%); font-family: 'Noto Serif JP', 'Playfair Display', 'Times New Roman', serif; overflow: hidden; color: #3b2c28; }
#loading { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 10px; min-width: 220px; text-align: center; color: #6b4c3b; font-size: 18px; font-weight: bold; pointer-events: none; transition: opacity 0.5s; z-index: 200; background: rgba(255,255,255,0.9); padding: 20px; border-radius: 12px; border: 1px solid #d6c7a1; box-shadow: 0 10px 30px rgba(67,49,34,0.18); }
#loading img { width: 168px; height: 168px; object-fit: contain; }
.panel { position: absolute; width: clamp(260px, 30vw, 360px); background: linear-gradient(135deg, #fdf8ee 0%, #f6eddc 100%); padding: clamp(12px, 2.2vw, 18px); border-radius: 14px; border: 1px solid #d9c7a4; box-shadow: 0 14px 32px rgba(67,49,34,0.18), 0 0 0 6px rgba(255,255,255,0.6); display: flex; flex-direction: column; gap: clamp(10px, 2vw, 14px); z-index: 100; transition: transform 0.2s ease; transform: scale(var(--panel-scale, 1)); max-height: calc(100vh - 40px); overflow-y: auto; }
#control-panel { top: 20px; right: 20px; transform-origin: top right; }
#display-panel { top: 20px; left: 20px; transform-origin: top left; }
.slider-container { display: flex; flex-direction: column; gap: 8px; padding: 8px 0; }
.slider-container .slider-label { font-size: 17px; font-weight: 600; color: #4a3527; font-family: 'Playfair Display', 'Noto Serif JP', serif; }
.size-slider-wrapper { display: flex; align-items: center; gap: 10px; }
.size-slider-wrapper .size-label { font-size: 13px; color: #6b4c3b; font-weight: 700; min-width: 30px; text-align: center; font-family: 'Playfair Display', 'Noto Serif JP', serif; }
.size-slider { flex: 1; height: 8px; border-radius: 4px; background: linear-gradient(90deg, #d9c7a4, #c9b48b); outline: none; -webkit-appearance: none; appearance: none; }
.size-slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 18px; height: 18px; border-radius: 50%; background: #8a6f5a; cursor: pointer; transition: background 0.2s, transform 0.1s; box-shadow: 0 2px 6px rgba(0,0,0,0.2); border: 1px solid #f4e7d1; }
.size-slider::-webkit-slider-thumb:hover { background: #6f5746; }
.size-slider::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #8a6f5a; cursor: pointer; border: 1px solid #f4e7d1; transition: background 0.2s; box-shadow: 0 2px 6px rgba(0,0,0,0.2); }
.size-slider::-moz-range-thumb:hover { background: #6f5746; }
.size-indicator { text-align: center; font-size: 14px; color: #6b4c3b; font-weight: 700; margin-top: 4px; font-family: 'Playfair Display', 'Noto Serif JP', serif; }
#coordinate-display { position: fixed; bottom: 18px; left: 20px; transform: translate(0, 0); background: linear-gradient(135deg, #fdf8ee 0%, #f6eddc 100%); padding: 16px 24px; border-radius: 12px; box-shadow: 0 10px 30px rgba(67,49,34,0.18); border: 1px solid #d9c7a4; backdrop-filter: blur(10px); z-index: 110; min-width: 300px; }
#coordinate-display h3 { margin: 0 0 12px 0; font-size: 16px; color: #4a3527; text-align: center; border-bottom: 2px solid #c8ac78; padding-bottom: 8px; font-family: 'Playfair Display', serif; }
#control-panel::-webkit-scrollbar { width: 8px; }
#control-panel::-webkit-scrollbar-track { background: #f3e8d4; border-radius: 10px; }
#control-panel::-webkit-scrollbar-thumb { background: #b59a74; border-radius: 10px; border: 1px solid #e8d9bd; }
#control-panel::-webkit-scrollbar-thumb:hover { background: #9d815a; }
h2 { margin: 0 0 6px 0; font-size: clamp(18px, 2.2vw, 22px); color: #4a3527; border-bottom: 2px solid #c8ac78; padding-bottom: clamp(6px, 1.2vw, 10px); font-family: 'Playfair Display', serif; letter-spacing: 0.5px; text-shadow: 0 1px 0 #fff; }
.panel-title { display: flex; align-items: center; gap: 10px; }
.panel-title img { width: 28px; height: 28px; object-fit: contain; }
.section-block { background: #fbf6eb; border: 1px solid #e1d2b2; border-radius: 10px; overflow: hidden; box-shadow: inset 0 1px 0 rgba(255,255,255,0.7); }
.section-title { margin: 0; padding: clamp(8px, 1.6vw, 12px); font-weight: 700; font-size: clamp(16px, 1.8vw, 18px); color: #4a3527; background: linear-gradient(90deg, #f3e6ce, #e9dab9); border-bottom: 1px solid #d6c7a1; font-family: 'Playfair Display', serif; letter-spacing: 0.3px; }
.section-body { padding: clamp(8px, 1.6vw, 12px); }
button { padding: clamp(10px, 2vw, 14px) clamp(10px, 2vw, 14px); border: 1px solid #d6c299; background: linear-gradient(180deg, #f7ecd5, #e9d7b5); color: #4a3527; border-radius: 6px; font-size: clamp(14px, 1.6vw, 16px); font-weight: 600; cursor: pointer; transition: all 0.2s ease; width: 100%; min-height: 40px; box-shadow: 0 2px 6px rgba(67,49,34,0.15); }
button:hover { background: linear-gradient(180deg, #f3e3c2, #e2cda1); border-color: #c5ad7d; color: #3b2c28; }
button:active { background: #c8ac78; color: white; transform: scale(0.98); }
button.selected { background-color: #d7c399; border-color: #b99b68; font-weight: 700; }
.panel-toggle { position: absolute; top: 20px; left: 20px; width: auto; padding: 10px 14px; min-height: auto; font-size: 14px; border-radius: 8px; background: linear-gradient(180deg, #f7ecd5, #e9d7b5); border-color: #d6c299; box-shadow: 0 2px 6px rgba(67,49,34,0.15); display: none; z-index: 150; }
.gender-toggle { display: flex; gap: 8px; margin-bottom: 8px; }
.gender-toggle button { width: auto; flex: 1; }
#bone-selection-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.span-2 { grid-column: span 2; }
/* スイッチのスタイル */
.switch-container { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }
.switch-label { font-size: 17px; font-weight: 600; color: #4a3527; font-family: 'Playfair Display', 'Noto Serif JP', serif; }
.switch { position: relative; display: inline-block; width: 46px; height: 24px; }
.switch-group { display: flex; align-items: center; gap: 8px; }
.switch-text { font-size: 12px; font-weight: 700; color: #6b4c3b; user-select: none; }
.hint-inline { margin-top: 10px; background: #f5e9d4; border: 1px solid #d6c299; color: #3b2c28; padding: 12px 14px; border-radius: 10px; font-size: 21px; line-height: 1.6; display: none; box-shadow: inset 0 1px 0 rgba(255,255,255,0.7); }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #d8c7a7; transition: .3s; border-radius: 22px; border: 1px solid #c7b389; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px; background-color: #fffaf1; transition: .3s; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.15); }
input:checked + .slider { background-color: #a48368; border-color: #8f7258; }
input:checked + .slider:before { transform: translateX(22px); }
.slider:hover { background-color: #cdbb97; }
input:checked + .slider:hover { background-color: #94755d; }
</style>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.160.0/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.160.0/examples/jsm/"
}
}
</script>
</head>
<body>
<div id="loading"><img src="./Logo.png" alt="logo"><span id="loading-text">モデルを読み込み中...</span></div>
<div id="control-panel" class="panel">
<h2><span class="panel-title"><img src="./Logo.png" alt="logo">アノテーション参考ツール</span></h2>
<div class="section-block">
<h3 class="section-title">性別</h3>
<div class="section-body" style="padding-top: 10px;">
<div class="gender-toggle" aria-label="性別切り替え">
<button id="gender-male" class="selected">男性</button>
<button id="gender-female">女性</button>
</div>
</div>
</div>
<div class="section-block">
<h3 class="section-title">関節選択</h3>
<div class="section-body">
<div id="bone-selection-list"></div>
<button onclick="window.attachModelRotation(this)" style="margin-top: 8px; background:#e3f2fd; border-color:#90caf9; color:#1976d2;">全体回転</button>
<button onclick="window.detachGizmo()" style="margin-top: 8px; background:#fff3cd; border-color:#ffe082; color:#b26a00;">選択解除</button>
<button onclick="window.resetModel()" style="margin-top: 8px; background:#d5f5e3; border-color:#a3e4d7; color:#1e8449;">姿勢リセット</button>
</div>
</div>
</div>
<div id="display-panel" class="panel">
<h2>表示設定</h2>
<div class="section-block">
<div class="section-body">
<div class="switch-container">
<span class="switch-label">骨格参考線</span>
<div class="switch-group">
<span class="switch-text">OFF</span>
<label class="switch">
<input type="checkbox" id="switch-armature" checked>
<span class="slider"></span>
</label>
<span class="switch-text">ON</span>
</div>
</div>
<div class="switch-container">
<span class="switch-label">グリッド</span>
<div class="switch-group">
<span class="switch-text">OFF</span>
<label class="switch">
<input type="checkbox" id="switch-grid" checked>
<span class="slider"></span>
</label>
<span class="switch-text">ON</span>
</div>
</div>
</div>
</div>
<div class="section-block">
<h3 class="section-title">パネルサイズ</h3>
<div class="section-body">
<div class="slider-container" style="padding:0;">
<div class="size-slider-wrapper">
<span class="size-label">小</span>
<input type="range" id="panel-size-slider" class="size-slider" min="0" max="100" value="50" step="1">
<span class="size-label">大</span>
</div>
<div class="size-indicator" id="size-indicator">100%</div>
</div>
</div>
</div>
<div class="section-block">
<div class="section-body">
<button onclick="window.showHintMessage()" style="margin-top: 4px; width:100%; padding:8px 12px; min-height:auto; font-size:13px; background:#e8f4ff; border-color:#bbdefb; color:#1e88e5;">作業ヒント</button>
<div id="hint-inline" class="hint-inline"></div>
<button onclick="window.reloadSite()" style="width:100%; margin-top:10px; padding:8px 12px; min-height:auto; font-size:13px; background:#e3f2fd; border-color:#90caf9; color:#1e88e5;">サイトリロード</button>
<button id="display-panel-hide" style="width:100%; margin-top:10px; padding:8px 12px; min-height:auto; font-size:13px; background:#f3e3c2; border-color:#c5ad7d; color:#3b2c28;">パネルを隠す</button>
</div>
</div>
<!-- Lovot 比較は一時的に非表示(有効化する場合はこのブロックのコメントを外してください)
<div class="section-block">
<h3 class="section-title">Lovot 比較</h3>
<div class="section-body">
<div class="switch-container">
<span class="switch-label">Lovot比較</span>
<label class="switch">
<input type="checkbox" id="switch-lovot" checked>
<span class="slider"></span>
</label>
</div>
</div>
</div>
-->
</div>
<div id="coordinate-display">
<div style="display:flex; align-items:center; justify-content:space-between; gap:16px;">
<div style="color:#000; font-weight:700; font-size:16px;">カメラ距離: <span id="camera-distance">-</span></div>
<details id="coord-details" style="margin:0;">
<summary style="cursor:pointer; font-weight:600; color:#3498db; font-size:12px; list-style:none; user-select:none; padding:4px 8px; background:#f0f8ff; border-radius:4px;">📍 詳細座標</summary>
<div style="display:grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top:12px; padding-top:12px; border-top:1px solid #eee;">
<div style="font-size:15px; font-family:monospace; line-height:1.6;">
<div style="font-weight:600; margin-bottom:6px;">カメラ</div>
<div style="color:#ff0000;">X: <span id="camera-x">0.00</span></div>
<div style="color:#00aa00;">Y: <span id="camera-y">0.00</span></div>
<div style="color:#0000ff;">Z: <span id="camera-z">0.00</span></div>
</div>
<div style="font-size:15px; font-family:monospace; line-height:1.6;">
<div style="font-weight:600; margin-bottom:6px;">関節</div>
<div style="color:#888; margin-bottom:3px; font-size:13px;" id="bone-name">未選択</div>
<div style="color:#ff0000;">X: <span id="bone-x">-</span></div>
<div style="color:#00aa00;">Y: <span id="bone-y">-</span></div>
<div style="color:#0000ff;">Z: <span id="bone-z">-</span></div>
</div>
</div>
</details>
</div>
</div>
<button id="display-panel-toggle" class="panel-toggle">表示設定を開く</button>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { TransformControls } from 'three/addons/controls/TransformControls.js';
// シーン設定
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf5f7fa);
scene.fog = new THREE.Fog(0xf5f7fa, 20, 100);
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 10000);
camera.position.set(0, 1.00, 5.00);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
document.body.appendChild(renderer.domElement);
// ローダー
const textureLoader = new THREE.TextureLoader();
// 照明設定
scene.add(new THREE.AmbientLight(0xffffff, 1.0));
const dirLight = new THREE.DirectionalLight(0xffffff, 1.5);
dirLight.position.set(5, 10, 7);
dirLight.castShadow = true;
scene.add(dirLight);
// グリッド
const gridHelper = new THREE.GridHelper(30, 30, 0x888888, 0xcccccc);
gridHelper.position.y = 0;
gridHelper.material.opacity = 0.5;
gridHelper.material.transparent = true;
scene.add(gridHelper);
// カスタム座標軸 (X=赤, Z=青, Yは非表示)
// X軸(赤)
const xAxisMaterial = new THREE.LineBasicMaterial({ color: 0xff0000 });
const xAxisGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-5, 0, 0),
new THREE.Vector3(5, 0, 0)
]);
const xAxis = new THREE.Line(xAxisGeometry, xAxisMaterial);
scene.add(xAxis);
// Z軸(青)
const zAxisMaterial = new THREE.LineBasicMaterial({ color: 0x0000ff });
const zAxisGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0, -5),
new THREE.Vector3(0, 0, 5)
]);
const zAxis = new THREE.Line(zAxisGeometry, zAxisMaterial);
scene.add(zAxis);
// コントローラー
const orbit = new OrbitControls(camera, renderer.domElement);
orbit.enableDamping = true;
orbit.dampingFactor = 0.15; // smooth but responsive damping
orbit.minDistance = 0.2; // fixed minimum distance
orbit.maxDistance = 20.0; // fixed maximum distance
orbit.zoomSpeed = 1.0; // standard scroll zoom speed
const control = new TransformControls(camera, renderer.domElement);
control.setSpace('local');
control.setMode('rotate');
control.addEventListener('dragging-changed', (event) => {
orbit.enabled = !event.value;
});
scene.add(control);
// 変数
let currentModel = null;
let allModelMeshes = [];
let foundBones = {};
let rawBonesList = [];
let armatureMeshes = []; // Armature メッシュ
let skeletonHelper = null; // 骨格ヘルパーライン
let octahedralBones = []; // ボーン接続ライン
let armatureInFrontEnabled = true; // Armature In Front 状態 (初期はON)
let selectedBone = null; // 現在選択中の関節
let selectedBoneName = ''; // 現在選択中の関節名
let boneMarkers = []; // 主要関節のカラードット
let lovotMesh = null; // Lovot 比較用プレーン
let lovotTexture = null;
let lovotVisible = false; // デフォルトで Lovot 比較を非表示
let hintVisible = false; // 操作ヒント表示状態
// DOM キャッシュ
const domRefs = {
cameraX: document.getElementById('camera-x'),
cameraY: document.getElementById('camera-y'),
cameraZ: document.getElementById('camera-z'),
cameraDistance: document.getElementById('camera-distance'),
boneName: document.getElementById('bone-name'),
boneX: document.getElementById('bone-x'),
boneY: document.getElementById('bone-y'),
boneZ: document.getElementById('bone-z')
};
const loadingOverlay = document.getElementById('loading');
const loadingTextEl = document.getElementById('loading-text');
function showLoading(message = 'モデルを読み込み中...') {
if (!loadingOverlay) return;
loadingOverlay.style.display = 'flex';
if (loadingTextEl) loadingTextEl.textContent = message;
}
function hideLoading() {
if (!loadingOverlay) return;
loadingOverlay.style.display = 'none';
}
// 共通一時ベクトル
const tmpBonePos = new THREE.Vector3();
const tmpMarkerPos = new THREE.Vector3();
const tmpBox = new THREE.Box3();
const tmpBoxSize = new THREE.Vector3();
const tmpBoxCenter = new THREE.Vector3();
const tmpLook = new THREE.Vector3();
const tmpSphere = new THREE.Sphere();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function normalizeModelScale(model) {
model.updateMatrixWorld(true);
tmpBox.setFromObject(model);
const height = tmpBox.max.y - tmpBox.min.y;
if (height > 0) {
const scale = THREE.MathUtils.clamp(TARGET_MODEL_HEIGHT / height, MIN_MODEL_SCALE, MAX_MODEL_SCALE);
model.scale.setScalar(scale);
model.updateMatrixWorld(true);
console.log(`📐 モデル自動スケール: height=${height.toFixed(3)} -> scale=${scale.toFixed(3)}`);
} else {
console.warn('⚠️ モデル高さが 0 のためスケーリングをスキップしました');
}
}
// 関節設定:名前・同義語・色をまとめて管理
const BONE_CONFIG = {
Hips: { displayName: '骨盤', color: 0xf5deb3, synonyms: ['pelvis', 'root', 'hips', 'mixamorig:Hips'] },
Spine: { displayName: '腰', color: 0xf5deb3, synonyms: ['spine', 'chest', 'torso', 'mixamorig:spine'] },
Head: { displayName: '首', color: 0xf5deb3, synonyms: ['head', 'neck', 'mixamorig:head'] },
RightUpLeg: { displayName: '右股関節', color: 0x33ccff, synonyms: ['rightupleg', 'thigh_r', 'mixamorig:rightupleg'] },
LeftUpLeg: { displayName: '左股関節', color: 0x8b0000, synonyms: ['leftupleg', 'thigh_l', 'mixamorig:leftupleg'] },
RightLeg: { displayName: '右膝', color: 0xf5deb3, synonyms: ['rightleg', 'calf_r', 'mixamorig:rightleg'] },
LeftLeg: { displayName: '左膝', color: 0xf5deb3, synonyms: ['leftleg', 'calf_l', 'mixamorig:leftleg'] },
RightFoot: { displayName: '右足首', color: 0xf5deb3, synonyms: ['rightfoot', 'foot_r', 'mixamorig:rightfoot'] },
LeftFoot: { displayName: '左足首', color: 0xf5deb3, synonyms: ['leftfoot', 'foot_l', 'mixamorig:leftfoot'] },
RightArm: { displayName: '右肩', color: 0x00bfa5, synonyms: ['rightarm', 'upperarm_r', 'mixamorig:rightarm'] },
LeftArm: { displayName: '左肩', color: 0x00008b, synonyms: ['leftarm', 'upperarm_l', 'mixamorig:leftarm'] },
RightForeArm: { displayName: '右肘', color: 0xf5deb3, synonyms: ['rightforearm', 'forearm_r', 'mixamorig:rightforearm'] },
LeftForeArm: { displayName: '左肘', color: 0xf5deb3, synonyms: ['leftforearm', 'forearm_l', 'mixamorig:leftforearm'] }
};
const KEY_JOINT_ORDER = [
'Head',
'LeftArm', 'RightArm',
'LeftForeArm', 'RightForeArm',
'Spine',
'Hips',
'LeftUpLeg', 'RightUpLeg',
'LeftLeg', 'RightLeg',
'LeftFoot', 'RightFoot'
];
const LOVOT_IMG_URL = './lovot.jpg';
const LOVOT_HEIGHT = 0.43; // meters (Lovot 実寸に合わせて調整)
const TARGET_MODEL_HEIGHT = 1.7; // meters, auto-scale models to this height
const MIN_MODEL_SCALE = 0.01;
const MAX_MODEL_SCALE = 10;
const MODEL_URL_MALE = './model.glb';
const MODEL_URL_FEMALE = './model_female.glb';
let currentModelUrl = MODEL_URL_MALE;
// モデルを読み込む
const loader = new GLTFLoader();
function loadModel(modelUrl, options = {}) {
const { loadingText } = options;
showLoading(loadingText || 'モデルを読み込み中...');
loader.load(modelUrl, (gltf) => {
currentModelUrl = modelUrl;
console.log(`GLB読み込み成功: ${modelUrl}`);
// 以前の選択を解除し、コントローラーが古い骨を指さないようにする
control.detach();
selectedBone = null;
selectedBoneName = '';
domRefs.boneName.textContent = '未選択';
domRefs.boneX.textContent = '-';
domRefs.boneY.textContent = '-';
domRefs.boneZ.textContent = '-';
initModel(gltf.scene);
}, undefined, (err) => {
console.warn(`${modelUrl} の読み込みに失敗`, err);
showLoading(`モデルの読み込みに失敗しました!\n${modelUrl} ファイルが存在することを確認してください。`);
});
}
loadModel(currentModelUrl);
// モデルリセット:GLB を再読込して初期状態へ
window.resetModel = function() {
showLoading('リセット中...');
control.detach();
selectedBone = null;
selectedBoneName = '';
domRefs.boneName.textContent = '未選択';
domRefs.boneX.textContent = '-';
domRefs.boneY.textContent = '-';
domRefs.boneZ.textContent = '-';
loadModel(currentModelUrl, { loadingText: 'リセット中...' });
};
function initModel(model) {
if (currentModel) scene.remove(currentModel);
currentModel = model;
// 自動スケーリング
normalizeModelScale(currentModel);
// データコンテナを初期化
allModelMeshes = [];
foundBones = {};
rawBonesList = [];
armatureMeshes = [];
console.log('🔍 モデル構造の詳細解析を開始...');
// 1回目: 全オブジェクトを走査
model.traverse(o => {
// ボーンを収集
if (o.isBone) {
if (!foundBones[o.name]) {
rawBonesList.push(o.name);
foundBones[o.name] = o;
console.log(`🦴 骨を検出: ${o.name}`);
}
}
// メッシュを収集
if (o.isMesh) {
allModelMeshes.push(o);
const nameLower = o.name.toLowerCase();
if (nameLower.includes('armature')) {
armatureMeshes.push(o);
}
}
});
// Armature 表示状態を初期設定に合わせる
armatureMeshes.forEach(mesh => {
mesh.visible = armatureInFrontEnabled;
setArmatureInFront(mesh, armatureInFrontEnabled);
});
scene.add(currentModel);
// --- ボーン接続ラインを生成 ---
if (rawBonesList.length > 0) {
// 既存の骨格をクリア
if (skeletonHelper) {
scene.remove(skeletonHelper);
skeletonHelper.dispose();
skeletonHelper = null;
}
octahedralBones.forEach(obj => {
if (obj.parent) obj.parent.remove(obj);
});
octahedralBones = [];
createOctahedralSkeleton();
console.log(`✨ ${rawBonesList.length} 本のボーンに基づき接続ラインを生成しました`);
}
// カラー関節マーカーを作成
createBoneMarkers();
// Lovot 比較は一時停止。必要ならコメントを外して有効化
// ensureLovotBillboard();
// updateLovotPlacement();
// UI を構築
buildBoneSelectionUI();
hideLoading();
focusCenter();
}
// 作業ヒント表示関数(パネル内でトグル表示)
window.showHintMessage = function() {
const box = document.getElementById('hint-inline');
if (!box) return;
hintVisible = !hintVisible;
if (hintVisible) {
box.innerHTML = '💡 作業ヒント:<br>1.関節選択のリストをクリックして関節を選択し、カラフルなリングで姿勢を調整します。<br>2.hipの位置はマーク通りですが、shoulderはマークより少し斜め上です。(正面の角度)<br>3.操作にはマウス左クリック又は Ctrl+左クリック。';
box.style.display = 'block';
} else {
box.style.display = 'none';
box.innerHTML = '';
}
};
// サイトをリロード
window.reloadSite = function() {
window.location.reload();
};
// ボーン接続ラインシステムを生成
function createOctahedralSkeleton() {
// 各ボーンに接続ラインを作成
rawBonesList.forEach(boneName => {
const bone = foundBones[boneName];
if (bone && bone.parent && bone.parent.isBone) {
// 接続ライン(シリンダー)を作成
const parent = bone.parent;
const line = createBoneLine(parent, bone);
if (line) {
scene.add(line);
octahedralBones.push(line);
}
}
});
}
// ボーン接続ライン(シリンダー)を生成
function createBoneLine(parent, child) {
const parentPos = new THREE.Vector3();
const childPos = new THREE.Vector3();
const direction = new THREE.Vector3();
parent.getWorldPosition(parentPos);
child.getWorldPosition(childPos);
const distance = parentPos.distanceTo(childPos);
if (distance < 0.001) return null; // 短すぎる場合は作成しない
direction.subVectors(childPos, parentPos);
const cylinderGeometry = new THREE.CylinderGeometry(0.005, 0.005, distance, 8);
const cylinderMaterial = new THREE.MeshBasicMaterial({
color: 0xffff00,
transparent: false,
opacity: 1.0,
depthTest: false,
depthWrite: false
});
const cylinder = new THREE.Mesh(cylinderGeometry, cylinderMaterial);
cylinder.material.opacity = 1.0; // 透明度は固定
cylinder.position.copy(parentPos).add(direction.multiplyScalar(0.5));
// ボーンに合わせて回転を設定
const axis = new THREE.Vector3(0, 1, 0);
cylinder.quaternion.setFromUnitVectors(axis, direction.normalize());
cylinder.renderOrder = 997;
cylinder.visible = armatureInFrontEnabled;
// ボーンに追従するグループを作成
const group = new THREE.Group();
group.add(cylinder);
// 毎フレーム位置を更新する関数
group.userData.updatePosition = function() {
parent.getWorldPosition(parentPos);
child.getWorldPosition(childPos);
const newDistance = parentPos.distanceTo(childPos);
const newDirection = direction.subVectors(childPos, parentPos);
cylinder.position.copy(parentPos).add(newDirection.clone().multiplyScalar(0.5));
cylinder.scale.y = newDistance / distance;
cylinder.quaternion.setFromUnitVectors(axis, newDirection.normalize());
};
return group;
}
// 関節の解決:同義語でボーンを検索
function resolveBone(key) {
const config = BONE_CONFIG[key];
if (!config) return null;
const synonyms = config.synonyms || [];
for (const syn of synonyms) {
const lowerSyn = syn.toLowerCase();
const normalizedSyn = lowerSyn.replace(/[^a-z0-9]/g, '');
for (const name in foundBones) {
const lowerName = name.toLowerCase();
const normalizedName = lowerName.replace(/[^a-z0-9]/g, '');
if (
lowerName === lowerSyn ||
lowerName.includes(lowerSyn) ||
normalizedName === normalizedSyn
) {
return foundBones[name];
}
}
}
return null;
}
// 主要関節用のカラーマーカーを作成
function createBoneMarkers() {
// 既存マーカーを削除
boneMarkers.forEach(marker => {
if (marker.mesh && marker.mesh.parent) {
marker.mesh.parent.remove(marker.mesh);
}
});
boneMarkers = [];
const sphereGeo = new THREE.SphereGeometry(0.03, 10, 10);
Object.entries(BONE_CONFIG).forEach(([key, config]) => {
const bone = resolveBone(key);
if (!bone) {
console.warn(`⚠️ 対応する骨が見つかりません: ${key}`);
return;
}
const mat = new THREE.MeshBasicMaterial({ color: config.color, depthTest: false, depthWrite: false });
const mesh = new THREE.Mesh(sphereGeo, mat);
mesh.renderOrder = 1200;
mesh.userData.targetBone = bone;
scene.add(mesh);
boneMarkers.push({ mesh, bone, displayName: config.displayName || bone.name });
});
console.log(`🌈 ${boneMarkers.length} 個の関節カラーマーカーを生成しました`);
}
// Lovot 平面の表示制御
function setLovotVisible(enabled) {
lovotVisible = enabled;
if (lovotMesh) lovotMesh.visible = enabled;
}
function updateLovotPlacement() {
if (!lovotMesh || !currentModel) return;
tmpBox.setFromObject(currentModel);
tmpBox.getCenter(tmpBoxCenter);
tmpBox.getSize(tmpBoxSize);
const groundY = tmpBox.min.y;
const aspect = (lovotTexture && lovotTexture.image && lovotTexture.image.height)
? lovotTexture.image.width / lovotTexture.image.height
: 0.8;
const width = LOVOT_HEIGHT * aspect;
lovotMesh.scale.set(width, LOVOT_HEIGHT, 1);
const offsetX = (tmpBoxSize.x * 0.5) + (width * 0.5) + 0.2;
lovotMesh.position.set(
tmpBoxCenter.x - offsetX,
groundY + (LOVOT_HEIGHT * 0.5),
tmpBoxCenter.z
);
}
function ensureLovotBillboard() {
if (lovotMesh) {
updateLovotPlacement();
return;
}
textureLoader.load(LOVOT_IMG_URL, (tex) => {
lovotTexture = tex;
const mat = new THREE.MeshBasicMaterial({ map: tex, transparent: true, side: THREE.DoubleSide });
const geo = new THREE.PlaneGeometry(1, 1);
lovotMesh = new THREE.Mesh(geo, mat);
lovotMesh.renderOrder = 900;
scene.add(lovotMesh);
setLovotVisible(lovotVisible);
updateLovotPlacement();
}, undefined, (err) => {
console.warn('Lovot 画像の読み込みに失敗しました', err);
});
}
// Armature In Front の設定/解除
function setArmatureInFront(mesh, enabled) {
if (enabled) {
mesh.renderOrder = 1000;
if (mesh.material) {
mesh.material.depthTest = false;
mesh.material.depthWrite = false;
}
} else {
mesh.renderOrder = 0;
if (mesh.material) {
mesh.material.depthTest = true;
mesh.material.depthWrite = true;
}
}
}
// ★★★ この関数でフィルタ済みの関節ボタンを生成 ★★★
function buildBoneSelectionUI() {
const displayDiv = document.getElementById('bone-selection-list');
if (!displayDiv) return;
let html = '';
KEY_JOINT_ORDER.forEach(key => {
const bone = resolveBone(key);
if (!bone) return;
const displayName = BONE_CONFIG[key]?.displayName || key;
const span2 = (key === 'Hips' || key === 'Spine' || key === 'Head') ? 'class="span-2"' : '';
html += `<button ${span2} onclick="window.attachGizmo('${bone.name}', this)">${displayName}</button>`;
});
displayDiv.innerHTML = html;
}
function getSelectableButtons() {
return document.querySelectorAll('#bone-selection-list button, button[onclick*="attachModelRotation"]');
}
function setSelectedButton(element) {
getSelectableButtons().forEach(btn => btn.classList.remove('selected'));
if (element) {
element.classList.add('selected');
}
}
window.attachModelRotation = function(element) {
if (currentModel) {
control.attach(currentModel);
setSelectedButton(element);
}
};
// HTML ボタンから呼び出すためのグローバル関数
window.attachGizmo = function(boneName, element) {
const bone = foundBones[boneName];
if (bone) {
control.attach(bone);
selectedBone = bone;
selectedBoneName = boneName;
setSelectedButton(element);
}
};
window.detachGizmo = function() {
control.detach();
selectedBone = null;
selectedBoneName = '';
domRefs.boneName.textContent = '未選択';
domRefs.boneX.textContent = '-';
domRefs.boneY.textContent = '-';
domRefs.boneZ.textContent = '-';
setSelectedButton(null);
};
function selectBoneFromMarker(marker) {
if (!marker || !marker.bone) return;
control.attach(marker.bone);
selectedBone = marker.bone;
selectedBoneName = marker.displayName || marker.bone.name;
domRefs.boneName.textContent = selectedBoneName;
setSelectedButton(null);
}
function handleMarkerPick(event) {
if (!boneMarkers.length) return;
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersects = raycaster.intersectObjects(boneMarkers.map(m => m.mesh), false);
if (intersects.length === 0) return;
const hitMesh = intersects[0].object;
const marker = boneMarkers.find(m => m.mesh === hitMesh);
if (marker) {
selectBoneFromMarker(marker);
}
}
renderer.domElement.addEventListener('pointerdown', handleMarkerPick);
function animate() {
requestAnimationFrame(animate);
orbit.update();
// ボーン接続ラインの位置を更新
octahedralBones.forEach(obj => {
if (obj.userData.updatePosition) {
obj.userData.updatePosition();
}
});
// カメラ座標を更新
domRefs.cameraX.textContent = camera.position.x.toFixed(2);
domRefs.cameraY.textContent = camera.position.y.toFixed(2);
domRefs.cameraZ.textContent = camera.position.z.toFixed(2);
// カメラから骨盤までの距離を計算して表示
const hipsBone = resolveBone('Hips');
if (hipsBone) {
hipsBone.getWorldPosition(tmpBonePos);
const distance = camera.position.distanceTo(tmpBonePos);
domRefs.cameraDistance.textContent = distance.toFixed(2) + ' m';
} else {
domRefs.cameraDistance.textContent = '-';
}
// 選択中の関節座標を更新
if (selectedBone) {
selectedBone.getWorldPosition(tmpBonePos);
domRefs.boneName.textContent = selectedBoneName;
domRefs.boneX.textContent = tmpBonePos.x.toFixed(2);
domRefs.boneY.textContent = tmpBonePos.y.toFixed(2);
domRefs.boneZ.textContent = tmpBonePos.z.toFixed(2);
}
// カラー関節マーカーの位置と距離スケーリングを更新
boneMarkers.forEach(marker => {
marker.bone.getWorldPosition(tmpMarkerPos);
marker.mesh.position.copy(tmpMarkerPos);
const dist = camera.position.distanceTo(tmpMarkerPos);
const scale = THREE.MathUtils.clamp(dist * 0.12, 0.5, 3.0);
marker.mesh.scale.setScalar(scale);
});
// Lovot 平面をカメラに向ける(水平回転のみで直立を維持)
if (lovotMesh && lovotMesh.visible) {
tmpLook.set(camera.position.x, lovotMesh.position.y, camera.position.z);
lovotMesh.lookAt(tmpLook);
}
renderer.render(scene, camera);
}
animate();
window.focusCenter = function() {
if (!currentModel) return;
// モデル中心に合わせてカメラを設定(固定ズーム範囲)
tmpBox.setFromObject(currentModel);
tmpBox.getCenter(tmpBoxCenter);
tmpBox.getBoundingSphere(tmpSphere);
const radius = tmpSphere.radius || 1;
// 距離範囲を固定してジャンプを防止
orbit.minDistance = 0.2;
orbit.maxDistance = 20.0;
camera.position.set(
tmpBoxCenter.x,
tmpBoxCenter.y + radius * 0.5,
tmpBoxCenter.z + 5.0
);
orbit.target.copy(tmpBoxCenter);
camera.lookAt(tmpBoxCenter);
orbit.update();
};
// --- イベントリスナー ---
const gridSwitch = document.getElementById('switch-grid');
if (gridSwitch) {
gridSwitch.addEventListener('change', (e) => {
gridHelper.visible = e.target.checked;
console.log(`グリッド: ${gridHelper.visible ? 'ON' : 'OFF'}`);
});
}
const armatureSwitch = document.getElementById('switch-armature');
if (armatureSwitch) {
armatureSwitch.addEventListener('change', (e) => {
armatureInFrontEnabled = e.target.checked;
console.log(`🔄 Armature 切り替え: ${armatureInFrontEnabled ? 'ON' : 'OFF'}`);
armatureMeshes.forEach(mesh => {
mesh.visible = armatureInFrontEnabled;
setArmatureInFront(mesh, armatureInFrontEnabled);
});
// ボーン接続ラインを制御
octahedralBones.forEach(obj => {
obj.visible = armatureInFrontEnabled;
});
console.log(`✨ ボーン接続ライン: visible=${armatureInFrontEnabled}`);
});
}
const genderButtons = {
male: document.getElementById('gender-male'),
female: document.getElementById('gender-female')
};
function setGender(gender) {
if (!genderButtons.male || !genderButtons.female) return;
const useFemale = gender === 'female';
genderButtons.male.classList.toggle('selected', !useFemale);
genderButtons.female.classList.toggle('selected', useFemale);
const targetUrl = useFemale ? MODEL_URL_FEMALE : MODEL_URL_MALE;
if (targetUrl === currentModelUrl) return;
const loadingText = useFemale ? '女性モデル読み込み中...' : '男性モデル読み込み中...';
loadModel(targetUrl, { loadingText });
}
if (genderButtons.male && genderButtons.female) {
genderButtons.male.addEventListener('click', () => setGender('male'));
genderButtons.female.addEventListener('click', () => setGender('female'));
// 初期選択を反映
const initialGender = currentModelUrl === MODEL_URL_FEMALE ? 'female' : 'male';
genderButtons.male.classList.toggle('selected', initialGender === 'male');
genderButtons.female.classList.toggle('selected', initialGender === 'female');
}
const panelSizeSlider = document.getElementById('panel-size-slider');
const sizeIndicator = document.getElementById('size-indicator');
if (panelSizeSlider && sizeIndicator) {
panelSizeSlider.addEventListener('input', (e) => {
const value = parseInt(e.target.value);
// 0-100 の範囲を 0.7-1.3 のスケールに変換
const scale = 0.7 + (value / 100) * 0.6;
document.documentElement.style.setProperty('--panel-scale', scale.toFixed(2));
// パーセンテージ表示
const percentage = Math.round(scale * 100);
sizeIndicator.textContent = `${percentage}%`;
console.log(`パネルサイズ: ${percentage}%`);
});
}
// コントロールパネルは max-height とスクロールで常に全項目にアクセス可能
// Lovot 比較は一時的に無効。再有効化する場合は以下のリスナーを戻してください
// const lovotSwitch = document.getElementById('switch-lovot');
// if (lovotSwitch) {
// lovotSwitch.addEventListener('change', (e) => {
// setLovotVisible(e.target.checked);
// console.log(`Lovot 比較: ${e.target.checked ? 'ON' : 'OFF'}`);
// });
// }
// 表示設定パネルの開閉
const displayPanel = document.getElementById('display-panel');
const displayPanelHideBtn = document.getElementById('display-panel-hide');
const displayPanelToggle = document.getElementById('display-panel-toggle');
if (displayPanelHideBtn && displayPanel && displayPanelToggle) {
displayPanelHideBtn.addEventListener('click', () => {
displayPanel.style.display = 'none';
displayPanelToggle.style.display = 'block';
});
displayPanelToggle.addEventListener('click', () => {
displayPanel.style.display = 'flex';
displayPanelToggle.style.display = 'none';
});
}
window.onresize = () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
};
</script>
</body>
</html>