add transparency gps

This commit is contained in:
math-pixel
2026-05-20 16:56:01 +02:00
parent 09a9471814
commit 246da0019a
4 changed files with 28 additions and 20 deletions
Binary file not shown.
+13 -9
View File
@@ -58,7 +58,7 @@ export const EbikeGPSMap: React.FC<EbikeGPSMapProps> = ({
height = 1, height = 1,
}) => { }) => {
const [waypoints, setWaypoints] = useState<Waypoint[]>([]); const [waypoints, setWaypoints] = useState<Waypoint[]>([]);
const [mapImage, setMapImage] = useState<HTMLImageElement | null>(null); const [mapImage, setMapImage] = useState<HTMLImageElement | HTMLCanvasElement | null>(null);
// Offscreen high-res canvas for crystal clear rendering // Offscreen high-res canvas for crystal clear rendering
const [offscreenCanvas] = useState(() => { const [offscreenCanvas] = useState(() => {
@@ -102,7 +102,8 @@ export const EbikeGPSMap: React.FC<EbikeGPSMapProps> = ({
}); });
}, []); }, []);
// Pre-load background map image if provided // Pre-load background map image (standard HTML5 Image loader)
// Since the user's PNG is already transparent, we don't need fetch or pixel manipulation!
useEffect(() => { useEffect(() => {
if (!mapImageUrl) { if (!mapImageUrl) {
setMapImage(null); setMapImage(null);
@@ -110,7 +111,9 @@ export const EbikeGPSMap: React.FC<EbikeGPSMapProps> = ({
} }
const img = new Image(); const img = new Image();
img.onload = () => setMapImage(img); img.onload = () => {
setMapImage(img);
};
img.onerror = () => { img.onerror = () => {
console.warn(`[GPS Component] Failed to load map background image from ${mapImageUrl}. Falling back to dynamic vector map.`); console.warn(`[GPS Component] Failed to load map background image from ${mapImageUrl}. Falling back to dynamic vector map.`);
setMapImage(null); setMapImage(null);
@@ -170,11 +173,12 @@ export const EbikeGPSMap: React.FC<EbikeGPSMapProps> = ({
return { x: px, y: py }; return { x: px, y: py };
}; };
// Draw loop // Draw loop
const draw = () => { const draw = () => {
const canvas = offscreenCanvas; const canvas = offscreenCanvas;
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d', { willReadFrequently: true, alpha: true });
ctx.globalAlpha = 0.5;
if (!ctx) return; if (!ctx) return;
const size = canvas.width; const size = canvas.width;
@@ -184,10 +188,9 @@ export const EbikeGPSMap: React.FC<EbikeGPSMapProps> = ({
// 1. Draw Map Background (Image or premium blueprint vectors) // 1. Draw Map Background (Image or premium blueprint vectors)
if (mapImage) { if (mapImage) {
ctx.drawImage(mapImage, 0, 0, size, size); ctx.drawImage(mapImage, 0, 0, size, size);
ctx.globalAlpha = 1.0;
} else { } else {
// Dynamic Sci-fi background grid // Dynamic Sci-fi background grid (Background is transparent!)
ctx.fillStyle = '#0a0d16'; // Deep space black
ctx.fillRect(0, 0, size, size);
// Sci-fi subgrid // Sci-fi subgrid
ctx.strokeStyle = 'rgba(30, 41, 59, 0.4)'; ctx.strokeStyle = 'rgba(30, 41, 59, 0.4)';
@@ -377,11 +380,12 @@ export const EbikeGPSMap: React.FC<EbikeGPSMapProps> = ({
return ( return (
<mesh castShadow receiveShadow> <mesh castShadow receiveShadow>
<planeGeometry args={[width, height]} /> <planeGeometry args={[width, height]} />
<meshBasicMaterial toneMapped={false} transparent opacity={0.95}> <meshBasicMaterial toneMapped={false} transparent={true} opacity={1} depthWrite={false}>
<canvasTexture <canvasTexture
ref={textureRef} ref={textureRef}
attach="map" attach="map"
image={offscreenCanvas} image={offscreenCanvas}
format={THREE.RGBAFormat}
minFilter={THREE.LinearFilter} minFilter={THREE.LinearFilter}
magFilter={THREE.LinearFilter} magFilter={THREE.LinearFilter}
/> />
+12 -8
View File
@@ -238,16 +238,20 @@ export function TestMap({ onOctreeReady }: TestMapProps): React.JSX.Element {
{/* Dynamic Futuristic 3D GPS Dashboard Preview */} {/* Dynamic Futuristic 3D GPS Dashboard Preview */}
<group position={[0, 2.8, -4.8]} rotation={[0, 0, 0]}> <group position={[0, 2.8, -4.8]} rotation={[0, 0, 0]}>
{/* Futuristic glowing screen frame */} {/* Futuristic glowing screen frame (commented out to show true 3D transparency!) */}
{/*
<mesh> <mesh>
<boxGeometry args={[4.2, 4.2, 0.1]} /> <boxGeometry args={[4.2, 4.2, 0.1]} />
<meshStandardMaterial color="#0f172a" roughness={0.2} metalness={0.8} /> <meshStandardMaterial color="#0f172a" roughness={0.2} metalness={0.8} transparent opacity={0.4} />
</mesh> </mesh>
{/* Glow accent border */} */}
{/* Glow accent border (commented out to remove any orange transparency tint!) */}
{/*
<mesh position={[0, 0, 0.01]}> <mesh position={[0, 0, 0.01]}>
<boxGeometry args={[4.05, 4.05, 0.02]} /> <boxGeometry args={[4.05, 4.05, 0.02]} />
<meshBasicMaterial color="#f97316" transparent opacity={0.2} /> <meshBasicMaterial color="#f97316" transparent opacity={0.1} />
</mesh> </mesh>
*/}
{/* GPS Map screen plane */} {/* GPS Map screen plane */}
<group position={[0, 0, 0.06]}> <group position={[0, 0, 0.06]}>
<EbikeGPSMap <EbikeGPSMap
@@ -257,10 +261,10 @@ export function TestMap({ onOctreeReady }: TestMapProps): React.JSX.Element {
destPos={{ x: -40, y: 0, z: 30 }} destPos={{ x: -40, y: 0, z: 30 }}
mapImageUrl="/map_background.png" mapImageUrl="/map_background.png"
worldBounds={{ worldBounds={{
minX: -146, // Les valeurs exactes "minX": -166,
maxX: 131, // que l'outil t'aura "maxX": 163,
minZ: -139, // affiché en temps réel ! "minZ": -142,
maxZ: 138 "maxZ": 138
}} }}
/> />
</group> </group>