roxy-cobewebgl 1.1.1 → 1.1.2
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/README.md +2 -0
- package/package.json +1 -1
- package/src/fallback.js +7 -3
- package/src/globe.worker.js +11 -4
- package/src/react/RoxyCobewebgl.jsx +1 -0
- package/src/vue/RoxyCobewebgl.vue +1 -0
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Cobe 风格的高性能点阵地球:纯 WebGL + GLSL,可选 **OffscreenCanvas Worker** 渲染(主线程只做交互),不支持时自动 **主线程 WebGL 回退**。以 **ESM** 发布,可在 Vite / Webpack 5+ 等打包器中使用。
|
|
4
4
|
|
|
5
|
+
**画布背景**:WebGL 使用带 **alpha** 的上下文(`premultipliedAlpha: false`),每帧以**透明色**清空缓冲,并用 `SRC_ALPHA` 混合绘制;球圆外(**`glowOn` 为关**时)为**全透明**,可透出下层。若仍看到暗边,多为**外圈光晕**,可把 `glowOn` 设为 `0`。`<canvas>` 建议配合 CSS `background: transparent`。
|
|
6
|
+
|
|
5
7
|
## 安装
|
|
6
8
|
|
|
7
9
|
```bash
|
package/package.json
CHANGED
package/src/fallback.js
CHANGED
|
@@ -431,6 +431,8 @@ export async function createFallbackGlobe(canvas, config) {
|
|
|
431
431
|
return null;
|
|
432
432
|
}
|
|
433
433
|
|
|
434
|
+
gl.clearColor(0, 0, 0, 0);
|
|
435
|
+
|
|
434
436
|
const program = createProgram(gl, VERTEX_SHADER, FRAGMENT_SHADER);
|
|
435
437
|
if (!program) {
|
|
436
438
|
onError(new Error('主着色器编译失败'));
|
|
@@ -515,6 +517,11 @@ export async function createFallbackGlobe(canvas, config) {
|
|
|
515
517
|
|
|
516
518
|
const debugVal = typeof state.debug === 'number' ? state.debug : (typeof window !== 'undefined' && window.__GLOBE_DEBUG__) || 0;
|
|
517
519
|
|
|
520
|
+
gl.clearColor(0, 0, 0, 0);
|
|
521
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
522
|
+
gl.enable(gl.BLEND);
|
|
523
|
+
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
|
524
|
+
|
|
518
525
|
gl.useProgram(program);
|
|
519
526
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
520
527
|
gl.enableVertexAttribArray(loc.a_position);
|
|
@@ -538,8 +545,6 @@ export async function createFallbackGlobe(canvas, config) {
|
|
|
538
545
|
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
|
539
546
|
|
|
540
547
|
if (arcProgram && arcAnimator) {
|
|
541
|
-
gl.enable(gl.BLEND);
|
|
542
|
-
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
|
543
548
|
gl.useProgram(arcProgram);
|
|
544
549
|
const aspect = canvas.width / canvas.height;
|
|
545
550
|
gl.uniform1f(arcLoc.u_phi, state.phi);
|
|
@@ -559,7 +564,6 @@ export async function createFallbackGlobe(canvas, config) {
|
|
|
559
564
|
gl.vertexAttribPointer(arcLoc.a_arcPos, 3, gl.FLOAT, false, 0, 0);
|
|
560
565
|
gl.drawArrays(gl.LINE_STRIP, st.startIdx, st.drawCount);
|
|
561
566
|
}
|
|
562
|
-
gl.disable(gl.BLEND);
|
|
563
567
|
}
|
|
564
568
|
rafId = requestAnimationFrame(render);
|
|
565
569
|
}
|
package/src/globe.worker.js
CHANGED
|
@@ -441,11 +441,16 @@ async function init(msg) {
|
|
|
441
441
|
if (msg.params) Object.assign(params, msg.params);
|
|
442
442
|
|
|
443
443
|
console.log('[Worker] init, canvas size:', canvas.width, canvas.height);
|
|
444
|
-
gl = canvas.getContext('webgl', {
|
|
444
|
+
gl = canvas.getContext('webgl', {
|
|
445
|
+
antialias: false,
|
|
446
|
+
alpha: true,
|
|
447
|
+
premultipliedAlpha: false,
|
|
448
|
+
});
|
|
445
449
|
if (!gl) {
|
|
446
450
|
self.postMessage({ type: 'error', msg: 'WebGL 不可用' });
|
|
447
451
|
return;
|
|
448
452
|
}
|
|
453
|
+
gl.clearColor(0, 0, 0, 0);
|
|
449
454
|
console.log('[Worker] WebGL context OK');
|
|
450
455
|
|
|
451
456
|
program = createProgram(gl, VERTEX_SHADER, FRAGMENT_SHADER);
|
|
@@ -521,6 +526,11 @@ function render(t) {
|
|
|
521
526
|
const timeSec = t * 0.001;
|
|
522
527
|
if (params.autoRotate) params.phi += params.rotationSpeed || 0.003;
|
|
523
528
|
|
|
529
|
+
gl.clearColor(0, 0, 0, 0);
|
|
530
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
531
|
+
gl.enable(gl.BLEND);
|
|
532
|
+
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
|
533
|
+
|
|
524
534
|
// Pass 1: 球体
|
|
525
535
|
gl.useProgram(program);
|
|
526
536
|
gl.bindBuffer(gl.ARRAY_BUFFER, quadBuffer);
|
|
@@ -547,8 +557,6 @@ function render(t) {
|
|
|
547
557
|
|
|
548
558
|
// Pass 2: 弧线
|
|
549
559
|
if (arcProgram && arcAnimator) {
|
|
550
|
-
gl.enable(gl.BLEND);
|
|
551
|
-
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
|
552
560
|
gl.useProgram(arcProgram);
|
|
553
561
|
const aspect = canvas.width / canvas.height;
|
|
554
562
|
gl.uniform1f(arcLoc.u_phi, params.phi);
|
|
@@ -570,7 +578,6 @@ function render(t) {
|
|
|
570
578
|
gl.vertexAttribPointer(arcLoc.a_arcPos, 3, gl.FLOAT, false, 0, 0);
|
|
571
579
|
gl.drawArrays(gl.LINE_STRIP, state.startIdx, state.drawCount);
|
|
572
580
|
}
|
|
573
|
-
gl.disable(gl.BLEND);
|
|
574
581
|
}
|
|
575
582
|
|
|
576
583
|
rafId = requestAnimationFrame(render);
|