Exemple #1
0
        public void TestWithSimplePathWithExtension()
        {
            var assetPath = new UFile("/a/b/c.txt");

            Assert.Equal("/a/b", assetPath.GetDirectory());
            Assert.Equal("c", assetPath.GetFileNameWithoutExtension());
            Assert.Equal(".txt", assetPath.GetFileExtension());
            Assert.Equal("/a/b/c", assetPath.GetDirectoryAndFileNameWithoutExtension());
            Assert.Equal("/a/b/c.txt", assetPath.FullPath);
        }
Exemple #2
0
        public void TestWithSimplePath()
        {
            var assetPath = new UFile("/a/b/c");

            Assert.AreEqual("/a/b", assetPath.GetDirectory());
            Assert.AreEqual("c", assetPath.GetFileName());
            Assert.AreEqual(null, assetPath.GetFileExtension());
            Assert.AreEqual("/a/b/c", assetPath.GetDirectoryAndFileName());
            Assert.AreEqual("/a/b/c", assetPath.FullPath);
        }
Exemple #3
0
        public void TestIsDirectoryOnly()
        {
            var dirPath = new UDirectory("/a/b/c");

            Assert.Equal("/a/b/c", dirPath.GetDirectory());

            var filePath = new UFile("/test.txt");

            Assert.Equal("/", filePath.GetDirectory());
            Assert.Equal("test.txt", filePath.GetFileName());
        }
Exemple #4
0
        public void TestIsDirectoryOnly()
        {
            Assert.False(new UFile("/a/b/c.txt").IsDirectoryOnly);

            var dirPath = new UDirectory("/a/b/c");

            Assert.True(dirPath.IsDirectoryOnly);
            Assert.AreEqual("/a/b/c", dirPath.GetDirectory());

            var filePath = new UFile("/test.txt");

            Assert.AreEqual("/", filePath.GetDirectory());
            Assert.AreEqual("test.txt", filePath.GetFileNameWithExtension());
        }
Exemple #5
0
        public void TestWithNormalization()
        {
            var assetPath = new UFile("/a/b/.././././//c.txt");

            Assert.Equal("/a", assetPath.GetDirectory());
            Assert.Equal("c", assetPath.GetFileNameWithoutExtension());
            Assert.Equal(".txt", assetPath.GetFileExtension());
            Assert.Equal("/a/c", assetPath.GetDirectoryAndFileNameWithoutExtension());
            Assert.Equal("/a/c.txt", assetPath.FullPath);

            assetPath = new UFile("../.././././//c.txt");
            Assert.Equal("../..", assetPath.GetDirectory());
            Assert.Equal("c", assetPath.GetFileNameWithoutExtension());
            Assert.Equal(".txt", assetPath.GetFileExtension());
            Assert.Equal("../../c", assetPath.GetDirectoryAndFileNameWithoutExtension());
            Assert.Equal("../../c.txt", assetPath.FullPath);

            assetPath = new UFile("a/../../../c.txt");
            Assert.Equal("../../c.txt", assetPath.FullPath);
        }
 private static string GenerateSeparateTextureURL(UFile originalLocation, string suffixName)
 {
     return(originalLocation.GetDirectory() + "/" + SplittedTextureNamePrefix + originalLocation.GetFileName() + suffixName);
 }
Exemple #7
0
        public void TestWithNormalization()
        {
            var assetPath = new UFile("/a/b/.././././//c.txt");
            Assert.AreEqual("/a", assetPath.GetDirectory());
            Assert.AreEqual("c", assetPath.GetFileName());
            Assert.AreEqual(".txt", assetPath.GetFileExtension());
            Assert.AreEqual("/a/c", assetPath.GetDirectoryAndFileName());
            Assert.AreEqual("/a/c.txt", assetPath.FullPath);

            assetPath = new UFile("../.././././//c.txt");
            Assert.AreEqual("../..", assetPath.GetDirectory());
            Assert.AreEqual("c", assetPath.GetFileName());
            Assert.AreEqual(".txt", assetPath.GetFileExtension());
            Assert.AreEqual("../../c", assetPath.GetDirectoryAndFileName());
            Assert.AreEqual("../../c.txt", assetPath.FullPath);

            assetPath = new UFile("a/../../../c.txt");
            Assert.AreEqual("../../c.txt", assetPath.FullPath);
        }
