Skip to content

Create professional demos and 3D mockups in seconds, directly in your browser

feat: enhance texture handling and renderer settings for improved performance

CristianOlivera1e3cfa73c1a39
diff --git a/lib/perspective3d.ts b/lib/perspective3d.ts
index d447cee..8911762 100644
--- a/lib/perspective3d.ts
+++ b/lib/perspective3d.ts
@@ -31,9 +31,11 @@ function ensureScene(aspect: number): { scene: THREE.Scene; plane: THREE.Mesh }
_offscreen = document.createElement("canvas");
_texture = new THREE.CanvasTexture(_offscreen);
_texture.colorSpace = THREE.SRGBColorSpace;
- _texture.minFilter = THREE.LinearFilter;
+ _texture.generateMipmaps = true;
+ _texture.minFilter = THREE.LinearMipmapLinearFilter;
_texture.magFilter = THREE.LinearFilter;
- _texture.generateMipmaps = false;
+ _texture.wrapS = THREE.ClampToEdgeWrapping;
+ _texture.wrapT = THREE.ClampToEdgeWrapping;
}
if (!_material) {
@@ -77,6 +79,7 @@ export function applyPerspective3D(
if (!_renderer) {
_renderer = buildRenderer();
+ _renderer.setPixelRatio(1);
}
if (_renderer.domElement.width !== w || _renderer.domElement.height !== h) {
_renderer.setSize(w, h, false);
@@ -84,6 +87,10 @@ export function applyPerspective3D(
const { scene, plane } = ensureScene(aspect);
+ if (_texture!.anisotropy < 2) {
+ _texture!.anisotropy = _renderer.capabilities.getMaxAnisotropy();
+ }
+
const off = _offscreen!;
if (off.width !== w || off.height !== h) {
off.width = w;