Exemplo n.º 1
0
 //regenerate all the fields we couldn't deserialize automatically
 public void OnAfterDeserialize()
 {
     alphaMasks.Clear();
     for (int i = 0; i < _alphaMasksKeys.Count; i++)
     {
         MATERIAL_SLOT slot = _alphaMasksKeys[i];
         Texture2D     tex  = _alphaMasksVals[i];
         alphaMasks[slot] = tex;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the Material in the specified MATERIAL_SLOT
        /// </summary>
        public Material GetActiveMaterialInSlot(MATERIAL_SLOT querySlot)
        {
            SkinnedMeshRenderer smr = GetSkinnedMeshRenderer();

            /*
             * //this causes a problem at runtime where all the mats are wrong
             * Material[] materials;
             * if (Application.isPlaying)
             * {
             *  materials = smr.materials;
             * } else
             * {
             *  materials = smr.sharedMaterials;
             * }
             */
            Material[] materials = smr.sharedMaterials;

            for (int i = 0; i < materials.Length; i++)
            {
                if (materials[i] == null)
                {
                    continue;
                }
                string        name = materials[i].name.ToLower();
                MATERIAL_SLOT slot = MATERIAL_SLOT.UNKNOWN;

                if (name.Contains("head"))
                {
                    slot = MATERIAL_SLOT.HEAD;
                }
                else if (name.Contains("body"))
                {
                    slot = MATERIAL_SLOT.BODY;
                }
                else if (name.Contains("genesis2"))
                {
                    slot = MATERIAL_SLOT.BODY;
                }
                else if (name.Contains("eyeandlash"))
                {
                    slot = MATERIAL_SLOT.EYEANDLASH;
                }

                if (querySlot.Equals(slot))
                {
                    return(materials[i]);
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Internal method. Updates the clothing textures.
        /// </summary>
        private void updateClothingTextures()
        {
            List <CostumeItem> visible_clothing = clothingModel.GetVisibleItems();

            //Debug.Log("AlphaInjectionManager.updateClothingTextures: " + visible_clothing.Count);
            subAlphaTextures.Clear();

            foreach (CostumeItem clothing_item in visible_clothing)
            {
                // Debug.Log ("VISBLECLOTH:"+clothing_item.name+":"+clothing_item.isVisible);
                CIclothing ci = (CIclothing)clothing_item;

                //LEGACY 1.0 code
                //if (ci.alphaMask != null)
                //	imagesToDraw.Add (ci.alphaMask);

                var matEnum = ci.alphaMasks.GetEnumerator();
                while (matEnum.MoveNext())
                {
                    MATERIAL_SLOT slot = matEnum.Current.Key;
                    if (!subAlphaTextures.ContainsKey(slot))
                    {
                        subAlphaTextures [slot] = new Dictionary <Texture2D, Texture2D> ();
                    }

                    Texture2D tex = ci.alphaMasks[slot];
                    if (tex == null)
                    {
                        continue;
                    }

                    //subAlphaTextures [slot].Add (ci.alphaMasks [slot],ci.alphaMasks [slot]);

                    subAlphaTextures[slot][tex] = tex;
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Draws the texture after a delay triggered by the invalidate function
        /// </summary>
        private void drawTexture()
        {
            dirty = false;
            //Back in 1.0 we only had one material we cared about which was the entire body which was ALWAYS at slot0, now we need to care about HEAD and BODY and order is not guaranteed so we now use a lookup

            //Debug.Log ("REDRAWING ALPHA INJECTION: " + Time.frameCount + " | " + figure.gameObject.transform.parent.name );

            //Material[] materials = figure.GetSkinnedMeshRenderer().sharedMaterials;

            Material[]          materials = GetMaterialsClone();
            SkinnedMeshRenderer smr       = figure.GetSkinnedMeshRenderer();

            for (int i = 0; i < materials.Length; i++)
            {
                if (materials[i] == null || !materials[i].HasProperty("_AlphaTex"))
                {
                    continue;
                }

                MATERIAL_SLOT slot = MATERIAL_SLOT.UNKNOWN;

                Texture2D[] masks = null;
                //TODO this is a TERRIBLE way of checking, we need to build a map
                if (materials[i].name.ToLower().Contains("head"))
                {
                    slot = MATERIAL_SLOT.HEAD;
                }
                else if (materials[i].name.ToLower().Contains("body"))
                {
                    slot = MATERIAL_SLOT.BODY;
                }
                else if (materials[i].name.ToLower().Contains("genesis2"))
                {
                    slot = MATERIAL_SLOT.BODY;
                }

                if (slot == MATERIAL_SLOT.UNKNOWN)
                {
                    //do nothing, we're not sure what slot to process
                    continue;
                }

                if (subAlphaTextures.ContainsKey(slot))
                {
                    masks = new Texture2D[subAlphaTextures[slot].Count];
                    subAlphaTextures[slot].Values.CopyTo(masks, 0);
                }

                RenderTexture rt  = null;
                Texture2D     tex = null;

                if (masks != null && masks.Length > 0)
                {
                    switch (textureMode)
                    {
                    case TEXTURE_MODE.FAST:
                        tex = new Texture2D(1024, 1024, TextureFormat.ARGB32, true);
                        TextureUtilities.OverlayArrayOfTexturesGPU(ref tex, masks);

                        //uncomment if you want to debug the masks
                        //TextureUtilities.OverlayArrayOfTexturesGPU(ref tex, masks,"Unlit/AlphaCombiner",true);
                        temporaryTexture2D.Add(tex);
                        materials[i].SetTexture("_AlphaTex", tex);

                        break;

                    case TEXTURE_MODE.FASTEST:
                        rt = TextureUtilities.OverlayArrayOfTexturesGPU(masks);
                        //rt = TextureUtilities.OverlayArrayOfTexturesGPU(masks, "Unlit/AlphaCombiner", true);
                        temporaryRenderTextures[i] = rt;
                        //UnityEngine.Debug.Log("Assigning rt: " + smr.name + " | " + slot);
                        materials[i].SetTexture("_AlphaTex", rt);
                        break;
                    }
                }
                else
                {
                    //no textures, clear it
                    materials[i].SetTexture("_AlphaTex", null);
                }

                /*
                 * RenderTexture rtOld = materials[i].GetTexture("_AlphaTex") as RenderTexture;
                 * if(rtOld != null)
                 * {
                 *  RenderTexture.Destroy(rtOld);
                 * }
                 */

                //UnityEngine.Debug.Log("Drawing Alpha: " + materials[i].name + " | " + materials.Length + " | " + (masks != null ? masks.Length.ToString() : "null") + " | " + slot + " | " + (tex != null ? "Tex is not null" : "tex is null"));
                //install the texture
                //materials[i].SetTexture("_AlphaTex", tex);
            }

            if (Application.isPlaying)
            {
                smr.materials = materials;
            }
            else
            {
                smr.sharedMaterials = materials;
            }
        }