Exemple #8
0
 public void TestWithSimplePathWithExtension()
 {
     var assetPath = new UFile("/a/b/c.txt");
     Assert.AreEqual("/a/b", assetPath.GetDirectory());
     Assert.AreEqual("c", assetPath.GetFileName());
     Assert.AreEqual(".txt", assetPath.GetFileExtension());
     Assert.AreEqual("/a/b/c", assetPath.GetDirectoryAndFileName());
     Assert.AreEqual("/a/b/c.txt", assetPath.FullPath);
 }
Exemple #9
0
        public void TestIsDirectoryOnly()
        {
            Assert.False(new UFile("/a/b/c.txt").IsDirectoryOnly);

            var dirPath = new UDirectory("/a/b/c");
            Assert.True(dirPath.IsDirectoryOnly);
            Assert.AreEqual("/a/b/c", dirPath.GetDirectory());

            var filePath = new UFile("/test.txt");
            Assert.AreEqual("/", filePath.GetDirectory());
            Assert.AreEqual("test.txt", filePath.GetFileNameWithExtension());
        }
Exemple #10
0
            protected override Task <ResultStatus> DoCommandOverride(ICommandContext commandContext)
            {
                var material = asset.Material.Clone();

                // Replace all empty Texture nodes by black color texture nodes (allow a display of the element even if material is incomplete)
                var emptyTextureNodeKeys = material.Nodes.Where(m => m.Value is MaterialTextureNode && !IsTextureReferenceValid((MaterialTextureNode)m.Value)).Select(m => m.Key).ToList();

                foreach (var emptyTextureNodeKey in emptyTextureNodeKeys)
                {
                    commandContext.Logger.Warning("Texture node '{0}' of material '{1}' is not pointing to a valid texture reference. " +
                                                  "This node will be replaced by black color Node.", emptyTextureNodeKey, assetItem.Location);
                    material.Nodes[emptyTextureNodeKey] = new MaterialColorNode(new Color4(0));
                }

                // Reduce trees on CPU
                var materialReducer = new MaterialTreeReducer(material);

                materialReducer.ReduceTrees();

                foreach (var reducedTree in materialReducer.ReducedTrees)
                {
                    material.Nodes[reducedTree.Key] = reducedTree.Value;
                }

                // Reduce on GPU
                // TODO: Adapt GPU reduction so that it is compatible Android color/alpha separation
                // TODO: Use the build engine processed output textures instead of the imported one (not existing any more)
                // TODO: Set the reduced texture output format
                // TODO: The graphics device cannot be shared with the Previewer
                //var graphicsDevice = (GraphicsDevice)context.Attributes.GetOrAdd(CompilerContext.GraphicsDeviceKey, key => GraphicsDevice.New(DeviceCreationFlags.None, GraphicsProfile.Level_11_0));
                //using (var materialTextureLayerFlattener = new MaterialTextureLayerFlattener(material, graphicsDevice))
                //{
                //    materialTextureLayerFlattener.PrepareForFlattening(new UDirectory(assetUrl.Directory));
                //    if (materialTextureLayerFlattener.HasCommands)
                //    {
                //        var compiler = EffectCompileCommand.GetOrCreateEffectCompiler(context);
                //        materialTextureLayerFlattener.Run(compiler);
                //        // store Material with modified textures
                //        material = materialTextureLayerFlattener.Material;
                //    }
                //}

                // Separate the textures into color/alpha components on Android to be able to use native ETC1 compression
                if (context.Platform == PlatformType.Android)
                {
                    var alphaComponentSplitter = new TextureAlphaComponentSplitter(assetItem.Package.Session);
                    material = alphaComponentSplitter.Run(material, new UDirectory(assetUrl.GetDirectory())); // store Material with alpha substituted textures
                }

                // Create the parameters
                var materialParameterCreator = new MaterialParametersCreator(material, assetUrl);

                if (materialParameterCreator.CreateParameterCollectionData(commandContext.Logger))
                {
                    return(Task.FromResult(ResultStatus.Failed));
                }

                var materialData = new MaterialData {
                    Parameters = materialParameterCreator.Parameters
                };

                var assetManager = new AssetManager();

                assetManager.Save(assetUrl, materialData);

                return(Task.FromResult(ResultStatus.Successful));
            }