Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

texture.objectFit(800/600, "cover") #28512

Closed
wants to merge 1 commit into from
Closed

Conversation

abernier
Copy link
Contributor

@abernier abernier commented May 28, 2024

Description

A utility-method, that partially implements https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit for THREE.Texture

given:

const w = 4
const h = 3
const geometry = new THREE.PlaneGeometry( w, h );
const material = new THREE.MeshBasicMaterial( {color: 0xffff00, side: THREE.DoubleSide} );
const plane = new THREE.Mesh( geometry, material );

const texture = new THREE.TextureLoader().load( "textures/water.jpg" );
material.map = texture

like in CSS, it could be handy to "cover" the plane with the texture:

texture.objectFit(w/h, "cover"); // 👈🏻 THIS

TODO:

  • update doc
  • an example?

@abernier abernier marked this pull request as draft May 28, 2024 12:46
Copy link

github-actions bot commented May 28, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
677.8 kB (168 kB) 678.3 kB (168.2 kB) +538 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Filesize dev Filesize PR Diff
455.8 kB (110.1 kB) 456.4 kB (110.2 kB) +538 B

@abernier abernier changed the title Texture.prototype.objectFit texture.objectFit(800/600, "cover") May 28, 2024
@abernier
Copy link
Contributor Author

Or maybe a TextureUtils function would be more appropriate?

@mrdoob
Copy link
Owner

mrdoob commented May 29, 2024

TextureUtils seems more appropriate yes.

@WestLangley
Copy link
Collaborator

Related: #17199

And a use case: https://threejs.org/examples/webgl_test_wide_gamut.html

@Mugen87
Copy link
Collaborator

Mugen87 commented May 30, 2024

I prefer the more explicit API style of #17199. So how about doing this:

TextureUtils.contain( texture, aspect );
TextureUtils.cover( texture, aspect );
TextureUtils.fill( texture, aspect );

@Mugen87
Copy link
Collaborator

Mugen87 commented Jun 21, 2024

Closing in favor of #28713.

@Mugen87 Mugen87 closed this Jun 21, 2024
@Mugen87 Mugen87 added this to the r166 milestone Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants