npm 中文文档 npm 中文文档
指南
npmjs.com (opens new window)
指南
npmjs.com (opens new window)
  • 快速入门

    • npm 是什么?
    • npm 安装和更新
    • npm 防止权限错误
    • npm package.json 文件
    • npm 安装包
    • npm 更新包
    • npm 卸载包
    • npm 创建 Node.js 模块
    • npm 发布和更新包
    • npm 使用语义化版本
    • npm 使用 Dist-tags 标记包
    • npm 包和模块的了解
  • 命令行
  • 配置 npm

SpectorJS


Summary


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

Spector is a tool aimed at WebGLdevelopers 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 listwith their associated visual statesand context information.

Build Status

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

Table of Content


Why
Browser extension
Use as a Module
Webpack sample

Use as a Script Reference
CDN
From the repository
Node_Modules
How To Reference

Basic usage
Custom data
Available APIs
Build Locally
Contribute
ChangeLog
Learn WebGl

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:

Chrome
Firefox

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:

  1. ``` sh
  2. npm install spectorjs

  3. ```

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:

  1. ``` sh
  2. mkdir sample
  3. cd sample
  4. npm init
  5. npm install webpack --save-dev
  6. npm install spectorjs --save-dev

  7. ```

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:

  1. ``` js
  2. var SPECTOR = require("spectorjs");

  3. var spector = new SPECTOR.Spector();
  4. spector.displayUI();
  5. ```

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

  1. ``` html
  2. <html>
  3.     <head>
  4.     </head>
  5.     <body>
  6.         <script type="text/javascript" src="bundle.js" charset="utf-8"></script>
  7.     </body>
  8. </html>
  9. ```

Now your application is ready. Go back to your command line and bundle the javascript file:

  1. ``` sh
  2. webpack entry.js bundle.js

  3. ```

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:

  1. ``` html
  2. <script type="text/javascript" src="https://spectorcdn.babylonjs.com/spector.bundle.js"></script>
  3. ```

Basic Usage


Back to top

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

  1. ``` js
  2. var spector = new SPECTOR.Spector();
  3. ```

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

  1. ``` js
  2. spector.displayUI();
  3. ```

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

  1. ``` js
  2. spector.onCapture.add((capture) => {
  3.     // Do something with capture.
  4.     var myEvent = new CustomEvent("SpectorOnCaptureEvent", { detail: { captureString: JSON.stringify(capture) } });
  5.     document.dispatchEvent(myEvent);
  6. });

  7. var canvas = document.getElementById("renderCanvas");
  8. spector.captureCanvas(canvas);
  9. ```

Another api you can rely upon is:

  1. ``` js
  2. spector.spyCanvases();
  3. ```

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_Metadatato your WebGLObjects.

  1. ``` js
  2. var cubeVerticesColorBuffer = gl.createBuffer();
  3. cubeVerticesColorBuffer.__SPECTOR_Metadata = { name: "cubeVerticesColorBuffer" };
  4. ```

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.
Last Updated: 2023-05-15 10:22:02