Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hubble example #14

Merged
merged 21 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e5c2306
Hubble Example
97morningstar Sep 1, 2020
cf4e50f
Fix bug on Video Capture. Drag functionality added
97morningstar Sep 2, 2020
814712d
Fix bug on Video Capture. Drag functionality added
97morningstar Sep 2, 2020
b3caef3
Changes: Keyframes function and drag functionality has been updated f…
97morningstar Sep 4, 2020
ec583b3
updateCamera is now optional
97morningstar Sep 8, 2020
bf22745
gltf-object-mapbox example deleted
97morningstar Sep 8, 2020
a4e200c
hubble-example name changed to update-viewState
97morningstar Sep 8, 2020
4b22ec5
hubble-example deleted
97morningstar Sep 8, 2020
d2c25ef
Renamed update-viewState to trips to ensure consistency
97morningstar Sep 8, 2020
fe96475
Added source to the deckgl building example | Clean any remaining ext…
97morningstar Sep 8, 2020
3b50d77
Deleted examples/trips/layers.js file
97morningstar Sep 8, 2020
f84055f
Added README
97morningstar Sep 9, 2020
fcedc17
Updated README
97morningstar Sep 9, 2020
2f5f0b6
Updated README
97morningstar Sep 9, 2020
bc67e62
Updated README
97morningstar Sep 9, 2020
f4b5303
Updated README: Added instructions on how to add functionality to a h…
97morningstar Sep 9, 2020
0a755f2
Updated README: Added instructions on how to add functionality to a h…
97morningstar Sep 9, 2020
6dbcd21
Updated README: Added instructions on how to add functionality to a h…
97morningstar Sep 9, 2020
8364204
Update README.md
97morningstar Sep 9, 2020
9a0f4d9
Update README.md
97morningstar Sep 9, 2020
5791649
Added an animated gif to demonstrate the usage
97morningstar Sep 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions examples/camera/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {layers} from './layers';
import {vignette, fxaa} from '@luma.gl/shadertools';
import {PostProcessEffect} from '@deck.gl/core';

import {CameraKeyframes} from '@hubble.gl/core';
import {easing} from 'popmotion';

const INITIAL_VIEW_STATE = {
longitude: -122.4,
latitude: 37.74,
Expand Down Expand Up @@ -38,8 +41,37 @@ export default function App() {
const deckgl = useRef(null);
const [ready, setReady] = useState(false);
const [busy, setBusy] = useState(false);

const [viewState, setViewState] = useState(INITIAL_VIEW_STATE); //Added to maintain user's interactions with viewState

const nextFrame = useNextFrame();

const updateCamera = (prevCamera) => {
// Set by User
prevCamera = new CameraKeyframes({
timings: [0, 5000],
keyframes: [
{
longitude: viewState.longitude,
latitude: viewState.latitude,
zoom: viewState.zoom,
pitch: viewState.pitch,
bearing: viewState.bearing
},
{
longitude: viewState.longitude,
latitude: viewState.latitude,
zoom: viewState.zoom,
bearing: viewState.bearing + 92,
pitch: viewState.pitch
}
],
easings: [easing.easeInOut]
});

return prevCamera;
}

return (
<div style={{position: 'relative'}}>
<div style={{position: 'absolute'}}>
Expand All @@ -51,10 +83,14 @@ export default function App() {
parameters={{
depthTest: false,
clearColor: [61 / 255, 20 / 255, 76 / 255, 1]
// blend: true,
// blendEquation: GL.FUNC_ADD,
// blendFunc: [GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA]
}}

viewState={viewState}
onViewStateChange={({viewState}) => {
97morningstar marked this conversation as resolved.
Show resolved Hide resolved
setViewState(viewState);
}}
controller={true}

effects={[vignetteEffect, aaEffect]}
layers={layers}
{...adapter.getProps(deckgl, setReady, nextFrame)}
Expand All @@ -66,6 +102,7 @@ export default function App() {
busy={busy}
setBusy={setBusy}
encoderSettings={encoderSettings}
updateCamera={updateCamera}
/>
)}
</div>
Expand Down
6 changes: 4 additions & 2 deletions examples/camera/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export async function sceneBuilder(animationLoop) {
easings: [easing.easeInOut]
})
};
animationLoop.timeline.attachAnimation(keyframes.camera);

const currentCamera = animationLoop.timeline.attachAnimation(keyframes.camera);

return new DeckScene({
animationLoop,
keyframes,
lengthMs: 5000,
width: 640,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if you're on this task yet but shouldn't this be modular? So that the user can set resolution themselves

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we've ever scoped or discussed setting resolution differently. At the moment it's designed to be set within scene definition since it's how I preferred to set up scenes.

We could change this to be optional if DeckAdapter is changed to only set it if it's defined. Happy to accept a PR for that.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I imagined those being values being set with state but I must have misremembered.

height: 480
height: 480,
currentCamera
});
}
41 changes: 40 additions & 1 deletion examples/terrain/app.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React, {useState, useRef} from 'react';
import DeckGL from '@deck.gl/react';
// eslint-disable-next-line import/no-extraneous-dependencies
import {DeckAdapter} from 'hubble.gl';
import {useNextFrame, BasicControls, ResolutionGuide} from '@hubble.gl/react';
import {sceneBuilder} from './scene';

