예제 #1
0
        public static H3D MergeFromBytearray(byte[] data, Renderer Renderer, H3D Scene = null)
        {
            if (Scene == null)
            {
                //Renderer.DeleteAll();

                Scene = new H3D();
            }


            H3DDict <H3DBone> Skeleton = null;

            if (Scene.Models.Count > 0)
            {
                Skeleton = Scene.Models[0].Skeleton;
            }

            H3D Data = SPICA.Formats.CtrGfx.Gfx.Open(new MemoryStream(data));

            if (Data != null)
            {
                Scene.Merge(Data);

                Renderer.Merge(Data);
            }

            return(Scene);
        }
예제 #2
0
파일: GFAreaLOD.cs 프로젝트: HelloOO7/SPICA
        public static H3D OpenAsH3D(Stream Input, GFPackage.Header Header, int StartIndex)
        {
            H3D Output = new H3D();

            //Textures and animations
            for (int i = StartIndex; i < Header.Entries.Length; i++)
            {
                byte[] Buffer = new byte[Header.Entries[i].Length];

                Input.Seek(Header.Entries[i].Address, SeekOrigin.Begin);

                Input.Read(Buffer, 0, Buffer.Length);

                Stream Input2 = new MemoryStream(Buffer);

                GFPackage.Header h = GFPackage.GetPackageHeader(Input2);

                for (int j = 0; j < h.Entries.Length; j++)
                {
                    byte[] Buffer2 = new byte[h.Entries[j].Length];

                    Input2.Seek(h.Entries[j].Address, SeekOrigin.Begin);

                    Input2.Read(Buffer2, 0, Buffer2.Length);
                    using (MemoryStream MS = new MemoryStream(Buffer2))
                    {
                        Output.Merge(H3D.Open(MS));
                    }
                }
            }

            return(Output);
        }
예제 #3
0
파일: MBn.cs 프로젝트: yorki00/SPICA
        public H3D ToH3D()
        {
            H3D Output = BaseScene;

            H3DModel Model = Output.Models[0];

            int IndicesIndex = 0, i = 0;

            foreach (H3DMesh Mesh in Model.Meshes.OrderBy(x => (int)x.MetaData["ShapeId"].Values[0]))
            {
                Mesh.PositionOffset = Vector4.Zero;

                Mesh.Attributes.Clear();
                Mesh.Attributes.AddRange(VerticesDesc[i].Attributes);

                Mesh.RawBuffer    = VerticesDesc[i].RawBuffer;
                Mesh.VertexStride = VerticesDesc[i].VertexStride;

                for (int j = 0; j < Mesh.SubMeshes.Count; j++)
                {
                    H3DSubMesh SM = Mesh.SubMeshes[j];

                    SM.Indices     = IndicesDesc[IndicesIndex].Indices;
                    SM.BoneIndices = IndicesDesc[IndicesIndex].BoneIndices;

                    IndicesIndex++;
                }

                i++;
            }

            return(Output);
        }
예제 #4
0
        public static H3D OpenAsH3D(Stream Input, GFPackage.Header Header, int StartIndex)
        {
            H3D Output = new H3D();

            //Textures and animations
            for (int i = StartIndex; i < Header.Entries.Length; i++)
            {
                byte[] Buffer = new byte[Header.Entries[i].Length];

                Input.Seek(Header.Entries[i].Address, SeekOrigin.Begin);

                Input.Read(Buffer, 0, Buffer.Length);

                if (Buffer.Length > 4 && Buffer[0] == 0 && Buffer[1] == 0 && Buffer[2] == 1 && Buffer[3] == 0)
                {
                    Output.Merge(new SPICA.Formats.GFL2.GFModelPack(new MemoryStream(Buffer)).ToH3D());
                }

                if (Buffer.Length < 4 || Encoding.ASCII.GetString(Buffer, 0, 4) != "BCH\0")
                {
                    continue;
                }

                using (MemoryStream MS = new MemoryStream(Buffer))
                {
                    Output.Merge(H3D.Open(MS));
                }
            }

            return(Output);
        }
예제 #5
0
        public H3D CreateH3DFromContent()
        {
            H3D Output = new H3D();

            foreach (byte[] File in Files)
            {
                if (File.Length < 4)
                {
                    continue;
                }

                if (File[0] == 'B' &&
                    File[1] == 'C' &&
                    File[2] == 'H' &&
                    File[3] == '\0')
                {
                    Output.Merge(H3D.Open(File));
                }

                if (File[0] == 0 && File[1] == 0 && File[2] == 1 && File[3] == 0)
                {
                    Output.Merge(new SPICA.Formats.GFL2.GFModelPack(new MemoryStream(File)).ToH3D());
                }
            }

            return(Output);
        }
예제 #6
0
 public void Merge(H3D Scene)
 {
     Merge(Scene.Models);
     Merge(Scene.Textures);
     Merge(Scene.LUTs);
     Merge(Scene.Lights);
     Merge(Scene.Shaders);
 }
예제 #7
0
파일: MTTexture.cs 프로젝트: yorki00/SPICA
        public H3D ToH3D()
        {
            H3D Output = new H3D();

            Output.Textures.Add(ToH3DTexture());

            return(Output);
        }
예제 #8
0
    public void ImportModel(PSMDImportManifest.Model modelManifest)
    {
        string path        = Path.Combine(_manifest.PsmdPkGraphicPath, modelManifest.PsmdModel);
        var    spicaHandle = H3D.Open(File.ReadAllBytes(path));

        string targetDir          = ImportHelpers.CreateDirectoryForImport(modelManifest.TargetName);
        string targetTexturesDir  = Path.Combine(targetDir, "Textures");
        string targetMaterialsDir = Path.Combine(targetDir, "Materials");
        string targetMeshesDir    = Path.Combine(targetDir, "Meshes");

        ImportHelpers.EnsureDirectoryExists(targetTexturesDir);
        ImportHelpers.EnsureDirectoryExists(targetMaterialsDir);

        string modelPath = Path.Combine(targetDir, $"{modelManifest.TargetName}.dae");

        new DAE(spicaHandle, 0).Save(modelPath);

        AssetDatabase.ImportAsset(modelPath.ToAssetPath());

        var unityTextures = new List <Texture>();

        foreach (var spicaTexture in spicaHandle.Textures)
        {
            var tempTexture = new Texture2D(spicaTexture.Width, spicaTexture.Height, TextureFormat.RGBA32, false);
            tempTexture.LoadRawTextureData(spicaTexture.ToRGBA());

            var unityTexture = new Texture2D(tempTexture.width, tempTexture.height, TextureFormat.RGBA32, true);
            unityTexture.SetPixels(tempTexture.GetPixels()); // Workaround to get mipmaps
            unityTexture.Apply(true);
            AssetDatabase.CreateAsset(unityTexture, Path.Combine(targetTexturesDir, $"{spicaTexture.Name}.asset").ToAssetPath());
            unityTextures.Add(unityTexture);
        }

        var modelImporter = AssetImporter.GetAtPath(modelPath.ToAssetPath()) as ModelImporter;

        if (modelImporter == null)
        {
            throw new Exception("Couldn't import model.");
        }

        var spicaMaterials = spicaHandle.Models[0].Materials;

        foreach (var spicaMaterial in spicaMaterials)
        {
            var material = CreateMaterial(spicaMaterial, unityTextures);
            AssetDatabase.CreateAsset(material, Path.Combine(targetMaterialsDir, $"{spicaMaterial.Name}.asset").ToAssetPath());

            modelImporter.AddRemap(new AssetImporter.SourceAssetIdentifier(typeof(Material), material.name + "_mat"), material);
        }

        modelImporter.SaveAndReimport();

        string prefabPath = Path.Combine(targetDir, $"{modelManifest.TargetName}.prefab").ToAssetPath();

        ImportHelpers.GeneratePrefabForModel(modelPath, prefabPath, targetMeshesDir);

        AssetImporter.GetAtPath(prefabPath).assetBundleName = modelManifest.TargetName;
    }
예제 #9
0
        private void FileOpen(string[] Files, bool MergeMode)
        {
            if (!MergeMode)
            {
                Renderer.DeleteAll();

                Renderer.Lights.Add(new Light()
                {
                    Ambient         = new Color4(0.1f, 0.1f, 0.1f, 1.0f),
                    Diffuse         = new Color4(0.9f, 0.9f, 0.9f, 1.0f),
                    Specular0       = new Color4(0.8f, 0.8f, 0.8f, 1.0f),
                    Specular1       = new Color4(0.4f, 0.4f, 0.4f, 1.0f),
                    TwoSidedDiffuse = true,
                    Enabled         = true
                });

                ResetTransforms();

                Scene = FileIO.Merge(Files, Renderer);

                if (Scene != null)
                {
                    TextureManager.Textures = Scene.Textures;
                    ModelsList.Bind(Scene.Models);
                    TexturesList.Bind(Scene.Textures);
                    CamerasList.Bind(Scene.Cameras);
                    LightsList.Bind(Scene.Lights);
                    SklAnimsList.Bind(Scene.SkeletalAnimations);
                    MatAnimsList.Bind(Scene.MaterialAnimations);
                    VisAnimsList.Bind(Scene.VisibilityAnimations);
                    CamAnimsList.Bind(Scene.CameraAnimations);
                    LUTsList.Bind(Scene.LUTs);

                    Animator.Enabled     = false;
                    LblAnimSpeed.Text    = string.Empty;
                    LblAnimLoopMode.Text = string.Empty;
                    AnimSeekBar.Value    = 0;
                    AnimSeekBar.Maximum  = 0;
                    AnimGrp.Frame        = 0;
                    AnimGrp.FramesCount  = 0;

                    if (Scene.Models.Count > 0)
                    {
                        ModelsList.Select(0);
                    }
                    else
                    {
                        UpdateTransforms();
                    }
                }
            }
            else
            {
                Scene = FileIO.Merge(Files, Renderer, Scene);
            }
        }
예제 #10
0
파일: SMD.cs 프로젝트: HelloOO7/SPICA
        public SMD(H3D Scene, int MdlIndex, int AnimIndex = -1)
        {
            int Index = 0;

            if (Scene == null || Scene.Models.Count == 0)
            {
                return;
            }

            if (MdlIndex != -1 && AnimIndex == -1)
            {
                H3DModel Mdl = Scene.Models[MdlIndex];

                foreach (H3DBone Bone in Mdl.Skeleton)
                {
                    SMDNode Node = new SMDNode()
                    {
                        Index       = Index,
                        Name        = Bone.Name,
                        ParentIndex = Bone.ParentIndex
                    };

                    SMDBone B = new SMDBone()
                    {
                        NodeIndex   = Index++,
                        Translation = Bone.Translation,
                        Rotation    = Bone.Rotation
                    };

                    Nodes.Add(Node);
                    Skeleton.Add(B);
                }

                foreach (H3DMesh Mesh in Mdl.Meshes)
                {
                    if (Mesh.Type == H3DMeshType.Silhouette)
                    {
                        continue;
                    }

                    PICAVertex[] Vertices = Mesh.GetVertices();

                    string MaterialName = Mdl.Materials[Mesh.MaterialIndex].Texture0Name;
                    if (MaterialName.Equals("projection_dummy") && Mdl.Materials[Mesh.MaterialIndex].Texture1Name != null)
                    {
                        MaterialName = Mdl.Materials[Mesh.MaterialIndex].Texture1Name;
                    }

                    Meshes.Add(new SMDMesh()
                    {
                        MaterialName = MaterialName + ".png",
                        Vertices     = MeshTransform.GetVerticesList(Mdl.Skeleton, Mesh)
                    });
                }
            }
        }
예제 #11
0
파일: FileIO.cs 프로젝트: Batonapiton/SPICA
        public static void ExportTextures(H3D Scene, string path)
        {
            TextureManager.Textures = Scene.Textures;
            for (int i = 0; i < Scene.Textures.Count; i++)
            {
                string FileName = Path.Combine(path, $"{Scene.Textures[i].Name}.png");

                TextureManager.GetTexture(i).Save(FileName);
            }
        }
예제 #12
0
        private void FileOpen(string[] Files, bool MergeMode)
        {
            if (!MergeMode)                     //if not merging in a model
            {
                Renderer.DeleteAll();           //clear existing meshes

                Renderer.Lights.Add(new Light() //add a new light to the {scene/renderer}
                {
                    Ambient         = new Color4(0.1f, 0.1f, 0.1f, 1.0f),
                    Diffuse         = new Color4(0.9f, 0.9f, 0.9f, 1.0f),
                    Specular0       = new Color4(0.8f, 0.8f, 0.8f, 1.0f),
                    Specular1       = new Color4(0.4f, 0.4f, 0.4f, 1.0f),
                    TwoSidedDiffuse = true,
                    Enabled         = true
                });

                ResetTransforms();

                Scene = FileIO.Merge(Files, Renderer);

                TextureManager.Textures = Scene.Textures;

                ModelsList.Bind(Scene.Models);
                TexturesList.Bind(Scene.Textures);
                CamerasList.Bind(Scene.Cameras);
                LightsList.Bind(Scene.Lights);
                SklAnimsList.Bind(Scene.SkeletalAnimations);
                MatAnimsList.Bind(Scene.MaterialAnimations);
                VisAnimsList.Bind(Scene.VisibilityAnimations);
                CamAnimsList.Bind(Scene.CameraAnimations);

                Animator.Enabled     = false;
                LblAnimSpeed.Text    = string.Empty;
                LblAnimLoopMode.Text = string.Empty;
                AnimSeekBar.Value    = 0;
                AnimSeekBar.Maximum  = 0;
                AnimGrp.Frame        = 0;
                AnimGrp.FramesCount  = 0;

                if (Scene.Models.Count > 0)
                {
                    //TODO: if not moving camera on model select, move camera to default pos here
                    ModelsList.Select(0);
                }
                else
                {
                    UpdateTransforms();
                }
            }
            else
            {
                Scene = FileIO.Merge(Files, Renderer, Scene);
            }
        }
예제 #13
0
        private void ConvertH3D(System.IO.Stream stream)
        {
            CanSave = true;

            System.IO.BinaryReader Reader = new System.IO.BinaryReader(stream);
            using (FileReader reader = new FileReader(stream, true))
            {
                uint magicNumber = reader.ReadUInt32();

                switch (magicNumber)
                {
                case 0x15122117:
                    FormatType = FileFormatType.GFModel;
                    H3DFile    = new H3D();
                    H3DFile.Models.Add(new SPICA.Formats.GFL2.Model.GFModel(Reader, "Model").ToH3DModel());
                    break;
                }

                string mbnPath = FilePath.Replace("bch", "mbn");

                if (reader.CheckSignature(3, "BCH"))
                {
                    H3DFile    = H3D.Open(stream.ToBytes());
                    FormatType = FileFormatType.BCH;
                    return;
                }
                else if (reader.CheckSignature(4, "CGFX"))
                {
                    H3DFile    = SPICA.Formats.CtrGfx.Gfx.Open(stream);
                    FormatType = FileFormatType.BCRES;
                }
                else if (GFPackage.IsValidPackage(stream))
                {
                    GFPackage.Header PackHeader = GFPackage.GetPackageHeader(stream);
                    switch (PackHeader.Magic)
                    {
                    case "PC": H3DFile = GFPkmnModel.OpenAsH3D(stream, PackHeader, null); break;
                    }
                }
                else if (System.IO.File.Exists(mbnPath))
                {
                    var ModelBinary = new SPICA.Formats.ModelBinary.MBn(new System.IO.BinaryReader(
                                                                            System.IO.File.OpenRead(mbnPath)), H3DFile);

                    H3DFile    = ModelBinary.ToH3D();
                    FormatType = FileFormatType.MBN;
                }
                else
                {
                    H3DFile = H3D.Open(stream.ToBytes());
                }
            }
        }
예제 #14
0
        public void Save(System.IO.Stream stream)
        {
            switch (FormatType)
            {
            case FileFormatType.BCH:
                H3D.Save(stream, H3DFile);
                break;

            default:
                throw new Exception($"File format cannot be saved yet! {FormatType}");
            }
        }
예제 #15
0
        public static void Save(H3D Scene, SceneState State)
        {
            if (Scene == null)
            {
                MessageBox.Show(
                    "Please load a file first!",
                    "No data",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);

                return;
            }

            using (SaveFileDialog SaveDlg = new SaveFileDialog())
            {
                SaveDlg.Filter =
                    "COLLADA 1.4.1|*.dae|" +
                    "Valve StudioMdl|*.smd|" +
                    "Binary Ctr H3D|*.bch|" +
                    "Material Script (Max)|*.ms|" +
                    "Material Dump|*.txt";

                //Offer to save using model name if possible
                if (State.ModelIndex > -1)
                {
                    SaveDlg.FileName = Scene.Models[State.ModelIndex].Name;
                }
                else
                {
                    SaveDlg.FileName = "Model";
                }

                if (SaveDlg.ShowDialog() == DialogResult.OK)
                {
                    int MdlIndex  = State.ModelIndex;
                    int AnimIndex = State.SklAnimIndex;

                    switch (SaveDlg.FilterIndex)
                    {
                    case 1: new DAE(Scene, MdlIndex, AnimIndex, Settings.Default.DebugCopyVtxAlpha).Save(SaveDlg.FileName); break;

                    case 2: new SMD(Scene, MdlIndex, AnimIndex).Save(SaveDlg.FileName); break;

                    case 3: H3D.Save(SaveDlg.FileName, Scene); break;

                    case 4: new MaterialScript(Scene, MdlIndex, AnimIndex).Save(SaveDlg.FileName); break;

                    case 5: new MaterialDump(Scene, MdlIndex, AnimIndex).Save(SaveDlg.FileName); break;
                    }
                }
            }
        }
예제 #16
0
 public GFPackedTexture(H3D Scene, int index = -1) : this()
 {
     if (index >= 0)
     {
         Textures.Add(new GFTexture(Scene.Textures[index]));
     }
     else
     {
         foreach (var t in Scene.Textures)
         {
             Textures.Add(new GFTexture(t));
         }
     }
 }
예제 #17
0
        public BLEND(H3D scene, int mdlIndex, int animIndex = -1)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");

            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Win32NT:
            case PlatformID.Win32S:
            case PlatformID.Win32Windows:
            case PlatformID.WinCE:
                blenderPath = Environment.ExpandEnvironmentVariables(@"%programfiles%\Blender Foundation\Blender\blender.exe");
                break;

            case PlatformID.Unix:
                throw new NotImplementedException();

            case PlatformID.MacOSX:
                throw new NotImplementedException();

            default:
                throw new PlatformNotSupportedException();
            }

            if (mdlIndex != -1)
            {
                var model = scene.Models[mdlIndex];

                CleanUpScene(model);

                if (model.Materials.Count > 0)
                {
                    BuildMaterials(model);
                }

                if ((model.Skeleton?.Count ?? 0) > 0)
                {
                    BuildArmature(model);
                }

                if (model.Meshes.Count > 0)
                {
                    BuildModel(model);
                }

                if (animIndex != -1)
                {
                    BuildAnimations(scene.SkeletalAnimations[animIndex], model);
                }
            }
        }
예제 #18
0
        public static int[] GetMotionIndices(H3D Scene, IEnumerable <string> MotionNames)
        {
            List <string> motionNames = new List <string>(MotionNames);
            List <int>    targets     = new List <int>();

            for (int i = 0; i < Scene.SkeletalAnimations.Count; i++)
            {
                if (motionNames.Contains(Scene.SkeletalAnimations[i].Name))
                {
                    targets.Add(i);
                }
            }
            return(targets.ToArray());
        }
예제 #19
0
        public static H3D OpenAsH3D(Stream Input, GFPackage.Header Header)
        {
            H3D Output;

            //Model
            byte[] Buffer = new byte[Header.Entries[0].Length];

            Input.Seek(Header.Entries[0].Address, SeekOrigin.Begin);

            Input.Read(Buffer, 0, Buffer.Length);

            using (MemoryStream MS = new MemoryStream(Buffer))
            {
                Output = H3D.Open(MS);
            }

            //Skeletal Animations
            if (Header.Entries.Length > 1)
            {
                Input.Seek(Header.Entries[1].Address, SeekOrigin.Begin);

                GF1MotionPack MotPack = new GF1MotionPack(Input);

                foreach (GF1Motion Mot in MotPack)
                {
                    H3DAnimation SklAnim = Mot.ToH3DSkeletalAnimation(Output.Models[0].Skeleton);

                    SklAnim.Name = $"Motion_{Mot.Index}";

                    Output.SkeletalAnimations.Add(SklAnim);
                }
            }

            //Material Animations
            if (Header.Entries.Length > 2)
            {
                Input.Seek(Header.Entries[2].Address, SeekOrigin.Begin);

                byte[] Data = new byte[Header.Entries[2].Length];

                Input.Read(Data, 0, Data.Length);

                H3D MatAnims = H3D.Open(Data);

                Output.Merge(MatAnims);
            }

            return(Output);
        }
예제 #20
0
        public static H3D IdentifyAndOpen(string FileName, H3DDict <H3DBone> Skeleton = null)
        {
            H3D Output = null;

            using (FileStream FS = new FileStream(FileName, FileMode.Open)){
                Output = IdentifyAndOpen(FS, Skeleton);
            }

            if (Output == null)
            {
                Output = FormatIdentifier.IdentifyAndOpen(FileName, Skeleton);
            }

            return(Output);
        }
예제 #21
0
        public static H3D OpenAsH3D(Stream input, GFPackage.Header header)
        {
            var output = default(H3D);

            //Model
            var buffer = new byte[header.Entries[1].Length];

            input.Seek(header.Entries[1].Address, SeekOrigin.Begin);

            input.Read(buffer, 0, buffer.Length);

            using (var ms = new MemoryStream(buffer))
                output = H3D.Open(ms);

            return(output);
        }
예제 #22
0
        public static H3D OpenAsH3D(Stream input, GFPackage.Header header, H3DDict <H3DBone> skeleton)
        {
            var output = new H3D();

            var reader = new BinaryReader(input);

            var index = 0;

            foreach (var entry in header.Entries)
            {
                input.Seek(entry.Address, SeekOrigin.Begin);

                if (index == 20)
                {
                    break;
                }

                if (index == 0)
                {
                    var motPack = new GF1MotionPack(reader);

                    foreach (var mot in motPack)
                    {
                        var anim = mot.ToH3DSkeletalAnimation(skeleton);

                        anim.Name = $"Motion_{index++}";

                        output.SkeletalAnimations.Add(anim);
                    }
                }
                else
                {
                    var data = reader.ReadBytes(entry.Length);

                    if (data.Length > 4 &&
                        data[0] == 'B' &&
                        data[1] == 'C' &&
                        data[2] == 'H' &&
                        data[3] == '\0')
                    {
                        output.Merge(H3D.Open(data));
                    }
                }
            }

            return(output);
        }
예제 #23
0
        public static H3D OpenAsH3D(Stream input, GFPackage.Header header)
        {
            var output = default(H3D);

            //Model
            var buffer = new byte[header.Entries[0].Length];

            input.Seek(header.Entries[0].Address, SeekOrigin.Begin);

            input.Read(buffer, 0, buffer.Length);

            using (var ms = new MemoryStream(buffer))
                output = H3D.Open(ms);

            //Skeletal Animations
            if (header.Entries.Length > 1)
            {
                input.Seek(header.Entries[1].Address, SeekOrigin.Begin);

                var motPack = new GF1MotionPack(input);

                foreach (var mot in motPack)
                {
                    var sklAnim = mot.ToH3DSkeletalAnimation(output.Models[0].Skeleton);

                    sklAnim.Name = $"Motion_{mot.Index}";

                    output.SkeletalAnimations.Add(sklAnim);
                }
            }

            //Material Animations
            if (header.Entries.Length > 2)
            {
                input.Seek(header.Entries[2].Address, SeekOrigin.Begin);

                var data = new byte[header.Entries[2].Length];

                input.Read(data, 0, data.Length);

                var matAnims = H3D.Open(data);

                output.Merge(matAnims);
            }

            return(output);
        }
예제 #24
0
        public static H3D OpenAsH3D(Stream Input, GFPackage.Header Header, H3DDict <H3DBone> Skeleton)
        {
            H3D Output = new H3D();

            BinaryReader Reader = new BinaryReader(Input);

            int Index = 0;

            foreach (GFPackage.Entry Entry in Header.Entries)
            {
                Input.Seek(Entry.Address, SeekOrigin.Begin);

                if (Index == 20)
                {
                    break;
                }

                if (Index == 0)
                {
                    GF1MotionPack MotPack = new GF1MotionPack(Reader);

                    foreach (GF1Motion Mot in MotPack)
                    {
                        H3DAnimation Anim = Mot.ToH3DSkeletalAnimation(Skeleton);

                        Anim.Name = $"Motion_{Index++}";

                        Output.SkeletalAnimations.Add(Anim);
                    }
                }
                else
                {
                    byte[] Data = Reader.ReadBytes(Entry.Length);

                    if (Data.Length > 4 &&
                        Data[0] == 'B' &&
                        Data[1] == 'C' &&
                        Data[2] == 'H' &&
                        Data[3] == '\0')
                    {
                        Output.Merge(H3D.Open(Data));
                    }
                }
            }

            return(Output);
        }
예제 #25
0
        public static void Save(H3D Scene, SceneState State)
        {
            if (Scene == null)
            {
                MessageBox.Show(
                    "Please load a file first!",
                    "No data",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);

                return;
            }

            using (SaveFileDialog SaveDlg = new SaveFileDialog())
            {
                SaveDlg.Filter =
                    "COLLADA 1.4.1|*.dae" +
                    "|Valve StudioMdl|*.smd" +
                    "|Binary Ctr H3D|*.bch" +
                    "|Game Freak Model|*.gfbmdl";

                SaveDlg.FileName = "Model";

                if (SaveDlg.ShowDialog() == DialogResult.OK)
                {
                    int MdlIndex  = State.ModelIndex;
                    int AnimIndex = State.SklAnimIndex;

                    switch (SaveDlg.FilterIndex)
                    {
                    case 1: new DAE(Scene, MdlIndex, AnimIndex).Save(SaveDlg.FileName); break;

                    case 2: new SMD(Scene, MdlIndex, AnimIndex).Save(SaveDlg.FileName); break;

                    case 3: H3D.Save(SaveDlg.FileName, Scene); break;

                    case 4:
                        using (BinaryWriter writer = new BinaryWriter(new FileStream(SaveDlg.FileName, FileMode.Create, FileAccess.Write)))
                        {
                            new GFModel(Scene.Models[State.ModelIndex], Scene.LUTs).Write(writer);
                            writer.Close();
                        }
                        break;
                    }
                }
            }
        }
예제 #26
0
파일: FileIO.cs 프로젝트: yorki00/SPICA
        public static H3D Merge(string[] FileNames, Renderer Renderer, H3D Scene = null)
        {
            if (Scene == null)
            {
                //Renderer.DeleteAll();

                Scene = new H3D();
            }

            int OpenFiles = 0;

            using (FrmLoading Form = new FrmLoading(FileNames.Length))
                foreach (string FileName in FileNames)
                {
                    Form.Proceed(FileName);

                    H3DDict <H3DBone> Skeleton = null;

                    if (Scene.Models.Count > 0)
                    {
                        Skeleton = Scene.Models[0].Skeleton;
                    }

                    H3D Data = FormatIdentifier.IdentifyAndOpen(FileName, Skeleton);

                    if (Data != null)
                    {
                        Scene.Merge(Data);

                        Renderer.Merge(Data);

                        OpenFiles++;
                    }
                }

            if (OpenFiles == 0)
            {
                MessageBox.Show(
                    "Unsupported file format!",
                    "Can't open file!",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);
            }

            return(Scene);
        }
예제 #27
0
        public static H3D OpenAsH3D(Stream Input, GFPackage.Header Header)
        {
            H3D Output;

            //Model
            byte[] Buffer = new byte[Header.Entries[1].Length];

            Input.Seek(Header.Entries[1].Address, SeekOrigin.Begin);

            Input.Read(Buffer, 0, Buffer.Length);

            using (MemoryStream MS = new MemoryStream(Buffer))
            {
                Output = H3D.Open(MS);
            }

            return(Output);
        }
예제 #28
0
파일: FileIO.cs 프로젝트: yorki00/SPICA
        public static void Export(H3D Scene, int Index = -1)
        {
            if (Index != -1)
            {
                //Export one
                using (SaveFileDialog SaveDlg = new SaveFileDialog())
                {
                    SaveDlg.Filter = "Portable Network Graphics|*.png|" +
                                     "GFTexture|*.*;*.pc;*.bin";
                    SaveDlg.FileName = Scene.Textures[Index].Name;

                    if (SaveDlg.ShowDialog() == DialogResult.OK)
                    {
                        switch (SaveDlg.FilterIndex)
                        {
                        case 1:                                 //PNG
                            TextureManager.GetTexture(Index).Save(SaveDlg.FileName);
                            break;

                        case 2:                                 //GFTexture
                            new GFPackedTexture(Scene, Index).Save(SaveDlg.FileName);
                            break;
                        }
                    }
                }
            }
            else
            {
                //Export all (or don't export if format can only export a single item)
                using (FolderBrowserDialog FolderDlg = new FolderBrowserDialog())
                {
                    if (FolderDlg.ShowDialog() == DialogResult.OK)
                    {
                        for (int i = 0; i < Scene.Textures.Count; i++)
                        {
                            string FileName = Path.Combine(FolderDlg.SelectedPath, $"{Scene.Textures[i].Name}.png");

                            TextureManager.GetTexture(i).Save(FileName);
                        }
                    }
                }
            }
        }
예제 #29
0
        public static H3D Merge(string[] FileNames, Renderer Renderer, H3D Scene = null)
        {
            int OpenFiles = 0;

            foreach (string FileName in FileNames)
            {
                H3DDict <H3DBone> Skeleton = null;

                if (Scene != null && Scene.Models.Count > 0)
                {
                    Skeleton = Scene.Models[0].Skeleton;
                }

                H3D Data = FormatIdentifier.IdentifyAndOpen(FileName, Skeleton);

                if (Data != null)
                {
                    if (Scene == null)
                    {
                        Scene = Data;
                    }
                    else
                    {
                        Scene.Merge(Data);
                    }

                    Renderer.Merge(Data);

                    OpenFiles++;
                }
            }

            if (OpenFiles == 0)
            {
                MessageBox.Show(
                    "Unsupported file format!",
                    "Can't open file!",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);
            }

            return(Scene);
        }
예제 #30
0
파일: FileIO.cs 프로젝트: Batonapiton/SPICA
 public static void ExportTextures(H3D Scene, string texturesDir, string texturesShinyDir)
 {
     TextureManager.Textures = Scene.Textures;
     for (int i = 0; i < Scene.Textures.Count; i++)
     {
         string textureName = Scene.Textures[i].Name;
         string fileName;
         if (textureName.Contains(".tga_1"))
         {
             textureName = textureName.Replace(".tga_1", ".tga");
             fileName    = Path.Combine(texturesShinyDir, $"{textureName}.png");
         }
         else
         {
             fileName = Path.Combine(texturesDir, $"{textureName}.png");
         }
         TextureManager.GetTexture(i).Save(fileName);
     }
 }