# cl0nazepamm/maxjs architecture

> Architecture diagram of the GitHub repository cl0nazepamm/maxjs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cl0nazepamm/maxjs
- Repository: https://github.com/cl0nazepamm/maxjs

## Overview

1. **What this repo is**
   - `max.js` is a hybrid 3ds Max plugin + web renderer.
   - The native side runs inside 3ds Max as a `.gup`/renderer integration, while the UI and real-time scene rendering live in a WebView2-hosted Three.js app.
   - The architecture is centered on keeping 3ds Max as the authoring/source-of-truth environment and mirroring it into a browser-based runtime.

2. **Primary boundary: native plugin vs web runtime**
   - The C++ side in `src/` is the Max integration layer: it reads scene data, handles renderer/ActiveShade behavior, and bridges to the browser.
   - The `web/` side is the runtime/rendering layer: it builds the Three.js scene, applies post-processing, and manages interactive features like HUD, layers, and animation.
   - This split is the most important diagram boundary in the project.

3. **Native integration layer**
   - `src/maxjs_main.cpp` is the plugin entry point.
   - `include/ircinterface.h`, `include/itreesinterface.h`, and the `ty*Ext.h` headers indicate custom interfaces/extensions used to connect to Max scene objects, particles, and volumes.
   - The native layer also exposes feature-specific modules like renderer, lights, material, fog, sky, toon, splat, deform, and audio.

4. **Real-time synchronization path**
   - The sync pipeline is defined by `src/sync_protocol.cpp/.h` and mirrored in `web/js/protocol.js`.
   - The README states this uses a **binary delta protocol over WebView2 shared memory**, so the key data flow is incremental scene changes rather than full scene re-export.
   - This is the core mechanism that keeps the Three.js view responsive to Max edits.

5. **Scene/runtime model**
   - The project uses a **dual-world architecture** described in the docs and README:
     - **Max-owned world**: authoritative scene objects, read-only mirror on the JS side.
     - **JS-authored world**: runtime-owned objects/layers that can be hot-loaded and managed in the web app.
     - **Overlay world**: HUD/UI elements outside the scene graph.
   - This separation matters for ownership, disposal, and persistence boundaries.

6. **Rendering subsystem**
   - The `src/threejs_*.cpp/.h` files are native feature adapters that map Max concepts into Three.js rendering capabilities.
   - Major areas include materials, lighting, fog, sky/environment, toon shading, deformation, splats, audio, and the renderer core.
   - The README shows the renderer supports WebGPU features heavily, especially for post-processing.

7. **Web app composition**
   - `web/index.html` bootstraps the browser-side runtime.
   - `web/js/project_runtime.js` appears to orchestrate startup and scene lifecycle.
   - `web/js/render_layers.js`, `layer_manager.js`, and `jsmod_registry.js` organize how scene/layer content is loaded and managed.
   - `web/vendor/` likely contains Three.js and related dependencies used by the runtime.

8. **Animation and media paths**
   - `web/js/maxjs_animation.js` and `web/js/maxjs_audio.js` handle animated tracks and audio-origin behavior on the JS side.
   - The README indicates the system supports transform, material, geometry, camera, visibility, and vertex-level animation, plus direct audio loading.
   - This suggests animation is not an afterthought; it is a dedicated data stream from Max to the runtime.

9. **Post-processing and visual effects**
   - `web/js/ssgi_fx.js`, `perf_hud.js`, and `VolumeRenderer.js` point to a postfx-heavy runtime.
   - The README explicitly lists SSGI, SSR, GTAO, motion blur, TRAA, bloom, DOF, toon outline, contact shadows, and retro/CRT/pixel effects.
   - These effects are applied in the web renderer, not in the native plugin, so the browser-side graphics stack is a major architectural pillar.

10. **Export/snapshot and persistence**
   - The README describes a WIP snapshot/export path that turns a scene into a standalone HTML site with assets, hierarchy, animation, lights, environment, splats, and layers.
   - That implies a second output mode besides live sync: packaging the mirrored runtime into a portable web artifact.
   - Layer persistence and resource disposal tracking are part of this export/runtime boundary.

11. **Build and deployment model**
   - The repo uses CMake and builds a Windows plugin targeting Visual Studio 2022 / the 3ds Max 2026 SDK.
   - WebView2 is a required runtime dependency set up by `setup_webview2.bat`.
   - Deployment is plugin-based: the compiled Max extension is copied into Max’s plugins folder and loaded by the host application.

12. **How to draw the architecture**
   - Draw 3ds Max on the left as the authoritative scene source.
   - Draw a native C++ bridge layer in the middle for scene extraction, sync protocol, and renderer integration.
   - Draw WebView2 as the transport/hosting boundary.
   - Draw the web runtime on the right: protocol decoding, runtime state, layer manager, animation/audio, Three.js renderer, and post-processing.
   - Add a separate ownership box for JS-authored layers/overlay UI to distinguish them from mirrored Max scene content.

Main entry points: [`src/threejs_renderer.cpp`](https://github.com/cl0nazepamm/maxjs/blob/master/src/threejs_renderer.cpp) (Renderer core), [`src/maxjs_main.cpp`](https://github.com/cl0nazepamm/maxjs/blob/master/src/maxjs_main.cpp) (Plugin entry), [`web/js/project_runtime.js`](https://github.com/cl0nazepamm/maxjs/blob/master/web/js/project_runtime.js) (Project runtime), [`web/js/render_layers.js`](https://github.com/cl0nazepamm/maxjs/blob/master/web/js/render_layers.js) (Render layers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_max["3ds Max"]
  node_max_host["3ds Max<br/>authoring host"]
end

subgraph group_native["Native bridge"]
  node_plugin_entry["Plugin entry<br/>gup entry<br/>[maxjs_main.cpp]"]
  node_sync_protocol_cpp["Sync protocol<br/>delta codec<br/>[sync_protocol.cpp]"]
  node_sync_protocol_h["Sync API<br/>protocol header<br/>[sync_protocol.h]"]
  node_renderer_core["Renderer core<br/>render bridge"]
  node_material_adapter["Materials<br/>feature adapter"]
  node_light_adapter["Lights<br/>feature adapter<br/>[threejs_lights.cpp]"]
  node_fog_adapter["Fog<br/>feature adapter<br/>[threejs_fog.cpp]"]
  node_sky_adapter["Sky<br/>feature adapter<br/>[threejs_sky.cpp]"]
  node_toon_adapter["Toon<br/>feature adapter<br/>[threejs_toon.cpp]"]
  node_splat_adapter["Splats<br/>feature adapter<br/>[threejs_splat.cpp]"]
  node_deform_adapter["Deform<br/>feature adapter<br/>[threejs_deform.cpp]"]
  node_audio_adapter["Audio<br/>feature adapter<br/>[threejs_audio.cpp]"]
  node_irc_iface["IRC iface<br/>max interface<br/>[ircinterface.h]"]
  node_trees_iface["Trees iface<br/>max interface<br/>[itreesinterface.h]"]
  node_particle_ext["Particle ext<br/>max extension"]
  node_volume_ext["Volume ext<br/>max extension"]
end

subgraph group_web["Web runtime"]
  node_webview2["WebView2<br/>host runtime"]
  node_index_html["Bootstrap<br/>html entry<br/>[index.html]"]
  node_project_runtime["Project runtime<br/>orchestrator<br/>[project_runtime.js]"]
  node_protocol_js["Protocol<br/>delta codec<br/>[protocol.js]"]
  node_layer_manager["Layer manager<br/>runtime state<br/>[layer_manager.js]"]
  node_render_layers["Render layers<br/>scene composer<br/>[render_layers.js]"]
  node_jsmod_registry["Module registry<br/>[jsmod_registry.js]"]
  node_anim_system["Animation<br/>timeline system<br/>[maxjs_animation.js]"]
  node_audio_system["Audio<br/>media system<br/>[maxjs_audio.js]"]
  node_volume_renderer["Volume renderer<br/>effect renderer<br/>[VolumeRenderer.js]"]
  node_ssgi_fx["Post FX<br/>effects stack<br/>[ssgi_fx.js]"]
end

subgraph group_overlay["JS-owned world"]
  node_perf_hud["HUD<br/>overlay ui<br/>[perf_hud.js]"]
end

node_max_host -->|"hosts"| node_plugin_entry
node_plugin_entry -->|"syncs via"| node_sync_protocol_cpp
node_sync_protocol_cpp -->|"mirrors"| node_protocol_js
node_plugin_entry -->|"drives"| node_renderer_core
node_plugin_entry -->|"uses"| node_irc_iface
node_plugin_entry -->|"uses"| node_trees_iface
node_plugin_entry -->|"extends"| node_particle_ext
node_plugin_entry -->|"extends"| node_volume_ext
node_renderer_core -->|"adapts"| node_material_adapter
node_renderer_core -->|"adapts"| node_light_adapter
node_renderer_core -->|"adapts"| node_fog_adapter
node_renderer_core -->|"adapts"| node_sky_adapter
node_renderer_core -->|"adapts"| node_toon_adapter
node_renderer_core -->|"adapts"| node_splat_adapter
node_renderer_core -->|"adapts"| node_deform_adapter
node_renderer_core -->|"adapts"| node_audio_adapter
node_webview2 -->|"hosts"| node_index_html
node_index_html -->|"boots"| node_project_runtime
node_project_runtime -->|"decodes"| node_protocol_js
node_project_runtime -->|"coordinates"| node_layer_manager
node_layer_manager -->|"builds"| node_render_layers
node_layer_manager -->|"registers"| node_jsmod_registry
node_render_layers -->|"uses"| node_anim_system
node_render_layers -->|"uses"| node_audio_system
node_render_layers -->|"renders"| node_volume_renderer
node_render_layers -->|"post-processes"| node_ssgi_fx
node_project_runtime -->|"overlays"| node_perf_hud
node_project_runtime -->|"runs in"| node_webview2
node_sync_protocol_cpp -->|"transports"| node_webview2
node_layer_manager -.->|"separates"| node_perf_hud

click node_plugin_entry "https://github.com/cl0nazepamm/maxjs/blob/master/src/maxjs_main.cpp"
click node_sync_protocol_cpp "https://github.com/cl0nazepamm/maxjs/blob/master/src/sync_protocol.cpp"
click node_sync_protocol_h "https://github.com/cl0nazepamm/maxjs/blob/master/src/sync_protocol.h"
click node_renderer_core "https://github.com/cl0nazepamm/maxjs/blob/master/src/threejs_renderer.cpp"
click node_material_adapter "https://github.com/cl0nazepamm/maxjs/blob/master/src/threejs_material.cpp"
click node_light_adapter "https://github.com/cl0nazepamm/maxjs/blob/master/src/threejs_lights.cpp"
click node_fog_adapter "https://github.com/cl0nazepamm/maxjs/blob/master/src/threejs_fog.cpp"
click node_sky_adapter "https://github.com/cl0nazepamm/maxjs/blob/master/src/threejs_sky.cpp"
click node_toon_adapter "https://github.com/cl0nazepamm/maxjs/blob/master/src/threejs_toon.cpp"
click node_splat_adapter "https://github.com/cl0nazepamm/maxjs/blob/master/src/threejs_splat.cpp"
click node_deform_adapter "https://github.com/cl0nazepamm/maxjs/blob/master/src/threejs_deform.cpp"
click node_audio_adapter "https://github.com/cl0nazepamm/maxjs/blob/master/src/threejs_audio.cpp"
click node_irc_iface "https://github.com/cl0nazepamm/maxjs/blob/master/include/ircinterface.h"
click node_trees_iface "https://github.com/cl0nazepamm/maxjs/blob/master/include/itreesinterface.h"
click node_particle_ext "https://github.com/cl0nazepamm/maxjs/blob/master/include/tyParticleObjectExt.h"
click node_volume_ext "https://github.com/cl0nazepamm/maxjs/blob/master/include/tyVolumeObjectExt.h"
click node_index_html "https://github.com/cl0nazepamm/maxjs/blob/master/web/index.html"
click node_project_runtime "https://github.com/cl0nazepamm/maxjs/blob/master/web/js/project_runtime.js"
click node_protocol_js "https://github.com/cl0nazepamm/maxjs/blob/master/web/js/protocol.js"
click node_layer_manager "https://github.com/cl0nazepamm/maxjs/blob/master/web/js/layer_manager.js"
click node_render_layers "https://github.com/cl0nazepamm/maxjs/blob/master/web/js/render_layers.js"
click node_jsmod_registry "https://github.com/cl0nazepamm/maxjs/blob/master/web/js/jsmod_registry.js"
click node_anim_system "https://github.com/cl0nazepamm/maxjs/blob/master/web/js/maxjs_animation.js"
click node_audio_system "https://github.com/cl0nazepamm/maxjs/blob/master/web/js/maxjs_audio.js"
click node_volume_renderer "https://github.com/cl0nazepamm/maxjs/blob/master/web/js/VolumeRenderer.js"
click node_ssgi_fx "https://github.com/cl0nazepamm/maxjs/blob/master/web/js/ssgi_fx.js"
click node_perf_hud "https://github.com/cl0nazepamm/maxjs/blob/master/web/js/perf_hud.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_max_host toneBlue
class node_plugin_entry,node_sync_protocol_cpp,node_sync_protocol_h,node_renderer_core,node_material_adapter,node_light_adapter,node_fog_adapter,node_sky_adapter,node_toon_adapter,node_splat_adapter,node_deform_adapter,node_audio_adapter,node_irc_iface,node_trees_iface,node_particle_ext,node_volume_ext toneAmber
class node_webview2,node_index_html,node_project_runtime,node_protocol_js,node_layer_manager,node_render_layers,node_jsmod_registry,node_anim_system,node_audio_system,node_volume_renderer,node_ssgi_fx toneMint
class node_perf_hud toneRose
```

## Components

### 3ds Max

Authoritative scene source and host environment

- **3ds Max**: authoring host · Authoritative scene and plugin host environment

### Native bridge

C++ plugin, sync, and renderer adapters inside Max

- [Plugin entry](https://github.com/cl0nazepamm/maxjs/blob/master/src/maxjs_main.cpp): gup entry · Native plugin bootstrap and host integration · `src/maxjs_main.cpp`
- [Sync protocol](https://github.com/cl0nazepamm/maxjs/blob/master/src/sync_protocol.cpp): delta codec · Binary delta scene sync on the native side · `src/sync_protocol.cpp`
- [Sync API](https://github.com/cl0nazepamm/maxjs/blob/master/src/sync_protocol.h): protocol header · Shared protocol definitions for scene mirroring · `src/sync_protocol.h`
- [Renderer core](https://github.com/cl0nazepamm/maxjs/blob/master/src/threejs_renderer.cpp): render bridge · Native renderer integration and host-facing render control · `src/threejs_renderer.cpp`
- [Materials](https://github.com/cl0nazepamm/maxjs/blob/master/src/threejs_material.cpp): feature adapter · Native mapping for material data and behavior · `src/threejs_material.cpp`
- [Lights](https://github.com/cl0nazepamm/maxjs/blob/master/src/threejs_lights.cpp): feature adapter · Native mapping for light data and behavior · `src/threejs_lights.cpp`
- [Fog](https://github.com/cl0nazepamm/maxjs/blob/master/src/threejs_fog.cpp): feature adapter · Native mapping for fog and atmosphere state · `src/threejs_fog.cpp`
- [Sky](https://github.com/cl0nazepamm/maxjs/blob/master/src/threejs_sky.cpp): feature adapter · Native mapping for environment and sky state · `src/threejs_sky.cpp`
- [Toon](https://github.com/cl0nazepamm/maxjs/blob/master/src/threejs_toon.cpp): feature adapter · Native mapping for stylized shading and outlines · `src/threejs_toon.cpp`
- [Splats](https://github.com/cl0nazepamm/maxjs/blob/master/src/threejs_splat.cpp): feature adapter · Native mapping for splat/point-style rendering · `src/threejs_splat.cpp`
- [Deform](https://github.com/cl0nazepamm/maxjs/blob/master/src/threejs_deform.cpp): feature adapter · Native deformation and geometry adaptation bridge · `src/threejs_deform.cpp`
- [Audio](https://github.com/cl0nazepamm/maxjs/blob/master/src/threejs_audio.cpp): feature adapter · Native audio integration and data bridge · `src/threejs_audio.cpp`
- [IRC iface](https://github.com/cl0nazepamm/maxjs/blob/master/include/ircinterface.h): max interface · Custom interface for scene/object integration · `include/ircinterface.h`
- [Trees iface](https://github.com/cl0nazepamm/maxjs/blob/master/include/itreesinterface.h): max interface · Custom interface for tree/scene traversal integration · `include/itreesinterface.h`
- [Particle ext](https://github.com/cl0nazepamm/maxjs/blob/master/include/tyParticleObjectExt.h): max extension · Particle object extension used by the plugin · `include/tyParticleObjectExt.h`
- [Volume ext](https://github.com/cl0nazepamm/maxjs/blob/master/include/tyVolumeObjectExt.h): max extension · Volume object extension used by the plugin · `include/tyVolumeObjectExt.h`

### Web runtime

Browser-hosted Three.js runtime and effects

- **WebView2**: host runtime · Embedded browser boundary used for the web renderer
- [Bootstrap](https://github.com/cl0nazepamm/maxjs/blob/master/web/index.html): html entry · Web runtime entry point and page shell · `web/index.html`
- [Project runtime](https://github.com/cl0nazepamm/maxjs/blob/master/web/js/project_runtime.js): orchestrator · Startup, scene lifecycle, and runtime coordination · `web/js/project_runtime.js`
- [Protocol](https://github.com/cl0nazepamm/maxjs/blob/master/web/js/protocol.js): delta codec · JS-side mirror of the binary sync protocol · `web/js/protocol.js`
- [Layer manager](https://github.com/cl0nazepamm/maxjs/blob/master/web/js/layer_manager.js): runtime state · Owns runtime layers and scene organization · `web/js/layer_manager.js`
- [Render layers](https://github.com/cl0nazepamm/maxjs/blob/master/web/js/render_layers.js): scene composer · Builds and updates renderable layer content · `web/js/render_layers.js`
- [Module registry](https://github.com/cl0nazepamm/maxjs/blob/master/web/js/jsmod_registry.js): registry · Registers hot-loaded JS modules and runtime components · `web/js/jsmod_registry.js`
- [Animation](https://github.com/cl0nazepamm/maxjs/blob/master/web/js/maxjs_animation.js): timeline system · Animated track ingestion and playback behavior · `web/js/maxjs_animation.js`
- [Audio](https://github.com/cl0nazepamm/maxjs/blob/master/web/js/maxjs_audio.js): media system · Runtime-side audio loading and playback behavior · `web/js/maxjs_audio.js`
- [Volume renderer](https://github.com/cl0nazepamm/maxjs/blob/master/web/js/VolumeRenderer.js): effect renderer · Specialized volumetric rendering support · `web/js/VolumeRenderer.js`
- [Post FX](https://github.com/cl0nazepamm/maxjs/blob/master/web/js/ssgi_fx.js): effects stack · Screen-space and post-processing effects pipeline · `web/js/ssgi_fx.js`

### JS-owned world

Runtime-owned layers and overlay/UI content

- [HUD](https://github.com/cl0nazepamm/maxjs/blob/master/web/js/perf_hud.js): overlay ui · Performance and runtime overlay UI · `web/js/perf_hud.js`

## Connections

- 3ds Max → Plugin entry: hosts · 3ds Max loads the plugin entry point
- Plugin entry → Sync protocol: syncs via · Native side serializes incremental scene changes
- Sync protocol → Protocol: mirrors · Shared protocol is decoded in the web runtime
- Plugin entry → Renderer core: drives · Plugin controls renderer integration and presentation
- Plugin entry → IRC iface: uses · Native integration relies on custom scene interfaces
- Plugin entry → Trees iface: uses · Native integration relies on traversal interfaces
- Plugin entry → Particle ext: extends · Particle object behavior is exposed through an extension
- Plugin entry → Volume ext: extends · Volume object behavior is exposed through an extension
- Renderer core → Materials: adapts · Renderer maps Max materials into web rendering state
- Renderer core → Lights: adapts · Renderer maps light data into web rendering state
- Renderer core → Fog: adapts · Renderer maps fog and atmosphere into web rendering state
- Renderer core → Sky: adapts · Renderer maps environment and sky into web rendering state
- Renderer core → Toon: adapts · Renderer maps stylized shading features
- Renderer core → Splats: adapts · Renderer maps splat rendering features
- Renderer core → Deform: adapts · Renderer maps deformation-related scene data
- Renderer core → Audio: adapts · Renderer and runtime coordinate audio-related state
- WebView2 → Bootstrap: hosts · Embedded browser loads the web application
- Bootstrap → Project runtime: boots · HTML bootstraps the runtime orchestrator
- Project runtime → Protocol: decodes · Runtime consumes incremental scene deltas
- Project runtime → Layer manager: coordinates · Startup wires runtime ownership and layer state
- Layer manager → Render layers: builds · Layer manager composes renderable scene layers
- Layer manager → Module registry: registers · Runtime modules are tracked for hot-loading and reuse
- Render layers → Animation: uses · Renderable content consumes animation state
- Render layers → Audio: uses · Renderable content can reference audio behavior
- Render layers → Volume renderer: renders · Volume content is handled by a dedicated renderer
- Render layers → Post FX: post-processes · Scene output flows through the effects stack
- Project runtime → HUD: overlays · Runtime exposes HUD and diagnostic overlay UI
- Project runtime → WebView2: runs in · Web runtime is hosted inside the embedded browser boundary
- Sync protocol → WebView2: transports · Binary delta data moves across the WebView2 shared-memory boundary
- Layer manager → HUD: separates · Overlay/UI is kept distinct from scene-owned layers
