Ejemplo n.º 1
0
    public void CanParseEscapedBackslashesInSamplerPathOfGeneralMaterial()
    {
        var parser   = new MdfParser("dummy", @"General
Texture 0 ""folder\\filename.tga""
");
        var material = parser.Parse();

        Assert.AreEqual(MdfType.General, material.type);
        Assert.AreEqual(@"folder\filename.tga", material.samplers[0].filename);
    }
Ejemplo n.º 2
0
    public void CanParseSimpleTexturedMaterial()
    {
        var parser   = new MdfParser("dummy", @"Textured
Texture ""folder/filename.tga""
");
        var material = parser.Parse();

        Assert.AreEqual(MdfType.Textured, material.type);
        Assert.AreEqual(@"folder/filename.tga", material.samplers[0].filename);
    }
    public ResourceRef <IMdfRenderMaterial> LoadMaterial(string name, Action <MdfMaterial> customizer = null)
    {
        var nameLower = name.ToLowerInvariant();

        // Do not cache if a customizer is present
        if (customizer == null && mNameRegistry.TryGetValue(name, out var materialRef))
        {
            return(materialRef.CloneRef());
        }

        try {
            var mdfContent  = _fs.ReadTextFile(name);
            var parser      = new MdfParser(name, mdfContent);
            var mdfMaterial = parser.Parse();
            customizer?.Invoke(mdfMaterial);

            Trace.Assert(_nextFreeId >= 1);
            // Assign ID
            var id = _nextFreeId++;

            var material = CreateDeviceMaterial(name, mdfMaterial);

            using var result = new ResourceRef <IMdfRenderMaterial>(
                      new MdfRenderMaterial(id, name, mdfMaterial, material)
                      );

            mIdRegistry[id] = result.CloneRef();
            if (customizer == null)
            {
                mNameRegistry[nameLower] = result.CloneRef();
            }

            return(result.CloneRef());
        } catch (Exception e) {
            Logger.Error("Unable to load MDF file '{0}': {1} {2}", name, e.GetType(), e.Message);
            return(new ResourceRef <IMdfRenderMaterial>(InvalidMdfRenderMaterial.Instance));
        }
    }