Beispiel #1
0
        TEX0Node FindSourceNode()
        {
            ResourceNode candidate = this;

            while (candidate is TEX0Node)
            {
                TEX0Node texNode = candidate as TEX0Node;
                if (!texNode.SharesData)
                {
                    return(texNode);
                }
                candidate = candidate.NextSibling();
            }
            return(NullTEX0Node());
        }
Beispiel #2
0
        // The offset from the start of the header to the start of its data.
        // Equal to the length of its header if not shared, the length of all headers between it and its data if shared.
        int OffsetToData()
        {
            int          offset = 0;
            ResourceNode node   = this;

            while (node is TEX0Node)
            {
                TEX0Node texNode = node as TEX0Node;
                offset += texNode.HeaderSize();
                if (!texNode.SharesData)
                {
                    return(offset);
                }
                node = node.NextSibling();
            }
            return(0);
        }
        internal void ApplyPAT0Texture(PAT0TextureNode node, int index)
        {
            PAT0TextureEntryNode prev = null;

            if (node != null && index != 0 && node.Children.Count > 0)
            {
                foreach (PAT0TextureEntryNode next in node.Children)
                {
                    if (next.Index == 0)
                    {
                        prev = next;
                        continue;
                    }
                    if (prev.key <= index - 1 && next.key > index - 1)
                    {
                        break;
                    }
                    prev = next;
                }

                PAT0Texture = prev.Texture;
                PAT0Palette = prev.Palette;
                if (!PAT0Textures.ContainsKey(PAT0Texture))
                {
                    TEX0Node texture = RootNode.FindChildByType(PAT0Texture, true, ResourceNodes.ResourceType.TEX0) as TEX0Node;
                    if (texture != null)
                    {
                        PAT0Textures[PAT0Texture] = new MDL0TextureNode(texture.Name)
                        {
                            Source = texture, palette = PAT0Palette != null?RootNode.FindChildByType(PAT0Palette, true, ResourceNodes.ResourceType.PLT0) as PLT0Node : null
                        }
                    }
                    ;
                }
                return;
            }
            else
            {
                PAT0Texture = PAT0Palette = null;
            }
        }
Beispiel #4
0
        private unsafe void Load(int index, int program)
        {
            if (TKContext.CurrentContext == null)
            {
                return;
            }

            Source = null;

            if (Texture != null)
            {
                Texture.Delete();
            }
            Texture = new GLTexture();
            Texture.Bind(index, program);

            Bitmap bmp = null;

            if (_folderWatcher.EnableRaisingEvents && !String.IsNullOrEmpty(_folderWatcher.Path))
            {
                bmp = SearchDirectory(_folderWatcher.Path + Name);
            }

            if (bmp == null && TKContext.CurrentContext._states.ContainsKey("_Node_Refs"))
            {
                List <ResourceNode> nodes    = TKContext.CurrentContext._states["_Node_Refs"] as List <ResourceNode>;
                List <ResourceNode> searched = new List <ResourceNode>(nodes.Count);
                TEX0Node            tNode    = null;

                foreach (ResourceNode n in nodes)
                {
                    ResourceNode node = n.RootNode;
                    if (searched.Contains(node))
                    {
                        continue;
                    }
                    searched.Add(node);

                    //Search node itself first
                    if ((tNode = node.FindChild("Textures(NW4R)/" + Name, true) as TEX0Node) != null)
                    {
                        Source = tNode;
                        Texture.Attach(tNode, _palette);
                        return;
                    }
                    else //Then search the directory
                    {
                        bmp = SearchDirectory(node._origPath);
                    }

                    if (bmp != null)
                    {
                        break;
                    }
                }
                searched.Clear();
            }

            if (bmp != null)
            {
                Texture.Attach(bmp);
            }
            else
            {
                Texture.Default();
            }
        }
