コード例 #1
0
ファイル: TestAssetImport.cs プロジェクト: zerodowned/paradox
        public void TestImportWithDuplicateWithinSameSession()
        {
            var          name        = "TestAssetImport";
            var          file        = Path.Combine(Path.GetTempPath(), name + ".tmp");
            const string fileContent = "This is the file content";

            File.WriteAllText(file, fileContent);

            var fileHash = ObjectId.FromBytes(Encoding.UTF8.GetBytes(fileContent));

            // Create a project with an asset reference a raw file
            var project = new Package();

            using (var session = new PackageSession(project))
            {
                var importSession = new AssetImportSession(session);

                // ------------------------------------------------------------------
                // Step 1: Add files to session
                // ------------------------------------------------------------------
                importSession.AddFile(file, project, UDirectory.Empty);
                // Simulate using another importer to duplicate the assets
                importSession.AddFile(file, new CustomImporter(), project, UDirectory.Empty);
                Assert.AreEqual(2, importSession.Imports[0].ByImporters.Count);

                // ------------------------------------------------------------------
                // Step 2: Stage assets
                // ------------------------------------------------------------------
                var stageResult = importSession.Stage();

                //importSession.Imports[0].ByImporters[1].Items[0].SelectedItem = importSession.Imports[0].ByImporters[1].Items[0].Merges[0].PreviousItem;
                // Merge 0 into 1
                importSession.Imports[0].ByImporters[0].Items[0].SelectedItem = importSession.Imports[0].ByImporters[0].Items[0].Merges[0].PreviousItem;

                // ------------------------------------------------------------------
                // Step 4: Merge the asset specified by the previous step
                // ------------------------------------------------------------------
                importSession.Merge();

                Assert.IsTrue(stageResult);

                // ------------------------------------------------------------------
                // Step 3: Import merged asset
                // ------------------------------------------------------------------
                var result = importSession.Import();
                Assert.AreEqual(3, project.Assets.Count);

                // TODO Add more tests
            }
        }
コード例 #2
0
ファイル: TestAssetImport.cs プロジェクト: Powerino73/paradox
        public void TestImportSessionSimple()
        {
            var name = "TestAssetImport";
            var file = Path.Combine(Path.GetTempPath(), name + ".tmp");
            const string fileContent = "This is the file content";
            File.WriteAllText(file, fileContent);
            var fileHash = ObjectId.FromBytes(Encoding.UTF8.GetBytes(fileContent));

            // Create a project with an asset reference a raw file
            var project = new Package();
            using (var session = new PackageSession(project))
            {
                var importSession = new AssetImportSession(session);

                // ------------------------------------------------------------------
                // Step 1: Add files to session
                // ------------------------------------------------------------------
                importSession.AddFile(file, project, UDirectory.Empty);

                // ------------------------------------------------------------------
                // Step 2: Stage assets
                // ------------------------------------------------------------------
                var stageResult = importSession.Stage();
                Assert.IsTrue(stageResult);
                Assert.AreEqual(0, project.Assets.Count);

                // ------------------------------------------------------------------
                // Step 3: Import asset directly (we don't try to merge)
                // ------------------------------------------------------------------
                importSession.Import();
                Assert.AreEqual(2, project.Assets.Count);
                var assetItem = project.Assets.FirstOrDefault(item => item.Asset is AssetImport);
                Assert.NotNull(assetItem);
                var importedAsset = (AssetImport)assetItem.Asset;

                Assert.IsInstanceOf<AssetImport>(importedAsset.Base.Asset);
                Assert.AreEqual((string)AssetBase.DefaultImportBase, importedAsset.Base.Location);

                // ------------------------------------------------------------------
                // Reset the import session
                // ------------------------------------------------------------------
                importSession.Reset();

                // Get the list of asset already in the project
                var ids = project.Assets.Select(item => item.Id).ToList();
                ids.Sort();

                // ------------------------------------------------------------------
                // Step 1: Add same file to the session
                // ------------------------------------------------------------------
                importSession.AddFile(file, project, UDirectory.Empty);

                // ------------------------------------------------------------------
                // Step 2: Stage assets
                // ------------------------------------------------------------------
                stageResult = importSession.Stage();

                // Select the previous item so that we will perform a merge
                foreach (var fileToImport in importSession.Imports)
                {
                    foreach (var import in fileToImport.ByImporters)
                    {
                        foreach (var assetImportMergeGroup in import.Items)
                        {
                            Assert.AreEqual(1, assetImportMergeGroup.Merges.Count);

                            // Check that we are matching correctly a previously imported asset
                            var previousItem = assetImportMergeGroup.Merges[0].PreviousItem;
                            Assert.IsTrue(project.Assets.ContainsById(previousItem.Id));

                            // Select the previous asset
                            assetImportMergeGroup.SelectedItem = previousItem;
                        }
                    }
                }

                // ------------------------------------------------------------------
                // Step 3: Merge the asset specified by the previous step
                // ------------------------------------------------------------------
                importSession.Merge();

                Assert.IsTrue(stageResult);
                Assert.AreEqual(2, project.Assets.Count);

                // ------------------------------------------------------------------
                // Step 4: Import merged asset
                // ------------------------------------------------------------------
                importSession.Import();
                Assert.AreEqual(2, project.Assets.Count);

                // Get the list of asset already in the project
                var newIds = project.Assets.Select(item => item.Id).ToList();
                newIds.Sort();

                // Check that we have exactly the same number of assets
                Assert.AreEqual(ids, newIds);

                // Check that new AssetObjectTestRaw.Value is setup to the new value (1, was previously 0)
                var assetRaw = project.Assets.Select(item => item.Asset).OfType<AssetObjectTestSub>().FirstOrDefault();
                Assert.IsNotNull(assetRaw);
                Assert.IsNotNull(assetRaw.Base);
                Assert.IsInstanceOf<AssetObjectTestSub>(assetRaw.Base.Asset);

                var assetRawBase = (AssetObjectTestSub)assetRaw.Base.Asset;
                Assert.AreEqual(1, assetRaw.Value);
                Assert.AreEqual(1, assetRawBase.Value);
            }
        }
