awacke1 commited on
Commit
09636a7
ยท
verified ยท
1 Parent(s): 8b7baa3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -93
app.py CHANGED
@@ -1,95 +1,4 @@
1
- import streamlit as st
2
- import os
3
- import base64
4
- from pathlib import Path
5
- import shutil
6
- import random
7
-
8
- # ๐ŸŒˆ Load A-Frame and custom components
9
- @st.cache_data
10
- def load_aframe_and_extras():
11
- return """
12
- <script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
13
- <script src="https://unpkg.com/aframe-event-set-component@5.0.0/dist/aframe-event-set-component.min.js"></script>
14
- <script>
15
- // ๐Ÿ•น๏ธ Make objects draggable
16
- AFRAME.registerComponent('draggable', {
17
- // ... (draggable component code remains the same)
18
- });
19
-
20
- // ๐Ÿฆ˜ Make objects bounce
21
- AFRAME.registerComponent('bouncing', {
22
- // ... (bouncing component code remains the same)
23
- });
24
-
25
- // ๐Ÿ’ก Create moving light sources
26
- AFRAME.registerComponent('moving-light', {
27
- // ... (moving-light component code remains the same)
28
- });
29
-
30
- // ๐Ÿ“ท Camera controls
31
- function moveCamera(direction) {
32
- var camera = document.querySelector('[camera]');
33
- var rig = document.querySelector('#rig');
34
- var pos = rig.getAttribute('position');
35
- var rot = rig.getAttribute('rotation');
36
- var speed = 0.5;
37
- var rotationSpeed = 5;
38
-
39
- switch(direction) {
40
- case 'up':
41
- pos.z -= speed;
42
- break;
43
- case 'down':
44
- pos.z += speed;
45
- break;
46
- case 'left':
47
- pos.x -= speed;
48
- break;
49
- case 'right':
50
- pos.x += speed;
51
- break;
52
- case 'rotateLeft':
53
- rot.y += rotationSpeed;
54
- break;
55
- case 'rotateRight':
56
- rot.y -= rotationSpeed;
57
- break;
58
- case 'reset':
59
- pos = {x: 0, y: 10, z: 0};
60
- rot = {x: -90, y: 0, z: 0};
61
- break;
62
- case 'ground':
63
- pos = {x: 0, y: 1.6, z: 0};
64
- rot = {x: 0, y: 0, z: 0};
65
- break;
66
- }
67
-
68
- rig.setAttribute('position', pos);
69
- rig.setAttribute('rotation', rot);
70
- }
71
-
72
- // โŒจ๏ธ Keyboard controls
73
- document.addEventListener('keydown', function(event) {
74
- switch(event.key.toLowerCase()) {
75
- case 'q':
76
- moveCamera('rotateLeft');
77
- break;
78
- case 'e':
79
- moveCamera('rotateRight');
80
- break;
81
- case 'z':
82
- moveCamera('reset');
83
- break;
84
- case 'c':
85
- moveCamera('ground');
86
- break;
87
- }
88
- });
89
- </script>
90
- """
91
-
92
- # ... (The rest of the functions remain the same)
93
 
94
  # ๐ŸŽญ Main function to run the Streamlit app
95
  def main():
@@ -133,7 +42,37 @@ def main():
133
  st.markdown("### ๐Ÿ“ Directory")
134
  directory = st.text_input("Enter path:", ".", key="directory_input")
135
 
136
- # ... (The rest of the main function remains the same)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
 
138
  camera_move = st.session_state.get('camera_move', None)
139
  if camera_move:
 
1
+ # ... (previous code remains the same)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  # ๐ŸŽญ Main function to run the Streamlit app
4
  def main():
 
42
  st.markdown("### ๐Ÿ“ Directory")
43
  directory = st.text_input("Enter path:", ".", key="directory_input")
44
 
45
+ if not os.path.isdir(directory):
46
+ st.sidebar.error("Invalid directory path")
47
+ return
48
+
49
+ file_types = ['obj', 'glb', 'webp', 'png', 'mp4']
50
+
51
+ if uploaded_files:
52
+ for uploaded_file in uploaded_files:
53
+ file_extension = Path(uploaded_file.name).suffix.lower()[1:]
54
+ if file_extension in file_types:
55
+ with open(os.path.join(directory, uploaded_file.name), "wb") as f:
56
+ shutil.copyfileobj(uploaded_file, f)
57
+ st.sidebar.success(f"Uploaded: {uploaded_file.name}")
58
+ else:
59
+ st.sidebar.warning(f"Skipped unsupported file: {uploaded_file.name}")
60
+
61
+ files = [f for f in os.listdir(directory) if f.split('.')[-1] in file_types]
62
+
63
+ aframe_scene = f"""
64
+ <a-scene embedded style="height: 600px; width: 100%;">
65
+ <a-entity id="rig" position="0 {max(grid_width, grid_height)} 0" rotation="-90 0 0">
66
+ <a-camera fov="60" look-controls wasd-controls cursor="rayOrigin: mouse" raycaster="objects: .raycastable"></a-camera>
67
+ </a-entity>
68
+ <a-sky color="#87CEEB"></a-sky>
69
+ <a-entity moving-light="color: #FFD700; speed: 0.07 0.05 0.06; bounds: 4 3 4" position="2 2 -2"></a-entity>
70
+ <a-entity moving-light="color: #FF6347; speed: 0.06 0.08 0.05; bounds: 4 3 4" position="-2 1 2"></a-entity>
71
+ <a-entity moving-light="color: #00CED1; speed: 0.05 0.06 0.07; bounds: 4 3 4" position="0 3 0"></a-entity>
72
+ """
73
+
74
+ assets, entities = generate_tilemap(files, directory, grid_width, grid_height, max_unique_models=5)
75
+ aframe_scene += assets + entities + "</a-scene>"
76
 
77
  camera_move = st.session_state.get('camera_move', None)
78
  if camera_move: