@treasuryspatial/map-react 0.1.6 → 0.1.8
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.
|
@@ -14,7 +14,7 @@ export type MapModeViewportHandle = {
|
|
|
14
14
|
animateToView: (_viewKey: string) => void;
|
|
15
15
|
capturePngDataUrl: () => string;
|
|
16
16
|
};
|
|
17
|
-
export type ApplyLightingPreset = (scene: THREE.Scene, presetKey: string) => void;
|
|
17
|
+
export type ApplyLightingPreset = (scene: THREE.Scene, renderer: THREE.WebGLRenderer, presetKey: string) => void;
|
|
18
18
|
export type ResolveMeshGroup = (geometry3dm: string) => Promise<THREE.Group | null>;
|
|
19
19
|
export type MapModeViewportProps = {
|
|
20
20
|
active: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapModeViewport.d.ts","sourceRoot":"","sources":["../src/MapModeViewport.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"MapModeViewport.d.ts","sourceRoot":"","sources":["../src/MapModeViewport.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA6F,MAAM,OAAO,CAAC;AAElH,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEhD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EASL,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC3B,MAAM,0BAA0B,CAAC;AAElC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,qBAAqB,CAAC;IACjC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1B,WAAW,EAAE,MAAM,EAAE,EAAE,CAAC;IACxB,KAAK,EAAE,cAAc,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,iBAAiB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IA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,eAAO,MAAM,eAAe,oGA8W1B,CAAC"}
|
package/dist/MapModeViewport.js
CHANGED
|
@@ -44,8 +44,8 @@ export const MapModeViewport = forwardRef(function MapModeViewport({ active, geo
|
|
|
44
44
|
useImperativeHandle(ref, () => ({
|
|
45
45
|
setLightingPreset: (presetKey) => {
|
|
46
46
|
lightingPresetRef.current = presetKey;
|
|
47
|
-
if (sceneRef.current) {
|
|
48
|
-
(applyLightingPreset ?? defaultApplyLightingPreset)(sceneRef.current, presetKey);
|
|
47
|
+
if (sceneRef.current && rendererRef.current) {
|
|
48
|
+
(applyLightingPreset ?? defaultApplyLightingPreset)(sceneRef.current, rendererRef.current, presetKey);
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
animateToView: () => { },
|
|
@@ -90,7 +90,7 @@ export const MapModeViewport = forwardRef(function MapModeViewport({ active, geo
|
|
|
90
90
|
zoom: startZoom,
|
|
91
91
|
bearing: startBearing,
|
|
92
92
|
pitch: startPitch,
|
|
93
|
-
projection: '
|
|
93
|
+
projection: 'mercator',
|
|
94
94
|
antialias: true,
|
|
95
95
|
preserveDrawingBuffer: true,
|
|
96
96
|
attributionControl: false,
|
|
@@ -226,9 +226,9 @@ export const MapModeViewport = forwardRef(function MapModeViewport({ active, geo
|
|
|
226
226
|
onInit: (scene, renderer) => {
|
|
227
227
|
sceneRef.current = scene;
|
|
228
228
|
rendererRef.current = renderer;
|
|
229
|
-
renderer.
|
|
230
|
-
renderer.
|
|
231
|
-
(applyLightingPreset ?? defaultApplyLightingPreset)(scene, lightingPresetRef.current);
|
|
229
|
+
renderer.shadowMap.enabled = true;
|
|
230
|
+
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
|
231
|
+
(applyLightingPreset ?? defaultApplyLightingPreset)(scene, renderer, lightingPresetRef.current);
|
|
232
232
|
},
|
|
233
233
|
});
|
|
234
234
|
}
|
|
@@ -313,6 +313,31 @@ export const MapModeViewport = forwardRef(function MapModeViewport({ active, geo
|
|
|
313
313
|
};
|
|
314
314
|
return (_jsxs("div", { className: "absolute inset-0", children: [_jsx("div", { ref: containerRef, className: "w-full h-full" }), !accessToken && (_jsx("div", { className: "absolute inset-0 z-[2] flex items-center justify-center bg-black/70 text-xs text-white font-nunito", children: "Mapbox access token missing." })), mapError && (_jsx("div", { className: "absolute inset-0 z-[2] flex items-center justify-center bg-black/70 text-xs text-white font-nunito", children: mapError })), !mapReady && !mapError && accessToken && (_jsx("div", { className: "absolute inset-0 z-[2] flex items-center justify-center bg-black/60 text-xs text-white font-nunito", children: "loading map\u2026" }))] }));
|
|
315
315
|
});
|
|
316
|
+
const ensureGeometryUvs = (geometry) => {
|
|
317
|
+
if (geometry.getAttribute('uv'))
|
|
318
|
+
return;
|
|
319
|
+
const pos = geometry.getAttribute('position');
|
|
320
|
+
if (!pos)
|
|
321
|
+
return;
|
|
322
|
+
geometry.computeBoundingBox();
|
|
323
|
+
const bbox = geometry.boundingBox;
|
|
324
|
+
if (!bbox)
|
|
325
|
+
return;
|
|
326
|
+
const size = new THREE.Vector3();
|
|
327
|
+
bbox.getSize(size);
|
|
328
|
+
const uvs = new Float32Array(pos.count * 2);
|
|
329
|
+
const denomX = size.x || 1;
|
|
330
|
+
const denomZ = size.z || 1;
|
|
331
|
+
for (let i = 0; i < pos.count; i += 1) {
|
|
332
|
+
const x = pos.getX(i);
|
|
333
|
+
const z = pos.getZ(i);
|
|
334
|
+
const u = (x - bbox.min.x) / denomX;
|
|
335
|
+
const v = (z - bbox.min.z) / denomZ;
|
|
336
|
+
uvs[i * 2] = u;
|
|
337
|
+
uvs[i * 2 + 1] = v;
|
|
338
|
+
}
|
|
339
|
+
geometry.setAttribute('uv', new THREE.BufferAttribute(uvs, 2));
|
|
340
|
+
};
|
|
316
341
|
function applyMaterialOverrides(group, settings) {
|
|
317
342
|
const color = new THREE.Color(settings?.color ?? '#ffffff');
|
|
318
343
|
const textureUrl = settings?.textureUrl;
|
|
@@ -337,9 +362,12 @@ function applyMaterialOverrides(group, settings) {
|
|
|
337
362
|
else
|
|
338
363
|
material?.dispose?.();
|
|
339
364
|
}
|
|
365
|
+
if (texture) {
|
|
366
|
+
ensureGeometryUvs(mesh.geometry);
|
|
367
|
+
}
|
|
340
368
|
mesh.material = new THREE.MeshStandardMaterial({
|
|
341
369
|
color,
|
|
342
|
-
roughness: 0.
|
|
370
|
+
roughness: 0.75,
|
|
343
371
|
metalness: 0,
|
|
344
372
|
side: THREE.DoubleSide,
|
|
345
373
|
map: texture ?? null,
|
|
@@ -347,10 +375,12 @@ function applyMaterialOverrides(group, settings) {
|
|
|
347
375
|
mesh.material.polygonOffset = true;
|
|
348
376
|
mesh.material.polygonOffsetFactor = 1.0;
|
|
349
377
|
mesh.material.polygonOffsetUnits = 1.0;
|
|
378
|
+
mesh.castShadow = false;
|
|
379
|
+
mesh.receiveShadow = false;
|
|
350
380
|
});
|
|
351
381
|
}
|
|
352
|
-
function defaultApplyLightingPreset(scene, _presetKey) {
|
|
353
|
-
scene.background =
|
|
382
|
+
function defaultApplyLightingPreset(scene, renderer, _presetKey) {
|
|
383
|
+
scene.background = new THREE.Color('#ffffff');
|
|
354
384
|
const lightsToRemove = scene.children.filter((child) => child instanceof THREE.Light);
|
|
355
385
|
lightsToRemove.forEach((light) => scene.remove(light));
|
|
356
386
|
scene.add(new THREE.AmbientLight('#ffffff', 0.6));
|
|
@@ -361,6 +391,8 @@ function defaultApplyLightingPreset(scene, _presetKey) {
|
|
|
361
391
|
const fill = new THREE.DirectionalLight('#ffffff', 0.4);
|
|
362
392
|
fill.position.set(-6, 8, -6);
|
|
363
393
|
scene.add(fill);
|
|
394
|
+
renderer.toneMapping = THREE.NeutralToneMapping;
|
|
395
|
+
renderer.toneMappingExposure = 1.05;
|
|
364
396
|
}
|
|
365
397
|
function applyMapVisibility(map, mode, cacheRef) {
|
|
366
398
|
if (!map?.getStyle?.())
|