File size: 39,094 Bytes
1893477
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3c94bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1893477
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3c94bc
1893477
 
 
e3c94bc
1893477
 
 
e3c94bc
1893477
 
 
 
 
 
e3c94bc
1893477
 
 
e3c94bc
1893477
 
 
e3c94bc
1893477
 
e3c94bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1893477
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9e79c75
1893477
 
9e79c75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1893477
9e79c75
 
 
 
 
 
 
 
 
 
 
1893477
 
 
9e79c75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1893477
 
9e79c75
 
 
 
 
 
 
 
 
 
 
 
1893477
 
9e79c75
1893477
9e79c75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1893477
 
 
 
9e79c75
1893477
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3c94bc
 
9e79c75
e3c94bc
 
 
 
 
 
1893477
 
9e79c75
 
 
 
 
 
 
e3c94bc
9e79c75
 
 
 
 
e3c94bc
9e79c75
 
e3c94bc
9e79c75
e3c94bc
 
 
 
f7f76eb
 
e3c94bc
f7f76eb
9e79c75
f7f76eb
 
9e79c75
f7f76eb
e3c94bc
9e79c75
 
 
 
e3c94bc
 
9e79c75
 
e3c94bc
9e79c75
 
e3c94bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9e79c75
 
 
 
 
 
 
 
 
 
 
 
 
 
1893477
e3c94bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1893477
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>BlockCraft Studio | Editor</title>
    <link rel="icon" type="image/x-icon" href="/static/favicon.ico">
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
    <script src="https://unpkg.com/feather-icons"></script>
    <script src="https://cdn.jsdelivr.net/npm/three@0.132.2/build/three.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/three@0.132.2/examples/js/controls/OrbitControls.js"></script>
    <style>
        .editor-window {
            background-color: rgba(30, 41, 59, 0.8);
            backdrop-filter: blur(10px);
        }
        .tab-active {
            border-bottom: 2px solid #60a5fa;
            color: #60a5fa;
        }
        .model-preview {
            background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
        }
        #viewport {
            width: 100%;
            height: 100%;
        }
        .property-panel {
            scrollbar-width: thin;
            scrollbar-color: #334155 #1e293b;
        }
        .property-panel::-webkit-scrollbar {
            width: 8px;
        }
        .property-panel::-webkit-scrollbar-track {
            background: #1e293b;
        }
        .property-panel::-webkit-scrollbar-thumb {
            background-color: #334155;
            border-radius: 6px;
        }
    </style>
</head>
<body class="bg-slate-900 text-gray-100 min-h-screen overflow-hidden flex flex-col">
    <!-- Top Toolbar -->
    <div class="bg-slate-800 border-b border-slate-700 p-2 flex items-center justify-between">
        <!-- AI Command Input -->
        <div class="relative flex-1 max-w-2xl mx-4">
            <input type="text" id="aiCommand" placeholder="Tell the AI what to build (e.g. 'Create a redstone-powered robot with glowing eyes')" 
                   class="w-full bg-slate-700 border border-slate-600 rounded-full px-4 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
            <button id="aiGenerateBtn" class="absolute right-2 top-1/2 transform -translate-y-1/2 bg-blue-500 hover:bg-blue-600 text-white p-1 rounded-full">
                <i data-feather="sparkles" class="w-4 h-4"></i>
            </button>
        </div>
<div class="flex items-center space-x-4">
            <button class="text-gray-300 hover:text-white hover:bg-slate-700 p-2 rounded">
                <i data-feather="menu"></i>
            </button>
            <div class="flex items-center">
                <i data-feather="box" class="text-blue-400 mr-2"></i>
                <span class="font-medium">Zombie King</span>
            </div>
        </div>
        <div class="flex items-center space-x-2 ml-4">
