static public GLMeshWirePlugin Get(Mesh meshToGetDisplayListFor, double nonPlanarAngleRequired = 0) { GLMeshWirePlugin plugin; meshesWithCacheData.TryGetValue(meshToGetDisplayListFor, out plugin); if (plugin != null && (meshToGetDisplayListFor.ChangedCount != plugin.meshUpdateCount || nonPlanarAngleRequired != plugin.nonPlanarAngleRequired)) { plugin.meshUpdateCount = meshToGetDisplayListFor.ChangedCount; plugin.AddRemoveData(); plugin.CreateRenderData(meshToGetDisplayListFor, nonPlanarAngleRequired); plugin.meshUpdateCount = meshToGetDisplayListFor.ChangedCount; plugin.nonPlanarAngleRequired = nonPlanarAngleRequired; } if (plugin == null) { GLMeshWirePlugin newPlugin = new GLMeshWirePlugin(); meshesWithCacheData.Add(meshToGetDisplayListFor, newPlugin); newPlugin.CreateRenderData(meshToGetDisplayListFor, nonPlanarAngleRequired); newPlugin.meshUpdateCount = meshToGetDisplayListFor.ChangedCount; newPlugin.nonPlanarAngleRequired = nonPlanarAngleRequired; return(newPlugin); } return(plugin); }
static public GLMeshWirePlugin Get(Mesh mesh, double nonPlanarAngleRequired = 0, Action meshChanged = null) { object meshData; mesh.PropertyBag.TryGetValue(GLMeshWirePluginName, out meshData); if (meshData is GLMeshWirePlugin plugin) { if (mesh.ChangedCount == plugin.meshUpdateCount && nonPlanarAngleRequired == plugin.nonPlanarAngleRequired) { return(plugin); } // else we need to rebuild the data plugin.meshUpdateCount = mesh.ChangedCount; mesh.PropertyBag.Remove(GLMeshWirePluginName); } GLMeshWirePlugin newPlugin = new GLMeshWirePlugin(); newPlugin.CreateRenderData(mesh, nonPlanarAngleRequired, meshChanged); newPlugin.meshUpdateCount = mesh.ChangedCount; mesh.PropertyBag.Add(GLMeshWirePluginName, newPlugin); return(newPlugin); }
private static void DrawWireOverlay(Mesh meshToRender, RenderTypes renderType, Color color, Action meshChanged = null) { GL.Color4(color.red, color.green, color.blue, color.alpha == 0 ? 255 : color.alpha); GL.Disable(EnableCap.Lighting); GL.DisableClientState(ArrayCap.TextureCoordArray); GLMeshWirePlugin glWireMeshPlugin = null; if (renderType == RenderTypes.Outlines) { glWireMeshPlugin = GLMeshWirePlugin.Get(meshToRender, MathHelper.Tau / 8, meshChanged); } else { glWireMeshPlugin = GLMeshWirePlugin.Get(meshToRender); } GL.EnableClientState(ArrayCap.VertexArray); VectorPOD <WireVertexData> edgeLines = glWireMeshPlugin.EdgeLines; unsafe { fixed(WireVertexData *pv = edgeLines.Array) { GL.VertexPointer(3, VertexPointerType.Float, 0, new IntPtr(pv)); GL.DrawArrays(BeginMode.Lines, 0, edgeLines.Count); } } GL.DisableClientState(ArrayCap.VertexArray); GL.Enable(EnableCap.Lighting); }
static public GLMeshWirePlugin Get(Mesh meshToGetDisplayListFor, double nonPlanarAngleRequired = 0) { GLMeshWirePlugin plugin; meshesWithCacheData.TryGetValue(meshToGetDisplayListFor, out plugin); if (plugin != null && (meshToGetDisplayListFor.ChangedCount != plugin.meshUpdateCount || nonPlanarAngleRequired != plugin.nonPlanarAngleRequired)) { plugin.meshUpdateCount = meshToGetDisplayListFor.ChangedCount; plugin.AddRemoveData(); plugin.CreateRenderData(meshToGetDisplayListFor, nonPlanarAngleRequired); plugin.meshUpdateCount = meshToGetDisplayListFor.ChangedCount; plugin.nonPlanarAngleRequired = nonPlanarAngleRequired; } if (plugin == null) { GLMeshWirePlugin newPlugin = new GLMeshWirePlugin(); meshesWithCacheData.Add(meshToGetDisplayListFor, newPlugin); newPlugin.CreateRenderData(meshToGetDisplayListFor, nonPlanarAngleRequired); newPlugin.meshUpdateCount = meshToGetDisplayListFor.ChangedCount; newPlugin.nonPlanarAngleRequired = nonPlanarAngleRequired; return newPlugin; } return plugin; }
private static void DrawWithWireOverlay(Mesh meshToRender, RenderTypes renderType) { GLMeshTrianglePlugin glMeshPlugin = GLMeshTrianglePlugin.Get(meshToRender); GL.Enable(EnableCap.PolygonOffsetFill); GL.PolygonOffset(1, 1); DrawToGL(meshToRender); GL.Color4(0, 0, 0, 255); GL.PolygonOffset(0, 0); GL.Disable(EnableCap.PolygonOffsetFill); GL.Disable(EnableCap.Lighting); GL.DisableClientState(ArrayCap.TextureCoordArray); GLMeshWirePlugin glWireMeshPlugin = null; if (renderType == RenderTypes.Outlines) { glWireMeshPlugin = GLMeshWirePlugin.Get(meshToRender, MathHelper.Tau / 8); } else { glWireMeshPlugin = GLMeshWirePlugin.Get(meshToRender); } VectorPOD <WireVertexData> edegLines = glWireMeshPlugin.edgeLinesData; GL.EnableClientState(ArrayCap.VertexArray); #if true unsafe { fixed(WireVertexData *pv = edegLines.Array) { GL.VertexPointer(3, VertexPointerType.Float, 0, new IntPtr(pv)); GL.DrawArrays(BeginMode.Lines, 0, edegLines.Count); } } #else GL.InterleavedArrays(InterleavedArrayFormat.V3f, 0, edegLines.Array); GL.DrawArrays(BeginMode.Lines, 0, edegLines.Count); #endif GL.DisableClientState(ArrayCap.VertexArray); GL.Enable(EnableCap.Lighting); }