@triforge/compositor-core 0.1.0 → 0.1.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompositorOutput.d.ts","sourceRoot":"","sources":["../../src/core/CompositorOutput.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAAE,KAAK,EAAE,MAAM,EAE7B,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"CompositorOutput.d.ts","sourceRoot":"","sources":["../../src/core/CompositorOutput.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAAE,KAAK,EAAE,MAAM,EAE7B,MAAM,OAAO,CAAA;AAUd,OAAO,KAAK,EAAE,QAAQ,EAAgB,MAAM,eAAe,CAAA;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAW,wBAAwB,CAAA;AAEpE,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,OAAO,CAAC,EAAG,iBAAiB,CAAA;IAC5B,QAAQ,EAAG,aAAa,CAAA;IACxB,KAAK,EAAM,KAAK,CAAA;IAChB,MAAM,EAAK,MAAM,CAAA;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,gBAAgB;IAC3B,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAA;IAEnC,OAAO,CAAC,SAAS,CAAe;IAChC,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,SAAS,CAA4B;IAC7C,OAAO,CAAC,SAAS,CAAS;gBAEd,IAAI,EAAE,uBAAuB;IAOzC,yDAAyD;IACzD,GAAG,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI;IAMzB,4DAA4D;IAC5D,MAAM,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI;IAM5B,wDAAwD;IACxD,IAAI,MAAM,IAAI,SAAS,QAAQ,EAAE,CAAwB;IAEzD,sDAAsD;IACtD,IAAI,UAAU,IAAI,OAAO,CAA0B;IAEnD;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAc9B;;;;OAIG;IACH,MAAM,IAAI,IAAI;IAQd,+DAA+D;IAC/D,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAK5C,OAAO,IAAI,IAAI;IAQf,OAAO,CAAC,aAAa;YA+CP,cAAc;CAiD7B"}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { Vector2, WebGLRenderTarget, LinearFilter, RGBAFormat, HalfFloatType, } from 'three';
|
|
2
|
+
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
|
|
3
|
+
import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass.js';
|
|
4
|
+
import { OutputPass } from 'three/examples/jsm/postprocessing/OutputPass.js';
|
|
5
|
+
import { ShaderPass } from 'three/examples/jsm/postprocessing/ShaderPass.js';
|
|
6
|
+
import { UnrealBloomPass } from 'three/examples/jsm/postprocessing/UnrealBloomPass.js';
|
|
7
|
+
import { FilmPass } from 'three/examples/jsm/postprocessing/FilmPass.js';
|
|
8
|
+
import { BokehPass } from 'three/examples/jsm/postprocessing/BokehPass.js';
|
|
9
|
+
import { SSAOPass } from 'three/examples/jsm/postprocessing/SSAOPass.js';
|
|
10
|
+
import { SSRPass } from 'three/examples/jsm/postprocessing/SSRPass.js';
|
|
2
11
|
/**
|
|
3
12
|
* CompositorOutput — terminal node of the compositor graph.
|
|
4
13
|
*
|
|
@@ -60,7 +69,7 @@ export class CompositorOutput {
|
|
|
60
69
|
this._composer = await this._compilePmndrs();
|
|
61
70
|
}
|
|
62
71
|
else {
|
|
63
|
-
this._composer =
|
|
72
|
+
this._composer = this._compileThree();
|
|
64
73
|
}
|
|
65
74
|
this._compiled = true;
|
|
66
75
|
}
|
|
@@ -88,31 +97,18 @@ export class CompositorOutput {
|
|
|
88
97
|
this._compiled = false;
|
|
89
98
|
}
|
|
90
99
|
// ── Three.js backend ──────────────────────────────────────────────────────
|
|
91
|
-
|
|
92
|
-
// Dynamically import three/addons so this package has no hard dependency
|
|
93
|
-
// on a specific addons path — works with CDN importmap and npm alike.
|
|
94
|
-
let EC;
|
|
95
|
-
let RenderPass;
|
|
96
|
-
let OutputPass;
|
|
97
|
-
try {
|
|
98
|
-
const [ecMod, rpMod, opMod] = await Promise.all([
|
|
99
|
-
import('three/addons/postprocessing/EffectComposer.js'),
|
|
100
|
-
import('three/addons/postprocessing/RenderPass.js'),
|
|
101
|
-
import('three/addons/postprocessing/OutputPass.js'),
|
|
102
|
-
]);
|
|
103
|
-
EC = ecMod['EffectComposer'];
|
|
104
|
-
RenderPass = rpMod['RenderPass'];
|
|
105
|
-
OutputPass = opMod['OutputPass'];
|
|
106
|
-
}
|
|
107
|
-
catch {
|
|
108
|
-
throw new Error('@st-compositor-core: Could not load three/addons postprocessing modules.\n' +
|
|
109
|
-
'Make sure "three/addons/" is in your importmap or install three with examples/jsm.\n' +
|
|
110
|
-
'Example importmap entry:\n' +
|
|
111
|
-
' "three/addons/": "https://unpkg.com/three@0.165.0/examples/jsm/"');
|
|
112
|
-
}
|
|
100
|
+
_compileThree() {
|
|
113
101
|
const activePasses = this._passes.filter(p => p.enabled);
|
|
114
|
-
//
|
|
115
|
-
const registry =
|
|
102
|
+
// Registry built from static imports — compatible with Vite, Webpack, Rollup, esbuild
|
|
103
|
+
const registry = {
|
|
104
|
+
ShaderPass,
|
|
105
|
+
UnrealBloomPass,
|
|
106
|
+
FilmPass,
|
|
107
|
+
BokehPass,
|
|
108
|
+
SSAOPass,
|
|
109
|
+
SSRPass,
|
|
110
|
+
RenderPass,
|
|
111
|
+
};
|
|
116
112
|
const size = new Vector2();
|
|
117
113
|
this._renderer.getSize(size);
|
|
118
114
|
const target = new WebGLRenderTarget(size.x, size.y, {
|
|
@@ -121,47 +117,27 @@ export class CompositorOutput {
|
|
|
121
117
|
format: RGBAFormat,
|
|
122
118
|
type: HalfFloatType,
|
|
123
119
|
});
|
|
124
|
-
const composer = new
|
|
120
|
+
const composer = new EffectComposer(this._renderer, target);
|
|
125
121
|
const addPass = (p) => composer.addPass(p);
|
|
126
|
-
// RenderPass first — renders the scene into the first buffer
|
|
127
122
|
addPass(new RenderPass(this._scene, this._camera));
|
|
128
123
|
registry['_renderer'] = this._renderer;
|
|
129
124
|
registry['_scene'] = this._scene;
|
|
130
125
|
registry['_camera'] = this._camera;
|
|
131
|
-
// User passes
|
|
132
126
|
for (const pass of activePasses) {
|
|
133
127
|
const built = pass._buildThree(size.x, size.y, registry);
|
|
134
128
|
if (built !== null)
|
|
135
129
|
addPass(built);
|
|
136
130
|
}
|
|
137
|
-
//
|
|
131
|
+
// Required since Three.js r152 to write to screen correctly
|
|
138
132
|
addPass(new OutputPass());
|
|
139
133
|
return composer;
|
|
140
134
|
}
|
|
141
|
-
async _loadThreePassModules(passes) {
|
|
142
|
-
const registry = {};
|
|
143
|
-
const needed = new Set();
|
|
144
|
-
for (const pass of passes) {
|
|
145
|
-
for (const dep of pass._threePassDeps()) {
|
|
146
|
-
needed.add(dep);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
await Promise.all([...needed].map(async (dep) => {
|
|
150
|
-
try {
|
|
151
|
-
const mod = await import(`three/addons/postprocessing/${dep}.js`);
|
|
152
|
-
Object.assign(registry, mod);
|
|
153
|
-
}
|
|
154
|
-
catch {
|
|
155
|
-
// Pass will throw its own clear error in _buildThree() if dep is missing
|
|
156
|
-
}
|
|
157
|
-
}));
|
|
158
|
-
return registry;
|
|
159
|
-
}
|
|
160
135
|
// ── pmndrs backend ────────────────────────────────────────────────────────
|
|
161
136
|
async _compilePmndrs() {
|
|
162
137
|
let pkg;
|
|
163
138
|
try {
|
|
164
|
-
|
|
139
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
140
|
+
pkg = await Function('m', 'return import(m)')('postprocessing');
|
|
165
141
|
}
|
|
166
142
|
catch {
|
|
167
143
|
throw new Error('@st-compositor-core: backend "pmndrs" requires the "postprocessing" package.\n' +
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@triforge/compositor-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Blender-matched compositor node graph for Three.js — backend-agnostic (three/addons or pmndrs/postprocessing)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -44,5 +44,11 @@
|
|
|
44
44
|
"homepage": "https://github.com/AftabIbrahimKazi/triforge#readme",
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"exports": {
|
|
49
|
+
".": {
|
|
50
|
+
"import": "./dist/index.js",
|
|
51
|
+
"types": "./dist/index.d.ts"
|
|
52
|
+
}
|
|
47
53
|
}
|
|
48
54
|
}
|