static public void CreatePointer(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, Vector3 startPos, Vector3 endPos, double radius, int steps, RGBA_Bytes color) { Vector3 direction = endPos - startPos; Vector3 directionNormal = direction.GetNormal(); Vector3 startSweepDirection = Vector3.GetPerpendicular(startPos, endPos).GetNormal(); int[] tubeStartIndices = new int[steps]; for (int i = 0; i < steps; i++) { // create tube ends verts Vector3 tubeNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); Vector3 offset = Vector3.Transform(startSweepDirection * radius, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); Vector3 tubeStart = startPos + offset; tubeStartIndices[i] = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(tubeStart, tubeNormal, color)); Vector3 tubeEnd = endPos + offset; } int tipEndIndex = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(endPos, directionNormal, color)); for (int i = 0; i < steps; i++) { // create tube polys indexData.Add(tubeStartIndices[i]); indexData.Add(tubeStartIndices[(i + 1) % steps]); indexData.Add(tipEndIndex); } }
public override void CreateRender3DData(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, GCodeRenderInfo renderInfo) { if ((renderInfo.CurrentRenderType & RenderType.Moves) == RenderType.Moves) { CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), .1, 6, GCodeRenderer.TravelColor, .2); } }
public RecursiveBlur(RecursizeBlurCalculator recursizeBluerCalculatorFactory) { m_sum1 = new VectorPOD<RecursizeBlurCalculator>(); m_sum2 = new VectorPOD<RecursizeBlurCalculator>(); m_buf = new VectorPOD<RGBA_Bytes>(); m_RecursizeBlurCalculatorFactory = recursizeBluerCalculatorFactory; }
private void CreateRenderData(Mesh meshToBuildListFor, double nonPlanarAngleRequired = 0) { edgeLinesData = new VectorPOD <WireVertexData>(); // first make sure all the textures are created foreach (MeshEdge meshEdge in meshToBuildListFor.MeshEdges) { if (nonPlanarAngleRequired > 0) { if (meshEdge.GetNumFacesSharingEdge() == 2) { FaceEdge firstFaceEdge = meshEdge.firstFaceEdge; FaceEdge nextFaceEdge = meshEdge.firstFaceEdge.radialNextFaceEdge; double angle = Vector3.CalculateAngle(firstFaceEdge.containingFace.normal, nextFaceEdge.containingFace.normal); if (angle > MathHelper.Tau * .1) { edgeLinesData.Add(AddVertex(meshEdge.VertexOnEnd[0].Position, meshEdge.VertexOnEnd[1].Position)); } } else { edgeLinesData.Add(AddVertex(meshEdge.VertexOnEnd[0].Position, meshEdge.VertexOnEnd[1].Position)); } } else { edgeLinesData.Add(AddVertex(meshEdge.VertexOnEnd[0].Position, meshEdge.VertexOnEnd[1].Position)); } } }
public override void CreateRender3DData(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, GCodeRenderInfo renderInfo) { if ((renderInfo.CurrentRenderType & RenderType.Retractions) == RenderType.Retractions) { var position = new Vector3(this.position); // retract and unretract are the extruder color Color color = renderInfo.GetMaterialColor(extruderIndex); // except for extruder 0 where they are the red and blue we are familiar with if (extruderIndex == 0) { if (extrusionAmount > 0) { color = Color.Blue; } else { color = Color.Red; } } if (extrusionAmount > 0) { // unretraction CreatePointer(colorVertexData, indexData, position + new Vector3(0, 0, 1.3), position + new Vector3(0, 0, .3), Radius(1), 5, color); } else { // retraction CreatePointer(colorVertexData, indexData, position + new Vector3(0, 0, .3), position + new Vector3(0, 0, 1.3), Radius(1), 5, color); } } }
public RecursiveBlur(RecursizeBlurCalculator recursizeBluerCalculatorFactory) { m_sum1 = new List <RecursizeBlurCalculator>(); m_sum2 = new List <RecursizeBlurCalculator>(); m_buf = new VectorPOD <Color>(); m_RecursizeBlurCalculatorFactory = recursizeBluerCalculatorFactory; }
public override void CreateRender3DData(VectorPOD<ColorVertexData> colorVertexData, VectorPOD<int> indexData, GCodeRenderInfo renderInfo) { if ((renderInfo.CurrentRenderType & RenderType.Retractions) == RenderType.Retractions) { Vector3 position = new Vector3(this.position); RGBA_Bytes color = MeshViewerWidget.GetMaterialColor(extruderIndex + 1); if (extruderIndex == 0) { if (extrusionAmount > 0) { color = RGBA_Bytes.Blue; } else { color = RGBA_Bytes.Red; } } if (extrusionAmount > 0) { // unretraction CreatePointer(colorVertexData, indexData, position + new Vector3(0, 0, 1.3), position + new Vector3(0, 0, .3), Radius(1), 5, color); } else { // retraction CreatePointer(colorVertexData, indexData, position + new Vector3(0, 0, .3), position + new Vector3(0, 0, 1.3), Radius(1), 5, color); } } }
private GCodeVertexBuffer Create3DDataForLayer(int layerIndex, GCodeRenderInfo renderInfo) { var colorVertexData = new VectorPOD <ColorVertexData>(); var vertexIndexArray = new VectorPOD <int>(); featureStartIndex[layerIndex].Clear(); featureEndIndex[layerIndex].Clear(); for (int i = 0; i < renderFeatures[layerIndex].Count; i++) { featureStartIndex[layerIndex].Add(vertexIndexArray.Count); RenderFeatureBase feature = renderFeatures[layerIndex][i]; if (feature != null) { // Build the color and index data for the feature feature.CreateRender3DData(colorVertexData, vertexIndexArray, renderInfo); } featureEndIndex[layerIndex].Add(vertexIndexArray.Count); } // Construct and return the new VertexBuffer object with all color/index data return(new GCodeVertexBuffer(vertexIndexArray.Array, colorVertexData.Array)); }
public override void CreateRender3DData(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, GCodeRenderInfo renderInfo) { if ((renderInfo.CurrentRenderType & RenderType.Extrusions) == RenderType.Extrusions) { Vector3Float start = this.GetStart(renderInfo); Vector3Float end = this.GetEnd(renderInfo); double radius = GetRadius(renderInfo.CurrentRenderType); Color lineColor; if (renderInfo.CurrentRenderType.HasFlag(RenderType.SpeedColors)) { lineColor = color; } else if (renderInfo.CurrentRenderType.HasFlag(RenderType.GrayColors)) { lineColor = ActiveTheme.Instance.IsDarkTheme ? Color.DarkGray : Color.Gray; } else { lineColor = renderInfo.GetMaterialColor(extruderIndex); } CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, lineColor, layerHeight); } }
public curve3_div() { m_points = new VectorPOD <Vector2>(); m_approximation_scale = (1.0); m_angle_tolerance = (0.0); m_count = (0); }
public override void CreateRender3DData(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, GCodeRenderInfo renderInfo) { if ((renderInfo.CurrentRenderType & RenderType.Retractions) == RenderType.Retractions) { Vector3 position = new Vector3(this.position); RGBA_Bytes color = MeshViewerWidget.GetMaterialColor(extruderIndex + 1); if (extruderIndex == 0) { if (extrusionAmount > 0) { color = RGBA_Bytes.Blue; } else { color = RGBA_Bytes.Red; } } if (extrusionAmount > 0) { // unretraction CreatePointer(colorVertexData, indexData, position + new Vector3(0, 0, 1.3), position + new Vector3(0, 0, .3), Radius(1), 5, color); } else { // retraction CreatePointer(colorVertexData, indexData, position + new Vector3(0, 0, .3), position + new Vector3(0, 0, 1.3), Radius(1), 5, color); } } }
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); }
public Curve3Div() { m_points = new VectorPOD <IVector <T> >(); m_approximation_scale = M.One <T>(); m_angle_tolerance = M.Zero <T>(); m_count = (0); }
public Curve3Div() { m_points = new VectorPOD <PointD>(); m_approximation_scale = (1.0); m_angle_tolerance = (0.0); m_count = (0); }
public void CopyFrom(VectorPOD <T> v) { Allocate(v.m_size); if (v.m_size != 0) { v.m_array.CopyTo(m_array, 0); } }
public override void CreateRender3DData(VectorPOD<ColorVertexData> colorVertexData, VectorPOD<int> indexData, GCodeRenderInfo renderInfo) { if ((renderInfo.CurrentRenderType & RenderType.Moves) == RenderType.Moves) { Vector3Float start = this.GetStart(renderInfo); Vector3Float end = this.GetEnd(renderInfo); CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), .1, 6, GCodeRenderer.TravelColor, .2); } }
public RasterizerCellsAA() { m_QSorter = new QuickSortCellAA(); m_sorted_cells = new VectorPOD <CellAA>(); m_sorted_y = new VectorPOD <sorted_y>(); m_min_x = (0x7FFFFFFF); m_min_y = (0x7FFFFFFF); m_max_x = (-0x7FFFFFFF); m_max_y = (-0x7FFFFFFF); m_sorted = (false); m_style_cell.Initial(); m_curr_cell.Initial(); }
private void AddVertex(VectorPOD <WireVertexData> edgeLines, Vector3Float vertex0, Vector3Float vertex1) { WireVertexData tempVertex; tempVertex.PositionsX = (float)vertex0.X; tempVertex.PositionsY = (float)vertex0.Y; tempVertex.PositionsZ = (float)vertex0.Z; edgeLines.Add(tempVertex); tempVertex.PositionsX = (float)vertex1.X; tempVertex.PositionsY = (float)vertex1.Y; tempVertex.PositionsZ = (float)vertex1.Z; edgeLines.Add(tempVertex); }
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); }
private void CreateRenderData(Mesh mesh, double nonPlanarAngleRequired = 0, Action meshChanged = null) { this.nonPlanarAngleRequired = nonPlanarAngleRequired; var edgeLines = new VectorPOD <WireVertexData>(); this.EdgeLines = edgeLines; // if we are trying to have a filtered list do this in a background thread and wait for the results if (nonPlanarAngleRequired > 0) { Task.Run(() => { var meshEdgeList = mesh.NewMeshEdges(); var filteredEdgeLines = new VectorPOD <WireVertexData>(); foreach (var meshEdge in meshEdgeList) { if (meshEdge.Faces.Count() == 2) { var faceNormal0 = mesh.Faces[meshEdge.Faces[0]].normal; var faceNormal1 = mesh.Faces[meshEdge.Faces[1]].normal; double angle = faceNormal0.CalculateAngle(faceNormal1); if (angle > nonPlanarAngleRequired) { AddVertex(filteredEdgeLines, mesh.Vertices[meshEdge.Vertex0Index], mesh.Vertices[meshEdge.Vertex1Index]); } } } this.EdgeLines = filteredEdgeLines; meshChanged?.Invoke(); }); } else { // create a quick edge list of all the polygon edges for (int faceIndex = 0; faceIndex < mesh.Faces.Count; faceIndex++) { var face = mesh.Faces[faceIndex]; AddVertex(edgeLines, mesh.Vertices[face.v0], mesh.Vertices[face.v1]); AddVertex(edgeLines, mesh.Vertices[face.v1], mesh.Vertices[face.v2]); AddVertex(edgeLines, mesh.Vertices[face.v2], mesh.Vertices[face.v0]); } } }
private void AllocateCellsIfRequired() { if (m_cells == null || (m_num_used_cells + 1) >= m_cells.Capacity()) { if (m_num_used_cells >= (int)cell_block_scale_e.cell_block_limit) { return; } uint new_num_allocated_cells = m_num_used_cells + (uint)cell_block_scale_e.cell_block_size; VectorPOD <CellAA> new_cells = new VectorPOD <CellAA>(new_num_allocated_cells); if (m_cells != null) { new_cells.CopyFrom(m_cells); } m_cells = new_cells; } }
///<summary> ///</summary> public AntiAliasedCompundRasterizer() { _rasterizer = new AntiAliasedRasterizerCells(); _vectorClipper = new VectorClipper_DoClip(); _fillingRule = Basics.FillingRule.NonZero; _layerOrder = ELayerOrder.LayerDirect; _activeStyles = new VectorPOD<StyleInfo>(); _activeStyleTable = new VectorPOD<uint>(); _activeStyleMask = new VectorPOD<byte>(); _cells = new VectorPOD<AntiAliasingCell>(); _coverBuffer = new VectorPOD<byte>(); _masterAlpha = new VectorPOD<uint>(); _minStyle = (0x7FFFFFFF); _maxStyle = (-0x7FFFFFFF); _startX = (0); _startY = (0); _scanY = (0x7FFFFFFF); _scanlineStart = (0); _scanlineLength = (0); }
public rasterizer_compound_aa() { m_Rasterizer = new rasterizer_cells_aa(); m_VectorClipper = new VectorClipper_DoClip(); m_filling_rule = agg_basics.filling_rule_e.fill_non_zero; m_layer_order = layer_order_e.layer_direct; m_styles = new VectorPOD<style_info>(); // Active Styles m_ast = new VectorPOD<int>(); // Active Style Table (unique values) m_asm = new VectorPOD<byte>(); // Active Style Mask m_cells = new VectorPOD<cell_aa>(); m_cover_buf = new VectorPOD<byte>(); m_master_alpha = new VectorPOD<int>(); m_min_style = (0x7FFFFFFF); m_max_style = (-0x7FFFFFFF); m_start_x = (0); m_start_y = (0); m_scan_y = (0x7FFFFFFF); m_sl_start = (0); m_sl_len = (0); }
public RasterizerCompoundAA() { m_Rasterizer = new RasterizerCellsAA(); m_VectorClipper = new VectorClipper <T>(); m_filling_rule = FillingRule.NonZero; m_layer_order = LayerOrder.Direct; m_styles = new VectorPOD <StyleInfo>(); // Active Styles m_ast = new VectorPOD <uint>(); // Active Style Table (unique values) m_asm = new VectorPOD <byte>(); // Active Style Mask m_cells = new VectorPOD <CellAA>(); m_cover_buf = new VectorPOD <byte>(); m_master_alpha = new VectorPOD <uint>(); m_min_style = (0x7FFFFFFF); m_max_style = (-0x7FFFFFFF); m_start_x = (0); m_start_y = (0); m_scan_y = (0x7FFFFFFF); m_sl_start = (0); m_sl_len = (0); }
private void Create3DDataForLayer(int layerIndex, VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> vertexIndexArray, GCodeRenderInfo renderInfo) { colorVertexData.Clear(); vertexIndexArray.Clear(); featureStartIndex[layerIndex].Clear(); featureEndIndex[layerIndex].Clear(); for (int i = 0; i < renderFeatures[layerIndex].Count; i++) { featureStartIndex[layerIndex].Add(vertexIndexArray.Count); RenderFeatureBase feature = renderFeatures[layerIndex][i]; if (feature != null) { feature.CreateRender3DData(colorVertexData, vertexIndexArray, renderInfo); } featureEndIndex[layerIndex].Add(vertexIndexArray.Count); } }
private void CreateRenderData(Mesh mesh, Action meshChanged = null) { var edgeLines = new VectorPOD <WireVertexData>(); // create a quick edge list of all the polygon edges for (int faceIndex = 0; faceIndex < mesh.Faces.Count; faceIndex++) { var face = mesh.Faces[faceIndex]; AddVertex(edgeLines, mesh.Vertices[face.v0], mesh.Vertices[face.v1]); AddVertex(edgeLines, mesh.Vertices[face.v1], mesh.Vertices[face.v2]); AddVertex(edgeLines, mesh.Vertices[face.v2], mesh.Vertices[face.v0]); } this.EdgeLines = edgeLines; // do this in a background thread and wait for the results Task.Run(() => { var meshEdgeList = mesh.NewMeshEdges(); var filteredEdgeLines = new VectorPOD <WireVertexData>(); foreach (var meshEdge in meshEdgeList) { if (meshEdge.Faces.Count() != 2) { AddVertex(filteredEdgeLines, mesh.Vertices[meshEdge.Vertex0Index], mesh.Vertices[meshEdge.Vertex1Index]); } } this.EdgeLines = filteredEdgeLines; meshChanged?.Invoke(); }); }
public override void CreateRender3DData(VectorPOD<ColorVertexData> colorVertexData, VectorPOD<int> indexData, GCodeRenderInfo renderInfo) { if ((renderInfo.CurrentRenderType & RenderType.Extrusions) == RenderType.Extrusions) { Vector3Float start = this.GetStart(renderInfo); Vector3Float end = this.GetEnd(renderInfo); double radius = GetRadius(renderInfo.CurrentRenderType); if ((renderInfo.CurrentRenderType & RenderType.SpeedColors) == RenderType.SpeedColors) { CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, color, layerHeight); } else { if (extruderIndex == 0) { CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, GCodeRenderer.ExtrusionColor, layerHeight); } else { CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, MeshViewerWidget.GetMaterialColor(extruderIndex + 1), layerHeight); } } } }
public override void CreateRender3DData(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, GCodeRenderInfo renderInfo) { if ((renderInfo.CurrentRenderType & RenderType.Retractions) == RenderType.Retractions) { Vector3 position = new Vector3(this.position); if (renderInfo.CurrentRenderType.HasFlag(RenderType.HideExtruderOffsets)) { Vector2 offset = renderInfo.GetExtruderOffset(extruderIndex); position = position + new Vector3(offset); } Color color = MeshViewerWidget.GetMaterialColor(extruderIndex + 1); if (extruderIndex == 0) { if (extrusionAmount > 0) { color = Color.Blue; } else { color = Color.Red; } } if (extrusionAmount > 0) { // unretraction CreatePointer(colorVertexData, indexData, position + new Vector3(0, 0, 1.3), position + new Vector3(0, 0, .3), Radius(1), 5, color); } else { // retraction CreatePointer(colorVertexData, indexData, position + new Vector3(0, 0, .3), position + new Vector3(0, 0, 1.3), Radius(1), 5, color); } } }
public override void CreateRender3DData(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, GCodeRenderInfo renderInfo) { if ((renderInfo.CurrentRenderType & RenderType.Extrusions) == RenderType.Extrusions) { double radius = GetRadius(renderInfo.CurrentRenderType); Color lineColor; if (renderInfo.CurrentRenderType.HasFlag(RenderType.SpeedColors)) { lineColor = color; } else if (renderInfo.CurrentRenderType.HasFlag(RenderType.GrayColors)) { lineColor = this.gray; } else { lineColor = renderInfo.GetMaterialColor(toolIndex); } CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, lineColor, layerHeight); } }
public override void CreateRender3DData(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, GCodeRenderInfo renderInfo) { if ((renderInfo.CurrentRenderType & RenderType.Extrusions) == RenderType.Extrusions) { Vector3Float start = this.GetStart(renderInfo); Vector3Float end = this.GetEnd(renderInfo); double radius = GetRadius(renderInfo.CurrentRenderType); if ((renderInfo.CurrentRenderType & RenderType.SpeedColors) == RenderType.SpeedColors) { CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, color, layerHeight); } else { if (extruderIndex == 0) { CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, GCodeRenderer.ExtrusionColor, layerHeight); } else { CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, MeshViewerWidget.GetMaterialColor(extruderIndex + 1), layerHeight); } } } }
// Copying public VectorPOD(VectorPOD <T> v) { m_size = v.m_size; m_capacity = v.m_capacity; m_array = (T[])v.m_array.Clone(); }
public void Render3D(GCodeRenderInfo renderInfo) { if (layerVertexBuffer == null) { layerVertexBuffer = new List <GCodeVertexBuffer>(); layerVertexBuffer.Capacity = gCodeFileToDraw.NumChangesInZ; for (int layerIndex = 0; layerIndex < gCodeFileToDraw.NumChangesInZ; layerIndex++) { layerVertexBuffer.Add(null); featureStartIndex.Add(new List <int>()); featureEndIndex.Add(new List <int>()); } } for (int layerIndex = 0; layerIndex < gCodeFileToDraw.NumChangesInZ; layerIndex++) { CreateFeaturesForLayerIfRequired(layerIndex); } if (lastRenderType != renderInfo.CurrentRenderType) { Clear3DGCode(); lastRenderType = renderInfo.CurrentRenderType; } if (renderFeatures.Count > 0) { for (int i = renderInfo.EndLayerIndex - 1; i >= renderInfo.StartLayerIndex; i--) { // If its the first render or we change what we are trying to render then create vertex data. if (layerVertexBuffer[i] == null) { VectorPOD <ColorVertexData> colorVertexData = new VectorPOD <ColorVertexData>(); VectorPOD <int> vertexIndexArray = new VectorPOD <int>(); Create3DDataForLayer(i, colorVertexData, vertexIndexArray, renderInfo); layerVertexBuffer[i] = new GCodeVertexBuffer(); layerVertexBuffer[i].SetVertexData(colorVertexData.Array); layerVertexBuffer[i].SetIndexData(vertexIndexArray.Array); } } GL.Disable(EnableCap.Texture2D); GL.PushAttrib(AttribMask.EnableBit); GL.DisableClientState(ArrayCap.TextureCoordArray); GL.Enable(EnableCap.PolygonSmooth); if (renderInfo.EndLayerIndex - 1 > renderInfo.StartLayerIndex) { for (int i = renderInfo.StartLayerIndex; i < renderInfo.EndLayerIndex - 1; i++) { int featuresOnLayer = renderFeatures[i].Count; if (featuresOnLayer > 1) { layerVertexBuffer[i].renderRange(0, featureEndIndex[i][featuresOnLayer - 1]); } } } // draw the partial layer of end-1 from startRatio to endRatio { int layerIndex = renderInfo.EndLayerIndex - 1; int featuresOnLayer = renderFeatures[layerIndex].Count; int startFeature = (int)(featuresOnLayer * renderInfo.FeatureToStartOnRatio0To1 + .5); startFeature = Math.Max(0, Math.Min(startFeature, featuresOnLayer)); int endFeature = (int)(featuresOnLayer * renderInfo.FeatureToEndOnRatio0To1 + .5); endFeature = Math.Max(0, Math.Min(endFeature, featuresOnLayer)); // try to make sure we always draw at least one feature if (endFeature <= startFeature) { endFeature = Math.Min(startFeature + 1, featuresOnLayer); } if (startFeature >= endFeature) { // This can only happen if the start and end are set to the last feature // Try to set the start feature to one from the end startFeature = Math.Max(endFeature - 1, 0); } if (endFeature > startFeature) { int ellementCount = featureEndIndex[layerIndex][endFeature - 1] - featureStartIndex[layerIndex][startFeature]; layerVertexBuffer[layerIndex].renderRange(featureStartIndex[layerIndex][startFeature], ellementCount); } } GL.PopAttrib(); } }
private void CreateRenderData(Mesh meshToBuildListFor, Func <Vector3Float, Color> getColorFunc) { subMeshs = new List <SubTriangleMesh>(); SubTriangleMesh currentSubMesh = null; VectorPOD <VertexTextureData> textureData = null; VectorPOD <VertexColorData> colorData = null; VectorPOD <VertexNormalData> normalData = null; VectorPOD <VertexPositionData> positionData = null; // first make sure all the textures are created for (int faceIndex = 0; faceIndex < meshToBuildListFor.Faces.Count; faceIndex++) { FaceTextureData faceTexture; meshToBuildListFor.FaceTextures.TryGetValue(faceIndex, out faceTexture); if (faceTexture != null) { ImageGlPlugin.GetImageGlPlugin(faceTexture.image, true); } // don't compare the data of the texture but rather if they are just the same object if (subMeshs.Count == 0 || (faceTexture != null && (object)subMeshs[subMeshs.Count - 1].texture != (object)faceTexture.image)) { SubTriangleMesh newSubMesh = new SubTriangleMesh(); newSubMesh.texture = faceTexture == null ? null : faceTexture.image; subMeshs.Add(newSubMesh); if (getColorFunc != null) { newSubMesh.UseVertexColors = true; } currentSubMesh = subMeshs[subMeshs.Count - 1]; textureData = currentSubMesh.textureData; colorData = currentSubMesh.colorData; normalData = currentSubMesh.normalData; positionData = currentSubMesh.positionData; } VertexColorData color = new VertexColorData(); if (getColorFunc != null) { var faceColor = getColorFunc(meshToBuildListFor.Faces[faceIndex].normal); color = new VertexColorData { red = faceColor.red, green = faceColor.green, blue = faceColor.blue }; } VertexTextureData tempTexture; VertexNormalData tempNormal; VertexPositionData tempPosition; tempTexture.textureU = faceTexture == null ? 0 : (float)faceTexture.uv0.X; tempTexture.textureV = faceTexture == null ? 0 : (float)faceTexture.uv0.Y; var normal = meshToBuildListFor.Faces[faceIndex].normal; tempNormal.normalX = normal.X; tempNormal.normalY = normal.Y; tempNormal.normalZ = normal.Z; int vertexIndex = meshToBuildListFor.Faces[faceIndex].v0; tempPosition.positionX = (float)meshToBuildListFor.Vertices[vertexIndex].X; tempPosition.positionY = (float)meshToBuildListFor.Vertices[vertexIndex].Y; tempPosition.positionZ = (float)meshToBuildListFor.Vertices[vertexIndex].Z; textureData.Add(tempTexture); normalData.Add(tempNormal); positionData.Add(tempPosition); colorData.add(color); tempTexture.textureU = faceTexture == null ? 0 : (float)faceTexture.uv1.X; tempTexture.textureV = faceTexture == null ? 0 : (float)faceTexture.uv1.Y; vertexIndex = meshToBuildListFor.Faces[faceIndex].v1; tempPosition.positionX = (float)meshToBuildListFor.Vertices[vertexIndex].X; tempPosition.positionY = (float)meshToBuildListFor.Vertices[vertexIndex].Y; tempPosition.positionZ = (float)meshToBuildListFor.Vertices[vertexIndex].Z; textureData.Add(tempTexture); normalData.Add(tempNormal); positionData.Add(tempPosition); colorData.add(color); tempTexture.textureU = faceTexture == null ? 0 : (float)faceTexture.uv2.X; tempTexture.textureV = faceTexture == null ? 0 : (float)faceTexture.uv2.Y; vertexIndex = meshToBuildListFor.Faces[faceIndex].v2; tempPosition.positionX = (float)meshToBuildListFor.Vertices[vertexIndex].X; tempPosition.positionY = (float)meshToBuildListFor.Vertices[vertexIndex].Y; tempPosition.positionZ = (float)meshToBuildListFor.Vertices[vertexIndex].Z; textureData.Add(tempTexture); normalData.Add(tempNormal); positionData.Add(tempPosition); colorData.add(color); } }
private void allocate_cells_if_required() { if (m_cells == null || (m_num_used_cells + 1) >= m_cells.capacity()) { if (m_num_used_cells >= (int)cell_block_scale_e.cell_block_limit) { return; } int new_num_allocated_cells = m_num_used_cells + (int)cell_block_scale_e.cell_block_size; VectorPOD<cell_aa> new_cells = new VectorPOD<cell_aa>(new_num_allocated_cells); if (m_cells != null) { new_cells.CopyFrom(m_cells); } m_cells = new_cells; } }
private void Create3DDataForLayer(int layerIndex, VectorPOD<ColorVertexData> colorVertexData, VectorPOD<int> vertexIndexArray, GCodeRenderInfo renderInfo) { colorVertexData.Clear(); vertexIndexArray.Clear(); featureStartIndex[layerIndex].Clear(); featureEndIndex[layerIndex].Clear(); for (int i = 0; i < renderFeatures[layerIndex].Count; i++) { featureStartIndex[layerIndex].Add(vertexIndexArray.Count); RenderFeatureBase feature = renderFeatures[layerIndex][i]; if (feature != null) { feature.CreateRender3DData(colorVertexData, vertexIndexArray, renderInfo); } featureEndIndex[layerIndex].Add(vertexIndexArray.Count); } }
public void Render3D(GCodeRenderInfo renderInfo) { if (layerVertexBuffer == null) { layerVertexBuffer = new List<GCodeVertexBuffer>(); layerVertexBuffer.Capacity = gCodeFileToDraw.NumChangesInZ; for (int layerIndex = 0; layerIndex < gCodeFileToDraw.NumChangesInZ; layerIndex++) { layerVertexBuffer.Add(null); featureStartIndex.Add(new List<int>()); featureEndIndex.Add(new List<int>()); } } for (int layerIndex = 0; layerIndex < gCodeFileToDraw.NumChangesInZ; layerIndex++) { CreateFeaturesForLayerIfRequired(layerIndex); } if (lastRenderType != renderInfo.CurrentRenderType) { Clear3DGCode(); lastRenderType = renderInfo.CurrentRenderType; } if (renderFeatures.Count > 0) { if (Is32Bit() && !GL.GlHasBufferObjects) { int maxFeaturesForThisSystem = 125000; int totalFeaturesToRunder = 0; bool cleanUnusedLayers = false; // if on 32 bit system make sure we don't run out of memory rendering too many features for (int i = renderInfo.EndLayerIndex - 1; i >= renderInfo.StartLayerIndex; i--) { if (totalFeaturesToRunder + renderFeatures[i].Count < maxFeaturesForThisSystem) { totalFeaturesToRunder += renderFeatures[i].Count; } else // don't render any of the layers below this and in fact remove them from memory if possible { renderInfo.startLayerIndex = i + 1; cleanUnusedLayers = true; break; } } if (cleanUnusedLayers) { // no remove any layers that are set that we are not going to render for (int removeIndex = 0; removeIndex < layerVertexBuffer.Count; removeIndex++) { if (removeIndex < renderInfo.StartLayerIndex || removeIndex >= renderInfo.EndLayerIndex) { if (layerVertexBuffer[removeIndex] != null) { layerVertexBuffer[removeIndex].Dispose(); layerVertexBuffer[removeIndex] = null; } } } } } for (int i = renderInfo.EndLayerIndex - 1; i >= renderInfo.StartLayerIndex; i--) { // If its the first render or we change what we are trying to render then create vertex data. if (layerVertexBuffer[i] == null) { VectorPOD<ColorVertexData> colorVertexData = new VectorPOD<ColorVertexData>(); VectorPOD<int> vertexIndexArray = new VectorPOD<int>(); Create3DDataForLayer(i, colorVertexData, vertexIndexArray, renderInfo); layerVertexBuffer[i] = new GCodeVertexBuffer(); layerVertexBuffer[i].SetVertexData(colorVertexData.Array); layerVertexBuffer[i].SetIndexData(vertexIndexArray.Array); } } GL.Disable(EnableCap.Texture2D); GL.PushAttrib(AttribMask.EnableBit); GL.DisableClientState(ArrayCap.TextureCoordArray); GL.Enable(EnableCap.PolygonSmooth); if (renderInfo.EndLayerIndex - 1 > renderInfo.StartLayerIndex) { for (int i = renderInfo.StartLayerIndex; i < renderInfo.EndLayerIndex - 1; i++) { int featuresOnLayer = renderFeatures[i].Count; if (featuresOnLayer > 1) { layerVertexBuffer[i].renderRange(0, featureEndIndex[i][featuresOnLayer - 1]); } } } // draw the partial layer of end-1 from startRatio to endRatio { int layerIndex = renderInfo.EndLayerIndex - 1; int featuresOnLayer = renderFeatures[layerIndex].Count; int startFeature = (int)(featuresOnLayer * renderInfo.FeatureToStartOnRatio0To1 + .5); startFeature = Math.Max(0, Math.Min(startFeature, featuresOnLayer)); int endFeature = (int)(featuresOnLayer * renderInfo.FeatureToEndOnRatio0To1 + .5); endFeature = Math.Max(0, Math.Min(endFeature, featuresOnLayer)); // try to make sure we always draw at least one feature if (endFeature <= startFeature) { endFeature = Math.Min(startFeature + 1, featuresOnLayer); } if (startFeature >= endFeature) { // This can only happen if the sart and end are set to the last feature // Try to set the start feture to one from the end startFeature = Math.Max(endFeature - 1, 0); } if (endFeature > startFeature) { int ellementCount = featureEndIndex[layerIndex][endFeature - 1] - featureStartIndex[layerIndex][startFeature]; layerVertexBuffer[layerIndex].renderRange(featureStartIndex[layerIndex][startFeature], ellementCount); } } GL.PopAttrib(); } }
private void CreateRenderData(Mesh meshToBuildListFor) { subMeshs = new List<SubTriangleMesh>(); SubTriangleMesh currentSubMesh = null; VectorPOD<TriangleVertexData> vertexDatas = new VectorPOD<TriangleVertexData>(); // first make sure all the textures are created foreach (Face face in meshToBuildListFor.Faces) { ImageBuffer faceTexture = face.GetTexture(0); if (faceTexture != null) { ImageGlPlugin.GetImageGlPlugin(faceTexture, true); } // don't compare the data of the texture but rather if they are just the same object if (subMeshs.Count == 0 || (object)subMeshs[subMeshs.Count - 1].texture != (object)faceTexture) { SubTriangleMesh newSubMesh = new SubTriangleMesh(); newSubMesh.texture = faceTexture; subMeshs.Add(newSubMesh); #if USE_VBO if (currentSubMesh != null) { CreateVBOForSubMesh(vertexDatas, currentSubMesh); vertexDatas.Clear(); } currentSubMesh = subMeshs[subMeshs.Count - 1]; #else currentSubMesh = subMeshs[subMeshs.Count - 1]; vertexDatas = currentSubMesh.vertexDatas; #endif } Vector2[] textureUV = new Vector2[2]; Vector3[] position = new Vector3[2]; int vertexIndex = 0; foreach (FaceEdge faceEdge in face.FaceEdges()) { if (vertexIndex < 2) { textureUV[vertexIndex] = faceEdge.GetUVs(0); position[vertexIndex] = faceEdge.firstVertex.Position; } else { TriangleVertexData tempVertex; tempVertex.textureU = (float)textureUV[0].x; tempVertex.textureV = (float)textureUV[0].y; tempVertex.positionsX = (float)position[0].x; tempVertex.positionsY = (float)position[0].y; tempVertex.positionsZ = (float)position[0].z; tempVertex.normalsX = (float)face.normal.x; tempVertex.normalsY = (float)face.normal.y; tempVertex.normalsZ = (float)face.normal.z; vertexDatas.Add(tempVertex); tempVertex.textureU = (float)textureUV[1].x; tempVertex.textureV = (float)textureUV[1].y; tempVertex.positionsX = (float)position[1].x; tempVertex.positionsY = (float)position[1].y; tempVertex.positionsZ = (float)position[1].z; tempVertex.normalsX = (float)face.normal.x; tempVertex.normalsY = (float)face.normal.y; tempVertex.normalsZ = (float)face.normal.z; vertexDatas.Add(tempVertex); Vector2 textureUV2 = faceEdge.GetUVs(0); Vector3 position2 = faceEdge.firstVertex.Position; tempVertex.textureU = (float)textureUV2.x; tempVertex.textureV = (float)textureUV2.y; tempVertex.positionsX = (float)position2.x; tempVertex.positionsY = (float)position2.y; tempVertex.positionsZ = (float)position2.z; tempVertex.normalsX = (float)face.normal.x; tempVertex.normalsY = (float)face.normal.y; tempVertex.normalsZ = (float)face.normal.z; vertexDatas.Add(tempVertex); textureUV[1] = faceEdge.GetUVs(0); position[1] = faceEdge.firstVertex.Position; } vertexIndex++; } } CreateVBOForSubMesh(vertexDatas, currentSubMesh); }
public AntiAliasedRasterizerCells() { m_QSorter = new QuickSortAntiAliasedCell(); m_sorted_cells = new VectorPOD<AntiAliasingCell>(); m_sorted_y = new VectorPOD<SortedY>(); m_min_x = (0x7FFFFFFF); m_min_y = (0x7FFFFFFF); m_max_x = (-0x7FFFFFFF); m_max_y = (-0x7FFFFFFF); m_sorted = (false); m_style_cell.Initial(); m_curr_cell.Initial(); }
static public void CreateCylinder(VectorPOD<ColorVertexData> colorVertexData, VectorPOD<uint> indexData, Vector3 startPos, Vector3 endPos, double radius, int steps, RGBA_Bytes color, double layerHeight) { Vector3 direction = endPos - startPos; Vector3 directionNormal = direction.GetNormal(); Vector3 startSweepDirection = Vector3.GetPerpendicular(startPos, endPos).GetNormal(); uint[] tubeStartIndices = new uint[steps]; uint[] tubeEndIndices = new uint[steps]; uint[] capStartIndices = new uint[steps]; uint[] capEndIndices = new uint[steps]; double halfHeight = layerHeight / 2 + (layerHeight * .1); double halfWidth = (radius * radius) / halfHeight; double zScale = halfHeight/radius; double xScale = halfWidth/radius; Vector3 scale = new Vector3(xScale, xScale, zScale); for (int i = 0; i < steps; i++) { // create tube ends verts Vector3 tubeNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); Vector3 offset = Vector3.Transform(startSweepDirection * radius, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); offset *= scale; Vector3 tubeStart = startPos + offset; tubeStartIndices[i] = (uint)colorVertexData.Count; colorVertexData.Add(new ColorVertexData(tubeStart, tubeNormal, color)); Vector3 tubeEnd = endPos + offset; tubeEndIndices[i] = (uint)colorVertexData.Count; colorVertexData.Add(new ColorVertexData(tubeEnd, tubeNormal, color)); // create cap verts Vector3 rotateAngle = Vector3.Cross(direction, startSweepDirection); Vector3 capStartNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(rotateAngle, MathHelper.Tau / 8)); capStartNormal = Vector3.Transform(capStartNormal, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); capStartNormal = (capStartNormal * scale).GetNormal(); Vector3 capStartOffset = capStartNormal * radius; capStartOffset *= scale; Vector3 capStart = startPos + capStartOffset; capStartIndices[i] = (uint)colorVertexData.Count; colorVertexData.Add(new ColorVertexData(capStart, capStartNormal, color)); Vector3 capEndNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(-rotateAngle, MathHelper.Tau / 8)); capEndNormal = Vector3.Transform(capEndNormal, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); capEndNormal = (capEndNormal * scale).GetNormal(); Vector3 capEndOffset = capEndNormal * radius; capEndOffset *= scale; Vector3 capEnd = endPos + capEndOffset; capEndIndices[i] = (uint)colorVertexData.Count; colorVertexData.Add(new ColorVertexData(capEnd, capEndNormal, color)); } uint tipStartIndex = (uint)colorVertexData.Count; Vector3 tipOffset = directionNormal * radius; tipOffset *= scale; colorVertexData.Add(new ColorVertexData(startPos - tipOffset, -directionNormal, color)); uint tipEndIndex = (uint)colorVertexData.Count; colorVertexData.Add(new ColorVertexData(endPos + tipOffset, directionNormal, color)); for (int i = 0; i < steps; i++) { // create tube polys indexData.Add(tubeStartIndices[i]); indexData.Add(tubeEndIndices[i]); indexData.Add(tubeEndIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[i]); indexData.Add(tubeEndIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[(i + 1) % steps]); // create start cap polys indexData.Add(tubeStartIndices[i]); indexData.Add(capStartIndices[i]); indexData.Add(capStartIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[i]); indexData.Add(capStartIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[(i + 1) % steps]); // create end cap polys indexData.Add(tubeEndIndices[i]); indexData.Add(capEndIndices[i]); indexData.Add(capEndIndices[(i + 1) % steps]); indexData.Add(tubeEndIndices[i]); indexData.Add(capEndIndices[(i + 1) % steps]); indexData.Add(tubeEndIndices[(i + 1) % steps]); // create start tip polys indexData.Add(tipStartIndex); indexData.Add(capStartIndices[i]); indexData.Add(capStartIndices[(i + 1) % steps]); // create end tip polys indexData.Add(tipEndIndex); indexData.Add(capEndIndices[i]); indexData.Add(capEndIndices[(i + 1) % steps]); } }
public abstract void CreateRender3DData(VectorPOD<ColorVertexData> colorVertexData, VectorPOD<uint> indexData, Affine transform, double layerScale, RenderType renderType);
private void CreateRenderData(Mesh meshToBuildListFor) { subMeshs = new List<SubTriangleMesh>(); SubTriangleMesh currentSubMesh = null; VectorPOD<VertexTextureData> textureData = new VectorPOD<VertexTextureData>(); VectorPOD<VertexNormalData> normalData = new VectorPOD<VertexNormalData>(); VectorPOD<VertexPositionData> positionData = new VectorPOD<VertexPositionData>(); // first make sure all the textures are created foreach (Face face in meshToBuildListFor.Faces) { ImageBuffer faceTexture = face.GetTexture(0); if (faceTexture != null) { ImageGlPlugin.GetImageGlPlugin(faceTexture, true); } // don't compare the data of the texture but rather if they are just the same object if (subMeshs.Count == 0 || (object)subMeshs[subMeshs.Count - 1].texture != (object)faceTexture) { SubTriangleMesh newSubMesh = new SubTriangleMesh(); newSubMesh.texture = faceTexture; subMeshs.Add(newSubMesh); currentSubMesh = subMeshs[subMeshs.Count - 1]; textureData = currentSubMesh.textrueData; normalData = currentSubMesh.normalData; positionData = currentSubMesh.positionData; } Vector2[] textureUV = new Vector2[2]; Vector3[] position = new Vector3[2]; int vertexIndex = 0; foreach (FaceEdge faceEdge in face.FaceEdges()) { if (vertexIndex < 2) { textureUV[vertexIndex] = faceEdge.GetUVs(0); position[vertexIndex] = faceEdge.firstVertex.Position; } else { VertexTextureData tempTexture; VertexNormalData tempNormal; VertexPositionData tempPosition; tempTexture.textureU = (float)textureUV[0].x; tempTexture.textureV = (float)textureUV[0].y; tempNormal.normalX = (float)face.normal.x; tempNormal.normalY = (float)face.normal.y; tempNormal.normalZ = (float)face.normal.z; tempPosition.positionX = (float)position[0].x; tempPosition.positionY = (float)position[0].y; tempPosition.positionZ = (float)position[0].z; textureData.Add(tempTexture); normalData.Add(tempNormal); positionData.Add(tempPosition); tempTexture.textureU = (float)textureUV[1].x; tempTexture.textureV = (float)textureUV[1].y; tempNormal.normalX = (float)face.normal.x; tempNormal.normalY = (float)face.normal.y; tempNormal.normalZ = (float)face.normal.z; tempPosition.positionX = (float)position[1].x; tempPosition.positionY = (float)position[1].y; tempPosition.positionZ = (float)position[1].z; textureData.Add(tempTexture); normalData.Add(tempNormal); positionData.Add(tempPosition); Vector2 textureUV2 = faceEdge.GetUVs(0); Vector3 position2 = faceEdge.firstVertex.Position; tempTexture.textureU = (float)textureUV2.x; tempTexture.textureV = (float)textureUV2.y; tempNormal.normalX = (float)face.normal.x; tempNormal.normalY = (float)face.normal.y; tempNormal.normalZ = (float)face.normal.z; tempPosition.positionX = (float)position2.x; tempPosition.positionY = (float)position2.y; tempPosition.positionZ = (float)position2.z; textureData.Add(tempTexture); normalData.Add(tempNormal); positionData.Add(tempPosition); textureUV[1] = faceEdge.GetUVs(0); position[1] = faceEdge.firstVertex.Position; } vertexIndex++; } } }
private static void CreateVBOForSubMesh(VectorPOD<TriangleVertexData> vertexDatas, SubTriangleMesh currentSubMesh) { #if USE_VBO currentSubMesh.count = vertexDatas.Count; currentSubMesh.vboHandle = GL.GenBuffer(); GL.BindBuffer(BufferTarget.ArrayBuffer, currentSubMesh.vboHandle); GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(currentSubMesh.count * VertexData.Stride), vertexDatas.Array, BufferUsageHint.StaticDraw); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); #endif }
public VectorPODRangeAdaptor(VectorPOD <uint> array, uint start, uint size) { m_array = (array); m_start = (start); m_size = (size); }
private void AllocateCellsIfRequired() { if (m_cells == null || (m_num_used_cells + 1) >= m_cells.Capacity()) { if (m_num_used_cells >= (int)ECellBlockScale.Limit) { return; } uint new_num_allocated_cells = m_num_used_cells + (uint)ECellBlockScale.Size; VectorPOD<AntiAliasingCell> new_cells = new VectorPOD<AntiAliasingCell>(new_num_allocated_cells); if (m_cells != null) { new_cells.CopyFrom(m_cells); } m_cells = new_cells; } }
public curve3_div() { m_points = new VectorPOD<Vector2>(); m_approximation_scale = (1.0); m_angle_tolerance = (0.0); m_count = (0); }
public abstract void CreateRender3DData(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, GCodeRenderInfo renderInfo);
public Curve4Div() { m_points = new VectorPOD<PointD>(); m_approximation_scale=(1.0); m_angle_tolerance=(0.0); m_cusp_limit=(0.0); m_count=(0); }
static public void CreateCylinder(VectorPOD <ColorVertexData> colorVertexData, VectorPOD <int> indexData, Vector3 startPos, Vector3 endPos, double radius, int steps, RGBA_Bytes color, double layerHeight) { Vector3 direction = endPos - startPos; Vector3 directionNormal = direction.GetNormal(); Vector3 startSweepDirection = Vector3.GetPerpendicular(startPos, endPos).GetNormal(); int[] tubeStartIndices = new int[steps]; int[] tubeEndIndices = new int[steps]; int[] capStartIndices = new int[steps]; int[] capEndIndices = new int[steps]; double halfHeight = layerHeight / 2 + (layerHeight * .1); double halfWidth = (radius * radius) / halfHeight; double zScale = halfHeight / radius; double xScale = halfWidth / radius; Vector3 scale = new Vector3(xScale, xScale, zScale); for (int i = 0; i < steps; i++) { // create tube ends verts Vector3 tubeNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); Vector3 offset = Vector3.Transform(startSweepDirection * radius, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); offset *= scale; Vector3 tubeStart = startPos + offset; tubeStartIndices[i] = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(tubeStart, tubeNormal, color)); Vector3 tubeEnd = endPos + offset; tubeEndIndices[i] = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(tubeEnd, tubeNormal, color)); // create cap verts Vector3 rotateAngle = Vector3.Cross(direction, startSweepDirection); Vector3 capStartNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(rotateAngle, MathHelper.Tau / 8)); capStartNormal = Vector3.Transform(capStartNormal, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); capStartNormal = (capStartNormal * scale).GetNormal(); Vector3 capStartOffset = capStartNormal * radius; capStartOffset *= scale; Vector3 capStart = startPos + capStartOffset; capStartIndices[i] = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(capStart, capStartNormal, color)); Vector3 capEndNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(-rotateAngle, MathHelper.Tau / 8)); capEndNormal = Vector3.Transform(capEndNormal, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); capEndNormal = (capEndNormal * scale).GetNormal(); Vector3 capEndOffset = capEndNormal * radius; capEndOffset *= scale; Vector3 capEnd = endPos + capEndOffset; capEndIndices[i] = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(capEnd, capEndNormal, color)); } int tipStartIndex = colorVertexData.Count; Vector3 tipOffset = directionNormal * radius; tipOffset *= scale; colorVertexData.Add(new ColorVertexData(startPos - tipOffset, -directionNormal, color)); int tipEndIndex = colorVertexData.Count; colorVertexData.Add(new ColorVertexData(endPos + tipOffset, directionNormal, color)); for (int i = 0; i < steps; i++) { // create tube polys indexData.Add(tubeStartIndices[i]); indexData.Add(tubeEndIndices[i]); indexData.Add(tubeEndIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[i]); indexData.Add(tubeEndIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[(i + 1) % steps]); // create start cap polys indexData.Add(tubeStartIndices[i]); indexData.Add(capStartIndices[i]); indexData.Add(capStartIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[i]); indexData.Add(capStartIndices[(i + 1) % steps]); indexData.Add(tubeStartIndices[(i + 1) % steps]); // create end cap polys indexData.Add(tubeEndIndices[i]); indexData.Add(capEndIndices[i]); indexData.Add(capEndIndices[(i + 1) % steps]); indexData.Add(tubeEndIndices[i]); indexData.Add(capEndIndices[(i + 1) % steps]); indexData.Add(tubeEndIndices[(i + 1) % steps]); // create start tip polys indexData.Add(tipStartIndex); indexData.Add(capStartIndices[i]); indexData.Add(capStartIndices[(i + 1) % steps]); // create end tip polys indexData.Add(tipEndIndex); indexData.Add(capEndIndices[i]); indexData.Add(capEndIndices[(i + 1) % steps]); } }
public abstract void CreateRender3DData(VectorPOD<ColorVertexData> colorVertexData, VectorPOD<int> indexData, GCodeRenderInfo renderInfo);
public RasterizerCellsAA() { m_QSorter = new QuickSortCellAA(); m_sorted_cells = new VectorPOD<CellAA>(); m_sorted_y = new VectorPOD<sorted_y>(); m_min_x = (0x7FFFFFFF); m_min_y = (0x7FFFFFFF); m_max_x = (-0x7FFFFFFF); m_max_y = (-0x7FFFFFFF); m_sorted = (false); m_style_cell.Initial(); m_curr_cell.Initial(); }
static public void CreatePointer(VectorPOD<ColorVertexData> colorVertexData, VectorPOD<uint> indexData, Vector3 startPos, Vector3 endPos, double radius, int steps, RGBA_Bytes color) { Vector3 direction = endPos - startPos; Vector3 directionNormal = direction.GetNormal(); Vector3 startSweepDirection = Vector3.GetPerpendicular(startPos, endPos).GetNormal(); uint[] tubeStartIndices = new uint[steps]; for (int i = 0; i < steps; i++) { // create tube ends verts Vector3 tubeNormal = Vector3.Transform(startSweepDirection, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); Vector3 offset = Vector3.Transform(startSweepDirection * radius, Matrix4X4.CreateRotation(direction, MathHelper.Tau / (steps * 2) + MathHelper.Tau / (steps) * i)); Vector3 tubeStart = startPos + offset; tubeStartIndices[i] = (uint)colorVertexData.Count; colorVertexData.Add(new ColorVertexData(tubeStart, tubeNormal, color)); Vector3 tubeEnd = endPos + offset; } uint tipEndIndex = (uint)colorVertexData.Count; colorVertexData.Add(new ColorVertexData(endPos, directionNormal, color)); for (int i = 0; i < steps; i++) { // create tube polys indexData.Add(tubeStartIndices[i]); indexData.Add(tubeStartIndices[(i + 1) % steps]); indexData.Add(tipEndIndex); } }
public void Render3D(GCodeRenderInfo renderInfo) { if (layerVertexBuffer == null) { layerVertexBuffer = new List<GCodeVertexBuffer>(); layerVertexBuffer.Capacity = gCodeFileToDraw.NumChangesInZ; for (int layerIndex = 0; layerIndex < gCodeFileToDraw.NumChangesInZ; layerIndex++) { layerVertexBuffer.Add(null); featureStartIndex.Add(new List<int>()); featureEndIndex.Add(new List<int>()); } } for (int layerIndex = 0; layerIndex < gCodeFileToDraw.NumChangesInZ; layerIndex++) { CreateFeaturesForLayerIfRequired(layerIndex); } if (lastRenderType != renderInfo.CurrentRenderType) { Clear3DGCode(); lastRenderType = renderInfo.CurrentRenderType; } if (renderFeatures.Count > 0) { for (int i = renderInfo.StartLayerIndex; i < renderInfo.EndLayerIndex; i++) { // If its the first render or we change what we are trying to render then create vertex data. if (layerVertexBuffer[i] == null) { VectorPOD<ColorVertexData> colorVertexData = new VectorPOD<ColorVertexData>(); VectorPOD<int> vertexIndexArray = new VectorPOD<int>(); Create3DDataForLayer(i, colorVertexData, vertexIndexArray, renderInfo); layerVertexBuffer[i] = new GCodeVertexBuffer(); layerVertexBuffer[i].SetVertexData(colorVertexData.Array); layerVertexBuffer[i].SetIndexData(vertexIndexArray.Array); } } GL.Disable(EnableCap.Texture2D); GL.PushAttrib(AttribMask.EnableBit); GL.DisableClientState(ArrayCap.TextureCoordArray); GL.Enable(EnableCap.PolygonSmooth); if (renderInfo.EndLayerIndex - 1 > renderInfo.StartLayerIndex) { for (int i = renderInfo.StartLayerIndex; i < renderInfo.EndLayerIndex - 1; i++) { int featuresOnLayer = renderFeatures[i].Count; if (featuresOnLayer > 1) { layerVertexBuffer[i].renderRange(0, featureEndIndex[i][featuresOnLayer - 1]); } } } // draw the partial layer of end-1 from startRatio to endRatio { int layerIndex = renderInfo.EndLayerIndex - 1; int featuresOnLayer = renderFeatures[layerIndex].Count; int startFeature = (int)(featuresOnLayer * renderInfo.FeatureToStartOnRatio0To1 + .5); startFeature = Math.Max(0, Math.Min(startFeature, featuresOnLayer)); int endFeature = (int)(featuresOnLayer * renderInfo.FeatureToEndOnRatio0To1 + .5); endFeature = Math.Max(0, Math.Min(endFeature, featuresOnLayer)); // try to make sure we always draw at least one feature if (endFeature <= startFeature) { endFeature = Math.Min(startFeature + 1, featuresOnLayer); } if (startFeature >= endFeature) { // This can only happen if the sart and end are set to the last feature // Try to set the start feture to one from the end startFeature = Math.Max(endFeature - 1, 0); } if (endFeature > startFeature) { int ellementCount = featureEndIndex[layerIndex][endFeature - 1] - featureStartIndex[layerIndex][startFeature]; layerVertexBuffer[layerIndex].renderRange(featureStartIndex[layerIndex][startFeature], ellementCount); } } GL.PopAttrib(); } }
public override void CreateRender3DData(VectorPOD<ColorVertexData> colorVertexData, VectorPOD<uint> indexData, Affine transform, double layerScale, RenderType renderType) { if ((renderType & RenderType.Retractions) == RenderType.Retractions) { Vector3 position = new Vector3(this.position); if (extrusionAmount > 0) { // unretraction CreatePointer(colorVertexData, indexData, position + new Vector3(0, 0, 1.3), position + new Vector3(0, 0, .3), Radius(1), 5, RGBA_Bytes.Blue); } else { // retraction CreatePointer(colorVertexData, indexData, position + new Vector3(0, 0, .3), position + new Vector3(0, 0, 1.3), Radius(1), 5, RGBA_Bytes.Red); } } }
public override void CreateRender3DData(VectorPOD<ColorVertexData> colorVertexData, VectorPOD<uint> indexData, Affine transform, double layerScale, RenderType renderType) { if ((renderType & RenderType.Moves) == RenderType.Moves) { CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), .1, 6, GCodeRenderer.TravelColor, .2); } }
private void AllocateCellsIfRequired() { if (m_cells == null || (m_num_used_cells + 1) >= m_cells.Capacity()) { if (m_num_used_cells >= (int)cell_block_scale_e.cell_block_limit) { return; } uint new_num_allocated_cells = m_num_used_cells + (uint)cell_block_scale_e.cell_block_size; VectorPOD<CellAA> new_cells = new VectorPOD<CellAA>(new_num_allocated_cells); if (m_cells != null) { new_cells.CopyFrom(m_cells); } m_cells = new_cells; } }
public override void CreateRender3DData(VectorPOD<ColorVertexData> colorVertexData, VectorPOD<uint> indexData, Affine transform, double layerScale, RenderType renderType) { if ((renderType & RenderType.Extrusions) == RenderType.Extrusions) { double area = extrusionVolumeMm3 / ((end - start).Length); double radius = Math.Sqrt(area / Math.PI); #if false CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, GCodeRenderer.ExtrusionColor, layerHeight); #else CreateCylinder(colorVertexData, indexData, new Vector3(start), new Vector3(end), radius, 6, color, layerHeight); #endif } }
public rasterizer_cells_aa() { m_QSorter = new QuickSort_cell_aa(); m_sorted_cells = new VectorPOD<cell_aa>(); m_sorted_y = new VectorPOD<sorted_y>(); m_min_x = (0x7FFFFFFF); m_min_y = (0x7FFFFFFF); m_max_x = (-0x7FFFFFFF); m_max_y = (-0x7FFFFFFF); m_sorted = (false); m_style_cell.initial(); m_curr_cell.initial(); }
private void CreateRenderData(Mesh meshToBuildListFor, double nonPlanarAngleRequired = 0) { edgeLinesData = new VectorPOD<WireVertexData>(); // first make sure all the textures are created foreach (MeshEdge meshEdge in meshToBuildListFor.MeshEdges) { if (nonPlanarAngleRequired > 0) { if (meshEdge.GetNumFacesSharingEdge() == 2) { FaceEdge firstFaceEdge = meshEdge.firstFaceEdge; FaceEdge nextFaceEdge = meshEdge.firstFaceEdge.radialNextFaceEdge; double angle = Vector3.CalculateAngle(firstFaceEdge.containingFace.normal, nextFaceEdge.containingFace.normal); if (angle > MathHelper.Tau * .1) { edgeLinesData.Add(AddVertex(meshEdge.VertexOnEnd[0].Position, meshEdge.VertexOnEnd[1].Position)); } } else { edgeLinesData.Add(AddVertex(meshEdge.VertexOnEnd[0].Position, meshEdge.VertexOnEnd[1].Position)); } } else { edgeLinesData.Add(AddVertex(meshEdge.VertexOnEnd[0].Position, meshEdge.VertexOnEnd[1].Position)); } } }