Beispiel #5
0
        public void ImportFolder(string inFolder)
        {
            DirectoryInfo dir = new DirectoryInfo(inFolder);

            FileInfo[] files;

            files = dir.GetFiles();
            foreach (FileInfo info in files)
            {
                string ext = Path.GetExtension(info.FullName).ToUpper();
                if (ext == ".PNG" || ext == ".TGA" || ext == ".BMP" || ext == ".JPG" || ext == ".JPEG" ||
                    ext == ".GIF" || ext == ".TIF" || ext == ".TIFF")
                {
                    using (TextureConverterDialog dlg = new TextureConverterDialog())
                    {
                        dlg.ImageSource = info.FullName;
                        dlg.ShowDialog(null, this);
                    }
                }
                else if (ext == ".TEX0")
                {
                    TEX0Node node = NodeFactory.FromFile(null, info.FullName) as TEX0Node;
                    GetOrCreateFolder <TEX0Node>().AddChild(node);
                }
                else if (ext == ".MDL0")
                {
                    MDL0Node node = NodeFactory.FromFile(null, info.FullName) as MDL0Node;
                    GetOrCreateFolder <MDL0Node>().AddChild(node);
                }
                else if (ext == ".CHR0")
                {
                    CHR0Node node = NodeFactory.FromFile(null, info.FullName) as CHR0Node;
                    GetOrCreateFolder <CHR0Node>().AddChild(node);
                }
                else if (ext == ".CLR0")
                {
                    CLR0Node node = NodeFactory.FromFile(null, info.FullName) as CLR0Node;
                    GetOrCreateFolder <CLR0Node>().AddChild(node);
                }
                else if (ext == ".SRT0")
                {
                    SRT0Node node = NodeFactory.FromFile(null, info.FullName) as SRT0Node;
                    GetOrCreateFolder <SRT0Node>().AddChild(node);
                }
                else if (ext == ".SHP0")
                {
                    SHP0Node node = NodeFactory.FromFile(null, info.FullName) as SHP0Node;
                    GetOrCreateFolder <SHP0Node>().AddChild(node);
                }
                else if (ext == ".PAT0")
                {
                    PAT0Node node = NodeFactory.FromFile(null, info.FullName) as PAT0Node;
                    GetOrCreateFolder <PAT0Node>().AddChild(node);
                }
                else if (ext == ".VIS0")
                {
                    VIS0Node node = NodeFactory.FromFile(null, info.FullName) as VIS0Node;
                    GetOrCreateFolder <VIS0Node>().AddChild(node);
                }
            }
        }
        private unsafe void Load(int index, int program, PLT0Node palette)
        {
            if (_context == null)
            {
                return;
            }

            Source = null;

            if (Texture != null)
            {
                Texture.Delete();
            }
            Texture = new GLTexture(_context, 0, 0);
            Texture.Bind(index, program);

            //ctx._states[String.Format("{0}_TexRef", Name)] = Texture;

            Bitmap   bmp   = null;
            TEX0Node tNode = null;

            if (_context._states.ContainsKey("_Node_Refs"))
            {
                List <ResourceNode> nodes    = _context._states["_Node_Refs"] as List <ResourceNode>;
                List <ResourceNode> searched = new List <ResourceNode>(nodes.Count);

                foreach (ResourceNode n in nodes)
                {
                    ResourceNode node = n.RootNode;
                    if (searched.Contains(node))
                    {
                        continue;
                    }
                    searched.Add(node);

                    //Search node itself first
                    if ((tNode = node.FindChild("Textures(NW4R)/" + Name, true) as TEX0Node) != null)
                    {
                        Source = tNode;
                        if (palette != null)
                        {
                            bmp = tNode.GetImage(0, palette);
                        }
                        else
                        {
                            bmp = tNode.GetImage(0);
                        }
                    }
                    else
                    {
                        //Then search node directory
                        string path = node._origPath;
                        if (path != null)
                        {
                            DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(path));
                            foreach (FileInfo file in dir.GetFiles(Name + ".*"))
                            {
                                if (file.Name.EndsWith(".tga"))
                                {
                                    Source = file.FullName;
                                    bmp    = TGA.FromFile(file.FullName);
                                    break;
                                }
                                else if (file.Name.EndsWith(".png") || file.Name.EndsWith(".tiff") || file.Name.EndsWith(".tif"))
                                {
                                    Source = file.FullName;
                                    bmp    = (Bitmap)Bitmap.FromFile(file.FullName);
                                    break;
                                }
                            }
                        }
                    }
                    if (bmp != null)
                    {
                        break;
                    }
                }
                searched.Clear();

                if (bmp != null)
                {
                    int w = bmp.Width, h = bmp.Height, size = w * h;

                    Texture._width  = w;
                    Texture._height = h;
                    //_context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MagFilter, (int)GLTextureFilter.LINEAR);
                    //_context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MinFilter, (int)GLTextureFilter.NEAREST_MIPMAP_LINEAR);
                    //_context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.BaseLevel, 0);

                    //if (tNode != null)
                    //    _context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MaxLevel, tNode.LevelOfDetail);
                    //else
                    //    _context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MaxLevel, 0);

                    BitmapData data = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                    try
                    {
                        using (UnsafeBuffer buffer = new UnsafeBuffer(size << 2))
                        {
                            ARGBPixel *sPtr = (ARGBPixel *)data.Scan0;
                            ABGRPixel *dPtr = (ABGRPixel *)buffer.Address;

                            for (int i = 0; i < size; i++)
                            {
                                *dPtr++ = (ABGRPixel)(*sPtr++);
                            }

                            int res = _context.gluBuild2DMipmaps(GLTextureTarget.Texture2D, GLInternalPixelFormat._4, w, h, GLPixelDataFormat.RGBA, GLPixelDataType.UNSIGNED_BYTE, buffer.Address);
                            if (res != 0)
                            {
                            }
                        }
                    }
                    finally
                    {
                        bmp.UnlockBits(data);
                        bmp.Dispose();
                    }
                }
            }
        }
Beispiel #7
0
        private unsafe void Load(int index, int program, PLT0Node palette)
        {
            if (_context == null)
            {
                return;
            }

            Source = null;

            if (Texture != null)
            {
                Texture.Delete();
            }
            Texture = new GLTexture();
            Texture.Bind(index, program, _context);

            //ctx._states[String.Format("{0}_TexRef", Name)] = Texture;

            Bitmap   bmp   = null;
            TEX0Node tNode = null;

            if (_context._states.ContainsKey("_Node_Refs"))
            {
                List <ResourceNode> nodes    = _context._states["_Node_Refs"] as List <ResourceNode>;
                List <ResourceNode> searched = new List <ResourceNode>(nodes.Count);

                foreach (ResourceNode n in nodes)
                {
                    ResourceNode node = n.RootNode;
                    if (searched.Contains(node))
                    {
                        continue;
                    }
                    searched.Add(node);

                    //Search node itself first
                    if ((tNode = node.FindChild("Textures(NW4R)/" + Name, true) as TEX0Node) != null)
                    {
                        Source = tNode;
                        if (palette != null)
                        {
                            Texture.Attach(tNode, palette);
                        }
                        else
                        {
                            Texture.Attach(tNode);
                        }
                        return;
                    }
                    else
                    {
                        //Then search node directory
                        string path = node._origPath;
                        if (path != null)
                        {
                            DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(path));
                            if (dir.Exists && Name != "<null>")
                            {
                                foreach (FileInfo file in dir.GetFiles(Name + ".*"))
                                {
                                    if (file.Name.EndsWith(".tga"))
                                    {
                                        Source = file.FullName;
                                        bmp    = TGA.FromFile(file.FullName);
                                        break;
                                    }
                                    else if (file.Name.EndsWith(".png") || file.Name.EndsWith(".tiff") || file.Name.EndsWith(".tif"))
                                    {
                                        Source = file.FullName;
                                        bmp    = (Bitmap)Bitmap.FromFile(file.FullName);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (bmp != null)
                    {
                        break;
                    }
                }
                searched.Clear();

                if (bmp != null)
                {
                    Texture.Attach(bmp);
                }
            }
        }
Beispiel #8
0
        private unsafe void Load(int index, int program)
        {
            if (TKContext.CurrentContext == null)
            {
                return;
            }

            bool isStage = false;

            Source = null;

            if (Texture != null)
            {
                Texture.Delete();
            }
            Texture = new GLTexture();
            Texture.Bind(index, program);

            Bitmap bmp = null;

            if (RootNode is ARCNode)
            {
                isStage = ((ARCNode)RootNode).IsStage;
            }

            if (_folderWatcher.EnableRaisingEvents && !String.IsNullOrEmpty(_folderWatcher.Path))
            {
                bmp = SearchDirectory(_folderWatcher.Path + Name);
            }

            BRRESNode parentBRRES = null;
            ARCNode   parentARC   = null;

            // Safely search for whether this is part of a BRRES
            if (_parent != null)
            {
                if (_parent._parent != null)
                {
                    if (_parent._parent._parent != null)
                    {
                        if (_parent._parent._parent._parent != null)
                        {
                            if (_parent._parent._parent._parent is BRRESNode)
                            {
                                parentBRRES = (BRRESNode)_parent._parent._parent._parent;
                                if (parentBRRES._parent != null)
                                {
                                    if (parentBRRES._parent is ARCNode)
                                    {
                                        parentARC = (ARCNode)parentBRRES._parent;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            List <ResourceNode> nodes = TKContext.CurrentContext._states["_Node_Refs"] as List <ResourceNode>;
            TEX0Node            tNode = null;

            if (bmp == null && TKContext.CurrentContext._states.ContainsKey("_Node_Refs") && parentBRRES != null)
            {
                ResourceNode node = parentBRRES;

                //Search node itself first
                if ((tNode = node.SearchForTextures("Textures(NW4R)/" + Name, true, false) as TEX0Node) != null)
                {
                    Source = tNode;
                    Texture.Attach(tNode, _palette);
                    return;
                }
            }

            if (bmp == null && TKContext.CurrentContext._states.ContainsKey("_Node_Refs") && parentARC != null)
            {
                ResourceNode node = parentARC;

                //Search node itself first
                if ((tNode = node.SearchForTextures("Textures(NW4R)/" + Name, true, isStage) as TEX0Node) != null)
                {
                    Source = tNode;
                    Texture.Attach(tNode, _palette);
                    return;
                }
                else //Then search the directory
                {
                    bmp = SearchDirectory(node._origPath);
                }
            }

            if (bmp != null)
            {
                Texture.Attach(bmp);
            }
            else
            {
                Texture.Default();
            }
        }