Пример #1
0
        public VPModel LoadTerrainInstance(string path, string resDir, string dir,
                                           string group = null, bool loadMats = true)
        {
            // Format path strings, return if the given files/directories don't exist
            path   = FormatCacheDir(path);
            resDir = FormatCacheDir(resDir);
            dir    = FormatCacheDir(dir);

            if (!File.Exists(path) || !Directory.Exists(resDir) || !Directory.Exists(dir))
            {
                return(null);
            }

            // Load Terrain Instance Info
            var instInfo = new GensTerrainInstanceInfo();

            instInfo.Load(path);

            return(Data.GetModel(instInfo.ModelFileName, resDir, true,
                                 loadMats, group, false, instInfo));
        }
Пример #2
0
        public static GensTerrainList LoadTerrainList(string path,
                                                      string groupsDir, string resDir, bool nonEditable = true)
        {
            // Terrain List
            GUI.ChangeLoadStatus("Terrain List");

            string dir         = Path.GetDirectoryName(path);
            var    terrainList = new GensTerrainList();

            terrainList.Load(path);

            // Terrain Groups
            int groupCount = terrainList.GroupEntries.Length;

            GUI.ShowProgress();

            for (int i = 0; i < groupCount; ++i)
            {
                // Update UI
                GUI.ChangeProgress((int)((i / (float)groupCount) * 100));
                GUI.ChangeLoadStatus($"Terrain Group {i + 1}/{groupCount}");

                // Get the path to the terrain group
                var    groupEntry = terrainList.GroupEntries[i];
                string groupDir   = Path.Combine(groupsDir,
                                                 groupEntry.FileName);

                string groupPath = Path.Combine(dir,
                                                $"{groupEntry.FileName}{GensTerrainGroup.Extension}");

                // Ensure the group exists
                if (!File.Exists(groupPath))
                {
                    LuaTerminal.LogWarning(string.Format(
                                               "WARNING: Terrain group \"{0}\" was skipped {1}",
                                               groupEntry.FileName, "because it was not found!"));

                    continue;
                }

                // Load the group
                var group = new GensTerrainGroup();
                group.Load(groupPath);

                Dictionary <string, VPModel> terrainGroup = null;
                Program.MainUIInvoke(() =>
                {
                    terrainGroup = GetTerrainGroup(groupEntry.FileName, true);
                });

                // Terrain Instances
                for (int i2 = 0; i2 < group.InstanceInfos.Length; ++i2)
                {
                    var infoEntry = group.InstanceInfos[i2];
                    for (int i3 = 0; i3 < infoEntry.FileNames.Length; ++i3)
                    {
                        string infoPath = Path.Combine(groupDir,
                                                       string.Format("{0}{1}",
                                                                     infoEntry.FileNames[i3],
                                                                     GensTerrainInstanceInfo.Extension));

                        if (!File.Exists(infoPath))
                        {
                            LuaTerminal.LogWarning(string.Format(
                                                       "WARNING: Terrain instance {0} was skipped {1}",
                                                       infoEntry.FileNames[i3], "because it was not found!"));

                            continue;
                        }

                        var info = new GensTerrainInstanceInfo();
                        info.Load(infoPath);

                        var instance = new VPObjectInstance(info.TransformMatrix,
                                                            info.FileName);

                        // Terrain Model
                        if (terrainGroup.ContainsKey(info.ModelFileName))
                        {
                            bool success = false;
                            Program.MainUIInvoke(new Action(() =>
                            {
                                success = AddInstance(info.ModelFileName,
                                                      instance, terrainGroup);
                            }));
                            continue;
                        }

                        string modelPath = Path.Combine(groupDir,
                                                        string.Format("{0}{1}",
                                                                      info.ModelFileName,
                                                                      GensModel.TerrainExtension));

                        if (!File.Exists(modelPath))
                        {
                            LuaTerminal.LogWarning(string.Format(
                                                       "WARNING: Terrain model \"{0}\" was skipped {1}",
                                                       info.ModelFileName, "because it was not found!"));

                            continue;
                        }

                        var mdl = new GensModel();
                        mdl.Load(modelPath);
                        mdl.Name = info.ModelFileName;

                        // Materials
                        var matExt = Types.MaterialExtension;
                        foreach (var mesh in mdl.Meshes)
                        {
                            LoadMaterial(Path.Combine(resDir,
                                                      $"{mesh.MaterialName}{matExt}"),
                                         mesh.MaterialName, nonEditable);
                        }

                        Program.MainUIInvoke(() =>
                        {
                            AddModelInstance(mdl, instance, terrainGroup);
                        });
                    }
                }
            }

            GUI.HideProgress();
            return(terrainList);
        }