Example #1
0
    public void Awake()
    {
        shapeTextureStorage   = new TextureStorage();
        specialTextureStorage = new TextureStorage();
        MaterialTextures      = new MaterialMatcher <MaterialTextureSet>();

        DefaultShapeTexIndex   = shapeTextureStorage.AddTexture(CreateFlatTexture(new Color(1f, 0.5f, 1f, 0.5f)));
        defaultSpecialTexIndex = specialTextureStorage.AddTexture(Texture2D.blackTexture);
    }
Example #2
0
    public void Awake()
    {
        _routiner = this;

        shapeTextureStorage   = new TextureStorage();
        specialTextureStorage = new TextureStorage();

        Debug.Log("Compiling material shape textures.");
        shapeTextureStorage.AddTextureArray(Resources.Load <Texture2DArray>("shapeTextures"));

        DefaultShapeTexIndex   = shapeTextureStorage.AddTexture(CreateFlatTexture(new Color(1f, 0.5f, 1f, 0.5f)));
        defaultSpecialTexIndex = specialTextureStorage.AddTexture(Texture2D.blackTexture);
    }
Example #3
0
    public ContentLoader()
    {
        materialTextureStorage = new TextureStorage();
        shapeTextureStorage    = new TextureStorage();
        specialTextureStorage  = new TextureStorage();
        materialColors         = new MaterialMatcher <ColorContent>();
        materialTextures       = new MaterialMatcher <TextureContent>();



        defaultMatTexIndex     = materialTextureStorage.AddTexture(CreateFlatTexture(new Color(0.5f, 0.5f, 0.5f, 0)));
        defaultShapeTexIndex   = shapeTextureStorage.AddTexture(CreateFlatTexture(new Color(1f, 0.5f, 1f, 0.5f)));
        defaultSpecialTexIndex = specialTextureStorage.AddTexture(Texture2D.blackTexture);
    }
Example #4
0
    public bool AddTypeElement(XElement elemtype)
    {
        XAttribute normalAtt = elemtype.Attribute("normal");
        Texture2D  normalMap = ContentLoader.LoadTexture(normalAtt, elemtype, new Color(0.5f, 0.5f, 1f), true);

        XAttribute alphaAtt = elemtype.Attribute("alpha");
        Texture2D  alphaMap = ContentLoader.LoadTexture(alphaAtt, elemtype, Color.white, true);

        XAttribute occlusionAtt = elemtype.Attribute("occlusion");
        Texture2D  occlusionMap = ContentLoader.LoadTexture(occlusionAtt, elemtype, Color.white, true);

        XAttribute patternAtt = elemtype.Attribute("pattern");
        Texture2D  patternTex = ContentLoader.LoadTexture(patternAtt, elemtype, Color.gray);

        GameSettings.MatchSizes(new Texture2D[] { normalMap, alphaMap, occlusionMap, patternTex });

        Texture2D combinedMap = new Texture2D(normalMap.width, normalMap.height, TextureFormat.ARGB32, true, true);

        combinedMap.filterMode = FilterMode.Trilinear;
        combinedMap.name       = normalMap.name + occlusionMap.name + alphaMap.name + patternTex.name;


        Color[] normalColors    = normalMap.GetPixels();
        Color[] occlusionColors = occlusionMap.GetPixels();
        Color[] alphaColors     = alphaMap.GetPixels();
        Color[] patternColors   = patternTex.GetPixels();

        for (int i = 0; i < normalColors.Length; i++)
        {
            normalColors[i] = new Color(occlusionColors[i].r, normalColors[i].g, alphaColors[i].r * patternColors[i].a, normalColors[i].r);
        }

        combinedMap.SetPixels(normalColors);
        combinedMap.Apply();

        if (store != null)
        {
            StorageIndex = store.AddTexture(combinedMap);
        }
        else
        {
            StorageIndex = -1;
        }
        Texture     = combinedMap;
        UniqueIndex = num_created;
        num_created++;
        return(true);
    }
Example #5
0
    public bool AddTypeElement(XElement elemtype)
    {
        XAttribute patternAtt = elemtype.Attribute("pattern");
        Texture2D  patternTex = ContentLoader.LoadTexture(patternAtt, elemtype, Color.gray);

        XAttribute specularAtt = elemtype.Attribute("specular");
        Texture2D  specularTex = ContentLoader.LoadTexture(specularAtt, elemtype, Color.black);

        GameSettings.MatchSizes(patternTex, specularTex);

        Texture2D combinedMap = new Texture2D(patternTex.width, patternTex.height, TextureFormat.ARGB32, true, false);

        combinedMap.filterMode = FilterMode.Trilinear;
        combinedMap.name       = patternTex.name + specularTex.name;

        Color[] patternColors  = patternTex.GetPixels();
        Color[] specularColors = specularTex.GetPixels();

        for (int i = 0; i < patternColors.Length; i++)
        {
            patternColors[i] = new Color(patternColors[i].r, patternColors[i].g, patternColors[i].b, specularColors[i].linear.r);
        }

        combinedMap.SetPixels(patternColors);
        combinedMap.Apply();

        if (store != null)
        {
            StorageIndex = store.AddTexture(combinedMap);
        }
        else
        {
            StorageIndex = -1;
        }
        Texture     = combinedMap;
        UniqueIndex = num_created;
        num_created++;
        return(true);
    }
    public bool AddTypeElement(XElement elemtype)
    {
        XAttribute metalAtt = elemtype.Attribute("metallic");
        Texture2D  metalMap = ContentLoader.LoadTexture(metalAtt, elemtype, Color.black, false);

        XAttribute illuminationAtt = elemtype.Attribute("illumination");
        Texture2D  illuminationMap = ContentLoader.LoadTexture(illuminationAtt, elemtype, Color.black, false);

        GameSettings.MatchSizes(metalMap, illuminationMap);

        Texture2D combinedMap = new Texture2D(metalMap.width, metalMap.height, TextureFormat.ARGB32, true, true);

        combinedMap.filterMode = FilterMode.Trilinear;
        combinedMap.name       = metalMap.name + illuminationMap.name;

        Color[] metalColors        = metalMap.GetPixels();
        Color[] illuminationColors = illuminationMap.GetPixels();

        for (int i = 0; i < metalColors.Length; i++)
        {
            metalColors[i] = new Color(metalColors[i].r, illuminationColors[i].g, 1, 1);
        }

        combinedMap.SetPixels(metalColors);
        combinedMap.Apply();

        if (store != null)
        {
            storageIndex = store.AddTexture(combinedMap);
        }
        else
        {
            storageIndex = -1;
        }
        Texture = combinedMap;

        return(true);
    }
Example #7
0
    public bool AddTypeElement(System.Xml.Linq.XElement elemtype)
    {
        if (store == null) //nowhere to put the image.
        {
            Debug.LogError("Texture Storage is Null: " + elemtype);
            return(false);
        }

        XAttribute fileAtt = elemtype.Attribute("file");

        if (fileAtt == null)
        {
            Debug.LogError("No file attribute in " + elemtype);
            //Add error message here
            return(false);
        }
        string filePath = Path.Combine(Path.GetDirectoryName(new Uri(elemtype.BaseUri).LocalPath), fileAtt.Value);

        filePath = Path.GetFullPath(filePath);

        if (!File.Exists(filePath))
        {
            Debug.LogError("File not found: " + filePath);
            return(false);
        }

        byte[] fileData = File.ReadAllBytes(filePath);

        Texture2D tex = new Texture2D(2, 2);

        tex.LoadImage(fileData);

        tex.name = filePath;

        storageIndex = store.AddTexture(tex);
        return(true);
    }
