@combos-fun/plugin-renderer-3d 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # @combos-fun/plugin-renderer-3d
2
+
3
+ @combos-fun/plugin-renderer-3d — part of the Combos Fun engine monorepo.
4
+
5
+ Keywords: `three.js`, `3d`, `rendering`, `webgl`, `renderer-base`, `scene`.
6
+
7
+ ## Documentation
8
+
9
+ - Per-package agent / developer notes: [`agent-skill.md`](./agent-skill.md)
10
+ - Machine-readable manifest: [`combos-plugin.json`](./combos-plugin.json)
11
+ (validated against `schemas/combos-plugin.schema.json` in the repo
12
+ root)
13
+ - Entry skill (single source of truth for AI agents working with this
14
+ monorepo): `skills/combos-engine-development/SKILL.md`
15
+
16
+ When consumed from npm, the manifest and agent notes are exposed as
17
+ stable subpaths:
18
+
19
+ ```ts
20
+ import manifest from '@combos-fun/plugin-renderer-3d/plugin-manifest';
21
+ // or fetch the markdown directly:
22
+ // require.resolve('@combos-fun/plugin-renderer-3d/agent-skill')
23
+ ```
24
+
25
+ ## License
26
+
27
+ Internal workspace package, part of the Combos Fun engine monorepo.
package/agent-skill.md ADDED
@@ -0,0 +1,138 @@
1
+ # `@combos-fun/plugin-renderer-3d` — Agent notes
2
+
3
+ 3D rendering foundation for Combos Fun. Wraps Three.js (`three` ^0.172) and exposes `Renderer3DSystem`, the `Renderer3D` base class, and a `ThreeContext` that owns the Three.js scene / camera / lights / WebGL renderer / `Clock` / `GLTFLoader`.
4
+
5
+ ## When to read
6
+
7
+ Read for any 3D rendering task: setting up the canvas, blank-3D-canvas debugging, custom 3D renderer plugins, async asset loading. All `plugin-renderer-3d-*` sub-plugins assume this file is already loaded.
8
+
9
+ ## Public API
10
+
11
+ ```ts
12
+ import {
13
+ Renderer3DSystem,
14
+ Renderer3D,
15
+ Renderer3DManager,
16
+ ThreeContext,
17
+ } from '@combos-fun/plugin-renderer-3d';
18
+ ```
19
+
20
+ ### `Renderer3DSystem`
21
+
22
+ `systemName = 'Renderer3DSystem'`. Init params:
23
+
24
+ | Field | Type | Default |
25
+ |-------|------|---------|
26
+ | `canvas` | `HTMLCanvasElement?` | — |
27
+ | `container` | `HTMLElement?` | — |
28
+ | `width` | `number` | `750` |
29
+ | `height` | `number` | `1000` |
30
+ | `antialias` | `boolean` | `true` |
31
+ | `backgroundColor` | `number` | `0x000000` |
32
+ | `backgroundAlpha` | `number` | `1` |
33
+
34
+ Either `canvas` or `container` must be provided.
35
+
36
+ ### Built-in scene defaults
37
+
38
+ `ThreeContext` automatically creates:
39
+
40
+ - `PerspectiveCamera` (FOV 75, z=5)
41
+ - `AmbientLight` (`0xffffff`, intensity `0.6`)
42
+ - `DirectionalLight` (`0xffffff`, intensity `0.8`, position `(5, 10, 7.5)`)
43
+ - `WebGLRenderer`, `Clock`, `GLTFLoader`
44
+
45
+ There are **no separate camera or light plugins** — these come for free.
46
+
47
+ ### `Renderer3D` base class
48
+
49
+ Extend this for any custom 3D rendering plugin:
50
+
51
+ ```ts
52
+ class MyRenderer3D extends Renderer3D {
53
+ init() {
54
+ this.rendererSystem = this.game.getSystem(Renderer3DSystem);
55
+ this.rendererSystem.rendererManager.register(this);
56
+ }
57
+ componentChanged(changed) {
58
+ const scene = this.threeContext.scene;
59
+ /* create / update / dispose THREE.Object3D under scene */
60
+ }
61
+ rendererUpdate(gameObject) {
62
+ /* per-frame sync */
63
+ }
64
+ }
65
+ ```
66
+
67
+ ### Async loading pattern
68
+
69
+ For 3D plugins that load assets (`Img3D`, `Model3D`, etc.) use the inherited helpers to drop stale work when a component is removed mid-load:
70
+
71
+ ```ts
72
+ const asyncId = this.increaseAsyncId(gameObject.id);
73
+ const data = await loadSomething();
74
+ if (!this.validateAsyncId(gameObject.id, asyncId)) return; // stale
75
+ /* attach data */
76
+ ```
77
+
78
+ This prevents memory leaks and double-add bugs when the same `GameObject` is re-used quickly.
79
+
80
+ ## Required setup
81
+
82
+ `Renderer3DSystem` **must** be the first system added before any 3D sub-system that calls `getSystem(Renderer3DSystem)` in `init`.
83
+
84
+ ```ts
85
+ new Game({
86
+ systems: [
87
+ new Renderer3DSystem({ canvas, width: 750, height: 1000 }),
88
+ new Graphics3DSystem(),
89
+ new Img3DSystem(),
90
+ // ...other 3D sub-systems, physics, audio
91
+ ],
92
+ });
93
+ ```
94
+
95
+ ## Runtime behaviour
96
+
97
+ - 3D Component fields use **direct URL strings** for `resource`
98
+ (unlike 2D which uses engine resource names).
99
+ - `ThreeContext` owns the render loop. `Renderer3D` subclasses register
100
+ with `rendererManager` and are driven each frame.
101
+ - Three.js `Object3D`s should always be attached to `this.threeContext.scene`,
102
+ not directly to the renderer.
103
+
104
+ ## Common pitfalls
105
+
106
+ | Symptom | Fix |
107
+ |---------|-----|
108
+ | Blank canvas | Add `Renderer3DSystem`; ensure `autoStart: true` or call `game.start()` |
109
+ | Nothing draws | Add the matching 3D sub-system (`Graphics3DSystem`, `GLBSystem`, etc.) before adding components |
110
+ | Object loaded but not visible | Object likely loaded at origin — adjust `position*` fields, or check camera distance (default `z=5`) |
111
+ | `getSystem` undefined | Use class reference `game.getSystem(Renderer3DSystem)` |
112
+ | Memory leak after fast remove | Use `increaseAsyncId` / `validateAsyncId` to drop stale async work |
113
+ | CORS errors loading 3D assets | Host on same origin or CORS-enabled CDN |
114
+
115
+ ## Minimal example
116
+
117
+ ```ts
118
+ import { Game } from '@combos-fun/engine';
119
+ import { Renderer3DSystem } from '@combos-fun/plugin-renderer-3d';
120
+
121
+ new Game({
122
+ systems: [
123
+ new Renderer3DSystem({
124
+ canvas: document.querySelector('#canvas')!,
125
+ width: 750,
126
+ height: 1000,
127
+ }),
128
+ ],
129
+ });
130
+ ```
131
+
132
+ This alone shows an empty 3D scene with default lighting. Add `Graphics3DSystem` etc. and matching components to render anything.
133
+
134
+ ## Verification
135
+
136
+ - `pnpm --filter @combos-fun/plugin-renderer-3d run build`
137
+ - Run a 3D example app and check the browser console for Three.js / WebGL
138
+ errors and missing assets.
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@combos-fun/plugin-renderer-3d",
3
+ "pluginId": "renderer-3d",
4
+ "category": "rendering",
5
+ "dimension": "3d",
6
+ "isCore": false,
7
+ "keywords": ["three.js", "3d", "rendering", "webgl", "renderer-base", "scene"],
8
+ "agentSkill": "./agent-skill.md",
9
+ "requires": ["@combos-fun/engine", "@combos-fun/inspector-decorator"],
10
+ "exports": [
11
+ "Renderer3DSystem",
12
+ "Renderer3D",
13
+ "Renderer3DManager",
14
+ "ThreeContext"
15
+ ]
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@combos-fun/plugin-renderer-3d",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "main": "index.js",
5
5
  "module": "dist/plugin-renderer-3d.esm.js",
6
6
  "bundle": "CombosFun.plugin.renderer.3d",
@@ -8,12 +8,26 @@
8
8
  "types": "dist/plugin-renderer-3d.d.ts",
9
9
  "files": [
10
10
  "index.js",
11
- "dist"
11
+ "dist",
12
+ "agent-skill.md",
13
+ "combos-plugin.json"
12
14
  ],
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/plugin-renderer-3d.esm.js",
18
+ "require": "./index.js",
19
+ "types": "./dist/plugin-renderer-3d.d.ts"
20
+ },
21
+ "./plugin-manifest": "./combos-plugin.json",
22
+ "./agent-skill": "./agent-skill.md"
23
+ },
24
+ "combos": {
25
+ "pluginManifest": "./combos-plugin.json"
26
+ },
13
27
  "dependencies": {
14
28
  "three": "^0.172.0",
15
- "@combos-fun/engine": "0.0.6",
16
- "@combos-fun/inspector-decorator": "0.0.6"
29
+ "@combos-fun/engine": "0.0.8",
30
+ "@combos-fun/inspector-decorator": "0.0.8"
17
31
  },
18
32
  "scripts": {
19
33
  "build": "node ../../scripts/build-package.mjs"