<button class="text-gray-300 hover:text-white hover:bg-slate-700 p-2 rounded">
                <i data-feather="save"></i>
            </button>
            <button class="text-gray-300 hover:text-white hover:bg-slate-700 p-2 rounded">
                <i data-feather="share-2"></i>
            </button>
            <div class="h-6 border-l border-slate-600"></div>
            <button class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-1 rounded text-sm flex items-center">
                <i data-feather="download" class="mr-1 w-4 h-4"></i>
                Export
            </button>
        </div>
    </div>
    
    <!-- Main Editor Area -->
    <div class="flex flex-1 overflow-hidden">
        <!-- Left Sidebar - Tools -->
        <div class="w-16 bg-slate-800 border-r border-slate-700 flex flex-col items-center py-4 space-y-4">
                <button class="tool-btn bg-blue-500 text-white p-2 rounded-lg" data-tool="select" data-tooltip="Select">
                    <i data-feather="mouse-pointer"></i>
                </button>
                <button class="tool-btn text-gray-300 hover:text-white hover:bg-slate-700 p-2 rounded-lg" data-tool="create" data-primitive="cube" data-tooltip="Cube">
                    <i data-feather="box"></i>
                </button>
                <button class="tool-btn text-gray-300 hover:text-white hover:bg-slate-700 p-2 rounded-lg" data-tool="create" data-primitive="sphere" data-tooltip="Sphere">
                    <i data-feather="circle"></i>
                </button>
                <button class="tool-btn text-gray-300 hover:text-white hover:bg-slate-700 p-2 rounded-lg" data-tool="create" data-primitive="cylinder" data-tooltip="Cylinder">
                    <i data-feather="circle"></i>
                </button>
                <button class="tool-btn text-gray-300 hover:text-white hover:bg-slate-700 p-2 rounded-lg" data-tool="create" data-primitive="cone" data-tooltip="Cone">
                    <i data-feather="triangle"></i>
                </button>
                <button class="tool-btn text-gray-300 hover:text-white hover:bg-slate-700 p-2 rounded-lg" data-tool="create" data-primitive="torus" data-tooltip="Torus">
                    <i data-feather="circle"></i>
                </button>
