get method

Texture? get(
  1. Texture? texture
)

Implementation

Texture? get(Texture? texture) {
  if (texture != null) {
    var mapping = texture.mapping;

    bool isEquirectMap = (mapping == EquirectangularReflectionMapping ||
        mapping == EquirectangularRefractionMapping);
    bool isCubeMap = (mapping == CubeReflectionMapping ||
        mapping == CubeRefractionMapping);

    // equirect/cube map to cubeUV conversion
    if (isEquirectMap || isCubeMap) {
      if (texture.isRenderTargetTexture && texture.needsPMREMUpdate == true) {
        texture.needsPMREMUpdate = false;

        var renderTarget = cubeUVmaps.get(texture);

        pmremGenerator ??= PMREMGenerator(renderer);

        renderTarget = isEquirectMap
            ? pmremGenerator.fromEquirectangular(texture, renderTarget)
            : pmremGenerator.fromCubemap(texture, renderTarget);
        cubeUVmaps.add(key: texture, value: renderTarget);

        return renderTarget.texture;
      } else {
        if (cubeUVmaps.has(texture)) {
          return cubeUVmaps.get(texture).texture;
        } else {
          var image = texture.image;

          if ((isEquirectMap && image != null && image.height > 0) ||
              (isCubeMap && image != null && isCubeTextureComplete(image))) {
            pmremGenerator ??= PMREMGenerator(renderer);

            var renderTarget = isEquirectMap
                ? pmremGenerator.fromEquirectangular(texture)
                : pmremGenerator.fromCubemap(texture);
            cubeUVmaps.add(key: texture, value: renderTarget);

            texture.addEventListener('dispose', onTextureDispose);

            return renderTarget.texture;
          } else {
            // image not yet ready. try the conversion next frame

            return null;
          }
        }
      }
    }
  }

  return texture;
}