private bool CalculateRects(UMAData.GeneratedMaterial material) { Rect nullRect = new Rect(0, 0, 0, 0); packTexture.Init(umaGenerator.atlasResolution, umaGenerator.atlasResolution, false); for (int atlasElementIndex = 0; atlasElementIndex < material.materialFragments.Count; atlasElementIndex++) { var tempMaterialDef = material.materialFragments[atlasElementIndex]; if (tempMaterialDef.isRectShared) { continue; } tempMaterialDef.atlasRegion = packTexture.Insert(Mathf.FloorToInt(tempMaterialDef.baseTexture[0].width * material.resolutionScale * tempMaterialDef.slotData.overlayScale), Mathf.FloorToInt(tempMaterialDef.baseTexture[0].height * material.resolutionScale * tempMaterialDef.slotData.overlayScale), MaxRectsBinPack.FreeRectChoiceHeuristic.RectBestLongSideFit); if (tempMaterialDef.atlasRegion == nullRect) { if (umaGenerator.fitAtlas) { Debug.LogWarning("Atlas resolution is too small, Textures will be reduced.", umaData.gameObject); return(false); } else { Debug.LogError("Atlas resolution is too small, not all textures will fit.", umaData.gameObject); } } } return(true); }
private PackSize CalculateRects(UMAData.GeneratedMaterial material, PackSize area) { Rect nullRect = new Rect(0, 0, 0, 0); PackSize lastPackSize = new PackSize(); packTexture.Init(area.Width, area.Height, false); for (int atlasElementIndex = 0; atlasElementIndex < material.materialFragments.Count; atlasElementIndex++) { var tempMaterialDef = material.materialFragments[atlasElementIndex]; if (tempMaterialDef.isRectShared) { continue; } int width = Mathf.FloorToInt(tempMaterialDef.baseOverlay.textureList[0].width * material.resolutionScale.x * tempMaterialDef.slotData.overlayScale); int height = Mathf.FloorToInt(tempMaterialDef.baseOverlay.textureList[0].height * material.resolutionScale.y * tempMaterialDef.slotData.overlayScale); // If either width or height are 0 we will end up with nullRect and potentially loop forever if (width == 0 || height == 0) { tempMaterialDef.atlasRegion = nullRect; continue; } tempMaterialDef.atlasRegion = packTexture.Insert(width, height, MaxRectsBinPack.FreeRectChoiceHeuristic.RectBestLongSideFit); lastPackSize.Width = width; lastPackSize.Height = height; if (tempMaterialDef.atlasRegion == nullRect) { if (umaGenerator.fitAtlas) { //if (Debug.isDebugBuild) // JRRM : re-enable this // Debug.LogWarning("Atlas resolution is too small, Textures will be reduced.", umaData.gameObject); lastPackSize.success = false; return(lastPackSize); } else { if (Debug.isDebugBuild) { Debug.LogError("Atlas resolution is too small, not all textures will fit.", umaData.gameObject); } } } } lastPackSize.success = true; return(lastPackSize); }
private void CalculateRects() { Rect nullRect = new Rect(0, 0, 0, 0); UMAData.AtlasList umaAtlasList = umaData.atlasList; for (int atlasIndex = 0; atlasIndex < umaAtlasList.atlas.Count; atlasIndex++) { umaAtlasList.atlas[atlasIndex].cropResolution = new Vector2(umaGenerator.atlasResolution, umaGenerator.atlasResolution); umaAtlasList.atlas[atlasIndex].resolutionScale = atlasResolutionScale; umaAtlasList.atlas[atlasIndex].mipmap = mipMapAdjust; packTexture.Init(umaGenerator.atlasResolution, umaGenerator.atlasResolution, false); bool textureFit = true; for (int atlasElementIndex = 0; atlasElementIndex < umaAtlasList.atlas[atlasIndex].atlasMaterialDefinitions.Count; atlasElementIndex++) { UMAData.AtlasMaterialDefinition tempMaterialDef = umaAtlasList.atlas[atlasIndex].atlasMaterialDefinitions[atlasElementIndex]; if (tempMaterialDef.atlasRegion == nullRect) { tempMaterialDef.atlasRegion = packTexture.Insert(Mathf.FloorToInt(tempMaterialDef.source.baseTexture[0].width * umaAtlasList.atlas[atlasIndex].resolutionScale * tempMaterialDef.source.slotData.overlayScale), Mathf.FloorToInt(tempMaterialDef.source.baseTexture[0].height * umaAtlasList.atlas[atlasIndex].resolutionScale * tempMaterialDef.source.slotData.overlayScale), MaxRectsBinPack.FreeRectChoiceHeuristic.RectBestLongSideFit); tempMaterialDef.isRectShared = false; umaAtlasList.atlas[atlasIndex].shader = tempMaterialDef.source.materialSample.shader; if (tempMaterialDef.atlasRegion == nullRect) { textureFit = false; if (umaGenerator.fitAtlas) { Debug.LogWarning("Atlas resolution is too small, Textures will be reduced."); } else { Debug.LogError("Atlas resolution is too small, not all textures will fit."); } } for (int atlasElementIndex2 = atlasElementIndex; atlasElementIndex2 < umaAtlasList.atlas[atlasIndex].atlasMaterialDefinitions.Count; atlasElementIndex2++) { if (atlasElementIndex != atlasElementIndex2) { if (tempMaterialDef.source.baseTexture[0] == umaAtlasList.atlas[atlasIndex].atlasMaterialDefinitions[atlasElementIndex2].source.baseTexture[0]) { umaAtlasList.atlas[atlasIndex].atlasMaterialDefinitions[atlasElementIndex2].atlasRegion = tempMaterialDef.atlasRegion; umaAtlasList.atlas[atlasIndex].atlasMaterialDefinitions[atlasElementIndex2].isRectShared = true; } } } } if (!textureFit && umaGenerator.fitAtlas) { //Reset calculation and reduce texture sizes textureFit = true; atlasElementIndex = -1; umaAtlasList.atlas[atlasIndex].resolutionScale = umaAtlasList.atlas[atlasIndex].resolutionScale * 0.5f; umaAtlasList.atlas[atlasIndex].mipmap++; packTexture.Init(umaGenerator.atlasResolution, umaGenerator.atlasResolution, false); for (int atlasElementIndex2 = 0; atlasElementIndex2 < umaAtlasList.atlas[atlasIndex].atlasMaterialDefinitions.Count; atlasElementIndex2++) { umaAtlasList.atlas[atlasIndex].atlasMaterialDefinitions[atlasElementIndex2].atlasRegion = nullRect; } } } } }