public override void Render(UiContext context, RectangleF clientRectangle) { if (Model == null) { return; } if (!CanRender(context)) { return; } var rect = context.PointsToPixels(clientRectangle); if (Clip) { context.RenderContext.ScissorEnabled = true; context.RenderContext.ScissorRectangle = rect; } Matrix4x4 rotationMatrix = Matrix4x4.Identity; var rot = Rotate + (RotateAnimation * (float)context.GlobalTime); if (rot != Vector3.Zero) { rotationMatrix = Matrix4x4.CreateRotationX(rot.X) * Matrix4x4.CreateRotationY(rot.Y) * Matrix4x4.CreateRotationZ(rot.Z); } float scaleMult = 1; if (BaseRadius > 0) { scaleMult = BaseRadius / model.GetRadius(); } var transform = Matrix4x4.CreateScale(Model.XScale * scaleMult, Model.YScale * scaleMult, 1) * rotationMatrix * Matrix4x4.CreateTranslation(Model.X, Model.Y, 0); transform *= CreateTransform((int)context.ViewportWidth, (int)context.ViewportHeight, rect); context.RenderContext.Cull = false; model.UpdateTransform(); model.Update(context.MatrixCam, context.GlobalTime, context.Data.ResourceManager); if (Tint != null) { var color = Tint.GetColor(context.GlobalTime); for (int i = 0; i < mats.Count; i++) { mats[i].Mat.Dc = color; } } model.DrawImmediate(context.RenderContext, context.Data.ResourceManager, transform, ref Lighting.Empty); if (Tint != null) { for (int i = 0; i < mats.Count; i++) { mats[i].Mat.Dc = mats[i].Dc; } } context.RenderContext.ScissorEnabled = false; context.RenderContext.Cull = true; }
void DoViewport(InterfaceModel mdl) { if (drawable == null) { return; } var szX = (int)ImGui.GetColumnWidth() - 5; var szY = (int)ImGui.GetWindowContentRegionMax().Y - (int)ImGui.GetCursorPosY() - 5; BindViewport(szX, szY); //Do drawing var rectangle = new Rectangle(5, 5, rtX - 10, rtY - 10); mainWindow.Renderer2D.Start(rtX, rtY); mainWindow.Renderer2D.FillRectangle(rectangle, Color4.CornflowerBlue); mainWindow.Renderer2D.Finish(); var transform = Matrix4x4.CreateScale(mdl.XScale, mdl.YScale, 1) * Matrix4x4.CreateTranslation(mdl.X, mdl.Y, 0); var mcam = new MatrixCamera(Matrix4x4.Identity); mcam.CreateTransform(rtX, rtY, rectangle); drawable.Update(mcam, TimeSpan.FromSeconds(mainWindow.TotalTime), context.ResourceManager); mainWindow.RenderState.Cull = false; mainWindow.RenderState.ScissorEnabled = true; mainWindow.RenderState.ScissorRectangle = rectangle; drawable.DrawImmediate(mainWindow.RenderState, context.ResourceManager, transform, ref Lighting.Empty); mainWindow.RenderState.ScissorEnabled = false; mainWindow.RenderState.Cull = true; DrawViewport(); }
protected override void Draw3DContent(UiContext context, RectangleF rect) { var cam = GetCamera(model.GetRadius() * 2f, context, rect); context.CommandBuffer.StartFrame(context.RenderContext); model.UpdateTransform(); model.Update(cam, context.GlobalTime, context.Data.ResourceManager); model.DrawBuffer(0, context.CommandBuffer, context.Data.ResourceManager, Matrix4x4.Identity, ref Lighting.Empty); context.CommandBuffer.DrawOpaque(context.RenderContext); context.RenderContext.DepthWrite = false; context.CommandBuffer.DrawTransparent(context.RenderContext); context.RenderContext.DepthWrite = true; }
public override void Render(UiContext context, RectangleF clientRectangle) { if (Model == null) { return; } if (!CanRender(context)) { return; } context.Mode3D(); var rect = context.PointsToPixels(clientRectangle); var transform = Matrix4x4.CreateScale(Model.XScale, Model.YScale, 1) * Matrix4x4.CreateTranslation(Model.X, Model.Y, 0); context.MatrixCam.CreateTransform((int)context.ViewportWidth, (int)context.ViewportHeight, rect); context.RenderState.Cull = false; model.UpdateTransform(); model.Update(context.MatrixCam, context.GlobalTime, context.ResourceManager); if (Tint != null) { var color = Tint.GetColor(context.GlobalTime); for (int i = 0; i < mats.Count; i++) { mats[i].Mat.Dc = color; } } model.DrawImmediate(context.RenderState, context.ResourceManager, transform, ref Lighting.Empty); if (Tint != null) { for (int i = 0; i < mats.Count; i++) { mats[i].Mat.Dc = mats[i].Dc; } } context.RenderState.Cull = true; }