Exemplo n.º 1
0
    public TextureRef AddImage(string filepath,int width,int height)
    {
        TextureRef texture = GetTexture(filepath);
        if(null != texture)
        {
            texture.Retain();
        }
        else if(null == texture)
        {
            texture = new TextureRef();
            texture.filepath = filepath;
            texture.width = width;
            texture.height = height;
            texture.Retain();
            mTextures.Add(texture);
            mTextures.Sort(new TextureSorter());

            mCachedSize += width * height * 4;//内存大小
            if(mCachedSize > MAX_CACHE_SIZE)
            {
                RemoveUnusedTextures();
            }

            hasNew = true;
        }
        return texture;
    }
Exemplo n.º 2
0
            public Material(FileReader reader, Header header) : base()
            {
                ParentLayout = header;

                TextureTransforms = new List <TextureTransform>();

                Name = reader.ReadString(0x14, true);

                BlackColor16   = reader.ReadColor16RGBA();
                WhiteColor16   = reader.ReadColor16RGBA();
                ColorRegister3 = reader.ReadColor16RGBA();
                TevColor1      = reader.ReadColor8RGBA();
                TevColor2      = reader.ReadColor8RGBA();
                TevColor3      = reader.ReadColor8RGBA();
                TevColor4      = reader.ReadColor8RGBA();
                flags          = reader.ReadUInt32();


                uint indSrtCount      = ExtractBits(flags, 2, 17);
                uint texCoordGenCount = ExtractBits(flags, 4, 20);
                uint mtxCount         = ExtractBits(flags, 4, 24);
                uint texCount         = ExtractBits(flags, 4, 28);

                TextureMaps = new TextureRef[texCount];
                for (int i = 0; i < texCount; i++)
                {
                    TextureMaps[i] = new TextureRef(reader, header);
                }

                for (int i = 0; i < mtxCount; i++)
                {
                    TextureTransforms.Add(new TextureTransform(reader));
                }
            }
        protected override bool OnInitialize()
        {
            MDL0MatLayer *header = Header;

            _unk2     = header->_unk2;
            _unk3     = header->_unk3;
            _unk4     = header->_unk4;
            _unk5     = header->_unk5;
            _layerId1 = header->_layerId1;
            _layerId2 = header->_layerId2;
            _unk8     = header->_unk8;
            _unk9     = header->_unk9;
            _float    = header->_float;
            _unk10    = header->_unk10;
            _unk11    = header->_unk11;

            if (header->_stringOffset != 0)
            {
                _name    = header->ResourceString;
                _texture = Model._textures.FindOrCreate(_name);
                _texture._texRefs.Add(this);
            }
            if (header->_secondaryOffset != 0)
            {
                string name = header->SecondaryTexture;
                _decal = Model._textures.FindOrCreate(name);
                _decal._decRefs.Add(this);
            }

            return(false);
        }
Exemplo n.º 4
0
            public Material(FileReader reader, Header header) : base()
            {
                ParentLayout = header;

                Name              = reader.ReadString(20, true);
                TevColor          = reader.ReadColor8RGBA();
                TevConstantColors = reader.ReadColor8sRGBA(6);
                flags             = reader.ReadUInt32();

                uint texCount     = flags & 3;
                uint mtxCount     = (flags >> 2) & 3;
                uint texCoordGens = (flags >> 4) & 3;
                uint tevStages    = (flags >> 6) & 7;

                TextureMaps       = new TextureRef[texCount];
                TextureTransforms = new TextureTransform[mtxCount];

                for (int i = 0; i < texCount; i++)
                {
                    TextureMaps[i] = new TextureRef(reader, header);
                }

                for (int i = 0; i < mtxCount; i++)
                {
                    TextureTransforms[i] = new TextureTransform(reader);
                }
            }
Exemplo n.º 5
0
        public static void WriteTextureRefs(this FMAT m, Material mat, ResFile resFile)
        {
            mat.TextureRefs = new List <TextureRef>();
            mat.TextureRefs.Clear();
            mat.Samplers.Clear();

            int index = 0;

            foreach (MatTexture textu in m.TextureMaps)
            {
                TextureRef texref = new TextureRef();
                texref.Name = textu.Name;

                Sampler sampler = new Sampler();
                sampler.TexSampler         = textu.wiiUSampler;
                sampler.TexSampler.MinLod  = textu.MinLod;
                sampler.TexSampler.MaxLod  = textu.MaxLod;
                sampler.TexSampler.LodBias = textu.BiasLod;
                sampler.Name = textu.SamplerName;
                mat.Samplers.Add(textu.SamplerName, sampler);

                Texture texMapped = new Texture();
                resFile.Textures.TryGetValue(textu.Name, out texMapped);
                texref.Texture = texMapped;

                mat.TextureRefs.Add(texref);
                index++;
            }
        }
Exemplo n.º 6
0
 public static void TextureRelease(
     TextureRef textureRef)
 {
     ThrowOut(
         SUTextureRelease(
             ref textureRef.intPtr),
         "Could not release texture.");
 }
