示例#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);
                }
            }
        }
示例#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);
            }
        }
示例#3
0
        public AssetCollection(DestinationFolder urhoDataPath, IEnumerable <AssetContext> assets)
        {
            _urhoDataPath = urhoDataPath;
            _assets       = assets.ToList();

            foreach (var assetContext in assets.Where(_ => _.Type == typeof(Material)))
            {
                AddMaterialPath(AssetDatabase.LoadAssetAtPath <Material>(assetContext.AssetPath),
                                assetContext.UrhoAssetName);
            }
        }