Skip to content

Changing texture url prop does not change the image used in texture #356

@nene

Description

@nene

Created a playground example with a toggle button that switches between two URL-s:

https://brianzinn.github.io/react-babylonjs/playground?snippetId=CTqBHrbd

But the image used by the texture is not updating.

This possibly happens because setting the url prop of a Texture does nothing. Instead one needs to call updateURL().

When I update the playground example with a code that calls updateURL() inside an effect, it works:

function MyMaterial({url}: {url: string}) {
  const ref = useRef<StandardMaterial>(null);

  useEffect(() => {
    if (ref.current) {
      ref.current.diffuseTexture.updateURL(url);
    }
  }, [url]);

  return (
    <standardMaterial ref={ref} name="mat">
      <texture url={url} />
    </standardMaterial>
  )
}

PS. I tried copying the whole code from playground to here as well, but for some reason the copy functionality doesn't quite work there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions