Ejemplo n.º 1
0
        public void AttachingCIItemToNode(GameObject currentNode, AssetSchematic schematic)
        {
            switch (schematic.type_and_function.item_function)
            {
            case ItemFunction.soft_wearable:
                CIclothing ciclothing = currentNode.AddComponent <CIclothing>();
                ciclothing.meshType = CONSTANTS.MESH_TYPE.CLOTH;
                ciclothing.dazName  = schematic.origin_and_description.name;
                ciclothing.ID       = schematic.origin_and_description.mcs_id;


                if (schematic.structure_and_physics.item_structure.alpha_masks_key != null)
                {
                    for (int i = 0; i < schematic.structure_and_physics.item_structure.alpha_masks_key.Count(); i++)
                    {
                        string slot = schematic.structure_and_physics.item_structure.alpha_masks_key[i];
                        string path = schematic.structure_and_physics.item_structure.alpha_masks[i];


                        switch (slot)
                        {
                        case "BODY":
                            ciclothing.alphaMasks[CONSTANTS.MATERIAL_SLOT.BODY] = GetTextureFromPath(path, basePath);
                            break;

                        case "HEAD":
                            ciclothing.alphaMasks[CONSTANTS.MATERIAL_SLOT.HEAD] = GetTextureFromPath(path, basePath);
                            break;

                        case "EYE":
                            //do nothing, we don't support this slot yet
                            break;
                        }
                    }
                }


                break;

            case ItemFunction.hair:
                CIhair cihair = currentNode.AddComponent <CIhair>();
                if (schematic.structure_and_physics.item_structure.overlay != null)
                {
                    cihair.overlay      = GetTextureFromPath(schematic.structure_and_physics.item_structure.overlay, basePath);
                    cihair.overlayColor = AssetSchematicUtility.ConvertColorStringToColor(schematic.structure_and_physics.item_structure.overlay_color);
                }
                cihair.meshType = CONSTANTS.MESH_TYPE.HAIR;
                cihair.dazName  = schematic.origin_and_description.name;
                cihair.ID       = schematic.origin_and_description.mcs_id;
                break;

            case ItemFunction.prop:
                CIprop ciprop = currentNode.AddComponent <CIprop>();
                ciprop.meshType = CONSTANTS.MESH_TYPE.PROP;
                ciprop.dazName  = schematic.origin_and_description.name;
                ciprop.ID       = schematic.origin_and_description.mcs_id;
                break;
            }
        }
