Exemplo n.º 1
0
        //private void FireSlotAtlasNotification(UMAData umaData, Material[] materials)
        //{
        //    for (int atlasIndex = 0; atlasIndex < umaData.atlasList.atlas.Count; atlasIndex++)
        //    {
        //        for (int materialDefinitionIndex = 0; materialDefinitionIndex < umaData.atlasList.atlas[atlasIndex].atlasMaterialDefinitions.Count; materialDefinitionIndex++)
        //        {
        //            var materialDefinition = umaData.atlasList.atlas[atlasIndex].atlasMaterialDefinitions[materialDefinitionIndex];
        //            var slotData = materialDefinition.source.slotData;
        //            if (slotData.SlotAtlassed != null)
        //            {
        //                slotData.SlotAtlassed.Invoke(umaData, slotData, materials[atlasIndex], materialDefinition.atlasRegion);
        //            }
        //        }
        //    }
        //    SlotData[] slots = umaData.umaRecipe.slotDataList;
        //    for (int slotIndex = 0; slotIndex < slots.Length; slotIndex++)
        //    {
        //        var slotData = slots[slotIndex];
        //        if (slotData == null) continue;
        //        if (slotData.textureNameList.Length == 1 && string.IsNullOrEmpty(slotData.textureNameList[0]))
        //        {
        //            if (slotData.SlotAtlassed != null)
        //            {
        //                slotData.SlotAtlassed.Invoke(umaData, slotData, materials[atlasIndex], materialDefinition.atlasRegion);
        //            }
        //        }
        //    }
        //}

        protected void BuildCombineInstances()
        {
            SkinnedMeshCombiner.CombineInstance combineInstance;

            for (int materialIndex = 0; materialIndex < umaData.generatedMaterials.materials.Count; materialIndex++)
            {
                var generatedMaterial = umaData.generatedMaterials.materials[materialIndex];
                combinedMaterialList.Add(generatedMaterial.material);

                for (int materialDefinitionIndex = 0; materialDefinitionIndex < generatedMaterial.materialFragments.Count; materialDefinitionIndex++)
                {
                    var materialDefinition = generatedMaterial.materialFragments[materialDefinitionIndex];
                    var slotData           = materialDefinition.slotData;
                    combineInstance                      = new SkinnedMeshCombiner.CombineInstance();
                    combineInstance.meshData             = slotData.asset.meshData;
                    combineInstance.targetSubmeshIndices = new int[combineInstance.meshData.subMeshCount];
                    for (int i = 0; i < combineInstance.meshData.subMeshCount; i++)
                    {
                        combineInstance.targetSubmeshIndices[i] = -1;
                    }
                    combineInstance.targetSubmeshIndices[slotData.asset.subMeshIndex] = materialIndex;
                    combinedMeshList.Add(combineInstance);

                    if (slotData.asset.SlotAtlassed != null)
                    {
                        slotData.asset.SlotAtlassed.Invoke(umaData, slotData, generatedMaterial.material, materialDefinition.atlasRegion);
                    }
                }
            }
        }
        protected void BuildCombineInstances()
        {
            SkinnedMeshCombiner.CombineInstance combineInstance;

            //Since BuildCombineInstances is called within a renderer loop, use a variable to keep track of the materialIndex per renderer
            int rendererMaterialIndex = 0;

            for (int materialIndex = 0; materialIndex < umaData.generatedMaterials.materials.Count; materialIndex++)
            {
                UMARendererAsset rendererAsset = umaData.GetRendererAsset(currentRendererIndex);
                var generatedMaterial          = umaData.generatedMaterials.materials[materialIndex];
                if (generatedMaterial.rendererAsset != rendererAsset)
                {
                    continue;
                }
                combinedMaterialList.Add(generatedMaterial);
                generatedMaterial.materialIndex = materialIndex;

                for (int materialDefinitionIndex = 0; materialDefinitionIndex < generatedMaterial.materialFragments.Count; materialDefinitionIndex++)
                {
                    var materialDefinition = generatedMaterial.materialFragments[materialDefinitionIndex];
                    var slotData           = materialDefinition.slotData;
                    combineInstance          = new SkinnedMeshCombiner.CombineInstance();
                    combineInstance.meshData = slotData.asset.meshData;

                    //New MeshHiding
                    if (slotData.meshHideMask != null)
                    {
                        combineInstance.triangleMask = slotData.meshHideMask;
                    }

                    combineInstance.targetSubmeshIndices = new int[combineInstance.meshData.subMeshCount];
                    for (int i = 0; i < combineInstance.meshData.subMeshCount; i++)
                    {
                        combineInstance.targetSubmeshIndices[i] = -1;
                    }
                    combineInstance.targetSubmeshIndices[slotData.asset.subMeshIndex] = rendererMaterialIndex;
                    combinedMeshList.Add(combineInstance);

                    if (slotData.asset.SlotAtlassed != null)
                    {
                        slotData.asset.SlotAtlassed.Invoke(umaData, slotData, generatedMaterial.material, materialDefinition.atlasRegion);
                    }
                    if (rendererAsset != null && rendererAsset.ClothProperties != null)
                    {
                        clothProperties = rendererAsset.ClothProperties;
                    }
                }
                rendererMaterialIndex++;
            }
        }