Example #8
0
    public bool AddTypeElement(System.Xml.Linq.XElement elemtype)
    {
        if (store == null) //nowhere to put the image.
        {
            Debug.LogError("Texture Storage is Null: " + elemtype);
            return(false);
        }

        XAttribute normalAtt = elemtype.Attribute("normal");

        if (normalAtt == null)
        {
            Debug.LogError("No normal map in " + elemtype);
            //Add error message here
            return(false);
        }
        string normalPath = Path.Combine(Path.GetDirectoryName(new Uri(elemtype.BaseUri).LocalPath), normalAtt.Value);

        normalPath = Path.GetFullPath(normalPath);

        if (!File.Exists(normalPath))
        {
            Debug.LogError("File not found: " + normalPath);
            return(false);
        }

        byte[]    normalData = File.ReadAllBytes(normalPath);
        Texture2D normalMap  = new Texture2D(2, 2, TextureFormat.ARGB32, false, true);

        normalMap.LoadImage(normalData);

        XAttribute specularAtt = elemtype.Attribute("specular");

        if (specularAtt == null)
        {
            Debug.LogError("No specular map in " + elemtype);
            //Add error message here
            return(false);
        }
        string specularPath = Path.Combine(Path.GetDirectoryName(new Uri(elemtype.BaseUri).LocalPath), specularAtt.Value);

        specularPath = Path.GetFullPath(specularPath);

        if (!File.Exists(specularPath))
        {
            Debug.LogError("File not found: " + specularPath);
            return(false);
        }

        byte[]    specularData = File.ReadAllBytes(specularPath);
        Texture2D specularMap  = new Texture2D(2, 2, TextureFormat.ARGB32, false, false);

        specularMap.LoadImage(specularData);

        if ((specularMap.width != normalMap.width) || (specularMap.height != normalMap.height))
        {
            TextureScale.Bilinear(specularMap, normalMap.width, normalMap.height);
        }

        XAttribute occlusionAtt = elemtype.Attribute("occlusion");

        if (occlusionAtt == null)
        {
            Debug.LogError("No occlusion map in " + elemtype);
            //Add error message here
            return(false);
        }
        string occlusionPath = Path.Combine(Path.GetDirectoryName(new Uri(elemtype.BaseUri).LocalPath), occlusionAtt.Value);

        occlusionPath = Path.GetFullPath(occlusionPath);

        if (!File.Exists(occlusionPath))
        {
            Debug.LogError("File not found: " + occlusionPath);
            return(false);
        }

        byte[] occlusionData = File.ReadAllBytes(occlusionPath);

        Texture2D occlusionMap = new Texture2D(2, 2, TextureFormat.ARGB32, false, true);

        occlusionMap.LoadImage(occlusionData);

        if (occlusionMap.width != normalMap.width || occlusionMap.height != normalMap.height)
        {
            TextureScale.Bilinear(occlusionMap, normalMap.width, normalMap.height);
        }

        Texture2D combinedMap = new Texture2D(normalMap.width, normalMap.height, TextureFormat.ARGB32, false, true);

        combinedMap.name = normalPath + occlusionAtt.Value + specularAtt.Value;

        Color[] normalColors    = normalMap.GetPixels();
        Color[] occlusionColors = occlusionMap.GetPixels();
        Color[] specularColors  = specularMap.GetPixels();

        if (normalColors.Length != specularColors.Length)
        {
            Debug.LogError("Maps aren't same size!");
        }

        for (int i = 0; i < normalColors.Length; i++)
        {
            normalColors[i] = new Color(occlusionColors[i].r, normalColors[i].g, specularColors[i].r, normalColors[i].r);
        }

        combinedMap.SetPixels(normalColors);
        combinedMap.Apply();

        storageIndex = store.AddTexture(combinedMap);
        return(true);
    }
Example #9
0
    public bool AddTypeElement(System.Xml.Linq.XElement elemtype)
    {
        if (store == null) //nowhere to put the image.
        {
            Debug.LogError("Texture Storage is Null: " + elemtype);
            return(false);
        }

        XAttribute patternAtt = elemtype.Attribute("pattern");

        if (patternAtt == null)
        {
            Debug.LogError("No pattern attribute in " + elemtype);
            //Add error message here
            return(false);
        }
        string patternPath = Path.Combine(Path.GetDirectoryName(new Uri(elemtype.BaseUri).LocalPath), patternAtt.Value);

        patternPath = Path.GetFullPath(patternPath);

        if (!File.Exists(patternPath))
        {
            Debug.LogError("File not found: " + patternPath);
            return(false);
        }

        byte[] patternData = File.ReadAllBytes(patternPath);

        Texture2D patternTex = new Texture2D(2, 2);

        patternTex.LoadImage(patternData);

        if (patternTex.width > GameSettings.Instance.rendering.maxTextureSize || patternTex.height > GameSettings.Instance.rendering.maxTextureSize)
        {
            if (patternTex.width > patternTex.height)
            {
                TextureScale.Bilinear(
                    patternTex,
                    GameSettings.Instance.rendering.maxTextureSize,
                    GameSettings.Instance.rendering.maxTextureSize * patternTex.height / patternTex.width);
            }
            else
            {
                TextureScale.Bilinear(
                    patternTex,
                    GameSettings.Instance.rendering.maxTextureSize * patternTex.width / patternTex.height,
                    GameSettings.Instance.rendering.maxTextureSize);
            }
        }

        XAttribute specularAtt = elemtype.Attribute("specular");

        if (specularAtt == null)
        {
            Debug.LogError("No specular attribute in " + elemtype);
            //Add error message here
            return(false);
        }
        string specularPath = Path.Combine(Path.GetDirectoryName(new Uri(elemtype.BaseUri).LocalPath), specularAtt.Value);

        specularPath = Path.GetFullPath(specularPath);

        if (!File.Exists(specularPath))
        {
            Debug.LogError("File not found: " + specularPath);
            return(false);
        }

        byte[] specularData = File.ReadAllBytes(specularPath);

        Texture2D specularTex = new Texture2D(2, 2);

        specularTex.LoadImage(specularData);

        if (specularTex.width != patternTex.width || specularTex.height != patternTex.height)
        {
            TextureScale.Bilinear(specularTex, patternTex.width, patternTex.height);
        }

        Texture2D combinedMap = new Texture2D(patternTex.width, patternTex.height, TextureFormat.ARGB32, false, false);

        combinedMap.name = patternPath + specularAtt.Value;

        Color[] patternColors  = patternTex.GetPixels();
        Color[] specularColors = specularTex.GetPixels();

        for (int i = 0; i < patternColors.Length; i++)
        {
            patternColors[i] = new Color(patternColors[i].r, patternColors[i].g, patternColors[i].b, specularColors[i].linear.r);
        }

        combinedMap.SetPixels(patternColors);
        combinedMap.Apply();


        storageIndex = store.AddTexture(combinedMap);
        return(true);
    }
Example #10
0
    public void Awake()
    {
        materialTextureStorage = new TextureStorage();
        shapeTextureStorage = new TextureStorage();
        specialTextureStorage = new TextureStorage();
        materialColors = new MaterialMatcher<ColorContent>();
        materialTextures = new MaterialMatcher<TextureContent>();

        DefaultMatTexIndex = materialTextureStorage.AddTexture(CreateFlatTexture(new Color(0.5f, 0.5f, 0.5f, 0)));
        DefaultShapeTexIndex = shapeTextureStorage.AddTexture(CreateFlatTexture(new Color(1f, 0.5f, 1f, 0.5f)));
        defaultSpecialTexIndex = specialTextureStorage.AddTexture(Texture2D.blackTexture);
    }
    public bool AddTypeElement(XElement elemtype)
    {
        if (store == null) //nowhere to put the image.
        {
            Debug.LogError("Texture Storage is Null: " + elemtype);
            return(false);
        }

        XAttribute metalAtt = elemtype.Attribute("metallic");

        if (metalAtt == null)
        {
            Debug.LogError("No metallic map in " + elemtype);
            return(false);
        }
        string metalPath = Path.Combine(Path.GetDirectoryName(new Uri(elemtype.BaseUri).LocalPath), metalAtt.Value);

        metalPath = Path.GetFullPath(metalPath);

        if (!File.Exists(metalPath))
        {
            Debug.LogError("File not found: " + metalPath);
            return(false);
        }

        byte[]    metalData = File.ReadAllBytes(metalPath);
        Texture2D metalMap  = new Texture2D(2, 2, TextureFormat.ARGB32, false, true);

        metalMap.LoadImage(metalData);

        metalMap.name = metalPath;

        if (metalMap.width > GameSettings.Instance.rendering.maxTextureSize || metalMap.height > GameSettings.Instance.rendering.maxTextureSize)
        {
            if (metalMap.width > metalMap.height)
            {
                TextureScale.Bilinear(
                    metalMap,
                    GameSettings.Instance.rendering.maxTextureSize,
                    GameSettings.Instance.rendering.maxTextureSize * metalMap.height / metalMap.width);
            }
            else
            {
                TextureScale.Bilinear(
                    metalMap,
                    GameSettings.Instance.rendering.maxTextureSize * metalMap.width / metalMap.height,
                    GameSettings.Instance.rendering.maxTextureSize);
            }
        }

        XAttribute illuminationAtt = elemtype.Attribute("illumination");

        if (illuminationAtt == null)
        {
            Debug.LogError("No illumination map in " + elemtype);
            //Add error message here
            return(false);
        }
        string illuminationPath = Path.Combine(Path.GetDirectoryName(new Uri(elemtype.BaseUri).LocalPath), illuminationAtt.Value);

        illuminationPath = Path.GetFullPath(illuminationPath);

        if (!File.Exists(illuminationPath))
        {
            Debug.LogError("File not found: " + illuminationPath);
            return(false);
        }

        byte[] illuminationData = File.ReadAllBytes(illuminationPath);

        Texture2D illuminationMap = new Texture2D(2, 2, TextureFormat.ARGB32, false, true);

        illuminationMap.LoadImage(illuminationData);

        if (illuminationMap.width != metalMap.width || illuminationMap.height != metalMap.height)
        {
            TextureScale.Bilinear(illuminationMap, metalMap.width, metalMap.height);
        }


        Texture2D combinedMap = new Texture2D(metalMap.width, metalMap.height, TextureFormat.ARGB32, false, true);

        combinedMap.name = metalPath + illuminationAtt.Value;

        Color[] metalColors        = metalMap.GetPixels();
        Color[] illuminationColors = illuminationMap.GetPixels();

        if (metalColors.Length != illuminationColors.Length)
        {
            Debug.LogError("Maps aren't same size!");
        }

        for (int i = 0; i < metalColors.Length; i++)
        {
            metalColors[i] = new Color(metalColors[i].r, illuminationColors[i].g, 1, 1);
        }

        combinedMap.SetPixels(metalColors);
        combinedMap.Apply();

        storageIndex = store.AddTexture(combinedMap);

        return(true);
    }