Esempio n. 1
0
        public TextureMetadataCollection(DestinationFolder urhoDataFolder)
        {
            var allMaterials = AssetDatabase.FindAssets("").Select(_ => AssetContext.Create(_, urhoDataFolder))
                               .Where(_ => _.Type == typeof(Material));

            foreach (var asset in allMaterials)
            {
                var material    = AssetDatabase.LoadAssetAtPath <Material>(asset.AssetPath);
                var description = new MaterialDescription(material);
                if (description.MetallicRoughness != null)
                {
                    var metallicRoughness = description.MetallicRoughness;
                    if (metallicRoughness.MetallicGloss != null)
                    {
                        var meta = AddTexture(metallicRoughness.MetallicGloss, new TextureReferences(
                                                  TextureSemantic.PBRMetallicGlossiness, 1.0f,
                                                  metallicRoughness.SmoothnessTextureChannel ==
                                                  SmoothnessTextureChannel.MetallicOrSpecularAlpha
                                ? metallicRoughness.MetallicGloss
                                : metallicRoughness.BaseColor, metallicRoughness.SmoothnessTextureChannel));
                    }

                    AddTexture(metallicRoughness.BaseColor, new TextureReferences(TextureSemantic.PBRBaseColor));
                    AddTexture(metallicRoughness.DetailBaseColor,
                               new TextureReferences(TextureSemantic.MainTextureDetail));
                }
                else if (description.SpecularGlossiness != null)
                {
                    var specularGlossiness = description.SpecularGlossiness;
                    if (specularGlossiness.PBRSpecular != null)
                    {
                        AddTexture(specularGlossiness.PBRSpecular, new TextureReferences(
                                       TextureSemantic.PBRSpecularGlossiness, 1.0f,
                                       specularGlossiness.Diffuse, specularGlossiness.SmoothnessTextureChannel));
                        AddTexture(specularGlossiness.Diffuse,
                                   new TextureReferences(TextureSemantic.PBRDiffuse, 1.0f, specularGlossiness.PBRSpecular,
                                                         specularGlossiness.SmoothnessTextureChannel));
                    }
                    else
                    {
                        AddTexture(specularGlossiness.Diffuse,
                                   new TextureReferences(TextureSemantic.PBRDiffuse, 1.0f, specularGlossiness.PBRSpecular,
                                                         specularGlossiness.SmoothnessTextureChannel));
                    }

                    AddTexture(specularGlossiness.DetailDiffuse,
                               new TextureReferences(TextureSemantic.MainTextureDetail));
                }
                else
                {
                    var legacy = description.Legacy;
                    AddTexture(legacy.Diffuse, new TextureReferences(TextureSemantic.MainTexture));
                    AddTexture(legacy.Specular, new TextureReferences(TextureSemantic.Specular));
                    AddCommonTextures(legacy);
                }
            }
        }
Esempio n. 2
0
        //[MenuItem("CONTEXT/Terrain/Export Terrain To Urho3D")]
        //static void ExportTerrain(MenuCommand command)
        //{
        //    if (!ResolveDataPath(out var urhoDataPath)) return;
        //}

        public static void ExportToUrho(string targetPath, bool overrideFiles, bool exportSelected)
        {
            if (string.IsNullOrWhiteSpace(targetPath))
            {
                return;
            }

            var urhoDataPath = new DestinationFolder(targetPath, overrideFiles);

            AssetCollection assets;

            if (Selection.assetGUIDs.Length == 0 || !exportSelected)
            {
                assets = new AssetCollection(urhoDataPath,
                                             AssetDatabase.FindAssets("").Select(_ => AssetContext.Create(_, urhoDataPath))
                                             .Where(_ => _.Type != null));
            }
            else
            {
                var selectedAssets = new HashSet <string>();
                foreach (var assetGuiD in Selection.assetGUIDs)
                {
                    AddSelection(assetGuiD, selectedAssets);
                }

                var enumerable    = selectedAssets.Select(_ => AssetContext.Create(_, urhoDataPath)).ToList();
                var assetContexts = enumerable.Where(_ => _.Type != null).ToList();
                assets = new AssetCollection(urhoDataPath, assetContexts);
            }

            _id = 0;

            var other = Split(assets, _ => _.Is3DAsset, _ => Process3DAsset(assets, _));
            var textureMetadataCollection = new TextureMetadataCollection(urhoDataPath);

            other = Split(other,
                          _ => _.Type == typeof(Texture3D) || _.Type == typeof(Texture2D) || _.Type == typeof(Cubemap),
                          _ => new TextureExporter(assets, textureMetadataCollection).ExportAsset(_));
            other = Split(other, _ => _.Type == typeof(Material),
                          _ => new MaterialExporter(assets, textureMetadataCollection).ExportAsset(_));
            var activeScene = SceneManager.GetActiveScene();

            other = Split(other, _ => _.Type == typeof(SceneAsset), _ =>
            {
                if (_.AssetPath == activeScene.path)
                {
                    ProcessSceneAsset(assets, _, activeScene);
                }
            });
            foreach (var assetContext in other)
            {
                ProcessAsset(assets, assetContext);
            }
        }
Esempio n. 3
0
        private static void ExportToUrho()
        {
            string urhoDataPath = EditorUtility.SaveFolderPanel("Save assets to Data folder", _prevFolder, "");

            if (string.IsNullOrEmpty(urhoDataPath))
            {
                return;
            }

            if (urhoDataPath.StartsWith(Path.GetDirectoryName(Application.dataPath).Replace('\\', '/'), StringComparison.InvariantCultureIgnoreCase))
            {
                EditorUtility.DisplayDialog("Error",
                                            "Selected path is inside Unity folder. Please select a different folder.", "Ok");
                return;
            }

            _prevFolder = urhoDataPath;

            AssetCollection assets;

            if (Selection.assetGUIDs.Length == 0)
            {
                assets = new AssetCollection(urhoDataPath, AssetDatabase.FindAssets("").Select(_ => AssetContext.Create(_, urhoDataPath)).Where(_ => _.Type != null));
            }
            else
            {
                var selectedAssets = new HashSet <string>();
                foreach (var assetGuiD in Selection.assetGUIDs)
                {
                    AddSelection(assetGuiD, selectedAssets);
                }
                assets = new AssetCollection(urhoDataPath, selectedAssets.Select(_ => AssetContext.Create(_, urhoDataPath)).Where(_ => _.Type != null));
            }
            _id = 0;
            //string urhoDataPath = @"C:\Temp\Data\";

            //foreach (var type in assets.Select(_ => _.Type).Distinct()) Debug.Log(type.FullName);

            List <AssetContext> other = Split(assets, _ => _.Is3DAsset, _ => Process3DAsset(assets, _));

            other = Split(other, _ => _.Type == typeof(Texture3D) || _.Type == typeof(Texture2D) || _.Type == typeof(Cubemap), _ => new TextureExporter(assets).ExportAsset(_));
            other = Split(other, _ => _.Type == typeof(Material), _ => new MaterialExporter(assets).ExportAsset(_));
            var activeScene = EditorSceneManager.GetActiveScene();

            other = Split(other, _ => _.Type == typeof(SceneAsset), _ =>
            {
                if (_.AssetPath == activeScene.path)
                {
                    ProcessSceneAsset(assets, _, activeScene);
                }
            });
            foreach (var assetContext in other)
            {
                ProcessAsset(assets, assetContext);
            }
            //foreach (var s in guids2)
            //{
            //    var path = AssetDatabase.GUIDToAssetPath(s);
            //    if (path.StartsWith(assetsPrefix))
            //    {
            //        path = path.Substring(assetsPrefix.Length);
            //    }

            //    if (path.StartsWith("PolygonSciFiCity"))
            //    {
            //        if (path.EndsWith(".prefab", true, CultureInfo.InvariantCulture))
            //        {
            //            ExportPrefab(s, path, @"C:\Temp\Data\");
            //        }

            //        if (path.EndsWith(".fbx", true, CultureInfo.InvariantCulture))
            //        {
            //            ExportModel(s, path, @"C:\Temp\Data\");
            //        }

            //        if (path.EndsWith(".mat", true, CultureInfo.InvariantCulture))
            //        {
            //            ExportMaterial(s, path, @"C:\Temp\Data\");
            //        }

            //        if (path.EndsWith(".png", true, CultureInfo.InvariantCulture) ||
            //            path.EndsWith(".dds", true, CultureInfo.InvariantCulture) ||
            //            path.EndsWith(".tga", true, CultureInfo.InvariantCulture))
            //        {
            //            CopyFileIfNew(s, path, @"C:\Temp\Data\");
            //        }
            //    }
            //}
        }