2d floor plan to 3d floor plan visualization that gives dollhouse view
To upload files, please first save the app
import streamlit as st
import pydeck as pdk
import numpy as np
import pandas as pd
st.title("3D Floor Plan Visualization")
st.write("This demo shows how to create a 3D floor plan visualization with a dollhouse view")
# Sample floor plan data
# Creating walls as rectangles with height
def create_wall_data():
# Outer walls
walls = [
# North wall
{"start": [0, 0], "end": [10, 0], "height": 3},
# East wall
{"start": [10, 0], "end": [10, 8], "height": 3},
# South wall
{"start": [10, 8], "end": [0, 8], "height": 3},
# West wall
{"start": [0, 8], "end": [0, 0], "height": 3},
# Interior walls
{"start": [5, 0], "end": [5, 4], "height": 3},
{"start": [5, 4], "end": [10, 4], "height": 3},
]
wall_data = []
for wall in walls:
# Create a rectangle for each wall
x1, y1 = wall["start"]
x2, y2 = wall["end"]
height = wall["height"]
wall_data.append({
"path": [[x1, y1], [x2, y2]],
"height": height
})
return pd.DataFrame(wall_data)
# Create floor data
def create_floor_data():
return pd.DataFrame({
"polygon": [
[[0, 0], [10, 0], [10, 8], [0, 8]] # Main floor polygon
],
"height": [0.2] # Floor thickness
})
wall_data = create_wall_data()
floor_data = create_floor_data()
# Create the 3D visualization
view_state = pdk.ViewState(
latitude=0,
longitude=0,
zoom=18,
pitch=45,
bearing=0
)
# Define layers
layers = [
# Floor layer
pdk.Layer(
"PolygonLayer",
floor_data,
get_polygon="polygon",
get_elevation=0,
get_fill_color=[200, 200, 200],
get_line_color=[100, 100, 100],
pickable=True,
extruded=True,
get_extrusion="height",
wireframe=True
),
# Walls layer
pdk.Layer(
"PathLayer",
wall_data,
get_path="path",
get_width=50, # Wall thickness
get_height="height",
get_color=[160, 160, 180],
pickable=True,
extruded=True
)
]
# Create the deck
deck = pdk.Deck(
layers=layers,
initial_view_state=view_state,
map_style=None
)
# Add controls
st.sidebar.header("View Controls")
pitch = st.sidebar.slider("Pitch", 0, 90, 45)
bearing = st.sidebar.slider("Bearing", 0, 360, 0)
# Update view state based on controls
deck.initial_view_state.pitch = pitch
deck.initial_view_state.bearing = bearing
# Display the visualization
st.pydeck_chart(deck)
st.markdown("""
### How to use:
1. Use the sliders in the sidebar to adjust the view angle
2. The pitch control adjusts the vertical viewing angle
3. The bearing control rotates the view around the vertical axis
4. You can also use your mouse to:
- Pan: Left mouse button
- Rotate: Right mouse button
- Zoom: Mouse wheel
""")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?