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

@gengine-js/gengine

v1.0.1

Published

A rendering engine based on webgpu

Downloads

3

Readme

GEngine.js

WebGPU Engine

install

$ yarn add @gengine-js/gengine

develop

# install
$ yarn

# dev
$ yarn dev

# build
$ yarn build

Usage

<script type="module">
	import {
		Mesh,
		PerspectiveCamera,
		Scene,
		PhongMaterial,
		Vector3,
		Color,
		SpotLight,
		PointLight,
		SphereGeometry,
		OrbitControl
	} from "../dist/index.js";
	const init = async () => {
		const geometry = new SphereGeometry(10);

		const phongMaterial = new PhongMaterial();
		phongMaterial.color = new Color(1.0, 0.0, 0.0);

		const primitive = new Mesh(geometry, phongMaterial);

		primitive.rotateX(-Math.PI / 2);

		const camera = new PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.01, 1000);

		camera.position.set(0, 20, 0);

		camera.lookAt(0, 0, 0);

		const spotLight = new SpotLight(new Vector3(1.0, 1.0, 1.0), 1.0, 15, 6, 1);
		spotLight.position = new Vector3(0, 20, 0);

		const scene = new Scene({ container: "app" });

		axes.scale.set(10, 10, 10);

		const control = new OrbitControl(camera, document.getElementById("app"));

		scene.add(primitive);

		scene.setCamera(camera);

		scene.add(pointLight);

		window.addEventListener("resize", onWindowResize);

		function onWindowResize() {
			camera.aspect = window.innerWidth / window.innerHeight;
			scene.resize(window.innerWidth, window.innerHeight);
		}
		function animate() {
			control.update();
			requestAnimationFrame(animate);
			scene.render();
		}
		animate();
	};
	init();
</script>

Native

<script type="module">
	import { Model, Context, Texture, RenderTarget, Attachment } from "webgpu-gengine-js";
	import { mat4, vec3 } from "gl-matrix";
	const init = async () => {
		//init context
		const context = new Context({
			canvas: null,
			container: document.getElementById("app"),
			pixelRatio: 1
		});
		const { canvas, presentationFormat } = context;
		await context.init();
		const { width, height, depth } = context.presentationSize;
		const colorAttachment = new Attachment(
			{ r: 0.0, g: 0.0, b: 0.0, a: 0 },
			{
				textureView: () => {
					return context.context.getCurrentTexture().createView();
				}
			}
		);
		const depthTexture = new Texture({
			label: "resolveDepth",
			size: { width, height, depth },
			format: "depth24plus",
			usage: GPUTextureUsage.RENDER_ATTACHMENT
		});
		const depthAttachment = new Attachment(1.0, { texture: depthTexture });
		//fbo
		const canvasRenderTarget = new RenderTarget("render", [colorAttachment], depthAttachment);
		const aspect = canvas.width / canvas.height;
		const projectionMatrix = mat4.perspective([], (2 * Math.PI) / 5, aspect, 1, 100.0);
		const modelViewProjectionMatrix = mat4.create();
		const model = new Model({
			shaderId: "model",
			frag: `
                            @fragment
                            fn main(@location(0) fragPosition: vec4<f32>) -> @location(0) vec4<f32> {
                                 return fragPosition;
                            }
                        `,
			vert: `
                            struct Uniforms {
                                modelViewProjectionMatrix : mat4x4<f32>,
                            }
                            @binding(0) @group(0) var<uniform> uniforms : Uniforms;
                            struct VertexOutput {
                                @builtin(position) Position : vec4<f32>,
                                @location(0) fragPosition: vec4<f32>,
                            }
                            @vertex
                            fn main(@location(0) position : vec4<f32>,@location(1) color : vec4<f32>) -> VertexOutput {
                                var output : VertexOutput;
                                output.Position = uniforms.modelViewProjectionMatrix * position;
                                output.fragPosition = 0.5 * (position + vec4(1.0, 1.0, 1.0, 1.0));
                                return output;
                            }
                        `,
			vertexBuffers: [
				{
					stepMode: "vertex", //optional
					uid: "vertAttr", //must
					attributes: {
						position: { size: 4, value: positions },
						color: { size: 4, value: colors }
					}
				}
			],
			uniformBuffers: [
				{
					type: "uniform",
					uid: "systemMatrix",
					uniforms: {
						modelViewProjectionMatrix: {
							type: "mat4",
							value: () => {
								let viewMatrix = mat4.identity([]);
								mat4.translate(viewMatrix, viewMatrix, vec3.fromValues(0, 0, -4));
								const now = Date.now() / 1000;
								mat4.rotate(
									viewMatrix,
									viewMatrix,
									1,
									vec3.fromValues(Math.sin(now), Math.cos(now), 0)
								);
								mat4.multiply(modelViewProjectionMatrix, projectionMatrix, viewMatrix);
								return modelViewProjectionMatrix;
							}
						}
					}
				}
			],
			renderState: {
				targets: [
					{
						format: presentationFormat
					}
				],
				primitive: {
					topology: "triangle-list",
					cullMode: "back"
				},
				depthStencil: {
					depthWriteEnabled: true,
					depthCompare: "less",
					format: "depth24plus"
				}
			},
			count: 36,
			instances: 1
		});

		function animate() {
			requestAnimationFrame(animate);
			const passEncoder = canvasRenderTarget.beginRenderPass(context.device);
			model.render({ device: context.device, passEncoder });
			canvasRenderTarget.endRenderPass();
		}
		animate();
	};
	init();
</script>

feature

  • [✔] Camera
    • [✔] PerspectiveCamera
    • [✔] OrthographicCamera
  • [✔] Math
  • [✔] control
    • [✔] OrbitControl
  • [✔] Light
    • [✔] AmbientLight
    • [✔] DirectionalLight
    • [✔] PointLight
    • [✔] SpotLight
  • [✔] Loader
    • [✔] GLTFLoader
    • [✔] CubeTextureLoader
  • [✔] Materials
    • [✔] ColorMaterial
    • [✔] Material
    • [✔] PbrMaterial(IBL/Light Render)
    • [✔] BlinPhongMaterial
    • [✔] ShaderMaterial
    • [✔] SkyBoxMaterial
  • [✔] Post-Effect
    • [✔] BloomPostEffect
  • [✔] Shadow
    • [✔] DirectionalLightShadow
    • [✔] PointLightShadow
    • [✔] SpotLightShadow

Next

  1. Complete animation
  2. Complete core glTF 2.0
  3. Text and Sprite
  4. Pick