Beispiel #1
0
                public void Upgrade(AssetMigrationContext context, string dependencyName, PackageVersion currentVersion, PackageVersion targetVersion, YamlMappingNode yamlAssetNode, PackageLoadingAssetFile assetFile)
                {
                    dynamic asset = new DynamicYamlMapping(yamlAssetNode);

                    AssetUpgraderBase.SetSerializableVersion(asset, dependencyName, targetVersion);

                    // Move Test4 to Test5
                    asset.Test5 = asset.Test4;
                    asset.Test4 = DynamicYamlEmpty.Default;
                }
Beispiel #2
0
                public void Upgrade(AssetMigrationContext context, string dependencyName, PackageVersion currentVersion, PackageVersion targetVersion, YamlMappingNode yamlAssetNode, PackageLoadingAssetFile assetFile)
                {
                    dynamic asset = new DynamicYamlMapping(yamlAssetNode);

                    // Note: seems little bit strange, but original test was not using targetVersion...
                    var serializedVersion = AssetRegistry.GetCurrentFormatVersions(typeof(MyUpgradedAsset))[dependencyName];
                    AssetUpgraderBase.SetSerializableVersion(asset, dependencyName, serializedVersion);

                    // Move Test1 to Test2
                    asset.Test2 = asset.Test1;
                    asset.Test1 = DynamicYamlEmpty.Default;
                }
Beispiel #3
0
                public void Upgrade(AssetMigrationContext context, string dependencyName, PackageVersion currentVersion, PackageVersion targetVersion, YamlMappingNode yamlAssetNode, PackageLoadingAssetFile assetFile)
                {
                    dynamic asset = new DynamicYamlMapping(yamlAssetNode);

                    AssetUpgraderBase.SetSerializableVersion(asset, dependencyName, targetVersion);

                    // Move Test2 to Test4
                    if (currentVersion == PackageVersion.Parse("0.0.2"))
                    {
                        asset.Test4 = asset.Test2;
                        asset.Test2 = DynamicYamlEmpty.Default;
                    }
                    // Move Test3 to Test4
                    else if (currentVersion == PackageVersion.Parse("0.0.3"))
                    {
                        asset.Test4 = asset.Test3;
                        asset.Test3 = DynamicYamlEmpty.Default;
                    }
                }
Beispiel #4
0
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
            {
                // Introduction of MaterialInstance
                var material = asset.Type.Material;

                if (material != null)
                {
                    asset.Type.MaterialInstance          = new YamlMappingNode();
                    asset.Type.MaterialInstance.Material = material;
                    asset.Type.Material = DynamicYamlEmpty.Default;
                }
                var type = asset.Type.Node as YamlMappingNode;

                if (type != null && type.Tag == "!CubeProceduralModel")
                {
                    // Size changed from scalar to vector3
                    var size = asset.Type.Size as DynamicYamlScalar;
                    if (size != null)
                    {
                        var vecSize = new YamlMappingNode
                        {
                            { new YamlScalarNode("X"), new YamlScalarNode(size.Node.Value) },
                            { new YamlScalarNode("Y"), new YamlScalarNode(size.Node.Value) },
                            { new YamlScalarNode("Z"), new YamlScalarNode(size.Node.Value) }
                        };
                        vecSize.Style   = DataStyle.Compact;
                        asset.Type.Size = vecSize;
                    }
                }
            }
Beispiel #5
0
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
            {
                // SerializedVersion format changed during renaming upgrade. However, before this was merged back in master, some asset upgrader still with older version numbers were developed.
                // However since this upgrader can be reapplied, it is not a problem
                var proceduralType = asset.Type;

                if (proceduralType.Node.Tag == "!CapsuleProceduralModel" && currentVersion != PackageVersion.Parse("0.0.6"))
                {
                    if (proceduralType.Radius == null)
                    {
                        proceduralType.Radius = 0.25f;
                    }
                }
            }
Beispiel #6
0
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
            {
                var proceduralType = asset.Type;

                if (proceduralType.Diameter != null)
                {
                    proceduralType.Radius   = 0.5f * (float)proceduralType.Diameter;
                    proceduralType.Diameter = DynamicYamlEmpty.Default;
                }
                if (proceduralType.Node.Tag == "!TorusProceduralModel" && proceduralType.Thickness != null)
                {
                    proceduralType.Thickness = 0.5f * (float)proceduralType.Thickness;
                }
            }
Beispiel #7
0
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
            {
                int backBufferWidth = asset.BackBufferWidth ?? 1280;

                asset.RemoveChild("BackBufferWidth");
                int backBufferHeight = asset.BackBufferHeight ?? 720;

                asset.RemoveChild("BackBufferHeight");
                GraphicsProfile profile = asset.DefaultGraphicsProfile ?? GraphicsProfile.Level_9_1;

                asset.RemoveChild("DefaultGraphicsProfile");
                ColorSpace colorSpace = asset.ColorSpace ?? ColorSpace.Linear;

                asset.RemoveChild("ColorSpace");
                DisplayOrientation displayOrientation = asset.DisplayOrientation ?? DisplayOrientation.Default;

                asset.RemoveChild("DisplayOrientation");
                TextureQuality textureQuality = asset.TextureQuality ?? TextureQuality.Fast;

                asset.RemoveChild("TextureQuality");
                var renderingMode = RenderingMode.HDR;

                if (asset.RenderingMode != null)
                {
                    if (asset.RenderingMode == "LDR")
                    {
                        renderingMode = RenderingMode.LDR;
                    }
                }
                asset.RemoveChild("RenderingMode");

                var configurations = new DynamicYamlArray(new YamlSequenceNode());

                asset.Defaults = configurations;

                dynamic renderingSettings = new DynamicYamlMapping(new YamlMappingNode {
                    Tag = "!SiliconStudio.Xenko.Graphics.RenderingSettings,SiliconStudio.Xenko.Graphics"
                });

                renderingSettings.DefaultBackBufferWidth  = backBufferWidth;
                renderingSettings.DefaultBackBufferHeight = backBufferHeight;
                renderingSettings.DefaultGraphicsProfile  = profile;
                renderingSettings.ColorSpace         = colorSpace;
                renderingSettings.DisplayOrientation = displayOrientation;
                asset.Defaults.Add(renderingSettings);

                dynamic editorSettings = new DynamicYamlMapping(new YamlMappingNode {
                    Tag = "!SiliconStudio.Xenko.Assets.EditorSettings,SiliconStudio.Xenko.Assets"
                });

                editorSettings.RenderingMode = renderingMode;
                asset.Defaults.Add(editorSettings);

                dynamic textSettings = new DynamicYamlMapping(new YamlMappingNode {
                    Tag = "!SiliconStudio.Xenko.Assets.Textures.TextureSettings,SiliconStudio.Xenko.Assets"
                });

                textSettings.TextureQuality = textureQuality;
                asset.Defaults.Add(textSettings);

                dynamic physicsSettings = new DynamicYamlMapping(new YamlMappingNode {
                    Tag = "!SiliconStudio.Xenko.Physics.PhysicsSettings,SiliconStudio.Xenko.Physics"
                });

                asset.Defaults.Add(physicsSettings);

                var defaultFilters = new DynamicYamlArray(new YamlSequenceNode());

                asset.PlatformFilters = defaultFilters;
                asset.PlatformFilters.Add("PowerVR SGX 54[0-9]");
                asset.PlatformFilters.Add("Adreno \\(TM\\) 2[0-9][0-9]");
                asset.PlatformFilters.Add("Adreno (TM) 320");
                asset.PlatformFilters.Add("Adreno (TM) 330");
                asset.PlatformFilters.Add("Adreno \\(TM\\) 4[0-9][0-9]");
                asset.PlatformFilters.Add("NVIDIA Tegra");
                asset.PlatformFilters.Add("Intel(R) HD Graphics");
                asset.PlatformFilters.Add("^Mali\\-4");
                asset.PlatformFilters.Add("^Mali\\-T6");
                asset.PlatformFilters.Add("^Mali\\-T7");
            }
Beispiel #8
0
 protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
 {
     foreach (var modelMaterial in asset.Materials)
     {
         var material = modelMaterial.Material;
         if (material != null)
         {
             modelMaterial.MaterialInstance          = new YamlMappingNode();
             modelMaterial.MaterialInstance.Material = material;
             modelMaterial.Material = DynamicYamlEmpty.Default;
         }
     }
 }
Beispiel #9
0
 /// <inheritdoc/>
 protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
 {
     asset.AnimationTimeMinimum = "0:00:00:00.0000000";
     asset.AnimationTimeMaximum = "0:00:30:00.0000000";  // Tentatively set this to 30 minutes
 }
Beispiel #10
0
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile,
                                                 OverrideUpgraderHint overrideHint)
            {
                if (asset.IsDynamic != null)
                {
                    var isDynamic = (bool)asset.IsDynamic;

                    // There is also SDF type, but old assets don't have it yet
                    asset.AddChild("FontType", isDynamic ? "Dynamic" : "Static");

                    asset.RemoveChild("IsDynamic");
                }
            }
Beispiel #11
0
        public void TestUpgrade(MyUpgradedAsset asset, bool needMigration)
        {
            var loadingFilePath = new PackageLoadingAssetFile(Path.Combine(DirectoryTestBase, "TestUpgrade\\Asset1.xkobj"), "");
            var outputFilePath = loadingFilePath.FilePath.FullPath;
            AssetSerializer.Save(outputFilePath, asset);

            var logger = new LoggerResult();
            var context = new AssetMigrationContext(null, logger);
            Assert.AreEqual(AssetMigration.MigrateAssetIfNeeded(context, loadingFilePath, "TestPackage"), needMigration);

            if (needMigration)
            {
                using (var fileStream = new FileStream(outputFilePath, FileMode.Truncate))
                    fileStream.Write(loadingFilePath.AssetContent, 0, loadingFilePath.AssetContent.Length);
            }

            Console.WriteLine(File.ReadAllText(outputFilePath).Trim());

            var upgradedAsset = AssetSerializer.Load<MyUpgradedAsset>(outputFilePath);
            AssertUpgrade(upgradedAsset);
        }
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
            {
                var rootNode = (YamlNode)asset.Node;

                foreach (var fxaaEffectNode in rootNode.AllNodes.OfType <YamlMappingNode>().Where(x => x.Tag == "!FXAAEffect").Select(x => new DynamicYamlMapping(x)))
                {
                    // We could remap quality but probably not worth the code complexity (esp. since previous quality slider from 10 to 39 was not "continuous", user probably didn't set it up properly anyway)
                    // Simply remove it so that it goes back to default value
                    fxaaEffectNode.RemoveChild("Quality");
                }
            }
Beispiel #13
0
 protected override void UpgradeAsset(AssetMigrationContext context, int currentVersion, int targetVersion, dynamic asset, PackageLoadingAssetFile assetFile)
 {
     if (asset.SRgb != null)
     {
         // By default transform to auto
         asset.ColorSpace = TextureColorSpace.Auto;
         asset.RemoveChild("SRgb");
     }
 }
Beispiel #14
0
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile,
                                                 OverrideUpgraderHint overrideHint)
            {
                dynamic newSource = new DynamicYamlMapping(new YamlMappingNode());

                var assetName   = (asset.FontName != null) ? (string)asset.FontName : null;
                var assetSource = (asset.Source != null) ? (string)asset.Source : null;

                // First check if the asset has a valid source
                if (assetSource != null && !assetSource.IsNullOrEmpty() && !assetSource.Equals("null"))
                {
                    newSource.Node.Tag = "!FileFontProvider";
                    newSource.AddChild("Source", assetSource);
                }

                // Only if the asset doesn't have a valid source can it be a system font
                else
                if (assetName != null && !assetName.IsNullOrEmpty() && !assetName.Equals("null"))
                {
                    newSource.Node.Tag = "!SystemFontProvider";
                    newSource.AddChild("FontName", assetName);

                    if (asset.Style != null)
                    {
                        newSource.AddChild("Style", asset.Style);
                    }
                }



                asset.RemoveChild("FontName");
                asset.RemoveChild("Source");
                asset.RemoveChild("Style");

                asset.AddChild("FontSource", newSource);


                if (asset.FontType != null)
                {
                    var fontType = (string)asset.FontType;
                    asset.RemoveChild("FontType");

                    dynamic newType = new DynamicYamlMapping(new YamlMappingNode());

                    if (fontType.Equals("Dynamic"))
                    {
                        newType.Node.Tag = "!RuntimeRasterizedSpriteFontType";

                        if (asset.Size != null)
                        {
                            newType.AddChild("Size", asset.Size);
                        }

                        if (asset.AntiAlias != null)
                        {
                            newType.AddChild("AntiAlias", asset.AntiAlias);
                        }
                    }
                    else
                    if (fontType.Equals("SDF"))
                    {
                        newType.Node.Tag = "!SignedDistanceFieldSpriteFontType";

                        if (asset.Size != null)
                        {
                            newType.AddChild("Size", asset.Size);
                        }

                        if (asset.CharacterSet != null)
                        {
                            newType.AddChild("CharacterSet", asset.CharacterSet);
                        }

                        if (asset.CharacterRegions != null)
                        {
                            newType.AddChild("CharacterRegions", asset.CharacterRegions);
                        }
                    }
                    else
                    {
                        newType.Node.Tag = "!OfflineRasterizedSpriteFontType";

                        if (asset.Size != null)
                        {
                            newType.AddChild("Size", asset.Size);
                        }

                        if (asset.CharacterSet != null)
                        {
                            newType.AddChild("CharacterSet", asset.CharacterSet);
                        }

                        if (asset.CharacterRegions != null)
                        {
                            newType.AddChild("CharacterRegions", asset.CharacterRegions);
                        }

                        if (asset.AntiAlias != null)
                        {
                            newType.AddChild("AntiAlias", asset.AntiAlias);
                        }

                        if (asset.IsPremultiplied != null)
                        {
                            newType.AddChild("IsPremultiplied", asset.IsPremultiplied);
                        }
                    }

                    asset.AddChild("FontType", newType);
                }

                asset.RemoveChild("IsPremultiplied");
                asset.RemoveChild("AntiAlias");
                asset.RemoveChild("UseKerning");
                asset.RemoveChild("Size");
                asset.RemoveChild("CharacterSet");
                asset.RemoveChild("CharacterRegions");
            }
Beispiel #15
0
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile,
                                                 OverrideUpgraderHint overrideHint)
            {
                dynamic settings = new DynamicYamlMapping(new YamlMappingNode {
                    Tag = "!Xenko.Navigation.NavigationSettings,Xenko.Navigation"
                });

                // Default build settings
                dynamic buildSettings = new DynamicYamlMapping(new YamlMappingNode());

                buildSettings.CellHeight             = 0.2f;
                buildSettings.CellSize               = 0.3f;
                buildSettings.TileSize               = 32;
                buildSettings.MinRegionArea          = 2;
                buildSettings.RegionMergeArea        = 20;
                buildSettings.MaxEdgeLen             = 12.0f;
                buildSettings.MaxEdgeError           = 1.3f;
                buildSettings.DetailSamplingDistance = 6.0f;
                buildSettings.MaxDetailSamplingError = 1.0f;
                settings.BuildSettings               = buildSettings;

                var groups = new DynamicYamlArray(new YamlSequenceNode());

                // Agent settings array
                settings.Groups = groups;

                asset.Defaults.Add(settings);
            }
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
            {
                if (asset.ColliderShapes == null)
                {
                    return;
                }

                foreach (dynamic shape in asset.ColliderShapes)
                {
                    var tag = shape.Node.Tag;
                    if (tag != "!Box2DColliderShapeDesc")
                    {
                        continue;
                    }

                    shape.Node.Tag = "!BoxColliderShapeDesc";
                    shape.Is2D     = true;
                    shape.Size.X   = shape.Size.X;
                    shape.Size.Y   = shape.Size.Y;
                    shape.Size.Z   = 0.01f;
                }
            }
Beispiel #17
0
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
            {
                // Replace ComputeCurveSamplerVector4 with ComputeCurveSamplerColor4.
                // Replace ComputeAnimationCurveVector4 with ComputeAnimationCurveColor4.
                // Replace Vector4 with Color4.
                Action <dynamic> updateSampler = sampler =>
                {
                    if (sampler == null || sampler.Node.Tag != "!ComputeCurveSamplerVector4")
                    {
                        return;
                    }

                    sampler.Node.Tag = "!ComputeCurveSamplerColor4";

                    var curve = sampler.Curve;
                    curve.Node.Tag = "!ComputeAnimationCurveColor4";
                    foreach (var kf in curve.KeyFrames)
                    {
                        var colorValue = new DynamicYamlMapping(new YamlMappingNode());
                        colorValue.AddChild("R", kf.Value.X);
                        colorValue.AddChild("G", kf.Value.Y);
                        colorValue.AddChild("B", kf.Value.Z);
                        colorValue.AddChild("A", kf.Value.W);

                        kf.Value = colorValue;
                    }
                };

                var hierarchy = asset.Hierarchy;
                var entities  = hierarchy.Entities;

                foreach (var entityAndDesign in entities)
                {
                    var entity = entityAndDesign.Entity;
                    foreach (var component in entity.Components)
                    {
                        var componentTag = component.Node.Tag;
                        if (componentTag != "!ParticleSystemComponent")
                        {
                            continue;
                        }

                        var particleSystem = component.ParticleSystem;
                        if (particleSystem == null)
                        {
                            continue;
                        }

                        foreach (var emitter in particleSystem.Emitters)
                        {
                            // Updaters
                            foreach (var updater in emitter.Updaters)
                            {
                                var updaterTag = updater.Node.Tag;
                                if (updaterTag != "!UpdaterColorOverTime")
                                {
                                    continue;
                                }

                                // Update the samplers
                                updateSampler(updater.SamplerMain);
                                updateSampler(updater.SamplerOptional);
                            }
                        }
                    }
                }
            }
Beispiel #18
0
 protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
 {
     asset.RemoveChild("SceneSettings");
 }
Beispiel #19
0
 protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
 {
     asset.Hierarchy.RootPartIds  = asset.Hierarchy.RootEntities;
     asset.Hierarchy.Parts        = asset.Hierarchy.Entities;
     asset.Hierarchy.RootEntities = DynamicYamlEmpty.Default;
     asset.Hierarchy.Entities     = DynamicYamlEmpty.Default;
     foreach (var entityDesign in asset.Hierarchy.Parts)
     {
         entityDesign.Folder             = entityDesign.Design.Folder;
         entityDesign.BaseId             = entityDesign.Design.BaseId;
         entityDesign.BasePartInstanceId = entityDesign.Design.BasePartInstanceId;
         entityDesign.Design             = DynamicYamlEmpty.Default;
     }
 }
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
            {
                YamlNode assetNode = asset.Node;

                foreach (var node in assetNode.AllNodes)
                {
                    if (node.Tag != null && node.Tag.EndsWith(",Stride.Engine")
                        // Several types are still in Stride.Engine
                        && node.Tag != "!Stride.Rendering.Compositing.ForwardRenderer,Stride.Engine" &&
                        node.Tag != "!Stride.Rendering.Compositing.SceneCameraRenderer,Stride.Engine")
                    {
                        node.Tag = node.Tag.Replace(",Stride.Engine", ",Stride.Rendering");
                    }
                }
            }
Beispiel #21
0
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
            {
                var hierarchy = asset.Hierarchy;
                var entities  = hierarchy.Entities;

                foreach (var entityAndDesign in entities)
                {
                    var entity = entityAndDesign.Entity;
                    foreach (var component in entity.Components)
                    {
                        var componentTag = component.Node.Tag;
                        if (componentTag != "!SpriteComponent")
                        {
                            continue;
                        }

                        var provider = component.SpriteProvider;
                        if (provider == null || provider.Node.Tag != "!SpriteFromSheet")
                        {
                            continue;
                        }

                        component.TransferChild("CurrentFrame", provider, "CurrentFrame");
                    }
                }
            }
Beispiel #22
0
 protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile)
 {
     asset.Parameters = DynamicYamlEmpty.Default;
 }
Beispiel #23
0
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
            {
                var hierarchy = asset.Hierarchy;
                var entities  = hierarchy.Entities;

                foreach (var entityAndDesign in entities)
                {
                    var entity = entityAndDesign.Entity;
                    foreach (var component in entity.Components)
                    {
                        var componentTag = component.Node.Tag;
                        if (componentTag != "!UIComponent")
                        {
                            continue;
                        }

                        // VirtualResolution
                        component.RenameChild("VirtualResolution", "Resolution");

                        // VirtualResolutionMode
                        component.RenameChild("VirtualResolutionMode", "ResolutionStretch");
                    }
                }
            }
Beispiel #24
0
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
            {
                var addRendering = true;
                var addEditor    = true;
                var addPhysics   = true;
                var addTexture   = true;

                foreach (DynamicYamlMapping mapping in asset.Defaults)
                {
                    if (mapping.Node.Tag == "!SiliconStudio.Xenko.Graphics.RenderingSettings,SiliconStudio.Xenko.Graphics")
                    {
                        addRendering = false;
                    }
                    if (mapping.Node.Tag == "!SiliconStudio.Xenko.Assets.EditorSettings,SiliconStudio.Xenko.Assets")
                    {
                        addEditor = false;
                    }
                    if (mapping.Node.Tag == "!SiliconStudio.Xenko.Assets.Textures.TextureSettings,SiliconStudio.Xenko.Assets")
                    {
                        addTexture = false;
                    }
                    if (mapping.Node.Tag == "!SiliconStudio.Xenko.Physics.PhysicsSettings,SiliconStudio.Xenko.Physics")
                    {
                        addPhysics = false;
                    }
                }

                if (addRendering)
                {
                    dynamic setting = new DynamicYamlMapping(new YamlMappingNode {
                        Tag = "!SiliconStudio.Xenko.Graphics.RenderingSettings,SiliconStudio.Xenko.Graphics"
                    });
                    asset.Defaults.Add(setting);
                }

                if (addEditor)
                {
                    dynamic setting = new DynamicYamlMapping(new YamlMappingNode {
                        Tag = "!SiliconStudio.Xenko.Assets.EditorSettings,SiliconStudio.Xenko.Assets"
                    });
                    asset.Defaults.Add(setting);
                }

                if (addPhysics)
                {
                    dynamic setting = new DynamicYamlMapping(new YamlMappingNode {
                        Tag = "!SiliconStudio.Xenko.Physics.PhysicsSettings,SiliconStudio.Xenko.Physics"
                    });
                    asset.Defaults.Add(setting);
                }

                if (addTexture)
                {
                    dynamic setting = new DynamicYamlMapping(new YamlMappingNode {
                        Tag = "!SiliconStudio.Xenko.Assets.Textures.TextureSettings,SiliconStudio.Xenko.Assets"
                    });
                    asset.Defaults.Add(setting);
                }
            }
Beispiel #25
0
 protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
 {
     if (asset.NoPremultiply != null)
     {
         asset.IsPremultiplied = !(bool)asset.NoPremultiply;
         asset.NoPremultiply   = DynamicYamlEmpty.Default;
     }
     if (asset.IsNotPremultiply != null)
     {
         asset.IsPremultiplied  = !(bool)asset.IsNotPremultiply;
         asset.IsNotPremultiply = DynamicYamlEmpty.Default;
     }
 }
Beispiel #26
0
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
            {
                var proceduralType = asset.Type;

                if (proceduralType.ScaleUV != null)
                {
                    var currentScale = (float)proceduralType.ScaleUV;

                    var vecSize = new YamlMappingNode
                    {
                        { new YamlScalarNode("X"), new YamlScalarNode(currentScale.ToString(CultureInfo.InvariantCulture)) },
                        { new YamlScalarNode("Y"), new YamlScalarNode(currentScale.ToString(CultureInfo.InvariantCulture)) }
                    };
                    vecSize.Style = DataStyle.Compact;

                    proceduralType.RemoveChild("ScaleUV");

                    proceduralType.UvScale = vecSize;
                }
                else if (proceduralType.UVScales != null)
                {
                    var x = (float)proceduralType.UVScales.X;
                    var y = (float)proceduralType.UVScales.Y;

                    var vecSize = new YamlMappingNode
                    {
                        { new YamlScalarNode("X"), new YamlScalarNode(x.ToString(CultureInfo.InvariantCulture)) },
                        { new YamlScalarNode("Y"), new YamlScalarNode(y.ToString(CultureInfo.InvariantCulture)) }
                    };
                    vecSize.Style = DataStyle.Compact;

                    proceduralType.RemoveChild("UVScales");

                    proceduralType.UvScale = vecSize;
                }
                else
                {
                    var vecSize = new YamlMappingNode
                    {
                        { new YamlScalarNode("X"), new YamlScalarNode("1") },
                        { new YamlScalarNode("Y"), new YamlScalarNode("1") }
                    };
                    vecSize.Style = DataStyle.Compact;

                    proceduralType.UvScale = vecSize;
                }
            }
        public override bool Upgrade(PackageSession session, ILogger log, Package dependentPackage, PackageDependency dependency, Package dependencyPackage, IList <PackageLoadingAssetFile> assetFiles)
        {
            if (dependency.Version.MinVersion < new PackageVersion("1.5.0-alpha01"))
            {
                RunAssetUpgradersUntilVersion(log, dependentPackage, XenkoConfig.PackageName, assetFiles, PackageVersion.Parse("1.5.0-alpha01"));
            }

            if (dependency.Version.MinVersion < new PackageVersion("1.5.0-alpha02"))
            {
                // Ideally, this should be part of asset upgrader but we can't upgrade multiple assets at once yet

                var modelAssets = assetFiles.Where(f => f.FilePath.GetFileExtension() == ".xkm3d").Select(x => x.AsYamlAsset()).ToArray();
                var animAssets  = assetFiles.Where(f => f.FilePath.GetFileExtension() == ".xkanim").Select(x => x.AsYamlAsset()).ToArray();
                var sceneAssets = assetFiles.Where(f => f.FilePath.GetFileExtension() == ".xkscene").Select(x => x.AsYamlAsset()).ToArray();

                // Select models with at least two nodes
                var modelAssetsWithSekeleton = modelAssets
                                               .Where(model => ((IEnumerable)model.DynamicRootNode.Nodes).Cast <object>().Count() > 1).ToArray();

                var animToModelMapping = new Dictionary <PackageLoadingAssetFile.YamlAsset, PackageLoadingAssetFile.YamlAsset>();

                // Find associations in scene
                foreach (var sceneAsset in sceneAssets)
                {
                    var hierarchy = sceneAsset.DynamicRootNode.Hierarchy;
                    foreach (dynamic entity in hierarchy.Entities)
                    {
                        var components         = entity.Entity.Components;
                        var animationComponent = components["AnimationComponent.Key"];
                        var model = components["ModelComponent.Key"]?.Model;
                        if (animationComponent != null && model != null)
                        {
                            var modelReference = DynamicYamlExtensions.ConvertTo <AssetReference>(model);
                            var modelAsset     = modelAssetsWithSekeleton.FirstOrDefault(x => x.Asset.AssetPath == modelReference.Location);

                            foreach (var animation in animationComponent.Animations)
                            {
                                var animationReference = DynamicYamlExtensions.ConvertTo <AssetReference>(animation.Value);
                                var animationAsset     = animAssets.FirstOrDefault(x => x.Asset.AssetPath == animationReference.Location);

                                if (modelAsset != null && animationAsset != null)
                                {
                                    animToModelMapping[animationAsset] = modelAsset;
                                }
                            }
                        }
                    }
                }

                // Find associations when sharing same source file
                foreach (var animationAsset in animAssets)
                {
                    // Comparing absolute path of assets
                    var modelAsset = modelAssetsWithSekeleton.FirstOrDefault(
                        x => UPath.Combine(animationAsset.Asset.AssetPath.GetParent(), new UFile((string)animationAsset.DynamicRootNode.Source))
                        == UPath.Combine(x.Asset.AssetPath.GetParent(), new UFile((string)x.DynamicRootNode.Source)));
                    if (modelAsset != null)
                    {
                        animToModelMapping[animationAsset] = modelAsset;
                    }
                }

                var modelToSkeletonMapping = new Dictionary <PackageLoadingAssetFile.YamlAsset, PackageLoadingAssetFile.YamlAsset>();

                // For each model asset, create skeleton assets
                foreach (var modelAsset in modelAssetsWithSekeleton)
                {
                    var skeletonAsset = new PackageLoadingAssetFile(modelAsset.Asset.FilePath.GetFullPathWithoutExtension() + " Skeleton.xkskel", modelAsset.Asset.SourceFolder)
                    {
                        AssetContent = System.Text.Encoding.UTF8.GetBytes("!Skeleton\r\nId: " + Guid.NewGuid())
                    };

                    using (var skeletonAssetYaml = skeletonAsset.AsYamlAsset())
                    {
                        // Set source
                        skeletonAssetYaml.DynamicRootNode.Source     = modelAsset.DynamicRootNode.Source;
                        skeletonAssetYaml.DynamicRootNode.SourceHash = modelAsset.DynamicRootNode.SourceHash;

                        // To be on the safe side, mark everything as preserved
                        var nodes = modelAsset.DynamicRootNode.Nodes;
                        foreach (var node in nodes)
                        {
                            node.Preserve = true;
                        }

                        skeletonAssetYaml.DynamicRootNode.Nodes       = nodes;
                        skeletonAssetYaml.DynamicRootNode.ScaleImport = modelAsset.DynamicRootNode.ScaleImport;

                        // Update model to point to this skeleton
                        modelAsset.DynamicRootNode.Skeleton = new AssetReference(AssetId.Parse((string)skeletonAssetYaml.DynamicRootNode.Id), skeletonAsset.AssetPath.MakeRelative(modelAsset.Asset.AssetPath.GetParent()));
                        modelToSkeletonMapping.Add(modelAsset, skeletonAssetYaml);
                    }

                    assetFiles.Add(skeletonAsset);
                }

                // Update animation to point to skeleton, and set preview default model
                foreach (var animToModelEntry in animToModelMapping)
                {
                    var animationAsset = animToModelEntry.Key;
                    var modelAsset     = animToModelEntry.Value;

                    var skeletonAsset = modelToSkeletonMapping[modelAsset];
                    animationAsset.DynamicRootNode.Skeleton     = new AssetReference(AssetId.Parse((string)skeletonAsset.DynamicRootNode.Id), skeletonAsset.Asset.AssetPath.MakeRelative(animationAsset.Asset.AssetPath.GetParent()));
                    animationAsset.DynamicRootNode.PreviewModel = new AssetReference(AssetId.Parse((string)modelAsset.DynamicRootNode.Id), modelAsset.Asset.AssetPath.MakeRelative(animationAsset.Asset.AssetPath.GetParent()));
                }

                // Remove Nodes from models
                foreach (var modelAsset in modelAssets)
                {
                    modelAsset.DynamicRootNode.Nodes = DynamicYamlEmpty.Default;
                    modelAsset.DynamicRootNode["~Base"].Asset.Nodes = DynamicYamlEmpty.Default;
                }

                // Save back
                foreach (var modelAsset in modelAssets)
                {
                    modelAsset.Dispose();
                }
                foreach (var animAsset in animAssets)
                {
                    animAsset.Dispose();
                }
            }

            if (dependency.Version.MinVersion < new PackageVersion("1.6.0-beta"))
            {
                // Delete EffectLogAsset
                foreach (var assetFile in assetFiles)
                {
                    if (assetFile.FilePath.GetFileName() == EffectLogAsset.DefaultFile)
                    {
                        assetFile.Deleted = true;
                    }
                }
            }

            if (dependency.Version.MinVersion < new PackageVersion("1.7.0-alpha02"))
            {
                foreach (var assetFile in assetFiles)
                {
                    if (!IsYamlAsset(assetFile))
                    {
                        continue;
                    }

                    using (var assetYaml = assetFile.AsYamlAsset())
                    {
                        if (assetYaml == null)
                        {
                            continue;
                        }

                        var sourceNode     = assetYaml.DynamicRootNode.Source;
                        var sourceHashNode = assetYaml.DynamicRootNode.SourceHash;
                        if (sourceHashNode != null)
                        {
                            var source     = DynamicYamlExtensions.ConvertTo <UFile>(sourceNode);
                            var sourceHash = DynamicYamlExtensions.ConvertTo <ObjectId>(sourceHashNode);
                            var dictionary = new Dictionary <UFile, ObjectId> {
                                { source, sourceHash }
                            };
                            var yamlDic = DynamicYamlExtensions.ConvertFrom(dictionary);
                            yamlDic.Node.Tag = null;
                            assetYaml.DynamicRootNode["~SourceHashes"] = yamlDic;
                            assetYaml.DynamicRootNode.SourceHash       = DynamicYamlEmpty.Default;
                        }
                        assetYaml.DynamicRootNode.ImporterId           = DynamicYamlEmpty.Default;
                        assetYaml.DynamicRootNode.SourceKeepSideBySide = DynamicYamlEmpty.Default;

                        var assetBase = assetYaml.DynamicRootNode["~Base"];
                        if (assetBase != null)
                        {
                            if (assetBase.Location == "--import--")
                            {
                                assetYaml.DynamicRootNode["~Base"] = DynamicYamlEmpty.Default;
                            }
                        }
                    }
                }
            }

            //Audio refactor
            if (dependency.Version.MinVersion < new PackageVersion("1.7.0-alpha03"))
            {
                var audioAssets = assetFiles.Where(f => f.FilePath.GetFileExtension() == ".xksnd").Select(x => x.AsYamlAsset()).ToArray();
                foreach (var assetFile in audioAssets)
                {
                    //dispose will save back
                    using (var assetYaml = assetFile)
                    {
                        if (assetYaml == null)
                        {
                            continue;
                        }

                        if (assetYaml.RootNode.Tag == "!SoundMusic")
                        {
                            assetYaml.RootNode.Tag = "!Sound";
                            assetYaml.DynamicRootNode.Spatialized    = false;
                            assetYaml.DynamicRootNode.StreamFromDisk = true;
                        }
                        else
                        {
                            assetYaml.RootNode.Tag = "!Sound";
                            assetYaml.DynamicRootNode.Spatialized    = true;
                            assetYaml.DynamicRootNode.StreamFromDisk = false;
                        }
                    }
                }
            }

            if (dependency.Version.MinVersion < new PackageVersion("1.7.0-alpha03"))
            {
                // Delete EffectLogAsset (now, most of it is auto generated automatically by drawing one frame of the game)
                foreach (var assetFile in assetFiles)
                {
                    if (assetFile.FilePath.GetFileName() == EffectLogAsset.DefaultFile)
                    {
                        assetFile.Deleted = true;
                    }
                }
            }

            if (dependency.Version.MinVersion < new PackageVersion("1.8.4-beta"))
            {
                // Add new generic parameter of MaterialSurfaceNormalMap to effect logs
                var regex = new Regex(@"(?<=ClassName:\s+MaterialSurfaceNormalMap\s+GenericArguments:\s+\[[^\]]*)(?=\])");
                foreach (var assetFile in assetFiles.Where(f => f.FilePath.GetFileExtension() == ".xkeffectlog"))
                {
                    var filePath = assetFile.FilePath;

                    // Load asset data, so the renamed file will have it's AssetContent set
                    if (assetFile.AssetContent == null)
                    {
                        assetFile.AssetContent = File.ReadAllBytes(filePath);
                    }

                    var sourceText      = System.Text.Encoding.UTF8.GetString(assetFile.AssetContent);
                    var newSourceText   = regex.Replace(sourceText, ", true");
                    var newAssetContent = System.Text.Encoding.UTF8.GetBytes(newSourceText);

                    if (newSourceText != sourceText)
                    {
                        assetFile.AssetContent = newAssetContent;
                    }

                    //File.WriteAllBytes(newFileName, newAssetContent);
                }
            }

            if (dependency.Version.MinVersion < new PackageVersion("1.9.0-beta"))
            {
                foreach (var assetFile in assetFiles)
                {
                    if (!IsYamlAsset(assetFile))
                    {
                        continue;
                    }

                    // This upgrader will also mark every yaml asset as dirty. We want to re-save everything with the new serialization system
                    using (var assetYaml = assetFile.AsYamlAsset())
                    {
                        if (assetYaml == null)
                        {
                            continue;
                        }

                        try
                        {
                            if (assetYaml.DynamicRootNode["~Base"] != null)
                            {
                                var location = ((YamlScalarNode)assetYaml.DynamicRootNode["~Base"].Location.Node).Value;
                                if (location != "--import--")
                                {
                                    var id       = ((YamlScalarNode)assetYaml.DynamicRootNode["~Base"].Asset.Id.Node).Value;
                                    var assetUrl = $"{id}:{location}";
                                    assetYaml.DynamicRootNode["Archetype"] = assetUrl;
                                }
                                assetYaml.DynamicRootNode["~Base"] = DynamicYamlEmpty.Default;
                            }
                        }
                        catch
                        (Exception e)
                        {
                            e.Ignore();
                        }
                    }
                }
            }

            return(true);
        }
Beispiel #28
0
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
            {
                // SerializedVersion format changed during renaming upgrade. However, before this was merged back in master, some asset upgrader still with older version numbers were developed.
                var proceduralType = asset.Type;

                if (proceduralType.Node.Tag == "!ConeProceduralModel" && currentVersion != PackageVersion.Parse("0.0.6"))
                {
                    if (proceduralType.LocalOffset == null)
                    {
                        dynamic offset = new DynamicYamlMapping(new YamlMappingNode());
                        offset.AddChild("X", 0.0f);
                        offset.AddChild("Y", 0.5f);
                        offset.AddChild("Z", 0.0f);
                        proceduralType.AddChild("LocalOffset", offset);
                    }
                }
            }
Beispiel #29
0
 protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
 {
     if (asset.ScaleImport != null && (float)asset.ScaleImport == 0.0f)
     {
         asset.RemoveChild("ScaleImport");
     }
 }
Beispiel #30
0
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
            {
                var proceduralType = asset.Type;

                if (proceduralType.Node.Tag == "!CapsuleProceduralModel" && proceduralType.Height != null)
                {
                    proceduralType.Length = 2f * (float)proceduralType.Height;
                    proceduralType.Height = DynamicYamlEmpty.Default;
                }
            }
Beispiel #31
0
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile,
                                                 OverrideUpgraderHint overrideHint)
            {
                var basePartMapping = new Dictionary <string, string>();

                if (asset["~BaseParts"] != null)
                {
                    foreach (dynamic basePart in asset["~BaseParts"])
                    {
                        try
                        {
                            var location = ((YamlScalarNode)basePart.Location.Node).Value;
                            var id       = ((YamlScalarNode)basePart.Asset.Id.Node).Value;
                            var assetUrl = $"{id}:{location}";

                            foreach (dynamic part in basePart.Asset.Hierarchy.Parts)
                            {
                                try
                                {
                                    var partId = ((YamlScalarNode)part.UIElement.Id.Node).Value;
                                    basePartMapping[partId] = assetUrl;
                                }
                                catch (Exception e)
                                {
                                    e.Ignore();
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            e.Ignore();
                        }
                    }
                    asset["~BaseParts"] = DynamicYamlEmpty.Default;
                }
                var uiElements = (DynamicYamlArray)asset.Hierarchy.Parts;

                foreach (dynamic uiDesign in uiElements)
                {
                    if (uiDesign.BaseId != null)
                    {
                        try
                        {
                            var    baseId         = ((YamlScalarNode)uiDesign.BaseId.Node).Value;
                            var    baseInstanceId = ((YamlScalarNode)uiDesign.BasePartInstanceId.Node).Value;
                            string assetUrl;
                            if (basePartMapping.TryGetValue(baseId, out assetUrl))
                            {
                                var baseNode = (dynamic)(new DynamicYamlMapping(new YamlMappingNode()));
                                baseNode.BasePartAsset = assetUrl;
                                baseNode.BasePartId    = baseId;
                                baseNode.InstanceId    = baseInstanceId;
                                uiDesign.Base          = baseNode;
                            }
                            uiDesign.BaseId             = DynamicYamlEmpty.Default;
                            uiDesign.BasePartInstanceId = DynamicYamlEmpty.Default;
                        }
                        catch (Exception e)
                        {
                            e.Ignore();
                        }
                    }
                }
            }
Beispiel #32
0
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile,
                                                 OverrideUpgraderHint overrideHint)
            {
                dynamic settings = new DynamicYamlMapping(new YamlMappingNode {
                    Tag = "!Xenko.Streaming.StreamingSettings,Xenko.Engine"
                });

                asset.Defaults.Add(settings);
            }
Beispiel #33
0
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
            {
                YamlNode assetNode = asset.Node;

                foreach (var node in assetNode.AllNodes)
                {
                    if (node.Tag == "!Xenko.Streaming.StreamingSettings,Xenko.Engine")
                    {
                        node.Tag = node.Tag.Replace(",Xenko.Engine", ",Xenko.Rendering");
                    }
                }
            }
            protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile, OverrideUpgraderHint overrideHint)
            {
                if (asset.ColliderShapes == null)
                {
                    return;
                }

                foreach (var colliderShape in asset.ColliderShapes)
                {
                    if (colliderShape.Node.Tag == "!Box2DColliderShapeDesc")
                    {
                        var size = 2f * DynamicYamlExtensions.ConvertTo <Vector2>(colliderShape.HalfExtent);
                        colliderShape.Size       = DynamicYamlExtensions.ConvertFrom(size);
                        colliderShape.HalfExtent = DynamicYamlEmpty.Default;
                    }
                    if (colliderShape.Node.Tag == "!BoxColliderShapeDesc")
                    {
                        var size = 2f * DynamicYamlExtensions.ConvertTo <Vector3>(colliderShape.HalfExtents);
                        colliderShape.Size        = DynamicYamlExtensions.ConvertFrom(size);
                        colliderShape.HalfExtents = DynamicYamlEmpty.Default;
                    }
                    if (colliderShape.Node.Tag == "!CapsuleColliderShapeDesc" || colliderShape.Node.Tag == "!CylinderColliderShapeDesc")
                    {
                        var upVector = DynamicYamlExtensions.ConvertTo <Vector3>(colliderShape.UpAxis);
                        if (upVector == Vector3.UnitX)
                        {
                            colliderShape.Orientation = ShapeOrientation.UpX;
                        }
                        if (upVector == Vector3.UnitZ)
                        {
                            colliderShape.Orientation = ShapeOrientation.UpZ;
                        }

                        colliderShape.UpAxis = DynamicYamlEmpty.Default;
                    }
                    if (colliderShape.Node.Tag == "!CapsuleColliderShapeDesc" && colliderShape.Height != null)
                    {
                        colliderShape.Length = 2f * (float)colliderShape.Height;
                        colliderShape.Height = DynamicYamlEmpty.Default;
                    }
                    if (colliderShape.Node.Tag == "!CylinderColliderShapeDesc")
                    {
                        colliderShape.Radius      = (float)colliderShape.HalfExtents.X;
                        colliderShape.Height      = 2f * (float)colliderShape.HalfExtents.Y;
                        colliderShape.HalfExtents = DynamicYamlEmpty.Default;
                    }
                }
            }
 /// <inheritdoc/>
 protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile)
 {
 }