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

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,148 @@
1
+ # `@combos-fun/plugin-renderer-3d` — Agent notes
2
+
3
+ 3D rendering foundation for Combos Fun. Wraps Three.js (`three` ^0.172) and
4
+ exposes `Renderer3DSystem`, the `Renderer3D` base class, and a
5
+ `ThreeContext` that owns the Three.js scene / camera / lights / WebGL
6
+ renderer / `Clock` / `GLTFLoader`.
7
+
8
+ ## When to read
9
+
10
+ Read for any 3D rendering task: setting up the canvas, blank-3D-canvas
11
+ debugging, custom 3D renderer plugins, async asset loading. All
12
+ `plugin-renderer-3d-*` sub-plugins assume this file is already loaded.
13
+
14
+ ## Public API
15
+
16
+ ```ts
17
+ import {
18
+ Renderer3DSystem,
19
+ Renderer3D,
20
+ Renderer3DManager,
21
+ ThreeContext,
22
+ } from '@combos-fun/plugin-renderer-3d';
23
+ ```
24
+
25
+ ### `Renderer3DSystem`
26
+
27
+ `systemName = 'Renderer3DSystem'`. Init params:
28
+
29
+ | Field | Type | Default |
30
+ |-------|------|---------|
31
+ | `canvas` | `HTMLCanvasElement?` | — |
32
+ | `container` | `HTMLElement?` | — |
33
+ | `width` | `number` | `750` |
34
+ | `height` | `number` | `1000` |
35
+ | `antialias` | `boolean` | `true` |
36
+ | `backgroundColor` | `number` | `0x000000` |
37
+ | `backgroundAlpha` | `number` | `1` |
38
+
39
+ Either `canvas` or `container` must be provided.
40
+
41
+ ### Built-in scene defaults
42
+
43
+ `ThreeContext` automatically creates:
44
+
45
+ - `PerspectiveCamera` (FOV 75, z=5)
46
+ - `AmbientLight` (`0xffffff`, intensity `0.6`)
47
+ - `DirectionalLight` (`0xffffff`, intensity `0.8`, position `(5, 10, 7.5)`)
48
+ - `WebGLRenderer`, `Clock`, `GLTFLoader`
49
+
50
+ There are **no separate camera or light plugins** — these come for free.
51
+
52
+ ### `Renderer3D` base class
53
+
54
+ Extend this for any custom 3D rendering plugin:
55
+
56
+ ```ts
57
+ class MyRenderer3D extends Renderer3D {
58
+ init() {
59
+ this.rendererSystem = this.game.getSystem(Renderer3DSystem);
60
+ this.rendererSystem.rendererManager.register(this);
61
+ }
62
+ componentChanged(changed) {
63
+ const scene = this.threeContext.scene;
64
+ /* create / update / dispose THREE.Object3D under scene */
65
+ }
66
+ rendererUpdate(gameObject) {
67
+ /* per-frame sync */
68
+ }
69
+ }
70
+ ```
71
+
72
+ ### Async loading pattern
73
+
74
+ For 3D plugins that load assets (`Img3D`, `Model3D`, etc.) use the
75
+ inherited helpers to drop stale work when a component is removed
76
+ mid-load:
77
+
78
+ ```ts
79
+ const asyncId = this.increaseAsyncId(gameObject.id);
80
+ const data = await loadSomething();
81
+ if (!this.validateAsyncId(gameObject.id, asyncId)) return; // stale
82
+ /* attach data */
83
+ ```
84
+
85
+ This prevents memory leaks and double-add bugs when the same `GameObject`
86
+ is re-used quickly.
87
+
88
+ ## Required setup
89
+
90
+ `Renderer3DSystem` **must** be the first system added before any 3D
91
+ sub-system that calls `getSystem(Renderer3DSystem)` in `init`.
92
+
93
+ ```ts
94
+ new Game({
95
+ systems: [
96
+ new Renderer3DSystem({ canvas, width: 750, height: 1000 }),
97
+ new Graphics3DSystem(),
98
+ new Img3DSystem(),
99
+ // ...other 3D sub-systems, physics, audio
100
+ ],
101
+ });
102
+ ```
103
+
104
+ ## Runtime behaviour
105
+
106
+ - 3D Component fields use **direct URL strings** for `resource`
107
+ (unlike 2D which uses engine resource names).
108
+ - `ThreeContext` owns the render loop. `Renderer3D` subclasses register
109
+ with `rendererManager` and are driven each frame.
110
+ - Three.js `Object3D`s should always be attached to `this.threeContext.scene`,
111
+ not directly to the renderer.
112
+
113
+ ## Common pitfalls
114
+
115
+ | Symptom | Fix |
116
+ |---------|-----|
117
+ | Blank canvas | Add `Renderer3DSystem`; ensure `autoStart: true` or call `game.start()` |
118
+ | Nothing draws | Add the matching 3D sub-system (`Graphics3DSystem`, `GLBSystem`, etc.) before adding components |
119
+ | Object loaded but not visible | Object likely loaded at origin — adjust `position*` fields, or check camera distance (default `z=5`) |
120
+ | `getSystem` undefined | Use class reference `game.getSystem(Renderer3DSystem)` |
121
+ | Memory leak after fast remove | Use `increaseAsyncId` / `validateAsyncId` to drop stale async work |
122
+ | CORS errors loading 3D assets | Host on same origin or CORS-enabled CDN |
123
+
124
+ ## Minimal example
125
+
126
+ ```ts
127
+ import { Game } from '@combos-fun/engine';
128
+ import { Renderer3DSystem } from '@combos-fun/plugin-renderer-3d';
129
+
130
+ new Game({
131
+ systems: [
132
+ new Renderer3DSystem({
133
+ canvas: document.querySelector('#canvas')!,
134
+ width: 750,
135
+ height: 1000,
136
+ }),
137
+ ],
138
+ });
139
+ ```
140
+
141
+ This alone shows an empty 3D scene with default lighting. Add
142
+ `Graphics3DSystem` etc. and matching components to render anything.
143
+
144
+ ## Verification
145
+
146
+ - `pnpm --filter @combos-fun/plugin-renderer-3d run build`
147
+ - Run a 3D example app and check the browser console for Three.js / WebGL
148
+ 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.7",
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.7",
30
+ "@combos-fun/inspector-decorator": "0.0.7"
17
31
  },
18
32
  "scripts": {
19
33
  "build": "node ../../scripts/build-package.mjs"