GithubHelp home page GithubHelp logo

alexxnica / spector.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from babylonjs/spector.js

0.0 1.0 0.0 15.65 MB

Explore and Troubleshoot your WebGL scenes with ease.

Home Page: http://spector.babylonjs.com

License: MIT License

JavaScript 4.35% HTML 0.45% TypeScript 91.12% CSS 4.08%

spector.js's Introduction

Summary

Explore and Troubleshoot your WebGL scenes (All engines and Vanilla script support) with ease.

Spector is a tool aim to WebGl developers willing to know what happens on their context. It enables capturing all the available information from a frame. You will be empowered to look at your entire commands list with their asoociated visual states and context information.

Build Status Code Climate

This can be used either as a browser extension or directly from your page a a Standalone Version.

Table of Content

Why

As a core member of the BabylonJS team I often found the need of debugging what is happening to my webgl context. I was a huge fan of webgl inspector until we introduced WebGl2 in Babylon. As the WebGL community as a whole is our focus, I thought it would be great to share an extension compatible with all the Webgl/Webgl2 engines available.

You can use the library inside of your own application easily. As it is transpiled as a UMD module, this will either work as a script reference or relying on you favorite bundling tools like webpack.

Browser extension

If you are willing to use the browser extension instead, you can refer to the following documentation: Browser Extension.

Or you can direclty install it from the store:

Use as a Module

In order to install the library in your application directory, please type the following commands on a command line prompt open on the application directory:

npm install spectorjs

From this point you are all set to use it in your app.

Webpack sample

As a quick demo, here is a simple way to use the spector module with webpack.

Please follow the instrctions below which are creating a new directory and installing the required tools:

mkdir sample
cd sample
npm init
npm install webpack --save-dev
npm install spectorjs --save-dev

Following the HelloWorld example from Webpack, you can now create in the sample folder:

A js file named entry.js containing the following code:

var SPECTOR = require("spectorjs");

var spector = new SPECTOR.Spector();
spector.displayUI();

And an html file named index.js containing the following code:

<html>
    <head>
    </head>
    <body>
        <script type="text/javascript" src="bundle.js" charset="utf-8"></script>
    </body>
</html>

Now your application is ready, go back to your command line and bundle the javascript file:

webpack entry.js bundle.js

You are all set, you can open your index.html file and see the inspector running. It will obviously won't be that usefull on an empty page but at least you get the integration idea.

Use as a Script Reference

CDN

Feel free to leverage the CDN to use the library from your own projets: https://spectorcdn.babylonjs.com/spector.bundle.js

Repo

If you prefer to host your own version, the library is available in the dist folder of the repo.

node_modules

If you used npm to install the library you can find the spector.bundle.js file in the node_module/spectorjs/dist folder.

How To Reference

Simply add the following tag in your html page header:

<script type="text/javascript" src="spector.bundle.js"></script>

Basic Usage

Once available in your app, you can instantiate an inspector by inserting the following command in your script:

var spector = new SPECTOR.Spector();

You can then display the embedded UI directly in your page:

spector.displayUI();

Or launch a capture and reuse its JSON result at your will:

spector.onCapture.add((capture) => {
    // Do something with capture.
    var myEvent = new CustomEvent("SpectorOnCaptureEvent", { detail: { captureString: JSON.stringify(capture) } });
    document.dispatchEvent(myEvent);
});

var canvas = document.getElementById("renderCanvas");
spector.captureCanvas(canvas);

Another api you can rely upon is:

spector.spyCanvases();

This will enable a complete tracking of the gl calls even before capturing which enables for instance access to the texture inputs or memory consumption information.

Custom Data

You can simply add custom data to the capture by adding a special field named __SPECTOR_Metadata to your WebGLObjects.

var cubeVerticesColorBuffer = gl.createBuffer();
cubeVerticesColorBuffer.__SPECTOR_Metadata = { name: "cubeVerticesColorBuffer" };

This will enable the visibility of your custom name in your capture. This can be an invaluable asset during troubleshoot session. This can also help referencing your materials friendly names from your captures.

Learn About WebGL

I would advise you to check out and start with the Awesome BabylonJS the community there will be more than happy to welcome anybody willing to learn Web 3d.

spector.js's People

Contributors

sebavan avatar temechon avatar rhmoller avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.