npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sakitam-gis/vis-engine

v1.5.3

Published

A sample gl render engine toolkit.

Downloads

124

Readme

vis-engine

vis-engine 是一个简单的 webgl 渲染引擎工具包,它的设计受到了 threejsogl 的启发。

它的定位介于 WebGL 封装和渲染引擎之间,包含了相机,Mesh 和 Shader 模块化以及 webgl 状态管理。

CI npm version npm downloads Coverage Status

Install

yarn add @sakitam-gis/vis-engine -S

pnpm i @sakitam-gis/vis-engine

import { Renderer, Raf, Scene, PerspectiveCamera, Geometry, Mesh, Program } from '@sakitam-gis/vis-engine';

Usage

Renderer

创建渲染器:

const renderer = new Renderer(canvas, {
  alpha: true,
});

Camera

创建相机:

const fov = 15;
const nearZ = 0.1;

const farZ = 100;
const camera = new PerspectiveCamera(fov, canvas.width / canvas.height, nearZ, farZ);
camera.position.z = fov;

Scene

创建场景:

const scene = new Scene();

Geometry

创建几何体对象:

const geometry = new Geometry(renderer, {
  position: {
    size: 3,
    data: new Float32Array([
      -1.6, 1.5, 0,
      -1, -1, 0,
      1, -1, 0,
      -1, -1, 0,
      1, -1, 0,
      1.6, 1.5, 0,
    ])
  },
});

Program

创建着色器资源:

const program = new Program(renderer, {
  vertexShader: `
    attribute vec2 uv;
    attribute vec3 position;
    uniform mat4 modelViewMatrix;
    uniform mat4 projectionMatrix;

    varying vec2 vUv;

    void main() {
        vUv = uv;

        gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);

        // gl_PointSize only applicable for gl.POINTS draw mode
        gl_PointSize = 5.0;
    }
    `,
  fragmentShader: `
    precision highp float;

    uniform float uTime;
    varying vec2 vUv;

    void main() {
        gl_FragColor.rgb = 0.5 + 0.3 * sin(vUv.yxx + uTime) + vec3(0.2, 0.0, 0.1);
        gl_FragColor.a = 1.0;
    }
    `,
  uniforms: {
    uTime: { value: 0 },
  },
});

Mesh

创建 Mesh:

const triangles = new Mesh(renderer, { mode: renderer.gl.TRIANGLES, geometry, program });

添加到场景

scene.add(triangles);

渲染

更新 uniform 变量并渲染场景:

const raf = new Raf((t) => {
  program.setUniform('uTime', t);
  renderer.render({ scene, camera });
});

Types

vis-engine 完全采用 Typescript 编写

Roadmap

📢注意:这是一个玩具项目,不是为了替代什么,但是我会尽力完善它,它最大的方向可能是和各类地图引擎结合例如 mapbox-gl/maptalks/leaflet 等,所以暂时没有固定的路线图。

License

BSD 3-Clause