| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | using System.IO; |
| | using System.Text; |
| | using System.Xml; |
| | using UnityEditor; |
| | using UnityEngine; |
| |
|
| | namespace Mujoco |
| | { |
| |
|
| | |
| | public class MjExporterEditorWindow : EditorWindow |
| | { |
| | [MenuItem("Assets/Export MuJoCo Scene")] |
| | public static void Apply() |
| | { |
| | if (Application.isPlaying || MjScene.InstanceExists) |
| | { |
| | Debug.LogWarning("MJCF exporting only available outside Play mode, and with no MjScene in the hierarchy."); |
| | return; |
| | } |
| |
|
| | string path = EditorUtility.SaveFilePanel("Save MJCF model", "", "model", "xml"); |
| | if (string.IsNullOrEmpty(path)) return; |
| |
|
| | |
| | var mjcf = MjScene.Instance.CreateScene(skipCompile: true); |
| | try |
| | { |
| | using (var stream = File.Open(path, FileMode.Create)) |
| | { |
| | using (var writer = new XmlTextWriter(stream, new UTF8Encoding(false))) |
| | { |
| | writer.Formatting = Formatting.Indented; |
| | mjcf.WriteContentTo(writer); |
| | Debug.Log($"MJCF saved to {path}"); |
| | } |
| | } |
| | } |
| | catch (IOException ex) |
| | { |
| | Debug.LogWarning("Failed to save Xml to a file: " + ex.ToString()); |
| | } |
| |
|
| | |
| | DestroyImmediate(MjScene.Instance.gameObject); |
| | } |
| | } |
| | } |
| |
|