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

VideoTexture: Allow changing image source #25724

Closed
wants to merge 10 commits into from
Closed

Conversation

LeviPesin
Copy link
Contributor

@LeviPesin LeviPesin commented Mar 28, 2023

Related issue: #25530 (comment) #24757 #24769

Description

Don't throw if video is null or undefined. Also allow changing image source.

@github-actions
Copy link

github-actions bot commented Mar 28, 2023

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
633.9 kB (157.1 kB) 634.2 kB (157.1 kB) +299 B

🌳 Bundle size after tree-shaking

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

Filesize dev Filesize PR Diff
425.1 kB (103 kB) 425.1 kB (103 kB) +0 B

@sunag
Copy link
Collaborator

sunag commented Mar 28, 2023

I think that this check should be in something like texture.video = video for example:

class VideoTexture extends Texture {
...
	set video( video = null ) {

		if ( ( video !== undefined ) && ( video !== null ) && ( video.requestVideoFrameCallback !== undefined ) ) {

			video.requestVideoFrameCallback( updateVideo );

		}

	}
...
}

Because it could be added implicitly.

@LeviPesin
Copy link
Contributor Author

I think this should be changed in another PR.

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 28, 2023

Can you please explain why the additional check is now necessary? I'm afraid it is not clear from the comment you have linked in your first post.

@LeviPesin
Copy link
Contributor Author

With this PR something like new VideoTexture() works (similar to new Texture(), new CubeTexture(), new DataTexture()).

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 28, 2023

It seems the PR does not work so far. When I use your version of VideoTexture and update webgl_materials_video such that the video is defined at a later point (via texture.image = video;), the texture stays black. And I think that happens because requestVideoFrameCallback() is never triggered.

@LeviPesin
Copy link
Contributor Author

Updated with @sunag's suggestion that fixes this.

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 29, 2023

Can you please verify what happens when you replace a video after the initial use of a texture? Is requestVideoFrameCallback() still executed for the replaced video?

@LeviPesin
Copy link
Contributor Author

Yes, but I think we have decided that image source shouldn't be changed afterwards -- see #24757, #24768, and #24769. But it can be fixed to allow this if desired.

@LeviPesin LeviPesin changed the title VideoTexture: Don't throw if video is null or undefined VideoTexture: Allow changing image source Mar 29, 2023
@LeviPesin
Copy link
Contributor Author

Updated.

I also moved updateVideo to an outer function (binding to this in the constructor) to make it slightly cleaner.


video.requestVideoFrameCallback( updateVideo );
this._videoFrameCallback();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This line sets needsUpdate to true when the video changes, which is correct behaviour, I think. (It has a side effect that it sets it after first created, but I think this shouldn't break anything?)

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 29, 2023

I have the feeling it is better to make the video to a mandatory parameter. In this case, we can avoid the additional code and keep the class more simple.

@LeviPesin
Copy link
Contributor Author

One of the use cases for using null or undefined instead of a video is:

const video = document.getElementById( 'video' );
const texture = new VideoTexture( video );

Also, all other textures support ommiting image parameter (and all parameters).

@LeviPesin
Copy link
Contributor Author

@mrdoob @Mugen87 So what's your opinion about this PR?

@LeviPesin
Copy link
Contributor Author

LeviPesin commented Apr 20, 2023

@mrdoob @Mugen87 Can this PR be merged, please? It both makes the code easier to understand, more compatible with other textures, and allows a few more use-cases.

@LeviPesin
Copy link
Contributor Author

@mrdoob @Mugen87 What is your opinion about this PR?

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 11, 2023

The resulting complexity isn't satisfying. I think it's best to keep the code as it is.

@Mugen87 Mugen87 closed this Dec 11, 2023
@LeviPesin
Copy link
Contributor Author

Well... But the original version of this PR wasn't that complex and you've requested to make it a bit more? But I don't think even the final version is so much more complex than it was originally...

@LeviPesin
Copy link
Contributor Author

LeviPesin commented Jan 16, 2024

Also, I think multiple users (at least one issue linked in the original post and you can count me too) has requested in the past the possibility to change the VideoTexture source, which this PR also addresses (and which you've also requested above).

@Mugen87 So may the decision to close this PR be reconsidered, please? I still think having this possibility would be better.

Repository owner locked as resolved and limited conversation to collaborators Jan 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants