Skip to content

Commit ec62749

Browse files
authored
tweaks to 3D buildings story (#93)
* tweaks to 3D buildings story * update packages
1 parent 8263cf2 commit ec62749

9 files changed

Lines changed: 3791 additions & 2450 deletions

File tree

example-mapbox/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
"ts": "tsc -w"
88
},
99
"dependencies": {
10-
"@ladle/react": "^2.15.0",
10+
"@ladle/react": "^4.0.2",
1111
"@react-three/drei": "^9.77.10",
1212
"@react-three/fiber": "^8.13.4",
1313
"leva": "^0.9.35",
1414
"mapbox-gl": "^2.15.0",
1515
"react": "^18.2.0",
1616
"react-dom": "^18.2.0",
1717
"react-map-gl": "^7.1.0",
18-
"react-three-map": "^0.2.1",
18+
"react-three-map": "^0.8.1",
1919
"three": "~0.153.0",
2020
"three-stdlib": "^2.23.10"
2121
},

example-mapbox/yarn.lock

Lines changed: 1889 additions & 1219 deletions
Large diffs are not rendered by default.

example-maplibre/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
"ts": "tsc -w"
88
},
99
"dependencies": {
10-
"@ladle/react": "^2.15.0",
10+
"@ladle/react": "^4.0.2",
1111
"@react-three/drei": "^9.77.10",
1212
"@react-three/fiber": "^8.13.4",
1313
"leva": "^0.9.35",
1414
"maplibre-gl": "^3.1.0",
1515
"react": "^18.2.0",
1616
"react-dom": "^18.2.0",
1717
"react-map-gl": "^7.1.0",
18-
"react-three-map": "^0.2.1",
18+
"react-three-map": "^0.8.1",
1919
"three": "~0.153.0",
2020
"three-stdlib": "^2.23.10"
2121
},

example-maplibre/yarn.lock

Lines changed: 1887 additions & 1217 deletions
Large diffs are not rendered by default.

stories/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"react": "^18.2.0",
2121
"react-dom": "^18.2.0",
2222
"react-map-gl": "^7.1.7",
23-
"react-three-map": "^0.6.1",
23+
"react-three-map": "^0.8.1",
2424
"suncalc": "^1.9.0",
2525
"three": "^0.159.0",
2626
"three-stdlib": "^2.28.7",

stories/src/adaptive-dpr.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const AdaptiveDpr = memo(() => {
88
const setDpr = useThree(s => s.setDpr);
99
const map = useMap();
1010
useEffect(() => {
11+
if(!map) return;
1112
const decreaseDpr = () => _setDpr(0.5)
1213
const increaseDpr = () => _setDpr(initialDpr);
1314

stories/src/free-3d-buildings/batched-buildings.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const BatchedBuildings = memo<BatchedBuildingsProps>(({ buildingsCenter,
3535

3636
const [hovered, hover] = useState<number>()
3737

38-
const { data, vertexCount, indexCount } = useMemo(() => {
38+
const { data, vertexCount, indexCount, key } = useMemo(() => {
3939
// lights
4040
const c00 = _color.set('#f0c505').getHSL({ h: 0, s: 0, l: 0 });
4141
const c01 = _color.set('#f38630').getHSL({ h: 0, s: 0, l: 0 });
@@ -69,7 +69,8 @@ export const BatchedBuildings = memo<BatchedBuildingsProps>(({ buildingsCenter,
6969
});
7070
const vertexCount = data.reduce((acc, d) => acc + d.vertexCount, 0);
7171
const indexCount = data.reduce((acc, d) => acc + d.indexCount, 0);
72-
return { data, vertexCount, indexCount };
72+
const key = MathUtils.generateUUID();
73+
return { data, vertexCount, indexCount, key };
7374
}, [origin, buildings])
7475

7576
const meshRef = useRef<BatchedMesh>(null);
@@ -92,9 +93,7 @@ export const BatchedBuildings = memo<BatchedBuildingsProps>(({ buildingsCenter,
9293

9394
material.setValue(item.i, 'roughness', roughness);
9495
material.setValue(item.i, 'metalness', metalness);
95-
9696
}
97-
9897
})
9998

10099
useLayoutEffect(() => {
@@ -106,6 +105,7 @@ export const BatchedBuildings = memo<BatchedBuildingsProps>(({ buildingsCenter,
106105
}, [data]); // eslint-disable-line react-hooks/exhaustive-deps
107106

108107
return <batchedMesh
108+
key={key}
109109
ref={meshRef}
110110
args={[data.length, vertexCount, indexCount]}
111111
rotation={[-90 * MathUtils.DEG2RAD, 0, -90 * MathUtils.DEG2RAD]}

stories/src/story-map.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const StoryMap: FC<StoryMapProps> = (props) => {
4343
{mapProvider === MapProvider.mapbox && <StoryMapbox {...props} canvas={canvas} />}
4444
{mapProvider === MapProvider.nomap && <Canvas
4545
{...props.canvas}
46-
camera={{ position: [0, 500, 0] }}
46+
camera={{ position: [0, 500, 0], far: 5000 }}
4747
>
4848
<MapControls makeDefault />
4949
{props.children}

stories/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4199,10 +4199,10 @@ react-refresh@^0.14.0:
41994199
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.14.0.tgz#4e02825378a5f227079554d4284889354e5f553e"
42004200
integrity sha512-wViHqhAd8OHeLS/IRMJjTSDHF3U9eWi62F/MledQGPdJGDhodXJ9PBLNGr6WWL7qlH12Mt3TyTpbS+hGXMjCzQ==
42014201

4202-
react-three-map@^0.6.1:
4203-
version "0.6.1"
4204-
resolved "https://registry.yarnpkg.com/react-three-map/-/react-three-map-0.6.1.tgz#566811527242bb8964586c405a5816a84f75cb40"
4205-
integrity sha512-DSL7fyeR+MqiB1f6fG8FHwMb0NoDhj6Yjyc5T9jU6Yo/dpxQdY9Mfjs++J0j8HofcEDTsgiQz2GXh2r4iSPmhA==
4202+
react-three-map@^0.8.1:
4203+
version "0.8.1"
4204+
resolved "https://registry.yarnpkg.com/react-three-map/-/react-three-map-0.8.1.tgz#0312e9a2cb1a19f67127ad11526f1e4e1f091852"
4205+
integrity sha512-QkOJzaUPs7ZjtsP9sA8Xdy/FGhh0Q+eR89yUJPM6zlNEdzr1pe1F+prQlgd3jmffzE3Drfg90DMzqh3yJZcLJQ==
42064206

42074207
react-use-measure@^2.1.1:
42084208
version "2.1.1"

0 commit comments

Comments
 (0)