Exemplo n.º 3
0
        protected void CombineByShader()
        {
            SkinnedMeshCombiner.CombineInstance combineInstance;

            for (int atlasIndex = 0; atlasIndex < umaData.atlasList.atlas.Count; atlasIndex++)
            {
                combinedMaterialList.Add(umaData.atlasList.atlas[atlasIndex].materialSample);

                for (int materialDefinitionIndex = 0; materialDefinitionIndex < umaData.atlasList.atlas[atlasIndex].atlasMaterialDefinitions.Count; materialDefinitionIndex++)
                {
                    combineInstance          = new SkinnedMeshCombiner.CombineInstance();
                    combineInstance.mesh     = umaData.atlasList.atlas[atlasIndex].atlasMaterialDefinitions[materialDefinitionIndex].source.slotData.meshRenderer.sharedMesh;
                    combineInstance.destMesh = new int[combineInstance.mesh.subMeshCount];
                    for (int i = 0; i < combineInstance.mesh.subMeshCount; i++)
                    {
                        combineInstance.destMesh[i] = -1;
                    }

                    combineInstance.bones = umaData.atlasList.atlas[atlasIndex].atlasMaterialDefinitions[materialDefinitionIndex].source.slotData.meshRenderer.bones;
                    combineInstance.destMesh[umaData.atlasList.atlas[atlasIndex].atlasMaterialDefinitions[materialDefinitionIndex].source.slotData.subMeshIndex] = atlasIndex;
                    combinedMeshList.Add(combineInstance);
                }
            }
        }
Exemplo n.º 4
0
        protected void CombineByMaterial()
        {
            SlotData[] slots         = umaData.umaRecipe.slotDataList;
            bool[]     shareMaterial = new bool[slots.Length];

            SkinnedMeshCombiner.CombineInstance combineInstance;

            int indexCount = 0;

            for (int slotIndex = 0; slotIndex < slots.Length; slotIndex++)
            {
                if (slots[slotIndex] != null)
                {
                    if (!shareMaterial[slotIndex])
                    {
                        combineInstance          = new SkinnedMeshCombiner.CombineInstance();
                        combineInstance.mesh     = slots[slotIndex].meshRenderer.sharedMesh;
                        combineInstance.destMesh = new int[combineInstance.mesh.subMeshCount];
                        for (int i = 0; i < combineInstance.mesh.subMeshCount; i++)
                        {
                            combineInstance.destMesh[i] = -1;
                        }

                        combineInstance.bones = slots[slotIndex].meshRenderer.bones;
                        combineInstance.destMesh[slots[slotIndex].subMeshIndex] = indexCount;
                        combinedMeshList.Add(combineInstance);

                        Material tempMaterial = Instantiate(slots[slotIndex].materialSample) as Material;
                        tempMaterial.name = slots[slotIndex].slotName;
                        for (int textureType = 0; textureType < textureNameList.Length; textureType++)
                        {
                            if (tempMaterial.HasProperty(textureNameList[textureType]))
                            {
                                slots[slotIndex].GetOverlay(0).textureList[textureType].filterMode = FilterMode.Bilinear;
                                tempMaterial.SetTexture(textureNameList[textureType], slots[slotIndex].GetOverlay(0).textureList[textureType]);
                            }
                        }
                        combinedMaterialList.Add(tempMaterial);


                        shareMaterial[slotIndex] = true;

                        for (int slotIndex2 = slotIndex; slotIndex2 < slots.Length; slotIndex2++)
                        {
                            if (slots[slotIndex2] != null)
                            {
                                if (slotIndex2 != slotIndex && !shareMaterial[slotIndex2])
                                {
                                    if (slots[slotIndex].GetOverlay(0).textureList[0].name == slots[slotIndex2].GetOverlay(0).textureList[0].name)
                                    {
                                        combineInstance          = new SkinnedMeshCombiner.CombineInstance();
                                        combineInstance.mesh     = slots[slotIndex2].meshRenderer.sharedMesh;
                                        combineInstance.destMesh = new int[combineInstance.mesh.subMeshCount];
                                        for (int i = 0; i < combineInstance.mesh.subMeshCount; i++)
                                        {
                                            combineInstance.destMesh[i] = -1;
                                        }

                                        combineInstance.bones = slots[slotIndex2].meshRenderer.bones;

                                        combineInstance.destMesh[slots[slotIndex2].subMeshIndex] = indexCount;
                                        combinedMeshList.Add(combineInstance);

                                        shareMaterial[slotIndex2] = true;
                                    }
                                }
                            }
                        }
                        indexCount++;
                    }
                }
                else
                {
                    shareMaterial[slotIndex] = true;
                }
            }
        }
Exemplo n.º 5
0
        //private void FireSlotAtlasNotification(UMAData umaData, Material[] materials)
        //{
        //    for (int atlasIndex = 0; atlasIndex < umaData.atlasList.atlas.Count; atlasIndex++)
        //    {
        //        for (int materialDefinitionIndex = 0; materialDefinitionIndex < umaData.atlasList.atlas[atlasIndex].atlasMaterialDefinitions.Count; materialDefinitionIndex++)
        //        {
        //            var materialDefinition = umaData.atlasList.atlas[atlasIndex].atlasMaterialDefinitions[materialDefinitionIndex];
        //            var slotData = materialDefinition.source.slotData;
        //            if (slotData.SlotAtlassed != null)
        //            {
        //                slotData.SlotAtlassed.Invoke(umaData, slotData, materials[atlasIndex], materialDefinition.atlasRegion);
        //            }
        //        }
        //    }
        //    SlotData[] slots = umaData.umaRecipe.slotDataList;
        //    for (int slotIndex = 0; slotIndex < slots.Length; slotIndex++)
        //    {
        //        var slotData = slots[slotIndex];
        //        if (slotData == null) continue;
        //        if (slotData.textureNameList.Length == 1 && string.IsNullOrEmpty(slotData.textureNameList[0]))
        //        {
        //            if (slotData.SlotAtlassed != null)
        //            {
        //                slotData.SlotAtlassed.Invoke(umaData, slotData, materials[atlasIndex], materialDefinition.atlasRegion);
        //            }
        //        }
        //    }
        //}

        protected void CombineByShader()
        {
            SkinnedMeshCombiner.CombineInstance combineInstance;

            for (int atlasIndex = 0; atlasIndex < umaData.atlasList.atlas.Count; atlasIndex++)
            {
                combinedMaterialList.Add(umaData.atlasList.atlas[atlasIndex].materialSample);

                for (int materialDefinitionIndex = 0; materialDefinitionIndex < umaData.atlasList.atlas[atlasIndex].atlasMaterialDefinitions.Count; materialDefinitionIndex++)
                {
                    var materialDefinition = umaData.atlasList.atlas[atlasIndex].atlasMaterialDefinitions[materialDefinitionIndex];
                    var slotData           = materialDefinition.source.slotData;
                    combineInstance          = new SkinnedMeshCombiner.CombineInstance();
                    combineInstance.mesh     = slotData.meshRenderer.sharedMesh;
                    combineInstance.destMesh = new int[combineInstance.mesh.subMeshCount];
                    for (int i = 0; i < combineInstance.mesh.subMeshCount; i++)
                    {
                        combineInstance.destMesh[i] = -1;
                    }

                    combineInstance.bones = slotData.meshRenderer.bones;
                    combineInstance.destMesh[slotData.subMeshIndex] = atlasIndex;
                    combinedMeshList.Add(combineInstance);

                    if (slotData.SlotAtlassed != null)
                    {
                        slotData.SlotAtlassed.Invoke(umaData, slotData, umaData.atlasList.atlas[atlasIndex].materialSample, materialDefinition.atlasRegion);
                    }
                }
            }


            SlotData[]      slots             = umaData.umaRecipe.slotDataList;
            int             indexCount        = 0;
            List <Material> sourceMaterials   = null;
            int             atlassedMaterials = combinedMaterialList.Count;

            for (int slotIndex = 0; slotIndex < slots.Length; slotIndex++)
            {
                if (slots[slotIndex] == null)
                {
                    continue;
                }
                if (slots[slotIndex].textureNameList.Length == 1 && string.IsNullOrEmpty(slots[slotIndex].textureNameList[0]))
                {
                    combineInstance          = new SkinnedMeshCombiner.CombineInstance();
                    combineInstance.mesh     = slots[slotIndex].meshRenderer.sharedMesh;
                    combineInstance.destMesh = new int[combineInstance.mesh.subMeshCount];
                    for (int i = 0; i < combineInstance.mesh.subMeshCount; i++)
                    {
                        combineInstance.destMesh[i] = -1;
                    }

                    combineInstance.bones = slots[slotIndex].meshRenderer.bones;

                    bool     contains     = false;
                    Material slotMaterial = null;
                    if (sourceMaterials != null)
                    {
                        for (int i = 0; i < sourceMaterials.Count; i++)
                        {
                            if (slots[slotIndex].materialSample == sourceMaterials[i])
                            {
                                slotMaterial = combinedMaterialList[i + atlassedMaterials];
                                combineInstance.destMesh[slots[slotIndex].subMeshIndex] = i + atlassedMaterials;
                                contains = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        sourceMaterials = new List <Material>(slots.Length);
                    }
                    if (!contains)
                    {
                        sourceMaterials.Add(slots[slotIndex].materialSample);
                        slotMaterial = new Material(slots[slotIndex].materialSample);
                        combinedMaterialList.Add(slotMaterial);
                        combineInstance.destMesh[slots[slotIndex].subMeshIndex] = combinedMaterialList.Count - 1;
                    }
                    if (slots[slotIndex].SlotAtlassed != null)
                    {
                        slots[slotIndex].SlotAtlassed.Invoke(umaData, slots[slotIndex], slotMaterial, new Rect(0, 0, 1, 1));
                    }

                    combinedMeshList.Add(combineInstance);
                    indexCount++;
                }
            }
        }