Add inspection rendering for scene graph

This commit is contained in:
John Lewin 2017-10-21 08:56:08 -07:00
parent daa4d5c53a
commit 6836abebf3
4 changed files with 90 additions and 42 deletions

View file

@ -114,7 +114,8 @@ namespace MatterHackers.MatterControl
if (systemWindow == Instance)
{
// If systemWindow is MatterControlApplication, include Scene
return new InspectForm(systemWindow, ApplicationController.Instance.DragDropData.SceneContext.Scene);
var partContext = ApplicationController.Instance.DragDropData;
return new InspectForm(systemWindow, partContext.SceneContext.Scene, partContext.View3DWidget);
}
else
{

View file

@ -87,7 +87,7 @@ namespace MatterHackers.MeshVisualizer
this.sceneContext = sceneContext;
this.interactionLayer = interactionLayer;
this.World = interactionLayer.World;
scene.SelectionChanged += (sender, e) =>
{
Invalidate();
@ -321,6 +321,8 @@ namespace MatterHackers.MeshVisualizer
private void DrawObject(IObject3D object3D, List<IObject3D> transparentMeshes, bool parentSelected, DrawEventArgs e)
{
var totalVertices = 0;
var debugBorderColor = RGBA_Bytes.Green;
var debugNotSelectedFillColor = new RGBA_Bytes(RGBA_Bytes.White, 120);
foreach (var renderData in object3D.VisibleMeshes())
{
@ -336,6 +338,7 @@ namespace MatterHackers.MeshVisualizer
bool tooBigForComplexSelection = totalVertices > 1000;
if (tooBigForComplexSelection
&& scene.DebugItem == null
&& scene.HasSelection
&& (object3D == scene.SelectedItem || scene.SelectedItem.Children.Contains(object3D)))
{
@ -365,7 +368,15 @@ namespace MatterHackers.MeshVisualizer
drawColor = MatterialRendering.Color(renderData.WorldMaterialIndex());
}
if (drawColor.alpha == 255)
bool isDebugItem = false;
bool renderAsSolid = drawColor.alpha == 255;
#if DEBUG
isDebugItem = scene.DebugItem == renderData;
renderAsSolid = (renderAsSolid && scene.DebugItem == null)
|| isDebugItem;
#endif
if (renderAsSolid)
{
GLHelper.Render(renderData.Mesh, drawColor, renderData.WorldMatrix(), RenderType, renderData.WorldMatrix() * World.ModelviewMatrix);
}
@ -375,7 +386,7 @@ namespace MatterHackers.MeshVisualizer
{
Mesh = renderData.Mesh,
Matrix = renderData.WorldMatrix(),
Color = drawColor,
Color = (scene.DebugItem == null) ? drawColor : debugNotSelectedFillColor,
MaterialIndex = renderData.WorldMaterialIndex(),
OutputType = renderData.WorldOutputType()
});
@ -386,6 +397,21 @@ namespace MatterHackers.MeshVisualizer
RenderSelection(renderData, frustum);
}
#if DEBUG
if (isDebugItem)
{
var aabb = object3D.GetAxisAlignedBoundingBox(Matrix4X4.Identity);
GLHelper.PrepareFor3DLineRender(true);
RenderAABB(frustum, aabb, Matrix4X4.Identity, debugBorderColor, 1);
if (renderData.Mesh != null)
{
GLHelper.Render(renderData.Mesh, debugBorderColor, renderData.WorldMatrix(), RenderTypes.Wireframe, renderData.WorldMatrix() * World.ModelviewMatrix);
}
}
#endif
// RenderNormals(renderData);
// turn lighting back on after rendering selection outlines

View file

@ -48,6 +48,7 @@
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.Location = new System.Drawing.Point(0, 0);
this.splitContainer1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
@ -57,8 +58,9 @@
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.propertyGrid1);
this.splitContainer1.Size = new System.Drawing.Size(1246, 972);
this.splitContainer1.SplitterDistance = 832;
this.splitContainer1.Size = new System.Drawing.Size(831, 632);
this.splitContainer1.SplitterDistance = 554;
this.splitContainer1.SplitterWidth = 3;
this.splitContainer1.TabIndex = 0;
//
// tabControl1
@ -67,20 +69,19 @@
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(832, 972);
this.tabControl1.Size = new System.Drawing.Size(554, 632);
this.tabControl1.TabIndex = 1;
this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.tabControl1_SelectedIndexChanged);
//
// tabPage1
//
this.tabPage1.Controls.Add(this.aggTreeView);
this.tabPage1.Location = new System.Drawing.Point(4, 29);
this.tabPage1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.tabPage1.Size = new System.Drawing.Size(815, 939);
this.tabPage1.Padding = new System.Windows.Forms.Padding(3, 3, 3, 3);
this.tabPage1.Size = new System.Drawing.Size(546, 606);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "SystemWindow";
this.tabPage1.UseVisualStyleBackColor = true;
@ -91,9 +92,10 @@
this.aggTreeView.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawText;
this.aggTreeView.FullRowSelect = true;
this.aggTreeView.HideSelection = false;
this.aggTreeView.Location = new System.Drawing.Point(4, 5);
this.aggTreeView.Location = new System.Drawing.Point(3, 3);
this.aggTreeView.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.aggTreeView.Name = "aggTreeView";
this.aggTreeView.Size = new System.Drawing.Size(807, 929);
this.aggTreeView.Size = new System.Drawing.Size(540, 600);
this.aggTreeView.TabIndex = 1;
this.aggTreeView.DrawNode += new System.Windows.Forms.DrawTreeNodeEventHandler(this.AggTreeView_DrawNode);
this.aggTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.AggTreeView_AfterSelect);
@ -101,11 +103,10 @@
// tabPage2
//
this.tabPage2.Controls.Add(this.sceneTreeView);
this.tabPage2.Location = new System.Drawing.Point(4, 29);
this.tabPage2.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.tabPage2.Size = new System.Drawing.Size(824, 939);
this.tabPage2.Padding = new System.Windows.Forms.Padding(3, 3, 3, 3);
this.tabPage2.Size = new System.Drawing.Size(547, 606);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "Scene";
this.tabPage2.UseVisualStyleBackColor = true;
@ -116,9 +117,10 @@
this.sceneTreeView.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawText;
this.sceneTreeView.FullRowSelect = true;
this.sceneTreeView.HideSelection = false;
this.sceneTreeView.Location = new System.Drawing.Point(4, 5);
this.sceneTreeView.Location = new System.Drawing.Point(3, 3);
this.sceneTreeView.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.sceneTreeView.Name = "sceneTreeView";
this.sceneTreeView.Size = new System.Drawing.Size(816, 929);
this.sceneTreeView.Size = new System.Drawing.Size(541, 600);
this.sceneTreeView.TabIndex = 2;
this.sceneTreeView.DrawNode += new System.Windows.Forms.DrawTreeNodeEventHandler(this.SceneTreeView_DrawNode);
this.sceneTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.SceneTreeView_AfterSelect);
@ -128,17 +130,19 @@
this.propertyGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
this.propertyGrid1.LineColor = System.Drawing.SystemColors.ControlDark;
this.propertyGrid1.Location = new System.Drawing.Point(0, 0);
this.propertyGrid1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.propertyGrid1.Name = "propertyGrid1";
this.propertyGrid1.Size = new System.Drawing.Size(410, 972);
this.propertyGrid1.Size = new System.Drawing.Size(274, 632);
this.propertyGrid1.TabIndex = 0;
this.propertyGrid1.PropertyValueChanged += new System.Windows.Forms.PropertyValueChangedEventHandler(this.propertyGrid1_PropertyValueChanged);
//
// InspectForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1246, 972);
this.ClientSize = new System.Drawing.Size(831, 632);
this.Controls.Add(this.splitContainer1);
this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.Name = "InspectForm";
this.Text = "InspectForm";
this.splitContainer1.Panel1.ResumeLayout(false);

View file

@ -6,6 +6,7 @@ using System.Windows.Forms;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.MeshVisualizer;
using MatterHackers.VectorMath;
@ -22,15 +23,22 @@ namespace MatterHackers.MatterControl
private Dictionary<IObject3D, TreeNode> sceneTreeNodes = new Dictionary<IObject3D, TreeNode>();
private InteractiveScene scene;
private View3DWidget view3DWidget;
public InspectForm(GuiWidget inspectedSystemWindow, InteractiveScene scene)
public InspectForm(GuiWidget inspectedSystemWindow, InteractiveScene scene, View3DWidget view3DWidget)
: this(inspectedSystemWindow)
{
this.view3DWidget = view3DWidget;
this.scene = scene;
this.scene.Children.ItemsModified += Scene_ChildrenModified;
sceneTreeView.SuspendLayout();
this.AddTree(scene, null, "Scene");
sceneTreeView.ResumeLayout();
if (view3DWidget.ContainsFocus)
{
tabControl1.SelectedIndex = 1;
}
}
private void Scene_ChildrenModified(object sender, EventArgs e)
@ -340,11 +348,13 @@ namespace MatterHackers.MatterControl
private void SceneTreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
this.InspectedObject3D = e.Node.Tag as IObject3D;
this.scene.DebugItem = this.InspectedObject3D;
view3DWidget.PartHasBeenChanged();
}
private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
{
this.InspectedWidget.Invalidate();
this.InspectedWidget?.Invalidate();
}
public void MoveUpTree()
@ -375,7 +385,9 @@ namespace MatterHackers.MatterControl
private void systemWindow_AfterDraw(object sender, EventArgs e)
{
if (this.Inspecting && !inspectedSystemWindow.HasBeenClosed)
if (this.Inspecting
&& !inspectedSystemWindow.HasBeenClosed
&& tabControl1.SelectedIndex == 0)
{
var namedChildren = new List<GuiWidget.WidgetAndPosition>();
inspectedSystemWindow.FindNamedChildrenRecursive(
@ -413,6 +425,7 @@ namespace MatterHackers.MatterControl
if (scene != null)
{
scene.Children.ItemsModified -= Scene_ChildrenModified;
scene.DebugItem = null;
}
if (mouseUpWidget != null)
@ -461,22 +474,10 @@ namespace MatterHackers.MatterControl
var node = e.Node;
if (node.IsVisible)
{
var item = node.Tag as IObject3D;
Brush brush;
if (scene.HasSelection
&& (scene.SelectedItem == item
|| scene.SelectedItem.Children.Contains(item)))
{
brush = SystemBrushes.Highlight;
}
else
{
brush = Brushes.Transparent;
}
e.Graphics.FillRectangle(brush, e.Node.Bounds);
//var item = node.Tag as IObject3D;
e.Graphics.FillRectangle(
(sceneTreeView.SelectedNode == node) ? SystemBrushes.Highlight : Brushes.Transparent,
node.Bounds);
TextRenderer.DrawText(
e.Graphics,
@ -487,5 +488,21 @@ namespace MatterHackers.MatterControl
Color.Transparent);
}
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.activeTreeNode != null
&& tabControl1.SelectedIndex != 0
&& this.activeTreeNode.Tag is GuiWidget widget)
{
widget.DebugShowBounds = false;
}
if (scene.DebugItem != null
&& tabControl1.SelectedIndex != 1)
{
scene.DebugItem = null;
}
}
}
}