pydeck: Load a local .glb file in ScengraphLayer #6323
|
I was wondering whether it is possible to load a local .glb file in my Scenegraph Layer using pydeck. import pydeck as pdk
layer = pdk.Layer(
"ScenegraphLayer",
data=[{'coordinates': [-122.466233, 37.684638]}],
scenegraph=r'./BoxAnimated.glb',
get_position="coordinates",
)
view_state = pdk.ViewState(latitude=37.684638, longitude=-122.466233, zoom=18, bearing=0, pitch=0)
r = pdk.Deck(layer, initial_view_state=view_state, map_style="light")
r.show()Am I missing something? |
Replies: 5 comments 6 replies
|
You should be able to look at the JavaScript console for errors. I haven't tried to use pydeck with the ScenegraphLayer, but I'm guessing this doesn't work because Javascript isn't able to load files in your local directory from the browser. The example loads data from a remote URL: One easy way to get around this is to start a local server in the directory with your files. You can run |
|
Thank you @kylebarron Running a local server could be an option but for the moment it raises a CORS error. In addition my end goal is to include the I know that I could upload the file and read it from a remote URL but the size of the actual file I need to open (>100mb) makes that quite difficult |
I'm not familiar with that layer, but you should consult the new example @ajduberstein added last week in #6308 |
|
@harisbal just published a version of pydeck with the ScenegraphLayer changes, so you might want to upgrade ( npm install -g http-server
# In the directory of your .glb file
http-server -p 8000 --corsI can verify that this code works for me (from the import pandas as pd
from pydeck import Layer, Deck
from pydeck.data_utils import compute_view
from pydeck.types import String
DATA_URL = "https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/bart-stations.json"
# Referencing the local file server
SCENEGRAPH_URL = "http://localhost:8000/BoxAnimated.glb"
# Automatically fit viewport location based on data
df = pd.read_json(DATA_URL)
view = compute_view(df["coordinates"])
layer = Layer(
type="ScenegraphLayer",
id="scenegraph-layer",
data=DATA_URL,
pickable=True,
scenegraph=SCENEGRAPH_URL,
get_position="coordinates",
get_orientation=[0, 180, 90],
size_scale=500,
_animations={"*": {"speed": 5}},
_lighting=String("pbr"),
)
# Render
r = Deck(layer, initial_view_state=view)
r.to_html("scenegraph_layer.html")Give this a try and let us know if it works. |
|
Moving this thread to Discussion. Please only use templates to open issues. |
@harisbal just published a version of pydeck with the ScenegraphLayer changes, so you might want to upgrade (
pip install -U pydeckif you're using pip). The Python SimpleHTTPServer doesn't enable CORS by default. Tryhttp-serverfor this.npm install -g http-server # In the directory of your .glb file http-server -p 8000 --corsI can verify that this code works for me (from the
examples/directory in pydeck):