<div class="h-px w-8 bg-slate-700 my-2"></div>
            <button class="text-gray-300 hover:text-white hover:bg-slate-700 p-2 rounded-lg tooltip" data-tooltip="Paint">
                <i data-feather="droplet"></i>
            </button>
            <button class="text-gray-300 hover:text-white hover:bg-slate-700 p-2 rounded-lg tooltip" data-tooltip="UV Editor">
                <i data-feather="image"></i>
            </button>
            <div class="h-px w-8 bg-slate-700 my-2"></div>
            <button class="text-gray-300 hover:text-white hover:bg-slate-700 p-2 rounded-lg tooltip" data-tooltip="Animate">
                <i data-feather="repeat"></i>
            </button>
            <button class="text-gray-300 hover:text-white hover:bg-slate-700 p-2 rounded-lg tooltip" data-tooltip="Sounds">
                <i data-feather="volume-2"></i>
            </button>
        </div>
        
        <!-- Center Viewport -->
        <div class="flex-1 relative">
            <div id="viewport" class="absolute inset-0">
                <!-- 3D viewport will be rendered here -->
                <div class="w-full h-full flex items-center justify-center">
                    <div class="text-center">
                        <i data-feather="box" class="w-16 h-16 mx-auto text-slate-500"></i>
                        <p class="text-slate-400 mt-2">3D Viewport</p>
                    </div>
                </div>
            </div>
            
            <!-- Viewport Controls -->
            <div class="absolute bottom-4 right-4 flex space-x-2">
                <button class="bg-slate-800 hover:bg-slate-700 text-gray-300 p-2 rounded-full">
                    <i data-feather="maximize"></i>
                </button>
                <button class="bg-slate-800 hover:bg-slate-700 text-gray-300 p-2 rounded-full">
                    <i data-feather="rotate-ccw"></i>
                </button>
                <button class="bg-slate-800 hover:bg-slate-700 text-gray-300 p-2 rounded-full">
                    <i data-feather="grid"></i>
                </button>
            </div>
        </div>
        
        <!-- Right Sidebar - Properties -->
        <div class="w-64 bg-slate-800 border-l border-slate-700 flex flex-col overflow-hidden">
            <div class="p-4 border-b border-slate-700">
                <h3 class="font-medium text-white">Properties</h3>
            </div>
            
            <div class="flex-1 overflow-y-auto property-panel p-4 space-y-6">
                <!-- Transform Section -->
                <div>
                    <div class="flex items-center justify-between mb-2">
                        <span class="text-sm font-medium text-gray-300">Transform</span>
                        <button class="text-gray-400 hover:text-white">
                            <i data-feather="more-horizontal" class="w-4 h-4"></i>
                        </button>
                    </div>
                    
                    <div class="space-y-2">
                        <div class="grid grid-cols-3 gap-2">
                            <div>
                                <label class="block text-xs text-gray-400 mb-1">X</label>
                                <input type="number" name="posX" value="0" class="transform-input w-full bg-slate-700 border border-slate-600 rounded px-2 py-1 text-sm">
                            </div>
                            <div>
                                <label class="block text-xs text-gray-400 mb-1">Y</label>
                                <input type="number" name="posY" value="0" class="transform-input w-full bg-slate-700 border border-slate-600 rounded px-2 py-1 text-sm">
                            </div>
                            <div>
                                <label class="block text-xs text-gray-400 mb-1">Z</label>
                                <input type="number" name="posZ" value="0" class="transform-input w-full bg-slate-700 border border-slate-600 rounded px-2 py-1 text-sm">
                            </div>
                        </div>
                        
                        <div class="grid grid-cols-3 gap-2">
                            <div>
                                <label class="block text-xs text-gray-400 mb-1">Rot X</label>
                                <input type="number" name="rotX" value="0" class="transform-input w-full bg-slate-700 border border-slate-600 rounded px-2 py-1 text-sm">
                            </div>
                            <div>
                                <label class="block text-xs text-gray-400 mb-1">Rot Y</label>
                                <input type="number" name="rotY" value="0" class="transform-input w-full bg-slate-700 border border-slate-600 rounded px-2 py-1 text-sm">
                            </div>
                            <div>
                                <label class="block text-xs text-gray-400 mb-1">Rot Z</label>
                                <input type="number" name="rotZ" value="0" class="transform-input w-full bg-slate-700 border border-slate-600 rounded px-2 py-1 text-sm">
                            </div>
                        </div>

                        <div class="grid grid-cols-3 gap-2">
                            <div>
                                <label class="block text-xs text-gray-400 mb-1">Scale X</label>
                                <input type="number" name="scaX" value="1" step="0.1" class="transform-input w-full bg-slate-700 border border-slate-600 rounded px-2 py-1 text-sm">
                            </div>
                            <div>
                                <label class="block text-xs text-gray-400 mb-1">Scale Y</label>
                                <input type="number" name="scaY" value="1" step="0.1" class="transform-input w-full bg-slate-700 border border-slate-600 rounded px-2 py-1 text-sm">
                            </div>
                            <div>
                                <label class="block text-xs text-gray-400 mb-1">Scale Z</label>
                                <input type="number" name="scaZ" value="1" step="0.1" class="transform-input w-full bg-slate-700 border border-slate-600 rounded px-2 py-1 text-sm">
                            </div>
                        </div>
