Пример #1
0
        private ImportedMaterial ConvertMaterial(Material mat)
        {
            ImportedMaterial iMat;

            if (mat != null)
            {
                iMat = ImportedHelpers.FindMaterial(mat.m_Name, MaterialList);
                if (iMat != null)
                {
                    return(iMat);
                }
                iMat      = new ImportedMaterial();
                iMat.Name = mat.m_Name;
                foreach (var col in mat.m_SavedProperties.m_Colors)
                {
                    switch (col.Key)
                    {
                    case "_Color":
                        iMat.Diffuse = col.Value;
                        break;

                    case "_SColor":
                        iMat.Ambient = col.Value;
                        break;

                    case "_EmissionColor":
                        iMat.Emissive = col.Value;
                        break;

                    case "_SpecularColor":
                    case "_SpecColor":
                        iMat.Specular = col.Value;
                        break;

                    case "_ReflectColor":
                        iMat.Reflection = col.Value;
                        break;
                    }
                }

                foreach (var flt in mat.m_SavedProperties.m_Floats)
                {
                    switch (flt.Key)
                    {
                    case "_Shininess":
                        iMat.Shininess = flt.Value;
                        break;

                    case "_Transparency":
                        iMat.Transparency = flt.Value;
                        break;
                    }
                }

                //textures
                iMat.Textures = new List <ImportedMaterialTexture>();
                foreach (var texEnv in mat.m_SavedProperties.m_TexEnvs)
                {
                    if (!texEnv.Value.m_Texture.TryGet <Texture2D>(out var m_Texture2D)) //TODO other Texture
                    {
                        continue;
                    }

                    var texture = new ImportedMaterialTexture();
                    iMat.Textures.Add(texture);

                    int dest = -1;
                    if (texEnv.Key == "_MainTex")
                    {
                        dest = 0;
                    }
                    else if (texEnv.Key == "_BumpMap")
                    {
                        dest = 3;
                    }
                    else if (texEnv.Key.Contains("Specular"))
                    {
                        dest = 2;
                    }
                    else if (texEnv.Key.Contains("Normal"))
                    {
                        dest = 1;
                    }

                    texture.Dest = dest;

                    if (textureNameDictionary.TryGetValue(m_Texture2D, out var textureName))
                    {
                        texture.Name = textureName;
                    }
                    else if (ImportedHelpers.FindTexture(m_Texture2D.m_Name + ".png", TextureList) != null) //已有相同名字的图片
                    {
                        for (int i = 1; ; i++)
                        {
                            var name = m_Texture2D.m_Name + $" ({i}).png";
                            if (ImportedHelpers.FindTexture(name, TextureList) == null)
                            {
                                texture.Name = name;
                                textureNameDictionary.Add(m_Texture2D, name);
                                break;
                            }
                        }
                    }
                    else
                    {
                        texture.Name = m_Texture2D.m_Name + ".png";
                        textureNameDictionary.Add(m_Texture2D, texture.Name);
                    }

                    texture.Offset = texEnv.Value.m_Offset;
                    texture.Scale  = texEnv.Value.m_Scale;
                    ConvertTexture2D(m_Texture2D, texture.Name);
                }

                MaterialList.Add(iMat);
            }
            else
            {
                iMat = new ImportedMaterial();
            }
            return(iMat);
        }
Пример #2
0
        private ImportedMaterial ConvertMaterial(Material mat)
        {
            ImportedMaterial iMat;

            if (mat != null)
            {
                iMat = ImportedHelpers.FindMaterial(mat.m_Name, MaterialList);
                if (iMat != null)
                {
                    return(iMat);
                }
                iMat      = new ImportedMaterial();
                iMat.Name = mat.m_Name;
                foreach (var col in mat.m_Colors)
                {
                    var color = new Color4(col.second[0], col.second[1], col.second[2], col.second[3]);
                    switch (col.first)
                    {
                    case "_Color":
                        iMat.Diffuse = color;
                        break;

                    case "_SColor":
                        iMat.Ambient = color;
                        break;

                    case "_EmissionColor":
                        iMat.Emissive = color;
                        break;

                    case "_SpecColor":
                        iMat.Specular = color;
                        break;

                    case "_RimColor":
                    case "_OutlineColor":
                    case "_ShadowColor":
                        break;
                    }
                }

                foreach (var flt in mat.m_Floats)
                {
                    switch (flt.first)
                    {
                    case "_Shininess":
                        iMat.Power = flt.second;
                        break;

                    case "_RimPower":
                    case "_Outline":
                        break;
                    }
                }

                //textures
                iMat.Textures   = new string[5];
                iMat.TexOffsets = new Vector2[5];
                iMat.TexScales  = new Vector2[5];
                foreach (var texEnv in mat.m_TexEnvs)
                {
                    Texture2D tex2D = null;
                    if (assetsfileList.TryGetPD(texEnv.m_Texture, out var TexturePD) && TexturePD.Type == ClassIDReference.Texture2D)//TODO other Texture
                    {
                        tex2D = new Texture2D(TexturePD, true);
                    }

                    if (tex2D == null)
                    {
                        continue;
                    }
                    int dest = texEnv.name == "_MainTex" ? 0 : texEnv.name == "_BumpMap" ? 4 : texEnv.name.Contains("Spec") ? 2 : texEnv.name.Contains("Norm") ? 3 : -1;
                    if (dest < 0 || iMat.Textures[dest] != null)
                    {
                        continue;
                    }
                    iMat.Textures[dest]   = TexturePD.Text + ".png";
                    iMat.TexOffsets[dest] = new Vector2(texEnv.m_Offset[0], texEnv.m_Offset[1]);
                    iMat.TexScales[dest]  = new Vector2(texEnv.m_Scale[0], texEnv.m_Scale[1]);
                    ConvertTexture2D(tex2D, iMat.Textures[dest]);
                }

                MaterialList.Add(iMat);
            }
            else
            {
                iMat = new ImportedMaterial();
            }
            return(iMat);
        }
