MB3_TextureCombinerPipeline.TexturePipelineData LoadPipelineData(Material resultMaterial, List <ShaderTextureProperty> texPropertyNames, List <GameObject> objsToMesh, List <Material> allowedMaterialsFilter, List <MB_TexSet> distinctMaterialTextures) { MB3_TextureCombinerPipeline.TexturePipelineData data = new MB3_TextureCombinerPipeline.TexturePipelineData(); data._textureBakeResults = _textureBakeResults; data._atlasPadding = _atlasPadding; if (_packingAlgorithm == MB2_PackingAlgorithmEnum.MeshBakerTexturePacker_Vertical && _useMaxAtlasHeightOverride) { data._maxAtlasHeight = _maxAtlasHeightOverride; data._useMaxAtlasHeightOverride = true; } else { data._maxAtlasHeight = _maxAtlasSize; } if (_packingAlgorithm == MB2_PackingAlgorithmEnum.MeshBakerTexturePacker_Horizontal && _useMaxAtlasWidthOverride) { data._maxAtlasWidth = _maxAtlasWidthOverride; data._useMaxAtlasWidthOverride = true; } else { data._maxAtlasWidth = _maxAtlasSize; } data._saveAtlasesAsAssets = _saveAtlasesAsAssets; data.resultType = _resultType; data._resizePowerOfTwoTextures = _resizePowerOfTwoTextures; data._fixOutOfBoundsUVs = _fixOutOfBoundsUVs; data._maxTilingBakeSize = _maxTilingBakeSize; data._packingAlgorithm = _packingAlgorithm; data._layerTexturePackerFastV2 = _layerTexturePackerFastMesh; data._meshBakerTexturePackerForcePowerOfTwo = _meshBakerTexturePackerForcePowerOfTwo; data._customShaderPropNames = _customShaderPropNames; data._normalizeTexelDensity = _normalizeTexelDensity; data._considerNonTextureProperties = _considerNonTextureProperties; data.doMergeDistinctMaterialTexturesThatWouldExceedAtlasSize = _doMergeDistinctMaterialTexturesThatWouldExceedAtlasSize; data.nonTexturePropertyBlender = new MB3_TextureCombinerNonTextureProperties(LOG_LEVEL, _considerNonTextureProperties); data.resultMaterial = resultMaterial; data.distinctMaterialTextures = distinctMaterialTextures; data.allObjsToMesh = objsToMesh; data.allowedMaterialsFilter = allowedMaterialsFilter; data.texPropertyNames = texPropertyNames; data.colorSpace = MBVersion.GetProjectColorSpace(); return(data); }
/// <summary> /// Creates one texture array per texture property. /// </summary> /// <returns></returns> internal static Texture2DArray[] CreateTextureArraysForResultMaterial(TexturePropertyData texPropertyData, List <ShaderTextureProperty> masterListOfTexProperties, MB_AtlasesAndRects[] resultAtlasesAndRectSlices, bool[] hasTexForProperty, MB3_TextureCombiner combiner, MB2_LogLevel LOG_LEVEL) { Debug.Assert(texPropertyData.sizes.Length == hasTexForProperty.Length); // ASSUMPTION all slices in the same format and the same size, alpha channel and mipMapCount string[] texPropertyNames = resultAtlasesAndRectSlices[0].texPropertyNames; Debug.Assert(texPropertyNames.Length == hasTexForProperty.Length); Texture2DArray[] texArrays = new Texture2DArray[texPropertyNames.Length]; // Each texture property (_MainTex, _Bump, ...) becomes a Texture2DArray for (int propIdx = 0; propIdx < texPropertyNames.Length; propIdx++) { if (!hasTexForProperty[propIdx]) { continue; } string propName = texPropertyNames[propIdx]; int numSlices = resultAtlasesAndRectSlices.Length; int w = (int)texPropertyData.sizes[propIdx].x; int h = (int)texPropertyData.sizes[propIdx].y; int numMips = (int)texPropertyData.numMipMaps[propIdx]; TextureFormat format = texPropertyData.formats[propIdx]; bool doMipMaps = texPropertyData.doMips[propIdx]; Debug.Assert(QualitySettings.desiredColorSpace == QualitySettings.activeColorSpace, "Wanted to use color space " + QualitySettings.desiredColorSpace + " but the activeColorSpace was " + QualitySettings.activeColorSpace + " hardware may not support the desired color space."); bool isLinear = MBVersion.GetProjectColorSpace() == ColorSpace.Linear; { if (IsLinearProperty(masterListOfTexProperties, propName)) { isLinear = true; } else { isLinear = false; } } Texture2DArray texArray = new Texture2DArray(w, h, numSlices, format, doMipMaps, isLinear); if (LOG_LEVEL >= MB2_LogLevel.info) { Debug.LogFormat("Creating Texture2DArray for property: {0} w: {1} h: {2} format: {3} doMips: {4} isLinear: {5}", propName, w, h, format, doMipMaps, isLinear); } for (int sliceIdx = 0; sliceIdx < numSlices; sliceIdx++) { Debug.Assert(resultAtlasesAndRectSlices[sliceIdx].atlases.Length == texPropertyNames.Length); Debug.Assert(resultAtlasesAndRectSlices[sliceIdx].texPropertyNames[propIdx] == propName); Texture2D srcTex = resultAtlasesAndRectSlices[sliceIdx].atlases[propIdx]; if (LOG_LEVEL >= MB2_LogLevel.debug) { Debug.LogFormat("Slice: {0} texture: {1}", sliceIdx, srcTex); } bool isCopy = false; if (srcTex == null) { if (LOG_LEVEL >= MB2_LogLevel.trace) { Debug.LogFormat("Texture is null for slice: {0} creating temporary texture", sliceIdx); } // Slices might not have all textures create a dummy if needed. srcTex = combiner._createTemporaryTexture(propName, w, h, format, doMipMaps, isLinear); } Debug.Assert(srcTex.width == texArray.width, "Source texture is not the same width as the texture array '" + srcTex + " srcWidth:" + srcTex.width + " texArrayWidth:" + texArray.width); Debug.Assert(srcTex.height == texArray.height, "Source texture is not the same height as the texture array " + srcTex + " srcWidth:" + srcTex.height + " texArrayWidth:" + texArray.height); Debug.Assert(srcTex.mipmapCount == numMips, "Source texture does have not the same number of mips as the texture array: " + srcTex + " numMipsTex: " + srcTex.mipmapCount + " numMipsTexArray: " + numMips + " texDims: " + srcTex.width + "x" + srcTex.height); Debug.Assert(srcTex.format == format, "Formats should have been converted before this. Texture: " + srcTex + "Source: " + srcTex.format + " Targ: " + format); for (int mipIdx = 0; mipIdx < numMips; mipIdx++) { Graphics.CopyTexture(srcTex, 0, mipIdx, texArray, sliceIdx, mipIdx); } if (isCopy) { MB_Utility.Destroy(srcTex); } } texArray.Apply(); texArrays[propIdx] = texArray; } return(texArrays); }