UNPKG

@awayjs/graphics

Version:
78 lines (77 loc) 3.11 kB
import { TextureAtlas } from './TextureAtlas'; var MaterialManager = /** @class */ (function () { function MaterialManager() { } MaterialManager.getMaterialForColor = function (color, alpha) { if (alpha === void 0) { alpha = 1; } if (color == 0) { color = 0x000001; } if (color == 0xFF8100) { alpha = 1; } //alpha=0.5; var texObj; if (!MaterialManager.materialClass) { throw ('no materialClass registered on MaterialManager!'); } if (MaterialManager._useTextureAtlasForColors) { texObj = TextureAtlas.getTextureForColor(color, alpha); if (MaterialManager._colorMaterials[texObj.bitmap.id]) { texObj.material = MaterialManager._colorMaterials[texObj.bitmap.id]; return texObj; } var newmat_1 = new MaterialManager.materialClass(texObj.bitmap); newmat_1.alphaBlending = true; newmat_1.useColorTransform = true; newmat_1.bothSides = true; MaterialManager._colorMaterials[texObj.bitmap.id] = newmat_1; texObj.material = newmat_1; return texObj; } texObj = {}; var colorstr = color + '_' + Math.round(alpha * 100).toString(); if (MaterialManager._colorMaterials[colorstr]) { texObj.material = MaterialManager._colorMaterials[colorstr]; return texObj; } var newmat = new MaterialManager.materialClass(color, alpha); newmat.alphaBlending = true; newmat.useColorTransform = true; newmat.bothSides = true; texObj.material = newmat; MaterialManager._colorMaterials[colorstr] = newmat; return texObj; }; MaterialManager.getMaterialForGradient = function (gradient) { if (!MaterialManager.materialClass) { throw ('no materialClass registered on MaterialManager!'); } var texObj = TextureAtlas.getTextureForGradient(gradient); // alpha=0.5; var lookupstr = texObj.bitmap.id.toString() + gradient.type.toString(); if (MaterialManager._textureMaterials[lookupstr]) { texObj.material = MaterialManager._textureMaterials[lookupstr]; return texObj; } var newmat = new MaterialManager.materialClass(texObj.bitmap); newmat.useColorTransform = true; newmat.alphaBlending = true; newmat.bothSides = true; MaterialManager._textureMaterials[lookupstr] = newmat; texObj.material = newmat; return texObj; }; MaterialManager.getMaterialForBitmap = function (bitmap) { var newmat = new MaterialManager.materialClass(bitmap); newmat.alphaBlending = true; newmat.useColorTransform = true; newmat.bothSides = true; return newmat; }; MaterialManager._colorMaterials = {}; MaterialManager._textureMaterials = {}; MaterialManager._useTextureAtlasForColors = true; return MaterialManager; }()); export { MaterialManager };