コード例 #3
0
ファイル: TestAssetImport.cs プロジェクト: Powerino73/paradox
        public void TestImportWithDuplicateWithinSameSession()
        {
            var name = "TestAssetImport";
            var file = Path.Combine(Path.GetTempPath(), name + ".tmp");
            const string fileContent = "This is the file content";
            File.WriteAllText(file, fileContent);

            var fileHash = ObjectId.FromBytes(Encoding.UTF8.GetBytes(fileContent));

            // Create a project with an asset reference a raw file
            var project = new Package();
            using (var session = new PackageSession(project))
            {
                var importSession = new AssetImportSession(session);

                // ------------------------------------------------------------------
                // Step 1: Add files to session
                // ------------------------------------------------------------------
                importSession.AddFile(file, project, UDirectory.Empty);
                // Simulate using another importer to duplicate the assets
                importSession.AddFile(file, new CustomImporter(), project, UDirectory.Empty);
                Assert.AreEqual(2, importSession.Imports[0].ByImporters.Count);

                // ------------------------------------------------------------------
                // Step 2: Stage assets
                // ------------------------------------------------------------------
                var stageResult = importSession.Stage();

                //importSession.Imports[0].ByImporters[1].Items[0].SelectedItem = importSession.Imports[0].ByImporters[1].Items[0].Merges[0].PreviousItem;
                // Merge 0 into 1
                importSession.Imports[0].ByImporters[0].Items[0].SelectedItem = importSession.Imports[0].ByImporters[0].Items[0].Merges[0].PreviousItem;

                // ------------------------------------------------------------------
                // Step 4: Merge the asset specified by the previous step
                // ------------------------------------------------------------------
                importSession.Merge();

                Assert.IsTrue(stageResult);

                // ------------------------------------------------------------------
                // Step 3: Import merged asset
                // ------------------------------------------------------------------
                var result = importSession.Import();
                Assert.AreEqual(3, project.Assets.Count);

                // TODO Add more tests
            }
        }
