Skip to content

Get and Set texture transform#4209

Merged
diegoteran merged 10 commits into
masterfrom
texture
May 4, 2023
Merged

Get and Set texture transform#4209
diegoteran merged 10 commits into
masterfrom
texture

Conversation

@diegoteran

Copy link
Copy Markdown
Collaborator

* Adds feature #3368
* Adds modelviewer.dev example
@diegoteran diegoteran requested a review from elalish April 10, 2023 22:46
Comment thread packages/modelviewer.dev/examples/scenegraph/index.html Outdated
Comment thread packages/modelviewer.dev/examples/scenegraph/index.html Outdated
Comment thread packages/modelviewer.dev/examples/scenegraph/index.html
Comment thread packages/modelviewer.dev/examples/scenegraph/index.html Outdated
Comment thread packages/modelviewer.dev/examples/scenegraph/index.html Outdated
Comment thread packages/modelviewer.dev/data/examples.json
Comment thread packages/model-viewer/src/features/scene-graph/texture-info.ts Outdated
@diegoteran diegoteran requested a review from elalish April 28, 2023 20:48
Comment thread packages/model-viewer/src/features/scene-graph/api.ts Outdated
Comment thread packages/model-viewer/src/features/scene-graph/api.ts Outdated
await waitForEvent(element, 'load');

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

Comment thread packages/model-viewer/src/three-components/gltf-instance/gltf-2.0.ts Outdated
@diegoteran diegoteran requested a review from elalish May 3, 2023 20:34

@elalish elalish left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread packages/model-viewer/src/features/scene-graph/sampler.ts Outdated
Comment thread packages/model-viewer/src/features/scene-graph/sampler.ts Outdated
Comment thread packages/model-viewer/src/features/scene-graph/sampler.ts Outdated
@diegoteran diegoteran requested a review from elalish May 3, 2023 21:23

@elalish elalish left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@elalish elalish left a comment

Copy link
Copy Markdown
Contributor

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