Skip to content

Get and Set texture transform#4209

Merged
diegoteran merged 10 commits intomasterfrom
texture
May 4, 2023
Merged

Get and Set texture transform#4209
diegoteran merged 10 commits intomasterfrom
texture

Conversation

@diegoteran
Copy link
Collaborator

* Adds feature #3368
* Adds modelviewer.dev example
@diegoteran diegoteran requested a review from elalish April 10, 2023 22:46
@diegoteran diegoteran requested a review from elalish April 28, 2023 20:48
await waitForEvent(element, 'load');

// Transform the textures.
const sampler = element.model?.materials[0].pbrMetallicRoughness['baseColorTexture'].texture?.sampler;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In tests you can use ! liberally, since if you're wrong, the test will fail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you won't have to keep doing it over and over down below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You marked this as resolved, but I don't think you made the change?

@diegoteran diegoteran requested a review from elalish May 3, 2023 20:34
Copy link
Contributor

@elalish elalish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, just some coding style left.

@diegoteran diegoteran requested a review from elalish May 3, 2023 21:23
Copy link
Contributor

@elalish elalish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed some things last time.

await waitForEvent(element, 'load');

// Transform the textures.
const sampler = element.model?.materials[0].pbrMetallicRoughness['baseColorTexture'].texture?.sampler;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You marked this as resolved, but I don't think you made the change?

<p>Scale: <span id="texture-scale"></span></p>
<input type="range" min="0.5" max="1.5" value="1" step="0.01" id="scaleSlider">
<p>Offset</p>
<input type="range" min="0.5" max="1.5" value="1" step="0.01" id="offsetSlider">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check alt text and ranges - e.g. offset should start at 0, rotation to go to pi, etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of using 3.14 as PI here?

const material = modelViewerTexture2.model.materials[0];

let rotationDisplay = document.querySelector('#texture-rotation');
let scaleDisplay = document.querySelector('#texture-scale');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer const to let.

private[$setProperty]<P extends 'minFilter'|'magFilter'|'wrapS'|'wrapT'>(
property: P, value: MinFilter|MagFilter|WrapMode) {
setRotation(rotation: number|null): void {
if(!rotation) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer == null for null checks, since truthiness can be surprising.

setWrapS(mode: WrapMode): void;
setWrapT(mode: WrapMode): void;
setRotation(rotation: number|null): void;
setScale(scale: Vector2|null): void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to define Vector2 in the docs.

scaleDisplay.textContent = scaleSlider.value;

// Texture wrap is often used as REPEAT.
material.pbrMetallicRoughness['baseColorTexture'].texture.sampler.setWrapS(10497); //WrapMode.Repeat
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if this is still necessary with the textureCube (since this is the glTF default already).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does work without it, but might be a good idea to leave it as an example

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's important for the examples to be as simple as possible, and enum numbers like that are confusing. We can answer something like this in a discussion if it comes up.

x: offsetSlider.value,
y: -offsetSlider.value
};
material.pbrMetallicRoughness['baseColorTexture'].texture.sampler.setOffset(offset);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's save this sampler as a const up above so we can simplify these example functions.

@diegoteran diegoteran requested a review from elalish May 3, 2023 22:59
Copy link
Contributor

@elalish elalish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@diegoteran diegoteran merged commit 3345a0a into master May 4, 2023
JL-Vidinoti pushed a commit to vidinoti/model-viewer that referenced this pull request Apr 22, 2024
* Get and Set texture transform

* Adds feature google#3368
* Adds modelviewer.dev example

* Texture Transform in Sampler

* constructor fix

* Sampler API working

Missing automated test

* Add test

* Document and clean gltf file.

* Revoke url from test

* Remove test.only

* Fix coding style.

* Clean index and test file
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.

2 participants