</div>
                </div>
                
                <!-- Minecraft Properties -->
                <div>
                    <div class="flex items-center justify-between mb-2">
                        <span class="text-sm font-medium text-gray-300">Minecraft Settings</span>
                    </div>
                    
                    <div class="space-y-2">
                        <div>
                            <label class="block text-xs text-gray-400 mb-1">Edition</label>
                            <select class="w-full bg-slate-700 border border-slate-600 rounded px-2 py-1 text-sm">
                                <option>Java Edition</option>
                                <option>Bedrock Edition</option>
                            </select>
                        </div>
                        
                        <div>
                            <label class="block text-xs text-gray-400 mb-1">Texture Size</label>
                            <select class="w-full bg-slate-700 border border-slate-600 rounded px-2 py-1 text-sm">
                                <option>16x16 (Default)</option>
                                <option>32x32</option>
                                <option>64x64</option>
                                <option>128x128</option>
                            </select>
                        </div>
                        
                        <div>
                            <label class="block text-xs text-gray-400 mb-1">Hitbox</label>
                            <div class="grid grid-cols-3 gap-2">
                                <div>
                                    <label class="block text-xs text-gray-400 mb-1">W</label>
                                    <input type="number" value="1" class="w-full bg-slate-700 border border-slate-600 rounded px-2 py-1 text-sm">
                                </div>
                                <div>
                                    <label class="block text-xs text-gray-400 mb-1">H</label>
                                    <input type="number" value="1" class="w-full bg-slate-700 border border-slate-600 rounded px-2 py-1 text-sm">
                                </div>
                                <div>
                                    <label class="block text-xs text-gray-400 mb-1">D</label>
                                    <input type="number" value="1" class="w-full bg-slate-700 border border-slate-600 rounded px-2 py-1 text-sm">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- Animation Controller -->
                <div>
                    <div class="flex items-center justify-between mb-2">
                        <span class="text-sm font-medium text-gray-300">Animations</span>
                        <button class="text-blue-400 hover:text-blue-300 text-xs flex items-center">
                            <i data-feather="plus" class="w-3 h-3 mr-1"></i>
                            Add
                        </button>
                    </div>
                    
                    <div class="space-y-2">
                        <div class="bg-slate-700 rounded p-2 flex items-center justify-between">
                            <div>
                                <span class="text-xs font-medium text-white">walk</span>
                                <div class="text-xs text-gray-400">7 keyframes</div>
                            </div>
                            <button class="text-gray-400 hover:text-white">
                                <i data-feather="edit-2" class="w-4 h-4"></i>
                            </button>
                        </div>
                        
                        <div class="bg-slate-700 rounded p-2 flex items-center justify-between">
                            <div>
                                <span class="text-xs font-medium text-white">attack</span>
                                <div class="text-xs text-gray-400">12 keyframes</div>
                            </div>
                            <button class="text-gray-400 hover:text-white">
                                <i data-feather="edit-2" class="w-4 h-4"></i>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- Bottom Timeline -->
    <div class="h-24 bg-slate-800 border-t border-slate-700 p-2">
        <div class="flex items-center justify-between mb-2">
            <div class="flex items-center space-x-2">
                <button class="text-gray-300 hover:text-white hover:bg-slate-700 p-1 rounded">
                    <i data-feather="play" class="w-4 h-4"></i>
                </button>
                <span class="text-xs text-gray-400">00:00 / 05:00</span>
            </div>
            
            <div class="flex items-center space-x-2">
                <span class="text-xs text-gray-400">Frame: 0</span>
                <button class="text-gray-300 hover:text-white hover:bg-slate-700 p-1 rounded text-xs">
                    <i data-feather="plus" class="w-3 h-3 mr-1"></i>
                    Keyframe
                </button>
            </div>
        </div>
        
        <div class="bg-slate-700 rounded h-12 relative">
            <!-- Timeline visualization would go here -->
            <div class="absolute inset-0 flex items-center justify-center text-gray-500 text-xs">
                Timeline - Drag to scrub
            </div>
        </div>
    </div>
    <script>
        // Initialize Feather Icons
        feather.replace();

        // AI Generation Handler
        document.getElementById('aiGenerateBtn').addEventListener('click', async function() {
            const command = document.getElementById('aiCommand').value.trim();
            if (!command) return;
            
            // Show loading state
            this.innerHTML = '<i data-feather="loader" class="w-4 h-4 animate-spin"></i>';
            feather.replace();
            
            try {
                // In a real implementation, this would call your NLP/AI backend
                const response = await mockAIRequest(command);
                
                // Process the AI response and update the 3D scene
                updateSceneWithAIResponse(response);
                
                // Show success feedback
                this.innerHTML = '<i data-feather="check" class="w-4 h-4 text-green-400"></i>';
                setTimeout(() => {
                    this.innerHTML = '<i data-feather="sparkles" class="w-4 h-4"></i>';
                    feather.replace();
                }, 2000);
            } catch (error) {
                this.innerHTML = '<i data-feather="x" class="w-4 h-4 text-red-400"></i>';
                setTimeout(() => {
                    this.innerHTML = '<i data-feather="sparkles" class="w-4 h-4"></i>';
                    feather.replace();
                }, 2000);
                console.error('AI generation failed:', error);
            }
        });
        // Enhanced AI request function with full mod generation
        async function mockAIRequest(prompt) {
            // Simulate API delay
            await new Promise(resolve => setTimeout(resolve, 2500));
            
            // Generate base response
            let response = {
                type: 'full_mod',
                name: prompt.substring(0, 20).trim() || 'Custom Mod',
                description: `A Minecraft mod that ${prompt.toLowerCase()}`,
                components: [],
                assets: {
                    models: [],
                    textures: [],
                    sounds: [],
                    animations: []
                },
                behaviors: [],
                resources: []
            };
            
            // Detect common mod types
            const lowerPrompt = prompt.toLowerCase();
            
            // Entity creation
            if (lowerPrompt.includes('robot') || lowerPrompt.includes('creature') || 
                lowerPrompt.includes('monster') || lowerPrompt.includes('mob')) {
                const entityType = lowerPrompt.includes('robot') ? 'robot' : 
                                 lowerPrompt.includes('monster') ? 'monster' : 'creature';
                
                response.type = 'entity';
                response.assets.models.push({
                    type: 'entity_model',
                    name: `${entityType}_model`,
                    geometry: 'humanoid',
                    textures: {
                        body: 'metallic',
                        eyes: 'glowing'
                    }
                });
                
                response.assets.animations.push(
                    { name: 'walk', keyframes: 12 },
                    { name: 'idle', keyframes: 8 },
                    { name: 'attack', keyframes: 16 }
                );
                
                response.assets.sounds.push(
                    { name: 'ambient', source: 'robot_beep.mp3' },
                    { name: 'hurt', source: 'metal_clank.mp3' }
                );
                
                response.behaviors.push({
                    type: 'entity_behavior',
                    movement: 'walk',
                    attack: lowerPrompt.includes('attack') ? 'melee' : 'none',
                    health: 20,
                    attributes: []
                });
            }
            // Block creation
            else if (lowerPrompt.includes('block') || lowerPrompt.includes('ore') || 
                     lowerPrompt.includes('machine')) {
                response.type = 'block';
                response.assets.models.push({
                    type: 'block_model',
                    name: 'custom_block',
                    geometry: 'cube',
                    textures: {
                        all: 'custom_block_texture.png'
                    }
                });
                
                response.behaviors.push({
                    type: 'block_behavior',
                    properties: {
                        hardness: lowerPrompt.includes('ore') ? 3 : 1.5,
                        light: lowerPrompt.includes('glow') ? 15 : 0,
                        requiresTool: lowerPrompt.includes('ore')
                    }
                });
            }
            // Item creation
            else if (lowerPrompt.includes('item') || lowerPrompt.includes('weapon') || 
                     lowerPrompt.includes('tool')) {
                response.type = 'item';
                response.assets.models.push({
                    type: 'item_model',
                    name: 'custom_item',
                    geometry: 'handheld'
                });
                
                response.behaviors.push({
                    type: 'item_behavior',
                    properties: {
                        durability: lowerPrompt.includes('tool') ? 250 : 1,
                        damage: lowerPrompt.includes('weapon') ? 5 : 0
                    }
                });
            }
            
            // Add default components
            response.components.push('model', 'texture', 'sound');
            
            // Add default resources
            response.resources.push(
                'lang/en_US.json',
                'textures/items',
                'textures/blocks',
                'sounds.json'
            );
            
            return response;
        }

        // Update scene with generated 3D model
        function updateSceneWithAIResponse(response) {
            // Clear existing model
            if (currentModel) {
                scene.remove(currentModel);
            }
            
            // Create new model based on response
            let geometry, material;
            
            if (response.type === 'entity') {
                geometry = new THREE.BoxGeometry(0.8, 1.8, 0.8);
                material = new THREE.MeshPhongMaterial({ 
                    color: 0x777777,
                    specular: 0x111111,
                    shininess: 30
                });
            } else if (response.type === 'block') {
                geometry = new THREE.BoxGeometry(1, 1, 1);
                material = new THREE.MeshPhongMaterial({ 
                    color: 0x55aaff,
                    specular: 0x111111,
                    shininess: 30
                });
            } else if (response.type === 'item') {
                geometry = new THREE.BoxGeometry(0.5, 0.5, 0.1);
                material = new THREE.MeshPhongMaterial({ 
                    color: 0xffaa00,
                    specular: 0x111111,
                    shininess: 50
                });
            } else {
                // Default cube
                geometry = new THREE.BoxGeometry(1, 1, 1);
                material = new THREE.MeshPhongMaterial({ 
                    color: 0x00aaff,
                    specular: 0x111111,
                    shininess: 30
                });
            }
            
            currentModel = new THREE.Mesh(geometry, material);
            scene.add(currentModel);
            
            // Auto-rotate the model
            const animateRotation = () => {
                if (currentModel) {
                    currentModel.rotation.y += 0.01;
                    requestAnimationFrame(animateRotation);
                }
            };
            animateRotation();
            
            // Update properties panel
            updatePropertiesPanel(response);
        }

        // Update properties panel with generated data
        function updatePropertiesPanel(response) {
            const propertiesDiv = document.querySelector('.property-panel');
            
            // Clear existing properties
            propertiesDiv.innerHTML = `
                <div class="p-4 border-b border-slate-700">
                    <h3 class="font-medium text-white">Properties</h3>
                </div>
                <div class="p-4">
                    <div class="flex items-center justify-between mb-2">
                        <span class="text-sm font-medium text-white">${response.name}</span>
                        <span class="text-xs px-2 py-1 rounded bg-blue-500/20 text-blue-400">${response.type}</span>
                    </div>
                    <p class="text-xs text-gray-400 mb-4">${response.description}</p>
                    
                    <div class="mb-4">
                        <span class="text-xs font-medium text-gray-300 block mb-2">Assets Generated</span>
                        <div class="grid grid-cols-2 gap-2 text-xs">
                            ${response.assets.models.map(m => `
                                <span class="bg-slate-700/50 rounded px-2 py-1 text-gray-300">${m.name}</span>
                            `).join('')}
                            ${response.assets.textures.map(t => `
                                <span class="bg-slate-700/50 rounded px-2 py-1 text-gray-300">${t}</span>
                            `).join('')}
                            ${response.assets.sounds.map(s => `
                                <span class="bg-slate-700/50 rounded px-2 py-1 text-gray-300">${s.name}</span>
                            `).join('')}
                            ${response.assets.animations.map(a => `
                                <span class="bg-slate-700/50 rounded px-2 py-1 text-gray-300">${a.name}</span>
                            `).join('')}
                        </div>
                    </div>
                    
                    <div>
                        <span class="text-xs font-medium text-gray-300 block mb-2">Behaviors</span>
                        <div class="space-y-2">
                            ${response.behaviors.map(b => `
                                <div class="bg-slate-700 rounded p-2">
                                    <div class="flex justify-between">
                                        <span class="text-xs font-medium text-white">${b.type}</span>
                                    </div>
                                    <div class="text-xs text-gray-400 mt-1">
                                        ${Object.entries(b.properties || {}).map(([k,v]) => `${k}: ${v}`).join(', ')}
                                    </div>
                                </div>
                            `).join('')}
                        </div>
                    </div>
                    
                    <div class="mt-6">
                        <button class="w-full bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded-md text-sm font-medium flex items-center justify-center">
                            <i data-feather="download" class="mr-2 w-4 h-4"></i>
                            Export Complete Package
                        </button>
                    </div>
                </div>
            `;
            
            feather.replace();
        }
// Tooltip functionality
        document.querySelectorAll('.tooltip').forEach(el => {
            const tooltip = document.createElement('div');
            tooltip.className = 'absolute hidden bg-slate-700 text-white text-xs px-2 py-1 rounded mt-2 whitespace-nowrap';
            tooltip.textContent = el.getAttribute('data-tooltip');
            
            el.appendChild(tooltip);
            el.style.position = 'relative';
            
            el.addEventListener('mouseenter', () => {
                tooltip.classList.remove('hidden');
            });
            
            el.addEventListener('mouseleave', () => {
                tooltip.classList.add('hidden');
            });
        });
        // Initialize 3D Scene with Three.js and modeling tools
        let scene, camera, renderer, controls;
        let currentModel = null;
        let selectedTool = 'select';
        let selectedPrimitive = 'cube';
        let models = [];
        let selectedModel = null;
        let gridHelper, axesHelper;
        function initViewport() {
            const viewport = document.getElementById('viewport');
            
            // Clear any existing content
            viewport.innerHTML = '';
            
            // Setup Three.js scene
            scene = new THREE.Scene();
            scene.background = new THREE.Color(0x0f172a);
            
            // Lighting
            const ambientLight = new THREE.AmbientLight(0x404040);
            scene.add(ambientLight);
            
            const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
            directionalLight.position.set(1, 1, 1).normalize();
            directionalLight.castShadow = true;
            scene.add(directionalLight);
            
            // Camera
            camera = new THREE.PerspectiveCamera(75, viewport.clientWidth / viewport.clientHeight, 0.1, 1000);
            camera.position.set(5, 5, 5);
            camera.lookAt(0, 0, 0);
            
            // Renderer
            renderer = new THREE.WebGLRenderer({ 
                antialias: true,
                alpha: true
            });
            renderer.setSize(viewport.clientWidth, viewport.clientHeight);
            renderer.shadowMap.enabled = true;
            renderer.shadowMap.type = THREE.PCFSoftShadowMap;
            viewport.appendChild(renderer.domElement);

            // Controls
            controls = new THREE.OrbitControls(camera, renderer.domElement);
            controls.enableDamping = true;
            controls.dampingFactor = 0.25;
            
            // Helpers
            gridHelper = new THREE.GridHelper(20, 20, 0x334155, 0x1e293b);
            scene.add(gridHelper);
            
            axesHelper = new THREE.AxesHelper(5);
            scene.add(axesHelper);
            
            // Set up raycasting for selection
            const raycaster = new THREE.Raycaster();
            const mouse = new THREE.Vector2();
            
            function onMouseClick(event) {
                if (selectedTool !== 'select') return;
                
                // Calculate mouse position in normalized device coordinates
                mouse.x = (event.clientX / renderer.domElement.clientWidth) * 2 - 1;
                mouse.y = - (event.clientY / renderer.domElement.clientHeight) * 2 + 1;
                
                // Update the raycaster
                raycaster.setFromCamera(mouse, camera);
                
                // Calculate objects intersecting the ray
                const intersects = raycaster.intersectObjects(models);
                
                if (intersects.length > 0) {
                    selectedModel = intersects[0].object;
                    updatePropertiesPanel();
                } else {
                    selectedModel = null;
                }
            }
            
            renderer.domElement.addEventListener('click', onMouseClick, false);
            // Tool functions
            function createPrimitive(type) {
                let geometry;
                switch(type) {
                    case 'cube':
                        geometry = new THREE.BoxGeometry(1, 1, 1);
                        break;
                    case 'sphere':
                        geometry = new THREE.SphereGeometry(0.5, 32, 32);
                        break;
                    case 'cylinder':
                        geometry = new THREE.CylinderGeometry(0.5, 0.5, 1, 32);
                        break;
                    case 'cone':
                        geometry = new THREE.ConeGeometry(0.5, 1, 32);
                        break;
                    case 'torus':
                        geometry = new THREE.TorusGeometry(0.5, 0.2, 16, 32);
                        break;
                    default:
                        geometry = new THREE.BoxGeometry(1, 1, 1);
                }
                
                const material = new THREE.MeshStandardMaterial({ 
                    color: 0x3b82f6,
                    metalness: 0.1,
                    roughness: 0.5,
                    side: THREE.DoubleSide
                });
                
                const mesh = new THREE.Mesh(geometry, material);
                mesh.castShadow = true;
                mesh.receiveShadow = true;
                scene.add(mesh);
                models.push(mesh);
                selectedModel = mesh;
                updatePropertiesPanel();
            }
            
            function updatePropertiesPanel() {
                const panel = document.querySelector('.property-panel');
                if (!panel) return;
                
                if (selectedModel) {
                    // Update transform values
                    panel.querySelector('input[name="posX"]').value = selectedModel.position.x.toFixed(2);
                    panel.querySelector('input[name="posY"]').value = selectedModel.position.y.toFixed(2);
                    panel.querySelector('input[name="posZ"]').value = selectedModel.position.z.toFixed(2);
                    
                    panel.querySelector('input[name="rotX"]').value = THREE.MathUtils.radToDeg(selectedModel.rotation.x).toFixed(2);
                    panel.querySelector('input[name="rotY"]').value = THREE.MathUtils.radToDeg(selectedModel.rotation.y).toFixed(2);
                    panel.querySelector('input[name="rotZ"]').value = THREE.MathUtils.radToDeg(selectedModel.rotation.z).toFixed(2);
                    
                    panel.querySelector('input[name="scaleX"]').value = selectedModel.scale.x.toFixed(2);
                    panel.querySelector('input[name="scaleY"]').value = selectedModel.scale.y.toFixed(2);
                    panel.querySelector('input[name="scaleZ"]').value = selectedModel.scale.z.toFixed(2);
                }
            }
            
            // Handle tool selection
            document.querySelectorAll('.tool-btn').forEach(btn => {
                btn.addEventListener('click', function() {
                    selectedTool = this.dataset.tool;
                    document.querySelectorAll('.tool-btn').forEach(b => b.classList.remove('bg-blue-500', 'text-white'));
                    this.classList.add('bg-blue-500', 'text-white');
                    
                    if (this.dataset.primitive) {
                        selectedPrimitive = this.dataset.primitive;
                        createPrimitive(selectedPrimitive);
                    }
                });
            });
            
            // Handle transform updates from property panel
            document.querySelectorAll('.transform-input').forEach(input => {
                input.addEventListener('change', function() {
                    if (!selectedModel) return;
                    
                    const axis = this.name.slice(0, 3);
                    const type = this.name.slice(3);
                    const value = parseFloat(this.value);
                    
                    if (type === 'X' || type === 'Y' || type === 'Z') {
                        if (axis === 'pos') {
                            selectedModel.position[type.toLowerCase()] = value;
                        } else if (axis === 'rot') {
                            selectedModel.rotation[type.toLowerCase()] = THREE.MathUtils.degToRad(value);
                        } else if (axis === 'sca') {
                            selectedModel.scale[type.toLowerCase()] = value;
                        }
                    }
                });
            });
            
            // Render loop
            function animate() {
                requestAnimationFrame(animate);
                controls.update();
                renderer.render(scene, camera);
            }
            animate();
            
            // Handle window resize
            window.addEventListener('resize', () => {
                camera.aspect = viewport.clientWidth / viewport.clientHeight;
                camera.updateProjectionMatrix();
                renderer.setSize(viewport.clientWidth, viewport.clientHeight);
            });
        }
        // Initialize the editor and tooltips
        document.addEventListener('DOMContentLoaded', () => {
            initViewport();
            
            // Initialize tooltips
            document.querySelectorAll('[data-tooltip]').forEach(el => {
                const tooltip = document.createElement('div');
                tooltip.className = 'absolute hidden bg-slate-700 text-white text-xs px-2 py-1 rounded mt-2 whitespace-nowrap z-50';
                tooltip.textContent = el.dataset.tooltip;
                el.appendChild(tooltip);
                el.style.position = 'relative';
                
                el.addEventListener('mouseenter', () => {
                    tooltip.classList.remove('hidden');
                });
                
                el.addEventListener('mouseleave', () => {
                    tooltip.classList.add('hidden');
                });
            });
        });
// Handle Enter key in command input
        document.getElementById('aiCommand').addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                document.getElementById('aiGenerateBtn').click();
            }
        });
    </script>
</body>
</html>