void scanAMF(string _line) { { _line = _line.Trim(); if (_line.StartsWith("|||ftlVAME")) { var chunks = _line.Split(' '); #region STL if (chunks[1] == "STL") { if (chunks[2] == "BEGIN") { vertices.Clear(); stlInterpreter = new StlInterpreter(); type = Type.STL; } else { InspectorL.lastLoaded = InspectorL.LastLoaded.STL; GameObject.Find("MESH").GetComponent<MakeMesh>().MergeMesh(); InspectorL.stlTimeSlider = MM.GetMesh().vertices.Length / 3 - 1; InspectorL.stlTimeSliderMin = 0; InspectorL.stlVisSlider = 1; stlCodeLoaded = true; InspectorManager.VoxelManager = true; type = Type.AMF; } } #endregion #region GCD if (chunks[1] == "GCD") { if (chunks[2] == "BEGIN") { gcdInterpreter = new GcdInterpreter(); vertices.Clear(); type = Type.GCD; } else { Draw(Type.GCD); InspectorL.gcdTimeSlider = gcdLines.Count - 1; InspectorL.gcdTimeSliderMin = 0; InspectorL.gcdVisSlider = 1; InspectorL.lastLoaded = InspectorL.LastLoaded.GCD; gcdCodeLoaded = true; type = Type.AMF; } } #endregion #region DMC if (chunks[1] == "DMC") { if (chunks[2] == "BEGIN") { dmcInterpreter = new DmcInterpreter(); vertices.Clear(); type = Type.DMC; } else { Draw(Type.DMC); InspectorL.dmcTimeSlider = dmcLines.Count - 1; InspectorL.dmcTimeSliderMin = 0; InspectorL.dmcVisSlider = 1; InspectorL.lastLoaded = InspectorL.LastLoaded.DMC; dmcCodeLoaded = true; type = Type.AMF; } } #endregion #region JOB if (chunks[1] == "JOB") { if (chunks[2] == "BEGIN") { jobInterpreter = new JobInterpreter(); vertices.Clear(); type = Type.JOB; } else { Draw(Type.JOB); InspectorL.jobTimeSlider = jobLines.Count - 1; InspectorL.jobTimeSliderMin = 0; InspectorL.jobVisSlider = 1; InspectorL.lastLoaded = InspectorL.LastLoaded.JOB; jobCodeLoaded = true; type = Type.AMF; } } #endregion #region voxels if (chunks[1] == "Voxels") { if (chunks[2] == "BEGIN") { vertices.Clear(); float.TryParse(chunks[3], out InspectorR.voxelVis); float.TryParse(chunks[4], out InspectorR.resolution); } else { //Camera.main.GetComponent<InspectorR>().OnVoxelize(); type = Type.AMF; } } #endregion #region Setup if (chunks[1] == "AMF") { if (chunks[2] == "BEGIN") { Camera.main.GetComponent<InspectorT>().Restart(); //var savedType = ""; //var sts //float.TryParse(chunks[3], out InspectorR.voxelVis); //float.TryParse(chunks[4], out InspectorR.resolution); } if (chunks[2] == "END") { //var savedType = ""; //var sts //float.TryParse(chunks[3], out InspectorR.voxelVis); //float.TryParse(chunks[4], out InspectorR.resolution); } } #endregion } } }
void Start () { stlInterpreter = new StlInterpreter(); mainMenu = GameObject.Find("Main Menu"); folderWindow = GameObject.Find("Folder Window"); sceneWindow = GameObject.Find("Scene Window"); folderWindow.GetComponent<PanelFades>().FadeOut(); sceneWindow.GetComponent<PanelFades>().FadeOut(); _cursor = Instantiate(cursor) as GameObject; _cursor.transform.SetParent(mainMenu.transform); var pos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y + mouseYoffset, -1f)); var rot = new Quaternion(0, 0, 0, 0); _cursor.transform.localPosition = pos; _cursor.transform.localRotation = rot; MM = GameObject.Find("MESH").GetComponent<MakeMesh>(); MM.material = Mat; MM.Begin(); for (int i = 0; i < landscapes.Count; i++) { var l = Instantiate(landscapes[i]); l.name = landscapes[i].name; l.active = false; landscapes[i] = l; } for (int i = 0; i < props.Count; i++) { var p = Instantiate(props[i]); p.name = props[i].name; p.active = false; props[i] = p; } var options = new List<Dropdown.OptionData>(skyboxes.Count); foreach (var skybox in skyboxes) { var newOption = new Dropdown.OptionData(skybox.name); options.Add(newOption); } skyboxDD.options = options; options = new List<Dropdown.OptionData>(MM.materials.Count); foreach (var mat in MM.materials) { var newOption = new Dropdown.OptionData(mat.name); options.Add(newOption); } materialDD.options = options; options = new List<Dropdown.OptionData>(landscapes.Count); var none = new Dropdown.OptionData("None"); options.Add(none); foreach (var landscape in landscapes) { var newOption = new Dropdown.OptionData(landscape.name); options.Add(newOption); } landscapeDD.options = options; options = new List<Dropdown.OptionData>(props.Count); options.Add(none); foreach (var prop in props) { var newOption = new Dropdown.OptionData(prop.name); options.Add(newOption); } propDD.options = options; currentProp = null; materialDD.onValueChanged.AddListener(delegate { MaterialDropdownValueChangedHandler(materialDD); }); skyboxDD.onValueChanged.AddListener(delegate { SkyboxDropdownValueChangedHandler(skyboxDD); }); landscapeDD.onValueChanged.AddListener(delegate { LandscapeDropdownValueChangedHandler(landscapeDD); }); propDD.onValueChanged.AddListener(delegate { PropDropdownValueChangedHandler(propDD); }); }
public void loadFile(bool _isBone) { System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog(); openFileDialog.InitialDirectory = UnityEngine.Application.dataPath + "/Models"; var sel = "STL Files (*.STL)|*.STL|Obj Files (*.OBJ, *.obj)|*.obj"; openFileDialog.Filter = sel; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = false; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { if (_isBone) { triangleListBone.Clear(); tempTriangleListBone.Clear(); stlInterpreter = new StlInterpreter(_isBone); } else { triangleListSocket.Clear(); tempTriangleListSocket.Clear(); stlInterpreter = new StlInterpreter(_isBone); } var fileName = openFileDialog.FileName; if (fileName.ToLower().EndsWith(".obj")) { var objI = new ObjInterpreter(fileName, _isBone); return; } stlInterpreter.ClearAll(); linesOfStl.Clear(); if (CheckForStlBinary(fileName)) { parseStlBinary = new Parse_StlBinary(fileName, null, _isBone); } else { var reader = new StreamReader(fileName); while (!reader.EndOfStream) { string line = reader.ReadToEnd(); line = line.Replace("facet", "|facet"); line = line.Replace("outer loop", "|outer loop"); line = line.Replace("endloop", "|endloop"); line = line.Replace("vertex", "|vertex"); line = line.Replace("endfacet", "|endfacet"); var _lines = line.Split('|'); foreach (var _line in _lines) { linesOfStl.Add(_line); } } foreach (var l in linesOfStl) { scanSTL(l); } if (_isBone) { foreach (var tri in triangleListBone) { var c = (camScript.MinBone + camScript.MaxBone) / 2.0f; tri.p1 -= c; tri.p2 -= c; tri.p3 -= c; } } else { foreach (var tri in triangleListSocket) { var c = (camScript.MinSocket + camScript.MaxSocket) / 2.0f; tri.p1 -= c; tri.p2 -= c; tri.p3 -= c; } } Generate(_isBone); } } catch { } } }