import streamlit as st
import streamlit.components.v1 as components
import random
import json
import os
# Initialize session state
if "entities" not in st.session_state:
st.session_state.entities = []
# Function to get random 3D model file
def get_random_3d_model():
model_dir = "models"
model_files = [f for f in os.listdir(model_dir) if f.endswith(('.glb', '.obj'))]
return os.path.join(model_dir, random.choice(model_files)) if model_files else None
# Function to add a new entity to the scene
def add_entity(entity_type):
model_path = get_random_3d_model()
if model_path:
new_entity = {
'type': entity_type,
'model': model_path,
'position': {
'x': random.uniform(-5, 5),
'y': 0,
'z': random.uniform(-5, 5)
},
'rotation': {
'x': 0,
'y': random.uniform(0, 360),
'z': 0
}
}
st.session_state.entities.append(new_entity)
# Function to generate A-Frame entities
def generate_aframe_entities():
entities_html = ""
for entity in st.session_state.entities:
entities_html += f'''