public void RemoveFigure(Figure3D Fig) { int Ind = Figs.IndexOf(Fig); if (Ind >= 0) { if (Selected == Fig) { Selected = null; } int Id = Fig.ID; Figs.RemoveAt(Ind); Figs.ForEach(delegate(Figure3D F) { if (F.ParrentID == Id) { F.ParrentID = -1; F.ApplyTransform(this); F.BuildVBO(false); } }); if (Parrent != null) { Parrent.ChangesUnsaved = true; } } else { throw new Exception("The scene does not contains the figure you want to remove from it."); } }
public void ApplyTransform(Scene3D s) { TransformedFaces.Clear(); MyAABB = new AABB(); Matrix TrfM = TransformToMatrix(); Figure3D ParrentF = s.Figs.Find(f => f.ID == this.ParrentID); Matrix ParrentM = ParrentF != null?ParrentF.GetTrasnformRecursive(s, 0) : null; foreach (Plane3D F in Faces) { Plane3D newF = new Plane3D(F); for (int i = 0; i < 3; ++i) { if (ParrentF != null) { newF.Vertex[i] = newF.Vertex[i].MultMatrix(ParrentM); } newF.Vertex[i] = newF.Vertex[i].MultMatrix(TrfM); MyAABB.Extend(newF.Vertex[i]); } newF.ID = ID; newF.CalcNormal(); TransformedFaces.Add(newF); } }
public void BeginFigure() { if (CurrentFigure != null) { throw new Exception("Call EndFigure first!"); } CurrentFigure = new Figure3D(this); }
public void EndFigure() { if (CurrentFigure == null) { throw new Exception("Call BeginFigure first!"); } Figs.Add(CurrentFigure); CurrentFigure = null; }
public void SelectFigure(Figure3D Fig) { if (Selected != null) { Selected.BuildVBO(false); } Selected = Figs.Contains(Fig) ? Fig : null; if (Selected != null) { Selected.BuildVBO(true); } }
public Matrix GetTrasnformRecursive(Scene3D s, int Call = 0) { if (Call > 10) { return(new Matrix(Matrix.Identity(4))); } Figure3D ParrentF = s.Figs.Find(f => f.ID == this.ParrentID); if (ParrentF == null) { return(TransformToMatrix()); } else { return(TransformToMatrix() * ParrentF.GetTrasnformRecursive(s, Call + 1)); } }
public void Open(string fName = "") { try { if (Asm != null) { Asm.Dispose(); Asm = null; } Selected = null; RaysVisible = false; AllRays.Clear(); InitialRays.Clear(); Figs.Clear(); if (fName == "") { fName = FileName; } else { FileName = fName; } DateTime Begin = DateTime.Now; Log("[i] Начинается загрузка файла \"" + fName + "\"."); Assembly aS = CSScript.Load(fName, null, true); Asm = new AsmHelper(aS); Log("[i] Загрузка файла завершена \"" + fName + "\"."); Log("[i] Выполнение скрипта вызовом Script.Load(this)."); Asm.Invoke("Script.Load", this); LoadedFromScript = true; Log("[i] Вызов метода Script.Load(this) завершен."); TransformFiguresAndMergeFaces(); Log("[i] Загрузка выполнена за " + (DateTime.Now - Begin).TotalSeconds + " сек."); } catch (csscript.CompilerException ce) { CompilerErrorCollection errors = (CompilerErrorCollection)ce.Data["Errors"]; foreach (CompilerError err in errors) { Log(@"/!\ Loader ERROR (C#) " + string.Format("{0}({1},{2}): {3} {4}: {5}", err.FileName, err.Line, err.Column, err.IsWarning ? "warning" : "error", err.ErrorNumber, err.ErrorText)); } } catch (ArgumentException ce) { Log(@"/!\ Loader ERROR (ArgumentExpection) " + ce.Message); } catch (ApplicationException ce) { Log(@"/!\ Loader ERROR (ApplicationExpection) " + ce.Message); } catch (Exception ce) { Log(@"/!\ Loader ERROR (Expection) " + ce.Message); } }