예제 #1
0
        private void UpdateFSOR(object sender, EventArgs e)
        {
            if (InternalChange)
            {
                return;
            }

            GameContent.Get.Changes.QueueResMod(new ResAction(() =>
            {
                UpdateParams();
                if (!IffMode)
                {
                    var lower = ActiveObject.OBJ.ChunkParent.Filename.ToLowerInvariant();
                    DGRP3DMesh.ParamsByIff[lower] = ActiveParams;
                }
                GameContent.Get.RCMeshes.ClearCache(ActiveDGRP);
                Debug3D.ForceUpdate();
            }, ActiveFSOR));
        }
예제 #2
0
        private void ImportButton_Click(object sender, EventArgs e)
        {
            var dialog = new OpenFileDialog
            {
                Title = "Select an OBJ file."
            };

            FolderOpen(dialog);
            var dgrp = ActiveDGRP;

            try
            {
                Stream str;
                if ((str = dialog.OpenFile()) != null)
                {
                    var obj = new OBJ(str);
                    //identify and copy replacement textures
                    //only happens when this iff doesnt have a 3d model

                    foreach (var mtl in obj.FacesByObjgroup.Keys)
                    {
                        var split = mtl.Split('_');
                        if (split.Length < 3 || split[1] == "SPR" || split[0] == "DEPTH")
                        {
                            continue;
                        }

                        var baseDir  = Path.GetDirectoryName(dialog.FileName);
                        var copyname = "TEX_" + split[2] + ".png";
                        if (IffMode)
                        {
                            var texID = ushort.Parse(split[2]);
                            var tex   = ActiveObject.Resource.Get <MTEX>(texID);
                            if (tex == null)
                            {
                                tex = new MTEX
                                {
                                    ChunkLabel     = "OBJ Import Texture",
                                    ChunkID        = texID,
                                    ChunkProcessed = true,
                                    ChunkType      = "MTEX",
                                    AddedByPatch   = true
                                };
                                (ActiveObject.Resource.Sprites ?? ActiveObject.Resource.MainIff).AddChunk(tex);
                            }

                            GameContent.Get.Changes.BlockingResMod(new ResAction(() =>
                            {
                                tex.SetData(File.ReadAllBytes(Path.Combine(baseDir, copyname)));
                            }, tex));
                        }
                        else
                        {
                            var texname = ActiveDGRP.ChunkParent.Filename.Replace('.', '_').Replace("spf", "iff") + "_";
                            texname += copyname;

                            File.Copy(Path.Combine(baseDir, copyname), Path.Combine(FSOEnvironment.ContentDir, "MeshReplace/", texname), true);
                        }
                    }

                    GameThread.NextUpdate(x =>
                    {
                        var mesh = new DGRP3DMesh(ActiveDGRP, obj, Client.GameFacade.GraphicsDevice);
                        if (IffMode)
                        {
                            var fsom = ActiveObject.Resource.Get <FSOM>(ActiveDGRP.ChunkID);
                            if (fsom == null)
                            {
                                fsom = new FSOM
                                {
                                    ChunkLabel     = "OBJ Import Mesh",
                                    ChunkID        = ActiveDGRP.ChunkID,
                                    ChunkProcessed = true,
                                    ChunkType      = "FSOM",
                                    AddedByPatch   = true
                                };
                                (ActiveObject.Resource.Sprites ?? ActiveObject.Resource.MainIff).AddChunk(fsom);
                            }
                            GameContent.Get.Changes.QueueResMod(new ResAction(() =>
                            {
                                fsom.SetMesh(mesh);
                                GameContent.Get.RCMeshes.ClearCache(ActiveDGRP);
                                Debug3D.ForceUpdate();
                            }, fsom));
                        }
                        else
                        {
                            GameContent.Get.RCMeshes.Replace(ActiveDGRP, mesh);
                            Debug3D.ForceUpdate();
                        }
                    });

                    str.Close();
                }
            } catch (Exception)
            {
            }
        }