Пример #3
0
        private ImportedMaterial ConvertMaterial(Material mat)
        {
            ImportedMaterial iMat;

            if (mat != null)
            {
                iMat = ImportedHelpers.FindMaterial(mat.m_Name, MaterialList);
                if (iMat != null)
                {
                    return(iMat);
                }
                iMat      = new ImportedMaterial();
                iMat.Name = mat.m_Name;
                foreach (var col in mat.m_SavedProperties.m_Colors)
                {
                    switch (col.Key)
                    {
                    case "_Color":
                        iMat.Diffuse = col.Value;
                        break;

                    case "_SColor":
                        iMat.Ambient = col.Value;
                        break;

                    case "_EmissionColor":
                        iMat.Emissive = col.Value;
                        break;

                    case "_SpecColor":
                        iMat.Specular = col.Value;
                        break;

                    case "_RimColor":
                    case "_OutlineColor":
                    case "_ShadowColor":
                        break;
                    }
                }

                foreach (var flt in mat.m_SavedProperties.m_Floats)
                {
                    switch (flt.Key)
                    {
                    case "_Shininess":
                        iMat.Power = flt.Value;
                        break;

                    case "_RimPower":
                    case "_Outline":
                        break;
                    }
                }

                //textures
                iMat.Textures   = new string[5];
                iMat.TexOffsets = new Vector2[5];
                iMat.TexScales  = new Vector2[5];
                foreach (var texEnv in mat.m_SavedProperties.m_TexEnvs)
                {
                    Texture2D m_Texture2D = null;
                    if (texEnv.Value.m_Texture.TryGet <Texture2D>(out var m_Texture)) //TODO other Texture
                    {
                        m_Texture2D = m_Texture;
                    }

                    if (m_Texture2D == null)
                    {
                        continue;
                    }
                    int dest = -1;
                    if (texEnv.Key == "_MainTex")
                    {
                        dest = 0;
                    }
                    else if (texEnv.Key == "_BumpMap")
                    {
                        dest = 4;
                    }
                    else if (texEnv.Key.Contains("Spec"))
                    {
                        dest = 2;
                    }
                    else if (texEnv.Key.Contains("Norm"))
                    {
                        dest = 3;
                    }
                    if (dest < 0 || iMat.Textures[dest] != null)
                    {
                        continue;
                    }

                    if (textureNameDictionary.TryGetValue(m_Texture, out var textureName))
                    {
                        iMat.Textures[dest] = textureName;
                    }
                    else if (ImportedHelpers.FindTexture(m_Texture2D.m_Name + ".png", TextureList) != null) //已有相同名字的图片
                    {
                        for (int i = 1; ; i++)
                        {
                            var name = m_Texture2D.m_Name + $" ({i}).png";
                            if (ImportedHelpers.FindTexture(name, TextureList) == null)
                            {
                                iMat.Textures[dest] = name;
                                textureNameDictionary.Add(m_Texture, name);
                                break;
                            }
                        }
                    }
                    else
                    {
                        iMat.Textures[dest] = m_Texture2D.m_Name + ".png";
                        textureNameDictionary.Add(m_Texture, iMat.Textures[dest]);
                    }
                    iMat.TexOffsets[dest] = texEnv.Value.m_Offset;
                    iMat.TexScales[dest]  = texEnv.Value.m_Scale;
                    ConvertTexture2D(m_Texture2D, iMat.Textures[dest]);
                }

                MaterialList.Add(iMat);
            }
            else
            {
                iMat = new ImportedMaterial();
            }
            return(iMat);
        }