react-babylon-map 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +78 -0
- package/demo.html +161 -0
- package/dist/cjs/main.js +520 -0
- package/dist/es/main.mjs +20 -0
- package/dist/es/main.mjs.map +1 -0
- package/dist/es/main10.mjs +33 -0
- package/dist/es/main10.mjs.map +1 -0
- package/dist/es/main11.mjs +12 -0
- package/dist/es/main11.mjs.map +1 -0
- package/dist/es/main12.mjs +14 -0
- package/dist/es/main12.mjs.map +1 -0
- package/dist/es/main13.mjs +12 -0
- package/dist/es/main13.mjs.map +1 -0
- package/dist/es/main14.mjs +5 -0
- package/dist/es/main14.mjs.map +1 -0
- package/dist/es/main15.mjs +12 -0
- package/dist/es/main15.mjs.map +1 -0
- package/dist/es/main16.mjs +25 -0
- package/dist/es/main16.mjs.map +1 -0
- package/dist/es/main17.mjs +54 -0
- package/dist/es/main17.mjs.map +1 -0
- package/dist/es/main18.mjs +88 -0
- package/dist/es/main18.mjs.map +1 -0
- package/dist/es/main19.mjs +18 -0
- package/dist/es/main19.mjs.map +1 -0
- package/dist/es/main2.mjs +9 -0
- package/dist/es/main2.mjs.map +1 -0
- package/dist/es/main20.mjs +21 -0
- package/dist/es/main20.mjs.map +1 -0
- package/dist/es/main21.mjs +61 -0
- package/dist/es/main21.mjs.map +1 -0
- package/dist/es/main3.mjs +46 -0
- package/dist/es/main3.mjs.map +1 -0
- package/dist/es/main4.mjs +23 -0
- package/dist/es/main4.mjs.map +1 -0
- package/dist/es/main5.mjs +69 -0
- package/dist/es/main5.mjs.map +1 -0
- package/dist/es/main6.mjs +35 -0
- package/dist/es/main6.mjs.map +1 -0
- package/dist/es/main7.mjs +65 -0
- package/dist/es/main7.mjs.map +1 -0
- package/dist/es/main8.mjs +14 -0
- package/dist/es/main8.mjs.map +1 -0
- package/dist/es/main9.mjs +26 -0
- package/dist/es/main9.mjs.map +1 -0
- package/dist/maplibre/cjs/main.js +520 -0
- package/dist/maplibre/es/main.mjs +20 -0
- package/dist/maplibre/es/main.mjs.map +1 -0
- package/dist/maplibre/es/main10.mjs +33 -0
- package/dist/maplibre/es/main10.mjs.map +1 -0
- package/dist/maplibre/es/main11.mjs +12 -0
- package/dist/maplibre/es/main11.mjs.map +1 -0
- package/dist/maplibre/es/main12.mjs +14 -0
- package/dist/maplibre/es/main12.mjs.map +1 -0
- package/dist/maplibre/es/main13.mjs +12 -0
- package/dist/maplibre/es/main13.mjs.map +1 -0
- package/dist/maplibre/es/main14.mjs +5 -0
- package/dist/maplibre/es/main14.mjs.map +1 -0
- package/dist/maplibre/es/main15.mjs +12 -0
- package/dist/maplibre/es/main15.mjs.map +1 -0
- package/dist/maplibre/es/main16.mjs +25 -0
- package/dist/maplibre/es/main16.mjs.map +1 -0
- package/dist/maplibre/es/main17.mjs +54 -0
- package/dist/maplibre/es/main17.mjs.map +1 -0
- package/dist/maplibre/es/main18.mjs +88 -0
- package/dist/maplibre/es/main18.mjs.map +1 -0
- package/dist/maplibre/es/main19.mjs +18 -0
- package/dist/maplibre/es/main19.mjs.map +1 -0
- package/dist/maplibre/es/main2.mjs +9 -0
- package/dist/maplibre/es/main2.mjs.map +1 -0
- package/dist/maplibre/es/main20.mjs +61 -0
- package/dist/maplibre/es/main20.mjs.map +1 -0
- package/dist/maplibre/es/main21.mjs +21 -0
- package/dist/maplibre/es/main21.mjs.map +1 -0
- package/dist/maplibre/es/main3.mjs +46 -0
- package/dist/maplibre/es/main3.mjs.map +1 -0
- package/dist/maplibre/es/main4.mjs +23 -0
- package/dist/maplibre/es/main4.mjs.map +1 -0
- package/dist/maplibre/es/main5.mjs +69 -0
- package/dist/maplibre/es/main5.mjs.map +1 -0
- package/dist/maplibre/es/main6.mjs +35 -0
- package/dist/maplibre/es/main6.mjs.map +1 -0
- package/dist/maplibre/es/main7.mjs +65 -0
- package/dist/maplibre/es/main7.mjs.map +1 -0
- package/dist/maplibre/es/main8.mjs +14 -0
- package/dist/maplibre/es/main8.mjs.map +1 -0
- package/dist/maplibre/es/main9.mjs +26 -0
- package/dist/maplibre/es/main9.mjs.map +1 -0
- package/dist/maplibre/types/api/canvas-props.d.ts +9 -0
- package/dist/maplibre/types/api/coordinates.d.ts +13 -0
- package/dist/maplibre/types/api/coords-to-vector-3.d.ts +3 -0
- package/dist/maplibre/types/api/coords.d.ts +5 -0
- package/dist/maplibre/types/api/index.d.ts +7 -0
- package/dist/maplibre/types/api/near-coordinates.d.ts +13 -0
- package/dist/maplibre/types/api/use-map.d.ts +3 -0
- package/dist/maplibre/types/api/vector-3-to-coords.d.ts +2 -0
- package/dist/maplibre/types/core/canvas-in-layer/use-canvas-in-layer.d.ts +15 -0
- package/dist/maplibre/types/core/canvas-in-layer/use-render.d.ts +15 -0
- package/dist/maplibre/types/core/canvas-in-layer/use-root.d.ts +11 -0
- package/dist/maplibre/types/core/canvas-overlay/canvas-portal.d.ts +10 -0
- package/dist/maplibre/types/core/canvas-overlay/init-canvas-fc.d.ts +11 -0
- package/dist/maplibre/types/core/canvas-overlay/render.d.ts +1 -0
- package/dist/maplibre/types/core/canvas-overlay/sync-camera-fc.d.ts +12 -0
- package/dist/maplibre/types/core/coords-to-matrix.d.ts +9 -0
- package/dist/maplibre/types/core/earth-radius.d.ts +1 -0
- package/dist/maplibre/types/core/generic-map.d.ts +49 -0
- package/dist/maplibre/types/core/matrix-utils.d.ts +7 -0
- package/dist/maplibre/types/core/sync-camera.d.ts +7 -0
- package/dist/maplibre/types/core/use-babylon-map.d.ts +32 -0
- package/dist/maplibre/types/core/use-coords-to-matrix.d.ts +6 -0
- package/dist/maplibre/types/core/use-coords.d.ts +5 -0
- package/dist/maplibre/types/core/use-function.d.ts +1 -0
- package/dist/maplibre/types/maplibre/canvas.d.ts +4 -0
- package/dist/maplibre/types/maplibre.index.d.ts +4 -0
- package/dist/types/api/canvas-props.d.ts +9 -0
- package/dist/types/api/coordinates.d.ts +13 -0
- package/dist/types/api/coords-to-vector-3.d.ts +3 -0
- package/dist/types/api/coords.d.ts +5 -0
- package/dist/types/api/index.d.ts +7 -0
- package/dist/types/api/near-coordinates.d.ts +13 -0
- package/dist/types/api/use-map.d.ts +3 -0
- package/dist/types/api/vector-3-to-coords.d.ts +2 -0
- package/dist/types/core/canvas-in-layer/use-canvas-in-layer.d.ts +15 -0
- package/dist/types/core/canvas-in-layer/use-render.d.ts +15 -0
- package/dist/types/core/canvas-in-layer/use-root.d.ts +11 -0
- package/dist/types/core/canvas-overlay/canvas-portal.d.ts +10 -0
- package/dist/types/core/canvas-overlay/init-canvas-fc.d.ts +11 -0
- package/dist/types/core/canvas-overlay/render.d.ts +1 -0
- package/dist/types/core/canvas-overlay/sync-camera-fc.d.ts +12 -0
- package/dist/types/core/coords-to-matrix.d.ts +9 -0
- package/dist/types/core/earth-radius.d.ts +1 -0
- package/dist/types/core/generic-map.d.ts +49 -0
- package/dist/types/core/matrix-utils.d.ts +7 -0
- package/dist/types/core/sync-camera.d.ts +7 -0
- package/dist/types/core/use-babylon-map.d.ts +32 -0
- package/dist/types/core/use-coords-to-matrix.d.ts +6 -0
- package/dist/types/core/use-coords.d.ts +5 -0
- package/dist/types/core/use-function.d.ts +1 -0
- package/dist/types/mapbox/canvas.d.ts +4 -0
- package/dist/types/mapbox.index.d.ts +4 -0
- package/package.json +58 -0
- package/plan.md +719 -0
- package/src/api/canvas-props.ts +10 -0
- package/src/api/coordinates.tsx +83 -0
- package/src/api/coords-to-vector-3.ts +39 -0
- package/src/api/coords.tsx +6 -0
- package/src/api/index.ts +7 -0
- package/src/api/near-coordinates.tsx +87 -0
- package/src/api/use-map.ts +8 -0
- package/src/api/vector-3-to-coords.ts +13 -0
- package/src/core/canvas-in-layer/use-canvas-in-layer.tsx +27 -0
- package/src/core/canvas-in-layer/use-render.ts +43 -0
- package/src/core/canvas-in-layer/use-root.tsx +82 -0
- package/src/core/canvas-overlay/canvas-portal.tsx +98 -0
- package/src/core/canvas-overlay/init-canvas-fc.tsx +45 -0
- package/src/core/canvas-overlay/render.tsx +1 -0
- package/src/core/canvas-overlay/sync-camera-fc.tsx +83 -0
- package/src/core/coords-to-matrix.ts +21 -0
- package/src/core/earth-radius.ts +1 -0
- package/src/core/events.ts +55 -0
- package/src/core/generic-map.ts +59 -0
- package/src/core/map-engine.tsx +70 -0
- package/src/core/matrix-utils.ts +22 -0
- package/src/core/sync-camera.ts +29 -0
- package/src/core/use-babylon-map.ts +46 -0
- package/src/core/use-coords-to-matrix.ts +13 -0
- package/src/core/use-coords.tsx +22 -0
- package/src/core/use-function.ts +10 -0
- package/src/mapbox/canvas.tsx +59 -0
- package/src/mapbox.index.ts +7 -0
- package/src/maplibre/canvas.tsx +59 -0
- package/src/maplibre.index.ts +7 -0
- package/src/vite-env.d.ts +1 -0
- package/stories/.ladle/components.tsx +50 -0
- package/stories/.ladle/style.css +63 -0
- package/stories/package.json +31 -0
- package/stories/pnpm-lock.yaml +5450 -0
- package/stories/sandbox.config.json +3 -0
- package/stories/src/adaptive-dpr.tsx +34 -0
- package/stories/src/billboard.stories.tsx +111 -0
- package/stories/src/buildings-3d.stories.tsx +280 -0
- package/stories/src/canvas/mapbox.stories.tsx +113 -0
- package/stories/src/canvas/maplibre.stories.tsx +93 -0
- package/stories/src/comparison.stories.tsx +161 -0
- package/stories/src/extrude/chaillot.ts +8 -0
- package/stories/src/exude-coordinates.stories.tsx +139 -0
- package/stories/src/free-3d-buildings/get-buildings-data.ts +49 -0
- package/stories/src/html-on-top.stories.tsx +156 -0
- package/stories/src/ifc/ifc-to-babylon.ts +97 -0
- package/stories/src/ifc/ifc.main.ts +904 -0
- package/stories/src/ifc/ifc2bb.ts +343 -0
- package/stories/src/ifc/model.ifc +14155 -0
- package/stories/src/ifc.stories.tsx +276 -0
- package/stories/src/mapbox/story-mapbox.tsx +97 -0
- package/stories/src/maplibre/story-maplibre.tsx +36 -0
- package/stories/src/multi-coordinates.stories.tsx +115 -0
- package/stories/src/pivot-controls.stories.tsx +148 -0
- package/stories/src/postprocessing.stories.tsx +125 -0
- package/stories/src/render-on-demand.stories.tsx +76 -0
- package/stories/src/story-map.tsx +44 -0
- package/stories/src/sunlight.stories.tsx +215 -0
- package/stories/src/vite-env.d.ts +1 -0
- package/stories/tsconfig.json +32 -0
- package/stories/tsconfig.node.json +10 -0
- package/stories/vite.config.ts +27 -0
- package/tsconfig.json +31 -0
- package/tsconfig.mapbox.json +7 -0
- package/tsconfig.maplibre.json +7 -0
- package/tsconfig.node.json +10 -0
- package/tsconfig.types.json +25 -0
- package/vite.config.ts +65 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(yarn install:*)",
|
|
5
|
+
"Bash(pnpm install:*)",
|
|
6
|
+
"Bash(npx tsc:*)",
|
|
7
|
+
"Bash(echo \"EXIT: $?\")",
|
|
8
|
+
"Bash(ls /home/ney/os/react-babylon-map/node_modules/.pnpm/@babylonjs+core*/node_modules/@babylonjs/core/package.json)",
|
|
9
|
+
"Bash(npx cross-env:*)",
|
|
10
|
+
"Bash(pnpm build:*)",
|
|
11
|
+
"Bash(cross-env LIB_MODE=1 MAP_MODE=0 vite build)",
|
|
12
|
+
"Bash(cross-env LIB_MODE=2 MAP_MODE=0 vite build)",
|
|
13
|
+
"Bash(cross-env LIB_MODE=1 MAP_MODE=1 vite build)",
|
|
14
|
+
"Bash(cross-env LIB_MODE=2 MAP_MODE=1 vite build)",
|
|
15
|
+
"Bash(npm install:*)",
|
|
16
|
+
"WebSearch",
|
|
17
|
+
"Bash(curl -s \"https://api.github.com/repos/simonedevit/reactylon\")",
|
|
18
|
+
"Bash(curl -s \"https://api.github.com/repos/simonedevit/reactylon/tree/main\")",
|
|
19
|
+
"Bash(curl -s \"https://api.github.com/repos/simonedevit/reactylon/contents\")",
|
|
20
|
+
"Bash(curl -s \"https://api.github.com/repos/simonedevit/reactylon/contents/packages\")",
|
|
21
|
+
"Bash(curl -s \"https://api.github.com/repos/simonedevit/reactylon/contents/packages/library\")",
|
|
22
|
+
"Bash(curl -s \"https://api.github.com/repos/simonedevit/reactylon/contents/packages/library/src\")",
|
|
23
|
+
"Bash(curl -s \"https://api.github.com/repos/simonedevit/reactylon/contents/packages/library/src/components\")",
|
|
24
|
+
"Bash(curl -s \"https://api.github.com/repos/simonedevit/reactylon/contents/packages/library/src/components/hosts\")",
|
|
25
|
+
"Bash(jq '.[] | {name: .name, type: .type, Map to get Engine.tsx file path})",
|
|
26
|
+
"Bash(curl -s \"https://api.github.com/search?q=repo%3Asimonedevit%2Freactylon+Engine+component&per_page=5\")",
|
|
27
|
+
"Bash(curl -s \"https://api.github.com/search?q=repo%3Asimonedevit%2Freactylon+Engine&per_page=5\")",
|
|
28
|
+
"Bash(curl -s \"https://api.github.com/repos/simonedevit/reactylon/contents/packages/library/src/core\")",
|
|
29
|
+
"Bash(curl -s \"https://api.github.com/repos/simonedevit/reactylon/contents/packages/library/src/core/components\")",
|
|
30
|
+
"Bash(curl -s \"https://api.github.com/search?q=repo%3Asimonedevit%2Freactylon+engine&type=code&per_page=10\")",
|
|
31
|
+
"Bash(curl -s \"https://api.github.com/repos/simonedevit/reactylon/contents/packages/library/src/_generated\")",
|
|
32
|
+
"Bash(curl -s \"https://api.github.com/repos/simonedevit/reactylon/contents/packages/library/src/_generated/babylon.core.declarations.ts\")",
|
|
33
|
+
"Bash(curl -s \"https://raw.githubusercontent.com/simonedevit/reactylon/main/packages/library/src/_generated/babylon.core.declarations.ts\")",
|
|
34
|
+
"Bash(curl -s \"https://raw.githubusercontent.com/simonedevit/reactylon/master/packages/library/src/_generated/babylon.core.declarations.ts\")",
|
|
35
|
+
"Bash(curl -s \"https://raw.githubusercontent.com/simonedevit/reactylon/main/packages/library/package.json\")",
|
|
36
|
+
"Bash(curl -s \"https://unpkg.com/reactylon@latest\")",
|
|
37
|
+
"Bash(pnpm add:*)",
|
|
38
|
+
"Bash(curl:*)",
|
|
39
|
+
"Bash(npx playwright:*)",
|
|
40
|
+
"Bash(npx puppeteer:*)",
|
|
41
|
+
"Bash(pnpm list:*)",
|
|
42
|
+
"Bash(PLAYWRIGHT_DOWNLOAD_HOST=https://npmmirror.com/mirrors/playwright npx playwright:*)",
|
|
43
|
+
"Bash(PLAYWRIGHT_DOWNLOAD_HOST=https://registry.npmmirror.com/-/binary/playwright npx playwright install chromium)",
|
|
44
|
+
"Bash(PLAYWRIGHT_DOWNLOAD_HOST=https://cdn.npmmirror.com/binaries/playwright npx playwright install chromium)",
|
|
45
|
+
"Read(//tmp/**)",
|
|
46
|
+
"Bash(npm init:*)",
|
|
47
|
+
"Bash(npm ls:*)",
|
|
48
|
+
"Bash(node -e \"try{require\\('puppeteer-core'\\)}catch\\(e\\){console.log\\('not installed'\\)}\")",
|
|
49
|
+
"Bash(cp /tmp/capture.cjs /home/ney/os/react-babylon-map/capture.cjs)",
|
|
50
|
+
"Bash(node capture.cjs)",
|
|
51
|
+
"Bash(node -e \"let s=''; process.stdin.on\\('data',d=>s+=d\\); process.stdin.on\\('end',\\(\\)=>console.log\\('OK:',s.trim\\(\\).substring\\(0,50\\)\\)\\)\")",
|
|
52
|
+
"Bash(npx esbuild:*)",
|
|
53
|
+
"Bash(xxd /home/ney/os/react-babylon-map/stories/src/buildings-3d.stories.tsx)",
|
|
54
|
+
"Bash(xxd /home/ney/os/react-babylon-map/stories/src/billboard.stories.tsx)",
|
|
55
|
+
"Bash(npx puppeteer-core:*)",
|
|
56
|
+
"Bash(npm root:*)",
|
|
57
|
+
"Bash(NODE_PATH=/home/ney/.nvm/versions/node/v22.16.0/lib/node_modules node:*)",
|
|
58
|
+
"Bash(pnpm dev:*)",
|
|
59
|
+
"Read(//home/ney/os/react-three-map/stories/**)",
|
|
60
|
+
"Bash(yarn dev:*)",
|
|
61
|
+
"Bash(node -e \"const pkg = require\\('@ifc-lite/geometry'\\); console.log\\(Object.keys\\(pkg\\)\\)\")",
|
|
62
|
+
"Bash(npx ladle:*)",
|
|
63
|
+
"Bash(./node_modules/.bin/ladle serve:*)",
|
|
64
|
+
"Bash(/home/ney/os/react-babylon-map/stories/node_modules/.bin/ladle serve:*)",
|
|
65
|
+
"Bash(NODE_PATH=$\\(npm root -g\\) node /tmp/screenshot-ifc.js)",
|
|
66
|
+
"Bash(NODE_PATH=$\\(npm root -g\\) node /tmp/screenshot-ifc-debug.js)",
|
|
67
|
+
"Bash(NODE_PATH=$\\(npm root -g\\) node /tmp/screenshot-ifc-debug2.js)",
|
|
68
|
+
"Bash(xxd)",
|
|
69
|
+
"Bash(NODE_PATH=$\\(npm root -g\\) node /tmp/screenshot-ifc-debug3.js)",
|
|
70
|
+
"Bash(NODE_PATH=$\\(npm root -g\\) node /tmp/screenshot-ifc-compare.js)",
|
|
71
|
+
"Bash(NODE_PATH=$\\(npm root -g\\) node /tmp/screenshot-ifc-final.js)",
|
|
72
|
+
"Bash(NODE_PATH=$\\(npm root -g\\) node /tmp/screenshot-ifc-debug4.js)",
|
|
73
|
+
"Bash(node -e ':*)",
|
|
74
|
+
"Bash(NODE_PATH=$\\(npm root -g\\) node /tmp/screenshot-ifc-final2.js)",
|
|
75
|
+
"Bash(node:*)"
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
}
|
package/demo.html
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<title>Add a 3D model with babylon.js</title>
|
|
5
|
+
<meta property="og:description" content="Use a custom style layer with babylon.js to add a 3D model to the map." />
|
|
6
|
+
<meta charset='utf-8'>
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
8
|
+
<link rel='stylesheet' href='https://unpkg.com/maplibre-gl@5.22.0/dist/maplibre-gl.css' />
|
|
9
|
+
<script src='https://unpkg.com/maplibre-gl@5.22.0/dist/maplibre-gl.js'></script>
|
|
10
|
+
<style>
|
|
11
|
+
body { margin: 0; padding: 0; }
|
|
12
|
+
html, body, #map { height: 100%; }
|
|
13
|
+
</style>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<script src="https://unpkg.com/babylonjs@5.42.2/babylon.js"></script>
|
|
17
|
+
<script src="https://unpkg.com/babylonjs-loaders@5.42.2/babylonjs.loaders.min.js"></script>
|
|
18
|
+
<div id="map"></div>
|
|
19
|
+
<script>
|
|
20
|
+
const BABYLON = window.BABYLON;
|
|
21
|
+
|
|
22
|
+
const map = (window.map = new maplibregl.Map({
|
|
23
|
+
container: 'map',
|
|
24
|
+
style: 'https://tiles.openfreemap.org/styles/bright',
|
|
25
|
+
zoom: 18,
|
|
26
|
+
center: [148.9819, -35.3981],
|
|
27
|
+
pitch: 60,
|
|
28
|
+
canvasContextAttributes: {antialias: true} // create the gl context with MSAA antialiasing, so custom layers are antialiased
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
// World matrix parameters
|
|
32
|
+
const worldOrigin = [148.9819, -35.39847];
|
|
33
|
+
const worldAltitude = 0;
|
|
34
|
+
|
|
35
|
+
// Maplibre.js default coordinate system (no rotations)
|
|
36
|
+
// +x east, -y north, +z up
|
|
37
|
+
//var worldRotate = [0, 0, 0];
|
|
38
|
+
|
|
39
|
+
// Babylon.js default coordinate system
|
|
40
|
+
// +x east, +y up, +z north
|
|
41
|
+
const worldRotate = [Math.PI / 2, 0, 0];
|
|
42
|
+
|
|
43
|
+
// Calculate mercator coordinates and scale
|
|
44
|
+
const worldOriginMercator = maplibregl.MercatorCoordinate.fromLngLat(
|
|
45
|
+
worldOrigin,
|
|
46
|
+
worldAltitude
|
|
47
|
+
);
|
|
48
|
+
const worldScale = worldOriginMercator.meterInMercatorCoordinateUnits();
|
|
49
|
+
|
|
50
|
+
// Calculate world matrix
|
|
51
|
+
const worldMatrix = BABYLON.Matrix.Compose(
|
|
52
|
+
new BABYLON.Vector3(worldScale, worldScale, worldScale),
|
|
53
|
+
BABYLON.Quaternion.FromEulerAngles(
|
|
54
|
+
worldRotate[0],
|
|
55
|
+
worldRotate[1],
|
|
56
|
+
worldRotate[2]
|
|
57
|
+
),
|
|
58
|
+
new BABYLON.Vector3(
|
|
59
|
+
worldOriginMercator.x,
|
|
60
|
+
worldOriginMercator.y,
|
|
61
|
+
worldOriginMercator.z
|
|
62
|
+
)
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
// configuration of the custom layer for a 3D model per the CustomLayerInterface
|
|
66
|
+
const customLayer = {
|
|
67
|
+
id: '3d-model',
|
|
68
|
+
type: 'custom',
|
|
69
|
+
renderingMode: '3d',
|
|
70
|
+
onAdd (map, gl) {
|
|
71
|
+
this.engine = new BABYLON.Engine(
|
|
72
|
+
gl,
|
|
73
|
+
true,
|
|
74
|
+
{
|
|
75
|
+
useHighPrecisionMatrix: true // Important to prevent jitter at mercator scale
|
|
76
|
+
},
|
|
77
|
+
true
|
|
78
|
+
);
|
|
79
|
+
this.scene = new BABYLON.Scene(this.engine);
|
|
80
|
+
/**
|
|
81
|
+
* optionally add
|
|
82
|
+
* this.scene.autoClearDepthAndStencil = false
|
|
83
|
+
* and for renderingGroupIds set this individually via
|
|
84
|
+
* this.scene.setRenderingAutoClearDepthStencil(1,false)
|
|
85
|
+
* to allow blending with maplibre scene
|
|
86
|
+
* as documented in https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#reducing-calls-to-glclear
|
|
87
|
+
*/
|
|
88
|
+
this.scene.autoClear = false;
|
|
89
|
+
/**
|
|
90
|
+
* use detachControl if you only want to interact with maplibre-gl and do not need pointer events of babylonjs.
|
|
91
|
+
* alternatively exchange this.scene.detachControl() with the following two lines, they will allow bubbling up events to maplibre-gl.
|
|
92
|
+
* this.scene.preventDefaultOnPointerDown = false
|
|
93
|
+
* this.scene.preventDefaultOnPointerUp = false
|
|
94
|
+
* https://doc.babylonjs.com/typedoc/classes/BABYLON.Scene#preventDefaultOnPointerDown
|
|
95
|
+
*/
|
|
96
|
+
this.scene.detachControl();
|
|
97
|
+
|
|
98
|
+
this.scene.beforeRender = () => {
|
|
99
|
+
this.engine.wipeCaches(true);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// create simple camera (will have its project matrix manually calculated)
|
|
103
|
+
this.camera = new BABYLON.Camera(
|
|
104
|
+
'Camera',
|
|
105
|
+
new BABYLON.Vector3(0, 0, 0),
|
|
106
|
+
this.scene
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
// create simple light
|
|
110
|
+
const light = new BABYLON.HemisphericLight(
|
|
111
|
+
'light1',
|
|
112
|
+
new BABYLON.Vector3(0, 0, 100),
|
|
113
|
+
this.scene
|
|
114
|
+
);
|
|
115
|
+
light.intensity = 0.7;
|
|
116
|
+
|
|
117
|
+
// Add debug axes viewer, positioned at origin, 10 meter axis lengths
|
|
118
|
+
new BABYLON.AxesViewer(this.scene, 10);
|
|
119
|
+
|
|
120
|
+
// load GLTF model in to the scene
|
|
121
|
+
BABYLON.SceneLoader.LoadAssetContainerAsync(
|
|
122
|
+
'https://maplibre.org/maplibre-gl-js/docs/assets/34M_17/34M_17.gltf',
|
|
123
|
+
'',
|
|
124
|
+
this.scene
|
|
125
|
+
).then((modelContainer) => {
|
|
126
|
+
modelContainer.addAllToScene();
|
|
127
|
+
|
|
128
|
+
const rootMesh = modelContainer.createRootMesh();
|
|
129
|
+
|
|
130
|
+
// If using maplibre.js coordinate system (+z up)
|
|
131
|
+
//rootMesh.rotation.x = Math.PI/2
|
|
132
|
+
|
|
133
|
+
// Create a second mesh
|
|
134
|
+
const rootMesh2 = rootMesh.clone();
|
|
135
|
+
|
|
136
|
+
// Position in babylon.js coordinate system
|
|
137
|
+
rootMesh2.position.x = 25; // +east, meters
|
|
138
|
+
rootMesh2.position.z = 25; // +north, meters
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
this.map = map;
|
|
142
|
+
},
|
|
143
|
+
render (gl, args) {
|
|
144
|
+
const cameraMatrix = BABYLON.Matrix.FromArray(args.defaultProjectionData.mainMatrix);
|
|
145
|
+
|
|
146
|
+
// world-view-projection matrix
|
|
147
|
+
const wvpMatrix = worldMatrix.multiply(cameraMatrix);
|
|
148
|
+
|
|
149
|
+
this.camera.freezeProjectionMatrix(wvpMatrix);
|
|
150
|
+
|
|
151
|
+
this.scene.render(false);
|
|
152
|
+
this.map.triggerRepaint();
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
map.on('style.load', () => {
|
|
157
|
+
map.addLayer(customLayer);
|
|
158
|
+
});
|
|
159
|
+
</script>
|
|
160
|
+
</body>
|
|
161
|
+
</html>
|