コード例 #4
0
ファイル: TestModelAsset.cs プロジェクト: Powerino73/paradox
        public void TestImportModelSimple()
        {
            var file = Path.Combine(Environment.CurrentDirectory, @"scenes\goblin.fbx");

            // Create a project with an asset reference a raw file
            var project = new Package { FullPath = Path.Combine(Environment.CurrentDirectory, "ModelAssets", "ModelAssets" + Package.PackageFileExtension) };
            using (var session = new PackageSession(project))
            {
                var importSession = new AssetImportSession(session);

                // ------------------------------------------------------------------
                // Step 1: Add files to session
                // ------------------------------------------------------------------
                importSession.AddFile(file, project, UDirectory.Empty);

                // ------------------------------------------------------------------
                // Step 2: Stage assets
                // ------------------------------------------------------------------
                var stageResult = importSession.Stage();
                Assert.IsTrue(stageResult);
                Assert.AreEqual(0, project.Assets.Count);

                // ------------------------------------------------------------------
                // Step 3: Import asset directly
                // ------------------------------------------------------------------
                importSession.Import();
                Assert.AreEqual(4, project.Assets.Count);
                var assetItem = project.Assets.FirstOrDefault(item => item.Asset is EntityAsset);
                Assert.NotNull(assetItem);

                EntityAnalysis.UpdateEntityReferences(((EntityAsset)assetItem.Asset).Hierarchy);

                var assetCollection = new AssetItemCollection();
                // Remove directory from the location
                assetCollection.Add(assetItem);

                Console.WriteLine(assetCollection.ToText());

                //session.Save();

                // Create and mount database file system
                var objDatabase = new ObjectDatabase("/data/db", "index", "/local/db");
                var databaseFileProvider = new DatabaseFileProvider(objDatabase);
                AssetManager.GetFileProvider = () => databaseFileProvider;

                ((EntityAsset)assetItem.Asset).Hierarchy.Entities[0].Components.RemoveWhere(x => x.Key != TransformComponent.Key);
                //((EntityAsset)assetItem.Asset).Data.Entities[1].Components.RemoveWhere(x => x.Key != SiliconStudio.Paradox.Engine.TransformComponent.Key);

                var assetManager = new AssetManager();
                assetManager.Save("Entity1", ((EntityAsset)assetItem.Asset).Hierarchy);

                assetManager = new AssetManager();
                var entity = assetManager.Load<Entity>("Entity1");

                var entity2 = entity.Clone();

                var entityAsset = (EntityAsset)assetItem.Asset;
                entityAsset.Hierarchy.Entities[0].Components.Add(TransformComponent.Key, new TransformComponent());

                var entityAsset2 = (EntityAsset)AssetCloner.Clone(entityAsset);
                entityAsset2.Hierarchy.Entities[0].Components.Get(TransformComponent.Key).Position = new Vector3(10.0f, 0.0f, 0.0f);

                AssetMerge.Merge(entityAsset, entityAsset2, null, AssetMergePolicies.MergePolicyAsset2AsNewBaseOfAsset1);
            }
        }
コード例 #5
0
        [Test, Ignore] // ignore the test as long as EntityAsset is not created during import anymore
        public void TestImportModelSimple()
        {
            var file = Path.Combine(Environment.CurrentDirectory, @"scenes\goblin.fbx");

            // Create a project with an asset reference a raw file
            var project = new Package {
                FullPath = Path.Combine(Environment.CurrentDirectory, "ModelAssets", "ModelAssets" + Package.PackageFileExtension)
            };

            using (var session = new PackageSession(project))
            {
                var importSession = new AssetImportSession(session);

                // ------------------------------------------------------------------
                // Step 1: Add files to session
                // ------------------------------------------------------------------
                importSession.AddFile(file, project, UDirectory.Empty);

                // ------------------------------------------------------------------
                // Step 2: Stage assets
                // ------------------------------------------------------------------
                var stageResult = importSession.Stage();
                Assert.IsTrue(stageResult);
                Assert.AreEqual(0, project.Assets.Count);

                // ------------------------------------------------------------------
                // Step 3: Import asset directly
                // ------------------------------------------------------------------
                importSession.Import();
                Assert.AreEqual(4, project.Assets.Count);
                var assetItem = project.Assets.FirstOrDefault(item => item.Asset is EntityAsset);
                Assert.NotNull(assetItem);

                EntityAnalysis.UpdateEntityReferences(((EntityAsset)assetItem.Asset).Hierarchy);

                var assetCollection = new AssetItemCollection();
                // Remove directory from the location
                assetCollection.Add(assetItem);

                Console.WriteLine(assetCollection.ToText());

                //session.Save();

                // Create and mount database file system
                var objDatabase          = new ObjectDatabase("/data/db", "index", "/local/db");
                var databaseFileProvider = new DatabaseFileProvider(objDatabase);
                AssetManager.GetFileProvider = () => databaseFileProvider;

                ((EntityAsset)assetItem.Asset).Hierarchy.Entities[0].Components.RemoveWhere(x => x.Key != TransformComponent.Key);
                //((EntityAsset)assetItem.Asset).Data.Entities[1].Components.RemoveWhere(x => x.Key != SiliconStudio.Paradox.Engine.TransformComponent.Key);

                var assetManager = new AssetManager();
                assetManager.Save("Entity1", ((EntityAsset)assetItem.Asset).Hierarchy);

                assetManager = new AssetManager();
                var entity = assetManager.Load <Entity>("Entity1");

                var entity2 = entity.Clone();

                var entityAsset = (EntityAsset)assetItem.Asset;
                entityAsset.Hierarchy.Entities[0].Components.Add(TransformComponent.Key, new TransformComponent());

                var entityAsset2 = (EntityAsset)AssetCloner.Clone(entityAsset);
                entityAsset2.Hierarchy.Entities[0].Components.Get(TransformComponent.Key).Position = new Vector3(10.0f, 0.0f, 0.0f);

                AssetMerge.Merge(entityAsset, entityAsset2, null, AssetMergePolicies.MergePolicyAsset2AsNewBaseOfAsset1);
            }
        }