Exemplo n.º 7
0
        public TextureRef createTexture(string name, int width, int height)
        {
            var texture = new TextureRef(name);

            texture.texture = new Texture2D(Root.instance.graphics.graphicsDevice, width, height);
            textures.Add(name, texture);
            return(texture);
        }
 public static void TextureCreateFromImageRep(
     TextureRef textureRef,
     ImageRepRef imageRepRef)
 {
     ThrowOut(
         SUTextureCreateFromImageRep(
             out textureRef.intPtr,
             imageRepRef.intPtr),
         "Could not create texture from image rep.");
 }
Exemplo n.º 9
0
 public static void TextureWriteToFile(
     TextureRef textureRef,
     string path)
 {
     ThrowOut(
         SUTextureWriteToFile(
             textureRef.intPtr,
             path),
         "Could not write texture to file.");
 }
 public static void TextureGetImageRep(
     TextureRef textureRef,
     ImageRepRef imageRepRef)
 {
     ThrowOut(
         SUTextureGetImageRep(
             textureRef.intPtr,
             out imageRepRef.intPtr),
         "Could not get image rep.");
 }
Exemplo n.º 11
0
 public static void MaterialSetTexture(
     MaterialRef materialRef,
     TextureRef textureRef)
 {
     ThrowOut(
         SUMaterialSetTexture(
             materialRef.intPtr,
             textureRef.intPtr),
         "Could not set texture.");
 }
Exemplo n.º 12
0
        public TextureRef findTexture(string name)
        {
            TextureRef texture = null;

            if (!textures.TryGetValue(name, out texture))
            {
                texture = new TextureRef(name);
                textures.Add(name, texture);
            }
            return(texture);
        }
        public TextureRef FindOrCreate(string name)
        {
            foreach (TextureRef t in _textures)
            {
                if (t.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
                    return t;
            }

            TextureRef tr = new TextureRef(name);
            _textures.Add(tr);
            return tr;
        }
Exemplo n.º 14
0
        // Note that scales are ignored when you assign UV coords to vertices.

        public static void TextureCreateFromFile(
            TextureRef textureRef,
            string path,
            double sScale,
            double tScale)
        {
            ThrowOut(
                SUTextureCreateFromFile(
                    out textureRef.intPtr,
                    path,
                    sScale,
                    tScale),
                "Could not create texture from file.");
        }
Exemplo n.º 15
0
        public static void WriteTextureRefs(this FMAT m, Material mat)
        {
            mat.TextureRefs = new List <TextureRef>();
            mat.TextureRefs.Clear();

            foreach (var textu in m.textures)
            {
                TextureRef texref = new TextureRef();
                texref.Name = textu.Name;
                Texture texMapped = new Texture();
                m.BFRESRender.resFileU.Textures.TryGetValue(textu.Name, out texMapped);
                texref.Texture = texMapped;
                mat.TextureRefs.Add(texref);
            }
        }
Exemplo n.º 16
0
        protected static Texture GetTexture(string name, Action <Texture> mutator)
        {
            if (Textures.ContainsKey(name))
            {
                if (mutator != null)
                {
                    Textures[name].Mutator += mutator;
                }
            }
            else
            {
                Textures[name] = new TextureRef(name, mutator ?? ((t) => { }));
            }

            return(Textures[name].Value);
        }
Exemplo n.º 17
0
        internal void releaseTextures(bool reload)
        {
            foreach (var texture in textures.Values)
            {
                texture.Dispose();
            }

            textures.Clear();
            if (reload)
            {
                basewhite         = new TextureRef("basewhite");
                basewhite.texture = new Texture2D(Root.instance.graphics.graphicsDevice, 1, 1);
                basewhite.texture.SetData(new Color[] { Color.White });
                textures.Add("basewhite", basewhite);
            }
        }
Exemplo n.º 18
0
        private void ReadAltImageRaw(int off)
        {
            AltImageRaw = new List <byte[]>();
            int size = getInt(off);

            byte[]     buff;
            TextureRef t;
            int        pos = off;

            while (isSquare2(size))
            {
                int sizeX = size;
                int sizeY = getInt(pos + 4);
                int msize = getInt(pos + 16);
                if (pos + msize > memsize)
                {
                    pos += 24;
                    break;
                }
                int offset = pos + 24;
                t       = new TextureRef();
                t.sizeX = sizeX / 2;
                t.sizeY = sizeY / 2;
                if (t.sizeX == 0)
                {
                    t.sizeX = 1;
                }
                if (t.sizeY == 0)
                {
                    t.sizeY = 1;
                }
                t.size    = (uint)msize;
                t.offset  = (uint)offset;
                t.InCache = false;
                buff      = new byte[msize + 24];
                for (int i = 0; i < msize + 24; i++)
                {
                    buff[i] = memory[pos + i];
                }
                pos += msize + 24;
                TextureTFCs.Add(t);
                AltImageRaw.Add(buff);
                size = getInt(pos);
            }
            currpos = pos;
        }
Exemplo n.º 19
0
        private static void BindGLTexture(TextureRef tex, STGenericTexture texture)
        {
            if (texture.RenderableTex == null || !texture.RenderableTex.GLInitialized)
            {
                texture.LoadOpenGLTexture();
            }

            //If the texture is still not initialized then return
            if (!texture.RenderableTex.GLInitialized)
            {
                return;
            }

            GL.BindTexture(TextureTarget.Texture2D, texture.RenderableTex.TexID);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleR, ConvertChannel(texture.RedChannel));
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleG, ConvertChannel(texture.GreenChannel));
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleB, ConvertChannel(texture.BlueChannel));
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleA, ConvertChannel(texture.AlphaChannel));
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, ConvertTextureWrap(tex.WrapModeU));
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, ConvertTextureWrap(tex.WrapModeV));
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, ConvertMagFilterMode(tex.MaxFilterMode));
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, ConvertMinFilterMode(tex.MinFilterMode));
        }
Exemplo n.º 20
0
        private void ReadImageRaw(int off)
        {
            if (TextureTFCs == null || TextureTFCs.Count < 1)
            {
                return;
            }
            int        size = (int)TextureTFCs[TextureTFCs.Count - 1].size;
            TextureRef t    = TextureTFCs[TextureTFCs.Count - 1];

            t.offset  = (uint)off;
            t.InCache = false;
            TextureTFCs[TextureTFCs.Count - 1] = t;
            ImageRaw = new byte[size];
            if (off + size >= memory.Length)
            {
                return;
            }
            for (int i = 0; i < size; i++)
            {
                ImageRaw[i] = memory[off + i];
            }
            ImageF  = new ImageFile(ImageRaw, T2D.PixelFormat, T2D.SizeX, T2D.SizeY);
            currpos = off + size;
        }
Exemplo n.º 21
0
        private void ReadProperties(int off)
        {
            TextureTFCs = new List <TextureRef>();
            TextureRef TRef = new TextureRef();

            OProps = new List <Property>();
            int    pos = off;
            int    MAXName = names.Length;
            string s = "", v;
            int    tmp = 0;
            int    n   = getInt(pos);

            if (n < MAXName)
            {
                s = names[n];
            }
            int t = getName(s);

            while (t != -1 && T2D.memsize == 0)
            {
                v = "";
                switch (t)
                {
                case 0:
                    pos += 8;
                    break;

                case 1:
                    T2D.Tsource = "Textures";
                    pos        += 8;
                    break;

                case 2:
                    T2D.Tsource = "CharTextures";
                    pos        += 8;
                    break;

                case 3:
                    pos += 16;
                    v    = "0x" + BitConverter.ToUInt32(memory, pos - 8).ToString("X");
                    break;

                case 4:
                    pos += 8;
                    n    = getInt(pos);
                    if (n < MAXName)
                    {
                        T2D.PixelFormat = names[n];
                    }
                    v    = T2D.PixelFormat;
                    pos += 8;
                    break;

                case 5:
                    pos += 8;
                    T2D.TCompressionSet = getInt(pos);
                    pos += 8;
                    break;

                case 6:
                    pos += 24;
                    v    = "0x" + BitConverter.ToUInt32(memory, pos - 16).ToString("X") + " 0x" +
                           BitConverter.ToUInt32(memory, pos - 12).ToString("X") + " 0x" +
                           BitConverter.ToUInt32(memory, pos - 8).ToString("X") + " 0x" +
                           BitConverter.ToUInt32(memory, pos - 4).ToString("X");
                    break;

                case 7:
                    pos += 24;
                    int src = getInt(pos);
                    T2D.Tsource = names[src].Substring(0, Math.Max(0, names[src].Length - 1));
                    pos        += 8;
                    v           = T2D.Tsource;
                    break;

                case 8:
                    pos       += 16;
                    T2D.Format = getInt(pos);
                    v          = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                    pos       += 8;
                    break;

                case 9:
                    pos         += 16;
                    T2D.LODGroup = getInt(pos);
                    v            = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                    pos         += 8;
                    break;

                case 10:
                    pos            += 16;
                    T2D.CompSetting = getInt(pos);
                    v    = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                    pos += 8;
                    break;

                case 11:
                    pos         += 24;
                    T2D.SizeX    = getInt(pos);
                    T2D.offSizeX = (uint)pos;
                    v            = BitConverter.ToUInt32(memory, pos) + " pixels";
                    pos         += 4;
                    break;

                case 12:
                    pos         += 24;
                    T2D.SizeY    = getInt(pos);
                    T2D.offSizeY = (uint)pos;
                    v            = BitConverter.ToUInt32(memory, pos) + " pixels";
                    pos         += 4;
                    break;

                case 13:
                    pos          += 24;
                    T2D.OSizeX    = getInt(pos);
                    T2D.offOSizeX = (uint)pos;
                    v             = BitConverter.ToUInt32(memory, pos) + " pixels";
                    pos          += 4;
                    break;

                case 14:
                    pos          += 24;
                    T2D.OSizeY    = getInt(pos);
                    T2D.offOSizeY = (uint)pos;
                    v             = BitConverter.ToUInt32(memory, pos) + " pixels";
                    pos          += 4;
                    break;

                case 15:
                    pos        += 24;
                    T2D.MipTail = getInt(pos);
                    v           = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                    pos        += 4;
                    break;

                case 16:
                    pos        += 24;
                    T2D.LODBias = getInt(pos);
                    v           = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                    pos        += 4;
                    break;

                case 17:
                    pos += 24;
                    T2D.InternalBias = getInt(pos);
                    v    = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                    pos += 4;
                    break;

                case 18:
                    pos          += 12;
                    T2D.CompNoMip = memory[pos];
                    v             = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                    pos          += 13;
                    break;

                case 19:
                    pos            += 12;
                    T2D.NeverStream = memory[pos];
                    v    = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                    pos += 13;
                    break;

                case 20:
                    pos     += 12;
                    T2D.SRGB = memory[pos];
                    v        = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                    pos     += 13;
                    break;

                case 21:
                    pos         += 12;
                    T2D.CompNone = memory[pos];
                    v            = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                    pos         += 13;
                    break;

                case 22:
                    pos += 28;
                    v    = "0x" + BitConverter.ToUInt32(memory, pos - 4).ToString("X");
                    break;

                case 23:
                    pos += 24;
                    tmp  = getInt(pos);
                    pos += 8;
                    if (tmp < names.Length && names[tmp] == "ByteProperty\0")
                    {
                        pos += 8;
                    }
                    else
                    {
                        T2D.memsize       = (uint)getInt(pos);
                        TRef.sizeX        = T2D.SizeX;
                        TRef.sizeY        = T2D.SizeY;
                        TRef.size         = getUInt(pos + 4);
                        TRef.offset       = getUInt(pos + 8);;
                        TRef.HeaderOffset = pos - 12;
                        TRef.InCache      = true;
                        TextureTFCs.Add(TRef);
                        pos += 12;
                        while (isSquare2(getInt(pos)) && isSquare2(getInt(pos + 4)))
                        {
                            T2D.SizeX = getInt(pos) / 2;
                            T2D.SizeY = getInt(pos + 4) / 2;
                            if (T2D.SizeX == 0)
                            {
                                T2D.SizeX = 1;
                            }
                            if (T2D.SizeY == 0)
                            {
                                T2D.SizeY = 1;
                            }
                            TRef.sizeX        = T2D.SizeX;
                            TRef.sizeY        = T2D.SizeY;
                            TRef.size         = getUInt(pos + 16);
                            TRef.offset       = getUInt(pos + 20);;
                            TRef.HeaderOffset = pos;
                            TextureTFCs.Add(TRef);
                            T2D.memsize = (uint)getInt(pos + 12);
                            pos        += 24;
                        }
                        T2D.headerend = (uint)pos;
                    }
                    break;

                case 24:
                    pos              += 16;
                    T2D.memsize       = (uint)getInt(pos);
                    TRef.sizeX        = T2D.SizeX;
                    TRef.sizeY        = T2D.SizeY;
                    TRef.size         = getUInt(pos + 4);
                    TRef.offset       = getUInt(pos + 8);
                    TRef.HeaderOffset = pos - 12;
                    TRef.InCache      = true;
                    TextureTFCs.Add(TRef);
                    pos += 12;
                    while (isSquare2(getInt(pos)) && isSquare2(getInt(pos + 4)))
                    {
                        T2D.SizeX = getInt(pos) / 2;
                        T2D.SizeY = getInt(pos + 4) / 2;
                        if (T2D.SizeX == 0)
                        {
                            T2D.SizeX = 1;
                        }
                        if (T2D.SizeY == 0)
                        {
                            T2D.SizeY = 1;
                        }
                        TRef.sizeX        = T2D.SizeX;
                        TRef.sizeY        = T2D.SizeY;
                        TRef.size         = getUInt(pos + 16);
                        TRef.offset       = getUInt(pos + 20);;
                        TRef.HeaderOffset = pos;
                        TRef.InCache      = true;
                        TextureTFCs.Add(TRef);
                        T2D.memsize = (uint)getInt(pos + 12);
                        pos        += 24;
                    }
                    T2D.headerend = (uint)pos;
                    break;

                case 25:
                    pos            += 12;
                    T2D.CompNoAlpha = memory[pos];
                    v    = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                    pos += 13;
                    break;

                case 26:
                    pos += 16;
                    v    = "0x" + BitConverter.ToUInt32(memory, pos - 4).ToString("X");
                    break;

                case 27:
                    pos += 12;
                    T2D.IsSourceArtUnComp = memory[pos];
                    v    = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                    pos += 13;
                    break;

                case 28:
                    pos += 24;
                    v    = "0x" + BitConverter.ToUInt32(memory, pos - 4).ToString("X");
                    break;

                case 29:
                    pos += 24;
                    v    = "0x" + BitConverter.ToUInt32(memory, pos - 4).ToString("X");
                    break;

                case 30:
                    pos += 16;
                    v    = "0x" + BitConverter.ToUInt32(memory, pos - 4).ToString("X");
                    break;

                case 31:
                    pos += 24;
                    v    = "0x" + BitConverter.ToUInt32(memory, pos - 8).ToString("X");
                    break;

                case 32:
                    pos += 16;
                    v    = "";
                    break;

                case 33:
                    pos += 28;
                    v    = "0x" + BitConverter.ToSingle(memory, pos - 4).ToString();
                    break;
                }
                OProps.Add(makeProp(s, v, ReadRaw(currpos, pos - currpos)));
                s = "";
                n = getInt(pos);
                if (n >= 0 && n < MAXName)
                {
                    s = names[n];
                }
                t = getName(s);
            }
            currpos = pos;
        }
Exemplo n.º 22
0
 public Material(string name, Header header)
 {
     TextureMaps       = new TextureRef[0];
     TextureTransforms = new List <TextureTransform>();
 }
Exemplo n.º 23
0
        protected static Texture GetTexture(string name, Action<Texture> mutator)
        {
            if (Textures.ContainsKey(name))
            {
                if (mutator != null)
                {
                    Textures[name].Mutator += mutator;
                }
            }
            else
            {
                Textures[name] = new TextureRef(name, mutator ?? ((t) => { }));
            }

            return Textures[name].Value;
        }
Exemplo n.º 24
0
    public static void CheckCommonFiles()
    {
        string commonUIPath = Application.dataPath + "/App/Pro/GameRes/UI/Module/common";
        string prefabPath   = Application.dataPath + "/App/Pro/GameRes/UIPrefabs";

        var pngs = Directory.GetFiles(commonUIPath, "*.meta", SearchOption.AllDirectories)
                   .Select(p => "Assets/" + p.Replace('\\', '/').Substring(Application.dataPath.Length + 1))
                   .Where(p => p.EndsWith(".png.meta")).ToList();

        var imgGuid2path = new Dictionary <string, string>();

        var uuidReg = new Regex(@"guid: ([a-f0-9]{32})");

        EditorUtility.ClearProgressBar();

        for (var i = 0; i < pngs.Count; ++i)
        {
            var png = pngs[i];

            var matcher = uuidReg.Match(File.ReadAllText(png));
            var guid    = matcher.Groups[1].Value;
            if (imgGuid2path.ContainsKey(guid))
            {
                Debug.LogError("uuid dup" + guid + " \n" + png + "\n" + imgGuid2path[guid]);
            }
            else
            {
                string _path = png.Substring(0, png.Length - 5).Replace("Assets/App/Pro/GameRes/UI/Module/", "");
                imgGuid2path.Add(guid, _path);
            }

            EditorUtility.DisplayProgressBar("扫描图片中", Path.GetFileNameWithoutExtension(png),
                                             (float)i / pngs.Count);
        }

        EditorUtility.ClearProgressBar();

        var prefabs = Directory.GetFiles(prefabPath, "*.prefab", SearchOption.AllDirectories).ToList();

        Dictionary <string, int> guidToNum = new Dictionary <string, int>();

        prefabs.ForEachI((prefab, i) =>
        {
            EditorUtility.DisplayProgressBar("分析prefab", Path.GetFileNameWithoutExtension(prefab), (float)i / prefabs.Count);

            var guids = getUUIDsInFile(prefab);
            foreach (var guid in guids)
            {
                if (imgGuid2path.ContainsKey(guid))
                {
                    if (!guidToNum.ContainsKey(guid))
                    {
                        guidToNum.Add(guid, 0);
                    }
                    else
                    {
                        guidToNum[guid]++;
                    }
                }
            }
        });

        EditorUtility.ClearProgressBar();

        List <TextureRef> list = new List <TextureRef>();

        foreach (var keyValuePair in guidToNum)
        {
            TextureRef tex = new TextureRef {
                refCount = keyValuePair.Value, uuid = keyValuePair.Key
            };

            list.Add(tex);
        }

        list.Sort((a, b) => a.refCount.CompareTo(b.refCount));

        StringBuilder sb = new StringBuilder();

        list.ForEach(l =>
        {
            sb.Append(l.refCount).Append("    ").Append(AssetDatabase.GUIDToAssetPath(l.uuid)).Append(Environment.NewLine);
        });

        string retName  = "fileList.txt";
        string filePath = Path.Combine(Application.temporaryCachePath, retName);

        if (File.Exists(filePath))
        {
            File.Delete(filePath);
        }

        File.WriteAllText(filePath, sb.ToString());
        System.Diagnostics.Process.Start(filePath);
    }
Exemplo n.º 25
0
        public static Material CreateSwitchMaterial(this BFRES.MaterialData mat)
        {
            Material m = new Material();

            m.Flags            = (MaterialFlags)mat.IsVisable;
            m.Name             = mat.Name;
            m.TextureRefs      = new List <TextureRef>();
            m.RenderInfos      = new List <RenderInfo>();
            m.Samplers         = new List <Sampler>();
            m.VolatileFlags    = new byte[0];
            m.UserDatas        = new List <UserData>();
            m.ShaderParams     = new List <ShaderParam>();
            m.SamplerDict      = new ResDict();
            m.RenderInfoDict   = new ResDict();
            m.ShaderParamDict  = new ResDict();
            m.UserDataDict     = new ResDict();
            m.VolatileFlags    = new byte[0];
            m.TextureSlotArray = new long[mat.textures.Count];
            m.SamplerSlotArray = new long[mat.textures.Count];
            m.ShaderParamData  = WriteShaderParams(mat);

            int CurTex = 0;

            foreach (BFRES.MatTexture tex in mat.textures)
            {
                TextureRef texture = new TextureRef();
                texture.Name = tex.Name;
                m.TextureRefs.Add(texture);

                Sampler samp = new Sampler();
                samp.BorderColorType = tex.BorderColorType;
                samp.CompareFunc     = tex.CompareFunc;
                samp.FilterMode      = tex.FilterMode;
                samp.LODBias         = tex.LODBias;
                samp.MaxAnisotropic  = tex.MaxAnisotropic;
                samp.MaxLOD          = tex.magFilter;
                samp.MinLOD          = tex.minFilter;
                samp.WrapModeU       = (TexClamp)tex.wrapModeS;
                samp.WrapModeV       = (TexClamp)tex.wrapModeT;
                samp.WrapModeW       = (TexClamp)tex.wrapModeW;

                m.Samplers.Add(samp);

                m.SamplerDict.Add(tex.SamplerName);

                m.TextureSlotArray[CurTex] = -1;
                m.SamplerSlotArray[CurTex] = -1;

                CurTex++;
            }

            int CurParam = 0;

            foreach (var prm in mat.matparam)
            {
                ShaderParam shaderParam = new ShaderParam();
                shaderParam.Name          = prm.Key;
                shaderParam.Type          = (ShaderParamType)prm.Value.Type;
                shaderParam.DependIndex   = (ushort)CurParam;
                shaderParam.DependedIndex = (ushort)CurParam;
                shaderParam.DataOffset    = (ushort)prm.Value.DataOffset;
                CurParam++;
            }
            foreach (BFRES.RenderInfoData rnd in mat.renderinfo)
            {
                RenderInfo renderInfo = new RenderInfo();
                renderInfo.Name = rnd.Name;

                if (rnd.Type == Syroot.NintenTools.Bfres.RenderInfoType.Int32)
                {
                    renderInfo.SetValue(rnd.Value_Ints);
                }
                if (rnd.Type == Syroot.NintenTools.Bfres.RenderInfoType.Single)
                {
                    renderInfo.SetValue(rnd.Value_Floats);
                }
                if (rnd.Type == Syroot.NintenTools.Bfres.RenderInfoType.String)
                {
                    renderInfo.SetValue(rnd.Value_Strings);
                }

                m.RenderInfos.Add(renderInfo);
            }

            ShaderAssign shaderAssign = new ShaderAssign();

            shaderAssign.ShaderArchiveName = mat.shaderassign.ShaderArchive;
            shaderAssign.ShadingModelName  = mat.shaderassign.ShaderModel;

            shaderAssign.ShaderOptionDict  = new ResDict();
            shaderAssign.AttribAssignDict  = new ResDict();
            shaderAssign.SamplerAssignDict = new ResDict();
            shaderAssign.ShaderOptions     = new List <string>();
            shaderAssign.AttribAssigns     = new List <string>();
            shaderAssign.SamplerAssigns    = new List <string>();

            foreach (var op in mat.shaderassign.options)
            {
                shaderAssign.ShaderOptionDict.Add(op.Key);
                shaderAssign.ShaderOptions.Add(op.Value);
            }
            foreach (var att in mat.shaderassign.attributes)
            {
                shaderAssign.AttribAssignDict.Add(att.Key);
                shaderAssign.AttribAssigns.Add(att.Value);
            }
            foreach (var smp in mat.shaderassign.samplers)
            {
                shaderAssign.SamplerAssignDict.Add(smp.Key);
                shaderAssign.SamplerAssigns.Add(smp.Value);
            }

            m.ShaderAssign = shaderAssign;

            return(m);
        }
