Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,14 +9,14 @@ if "entities" not in st.session_state:
|
|
9 |
st.session_state.entities = []
|
10 |
|
11 |
# Function to get random 3D model file
|
12 |
-
def get_random_3d_model(
|
13 |
-
model_dir =
|
14 |
model_files = [f for f in os.listdir(model_dir) if f.endswith(('.glb', '.obj'))]
|
15 |
return os.path.join(model_dir, random.choice(model_files)) if model_files else None
|
16 |
|
17 |
# Function to add a new entity to the scene
|
18 |
def add_entity(entity_type):
|
19 |
-
model_path = get_random_3d_model(
|
20 |
if model_path:
|
21 |
new_entity = {
|
22 |
'type': entity_type,
|
@@ -59,9 +59,8 @@ html_template = '''
|
|
59 |
<body>
|
60 |
<a-scene>
|
61 |
<a-assets>
|
62 |
-
<a-asset-item id="
|
63 |
-
<a-asset-item id="
|
64 |
-
<a-asset-item id="creature" src="{creature_model}"></a-asset-item>
|
65 |
</a-assets>
|
66 |
|
67 |
<a-sky color="#ECECEC"></a-sky>
|
@@ -82,14 +81,11 @@ def main():
|
|
82 |
# Sidebar
|
83 |
st.sidebar.title("Chofko's Ecosystem Controls")
|
84 |
|
85 |
-
if st.sidebar.button("
|
86 |
-
add_entity("
|
87 |
|
88 |
-
if st.sidebar.button("
|
89 |
-
add_entity("
|
90 |
-
|
91 |
-
if st.sidebar.button("🐾 Add Creature"):
|
92 |
-
add_entity("creature")
|
93 |
|
94 |
if st.sidebar.button("🗑️ Clear All Entities"):
|
95 |
st.session_state.entities = []
|
@@ -98,16 +94,14 @@ def main():
|
|
98 |
st.sidebar.json(st.session_state.entities)
|
99 |
|
100 |
# Main area - HTML5 canvas
|
101 |
-
|
102 |
-
|
103 |
-
creature_model = get_random_3d_model("creature") or ""
|
104 |
|
105 |
entities_html = generate_aframe_entities()
|
106 |
|
107 |
html_content = html_template.format(
|
108 |
-
|
109 |
-
|
110 |
-
creature_model=creature_model,
|
111 |
entities=entities_html
|
112 |
)
|
113 |
|
|
|
9 |
st.session_state.entities = []
|
10 |
|
11 |
# Function to get random 3D model file
|
12 |
+
def get_random_3d_model():
|
13 |
+
model_dir = "models"
|
14 |
model_files = [f for f in os.listdir(model_dir) if f.endswith(('.glb', '.obj'))]
|
15 |
return os.path.join(model_dir, random.choice(model_files)) if model_files else None
|
16 |
|
17 |
# Function to add a new entity to the scene
|
18 |
def add_entity(entity_type):
|
19 |
+
model_path = get_random_3d_model()
|
20 |
if model_path:
|
21 |
new_entity = {
|
22 |
'type': entity_type,
|
|
|
59 |
<body>
|
60 |
<a-scene>
|
61 |
<a-assets>
|
62 |
+
<a-asset-item id="skybike" src="{skybike_model}"></a-asset-item>
|
63 |
+
<a-asset-item id="heart" src="{heart_model}"></a-asset-item>
|
|
|
64 |
</a-assets>
|
65 |
|
66 |
<a-sky color="#ECECEC"></a-sky>
|
|
|
81 |
# Sidebar
|
82 |
st.sidebar.title("Chofko's Ecosystem Controls")
|
83 |
|
84 |
+
if st.sidebar.button("🚲 Add SkyBike"):
|
85 |
+
add_entity("skybike")
|
86 |
|
87 |
+
if st.sidebar.button("❤️ Add Heart"):
|
88 |
+
add_entity("heart")
|
|
|
|
|
|
|
89 |
|
90 |
if st.sidebar.button("🗑️ Clear All Entities"):
|
91 |
st.session_state.entities = []
|
|
|
94 |
st.sidebar.json(st.session_state.entities)
|
95 |
|
96 |
# Main area - HTML5 canvas
|
97 |
+
skybike_model = "models/SkyBike.glb"
|
98 |
+
heart_model = "models/Heart.obj"
|
|
|
99 |
|
100 |
entities_html = generate_aframe_entities()
|
101 |
|
102 |
html_content = html_template.format(
|
103 |
+
skybike_model=skybike_model,
|
104 |
+
heart_model=heart_model,
|
|
|
105 |
entities=entities_html
|
106 |
)
|
107 |
|