コード例 #6
0
ファイル: TestAssetImport.cs プロジェクト: zerodowned/paradox
        public void TestImportSessionSimple()
        {
            var          name        = "TestAssetImport";
            var          file        = Path.Combine(Path.GetTempPath(), name + ".tmp");
            const string fileContent = "This is the file content";

            File.WriteAllText(file, fileContent);
            var fileHash = ObjectId.FromBytes(Encoding.UTF8.GetBytes(fileContent));

            // Create a project with an asset reference a raw file
            var project = new Package();

            using (var session = new PackageSession(project))
            {
                var importSession = new AssetImportSession(session);

                // ------------------------------------------------------------------
                // Step 1: Add files to session
                // ------------------------------------------------------------------
                importSession.AddFile(file, project, UDirectory.Empty);

                // ------------------------------------------------------------------
                // Step 2: Stage assets
                // ------------------------------------------------------------------
                var stageResult = importSession.Stage();
                Assert.IsTrue(stageResult);
                Assert.AreEqual(0, project.Assets.Count);

                // ------------------------------------------------------------------
                // Step 3: Import asset directly (we don't try to merge)
                // ------------------------------------------------------------------
                importSession.Import();
                Assert.AreEqual(2, project.Assets.Count);
                var assetItem = project.Assets.FirstOrDefault(item => item.Asset is AssetImport);
                Assert.NotNull(assetItem);
                var importedAsset = (AssetImport)assetItem.Asset;

                Assert.IsInstanceOf <AssetImport>(importedAsset.Base.Asset);
                Assert.AreEqual((string)AssetBase.DefaultImportBase, importedAsset.Base.Location);

                // ------------------------------------------------------------------
                // Reset the import session
                // ------------------------------------------------------------------
                importSession.Reset();

                // Get the list of asset already in the project
                var ids = project.Assets.Select(item => item.Id).ToList();
                ids.Sort();

                // ------------------------------------------------------------------
                // Step 1: Add same file to the session
                // ------------------------------------------------------------------
                importSession.AddFile(file, project, UDirectory.Empty);

                // ------------------------------------------------------------------
                // Step 2: Stage assets
                // ------------------------------------------------------------------
                stageResult = importSession.Stage();

                // Select the previous item so that we will perform a merge
                foreach (var fileToImport in importSession.Imports)
                {
                    foreach (var import in fileToImport.ByImporters)
                    {
                        foreach (var assetImportMergeGroup in import.Items)
                        {
                            Assert.AreEqual(1, assetImportMergeGroup.Merges.Count);

                            // Check that we are matching correctly a previously imported asset
                            var previousItem = assetImportMergeGroup.Merges[0].PreviousItem;
                            Assert.IsTrue(project.Assets.ContainsById(previousItem.Id));

                            // Select the previous asset
                            assetImportMergeGroup.SelectedItem = previousItem;
                        }
                    }
                }

                // ------------------------------------------------------------------
                // Step 3: Merge the asset specified by the previous step
                // ------------------------------------------------------------------
                importSession.Merge();

                Assert.IsTrue(stageResult);
                Assert.AreEqual(2, project.Assets.Count);

                // ------------------------------------------------------------------
                // Step 4: Import merged asset
                // ------------------------------------------------------------------
                importSession.Import();
                Assert.AreEqual(2, project.Assets.Count);

                // Get the list of asset already in the project
                var newIds = project.Assets.Select(item => item.Id).ToList();
                newIds.Sort();

                // Check that we have exactly the same number of assets
                Assert.AreEqual(ids, newIds);

                // Check that new AssetObjectTestRaw.Value is setup to the new value (1, was previously 0)
                var assetRaw = project.Assets.Select(item => item.Asset).OfType <AssetObjectTestSub>().FirstOrDefault();
                Assert.IsNotNull(assetRaw);
                Assert.IsNotNull(assetRaw.Base);
                Assert.IsInstanceOf <AssetObjectTestSub>(assetRaw.Base.Asset);

                var assetRawBase = (AssetObjectTestSub)assetRaw.Base.Asset;
                Assert.AreEqual(1, assetRaw.Value);
                Assert.AreEqual(1, assetRawBase.Value);
            }
        }