|
|
6 mesi fa | |
|---|---|---|
| .. | ||
| icons | 9 mesi fa | |
| panel | 6 mesi fa | |
| README.md | 10 mesi fa | |
| background.js | 6 mesi fa | |
| bridge.js | 6 mesi fa | |
| content-script.js | 7 mesi fa | |
| devtools.js | 10 mesi fa | |
| index.html | 10 mesi fa | |
| manifest.json | 6 mesi fa | |
| screenshot.png | 10 mesi fa | |
This Chrome DevTools extension provides debugging capabilities for Three.js applications. It allows you to inspect scenes, objects, materials, and renderers.
Development Mode:
chrome://extensions/devtools directoryUsage:
The extension follows a standard Chrome DevTools extension architecture:
background.js): Manages the extension lifecycle and communication ports between the panel and content script.devtools.js): Creates the panel when the DevTools window opens.panel/panel.html, panel/panel.js, panel/panel.css): The DevTools panel interface that displays the data.content-script.js): Injected into the web page. Relays messages between the background script and the bridge script.bridge.js): Injected into the page's context by the content script. Directly interacts with the Three.js instance, detects objects, gathers data, and communicates back via the content script.content-script.js injects bridge.js into the page.bridge.js creates the window.__THREE_DEVTOOLS__ global object.panel.js connects to background.js (init) and immediately requests the current state (request-state).background.js relays the state request to content-script.js, which posts it to bridge.js.bridge.js responds by sending back observed renderer data (renderer message) and batched scene data (scene message).window.__THREE_DEVTOOLS__ and sends registration/observation events to the bridge script as objects are created or the library initializes.bridge.js)The bridge acts as the communication layer between the Three.js instance on the page and the DevTools panel:
DevToolsEventTarget) to manage communication readiness and backlog events before the panel connects.Object Tracking:
getObjectData(): Extracts essential data (UUID, type, name, parent, children, etc.) from Three.js objects.devTools.objects) of all observed objects.Initial Observation & Batching:
observe event (via window.__THREE_DEVTOOLS__.dispatchEvent):
'renderer' message.'scene' batch message.State Request Handling:
request-state (on load/reload), the bridge iterates its known objects and sends back the current renderer data ('renderer') and scene data ('scene' batch).Message Handling:
request-state.panel/)The panel UI provides the visual representation of the Three.js objects:
WebGLRenderer instances.init, request-state).window.__THREE_DEVTOOLS__ and uses its dispatchEvent method (sending 'register', 'observe').window.postMessage to send data ('register', 'renderer', 'scene', 'update') to the content script.chrome.runtime.sendMessage to relay messages from the bridge to the background.port.postMessage) to send data to the panel.The extension relies on Three.js having built-in support for DevTools. When Three.js detects the presence of window.__THREE_DEVTOOLS__, it interacts with it, primarily by dispatching events.
The bridge script listens for these events, organizes the data, and provides it to the DevTools panel.
To modify the extension:
devtools directory.chrome://extensions/, find the unpacked extension, and click the reload icon.