• Stars
    star
    1,215
  • Rank 37,016 (Top 0.8 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 7 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Explore and Troubleshoot your WebGL scenes with ease.

SpectorJS

Summary

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

Spector is a tool aimed at WebGL developers wanting to know what happens in their context. It enables capturing of all the available information from a frame. You will be able to look at your entire commands list with their associated visual states and context information.

Build Status devDependencies Status

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

Table of Content

Why

Back to top

As a core member of the BabylonJS team I often found the need to debug what was 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. It will either work as a script reference or with your favorite bundling tools like webpack.

Browser extension

Back to top

If you are willing to use the browser extension, you can direclty install it from the store:

You can find on Real Time Rendering a complete tutorial about the Spector extension. Else, you can refer to the extension documentation to learn how to use it.

Or you can take a look at the following documentation to load it from the source: Browser Extension.

Use as a Module

Back to top

In order to install the library in your application directory, please type the following command 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

Back to top

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

Please follow the instructions below to create a new directory and install 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 it 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 obviously won't be that usefull on an empty page but at least you get the integration idea.

Use as a Script Reference

Back to top

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="https://spectorcdn.babylonjs.com/spector.bundle.js"></script>

Basic Usage

Back to top

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

Back to top

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 with referencing your materials' friendly names from your captures.

Learn About WebGL

Back to top

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.

More Repositories

1

Babylon.js

Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.
TypeScript
22,116
star
2

Editor

Community managed visual editor for Babylon.js
TypeScript
804
star
3

BabylonNative

Build cross-platform native applications with the power of the Babylon.js JavaScript framework
C++
729
star
4

Exporters

Exporters for Babylon.js and gltf file formats
Mathematica
577
star
5

BabylonReactNative

Build React Native applications with the power of Babylon Native
C++
350
star
6

BlenderExporter

Exports From Blender to Babylon.JS in JSON / .babylon format
Python
280
star
7

Website

Main babylon.js website
JavaScript
197
star
8

Extensions

Extensions for Babylon.js
JavaScript
169
star
9

UnityExporter

Home of the community maintained Unity exporter for Babylon.js
159
star
10

Assets

A place for public domain digital assets to use.
JavaScript
142
star
11

SpacePirates

The Space Pirates game is a demo made to celebrate the Babylon.js 5.0 Release.
TypeScript
142
star
12

SummerFestival

Source code for game tutorial written by capucat
TypeScript
127
star
13

BabylonAR

Home of the Babylon.AR project
TypeScript
72
star
14

Documentation

Babylon.js's documentation website
TypeScript
71
star
15

OldDocumentationSite

Babylon.js documentation page
JavaScript
66
star
16

MeshesLibrary

Use this repo as a place to share your scenes and meshes
JavaScript
47
star
17

BabylonReactNativeSample

Java
33
star
18

CYOS

Create Your Own Shader
JavaScript
23
star
19

BabylonPolymorph

C++
22
star
20

SpacePiratesAR

Space Pirates Demo with Babylon React-Native and AR.
TypeScript
19
star
21

npm-package-template

JavaScript
16
star
22

Controls

Set of web controls using babylon.js and the GPU to render their content in a hardware accelerated way
TypeScript
15
star
23

JsRuntimeHost

The JsRuntimeHost is a library that provides cross-platform C++ JavaScript hosting for any JavaScript engines with Node-API support such as Chakra, V8, or JavaScriptCore.
C++
12
star
24

Brand-Toolkit

11
star
25

twgsl

C++
9
star
26

BabylonNativeExamples

A collection of sample code projects using Babylon Native to illustrate various scenarios
C++
8
star
27

UrlLib

UrlLib is a cross-platform C++ library that utilizes platform-specific implementations for URL-related functionality
C++
7
star
28

Demos

A repository of Babylon.js Demos
TypeScript
5
star
29

asset-host-template

5
star
30

havok

The Havok Physics plugin runtime files (wasm and js)
TypeScript
5
star
31

Documentation-search-engine

Website used to store documentation search engine
JavaScript
3
star
32

SpectorJSWebsite

Website for https://github.com/BabylonJS/Spector.js
JavaScript
3
star
33

CMakeExtensions

Helper functions for CMake
CMake
2
star
34

SnippetServerReference

JavaScript
1
star
35

AndroidExtensions

AndroidExtensions is a C++ utility library for Android development
C++
1
star