import {CameraKeyframes} from '@hubble.gl/core';
import {easing} from 'popmotion';


const INITIAL_VIEW_STATE = {
latitude: 46.24,
longitude: -122.18,
Expand Down Expand Up @@ -33,8 +36,36 @@ export default function App() {
const deckgl = useRef(null);
const [ready, setReady] = useState(false);
const [busy, setBusy] = useState(false);
const [viewState, setViewState] = useState(INITIAL_VIEW_STATE);

const nextFrame = useNextFrame();

const updateCamera = (prevCamera) => {
// Set by User
prevCamera = new CameraKeyframes({
timings: [0, 5000],
keyframes: [
{
longitude: viewState.longitude,
latitude: viewState.latitude,
zoom: viewState.zoom,
pitch: viewState.pitch,
bearing: viewState.bearing
},
{
longitude: viewState.longitude,
latitude: viewState.latitude,
zoom: viewState.zoom,
bearing: viewState.bearing + 92,
pitch: viewState.pitch
}
],
easings: [easing.easeInOut]
});

return prevCamera;
}

return (
<div style={{position: 'relative'}}>
<div style={{position: 'absolute'}}>
Expand All @@ -43,6 +74,13 @@ export default function App() {
<DeckGL
ref={deckgl}
initialViewState={INITIAL_VIEW_STATE}

viewState={viewState}
onViewStateChange={({viewState}) => {
setViewState(viewState);
}}
controller={true}

{...adapter.getProps(deckgl, setReady, nextFrame)}
/>
<div style={{position: 'absolute'}}>
Expand All @@ -52,6 +90,7 @@ export default function App() {
busy={busy}
setBusy={setBusy}
encoderSettings={encoderSettings}
updateCamera={updateCamera}
/>
)}
</div>
Expand Down
1 change: 0 additions & 1 deletion examples/terrain/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ function getKeyframes(animationLoop, data) {
export const sceneBuilder = animationLoop => {
const lengthMs = 15000;
const data = {};
// set up keyframes
const keyframes = getKeyframes(animationLoop, data);
return new DeckScene({
animationLoop,
Expand Down
123 changes: 123 additions & 0 deletions examples/trips/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
This is a minimal standalone version of the [TripsLayer example](https://deck.gl/examples/trips-layer/)
on [deck.gl](http://deck.gl) website.

### Purpose

Users can drag, zoom in and zoom out, change pitch and bearing from within the deckgl canvas. The camera will start at the last position (viewState) the user was at, improving the experience of exporting the camera movements.

![](https://user-images.githubusercontent.com/26909101/92542712-25c01d00-f20f-11ea-9aee-1bc2806685dc.gif)

### Usage

Copy the content of this folder to your project.

To see the base map, you need a [Mapbox access token](https://docs.mapbox.com/help/how-mapbox-works/access-tokens/). You can either set an environment variable:

```bash
export MapboxAccessToken=<mapbox_access_token>
```

Or set `MAPBOX_TOKEN` directly in `app.js`.

Other options can be found at [using with Mapbox GL](../../../docs/get-started/using-with-mapbox-gl.md).

### Installation

```bash
# install dependencies within hubble.gl root
npm install
# or
yarn
yarn bootstrap
# To install example go to the folder
cd examples/trips
# do this once per example
yarn
# To run the example
yarn start-local
```

### Data format
Sample data is stored in [deck.gl Example Data](https://github.com/visgl/deck.gl-data/tree/master/examples/trips). To use your own data, check out
the [documentation of TripsLayer](../../../docs/layers/trips-layer.md).

### How to add this feature to a hubble.gl example

1. Add to props of the `DeckGl `component


```
viewState={viewState}
onViewStateChange={({viewState}) => {
setViewState(viewState);
}}
controller={true}
```

1.1 Add the `viewState` state to App.js

```
const [viewState, setViewState] = useState(INITIAL_VIEW_STATE);
```

2. Add the prop method `updateCamera` to `BasicControls `component (optional)

```
updateCamera={updateCamera}
```

3. Add the optional method to start the camera from the current `viewState `(optional)

```
const updateCamera = (prevCamera) => {
// Set by User
prevCamera = new CameraKeyframes({
timings: [0, 5000],
keyframes: [
{
longitude: viewState.longitude,
latitude: viewState.latitude,
zoom: viewState.zoom,
pitch: viewState.pitch,
bearing: viewState.bearing
},
{
longitude: viewState.longitude,
latitude: viewState.latitude,
zoom: viewState.zoom,
bearing: viewState.bearing + 92,
pitch: viewState.pitch // up to 45/50
}
],
easings: [easing.easeInOut]
});

return prevCamera;
}
```
3.1. Imports

```
import {CameraKeyframes} from '@hubble.gl/core';
import {easing} from 'popmotion';
```

4. Fix this line when attaching the camera to the timeline

```
const currentCamera = animationLoop.timeline.attachAnimation(keyframes.camera);
```

4.1. Add as prop to `DeckScene`

```
return new DeckScene({
animationLoop,
keyframes,
lengthMs: 5000,
width: 1280,
height: 720,
currentCamera // Here
});
```

Loading