Feature request: create texture object without any callbacks when data is in memory

Description of the problem

Since the texture object store the texture information in the .image property, we have to use callback function even the image data is already in the memory like the following:

  var imageDataInBase64 = '.........';
  var image = new Image();
  image.src = `data:image/png;base64' + imageDataInBase64;
  var texture = new THREE.Texture();
  texture.image = image;
  image.onload = function() {
    texture.needsUpdate = true;
  };

It will be very convenient if we can construct a texture object directly and synchronously without any callbacks when the image data is already in the memory. (IMHO, It’s also good to de-couple the logic of loading data and using data from the software engineering perspective.)

By the way, there are many cases when a texture image data is already there in the memory, such as:

  1. The image data is generated by code in the memory;
  2. The image data is loaded from a local database/disk when in Electron/NW.js applications.
Three.js version
  • Dev
  • [X ] r87
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS
Hardware Requirements (graphics card, VR Device, …)

Author: Fantashit

1 thought on “Feature request: create texture object without any callbacks when data is in memory

  1. What @mrdoob wrote works in my environment.

    I don’t think that is guaranteed. You have to be careful not to set the needsUpdate flag too early, in the event that render() is called before the image loads.

    var image = new Image();
    image.src = 'data:image/png;base64' + imageDataInBase64;
    var texture = new THREE.Texture( image );
    image.onload = function() {
        texture.needsUpdate = true;
    };

Comments are closed.