Extract debug Drawables
This commit is contained in:
parent
f6a1029efc
commit
2a37ac564a
5 changed files with 158 additions and 39 deletions
|
|
@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using MatterHackers.Agg.UI;
|
using MatterHackers.Agg.UI;
|
||||||
|
using MatterHackers.DataConverters3D;
|
||||||
using MatterHackers.VectorMath;
|
using MatterHackers.VectorMath;
|
||||||
|
|
||||||
namespace MatterHackers.MatterControl.PartPreviewWindow
|
namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
|
|
@ -36,4 +37,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
{
|
{
|
||||||
void Draw(GuiWidget sender, DrawEventArgs e, Matrix4X4 itemMaxtrix, WorldView world);
|
void Draw(GuiWidget sender, DrawEventArgs e, Matrix4X4 itemMaxtrix, WorldView world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface IDrawableItem
|
||||||
|
{
|
||||||
|
void Draw(GuiWidget sender, IObject3D item, DrawEventArgs e, Matrix4X4 itemMaxtrix, WorldView world);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2019, Lars Brubaker, John Lewin
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
The views and conclusions contained in the software and documentation are those
|
||||||
|
of the authors and should not be interpreted as representing official policies,
|
||||||
|
either expressed or implied, of the FreeBSD Project.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using MatterHackers.Agg.UI;
|
||||||
|
using MatterHackers.DataConverters3D;
|
||||||
|
using MatterHackers.RenderOpenGl;
|
||||||
|
using MatterHackers.VectorMath;
|
||||||
|
|
||||||
|
namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
|
{
|
||||||
|
public class NormalsDrawable : IDrawableItem
|
||||||
|
{
|
||||||
|
private BedConfig sceneContext;
|
||||||
|
private InteractiveScene scene;
|
||||||
|
|
||||||
|
public NormalsDrawable(BedConfig sceneContext)
|
||||||
|
{
|
||||||
|
this.sceneContext = sceneContext;
|
||||||
|
this.scene = sceneContext.Scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw(GuiWidget sender, IObject3D item, DrawEventArgs e, Matrix4X4 itemMaxtrix, WorldView world)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
#if false
|
||||||
|
if (item.Mesh?.Faces.Count <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var frustum = world.GetClippingFrustum();
|
||||||
|
|
||||||
|
var mesh = item.Mesh;
|
||||||
|
|
||||||
|
foreach (var face in mesh.Faces)
|
||||||
|
{
|
||||||
|
int vertexCount = 0;
|
||||||
|
Vector3 faceCenter = Vector3.Zero;
|
||||||
|
foreach (var v in new[] { face.v0, face.v1, face.v2 })
|
||||||
|
{
|
||||||
|
var vertex = mesh.Vertices[v];
|
||||||
|
|
||||||
|
faceCenter += vertex.Position;
|
||||||
|
vertexCount++;
|
||||||
|
}
|
||||||
|
faceCenter /= vertexCount;
|
||||||
|
|
||||||
|
var matrix = item.WorldMatrix();
|
||||||
|
|
||||||
|
var transformed1 = Vector3Ex.Transform(faceCenter, matrix);
|
||||||
|
var normal = Vector3Ex.TransformNormal(face.Normal, matrix).GetNormal();
|
||||||
|
|
||||||
|
world.Render3DLineNoPrep(frustum, transformed1, transformed1 + normal, Color.Red, 2);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2019, Lars Brubaker, John Lewin
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
The views and conclusions contained in the software and documentation are those
|
||||||
|
of the authors and should not be interpreted as representing official policies,
|
||||||
|
either expressed or implied, of the FreeBSD Project.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using MatterHackers.Agg.UI;
|
||||||
|
using MatterHackers.DataConverters3D;
|
||||||
|
using MatterHackers.RayTracer;
|
||||||
|
using MatterHackers.VectorMath;
|
||||||
|
|
||||||
|
namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
|
{
|
||||||
|
public class TraceDataDrawable : IDrawable
|
||||||
|
{
|
||||||
|
private BedConfig sceneContext;
|
||||||
|
private InteractiveScene scene;
|
||||||
|
|
||||||
|
public TraceDataDrawable(BedConfig sceneContext)
|
||||||
|
{
|
||||||
|
this.sceneContext = sceneContext;
|
||||||
|
this.scene = sceneContext.Scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw(GuiWidget sender, DrawEventArgs e, Matrix4X4 itemMaxtrix, WorldView world)
|
||||||
|
{
|
||||||
|
// RenderSceneTraceData
|
||||||
|
var bvhIterator = new BvhIterator(scene?.TraceData(), decentFilter: (x) =>
|
||||||
|
{
|
||||||
|
var center = x.Bvh.GetCenter();
|
||||||
|
var worldCenter = Vector3Ex.Transform(center, x.TransformToWorld);
|
||||||
|
if (worldCenter.Z > 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
InteractionLayer.RenderBounds(e, world, bvhIterator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -126,23 +126,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
base.OnDraw(graphics2D);
|
base.OnDraw(graphics2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RendereSceneTraceData(DrawEventArgs e)
|
|
||||||
{
|
|
||||||
var bvhIterator = new BvhIterator(Scene?.TraceData(), decentFilter: (x) =>
|
|
||||||
{
|
|
||||||
var center = x.Bvh.GetCenter();
|
|
||||||
var worldCenter = Vector3Ex.Transform(center, x.TransformToWorld);
|
|
||||||
if (worldCenter.Z > 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
RenderBounds(e, World, bvhIterator);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RenderBounds(DrawEventArgs e, WorldView World, IEnumerable<BvhIterator> allResults)
|
public static void RenderBounds(DrawEventArgs e, WorldView World, IEnumerable<BvhIterator> allResults)
|
||||||
{
|
{
|
||||||
foreach (var x in allResults)
|
foreach (var x in allResults)
|
||||||
|
|
|
||||||
|
|
@ -370,28 +370,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
return drawColor;
|
return drawColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RenderNormals(IObject3D renderData)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
//var frustum = World.GetClippingFrustum();
|
|
||||||
|
|
||||||
//foreach (var face in renderData.Mesh.Faces)
|
|
||||||
//{
|
|
||||||
// int vertexCount = 0;
|
|
||||||
// Vector3 faceCenter = Vector3.Zero;
|
|
||||||
// foreach (var vertex in face.Vertices())
|
|
||||||
// {
|
|
||||||
// faceCenter += vertex.Position;
|
|
||||||
// vertexCount++;
|
|
||||||
// }
|
|
||||||
// faceCenter /= vertexCount;
|
|
||||||
|
|
||||||
// var transformed1 = Vector3Ex.Transform(faceCenter, renderData.Matrix);
|
|
||||||
// var normal = Vector3Ex.TransformNormal(face.Normal, renderData.Matrix).GetNormal();
|
|
||||||
|
|
||||||
// World.Render3DLineNoPrep(frustum, transformed1, transformed1 + normal, Color.Red, 2);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RenderSelection(IObject3D item, Frustum frustum, Color selectionColor)
|
private void RenderSelection(IObject3D item, Frustum frustum, Color selectionColor)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue