From e54de77a1d6965180548665f93cc2316fabb6efc Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Tue, 1 Aug 2017 17:38:07 -0700 Subject: [PATCH] Making a material visualizer --- PartPreviewWindow/View3D/MeshViewerWidget.cs | 8 ++- PartPreviewWindow/View3D/View3DWidget.cs | 63 ++++++++++--------- .../SlicerMapping/EngineMappingCura.cs | 6 +- Submodules/agg-sharp | 2 +- 4 files changed, 46 insertions(+), 33 deletions(-) diff --git a/PartPreviewWindow/View3D/MeshViewerWidget.cs b/PartPreviewWindow/View3D/MeshViewerWidget.cs index 4cb3da417..7023a8742 100644 --- a/PartPreviewWindow/View3D/MeshViewerWidget.cs +++ b/PartPreviewWindow/View3D/MeshViewerWidget.cs @@ -631,6 +631,12 @@ namespace MatterHackers.MeshVisualizer drawColor = new RGBA_Bytes(RGBA_Bytes.Gray, 120); } + // check if we should be rendering materials + if (this.RenderType == RenderTypes.Materials) + { + drawColor = RGBA_Floats.FromHSL(Math.Max(renderData.MaterialIndex, 0) / 4.0, .99, .49).GetAsRGBA_Bytes(); + } + if (drawColor.Alpha0To1 == 0) { drawColor = lastDrawColor; @@ -639,7 +645,7 @@ namespace MatterHackers.MeshVisualizer { lastDrawColor = drawColor; } - + GLHelper.Render(renderData.Mesh, drawColor, renderData.Matrix, RenderType); } } diff --git a/PartPreviewWindow/View3D/View3DWidget.cs b/PartPreviewWindow/View3D/View3DWidget.cs index 1c04d3ab1..2d1e1b092 100644 --- a/PartPreviewWindow/View3D/View3DWidget.cs +++ b/PartPreviewWindow/View3D/View3DWidget.cs @@ -354,17 +354,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow doEdittingButtonsContainer.AddChild(mirrorButton); // put in the material options - int numberOfExtruders = ActiveSliceSettings.Instance.GetValue(SettingsKey.extruder_count); - if (numberOfExtruders > 1) + var materialsButton = new PopupButton(smallMarginButtonFactory.Generate("Materials".Localize())) { - var materialsButton = new PopupButton(smallMarginButtonFactory.Generate("Materials".Localize())) - { - PopDirection = Direction.Up, - PopupContent = this.AddMaterialControls(), - AlignToRightEdge = true - }; - doEdittingButtonsContainer.AddChild(materialsButton); - } + PopDirection = Direction.Up, + PopupContent = this.AddMaterialControls(), + AlignToRightEdge = true + }; + doEdittingButtonsContainer.AddChild(materialsButton); } editToolBar.AddChild(doEdittingButtonsContainer); @@ -1502,7 +1498,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow }; extruderButtons.Clear(); - for (int extruderIndex = 0; extruderIndex < ActiveSliceSettings.Instance.GetValue(SettingsKey.extruder_count); extruderIndex++) + int extruderCount = 4; + for (int extruderIndex = 0; extruderIndex < extruderCount; extruderIndex++) { FlowLayoutWidget colorSelectionContainer = new FlowLayoutWidget(FlowDirection.LeftToRight); colorSelectionContainer.HAnchor = HAnchor.FitToChildren; @@ -1520,7 +1517,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { if (Scene.HasSelection) { - Scene.SelectedItem.ExtruderIndex = extruderIndexCanPassToClick; + Scene.SelectedItem.MaterialIndex = extruderIndexCanPassToClick; PartHasBeenChanged(); } }; @@ -1736,7 +1733,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow // Set the material selector to have the correct material button selected for (int i = 0; i < extruderButtons.Count; i++) { - if (selectedItem.ExtruderIndex == i) + if (selectedItem.MaterialIndex == i) { ((RadioButton)extruderButtons[i]).Checked = true; setSelection = true; @@ -2368,6 +2365,25 @@ namespace MatterHackers.MatterControl.PartPreviewWindow container.AddChild(renderTypeCheckBox); } + // Materials option + { + RadioButton materialsCheckBox = new RadioButton("Materials".Localize(), textColor: itemTextColor); + materialsCheckBox.Checked = (meshViewerWidget.RenderType == RenderTypes.Materials); + + materialsCheckBox.CheckedStateChanged += (sender, e) => + { + if (materialsCheckBox.Checked) + { + meshViewerWidget.RenderType = RenderTypes.Materials; + UserSettings.Instance.set("defaultRenderSetting", meshViewerWidget.RenderType.ToString()); + } + }; + + container.AddChild(materialsCheckBox); + } + + + // overhang setting { RadioButton renderTypeCheckBox = new RadioButton("Overhang".Localize(), textColor: itemTextColor); renderTypeCheckBox.Checked = (meshViewerWidget.RenderType == RenderTypes.Overhang); @@ -2382,14 +2398,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow meshViewerWidget.RenderType = RenderTypes.Overhang; UserSettings.Instance.set("defaultRenderSetting", meshViewerWidget.RenderType.ToString()); - foreach (var meshAndTransform in scene.VisibleMeshes(Matrix4X4.Identity)) + foreach (var meshRenderData in scene.VisibleMeshes(Matrix4X4.Identity)) { - meshAndTransform.Mesh.MarkAsChanged(); + meshRenderData.Mesh.MarkAsChanged(); // change the color to be the right thing - GLMeshTrianglePlugin glMeshPlugin = GLMeshTrianglePlugin.Get(meshAndTransform.Mesh, (faceEdge) => + GLMeshTrianglePlugin glMeshPlugin = GLMeshTrianglePlugin.Get(meshRenderData.Mesh, (faceEdge) => { Vector3 normal = faceEdge.ContainingFace.normal; - normal = Vector3.TransformVector(normal, meshAndTransform.Matrix).GetNormal(); + normal = Vector3.TransformVector(normal, meshRenderData.Matrix).GetNormal(); VertexColorData colorData = new VertexColorData(); double startColor = 223.0 / 360.0; @@ -2409,21 +2425,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow }); } } - else - { - // TODO: Implement - /* - foreach (var meshTransform in Scene.VisibleMeshes(Matrix4X4.Identity)) - { - // turn off the overhang colors - } */ - } }; container.AddChild(renderTypeCheckBox); - - return container; } + + return container; } protected bool autoRotating = false; diff --git a/SlicerConfiguration/SlicerMapping/EngineMappingCura.cs b/SlicerConfiguration/SlicerMapping/EngineMappingCura.cs index dc48b81c6..87f90ec83 100644 --- a/SlicerConfiguration/SlicerMapping/EngineMappingCura.cs +++ b/SlicerConfiguration/SlicerMapping/EngineMappingCura.cs @@ -87,7 +87,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration // needs testing, not working new ScaledSingleNumber("support_material_spacing", "supportLineDistance", 1000), - new SupportMatterial("support_material", "supportAngle"), + new SupportMaterial("support_material", "supportAngle"), new VisibleButNotMappedToEngine("support_material_threshold"), new MappedSetting("support_material_create_internal_support", "supportEverywhere"), new ScaledSingleNumber("support_material_xy_distance", "supportXYDistance", 1000), @@ -172,9 +172,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration } } - public class SupportMatterial : MappedSetting + public class SupportMaterial : MappedSetting { - public SupportMatterial(string canonicalSettingsName, string exportedName) + public SupportMaterial(string canonicalSettingsName, string exportedName) : base(canonicalSettingsName, exportedName) { } diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index e52941469..058af7cc2 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit e529414690964af6821a7f74f5b102df280ed580 +Subproject commit 058af7cc2d2da01c84501bfe3291a7422a08a669