private void UpdateRootPointBox() { string old_selected_name; if (rootPoints.SelectedIndex > 0) { old_selected_name = root_point_items[rootPoints.SelectedIndex].Name; } else { // Use the root point, if it exists. Otherwise, this won't match and // we'll use the default new_index of 0. old_selected_name = "root_point"; } int new_index = 0; root_point_items.Clear(); root_point_items.Add(new RootPointItem("None", 0)); if (scriptFile.Selected != null) { // If we're using a script, we unfortunately have to fully load the file to evaluate the script string model_file = baseModelFileBrowser.Enabled ? baseModelFileBrowser.Selected : null; FullModelData data = model_file != null?ModelReader.Open(model_file) : new FullModelData(); // TODO display the errors in a less intrusive way bool success = Modelscript.Script.ExecuteFileWithMsgBox(ref data, scriptFile.Selected); if (!success) { return; } foreach (Object3D obj in data.SectionsOfType <Object3D>()) { root_point_items.Add(new RootPointItem(obj.Name, obj.SectionId)); if (old_selected_name == obj.Name) { new_index = root_point_items.Count - 1; } } } else if (baseModelFileBrowser.Enabled && baseModelFileBrowser.Selected != null) { // If there is no script file, just skim the model and collect the object IDs like that. // This isn't a major improvement, but it does increase performance. StaticStorage.hashindex.Load(); ModelReader.VisitModel(baseModelFileBrowser.Selected, (reader, header) => { if (header.type == Tags.object3D_tag) { // First field of Object3D ulong hashname = reader.ReadUInt64(); string name = StaticStorage.hashindex.GetString(hashname); RootPointItem item = new RootPointItem(name, header.id); root_point_items.Add(item); Log.Default.Debug("Scanning for rootpoint: {0}", name); if (old_selected_name == name) { new_index = root_point_items.Count - 1; } } }); } rootPoints.Items.Clear(); rootPoints.Items.AddRange(root_point_items.ToArray()); rootPoints.SelectedIndex = new_index; }