void Awake() { slotLibrary = GameObject.Find("SlotLibrary").GetComponent<SlotLibrary>(); overlayLibrary = GameObject.Find("OverlayLibrary").GetComponent<OverlayLibrary>(); raceLibrary = GameObject.Find("RaceLibrary").GetComponent<RaceLibrary>(); generator = GameObject.Find("UMAGenerator").GetComponent<UMAGenerator>(); }
void findUMAStuff() { this.slotLibrary = GameObject.Find ("SlotLibrary").GetComponent<SlotLibrary>(); this.generator = GameObject.Find ("UMAGenerator").GetComponent<UMAGenerator>(); this.overlayLibrary = GameObject.Find("OverlayLibrary").GetComponent<OverlayLibrary>(); this.raceLibrary = GameObject.Find ("RaceLibrary").GetComponent<RaceLibrary>(); }
public void Initialize() { if (context == null) { context = UMAContext.FindInstance(); } if (umaData == null) { umaData = GetComponent<UMAData>(); if (umaData == null) { umaData = gameObject.AddComponent<UMAData>(); if (umaGenerator != null && !umaGenerator.gameObject.activeInHierarchy) { Debug.LogError("Invalid UMA Generator on Avatar.", gameObject); Debug.LogError("UMA generators must be active scene objects!", umaGenerator.gameObject); umaGenerator = null; } } } if (umaGenerator != null) { umaData.umaGenerator = umaGenerator; } if (CharacterCreated != null) umaData.CharacterCreated = CharacterCreated; if (CharacterDestroyed != null) umaData.CharacterDestroyed = CharacterDestroyed; if (CharacterUpdated != null) umaData.CharacterUpdated = CharacterUpdated; }
public bool Validate(UMAGeneratorBase generator) { bool valid = true; if ((umaTarget == UMATarget.Humanoid) && (TPose == null)) { Debug.LogError("Humanoid UMA target missing required TPose data!"); valid = false; } return valid; }
public int GetTextureChannelCount(UMAGeneratorBase generator) { int res; if (textureNameList != null && textureNameList.Length > 0) { if (string.IsNullOrEmpty(textureNameList[0])) return 0; return textureNameList.Length; } if (generator != null) { return generator.textureNameList.Length; } return 2; // UMA built in default }
void Awake() { firstBake = true; if (!umaGenerator) { var generatorGO = GameObject.Find("UMAGenerator"); if (generatorGO == null) { return; } umaGenerator = generatorGO.GetComponent <UMAGeneratorBase>(); } if (umaRecipe == null) { umaRecipe = new UMARecipe(); } else { SetupOnAwake(); } }
public bool Validate(UMAGeneratorBase generator) { bool valid = true; if (raceData == null) { Debug.LogError("UMA recipe missing required race!"); valid = false; } else { valid = valid && raceData.Validate(generator); } if (slotDataList == null || slotDataList.Length == 0) { Debug.LogError("UMA recipe slot list is empty!"); valid = false; } int slotDataCount = 0; for (int i = 0; i < slotDataList.Length; i++) { var slotData = slotDataList[i]; if (slotData != null) { slotDataCount++; valid = valid && slotData.Validate(generator); } } if (slotDataCount < 1) { Debug.LogError("UMA recipe slot list contains only null objects!"); valid = false; } return(valid); }
public int GetTextureChannelCount(UMAGeneratorBase generator) { return(asset.GetTextureChannelCount(generator)); }
public override void Prepare(UMAData _umaData, UMAGeneratorBase _umaGenerator) { umaData = _umaData; umaGenerator = _umaGenerator; }
/// <summary> /// Setup data for atlas building. /// </summary> /// <param name="_umaData">UMA data.</param> /// <param name="_umaGenerator">UMA generator.</param> public void ProcessTexture(UMAData _umaData, UMAGeneratorBase _umaGenerator) { umaData = _umaData; umaGenerator = _umaGenerator; if (umaGenerator is UMAGenerator) { fastPath = (umaGenerator as UMAGenerator).fastGeneration; } if (umaData.atlasResolutionScale <= 0) umaData.atlasResolutionScale = 1f; var textureMerge = umaGenerator.textureMerge; textureMerge.RefreshMaterials(); if (textureMerge == null) { if (Debug.isDebugBuild) Debug.LogError("TextureMerge is null!"); // yield return null; } try { for (int atlasIndex = umaData.generatedMaterials.materials.Count - 1; atlasIndex >= 0; atlasIndex--) { var generatedMaterial = umaData.generatedMaterials.materials[atlasIndex]; //Rendering Atlas int moduleCount = 0; //Process all necessary TextureModules for (int i = 0; i < generatedMaterial.materialFragments.Count; i++) { if (!generatedMaterial.materialFragments[i].isRectShared && !generatedMaterial.materialFragments[i].isNoTextures) { moduleCount++; moduleCount = moduleCount + generatedMaterial.materialFragments[i].overlays.Length; } } textureMerge.EnsureCapacity(moduleCount); var slotData = generatedMaterial.materialFragments[0].slotData; resultingTextures = new Texture[slotData.material.channels.Length]; for (int textureType = slotData.material.channels.Length - 1; textureType >= 0; textureType--) { switch (slotData.material.channels[textureType].channelType) { case UMAMaterial.ChannelType.Texture: case UMAMaterial.ChannelType.DiffuseTexture: case UMAMaterial.ChannelType.NormalMap: case UMAMaterial.ChannelType.DetailNormalMap: { bool CopyRTtoTex = SupportsRTToTexture2D && fastPath; textureMerge.Reset(); for (int i = 0; i < generatedMaterial.materialFragments.Count; i++) { textureMerge.SetupModule(generatedMaterial, i, textureType); } //last element for this textureType moduleCount = 0; int width = Mathf.FloorToInt(generatedMaterial.cropResolution.x); int height = Mathf.FloorToInt(generatedMaterial.cropResolution.y); if (width == 0 || height == 0) { continue; } //this should be restricted to >= 1 but 0 was allowed before and projects may have the umaMaterial value serialized to 0. float downSample = (slotData.material.channels[textureType].DownSample == 0) ? 1f : (1f / slotData.material.channels[textureType].DownSample); destinationTexture = new RenderTexture(Mathf.FloorToInt(generatedMaterial.cropResolution.x * umaData.atlasResolutionScale * downSample), Mathf.FloorToInt(generatedMaterial.cropResolution.y * umaData.atlasResolutionScale * downSample), 0, slotData.material.channels[textureType].textureFormat, RenderTextureReadWrite.Linear); destinationTexture.filterMode = FilterMode.Point; destinationTexture.useMipMap = umaGenerator.convertMipMaps && CopyRTtoTex;// && !umaGenerator.convertRenderTexture; destinationTexture.name = slotData.material.name + " Chan " + textureType + " frame: " + Time.frameCount; //Draw all the Rects here Color backgroundColor; UMAMaterial.ChannelType channelType = slotData.material.channels[textureType].channelType; if (slotData.material.MaskWithCurrentColor && (channelType == UMAMaterial.ChannelType.DiffuseTexture || channelType == UMAMaterial.ChannelType.Texture || channelType == UMAMaterial.ChannelType.TintedTexture)) { backgroundColor = slotData.material.maskMultiplier * textureMerge.camBackgroundColor; } else { backgroundColor = UMAMaterial.GetBackgroundColor(slotData.material.channels[textureType].channelType); } textureMerge.DrawAllRects(destinationTexture, width, height, backgroundColor, umaGenerator.SharperFitTextures); //PostProcess textureMerge.PostProcess(destinationTexture, slotData.material.channels[textureType].channelType); if (umaGenerator.convertRenderTexture || slotData.material.channels[textureType].ConvertRenderTexture) { #region Convert Render Textures if(CopyRTtoTex) { // copy the texture with mips to the Texture2D Texture2D tempTexture; tempTexture = new Texture2D(destinationTexture.width, destinationTexture.height, TextureFormat.ARGB32, umaGenerator.convertMipMaps, true); Graphics.CopyTexture(destinationTexture, tempTexture); destinationTexture.Release(); UnityEngine.GameObject.DestroyImmediate(destinationTexture); tempTexture.wrapMode = TextureWrapMode.Repeat; tempTexture.anisoLevel = slotData.material.AnisoLevel; tempTexture.mipMapBias = slotData.material.MipMapBias; tempTexture.filterMode = slotData.material.MatFilterMode; resultingTextures[textureType] = tempTexture as Texture; if(!slotData.material.channels[textureType].NonShaderTexture) { if (generatedMaterial.umaMaterial.translateSRP) { generatedMaterial.material.SetTexture(UMAUtils.TranslatedSRPTextureName(slotData.material.channels[textureType].materialPropertyName), tempTexture); } else { generatedMaterial.material.SetTexture(slotData.material.channels[textureType].materialPropertyName, tempTexture); } } } else { #if USE_ASYNC_GPU_READBACK // Todo: use AsyncGPUReadback to get the texture if possible. // // material == generatedMaterial.material // umaData == ; // slotData == ; // propname == slotData.material.channels[textureType].materialPropertyName // mipcount // mipsconverted[] // Data. //for (int i=0;i< destinationTexture.mipmapCount;i++) //{ // //} #else Texture2D tempTexture; tempTexture = new Texture2D(destinationTexture.width, destinationTexture.height, TextureFormat.ARGB32, umaGenerator.convertMipMaps, true); RenderTexture.active = destinationTexture; tempTexture.ReadPixels(new Rect(0, 0, destinationTexture.width, destinationTexture.height), 0, 0, umaGenerator.convertMipMaps); //resultingTextures[textureType] = tempTexture as Texture; RenderTexture.active = null; destinationTexture.Release(); UnityEngine.GameObject.DestroyImmediate(destinationTexture); // if (!fastPath) yield return 6; //tempTexture = resultingTextures[textureType] as Texture2D; tempTexture.Apply(); tempTexture.wrapMode = TextureWrapMode.Repeat; tempTexture.anisoLevel = slotData.material.AnisoLevel; tempTexture.mipMapBias = slotData.material.MipMapBias; tempTexture.filterMode = slotData.material.MatFilterMode; //if (slotData.asset.material.channels[textureType].Compression != UMAMaterial.CompressionSettings.None) //{ // tempTexture.Compress(slotData.asset.material.channels[textureType].Compression == UMAMaterial.CompressionSettings.HighQuality); // } resultingTextures[textureType] = tempTexture; if(!slotData.material.channels[textureType].NonShaderTexture) { if (generatedMaterial.umaMaterial.translateSRP) { generatedMaterial.material.SetTexture(UMAUtils.TranslatedSRPTextureName(slotData.material.channels[textureType].materialPropertyName), tempTexture); } else { generatedMaterial.material.SetTexture(slotData.material.channels[textureType].materialPropertyName, tempTexture); } generatedMaterial.material.SetTexture(UMAUtils.TranslatedSRPTextureName(slotData.material.channels[textureType].materialPropertyName), tempTexture); } } #endif #endregion } else { destinationTexture.anisoLevel = slotData.material.AnisoLevel; destinationTexture.mipMapBias = slotData.material.MipMapBias; destinationTexture.filterMode = slotData.material.MatFilterMode; destinationTexture.wrapMode = TextureWrapMode.Repeat; resultingTextures[textureType] = destinationTexture; if (!slotData.material.channels[textureType].NonShaderTexture) { if (generatedMaterial.umaMaterial.translateSRP) { generatedMaterial.material.SetTexture(UMAUtils.TranslatedSRPTextureName(slotData.material.channels[textureType].materialPropertyName), destinationTexture); } else { generatedMaterial.material.SetTexture(slotData.material.channels[textureType].materialPropertyName, destinationTexture); } } } break; } case UMAMaterial.ChannelType.MaterialColor: { if (slotData.material.channels[textureType].NonShaderTexture) break; generatedMaterial.material.SetColor(slotData.material.channels[textureType].materialPropertyName, generatedMaterial.materialFragments[0].baseColor); break; } case UMAMaterial.ChannelType.TintedTexture: { for (int i = 0; i < generatedMaterial.materialFragments.Count; i++) { var fragment = generatedMaterial.materialFragments[i]; if (fragment.isRectShared) continue; for (int j = 0; j < fragment.baseOverlay.textureList.Length; j++) { if (fragment.baseOverlay.textureList[j] != null) { if (!slotData.material.channels[textureType].NonShaderTexture) { if (generatedMaterial.umaMaterial.translateSRP) { generatedMaterial.material.SetTexture(UMAUtils.TranslatedSRPTextureName(slotData.material.channels[j].materialPropertyName), fragment.baseOverlay.textureList[j]); } else { generatedMaterial.material.SetTexture(slotData.material.channels[j].materialPropertyName, fragment.baseOverlay.textureList[j]); } } if (j == 0) { generatedMaterial.material.color = fragment.baseColor; } } } foreach (var overlay in fragment.overlays) { if (generatedMaterial.textureNameList == null) for (int j = 0; j < overlay.textureList.Length; j++) { if (overlay.textureList[j] != null) { if (!slotData.material.channels[textureType].NonShaderTexture) { if (generatedMaterial.umaMaterial.translateSRP) { generatedMaterial.material.SetTexture(UMAUtils.TranslatedSRPTextureName(slotData.material.channels[j].materialPropertyName), overlay.textureList[j]); } else { generatedMaterial.material.SetTexture(slotData.material.channels[j].materialPropertyName, overlay.textureList[j]); } } } } } } break; } } } generatedMaterial.resultingAtlasList = resultingTextures; } } finally { RenderTexture.active = null; } }
internal bool Validate(UMAGeneratorBase generator) { bool valid = true; if( meshRenderer != null ) { string[] activeList; if( textureNameList == null || textureNameList.Length == 0 ) { activeList = generator.textureNameList; } else { activeList = textureNameList; } int count = activeList.Length; while (count > 0 && string.IsNullOrEmpty(activeList[count - 1])) { count--; } for (int i = 0; i < overlayList.Count; i++) { var overlayData = overlayList[i]; if (overlayData != null) { if (overlayData.textureList.Length != count) { Debug.LogError(overlayData.overlayName); Debug.LogError(overlayData.textureList.Length); Debug.LogError(slotName); Debug.LogError(count); Debug.LogError(string.Format("Overlay '{0]' only have {1} textures, but it is added to SlotData '{2}' which requires {3} textures.", overlayData.overlayName, overlayData.textureList.Length, slotName, count)); valid = false; } } } } return valid; }
public int GetTextureChannelCount(UMAGeneratorBase generator) { return material.channels.Length; }
/// <summary> /// Setup data for atlas building. /// </summary> /// <param name="_umaData">UMA data.</param> /// <param name="_umaGenerator">UMA generator.</param> public void ProcessTexture(UMAData _umaData, UMAGeneratorBase _umaGenerator) { umaData = _umaData; umaGenerator = _umaGenerator; if (umaGenerator is UMAGenerator) { fastPath = (umaGenerator as UMAGenerator).fastGeneration; } if (umaData.atlasResolutionScale <= 0) { umaData.atlasResolutionScale = 1f; } var textureMerge = umaGenerator.textureMerge; textureMerge.RefreshMaterials(); if (textureMerge == null) { if (Debug.isDebugBuild) { Debug.LogError("TextureMerge is null!"); } // yield return null; } try { for (int atlasIndex = umaData.generatedMaterials.materials.Count - 1; atlasIndex >= 0; atlasIndex--) { var generatedMaterial = umaData.generatedMaterials.materials[atlasIndex]; //Rendering Atlas int moduleCount = 0; //Process all necessary TextureModules for (int i = 0; i < generatedMaterial.materialFragments.Count; i++) { if (!generatedMaterial.materialFragments[i].isRectShared && !generatedMaterial.materialFragments[i].isNoTextures) { moduleCount++; moduleCount = moduleCount + generatedMaterial.materialFragments[i].overlays.Length; } } textureMerge.EnsureCapacity(moduleCount); var slotData = generatedMaterial.materialFragments[0].slotData; resultingTextures = new Texture[slotData.material.channels.Length]; for (int textureType = slotData.material.channels.Length - 1; textureType >= 0; textureType--) { switch (slotData.material.channels[textureType].channelType) { case UMAMaterial.ChannelType.Texture: case UMAMaterial.ChannelType.DiffuseTexture: case UMAMaterial.ChannelType.NormalMap: case UMAMaterial.ChannelType.DetailNormalMap: { textureMerge.Reset(); for (int i = 0; i < generatedMaterial.materialFragments.Count; i++) { textureMerge.SetupModule(generatedMaterial, i, textureType); } //last element for this textureType moduleCount = 0; int width = Mathf.FloorToInt(generatedMaterial.cropResolution.x); int height = Mathf.FloorToInt(generatedMaterial.cropResolution.y); if (width == 0 || height == 0) { continue; } //this should be restricted to >= 1 but 0 was allowed before and projects may have the umaMaterial value serialized to 0. float downSample = (slotData.material.channels[textureType].DownSample == 0) ? 1f : (1f / slotData.material.channels[textureType].DownSample); destinationTexture = new RenderTexture(Mathf.FloorToInt(generatedMaterial.cropResolution.x * umaData.atlasResolutionScale * downSample), Mathf.FloorToInt(generatedMaterial.cropResolution.y * umaData.atlasResolutionScale * downSample), 0, slotData.material.channels[textureType].textureFormat, RenderTextureReadWrite.Linear); destinationTexture.filterMode = FilterMode.Point; destinationTexture.useMipMap = umaGenerator.convertMipMaps && !umaGenerator.convertRenderTexture; destinationTexture.name = slotData.material.name + " Chan " + textureType + " frame: " + Time.frameCount; //Draw all the Rects here Color backgroundColor; UMAMaterial.ChannelType channelType = slotData.material.channels[textureType].channelType; if (slotData.material.MaskWithCurrentColor && (channelType == UMAMaterial.ChannelType.DiffuseTexture || channelType == UMAMaterial.ChannelType.Texture || channelType == UMAMaterial.ChannelType.TintedTexture)) { backgroundColor = slotData.material.maskMultiplier * textureMerge.camBackgroundColor; } else { backgroundColor = UMAMaterial.GetBackgroundColor(slotData.material.channels[textureType].channelType); } textureMerge.DrawAllRects(destinationTexture, width, height, backgroundColor, umaGenerator.SharperFitTextures); //PostProcess textureMerge.PostProcess(destinationTexture, slotData.material.channels[textureType].channelType); if (umaGenerator.convertRenderTexture || slotData.material.channels[textureType].ConvertRenderTexture) { #region Convert Render Textures // if (!fastPath) yield return 25; Texture2D tempTexture; tempTexture = new Texture2D(destinationTexture.width, destinationTexture.height, TextureFormat.ARGB32, umaGenerator.convertMipMaps, true); int xblocks = destinationTexture.width / 512; int yblocks = destinationTexture.height / 512; if (xblocks == 0 || yblocks == 0 || fastPath) { RenderTexture.active = destinationTexture; //Debug.Log("CVT-FP Activated " + destinationTexture.name); tempTexture.ReadPixels(new Rect(0, 0, destinationTexture.width, destinationTexture.height), 0, 0, umaGenerator.convertMipMaps); // Debug.Log("CVT-FP Cleared " + destinationTexture.name); } else { // figures that ReadPixels works differently on OpenGL and DirectX, someday this code will break because Unity fixes this bug! if (IsOpenGL()) { for (int x = 0; x < xblocks; x++) { for (int y = 0; y < yblocks; y++) { RenderTexture.active = destinationTexture; // Debug.Log("CVT-SP OGL Activated " + destinationTexture.name+" "+x+" "+y); tempTexture.ReadPixels(new Rect(x * 512, y * 512, 512, 512), x * 512, y * 512, umaGenerator.convertMipMaps); // Debug.Log("CVT-SP OGL Cleared " + destinationTexture.name + " " + x + " " + y); // yield return 8; } } } else { for (int x = 0; x < xblocks; x++) { for (int y = 0; y < yblocks; y++) { // Debug.Log("CVT-SP NOTOGL Activated " + destinationTexture.name + " " + x + " " + y); RenderTexture.active = destinationTexture; tempTexture.ReadPixels(new Rect(x * 512, destinationTexture.height - 512 - y * 512, 512, 512), x * 512, y * 512, umaGenerator.convertMipMaps); // Debug.Log("CVT-SP NOTOGL Cleared " + destinationTexture.name + " " + x + " " + y); // yield return 8; } } } } resultingTextures[textureType] = tempTexture as Texture; destinationTexture.Release(); UnityEngine.GameObject.DestroyImmediate(destinationTexture); // if (!fastPath) yield return 6; tempTexture = resultingTextures[textureType] as Texture2D; tempTexture.Apply(); tempTexture.wrapMode = TextureWrapMode.Repeat; tempTexture.anisoLevel = slotData.material.AnisoLevel; tempTexture.mipMapBias = slotData.material.MipMapBias; tempTexture.filterMode = slotData.material.MatFilterMode; //if (slotData.asset.material.channels[textureType].Compression != UMAMaterial.CompressionSettings.None) //{ // tempTexture.Compress(slotData.asset.material.channels[textureType].Compression == UMAMaterial.CompressionSettings.HighQuality); // } resultingTextures[textureType] = tempTexture; if (!slotData.material.channels[textureType].NonShaderTexture) { generatedMaterial.material.SetTexture(slotData.material.channels[textureType].materialPropertyName, tempTexture); } #endregion } else { destinationTexture.anisoLevel = slotData.material.AnisoLevel; destinationTexture.mipMapBias = slotData.material.MipMapBias; destinationTexture.filterMode = slotData.material.MatFilterMode; destinationTexture.wrapMode = TextureWrapMode.Repeat; resultingTextures[textureType] = destinationTexture; if (!slotData.material.channels[textureType].NonShaderTexture) { generatedMaterial.material.SetTexture(slotData.material.channels[textureType].materialPropertyName, destinationTexture); } } break; } case UMAMaterial.ChannelType.MaterialColor: { if (slotData.material.channels[textureType].NonShaderTexture) { break; } generatedMaterial.material.SetColor(slotData.material.channels[textureType].materialPropertyName, generatedMaterial.materialFragments[0].baseColor); break; } case UMAMaterial.ChannelType.TintedTexture: { for (int i = 0; i < generatedMaterial.materialFragments.Count; i++) { var fragment = generatedMaterial.materialFragments[i]; if (fragment.isRectShared) { continue; } for (int j = 0; j < fragment.baseOverlay.textureList.Length; j++) { if (fragment.baseOverlay.textureList[j] != null) { if (!slotData.material.channels[textureType].NonShaderTexture) { generatedMaterial.material.SetTexture(slotData.material.channels[j].materialPropertyName, fragment.baseOverlay.textureList[j]); } if (j == 0) { generatedMaterial.material.color = fragment.baseColor; } } } foreach (var overlay in fragment.overlays) { if (generatedMaterial.textureNameList == null) { for (int j = 0; j < overlay.textureList.Length; j++) { if (overlay.textureList[j] != null) { if (!slotData.material.channels[textureType].NonShaderTexture) { generatedMaterial.material.SetTexture(slotData.material.channels[j].materialPropertyName, overlay.textureList[j]); } } } } } } break; } } } generatedMaterial.resultingAtlasList = resultingTextures; } } finally { RenderTexture.active = null; } }
void init(UMAGeneratorBase generator, [InjectOptional] UMARecipe recipe) { this.umaGenerator = generator; this.umaRecipe = recipe; }
void setupFallbackObjects() { if (generator == null) { generator = GameObject.Find("UMAGenerator").GetComponent<UMAGenerator>(); } if (slotLibrary == null) { slotLibrary = GameObject.Find("SlotLibrary").GetComponent<SlotLibrary>(); } if (overlayLibrary == null) { overlayLibrary = GameObject.Find("OverlayLibrary").GetComponent<OverlayLibrary>(); } if (raceLibrary == null) { raceLibrary = GameObject.Find("RaceLibrary").GetComponent<RaceLibrary>(); } }
public int GetTextureChannelCount(UMAGeneratorBase generator) { return(material.channels.Length); }
public void Prepare(UMAGeneratorBase _umaGenerator, UMAData _umaData, TextureProcessBaseCoroutine textureProcessCoroutine) { umaGenerator = _umaGenerator; umaData = _umaData; this.textureProcessCoroutine = textureProcessCoroutine; }
/// <summary> /// Setup data for atlas building. /// </summary> /// <param name="_umaData">UMA data.</param> /// <param name="_umaGenerator">UMA generator.</param> public override void Prepare(UMAData _umaData, UMAGeneratorBase _umaGenerator) { umaData = _umaData; umaGenerator = _umaGenerator; if (umaData.atlasResolutionScale <= 0) umaData.atlasResolutionScale = 1f; }
public abstract void Prepare(UMAData _umaData, UMAGeneratorBase _umaGenerator);