예제 #1
0
        private string createMultiMaterial(Material[] mats)
        {
            MultiMaterial3JS multiMatJS = new MultiMaterial3JS();
            string           multName   = string.Empty;

            foreach (Material mat in mats)
            {
                string uuid = string.Empty;
                multName += Utils.capitalizeFirstSymbol(mat.name.Substring(0, mat.name.Length / 2));
                if (Utils.dictContainsValue(out uuid, materials, mat))
                {
                    // If we already had the same material, find it
                    Material3JS existingMatJS = content.materials.Find(x => (x.uuid.Equals(uuid)));
                    if (existingMatJS == null)
                    {
                        // If we didn't find the material, it has to be somewhere in multimaterials children
                        // Let's loop through them to get the desired
                        foreach (Material3JS material in content.materials)
                        {
                            if (material is MultiMaterial3JS)
                            {
                                existingMatJS = (material as MultiMaterial3JS).materials.Find(x => (x.uuid.Equals(uuid)));
                                if (existingMatJS != null)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    multiMatJS.materials.Add(existingMatJS);
                }
                else
                {
                    // Else create one
                    // And, duhh, find it too
                    uuid = createMaterial(mat);
                    Material3JS existingMatJS = content.materials.Find(x => (x.uuid.Equals(uuid)));
                    multiMatJS.materials.Add(existingMatJS);
                    // Because we created new material for the purpose of multimaterial
                    // Remove it from other general materials
                    content.materials.Remove(existingMatJS);
                    materials.Remove(uuid);
                }
            }
            multiMatJS.name = multName;
            content.materials.Add(multiMatJS);
            multiMaterials.Add(multiMatJS.uuid, mats);
            return(multiMatJS.uuid);
        }
예제 #2
0
        private string parseMaterials(GameObject gameObject)
        {
            Renderer renderer = gameObject.GetComponent <Renderer>();
            string   uuid     = string.Empty;

            if (renderer.sharedMaterials.Length > 1)
            {
                Material[] objMaterials = renderer.sharedMaterials;
                // If cash contains the same array of materials, get their uuid
                // Else create a new one
                if (!Utils.dictContainsArray(out uuid, multiMaterials, objMaterials))
                {
                    uuid = createMultiMaterial(objMaterials);
                }
            }
            else
            {
                Material objMaterial = renderer.sharedMaterial;
                // If cash contains the same material, get its uuid
                // Else create a new one
                if (Utils.dictContainsValue(out uuid, materials, objMaterial))
                {
                    Material3JS existingMatJS = content.materials.Find(x => (x.uuid.Equals(uuid)));
                    if (existingMatJS == null)
                    {
                        // If we didn't find the material in main list, it has to be somewhere in multimaterials children
                        // Let's loop through them to get the desired
                        foreach (Material3JS material in content.materials)
                        {
                            if (material is MultiMaterial3JS)
                            {
                                existingMatJS = (material as MultiMaterial3JS).materials.Find(x => (x.uuid.Equals(uuid)));
                                if (existingMatJS != null)
                                {
                                    // Copy the material to main list
                                    content.materials.Add(existingMatJS);
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    uuid = createMaterial(objMaterial);
                }
            }
            return(uuid);
        }