/// <summary>
 ///     Initializes the control with animation data.
 /// </summary>
 /// <param name="renderEngine">Renderer used to render the model</param>
 /// <param name="ctrl">The animation control</param>
 /// <param name="anms">The list with animations</param>
 /// <param name="t">The animation type (used on Export/Import options)</param>
 public void initialize(RenderEngine renderEngine, RenderEngine.animationControl ctrl, RenderBase.OAnimationListBase anms, FileIO.fileType t)
 {
     renderer = renderEngine;
     control = ctrl;
     animations = anms;
     type = t;
     control.FrameChanged += Control_FrameChanged;
     updateList();
 }
        public void launch(object data)
        {
            RenderBase.OModelGroup group = (RenderBase.OModelGroup)data;
            animations = new RenderBase.OAnimationListBase();

            foreach (RenderBase.OAnimationBase mAnim in group.materialAnimation.list)
            {
                animations.list.Add(mAnim);
            }

            foreach (RenderBase.OAnimationBase sAnim in group.skeletalAnimation.list)
            {
                animations.list.Add(sAnim);
            }

            foreach (RenderBase.OAnimationBase vAnim in group.visibilityAnimation.list)
            {
                animations.list.Add(vAnim);
            }

            updateList();
        }
        public void launch(RenderEngine renderEngine, FileIO.fileType type)
        {
            renderer = renderEngine;
            this.type = type;
            switch (type)
            {
                case FileIO.fileType.skeletalAnimation:
                    control = renderer.ctrlSA;
                    animations = renderer.models.skeletalAnimation;
                    break;
                case FileIO.fileType.materialAnimation:
                    control = renderer.ctrlMA;
                    animations = renderer.models.materialAnimation;
                    break;
                case FileIO.fileType.visibilityAnimation:
                    control = renderer.ctrlVA;
                    animations = renderer.models.visibilityAnimation;
                    break;
            }

            control.FrameChanged += Control_FrameChanged;
            updateList();
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Imports a file of the given type.
        ///     Returns data relative to the chosen type.
        /// </summary>
        /// <param name="type">The type of the data</param>
        /// <returns></returns>
        public static object import(fileType type)
        {
            using (OpenFileDialog openDlg = new OpenFileDialog())
            {
                openDlg.Multiselect = true;

                switch (type)
                {
                case fileType.model:
                    openDlg.Title  = "Import models";
                    openDlg.Filter = "All files|*.*";

                    if (openDlg.ShowDialog() == DialogResult.OK)
                    {
                        List <RenderBase.OModel> output = new List <RenderBase.OModel>();
                        foreach (string fileName in openDlg.FileNames)
                        {
                            output.AddRange(((RenderBase.OModelGroup)load(fileName).data).model);
                        }
                        return(output);
                    }
                    break;

                case fileType.texture:
                    openDlg.Title  = "Import textures";
                    openDlg.Filter = "All files|*.*";

                    if (openDlg.ShowDialog() == DialogResult.OK)
                    {
                        List <RenderBase.OTexture> output = new List <RenderBase.OTexture>();
                        foreach (string fileName in openDlg.FileNames)
                        {
                            file file = load(fileName);
                            switch (file.type)
                            {
                            case formatType.model: output.AddRange(((RenderBase.OModelGroup)file.data).texture); break;

                            case formatType.texture: output.AddRange((List <RenderBase.OTexture>)file.data); break;

                            case formatType.image: output.Add((RenderBase.OTexture)file.data); break;
                            }
                        }
                        return(output);
                    }
                    break;

                case fileType.skeletalAnimation:
                    openDlg.Title  = "Import skeletal animations";
                    openDlg.Filter = "All files|*.*";

                    if (openDlg.ShowDialog() == DialogResult.OK)
                    {
                        RenderBase.OAnimationListBase output = new RenderBase.OAnimationListBase();
                        foreach (string fileName in openDlg.FileNames)
                        {
                            output.list.AddRange(((RenderBase.OModelGroup)load(fileName).data).skeletalAnimation.list);
                        }
                        return(output);
                    }
                    break;

                case fileType.materialAnimation:
                    openDlg.Title  = "Import material animations";
                    openDlg.Filter = "All files|*.*";

                    if (openDlg.ShowDialog() == DialogResult.OK)
                    {
                        RenderBase.OAnimationListBase output = new RenderBase.OAnimationListBase();
                        foreach (string fileName in openDlg.FileNames)
                        {
                            output.list.AddRange(((RenderBase.OModelGroup)load(fileName).data).materialAnimation.list);
                        }
                        return(output);
                    }
                    break;

                case fileType.visibilityAnimation:
                    openDlg.Title  = "Import visibility animations";
                    openDlg.Filter = "All files|*.*";

                    if (openDlg.ShowDialog() == DialogResult.OK)
                    {
                        RenderBase.OAnimationListBase output = new RenderBase.OAnimationListBase();
                        foreach (string fileName in openDlg.FileNames)
                        {
                            output.list.AddRange(((RenderBase.OModelGroup)load(fileName).data).visibilityAnimation.list);
                        }
                        return(output);
                    }
                    break;
                }
            }

            return(null);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Imports a file of the given type.
        ///     Returns data relative to the chosen type.
        /// </summary>
        /// <param name="type">The type of the data</param>
        /// <returns></returns>
        public static object import(fileType type)
        {
            using (OpenFileDialog openDlg = new OpenFileDialog())
            {
                openDlg.Multiselect = true;

                switch (type)
                {
                    case fileType.model:
                        openDlg.Title = "Import models";
                        openDlg.Filter = "All files|*.*";

                        if (openDlg.ShowDialog() == DialogResult.OK)
                        {
                            omodelOutput = new List<RenderBase.OModel>();
                            foreach (string fileName in openDlg.FileNames)
                            {
                                omodelOutput.AddRange(((RenderBase.OModelGroup)load(fileName).data).model);
                            }
                            return omodelOutput;
                        }
                        break;
                    case fileType.texture:
                        openDlg.Title = "Import textures";
                        openDlg.Filter = "All files|*.*";

                        if (openDlg.ShowDialog() == DialogResult.OK)
                        {
                            otexOutput = new List<RenderBase.OTexture>();
                            foreach (string fileName in openDlg.FileNames)
                            {
                                file file = load(fileName);
                                switch (file.type)
                                {
                                    case formatType.model: otexOutput.AddRange(((RenderBase.OModelGroup)file.data).texture); break;
                                    case formatType.texture: otexOutput.AddRange((List<RenderBase.OTexture>)file.data); break;
                                }
                            }
                            return otexOutput;
                        }
                        break;
                    case fileType.skeletalAnimation:
                        openDlg.Title = "Import skeletal animations";
                        openDlg.Filter = "All files|*.*";

                        if (openDlg.ShowDialog() == DialogResult.OK)
                        {
                            output = new RenderBase.OAnimationListBase();
                            foreach (string fileName in openDlg.FileNames)
                            {
                                try
                                {
                                    output.list.AddRange(((RenderBase.OModelGroup)load(fileName).data).skeletalAnimation.list);
                                }
                                catch
                                {
                                }
                            }
                            return output;
                        }
                        break;
                    case fileType.materialAnimation:
                        openDlg.Title = "Import material animations";
                        openDlg.Filter = "All files|*.*";

                        if (openDlg.ShowDialog() == DialogResult.OK)
                        {
                            output = new RenderBase.OAnimationListBase();
                            foreach (string fileName in openDlg.FileNames)
                            {
                                try
                                {
                                    output.list.AddRange(((RenderBase.OModelGroup)load(fileName).data).materialAnimation.list);
                                }
                                catch
                                {
                                }
                            }
                            return output;
                        }
                        break;
                    case fileType.visibilityAnimation:
                        openDlg.Title = "Import visibility animations";
                        openDlg.Filter = "All files|*.*";

                        if (openDlg.ShowDialog() == DialogResult.OK)
                        {
                            output = new RenderBase.OAnimationListBase();
                            foreach (string fileName in openDlg.FileNames)
                            {
                                try
                                {
                                    output.list.AddRange(((RenderBase.OModelGroup)load(fileName).data).visibilityAnimation.list);
                                }
                                catch
                                {
                                }
                            }
                            return output;
                        }
                        break;
                }
            }

            return null;
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Imports a file of the given type.
        ///     Returns data relative to the chosen type.
        /// </summary>
        /// <param name="type">The type of the data</param>
        /// <returns></returns>
        public static Object import(fileType type)
        {
            using (OpenFileDialog openDlg = new OpenFileDialog())
            {
                openDlg.Multiselect = true;

                switch (type)
                {
                    case fileType.model:
                        openDlg.Title = "Import Model";
                        openDlg.Filter = "All supported files|*.bch;*.bcmdl;*.bcres;*.cx;*.lz;*.cmp;*.zmdl;*.smes;*.smd";
                        openDlg.Filter += "|Binary CTR H3D|*.bch";
                        openDlg.Filter += "|Binary CTR Model|*.bcmdl";
                        openDlg.Filter += "|Binary CTR Resource|*.bcres";
                        openDlg.Filter += "|Compressed file|*.cx;*.lz;*.cmp";
                        openDlg.Filter += "|Fantasy Life Model|*.zmdl";
                        openDlg.Filter += "|New Love Plus Mesh|*.smes";
                        openDlg.Filter += "|StudioMdl Model|*.smd";
                        openDlg.Filter += "|All files|*.*";

                        if (openDlg.ShowDialog() == DialogResult.OK)
                        {
                            List<RenderBase.OModel> output = new List<RenderBase.OModel>();
                            foreach (string fileName in openDlg.FileNames)
                            {
                                try
                                {
                                    switch (Path.GetExtension(fileName).ToLower())
                                    {
                                        case ".smd": output.AddRange(SMD.import(fileName).model); break;
                                        default:
                                            byte[] buffer = File.ReadAllBytes(fileName);
                                            Stream data = new MemoryStream(buffer);
                                            fileFormat format = identify(fileName);
                                            if (isCompressed(format)) decompress(ref data, ref format);
                                            switch (format)
                                            {
                                                case fileFormat.flZMdl: output.AddRange(ZMDL.load(data).model); break;
                                                case fileFormat.nlpSMes: output.AddRange(NLP.loadMesh(data).model); break;
                                                case fileFormat.nw4cCGfx: output.AddRange(CGFX.load(data).model); break;
                                                case fileFormat.nw4cH3D: output.AddRange(BCH.load((MemoryStream)data).model); break;
                                                case fileFormat.pkmnContainer: 
                                                    GenericContainer.OContainer container = PkmnContainer.load(data);
                                                    switch (container.fileIdentifier)
                                                    {
                                                        case "PC": //Pokémon model
                                                            output.AddRange(BCH.load(new MemoryStream(container.content[0].data)).model);
                                                            break;
                                                        case "MM": //Pokémon Overworld model
                                                            output.AddRange(BCH.load(new MemoryStream(container.content[0].data)).model);
                                                            break;
                                                        case "GR": //Pokémon Map model
                                                            output.AddRange(BCH.load(new MemoryStream(container.content[1].data)).model);
                                                            break;
                                                        case "PT": //Pokémon texture
                                                            output.AddRange(BCH.load(new MemoryStream(container.content[0].data)).model);
                                                            break;
                                                        case "PK": //Pokemon Visibility/Skeletal animations
                                                            output.AddRange(BCH.load(new MemoryStream(container.content[0].data)).model);
                                                            break;
                                                        case "PB": //Pokémon material animations
                                                            output.AddRange(BCH.load(new MemoryStream(container.content[0].data)).model);
                                                            break;
                                                        case "AD": //???
                                                            output.AddRange(BCH.load(new MemoryStream(container.content[0].data)).model);
                                                            break;
                                                    }
                                                    break;
                                                default: data.Close(); break;
                                            }
                                            break;
                                    }
                                }
                                catch
                                {
                                    Debug.WriteLine("FileIO: Unable to import model file \"" + fileName + "\"!");
                                }
                            }
                            return output;
                        }
                        break;
                    case fileType.texture:
                        openDlg.Title = "Import Texture";
                        openDlg.Filter = "All supported files|*.bch;*.bcmdl;*.bcres;*.bctex;*.cx;*.lz;*.cmp;*.ztex";
                        openDlg.Filter += "|Binary CTR H3D|*.bch";
                        openDlg.Filter += "|Binary CTR Model|*.bcmdl";
                        openDlg.Filter += "|Binary CTR Resource|*.bcres";
                        openDlg.Filter += "|Binary CTR Texture|*.bctex";
                        openDlg.Filter += "|Compressed file|*.cx;*.lz;*.cmp";
                        openDlg.Filter += "|Fantasy Life Texture|*.ztex";
                        openDlg.Filter += "|All files|*.*";

                        if (openDlg.ShowDialog() == DialogResult.OK)
                        {
                            List<RenderBase.OTexture> output = new List<RenderBase.OTexture>();
                            foreach (string fileName in openDlg.FileNames)
                            {
                                byte[] buffer = File.ReadAllBytes(fileName);
                                Stream data = new MemoryStream(buffer);
                                fileFormat format = identify(fileName);
                                if (isCompressed(format)) decompress(ref data, ref format);
                                switch (format)
                                {
                                    case fileFormat.flZTex: output.AddRange(ZTEX.load(data)); break;
                                    case fileFormat.nw4cCGfx: output.AddRange(CGFX.load(data).texture); break;
                                    case fileFormat.nw4cH3D: output.AddRange(BCH.load((MemoryStream)data).texture); break;
                                    case fileFormat.pkmnContainer: 
                                        GenericContainer.OContainer container = PkmnContainer.load(data);
                                        switch (container.fileIdentifier)
                                        {
                                            case "PC": //Pokémon model
                                                output.AddRange(BCH.load(new MemoryStream(container.content[0].data)).texture);
                                                break;
                                            case "MM": //Pokémon Overworld model
                                                output.AddRange(BCH.load(new MemoryStream(container.content[0].data)).texture);
                                                break;
                                            case "GR": //Pokémon Map model
                                                output.AddRange(BCH.load(new MemoryStream(container.content[1].data)).texture);
                                                break;
                                            case "PT": //Pokémon texture
                                                output.AddRange(BCH.load(new MemoryStream(container.content[0].data)).texture);
                                                break;
                                            case "PK": //Pokemon Visibility/Skeletal animations
                                                output.AddRange(BCH.load(new MemoryStream(container.content[0].data)).texture);
                                                break;
                                            case "PB": //Pokémon material animations
                                                output.AddRange(BCH.load(new MemoryStream(container.content[0].data)).texture);
                                                break;
                                            case "AD": //???
                                                output.AddRange(BCH.load(new MemoryStream(container.content[0].data)).texture);
                                                break;
                                        }
                                        break;
                                    default: data.Close(); break;
                                }
                            }
                            return output;
                        }
                        break;
                    case fileType.skeletalAnimation:
                        openDlg.Title = "Import Skeletal Animation";
                        openDlg.Filter = "All supported files|*.bch;*.bcres;*.bcskla;*.smd";
                        openDlg.Filter += "|Binary CTR H3D|*.bch";
                        openDlg.Filter += "|Binary CTR Resource|*.bcres";
                        openDlg.Filter += "|Binary CTR Skeletal Animation|*.bcskla";
                        openDlg.Filter += "|StudioMdl Model|*.smd";
                        openDlg.Filter += "|All files|*.*";

                        if (openDlg.ShowDialog() == DialogResult.OK)
                        {
                            RenderBase.OAnimationListBase output = new RenderBase.OAnimationListBase();
                            foreach (string fileName in openDlg.FileNames)
                            {
                                switch (Path.GetExtension(fileName).ToLower())
                                {
                                    case ".smd": output.list.AddRange(SMD.import(fileName).skeletalAnimation.list); break;
                                    default:
                                        byte[] buffer = File.ReadAllBytes(fileName);
                                        Stream data = new MemoryStream(buffer);
                                        fileFormat format = identify(fileName);
                                        if (isCompressed(format)) decompress(ref data, ref format);
                                        switch (format)
                                        {
                                            case fileFormat.nw4cCGfx: output.list.AddRange(CGFX.load(data).skeletalAnimation.list); break;
                                            case fileFormat.nw4cH3D: output.list.AddRange(BCH.load((MemoryStream)data).skeletalAnimation.list); break;
                                            default: data.Close(); break;
                                        }
                                        break;
                                }
                            }
                            return output;
                        }
                        break;
                    case fileType.materialAnimation:
                        openDlg.Title = "Import Material Animation";
                        openDlg.Filter = "All supported files|*.bch;";
                        openDlg.Filter += "|Binary CTR H3D|*.bch";
                        openDlg.Filter += "|All files|*.*";

                        if (openDlg.ShowDialog() == DialogResult.OK)
                        {
                            RenderBase.OAnimationListBase output = new RenderBase.OAnimationListBase();
                            foreach (string fileName in openDlg.FileNames)
                            {

                                byte[] buffer = File.ReadAllBytes(fileName);
                                Stream data = new MemoryStream(buffer);
                                fileFormat format = identify(fileName);
                                if (isCompressed(format)) decompress(ref data, ref format);
                                switch (format)
                                {
                                    case fileFormat.nw4cCGfx: output.list.AddRange(CGFX.load(data).materialAnimation.list); break;
                                    case fileFormat.nw4cH3D: output.list.AddRange(BCH.load((MemoryStream)data).materialAnimation.list); break;
                                    default: data.Close(); break;
                                }
                            }
                            return output;
                        }
                        break;
                    case fileType.visibilityAnimation:
                        openDlg.Title = "Import Visibility Animation";
                        openDlg.Filter = "All supported files|*.bch;";
                        openDlg.Filter += "|Binary CTR H3D|*.bch";
                        openDlg.Filter += "|All files|*.*";

                        if (openDlg.ShowDialog() == DialogResult.OK)
                        {
                            RenderBase.OAnimationListBase output = new RenderBase.OAnimationListBase();
                            foreach (string fileName in openDlg.FileNames)
                            {

                                byte[] buffer = File.ReadAllBytes(fileName);
                                Stream data = new MemoryStream(buffer);
                                fileFormat format = identify(fileName);
                                if (isCompressed(format)) decompress(ref data, ref format);
                                switch (format)
                                {
                                    case fileFormat.nw4cCGfx: output.list.AddRange(CGFX.load(data).visibilityAnimation.list); break;
                                    case fileFormat.nw4cH3D: output.list.AddRange(BCH.load((MemoryStream)data).visibilityAnimation.list); break;
                                    default: data.Close(); break;
                                }
                            }
                            return output;
                        }
                        break;
                }
            }

            return null;
        }