Tanoda
ModelEditorLogicManager.cs
Go to the documentation of this file.
1using System.Collections;
2using System.Collections.Generic;
3using System.IO;
4using System.Text;
5using GILES;
6using Parabox.STL;
7using UnityEngine;
9
10public class ModelEditorLogicManager : MonoBehaviour
11{
12 #region Static Instance
14
15 private void Awake()
16 {
17 if (!instance)
18 instance = this;
19 else
20 Destroy(this);
21 }
22 #endregion
23
24 public GameObject currentModel;
25
26 private Dictionary<int, Vector3> editedVertexes = new Dictionary<int, Vector3>();
27
28 public void SetVertex(List<int> vertexIndex, Vector3 position)
29 {
30 if (editedVertexes == null)
31 editedVertexes = new Dictionary<int, Vector3>();
32
33 foreach (var i in vertexIndex)
34 {
35 if (editedVertexes.ContainsKey(i))
36 {
37 editedVertexes[i] = position;
38 }
39 else
40 {
41 editedVertexes.Add(i, position);
42 }
43 }
44 }
45
46 public void Save()
47 {
48 #region old logic
49 //var allVE = FindObjectsOfType<VertexEditor>();
50 //foreach (var ve in allVE)
51 //{
52 // ve.gameObject.SetActive(false);
53 //}
54 //
55 //var file = FBXExporter.ExportGameObjToFBXString(currentModel);
58 //var data = Encoding.UTF8.GetBytes(file);
59 //System.IO.File.WriteAllBytes("teszt.1.fbx", data);
61 //FileDragAndDrop.instance.OnFileData(data, currentModel.name + "_edited.fbx", "");
62 //
63 //foreach (var ve in allVE)
64 //{
65 // ve.gameObject.SetActive(true);
66 //}
67 #endregion
68
69 var data = "";
70
71 if (File.Exists(currentModel.name + ".mod"))
72 File.Delete(currentModel.name + ".mod");
73
74 foreach (var v in editedVertexes)
75 {
76 File.AppendAllText(currentModel.name + ".mod", $"{v.Key};{v.Value.x:F4};{v.Value.y:F4};{v.Value.z:F4};\n");
77 data += $"{v.Key};{v.Value.x:F4};{v.Value.y:F4};{v.Value.z:F4};\n";
78 }
79
80 editedVertexes = new Dictionary<int, Vector3>();
82 FileDragAndDrop.instance.OnFileData(Encoding.UTF8.GetBytes(data), currentModel.name + ".mod", "", newUpload: true);
83 Destroy(currentModel);
84 pb_SceneCamera.Focus(Vector3.zero, 5f);
85 }
86
87 public void Cancel()
88 {
89 editedVertexes = new Dictionary<int, Vector3>();
91 Destroy(currentModel);
92 }
93}
void SwitchToMain()
static CanvasManager instance
static FileDragAndDrop instance
void OnFileData(byte[] fileData, string fileName, string modified, NetworkManager.WSFile wsFile=default, bool global=false, bool newUpload=false)
static void Focus(Vector3 target)
static ModelEditorLogicManager instance
void SetVertex(List< int > vertexIndex, Vector3 position)