Skip to content

Conversation

@mahi656
Copy link

@mahi656 mahi656 commented Nov 8, 2025

Description:
This PR introduces a new utility setMaterialMap.js that addresses issue #31934.

  • The setMaterialMap function is designed to be called whenever assigning a texture to a material's map property, particularly for special cases like VideoTexture, where material.needsUpdate must be set to ensure proper rendering updates.

Changes:

  • Added utils/setMaterialMap.js as a reusable function to safely assign textures to materials.
  • Ensures material.needsUpdate = true automatically when switching from a regular Texture to a VideoTexture (or any dynamic texture), preventing potential rendering issues or crashes.

Usage Example:
Instead of manually doing:

material.map = videoTexture;
material.needsUpdate = true;

@@ -0,0 +1,7 @@
export function setMaterialMap(material, map) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This helper is not ideal since it performs operations which are not always required when setting a map. If you just want to exchange an existing texture there is no need to set needsUpdate to true.

three.js is designed in a way that needsUpdate should be used on app level.

@Mugen87 Mugen87 closed this Nov 9, 2025
@Mugen87 Mugen87 added this to the r182 milestone Nov 9, 2025
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