我决定不从Babylonjs 基础来讲了 直接整合mapbox与babylonjs可视化来讲
我整合一个类库 后续不断更新中
- npm i @haibalai/mapbox-babylonjs
初始化mapbox-babylonjs 类库, map 是mapbox.gl 的map 对象
- import { BabylonMapManager } from "@haibalai/mapbox-babylonjs";
- BabylonMapManager.init(map);
添加特效
- import { BabylonMapManager } from "@haibalai/mapbox-babylonjs";
- const fragmentShader = `
- uniform float iTime;
- const vec2 iResolution = vec2(1.0,1.0);
- varying vec2 vUv;
- #define POINT_COUNT 8
- vec2 points[POINT_COUNT];
- constfloat speed = -0.5;
- constfloat len = 0.25;
- constfloat scale = 0.012;
- float intensity = 1.3;
- float radius = 0.015;
- //https://www.shadertoy.com/view/MlKcDD
- //Signed distance to a quadratic bezier
- floatsdBezier(vec2 pos, vec2 A, vec2 B, vec2 C){
- vec2 a = B - A;
- vec2 b = A - 2.0*B + C;
- vec2 c = a * 2.0;
- vec2 d = A - pos;
- float kk = 1.0 / dot(b,b);
- float kx = kk * dot(a,b);
- float ky = kk * (2.0*dot(a,a)+dot(d,b)) / 3.0;
- float kz = kk * dot(d,a);