コード例 #1
0
        private void exportBttn_Click(object sender, EventArgs e)
        {
            var script = new List <IScriptItem>();

            script.Add(new LoadModel()
            {
                File = inputFileBox.Selected
            });
            model = ModelReader.Open(inputFileBox.Selected);

            var exportCmd = new Export();

            var type = formatBox.SelectedItem as FileTypeInfo;

            if (type == null)
            {
                MessageBox.Show("Unknown format '{format}'");
                return;
            }
            var outName = System.IO.Path.ChangeExtension(inputFileBox.Selected, type.Extension);

            exportCmd.File = outName;
            script.Add(exportCmd);
            Script.ExecuteItems(script, System.IO.Directory.GetCurrentDirectory());

            MessageBox.Show($"Successfully exported model {inputFileBox.Selected.Split('\\').Last()} (placed in the input model folder)");
        }
コード例 #2
0
        public override void Execute(ScriptState state)
        {
            string resolvedPath = state.ResolvePath(File);

            state.Log.Status($"Loading model from {resolvedPath}");
            state.Data = ModelReader.Open(resolvedPath);
        }
コード例 #3
0
        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;
        }