@combos-fun/plugin-renderer-3d 0.1.21 → 0.1.23
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/agent-skill.md +1 -0
- package/dist/plugin-renderer-3d.cjs.js +62 -11
- package/dist/plugin-renderer-3d.cjs.js.map +1 -1
- package/dist/plugin-renderer-3d.cjs.prod.js +1 -1
- package/dist/plugin-renderer-3d.d.ts +7 -1
- package/dist/plugin-renderer-3d.esm.js +63 -12
- package/dist/plugin-renderer-3d.esm.js.map +1 -1
- package/package.json +3 -3
package/agent-skill.md
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
| Param | Default |
|
|
23
23
|
| --- | --- |
|
|
24
24
|
| `width` / `height` | `750` / `1334` |
|
|
25
|
+
| `adaptivePixelRatio` | `false` |
|
|
25
26
|
| `antialias` | `true` |
|
|
26
27
|
| `backgroundColor` / `backgroundAlpha` | `0x000000` / `1` |
|
|
27
28
|
| `fog` | `false` (object: background color / `8` / `40`) |
|
|
@@ -155,8 +155,10 @@ class ThreeContext {
|
|
|
155
155
|
rendererOpts.alpha = true;
|
|
156
156
|
}
|
|
157
157
|
this.renderer = new three.WebGLRenderer(rendererOpts);
|
|
158
|
-
this.renderer.setPixelRatio(
|
|
159
|
-
this.renderer.setSize(width, height);
|
|
158
|
+
this.renderer.setPixelRatio(1);
|
|
159
|
+
this.renderer.setSize(Math.max(1, Math.round(width * pixelRatio)), Math.max(1, Math.round(height * pixelRatio)), false);
|
|
160
|
+
this.renderer.domElement.style.width = '';
|
|
161
|
+
this.renderer.domElement.style.height = '';
|
|
160
162
|
this.renderer.setClearColor(backgroundColor, backgroundAlpha);
|
|
161
163
|
this.renderer.toneMapping = TONE_MAPPING[params.toneMapping ?? 'aces'] ?? three.ACESFilmicToneMapping;
|
|
162
164
|
this.renderer.toneMappingExposure = params.toneMappingExposure ?? 1;
|
|
@@ -206,8 +208,23 @@ class ThreeContext {
|
|
|
206
208
|
if (!(pixelRatio > 0) || pixelRatio === this.pixelRatio)
|
|
207
209
|
return;
|
|
208
210
|
this.pixelRatio = pixelRatio;
|
|
209
|
-
|
|
210
|
-
|
|
211
|
+
}
|
|
212
|
+
/** Drawing buffer in device pixels. Does not write canvas CSS size. */
|
|
213
|
+
presentBuffer(bufferWidth, bufferHeight) {
|
|
214
|
+
if (!(bufferWidth >= 1) || !(bufferHeight >= 1))
|
|
215
|
+
return;
|
|
216
|
+
this.renderer.setDrawingBufferSize(bufferWidth, bufferHeight, 1);
|
|
217
|
+
const canvas = this.renderer.domElement;
|
|
218
|
+
if (canvas.width !== bufferWidth || canvas.height !== bufferHeight) {
|
|
219
|
+
canvas.width = bufferWidth;
|
|
220
|
+
canvas.height = bufferHeight;
|
|
221
|
+
}
|
|
222
|
+
this.camera.aspect = bufferWidth / bufferHeight;
|
|
223
|
+
this.camera.updateProjectionMatrix();
|
|
224
|
+
if (this.fallbackCamera !== this.camera) {
|
|
225
|
+
this.fallbackCamera.aspect = bufferWidth / bufferHeight;
|
|
226
|
+
this.fallbackCamera.updateProjectionMatrix();
|
|
227
|
+
}
|
|
211
228
|
}
|
|
212
229
|
configureTexture(texture) {
|
|
213
230
|
if (!texture?.isTexture || this.anisotropy <= 1)
|
|
@@ -486,7 +503,7 @@ class ThreeContext {
|
|
|
486
503
|
this.fallbackCamera.aspect = width / height;
|
|
487
504
|
this.fallbackCamera.updateProjectionMatrix();
|
|
488
505
|
}
|
|
489
|
-
this.renderer.setSize(width, height);
|
|
506
|
+
this.renderer.setSize(width, height, false);
|
|
490
507
|
}
|
|
491
508
|
destroy() {
|
|
492
509
|
for (const id of this.models.keys()) {
|
|
@@ -724,13 +741,16 @@ let Renderer3DSystem$1 = class Renderer3DSystem extends engine.System {
|
|
|
724
741
|
this.name = 'Renderer3DSystem';
|
|
725
742
|
this.adaptive = null;
|
|
726
743
|
this.pauseWhenHidden = true;
|
|
744
|
+
this.resolution = 1;
|
|
745
|
+
this.resizeObserver = null;
|
|
727
746
|
}
|
|
728
747
|
static { this.systemName = 'Renderer3DSystem'; }
|
|
729
748
|
init(params) {
|
|
730
749
|
const opts = params || {};
|
|
731
750
|
const width = opts.width || 750;
|
|
732
751
|
const height = opts.height || 1334;
|
|
733
|
-
const quality = engine.resolveRenderQuality(opts, { adaptivePixelRatio:
|
|
752
|
+
const quality = engine.resolveRenderQuality(opts, { adaptivePixelRatio: false });
|
|
753
|
+
this.resolution = quality.pixelRatio;
|
|
734
754
|
this.pauseWhenHidden = quality.pauseWhenHidden;
|
|
735
755
|
this.adaptive = new engine.AdaptivePixelRatio({
|
|
736
756
|
pixelRatio: quality.pixelRatio,
|
|
@@ -758,6 +778,7 @@ let Renderer3DSystem$1 = class Renderer3DSystem extends engine.System {
|
|
|
758
778
|
directionalIntensity: opts.directionalIntensity,
|
|
759
779
|
});
|
|
760
780
|
this.game.canvas = this.threeContext.renderer.domElement;
|
|
781
|
+
this.observeCanvas(this.game.canvas);
|
|
761
782
|
this.rendererManager = new Renderer3DManager({
|
|
762
783
|
game: this.game,
|
|
763
784
|
rendererSystem: this,
|
|
@@ -805,14 +826,44 @@ let Renderer3DSystem$1 = class Renderer3DSystem extends engine.System {
|
|
|
805
826
|
return;
|
|
806
827
|
}
|
|
807
828
|
const next = this.adaptive?.sample(e?.deltaTime ?? 0);
|
|
808
|
-
if (next != null)
|
|
809
|
-
this.
|
|
829
|
+
if (next != null) {
|
|
830
|
+
this.resolution = next;
|
|
831
|
+
this.threeContext.pixelRatio = next;
|
|
832
|
+
this.applyDisplay();
|
|
833
|
+
}
|
|
810
834
|
this.threeContext.update();
|
|
811
835
|
}
|
|
812
|
-
resize(
|
|
813
|
-
this.
|
|
836
|
+
resize(_width, _height) {
|
|
837
|
+
this.applyDisplay();
|
|
838
|
+
}
|
|
839
|
+
observeCanvas(canvas) {
|
|
840
|
+
this.resizeObserver?.disconnect();
|
|
841
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
842
|
+
this.resizeObserver = new ResizeObserver(() => this.applyDisplay());
|
|
843
|
+
this.resizeObserver.observe(canvas);
|
|
844
|
+
}
|
|
845
|
+
this.applyDisplay();
|
|
846
|
+
}
|
|
847
|
+
applyDisplay() {
|
|
848
|
+
const canvas = this.threeContext?.renderer?.domElement;
|
|
849
|
+
if (!canvas || typeof canvas.getBoundingClientRect !== 'function')
|
|
850
|
+
return;
|
|
851
|
+
const box = canvas.getBoundingClientRect();
|
|
852
|
+
const buffer = engine.displayBufferSize(box, this.resolution);
|
|
853
|
+
if (!buffer)
|
|
854
|
+
return;
|
|
855
|
+
const currentW = canvas.width;
|
|
856
|
+
const currentH = canvas.height;
|
|
857
|
+
if (currentW === buffer.bufferWidth && currentH === buffer.bufferHeight) {
|
|
858
|
+
const aspect = buffer.bufferWidth / buffer.bufferHeight;
|
|
859
|
+
if (Math.abs(this.threeContext.camera.aspect - aspect) < 1e-6)
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
this.threeContext.presentBuffer(buffer.bufferWidth, buffer.bufferHeight);
|
|
814
863
|
}
|
|
815
864
|
onDestroy() {
|
|
865
|
+
this.resizeObserver?.disconnect();
|
|
866
|
+
this.resizeObserver = null;
|
|
816
867
|
this.threeContext?.destroy();
|
|
817
868
|
this.threeContext = null;
|
|
818
869
|
}
|
|
@@ -827,7 +878,7 @@ var Renderer3DSystem = Renderer3DSystem$1;
|
|
|
827
878
|
/** Auto-generated by scripts/build-package.mjs — do not edit. */
|
|
828
879
|
Object.assign(Renderer3DSystem, {
|
|
829
880
|
packageName: "@combos-fun/plugin-renderer-3d",
|
|
830
|
-
packageVersion: "0.1.
|
|
881
|
+
packageVersion: "0.1.23",
|
|
831
882
|
});
|
|
832
883
|
|
|
833
884
|
class Renderer3D extends engine.System {
|