Improving subtract object rendering
This commit is contained in:
parent
76c4985111
commit
ac03a4fcfd
16 changed files with 116 additions and 105 deletions
|
|
@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project.
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -52,10 +53,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
|
||||
public SelectedChildren SelectedChildren { get; set; } = new SelectedChildren();
|
||||
|
||||
public void DrawEditor(object sender, DrawEventArgs e)
|
||||
public void DrawEditor(InteractionLayer layer, List<Object3DView> transparentMeshes, DrawEventArgs e, ref bool suppressNormalDraw)
|
||||
{
|
||||
if (sender is InteractionLayer layer
|
||||
&& layer.Scene.SelectedItem != null
|
||||
if (layer.Scene.SelectedItem != null
|
||||
&& layer.Scene.SelectedItem.DescendantsAndSelf().Where((i) => i == this).Any())
|
||||
{
|
||||
// draw the component objects
|
||||
|
|
@ -143,47 +143,34 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
|
||||
ProgressStatus progressStatus = new ProgressStatus();
|
||||
progressStatus.Status = "Do CSG";
|
||||
foreach (var paint in paintObjects)
|
||||
foreach (var keep in keepObjects)
|
||||
{
|
||||
Mesh paintMesh = null;
|
||||
var paintWorldMatrix = paint.WorldMatrix(SourceContainer);
|
||||
var keepResultsMesh = keep.Mesh;
|
||||
var keepWorldMatrix = keep.WorldMatrix(SourceContainer);
|
||||
|
||||
foreach (var keep in keepObjects)
|
||||
foreach (var paint in paintObjects)
|
||||
{
|
||||
var keepResultsMesh = keep.Mesh;
|
||||
|
||||
var intersect = BooleanProcessing.Do(keepResultsMesh, keep.WorldMatrix(SourceContainer),
|
||||
paint.Mesh, paintWorldMatrix,
|
||||
Mesh paintMesh = BooleanProcessing.Do(keepResultsMesh, keepWorldMatrix,
|
||||
paint.Mesh, paint.WorldMatrix(SourceContainer),
|
||||
2, reporter, amountPerOperation, percentCompleted, progressStatus, cancellationToken);
|
||||
|
||||
keepResultsMesh = BooleanProcessing.Do(keepResultsMesh, keep.WorldMatrix(SourceContainer),
|
||||
paint.Mesh, paintWorldMatrix,
|
||||
keepResultsMesh = BooleanProcessing.Do(keepResultsMesh, keepWorldMatrix,
|
||||
paint.Mesh, paint.WorldMatrix(SourceContainer),
|
||||
1, reporter, amountPerOperation, percentCompleted, progressStatus, cancellationToken);
|
||||
|
||||
// after the first time we get a result the results mesh is in the right coordinate space
|
||||
paintWorldMatrix = Matrix4X4.Identity;
|
||||
keepWorldMatrix = Matrix4X4.Identity;
|
||||
|
||||
// keep all the intersections together
|
||||
if (paintMesh == null)
|
||||
// store our intersection (paint) results mesh
|
||||
var paintResultsItem = new Object3D()
|
||||
{
|
||||
paintMesh = intersect;
|
||||
}
|
||||
else // union into the current paint
|
||||
{
|
||||
paintMesh = BooleanProcessing.Do(paintMesh, Matrix4X4.Identity,
|
||||
intersect, Matrix4X4.Identity, 0, reporter, amountPerOperation, percentCompleted, progressStatus, cancellationToken);
|
||||
}
|
||||
|
||||
// store our results mesh
|
||||
var keepResultsItem = new Object3D()
|
||||
{
|
||||
Mesh = keepResultsMesh,
|
||||
Mesh = paintMesh,
|
||||
Visible = false
|
||||
};
|
||||
// copy all the properties but the matrix
|
||||
keepResultsItem.CopyProperties(keep, Object3DPropertyFlags.All & (~(Object3DPropertyFlags.Matrix | Object3DPropertyFlags.Visible)));
|
||||
paintResultsItem.CopyProperties(paint, Object3DPropertyFlags.All & (~(Object3DPropertyFlags.Matrix | Object3DPropertyFlags.Visible)));
|
||||
// and add it to this
|
||||
this.Children.Add(keepResultsItem);
|
||||
this.Children.Add(paintResultsItem);
|
||||
|
||||
// report our progress
|
||||
percentCompleted += amountPerOperation;
|
||||
|
|
@ -192,15 +179,15 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
}
|
||||
|
||||
// store our results mesh
|
||||
var paintResultsItem = new Object3D()
|
||||
var keepResultsItem = new Object3D()
|
||||
{
|
||||
Mesh = paintMesh,
|
||||
Mesh = keepResultsMesh,
|
||||
Visible = false
|
||||
};
|
||||
// copy all the properties but the matrix
|
||||
paintResultsItem.CopyProperties(paint, Object3DPropertyFlags.All & (~(Object3DPropertyFlags.Matrix | Object3DPropertyFlags.Visible)));
|
||||
keepResultsItem.CopyProperties(keep, Object3DPropertyFlags.All & (~(Object3DPropertyFlags.Matrix | Object3DPropertyFlags.Visible)));
|
||||
// and add it to this
|
||||
this.Children.Add(paintResultsItem);
|
||||
this.Children.Add(keepResultsItem);
|
||||
}
|
||||
|
||||
foreach (var child in Children)
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project.
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -52,12 +53,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
|
||||
public SelectedChildren SelectedChildren { get; set; } = new SelectedChildren();
|
||||
|
||||
public void DrawEditor(object sender, DrawEventArgs e)
|
||||
public void DrawEditor(InteractionLayer layer, List<Object3DView> transparentMeshes, DrawEventArgs e, ref bool suppressNormalDraw)
|
||||
{
|
||||
if (sender is InteractionLayer layer
|
||||
&& layer.Scene.SelectedItem != null
|
||||
&& layer.Scene.SelectedItem.DescendantsAndSelf().Where((i) => i == this).Any())
|
||||
if (layer.Scene.SelectedItem != null
|
||||
&& layer.Scene.SelectedItem == this)
|
||||
{
|
||||
suppressNormalDraw = true;
|
||||
|
||||
var removeObjects = this.SourceContainer.VisibleMeshes()
|
||||
.Where((i) => SelectedChildren.Contains(i.Name)).ToList();
|
||||
var keepObjects = this.SourceContainer.VisibleMeshes()
|
||||
|
|
@ -65,22 +67,28 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
|
||||
foreach (var item in removeObjects)
|
||||
{
|
||||
GLHelper.Render(item.Mesh,
|
||||
Color.Transparent,
|
||||
item.WorldMatrix(),
|
||||
RenderTypes.Outlines,
|
||||
item.WorldMatrix() * layer.World.ModelviewMatrix,
|
||||
Color.Red);
|
||||
transparentMeshes.Add(new Object3DView(item, new Color(item.WorldColor(SourceContainer), 128)));
|
||||
}
|
||||
|
||||
foreach (var item in keepObjects)
|
||||
{
|
||||
GLHelper.Render(item.Mesh,
|
||||
Color.Transparent,
|
||||
item.WorldMatrix(),
|
||||
RenderTypes.Outlines,
|
||||
item.WorldMatrix() * layer.World.ModelviewMatrix,
|
||||
Color.Green);
|
||||
var subtractChild = this.Children.Where(i => i.Name == item.Name).FirstOrDefault();
|
||||
if (subtractChild != null)
|
||||
{
|
||||
GLHelper.Render(subtractChild.Mesh,
|
||||
subtractChild.Color,
|
||||
subtractChild.WorldMatrix(),
|
||||
RenderTypes.Outlines,
|
||||
subtractChild.WorldMatrix() * layer.World.ModelviewMatrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
GLHelper.Render(item.Mesh,
|
||||
item.WorldColor(SourceContainer),
|
||||
item.WorldMatrix(),
|
||||
RenderTypes.Outlines,
|
||||
item.WorldMatrix() * layer.World.ModelviewMatrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -204,11 +212,20 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.View3D
|
|||
this.Children.Add(resultsItem);
|
||||
}
|
||||
|
||||
bool first = true;
|
||||
foreach (var child in Children)
|
||||
{
|
||||
child.Visible = true;
|
||||
if (first)
|
||||
{
|
||||
// hid the source item
|
||||
child.Visible = false;
|
||||
first = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
child.Visible = true;
|
||||
}
|
||||
}
|
||||
SourceContainer.Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue