2d floor plan to 3d visualization that gives doll house view(top view)
To upload files, please first save the app
import streamlit as st
import numpy as np
import plotly.graph_objects as go
st.title("2D Floor Plan to 3D Visualization")
# Sample floor plan dimensions
st.sidebar.header("Floor Plan Settings")
length = st.sidebar.number_input("Room Length (meters)", min_value=1.0, max_value=20.0, value=10.0)
width = st.sidebar.number_input("Room Width (meters)", min_value=1.0, max_value=20.0, value=8.0)
height = st.sidebar.number_input("Room Height (meters)", min_value=1.0, max_value=5.0, value=3.0)
# Create walls data
def create_walls(length, width, height):
# Floor
floor_x = [0, length, length, 0, 0]
floor_y = [0, 0, width, width, 0]
floor_z = [0, 0, 0, 0, 0]
# Ceiling
ceiling_x = [0, length, length, 0, 0]
ceiling_y = [0, 0, width, width, 0]
ceiling_z = [height, height, height, height, height]
# Walls
wall1_x = [0, length, length, 0]
wall1_y = [0, 0, 0, 0]
wall1_z = [0, 0, height, height]
wall2_x = [length, length, length, length]
wall2_y = [0, width, width, 0]
wall2_z = [0, 0, height, height]
wall3_x = [length, 0, 0, length]
wall3_y = [width, width, width, width]
wall3_z = [0, 0, height, height]
wall4_x = [0, 0, 0, 0]
wall4_y = [width, 0, 0, width]
wall4_z = [0, 0, height, height]
return {
'floor': (floor_x, floor_y, floor_z),
'ceiling': (ceiling_x, ceiling_y, ceiling_z),
'wall1': (wall1_x, wall1_y, wall1_z),
'wall2': (wall2_x, wall2_y, wall2_z),
'wall3': (wall3_x, wall3_y, wall3_z),
'wall4': (wall4_x, wall4_y, wall4_z)
}
# Create 3D visualization
walls = create_walls(length, width, height)
fig = go.Figure()
# Add walls
wall_colors = ['lightgrey', 'lightgrey', 'lightgrey', 'lightgrey']
wall_names = ['wall1', 'wall2', 'wall3', 'wall4']
for name, color in zip(wall_names, wall_colors):
x, y, z = walls[name]
fig.add_trace(go.Mesh3d(
x=x, y=y, z=z,
i=[0, 0, 0],
j=[1, 2, 3],
k=[2, 3, 1],
color=color,
opacity=0.7,
name=name
))
# Add floor and ceiling
floor_ceiling_colors = ['lightblue', 'lightgreen']
floor_ceiling_names = ['floor', 'ceiling']
for name, color in zip(floor_ceiling_names, floor_ceiling_colors):
x, y, z = walls[name]
fig.add_trace(go.Mesh3d(
x=x, y=y, z=z,
i=[0, 0, 0],
j=[1, 2, 3],
k=[2, 3, 1],
color=color,
opacity=0.7,
name=name
))
# Update layout
fig.update_layout(
scene=dict(
aspectmode='data',
camera=dict(
up=dict(x=0, y=0, z=1),
center=dict(x=0, y=0, z=0),
eye=dict(x=1.5, y=1.5, z=2)
)
),
showlegend=True,
title="3D Floor Plan Visualization"
)
# Display the plot
st.plotly_chart(fig, use_container_width=True)
# Instructions
st.sidebar.markdown("""
## Instructions
1. Adjust the room dimensions using the sliders
2. The 3D visualization will update automatically
3. You can:
- Rotate the view by clicking and dragging
- Zoom with the scroll wheel
- Double-click to reset the view
""")
# Additional information
st.markdown("""
### Features
- Interactive 3D visualization
- Adjustable room dimensions
- Different colors for floor, ceiling, and walls
- Doll house view from top
- Fully rotatable and zoomable visualization
""")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?