def __init__(self, world, resourceLoader, blockModels, maxLOD=0, overrideMaxSize=None): """ Important members: textureData: RGBA Texture Data as a numpy array. texCoordsByName: Dictionary of texture coordinates. Usable for textures loaded using the extraTextures argument or from block definitions. Maps "texture_name" -> (left, top, right, bottom) :param world: :type world: mceditlib.worldeditor.WorldEditor :param resourceLoader: :type resourceLoader: mcedit2.resourceloader.ResourceLoader :param blockModels: :type blockModels: mcedit2.rendering.blockmodels.BlockModels :param maxLOD: Adds wrapped borders to each texture to allow mipmapping at this level of detail :type maxLOD: int :param overrideMaxSize: Override the maximum texture size - ONLY use for testing TextureAtlas without creating a GL context. :type overrideMaxSize: int or None :return: :rtype: TextureAtlas """ self.overrideMaxSize = overrideMaxSize self.blockModels = blockModels self.blocktypes = world.blocktypes self._filename = world.filename self._resourceLoader = resourceLoader self._lightTexture = None self._terrainTexture = None self._maxLOD = maxLOD names = set() self._rawTextures = rawTextures = [] assert "MCEDIT_UNKNOWN" in blockModels.getTextureNames() for filename in blockModels.getTextureNames(): if filename in names: continue try: f = self._openImageStream(filename) rawTextures.append((filename, ) + loadPNGData(f.read())) names.add(filename) log.debug("Loaded texture %s", filename) except ResourceNotFound as e: log.error("Could not load texture %s: %r", filename, e) except Exception as e: log.exception("%s while loading texture '%s', skipping...", e, filename) rawSize = sum(a.nbytes for (n, w, h, a) in rawTextures) log.info("Preloaded %d textures for world %s (%i kB)", len(self._rawTextures), util.displayName(self._filename), rawSize / 1024)
def __init__(self, world, resourceLoader, blockModels, maxLOD=0, overrideMaxSize=None): """ Important members: textureData: RGBA Texture Data as a numpy array. texCoordsByName: Dictionary of texture coordinates. Usable for textures loaded using the extraTextures argument or from block definitions. Maps "texture_name" -> (left, top, right, bottom) :param world: :type world: mceditlib.worldeditor.WorldEditor :param resourceLoader: :type resourceLoader: mcedit2.resourceloader.ResourceLoader :param blockModels: :type blockModels: mcedit2.rendering.blockmodels.BlockModels :param maxLOD: Adds wrapped borders to each texture to allow mipmapping at this level of detail :type maxLOD: int :param overrideMaxSize: Override the maximum texture size - ONLY use for testing TextureAtlas without creating a GL context. :type overrideMaxSize: int or None :return: :rtype: TextureAtlas """ self.overrideMaxSize = overrideMaxSize self.blockModels = blockModels self.blocktypes = world.blocktypes self._filename = world.filename self._resourceLoader = resourceLoader self._lightTexture = None self._terrainTexture = None self._maxLOD = maxLOD names = set() self._rawTextures = rawTextures = [] assert "MCEDIT_UNKNOWN" in blockModels.getTextureNames() for filename in blockModels.getTextureNames(): if filename in names: continue try: f = self._openImageStream(filename) rawTextures.append((filename,) + loadPNGData(f.read())) names.add(filename) log.debug("Loaded texture %s", filename) except ResourceNotFound as e: log.error("Could not load texture %s: %r", filename, e) except Exception as e: log.exception("%s while loading texture '%s', skipping...", e, filename) rawSize = sum(a.nbytes for (n, w, h, a) in rawTextures) log.info("Preloaded %d textures for world %s (%i kB)", len(self._rawTextures), util.displayName(self._filename), rawSize/1024)
def getModelTexture(self, texturePath): if texturePath in self.modelTextures: return self.modelTextures[texturePath] try: w, h, rgba = loadPNGData(self.textureAtlas.resourceLoader.openStream(texturePath).read()) except Exception as e: log.exception("Model texture %s could not be loaded", texturePath) else: modelTex = Texture(image=rgba[::-1], width=w, height=h) self.modelTextures[texturePath] = modelTex return modelTex
def getModelTexture(self, texturePath): if texturePath in self.modelTextures: return self.modelTextures[texturePath] try: w, h, rgba = loadPNGData( self.textureAtlas.resourceLoader.openStream( texturePath).read()) except Exception as e: log.exception("Model texture %s could not be loaded", texturePath) else: modelTex = Texture(image=rgba[::-1], width=w, height=h) self.modelTextures[texturePath] = modelTex return modelTex