-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1130 lines (970 loc) · 39.9 KB
/
index.html
File metadata and controls
1130 lines (970 loc) · 39.9 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="PranaMap - Interactive energy healing intake system for Reiki practitioners and patients">
<title>PranaMap | Energy Healing Intake System</title>
<!-- ============================================
EXTERNAL DEPENDENCIES
Three.js library for 3D rendering
============================================= -->
<script src="https://unpkg.com/three@0.128.0/build/three.min.js"></script>
<script src="https://unpkg.com/three@0.128.0/examples/js/loaders/GLTFLoader.js"></script>
<style>
/* ==========================================
CSS RESET & BASE STYLES
Normalize browser defaults
========================================== */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f5f5f5;
color: #333;
min-height: 100vh;
display: flex;
flex-direction: column;
}
/* ==========================================
HEADER & NAVIGATION
Top bar with logo and navigation links
========================================== */
header {
background-color: #fff;
border-bottom: 1px solid #e0e0e0;
padding: 1.25rem 2rem;
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
font-size: 1.5rem;
font-weight: 600;
color: #2c3e50;
letter-spacing: 0.5px;
}
.logo span {
font-weight: 300;
color: #7f8c8d;
}
nav {
display: flex;
gap: 2rem;
}
nav a {
text-decoration: none;
color: #7f8c8d;
font-size: 0.9rem;
transition: color 0.2s ease;
}
nav a:hover {
color: #2c3e50;
}
/* ==========================================
MAIN LAYOUT
Two-column layout: viewer + sidebar panel
========================================== */
main {
flex: 1;
display: flex;
padding: 2rem;
gap: 2rem;
}
/* ==========================================
3D VIEWER CONTAINER
Houses the Three.js canvas and lotus backdrop
========================================== */
.viewer-container {
flex: 2;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
position: relative;
height: 480px;
max-height: 480px;
overflow: hidden;
}
/* Lotus SVG positioned behind the 3D model */
.lotus-backdrop {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 450px;
height: 360px;
pointer-events: none; /* Allow clicks to pass through */
z-index: 5;
}
/* Three.js canvas container */
#canvas-container {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 10;
}
/* Loading state overlay */
.loading-indicator {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 0.9rem;
color: #7f8c8d;
z-index: 15;
}
/* Instructions tooltip at bottom of viewer */
.viewer-instructions {
position: absolute;
bottom: 1rem;
left: 1rem;
background: rgba(255, 255, 255, 0.95);
padding: 0.75rem 1rem;
border-radius: 4px;
font-size: 0.8rem;
color: #7f8c8d;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
z-index: 20;
}
/* ==========================================
SIDEBAR PANEL
Contains Energy Centers list and Session Summary
========================================== */
.panel {
flex: 1;
display: flex;
flex-direction: column;
gap: 1.5rem;
}
/* Card component - reusable container style */
.card {
background-color: #fff;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
padding: 1.5rem;
}
.card h2 {
font-size: 1rem;
font-weight: 600;
color: #2c3e50;
margin-bottom: 1rem;
padding-bottom: 0.75rem;
border-bottom: 1px solid #eee;
}
/* ==========================================
CHAKRA LIST
Clickable list of energy centers
========================================== */
.chakra-list {
list-style: none;
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.chakra-item {
display: flex;
align-items: center;
padding: 0.75rem;
border-radius: 6px;
cursor: pointer;
transition: background-color 0.2s ease;
border: 1px solid transparent;
}
.chakra-item:hover {
background-color: #f8f9fa;
}
.chakra-item.selected {
background-color: #f0f4f8;
border-color: #d0d9e0;
}
/* Colored dot indicator for each chakra */
.chakra-indicator {
width: 12px;
height: 12px;
border-radius: 50%;
margin-right: 0.75rem;
}
.chakra-name {
font-size: 0.9rem;
color: #2c3e50;
flex: 1;
}
.chakra-sanskrit {
font-size: 0.75rem;
color: #95a5a6;
font-style: italic;
}
/* Status dot - shows if chakra has been marked */
.chakra-status {
width: 8px;
height: 8px;
border-radius: 50%;
background-color: #e0e0e0;
margin-left: 0.5rem;
}
.chakra-status.marked {
background-color: #e74c3c;
}
/* ==========================================
CHAKRA DETAIL PANEL
Shows when a chakra is selected
========================================== */
.selected-info {
display: none;
margin-top: 1rem;
padding-top: 1rem;
border-top: 1px solid #eee;
}
.selected-info.visible {
display: block;
}
.selected-info h3 {
font-size: 0.95rem;
color: #2c3e50;
margin-bottom: 0.5rem;
}
.selected-info p {
font-size: 0.85rem;
color: #7f8c8d;
line-height: 1.5;
margin-bottom: 1rem;
}
.acupoint-reference {
font-size: 0.75rem;
color: #95a5a6;
margin-top: 0.25rem;
}
/* ==========================================
FORM ELEMENTS
Slider, textarea, buttons
========================================== */
.intensity-label {
font-size: 0.8rem;
color: #7f8c8d;
margin-bottom: 0.5rem;
}
.intensity-slider {
width: 100%;
margin-bottom: 1rem;
}
textarea {
width: 100%;
padding: 0.75rem;
border: 1px solid #e0e0e0;
border-radius: 4px;
font-family: inherit;
font-size: 0.85rem;
resize: vertical;
min-height: 80px;
transition: border-color 0.2s ease;
}
textarea:focus {
outline: none;
border-color: #bdc3c7;
}
textarea::placeholder {
color: #bdc3c7;
}
/* Button styles */
.btn {
padding: 0.75rem 1.5rem;
border: none;
border-radius: 4px;
font-size: 0.85rem;
cursor: pointer;
transition: all 0.2s ease;
margin-top: 0.5rem;
}
.btn-primary {
background-color: #2c3e50;
color: #fff;
}
.btn-primary:hover {
background-color: #34495e;
}
.btn-secondary {
background-color: #ecf0f1;
color: #2c3e50;
}
.btn-secondary:hover {
background-color: #d5dbdb;
}
/* ==========================================
FOOTER
Bottom bar with attribution
========================================== */
footer {
background-color: #fff;
border-top: 1px solid #e0e0e0;
padding: 1rem 2rem;
text-align: center;
font-size: 0.8rem;
color: #95a5a6;
}
</style>
</head>
<body>
<!-- ==========================================
HEADER
Logo and main navigation
=========================================== -->
<header>
<div class="logo">Prana<span>Map</span></div>
<nav aria-label="Main navigation">
<a href="#" class="active">Patient Intake</a>
<a href="#">Session History</a>
<a href="#">About</a>
</nav>
</header>
<!-- ==========================================
MAIN CONTENT
Two-column layout with 3D viewer and sidebar
=========================================== -->
<main>
<!-- 3D Viewer Section -->
<section class="viewer-container" aria-label="3D body viewer">
<!-- Decorative lotus flower backdrop -->
<div class="lotus-backdrop" aria-hidden="true">
<svg viewBox="0 0 400 300" xmlns="http://www.w3.org/2000/svg">
<!-- Center petal -->
<ellipse cx="200" cy="150" rx="25" ry="70" fill="#c9a227" opacity="0.15"/>
<!-- Inner petals - rotated symmetrically -->
<ellipse cx="200" cy="150" rx="25" ry="70" fill="#c9a227" opacity="0.12" transform="rotate(-20, 200, 150)"/>
<ellipse cx="200" cy="150" rx="25" ry="70" fill="#c9a227" opacity="0.12" transform="rotate(20, 200, 150)"/>
<!-- Middle petals -->
<ellipse cx="200" cy="150" rx="28" ry="75" fill="#c9a227" opacity="0.10" transform="rotate(-40, 200, 150)"/>
<ellipse cx="200" cy="150" rx="28" ry="75" fill="#c9a227" opacity="0.10" transform="rotate(40, 200, 150)"/>
<!-- Outer petals -->
<ellipse cx="200" cy="150" rx="32" ry="82" fill="#c9a227" opacity="0.08" transform="rotate(-60, 200, 150)"/>
<ellipse cx="200" cy="150" rx="32" ry="82" fill="#c9a227" opacity="0.08" transform="rotate(60, 200, 150)"/>
<ellipse cx="200" cy="150" rx="36" ry="90" fill="#c9a227" opacity="0.06" transform="rotate(-80, 200, 150)"/>
<ellipse cx="200" cy="150" rx="36" ry="90" fill="#c9a227" opacity="0.06" transform="rotate(80, 200, 150)"/>
<!-- Base petals - horizontal foundation -->
<ellipse cx="200" cy="185" rx="55" ry="18" fill="#c9a227" opacity="0.10"/>
<ellipse cx="150" cy="178" rx="35" ry="12" fill="#c9a227" opacity="0.07" transform="rotate(-15, 150, 178)"/>
<ellipse cx="250" cy="178" rx="35" ry="12" fill="#c9a227" opacity="0.07" transform="rotate(15, 250, 178)"/>
</svg>
</div>
<!-- Three.js renders into this container -->
<div id="canvas-container"></div>
<!-- Loading state - hidden once model loads -->
<div class="loading-indicator" id="loading-indicator">Loading model...</div>
<!-- User instructions -->
<div class="viewer-instructions">
Click and drag to rotate. Scroll to zoom. Click a chakra point to select.
</div>
</section>
<!-- Sidebar Panel -->
<aside class="panel">
<!-- Energy Centers Card -->
<article class="card">
<h2>Energy Centers</h2>
<!-- Chakra list populated by JavaScript -->
<ul class="chakra-list" id="chakra-list" role="listbox" aria-label="Select a chakra"></ul>
<!-- Detail panel - shown when chakra is selected -->
<div class="selected-info" id="selected-info">
<h3 id="selected-name"></h3>
<p id="selected-description"></p>
<p class="acupoint-reference" id="selected-acupoint"></p>
<label class="intensity-label" for="intensity-slider">
Intensity of imbalance felt
</label>
<input
type="range"
class="intensity-slider"
id="intensity-slider"
min="1"
max="10"
value="5"
aria-describedby="intensity-description"
>
<textarea
id="notes-input"
placeholder="Describe what you are experiencing in this area..."
aria-label="Notes about this chakra"
></textarea>
<button class="btn btn-primary" id="mark-btn">Mark as Area of Concern</button>
</div>
</article>
<!-- Session Summary Card -->
<article class="card">
<h2>Session Summary</h2>
<p id="summary-text" style="font-size: 0.85rem; color: #7f8c8d;">
No areas marked yet. Select chakra points on the figure or from the list to indicate areas where you feel energetic imbalance.
</p>
<button class="btn btn-secondary" id="clear-btn" style="display: none;">Clear All</button>
<button class="btn btn-primary" id="submit-btn" style="display: none; margin-left: 0.5rem;">Submit to Practitioner</button>
</article>
</aside>
</main>
<!-- ==========================================
FOOTER
Attribution and project info
=========================================== -->
<footer>
<p>PranaMap — Energy Healing Intake System. Inspired by bioelectric field research.</p>
</footer>
<!-- ==========================================
JAVASCRIPT
Application logic for 3D viewer and UI
=========================================== -->
<script>
/* ==========================================
CHAKRA DATA CONFIGURATION
Defines the 7 primary chakras with their
properties, colors, and 3D positions
========================================== */
const CHAKRA_DATA = [
{
id: 'crown',
name: 'Crown',
sanskrit: 'Sahasrara',
color: 0x9c27b0, // Violet
position: { x: 0, y: 18.5, z: 0 },
description: 'Spiritual connection, higher consciousness, enlightenment, and unity with the divine.',
acupoint: 'Correlates to GV20 (Bai Hui) — Point of energy union measured at top of head'
},
{
id: 'third-eye',
name: 'Third Eye',
sanskrit: 'Ajna',
color: 0x3f51b5, // Indigo
position: { x: 0, y: 17.2, z: 1.2 },
description: 'Intuition, inner wisdom, insight, and perception beyond ordinary sight.',
acupoint: 'Located between the eyebrows, associated with pineal gland function'
},
{
id: 'throat',
name: 'Throat',
sanskrit: 'Vishuddha',
color: 0x2196f3, // Blue
position: { x: 0, y: 15.5, z: 0.8 },
description: 'Communication, self-expression, truth, and authenticity.',
acupoint: 'Thyroid region, connected to expression and metabolism'
},
{
id: 'heart',
name: 'Heart',
sanskrit: 'Anahata',
color: 0x4caf50, // Green
position: { x: 0, y: 13.8, z: 1.0 },
description: 'Love, compassion, emotional balance, and connection to others.',
acupoint: 'Correlates to HT7 — Heart meridian measurement point'
},
{
id: 'solar-plexus',
name: 'Solar Plexus',
sanskrit: 'Manipura',
color: 0xffeb3b, // Yellow
position: { x: 0, y: 12.0, z: 1.2 },
description: 'Personal power, confidence, willpower, and self-esteem.',
acupoint: 'Correlates to CT12 — Solar plexus measurement point'
},
{
id: 'sacral',
name: 'Sacral',
sanskrit: 'Svadhisthana',
color: 0xff9800, // Orange
position: { x: 0, y: 10.2, z: 1.0 },
description: 'Creativity, emotions, sensuality, pleasure, and adaptability.',
acupoint: 'Lower abdominal region, connected to reproductive and digestive systems'
},
{
id: 'root',
name: 'Root',
sanskrit: 'Muladhara',
color: 0xf44336, // Red
position: { x: 0, y: 8.5, z: 0.5 },
description: 'Grounding, survival, security, and physical vitality.',
acupoint: 'Base of spine, correlates to BL24 — Bladder meridian points (lumbar region)'
}
];
/* ==========================================
APPLICATION STATE
Global variables for tracking app state
========================================== */
let selectedChakra = null; // Currently selected chakra object
let markedChakras = {}; // Object storing marked chakras and their data
// Three.js scene components
let scene, camera, renderer;
let humanGroup, humanModel;
let chakraMeshes = {}; // Maps chakra IDs to their 3D mesh objects
// Mouse interaction state
let isDragging = false;
let prevMouseX = 0;
let prevMouseY = 0;
/* ==========================================
THREE.JS SCENE INITIALIZATION
========================================== */
/**
* Initializes the Three.js scene, camera, renderer, and lighting.
* Sets up event listeners for user interaction.
*/
function initScene() {
const container = document.getElementById('canvas-container');
const width = container.clientWidth;
const height = container.clientHeight;
// Create scene with transparent background
scene = new THREE.Scene();
scene.background = null;
// Configure camera - positioned to see full body
camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 1000);
camera.position.set(0, 13, 45);
// Configure renderer with transparency support
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setClearColor(0x000000, 0);
renderer.setSize(width, height);
renderer.setPixelRatio(window.devicePixelRatio);
container.appendChild(renderer.domElement);
// Set up lighting
setupLighting();
// Create group to hold human model and chakras
humanGroup = new THREE.Group();
scene.add(humanGroup);
// Load the 3D human model
loadHumanModel();
// Attach event listeners
attachEventListeners();
// Start render loop
animate();
}
/**
* Configures scene lighting for optimal model visibility.
* Uses ambient light plus three directional lights for depth.
*/
function setupLighting() {
// Soft ambient light for overall illumination
const ambientLight = new THREE.AmbientLight(0xffffff, 0.7);
scene.add(ambientLight);
// Main directional light from upper right
const mainLight = new THREE.DirectionalLight(0xffffff, 0.8);
mainLight.position.set(10, 20, 15);
scene.add(mainLight);
// Back light for depth
const backLight = new THREE.DirectionalLight(0xffffff, 0.4);
backLight.position.set(-10, 10, -10);
scene.add(backLight);
// Fill light from front
const fillLight = new THREE.DirectionalLight(0xffffff, 0.3);
fillLight.position.set(0, 5, 20);
scene.add(fillLight);
}
/**
* Attaches mouse and window event listeners for interaction.
*/
function attachEventListeners() {
const canvas = renderer.domElement;
canvas.addEventListener('mousedown', handleMouseDown);
canvas.addEventListener('mousemove', handleMouseMove);
canvas.addEventListener('mouseup', handleMouseUp);
canvas.addEventListener('wheel', handleMouseWheel);
canvas.addEventListener('click', handleCanvasClick);
window.addEventListener('resize', handleWindowResize);
}
/* ==========================================
MODEL LOADING
========================================== */
/**
* Loads the GLB human figure model and applies translucent material.
* Creates chakra points once model is loaded.
*/
function loadHumanModel() {
const loader = new THREE.GLTFLoader();
loader.load(
'pranamap-figure.glb',
onModelLoaded,
onModelProgress,
onModelError
);
}
/**
* Callback when model loads successfully.
* @param {Object} gltf - The loaded GLTF object
*/
function onModelLoaded(gltf) {
humanModel = gltf.scene;
// Apply translucent material to all meshes
humanModel.traverse(function(child) {
if (child.isMesh) {
child.material = new THREE.MeshPhongMaterial({
color: 0xc9b8a8, // Warm neutral tone
transparent: true,
opacity: 0.6, // Semi-transparent to show chakras
side: THREE.DoubleSide,
depthWrite: false
});
}
});
humanGroup.add(humanModel);
// Create chakra points on the model
createChakraPoints();
// Hide loading indicator
document.getElementById('loading-indicator').style.display = 'none';
}
/**
* Callback for model loading progress.
* @param {ProgressEvent} xhr - The progress event
*/
function onModelProgress(xhr) {
if (xhr.total > 0) {
const percent = (xhr.loaded / xhr.total * 100).toFixed(0);
document.getElementById('loading-indicator').textContent =
'Loading model... ' + percent + '%';
}
}
/**
* Callback for model loading error.
* @param {Error} error - The error object
*/
function onModelError(error) {
console.error('Error loading model:', error);
document.getElementById('loading-indicator').textContent =
'Error loading model. Please refresh.';
}
/* ==========================================
CHAKRA VISUALIZATION
========================================== */
/**
* Creates 3D sphere representations for each chakra.
* Each chakra has an outer glow sphere and inner core sphere.
*/
function createChakraPoints() {
CHAKRA_DATA.forEach(chakra => {
// Outer glow sphere - larger, more transparent
const glowGeometry = new THREE.SphereGeometry(0.35, 32, 32);
const glowMaterial = new THREE.MeshBasicMaterial({
color: chakra.color,
transparent: true,
opacity: 0.55
});
const glowSphere = new THREE.Mesh(glowGeometry, glowMaterial);
// Inner core sphere - smaller, fully opaque
const coreGeometry = new THREE.SphereGeometry(0.18, 32, 32);
const coreMaterial = new THREE.MeshBasicMaterial({
color: chakra.color,
transparent: true,
opacity: 1.0
});
const coreSphere = new THREE.Mesh(coreGeometry, coreMaterial);
// Group glow and core together
const chakraGroup = new THREE.Group();
chakraGroup.add(glowSphere);
chakraGroup.add(coreSphere);
chakraGroup.position.set(
chakra.position.x,
chakra.position.y,
chakra.position.z
);
// Store chakra ID for raycasting identification
chakraGroup.userData = { chakraId: chakra.id };
humanGroup.add(chakraGroup);
// Store reference for later manipulation
chakraMeshes[chakra.id] = {
group: chakraGroup,
glow: glowSphere,
core: coreSphere
};
});
}
/* ==========================================
ANIMATION LOOP
========================================== */
/**
* Main animation loop. Handles chakra pulsing animation
* and renders the scene.
*/
function animate() {
requestAnimationFrame(animate);
// Animate chakra pulsing effect
animateChakraPulse();
renderer.render(scene, camera);
}
/**
* Creates subtle pulsing animation for chakra glow spheres.
* Marked chakras pulse larger than unmarked ones.
*/
function animateChakraPulse() {
const time = Date.now() * 0.002;
Object.keys(chakraMeshes).forEach((id, index) => {
const mesh = chakraMeshes[id];
// Calculate pulse scale using sine wave
const pulse = 1 + Math.sin(time + index * 0.5) * 0.15;
// Marked chakras appear larger
const baseScale = markedChakras[id] ? 1.4 : 1;
mesh.glow.scale.setScalar(pulse * baseScale);
});
}
/* ==========================================
EVENT HANDLERS
========================================== */
/**
* Handles mouse down - starts drag rotation.
* @param {MouseEvent} event
*/
function handleMouseDown(event) {
isDragging = true;
prevMouseX = event.clientX;
prevMouseY = event.clientY;
}
/**
* Handles mouse move - rotates model if dragging.
* @param {MouseEvent} event
*/
function handleMouseMove(event) {
if (!isDragging) return;
const deltaX = event.clientX - prevMouseX;
const deltaY = event.clientY - prevMouseY;
// Rotate model based on mouse movement
humanGroup.rotation.y += deltaX * 0.01;
humanGroup.rotation.x += deltaY * 0.005;
// Clamp vertical rotation to prevent flipping
humanGroup.rotation.x = Math.max(-0.5, Math.min(0.5, humanGroup.rotation.x));
prevMouseX = event.clientX;
prevMouseY = event.clientY;
}
/**
* Handles mouse up - stops drag rotation.
*/
function handleMouseUp() {
isDragging = false;
}
/**
* Handles mouse wheel - zooms camera in/out.
* @param {WheelEvent} event
*/
function handleMouseWheel(event) {
event.preventDefault();
camera.position.z += event.deltaY * 0.05;
// Clamp zoom range
camera.position.z = Math.max(25, Math.min(80, camera.position.z));
}
/**
* Handles canvas click - selects chakra via raycasting.
* @param {MouseEvent} event
*/
function handleCanvasClick(event) {
// Ignore if user was dragging (not a click)
if (Math.abs(event.clientX - prevMouseX) > 5 ||
Math.abs(event.clientY - prevMouseY) > 5) {
return;
}
// Convert mouse position to normalized device coordinates
const rect = renderer.domElement.getBoundingClientRect();
const mouse = new THREE.Vector2(
((event.clientX - rect.left) / rect.width) * 2 - 1,
-((event.clientY - rect.top) / rect.height) * 2 + 1
);
// Raycast to find clicked chakra
const raycaster = new THREE.Raycaster();
raycaster.setFromCamera(mouse, camera);
// Collect all chakra meshes for intersection test
const chakraObjects = [];
Object.values(chakraMeshes).forEach(m => {
chakraObjects.push(m.glow, m.core);
});
const intersects = raycaster.intersectObjects(chakraObjects);
if (intersects.length > 0) {
const clickedObject = intersects[0].object;
const chakraGroup = clickedObject.parent;
const chakraId = chakraGroup.userData.chakraId;
if (chakraId) {
selectChakra(chakraId);
}
}
}
/**
* Handles window resize - updates camera and renderer.
*/
function handleWindowResize() {
const container = document.getElementById('canvas-container');
const width = container.clientWidth;
const height = container.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
}
/* ==========================================
UI FUNCTIONS
========================================== */
/**
* Builds the chakra list in the sidebar from CHAKRA_DATA.
* Called once on page load.
*/
function buildChakraList() {
const list = document.getElementById('chakra-list');
list.innerHTML = '';
CHAKRA_DATA.forEach(chakra => {
const li = document.createElement('li');
li.className = 'chakra-item';
li.dataset.chakraId = chakra.id;
li.setAttribute('role', 'option');
// Convert hex color to CSS format
const colorHex = '#' + chakra.color.toString(16).padStart(6, '0');
li.innerHTML = `
<div class="chakra-indicator" style="background-color: ${colorHex}"></div>
<span class="chakra-name">${chakra.name}</span>
<span class="chakra-sanskrit">${chakra.sanskrit}</span>
<div class="chakra-status" id="status-${chakra.id}"></div>
`;
li.addEventListener('click', () => selectChakra(chakra.id));
list.appendChild(li);
});
}
/**
* Selects a chakra and updates both UI and 3D visualization.
* @param {string} chakraId - The ID of the chakra to select
*/
function selectChakra(chakraId) {
selectedChakra = CHAKRA_DATA.find(c => c.id === chakraId);
// Update list selection state
document.querySelectorAll('.chakra-item').forEach(item => {
item.classList.toggle('selected', item.dataset.chakraId === chakraId);
});
// Show and populate detail panel
const infoPanel = document.getElementById('selected-info');
infoPanel.classList.add('visible');
document.getElementById('selected-name').textContent =
`${selectedChakra.name} — ${selectedChakra.sanskrit}`;
document.getElementById('selected-description').textContent =
selectedChakra.description;
document.getElementById('selected-acupoint').textContent =
selectedChakra.acupoint;
// Load existing data if chakra was previously marked
if (markedChakras[chakraId]) {
document.getElementById('intensity-slider').value =
markedChakras[chakraId].intensity;
document.getElementById('notes-input').value =
markedChakras[chakraId].notes;
document.getElementById('mark-btn').textContent = 'Update Concern';
} else {
document.getElementById('intensity-slider').value = 5;
document.getElementById('notes-input').value = '';
document.getElementById('mark-btn').textContent = 'Mark as Area of Concern';
}
// Highlight selected chakra in 3D view
highlightSelectedChakra(chakraId);
}
/**
* Highlights the selected chakra in the 3D visualization.
* @param {string} chakraId - The ID of the selected chakra
*/
function highlightSelectedChakra(chakraId) {
Object.keys(chakraMeshes).forEach(id => {
const mesh = chakraMeshes[id];
if (id === chakraId) {
// Selected chakra - brighter
mesh.core.material.opacity = 1;
mesh.glow.material.opacity = 0.7;