Exemplo n.º 26
0
        private void ReadProperties(int off)
        {
            TextureTFCs = new List<TextureRef>();
            TextureRef TRef = new TextureRef();
            OProps = new List<Property>();
            int pos = off;
            int MAXName = names.Length;
            string s = "",v;
            int tmp = 0;
            int n = getInt(pos);
            if(n<MAXName) s=names[n];
            int t = getName(s);
            while (t != -1 && T2D.memsize == 0)
            {
                v = "";
                switch (t)
                {
                    case 0:
                        pos += 8;
                        break;
                    case 1:
                        T2D.Tsource = "Textures";
                        pos += 8; 
                        break;
                    case 2:
                        T2D.Tsource = "CharTextures";
                        pos += 8;
                        break;
                    case 3:
                        pos += 16;
                        v = "0x" + BitConverter.ToUInt32(memory, pos - 8).ToString("X");
                        break;
                    case 4:
                        pos += 8;
                        n = getInt(pos);
                        if (n < MAXName) T2D.PixelFormat = names[n];
                        v = T2D.PixelFormat;
                        pos += 8;
                        break;
                    case 5:
                        pos += 8;
                        T2D.TCompressionSet = getInt(pos);
                        pos += 8;
                        break;
                    case 6:
                        pos += 24;
                        v = "0x" + BitConverter.ToUInt32(memory, pos - 16).ToString("X") + " 0x" + 
                                   BitConverter.ToUInt32(memory, pos - 12).ToString("X") + " 0x" + 
                                   BitConverter.ToUInt32(memory, pos - 8).ToString("X") + " 0x" + 
                                   BitConverter.ToUInt32(memory, pos - 4).ToString("X");
                        break;
                    case 7:
                        pos += 24;
                        int src = getInt(pos);
                        T2D.Tsource = names[src].Substring(0,Math.Max(0,names[src].Length-1));
                        pos += 8;
                        v = T2D.Tsource;
                        break;
                    case 8:
                        pos += 16;
                        T2D.Format = getInt(pos);
                        v = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                        pos += 8;
                        break;
                    case 9:
                        pos += 16;
                        T2D.LODGroup = getInt(pos);
                        v = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                        pos += 8;
                        break;
                    case 10:
                        pos += 16;
                        T2D.CompSetting = getInt(pos);
                        v = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                        pos += 8;
                        break;
                    case 11:
                        pos += 24;
                        T2D.SizeX = getInt(pos);
                        T2D.offSizeX =(uint)pos;
                        v = BitConverter.ToUInt32(memory, pos) + " pixels";
                        pos += 4;
                        break;
                    case 12:
                        pos += 24;
                        T2D.SizeY = getInt(pos);
                        T2D.offSizeY = (uint)pos;
                        v = BitConverter.ToUInt32(memory, pos) + " pixels";
                        pos += 4;
                        break;
                    case 13:
                        pos += 24;
                        T2D.OSizeX = getInt(pos);
                        T2D.offOSizeX = (uint)pos;
                        v = BitConverter.ToUInt32(memory, pos) + " pixels";
                        pos += 4;
                        break;
                    case 14:
                        pos += 24;
                        T2D.OSizeY = getInt(pos);
                        T2D.offOSizeY = (uint)pos;
                        v = BitConverter.ToUInt32(memory, pos) + " pixels";
                        pos += 4;
                        break;
                    case 15:
                        pos += 24;
                        T2D.MipTail = getInt(pos);
                        v = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                        pos += 4;
                        break;
                    case 16:
                        pos += 24;
                        T2D.LODBias = getInt(pos);
                        v = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                        pos += 4;
                        break;
                    case 17:
                        pos += 24;
                        T2D.InternalBias = getInt(pos);
                        v = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                        pos += 4;
                        break;
                    case 18:
                        pos += 12;
                        T2D.CompNoMip = memory[pos];
                        v = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                        pos += 13;
                        break;
                    case 19:
                        pos += 12;
                        T2D.NeverStream = memory[pos];
                        v = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                        pos += 13;
                        break;
                    case 20:
                        pos += 12;
                        T2D.SRGB = memory[pos];
                        v = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                        pos += 13;
                        break; 
                    case 21:
                        pos += 12;
                        T2D.CompNone = memory[pos];
                        v = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                        pos += 13;
                        break;
                    case 22:
                        pos += 28;
                        v = "0x" + BitConverter.ToUInt32(memory, pos - 4).ToString("X");
                        break;
                    case 23:
                        pos += 24;
                        tmp = getInt(pos);
                        pos += 8;
                        if (tmp<names.Length && names[tmp] == "ByteProperty\0")
                            pos += 8;
                        else
                        {
                            T2D.memsize = (uint)getInt(pos);
                            TRef.sizeX = T2D.SizeX;
                            TRef.sizeY = T2D.SizeY;
                            TRef.size = getUInt(pos + 4);
                            TRef.offset = getUInt(pos + 8); ;
                            TRef.HeaderOffset = pos - 12;
                            TRef.InCache = true;
                            TextureTFCs.Add(TRef);
                            pos += 12;
                                while (isSquare2(getInt(pos)) && isSquare2(getInt(pos + 4)))
                                {
                                    T2D.SizeX = getInt(pos) / 2;
                                    T2D.SizeY = getInt(pos + 4) / 2;
                                    if (T2D.SizeX == 0)
                                        T2D.SizeX = 1;
                                    if (T2D.SizeY == 0)
                                        T2D.SizeY = 1;
                                    TRef.sizeX = T2D.SizeX;
                                    TRef.sizeY = T2D.SizeY;
                                    TRef.size = getUInt(pos + 16);
                                    TRef.offset = getUInt(pos + 20); ;
                                    TRef.HeaderOffset = pos;
                                    TextureTFCs.Add(TRef);
                                    T2D.memsize = (uint)getInt(pos + 12);
                                    pos += 24;
                                }
                            T2D.headerend = (uint)pos;
                        }
                        break;
                    case 24:
                        pos += 16;
                        T2D.memsize = (uint)getInt(pos);
                        TRef.sizeX = T2D.SizeX;
                        TRef.sizeY = T2D.SizeY;
                        TRef.size = getUInt(pos + 4);
                        TRef.offset = getUInt(pos + 8);
                        TRef.HeaderOffset = pos - 12;
                        TRef.InCache = true;
                        TextureTFCs.Add(TRef);
                        pos += 12;
                                while (isSquare2(getInt(pos)) && isSquare2(getInt(pos + 4)))
                                {
                                    T2D.SizeX = getInt(pos) / 2;
                                    T2D.SizeY = getInt(pos + 4) / 2;
                                    if (T2D.SizeX == 0)
                                        T2D.SizeX = 1;
                                    if (T2D.SizeY == 0)
                                        T2D.SizeY = 1;
                                    TRef.sizeX = T2D.SizeX;
                                    TRef.sizeY = T2D.SizeY;
                                    TRef.size = getUInt(pos + 16);
                                    TRef.offset = getUInt(pos + 20); ;
                                    TRef.HeaderOffset = pos;
                                    TRef.InCache = true;
                                    TextureTFCs.Add(TRef);
                                    T2D.memsize = (uint)getInt(pos + 12);
                                    pos += 24;
                                }
                        T2D.headerend = (uint)pos;
                        break;
                    case 25:
                        pos += 12;
                        T2D.CompNoAlpha = memory[pos];
                        v = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                        pos += 13;
                        break; 
                    case 26:
                        pos += 16;
                        v = "0x" + BitConverter.ToUInt32(memory, pos - 4).ToString("X");
                        break;
                    case 27:
                        pos += 12;
                        T2D.IsSourceArtUnComp = memory[pos];
                        v = "0x" + BitConverter.ToUInt32(memory, pos).ToString("X");
                        pos += 13;
                        break;
                    case 28:
                        pos += 24;
                        v = "0x" + BitConverter.ToUInt32(memory, pos - 4).ToString("X");
                        break;
                    case 29:
                        pos += 24;
                        v = "0x" + BitConverter.ToUInt32(memory, pos - 4).ToString("X");
                        break;
                    case 30:
                        pos += 16;
                        v = "0x" + BitConverter.ToUInt32(memory, pos - 4).ToString("X");
                        break;
                    case 31:
                        pos += 24;
                        v = "0x" + BitConverter.ToUInt32(memory, pos - 8).ToString("X");
                        break;
                    case 32:
                        pos += 16;
                        v = "";
                        break;
                    case 33:
                        pos += 28;
                        v = "0x" + BitConverter.ToSingle(memory, pos - 4).ToString();
                        break;

                }
                OProps.Add(makeProp(s,v,ReadRaw(currpos,pos-currpos)));
                s = "";
                n = getInt(pos);
                if (n>= 0 && n < MAXName) s = names[n];
                t = getName(s);
            }
            currpos = pos;
        }
Exemplo n.º 27
0
 private void ReadAltImageRaw(int off)
 {
     AltImageRaw = new List<byte[]>();
     int size = getInt(off);
     byte[] buff;
     TextureRef t;
     int pos = off;
     while (isSquare2(size))
     {
         int sizeX = size;
         int sizeY = getInt(pos + 4);
         int msize = getInt(pos + 16);
         if (pos + msize > memsize)
         {
             pos += 24;
             break;
         }
         int offset = pos + 24;
         t = new TextureRef();
         t.sizeX = sizeX / 2;                
         t.sizeY = sizeY / 2;
         if (t.sizeX == 0)
             t.sizeX = 1;
         if (t.sizeY == 0)
             t.sizeY = 1;
         t.size = (uint)msize;
         t.offset = (uint)offset;
         t.InCache = false;
         buff = new byte[msize + 24];
         for (int i = 0; i < msize + 24; i++)
             buff[i] = memory[pos + i];
         pos += msize + 24;
         TextureTFCs.Add(t);
         AltImageRaw.Add(buff);
         size = getInt(pos);
     }
     currpos = pos;
 }
Exemplo n.º 28
0
 public Material()
 {
     TextureMaps       = new TextureRef[0];
     TextureTransforms = new TextureTransform[0];
 }