Ejemplo n.º 2
0
        public Material CreateMorphMaterial(AssetSchematic schematic, Dictionary <string, Texture2D> textures)
        {
            string shaderName = "Standard";

            if (schematic.structure_and_physics.material_structure.shader != null && schematic.structure_and_physics.material_structure.shader != "")
            {
                shaderName = schematic.structure_and_physics.material_structure.shader;
            }
            Shader shader = Shader.Find(shaderName);

            if (shader == null)
            {
                UnityEngine.Debug.LogError("Unable to find shader: " + shaderName);
                throw new UnityException("Unable to locate shader");
            }

            var material = new Material(shader);

            /**
             *          List of textures that a material can have:
             *                  albedo;
             *                  metal;
             *                  smoothness;
             *                  emission;
             *                  normal;
             *                  detail_normal;
             *                  transparency;
             */

            //we also need to enable keywords if we use certain layers
            // For more info see: https://docs.unity3d.com/Manual/MaterialsAccessingViaScript.html


            if (textures.ContainsKey("albedo"))
            {
                material.SetTexture("_MainTex", textures["albedo"]);
            }
            if (textures.ContainsKey("metal"))
            {
                material.SetTexture("_MetallicGlossMap", textures["metal"]);
                material.EnableKeyword("_METALLICGLOSSMAP");
            }
            if (textures.ContainsKey("height"))
            {
                material.SetTexture("_ParallaxMap", textures["height"]);
                material.EnableKeyword("_PARALLAXMAP");
            }
            if (textures.ContainsKey("normal"))
            {
                material.SetTexture("_BumpMap", textures["normal"]);
                material.EnableKeyword("_NORMALMAP");
            }
            if (textures.ContainsKey("detail_normal"))
            {
                material.SetTexture("_DetailNormalMap", textures["detail_normal"]);
                material.EnableKeyword("_DETAIL_MULX2");
            }
            if (textures.ContainsKey("specular"))
            {
                material.SetTexture("_SpecGlossMap", textures["specular"]);
                material.EnableKeyword("_SPECGLOSSMAP");
            }
            if (textures.ContainsKey("emission"))
            {
                material.SetTexture("_EmissionMap", textures["emission"]);
                material.EnableKeyword("_EMISSION");
            }

            /*
             * //uncomment if you want to know which keywords were enabled
             * string[] shaderKeywords = material.shaderKeywords;
             * for(int i = 0;  i < shaderKeywords.Length; i++)
             * {
             *  UnityEngine.Debug.Log("Keyword: " + shaderKeywords[i]);
             * }
             */

            if (!String.IsNullOrEmpty(schematic.structure_and_physics.material_structure.albedo_tint))
            {
                Color c = AssetSchematicUtility.ConvertColorStringToColor(schematic.structure_and_physics.material_structure.albedo_tint);
                material.SetColor("_Color", c);
            }
            if (!String.IsNullOrEmpty(schematic.structure_and_physics.material_structure.emission_value))
            {
                Color c = AssetSchematicUtility.ConvertColorStringToColor(schematic.structure_and_physics.material_structure.emission_value);
                material.SetColor("_EmissionColor", c);
            }
            if (material.HasProperty("_DetailNormalMapScale") && schematic.structure_and_physics.material_structure.detail_normal_value > 0f)
            {
                material.SetFloat("_DetailNormalMapScale", schematic.structure_and_physics.material_structure.detail_normal_value);
            }

            if (schematic.structure_and_physics.material_structure.shader_keywords != null)
            {
                for (int i = 0; i < schematic.structure_and_physics.material_structure.shader_keywords.Length; i++)
                {
                    material.EnableKeyword(schematic.structure_and_physics.material_structure.shader_keywords[i]);
                }
            }
            if (schematic.structure_and_physics.material_structure.shader_tags != null)
            {
                for (int i = 0; i < schematic.structure_and_physics.material_structure.shader_tags.Length; i++)
                {
                    string key = schematic.structure_and_physics.material_structure.shader_tags[i];
                    int    pos = key.IndexOf('=');
                    if (pos < 0)
                    {
                        UnityEngine.Debug.Log("Invalid material shader_tag: " + schematic.origin_and_description.name + " => " + schematic.origin_and_description.mcs_id + " tag: " + key);
                        throw new Exception("Invalid shader tag");
                    }
                    material.SetOverrideTag(key.Substring(0, pos), key.Substring(pos + 1));
                }
            }
            if (schematic.structure_and_physics.material_structure.shader_properties != null)
            {
                for (int i = 0; i < schematic.structure_and_physics.material_structure.shader_properties.Length; i++)
                {
                    string key           = schematic.structure_and_physics.material_structure.shader_properties[i];
                    int    typePos       = key.IndexOf(':');
                    int    equalPos      = key.IndexOf('=');
                    string type          = key.Substring(0, typePos);
                    string propertyKey   = key.Substring(typePos + 1, equalPos - (typePos + 1));
                    string propertyValue = key.Substring(equalPos + 1);

                    switch (type)
                    {
                    case "int":
                        material.SetInt(propertyKey, Int32.Parse(propertyValue));
                        break;

                    case "float":
                        material.SetFloat(propertyKey, float.Parse(propertyValue));
                        break;

                    case "color":
                        Color c = AssetSchematicUtility.ConvertColorStringToColor(propertyValue);
                        material.SetColor(propertyKey, c);
                        break;

                    default:
                        UnityEngine.Debug.Log("Invalid material property: " + schematic.origin_and_description.name + " => " + schematic.origin_and_description.mcs_id + " key: " + key);
                        throw new Exception("Invalid shader property");
                        break;
                    }
                }
            }
            if (schematic.structure_and_physics.material_structure.render_queue != -2)
            {
                material.renderQueue = schematic.structure_and_physics.material_structure.render_queue;
            }


            return(material);
        }