/// <summary> /// compiles the <see cref="DrawAction"/> draw and returns a meshContainer. /// The <b>progs</b> of this is a list of <see cref="Mesh"/>. /// This method is called from <see cref="Entity.Compile(OpenGlDevice)"/>. /// </summary> /// <param name="Device"><see cref="OpenGlDevice"/> in which will be drawn.</param> /// <param name="Draw">the <see cref="DrawAction"/>, which is used to produce a <see cref="MeshContainer"/></param> /// <returns></returns> public static MeshContainer Compile(OpenGlDevice Device, DrawAction Draw) { Device.PushMatrix(); MeshListCurrent = new MeshContainer(); bool Compiling = Entity.Compiling; if (Compiling) { MeshCreator.Push(); } bool SaveCompiling = Entity.Compiling; Entity.Compiling = true; RenderKind SaveRenderKind = Device.RenderKind; Device.RenderKind = RenderKind.Render; MeshIndices.Clear(); Draw(Device); Renew(); Entity.Compiling = SaveCompiling; Device.RenderKind = SaveRenderKind; Device.PopMatrix(); MeshContainer Result = MeshListCurrent; if (Compiling) { MeshCreator.Pop(); } return(Result); }
Texture GetPatternTexture(OpenGlDevice Device) { Texture Save = Device.texture; if (Pattern == null) { return(null); } Rectangled R = new Rectangled(Pattern.PatternX, Pattern.PatternY, Pattern.PatternWidth, Pattern.PatternHeight); FBO FrameBuffer = new FBO(); FrameBuffer.BackGround = System.Drawing.Color.Transparent; Device.PushMatrix(); xyz RU = new xyz(R.Width, R.Height, 0); xyz RD = new xyz(R.X, R.Y, 0); Point _RU = Device.ToScr(RU); Point _RD = Device.ToScr(RD); FrameBuffer.Init((int)(_RU.X - _RD.X), (int)(_RD.Y - _RU.Y)); FrameBuffer.EnableWriting(); Pattern.Paint(Device); Device.PopMatrix(); FrameBuffer.DisableWriting(); Texture result = FrameBuffer.Texture; Device.texture = Save; result.WorldWidth = R.Width; result.WorldHeight = R.Height; result.Translation = new xy(R.X, R.Y); FrameBuffer.Dispose(true); return(result); }
/// <summary> /// paints the upper plane. You can override this metod e.g to gives the uppPlane a materal. See also <see cref="DrawUpPlane(OpenGlDevice)"/> /// </summary> /// <param name="Device">the device in wich will drawn.</param> protected virtual void DrawDownPlane(OpenGlDevice Device) { Device.PushMatrix(); Device.MulMatrix(DownMatrix); Device.drawPolyPolyLine(DownLoxy); Device.PopMatrix(); if (Device.RenderKind == RenderKind.SnapBuffer) { SnappItem SI = Selector.StoredSnapItems[Selector.StoredSnapItems.Count - 1]; { SI.OfObject = this; } } }
/// <summary> /// overrides the <see cref="CustomEntity.OnDraw(OpenGlDevice)"/>method. /// </summary> /// <param name="Device"></param> protected override void OnDraw(OpenGlDevice Device) { Device.PushMatrix(); Device.MulMatrix(_Transformation); if (Device.RenderKind != RenderKind.SnapBuffer) { Material SaveE = Device.Material; Device.Material = ShaftMaterial; Arc K = new Arc(new xy(0, 0), Radius); K.ClockWise = false; Device.drawCurve(K); Device.drawCylinder(Radius, Size - TopHeight); Device.PushMatrix(); Device.MulMatrix(Matrix.Translation(0, 0, Size - TopHeight)); Device.Material = TopMaterial; Device.drawConePointed(TopRadius, TopHeight); K = new Arc(new xy(0, 0), TopRadius); K.ClockWise = false; Device.drawCurve(K); Device.PopMatrix(); Device.Material = SaveE; } else { Device.PushTag(0); Device.drawLine(new xyz(0, 0, 0), new xyz(0, 0, Size)); Device.PopTag(); Device.PushTag(1); Device.drawPoint(new xyz(0, 0, 0), 0.3); Device.PopTag(); Device.PushTag(2); Device.drawPoint(new xyz(0, 0, Size), 0.3); Device.PopTag(); } Device.PopMatrix(); base.OnDraw(Device); }
MeshContainer DoCompile(OpenGlDevice Device) { Device.PushMatrix(); Device.ModelMatrix = Matrix.identity; if (Mesh != null) { Mesh.Dispose(); } MeshContainer M = MeshCreator.Compile(Device, CompileDraw); Device.PopMatrix(); return(M); }
void CompileMeshDraw(OpenGlDevice Device) { if (Device.RenderKind == RenderKind.SnapBuffer) { Device.PushMatrix(); Device.MulMatrix(Transformation); } OnDraw(Device); //if (Draw != null) Draw(this, Device); for (int i = 0; i < Children.Count; i++) { Children[i].Paint(Device); } if (Device.RenderKind == RenderKind.SnapBuffer) { Device.PopMatrix(); } }
/// <summary> /// paints the upper plane. You can override this metod e.g to gives the uppPlane a materal. /// <br/> /// f.e:<br/> /// class MyPolyExtruder:PolyCurveExtruder<br/> ///{<br/> ///protected override void DrawUpPlane(OpenGlDevice Device)<br/> ///{<br/> ///Material Save = Device.Material<br/> ///Device.Material = Materials.Gold;<br/> /// base.DrawUpPlane(Device);<br/> ///Device.Material = Save;<br/> ///} ///} /// </summary> /// <param name="Device">the device in wich will drawn.</param> protected virtual void DrawUpPlane(OpenGlDevice Device) { Device.PushMatrix(); Device.MulMatrix(UpMatrix); Device.drawPolyPolyLine(UpLoxy); if (Device.RenderKind == RenderKind.SnapBuffer) { if (Selector.StoredSnapItems.Count > 0) { SnappItem SI = Selector.StoredSnapItems[Selector.StoredSnapItems.Count - 1]; if (SI != null) { SI.OfObject = this; } } } Device.PopMatrix(); }
/// <summary> /// overriders the <see cref="CustomEntity.OnDraw(OpenGlDevice)"/> method. /// </summary> /// <param name="Device"></param> protected override void OnDraw(OpenGlDevice Device) { if (Device.RenderKind != RenderKind.Render) { return; } Device.PushMatrix(); Device.ModelMatrix = Matrix.identity; _Base = new Base(true); if (Device.SnappItems.Count > 0) { if ((Device.SnappItems[0].Crossed) && (CrossStyle != Cross.None)) { Base Base = new Base(true); Base.BaseO = Device.SnappItems[0].Point; Color C = Device.Ambient; Device.Ambient = ColoroFtheCrossSymbol; double r = Device.PixelToWorld(Device.SnappItems[0].Point, CrossSize); if (CrossStyle == Cross.Sphere) { Device.drawSphere(Device.SnappItems[0].Point, r / 2f); } if (CrossStyle == Cross.Cube) { Base B = Device.SnappItems[0].GetBase(); Matrix M = B.ToMatrix(); Device.PushMatrix(); Device.ModelMatrix = M; Device.drawBox(new xyz(-r / 2, -r / 2, -r / 2), new xyz(r, r, r)); Device.PopMatrix(); } if ((_Base.BaseO.X == 2) && (_Base.BaseO.y == 2) && (_Base.BaseO.Z == 2)) { } Device.Ambient = C; return; } else { _Base.BaseO = Device.SnappItems[0].Point; if (_Base.BaseO.dist(Device.Currentxyz) > 0.1) { } if (!AxisFix) { { _Base = Device.SnappItems[0].GetBase(); } } } } else { _Base = Base.UnitBase; _Base.BaseO = Device.Currentxyz; } float PenW = Device.PenWidth; Device.PenWidth = PenWidth; Color SaveEmission = Device.Emission; bool Save = Device.LightEnabled; Device.LightEnabled = true; Device.Emission = xAxisColor; Device.drawLine(Base.BaseO - Base.BaseX * Device.PixelToWorld(Base.BaseO, Size), Base.BaseO + Base.BaseX * Device.PixelToWorld(Base.BaseO, Size)); double d = Device.PixelToWorld(Base.BaseO, Size); Device.Emission = yAxisColor; Device.drawLine(Base.BaseO - Base.BaseY * Device.PixelToWorld(Base.BaseO, Size), Base.BaseO + Base.BaseY * Device.PixelToWorld(Base.BaseO, Size)); Device.Emission = zAxisColor; Device.drawLine(Base.BaseO - Base.BaseZ * Device.PixelToWorld(Base.BaseO, Size), Base.BaseO + Base.BaseZ * Device.PixelToWorld(Base.BaseO, Size)); Device.LightEnabled = Save; Device.Emission = SaveEmission; Device.PenWidth = PenW; Device.PopMatrix(); BaseZ = Base.BaseZ; base.OnDraw(Device); }
/// <summary> /// overrides the <see cref="CustomEntity.OnDraw(OpenGlDevice)"/> method. /// </summary> /// <param name="Device"></param> protected override void OnDraw(OpenGlDevice Device) { base.OnDraw(Device); if (Transverse == null) { return; } if (Transverse.Count == 0) { return; } for (int i = 1; i > 0; i--) { if (Trace[i].dist(Trace[i - 1]) < Utils.epsilon) { Trace.RemoveAt(i); } } if ((Trace.Count == 3) && (Trace.Closed())) { Trace.RemoveAt(2); } if (Trace.Count <= 1) { return; } // if (Trace.Count <= 1) return; xyz Basey = new xyz(0, 0, 0); if (Trace.Count == 2) { Basey = new xyz(0, 0, -1); if ((Basey & (Trace[1] - Trace[0])).length() < 0.000001) { Basey = new xyz(0, -1, 0); } } else { Basey = (((Trace[2] - Trace[1]) & (Trace[0] - Trace[1]))).normalized() * (-1); } for (int i = 0; i < Trace.Count - 1; i++) { xyz N1, N2; if (i == 0) { if (Trace.Closed()) { N1 = (Trace[i + 1] - Trace[i]).normalized() - (Trace[Trace.Count - 2] - Trace[i]).normalized(); } else { N1 = (Trace[i + 1] - Trace[i]).normalized(); } if ((i + 2) == Trace.Count) { N2 = (Trace[i] - Trace[i + 1]).normalized() & Basey; } else { N2 = (Trace[i] - Trace[i + 1]).normalized() - (Trace[i + 2] - Trace[i + 1]).normalized(); } } else if (i == (Trace.Count - 2)) { N1 = (Trace[i + 1] - Trace[i]).normalized() - (Trace[i - 1] - Trace[i]).normalized(); if (Trace.Closed()) { N2 = (Trace[i] - Trace[0]).normalized() - (Trace[1] - Trace[0]).normalized(); } else { N2 = (Trace[i] - Trace[Trace.Count - 1]).normalized(); } } else { N1 = (Trace[i + 1] - Trace[i]).normalized() - (Trace[i - 1] - Trace[i]).normalized(); N2 = (Trace[i] - Trace[i + 1]).normalized() - (Trace[i + 2] - Trace[i + 1]).normalized(); } if (Trace.Count == 2) { N1 = Trace[1] - Trace[0]; N2 = Trace[0] - Trace[1]; } Plane P1 = new Plane(Trace[i], N1.normalized()); Plane P2 = new Plane(Trace[i + 1], N2.normalized()); if (i > 0) { Basey = Matrix.Mirror(P1) * Basey - Matrix.Mirror(P1) * new xyz(0, 0, 0); } Base B = new Base(); B.BaseO = Trace[i]; B.BaseZ = (Trace[i + 1] - Trace[i]).normalized(); B.BaseY = Basey.normalized(); B.BaseX = (B.BaseY & B.BaseZ).normalized(); B.BaseY = B.BaseZ & B.BaseX * (-1); Matrix BInvert = B.ToMatrix().invert(); Plane DownPlane = BInvert * P1; Plane UpPlane = BInvert * P2; Device.PushMatrix(); Device.MulMatrix(B.ToMatrix()); for (int m = 0; m < Transverse.Count; m++) { for (int n = 0; n < Transverse[m].Count; n++) { CurveExtruder CE = new CurveExtruder(); CE.Height = -1; CE.DownPlane = BInvert * P1; CE.UpPlane = BInvert * P2; CE.Curve = Transverse[m][n]; CE.Paint(Device); if (Device.RenderKind == RenderKind.SnapBuffer) { SnappItem SI = Selector.StoredSnapItems[Selector.StoredSnapItems.Count - 1]; if (SI != null) { SI.OfObject = this; } } } } double L = (Trace[i + 1] - Trace[i]).length(); if ((i == 0) && (CloseFirst)) { Device.drawPolyPolyCurve(Transverse); } if ((i == Trace.Count - 2) && (CloseLast)) { Device.PushMatrix(); Device.MulMatrix(Matrix.Translation(new xyz(0, 0, L))); Device.drawPolyPolyCurve(Transverse); Device.PopMatrix(); } Device.PopMatrix(); } }
/// <summary> /// overrides the draw nethod and paints the axis. /// </summary> /// <param name="Device"></param> protected override void OnDraw(OpenGlDevice Device) { if (FullSize) { xy WE = Device.WorldExtensions; if (WE.dist(Size.toXY()) > 0.2) { SetInvalid(true); } Size = new xyz(WE.x, WE.y, WE.x); } if (Font == null) { Font = new Drawing3d.Font(FontName); } SaveFontSize = Font.FontSize; Font.FontSize = TextHeight; base.OnDraw(Device); Device.PushMatrix(); Device.MulMatrix(AxesBase.ToMatrix()); bool SaveLighting = Device.LightEnabled; Device.LightEnabled = false; Color Save = Device.Emission; Device.Emission = Color; if (LeftAndRight) { Device.drawLine(new xyz(-Size.x, 0, 0), new xyz(Size.x, 0, 0)); Device.drawLine(new xyz(0, -Size.y, 0), new xyz(0, Size.y, 0)); if (Dim3d) { Device.drawLine(new xyz(0, 0, -Size.z), new xyz(0, 0, Size.z)); } } { Device.drawLine(new xyz(0, 0, 0), new xyz(Size.x, 0, 0)); Device.drawLine(new xyz(0, 0, 0), new xyz(0, Size.y, 0)); if (Dim3d) { Device.drawLine(new xyz(0, 0, 0), new xyz(0, 0, Size.z)); } } xyz n1 = new xyz(0, DeviderLineLength, 0); int from = (int)(-Size.x / Devider.x); if (!LeftAndRight) { from = 0; } if (Device.RenderKind == RenderKind.Render) { for (int i = from; i <= Size.x / Devider.x; i++) { if (ShowDevider) { Device.drawLine(new xyz(Devider.x * i, 0, 0) - n1, new xyz(Devider.x * i, 0, 0) + n1); } if (ShowText) { double Pos = Devider.x * i - ((float)Device.getEnvText(Font, i.ToString()).x / 2f); Device.drawText(Font, Matrix.Translation(new xyz(Pos, DeviderLineLength, 0)), i.ToString(), 0); } } from = (int)(-Size.y / Devider.y); if (!LeftAndRight) { from = 0; } n1 = new xyz(DeviderLineLength, 0, 0); for (int i = from; i <= Size.y / Devider.y; i++) { if (i != 0) { if (ShowDevider) { Device.drawLine(new xyz(0, Devider.y * i, 0) - n1, new xyz(0, Devider.y * i, 0) + n1); } if (ShowText) { double Pos = Devider.x * i - ((float)Device.getEnvText(Font, i.ToString()).y / 2f); Device.drawText(Font, Matrix.Translation(new xyz(DeviderLineLength, Pos, 0)), i.ToString(), 0); } } } if (Dim3d) { for (int i = from; i <= Size.z / Devider.z; i++) { if (i != 0) { if (ShowDevider) { Device.drawLine(new xyz(0, 0, Devider.z * i) - n1, new xyz(0, 0, Devider.z * i) + n1); } if (ShowText) { double Pos = Devider.z * i - ((float)Device.getEnvText(Font, i.ToString()).y / 2f); Device.drawText(Font, Matrix.Translation(new xyz(DeviderLineLength, 0, Pos)), i.ToString(), 0); } } } } } if (Device.RenderKind == RenderKind.SnapBuffer) { if (LeftAndRight) { Device.drawLine(new xyz(-Size.x, 0, 0), new xyz(Size.x, 0, 0)); Device.drawLine(new xyz(0, -Size.y, 0), new xyz(0, Size.y, 0)); if (Dim3d) { Device.drawLine(new xyz(0, 0, -Size.z), new xyz(0, 0, Size.z)); } } else if (LeftAndRight) { Device.drawLine(new xyz(0, 0, 0), new xyz(Size.x, 0, 0)); Device.drawLine(new xyz(0, 0, 0), new xyz(0, Size.y, 0)); if (Dim3d) { Device.drawLine(new xyz(0, 0, 0), new xyz(0, 0, Size.z)); } } for (int i = from; i <= Size.x / Devider.x; i++) { Device.drawPoint(new xyz(Devider.x * i, 0, 0), Devider.x / 4); if (ShowText) { double Pos = Devider.x * i - ((float)Device.getEnvText(Font, i.ToString()).x / 2f); MeshContainer M = MeshCreator.MeshListCurrent; Device.drawText(Font, Matrix.Translation(new xyz(Pos, DeviderLineLength, 0)), i.ToString(), 0); M = MeshCreator.MeshListCurrent; } } from = (int)(-Size.y / Devider.y); if (!LeftAndRight) { from = 0; } n1 = new xyz(DeviderLineLength, 0, 0); for (int i = from; i <= Size.y / Devider.y; i++) { if (i != 0) { Device.drawPoint(new xyz(0, Devider.y * i, 0), Devider.x / 4); if (ShowText) { double Pos = Devider.x * i - ((float)Device.getEnvText(Font, i.ToString()).y / 2f); Device.drawText(Font, Matrix.Translation(new xyz(DeviderLineLength, Pos, 0)), i.ToString(), 0); } } } if (Dim3d) { for (int i = from; i <= Size.z / Devider.z; i++) { if (i != 0) { Device.drawPoint(new xyz(0, 0, Devider.z * i), Devider.x / 4); if (ShowText) { double Pos = Devider.z * i - ((float)Device.getEnvText(Font, i.ToString()).y / 2f); Device.drawText(Font, Matrix.Translation(new xyz(DeviderLineLength, 0, Pos)), i.ToString(), 0); } } } } } Device.Emission = Save; Device.LightEnabled = SaveLighting; Font.FontSize = SaveFontSize; Device.PopMatrix(); }
/// <summary> /// calls recursively the <see cref="CustomEntity.OnDraw(OpenGlDevice)"/>method of the members in the <see cref="Children"/>list. /// </summary> /// <param name="Device"></param> public void Paint(OpenGlDevice Device) { if ((!Visible) && (Device.RenderKind != RenderKind.SnapBuffer)) { return; } double SaveOpacity = Device.Translucent; OpenGlDevice.CheckError(); if (Device.RenderKind == RenderKind.Render) { if ((Pattern != null) && (Texture == null)) { Texture = GetPatternTexture(Device);// ActivatePattern(Device); } } OpenGlDevice.CheckError(); Entity SaveCurrent = CurrentEntity; if (HasTexture) { Device.texture = Texture; } if (HasMaterial) { Device.Material = Material; } if (HasOpacity) { Device.Translucent = System.Math.Min(Opacity, Device.Translucent); } CurrentEntity = this; if (Device.OutFitChanged) { setMesh(null); } if (Device.RenderKind == RenderKind.Render) { if (Invalid) { Device.invalid = true; } } if (((Mesh == null) || (Invalid)) && (CompileEnable) && (!Compiling) && (Device.RenderKind == RenderKind.Render)) { Compile(Device); // sollte nicht bei refreshSnapBuffer auf gerufen werden } Invalid = false; if (Device.Selector.CreateSnap) // kommt vonRefreshMeshBuffer { if (SnappEnable) { MeshCreator.CreateMeshes(Device, CompileMeshDraw); // Entity wird gedrawt im snap items mode } return; // eventuell Children interndraw braucht nicht aufgerufen werden!!! } if (HasTransformation) { Device.PushMatrix(); Device.MulMatrix(Transformation); } if ((Mesh != null))// && (Device.RenderKind == RenderKind.Render)) { Mesh.internDraw(Device); base.OnDraw(Device); } else { if (Mesh != null) { Mesh.Paint(Device); } else { internDraw(Device); // bei snap wird im createsnap registriert } } if (Mesh == null) { for (int i = 0; i < Children.Count; i++) { if (Children[i].Visible) { Children[i].Paint(Device); } } } CurrentEntity = SaveCurrent; if (HasTransformation) { Device.PopMatrix(); } if (HasOpacity) { Device.Translucent = SaveOpacity; } if (Entity.Compiling) { MeshCreator.CheckMeshCreator(); } OpenGlDevice.CheckError(); if (Device.RenderKind == RenderKind.Render) { Invalid = false; } }