void CreateMeasureCube(Vector2 startPoint, string text, double width, double height) { //outerbox var cubeModel = new STLModel3D(TypeObject.None, false); //cubeModel = (new Cube(12.8f, 8f, 5f)).AsSTLModel3D(Managers.MaterialManager.DefaultMaterial); var outerPath = new Polygon(new PolygonPoint(-(width / 2), -(height / 2)), new PolygonPoint((width / 2), -(height / 2)), new PolygonPoint((width / 2), (height / 2)), new PolygonPoint(-(width / 2), (height / 2))); var textAsPolygonSet = new PolygonSet(); var letterPolygonsTop = FontTessellationEngine.ConvertStringToTrianglesWithOuterPath(text, FontStyle.Bold, outerPath, out textAsPolygonSet); outerPath = new Polygon(new PolygonPoint(-(width / 2), -(height / 2)), new PolygonPoint((width / 2), -(height / 2)), new PolygonPoint((width / 2), (height / 2)), new PolygonPoint(-(width / 2), (height / 2))); var letterPolygonsBottom = FontTessellationEngine.ConvertStringToTrianglesWithOuterPath(text, FontStyle.Bold, outerPath, out textAsPolygonSet); foreach (var t in letterPolygonsBottom[0]) { t.Flip(); } cubeModel.Triangles = letterPolygonsTop; foreach (var t in letterPolygonsTop[0]) { t.Vectors[0].Position += new Vector3Class(0, 0, 5); t.Vectors[1].Position += new Vector3Class(0, 0, 5); t.Vectors[2].Position += new Vector3Class(0, 0, 5); } cubeModel.Triangles[0].AddRange(letterPolygonsBottom[0]); cubeModel._scaleFactorX = cubeModel._scaleFactorY = cubeModel._scaleFactorZ = 1; cubeModel.Scale(0.1f, 0.1f, 1f, Events.ScaleEventArgs.TypeAxis.ALL, true, true); CreateExtrudeTriangles(cubeModel, outerPath.Points); foreach (var polygon in outerPath.Holes) { CreateExtrudeTriangles(cubeModel, polygon.Points, true); foreach (var holePolygon in polygon.Holes) { CreateExtrudeTriangles(cubeModel, holePolygon.Points, true); } } //center triangle cubeModel.UpdateBoundries(); cubeModel.UpdateDefaultCenter(); cubeModel.Triangles.UpdateWithMoveTranslation(new Vector3Class(startPoint.X, startPoint.Y, 0) - new Vector3Class(cubeModel.LeftPoint, cubeModel.BackPoint, -0.2f)); //orient model properly cubeModel.HorizontalMirror(false, true); cubeModel.Rotate(0, 0, 180, Events.RotationEventArgs.TypeAxis.Z); cubeModel.UpdateTrianglesMinMaxZ(); this.Triangles[0].AddRange(cubeModel.Triangles[0]); }
private STLModel3D CalcOrientationGizmoPart(float sizeCorrection, SideSelectionType firstSideSelectionType, SideSelectionType secondSideSelectionType, SideSelectionType thirdSideSelectionType, SideSelectionType cornerSelectionType) { var defaultSize = 5f * sizeCorrection; var defaultOffsetSize = defaultSize - (1f * sizeCorrection); var defaultOffsetSizeHalf = defaultSize + ((1f * sizeCorrection) / 2f); var result = new STLModel3D(); result.Triangles = new TriangleInfoList(); var cubePoints = new List <Vector3Class>(); cubePoints.Add(new Vector3Class(0, 0, defaultOffsetSizeHalf)); //top cubePoints.Add(new Vector3Class(0, -defaultOffsetSize, defaultOffsetSizeHalf)); //top cubePoints.Add(new Vector3Class(defaultOffsetSize, -defaultOffsetSize, defaultOffsetSizeHalf)); //top cubePoints.Add(new Vector3Class(defaultOffsetSize, 0, defaultOffsetSizeHalf)); //top cubePoints.Add(new Vector3Class(0, -defaultOffsetSize, defaultOffsetSizeHalf)); //top cubePoints.Add(new Vector3Class(0, -defaultSize, defaultOffsetSizeHalf)); //top cubePoints.Add(new Vector3Class(defaultOffsetSize, -defaultSize, defaultOffsetSizeHalf)); //top cubePoints.Add(new Vector3Class(defaultOffsetSize, -defaultOffsetSize, defaultOffsetSizeHalf)); //top cubePoints.Add(new Vector3Class(defaultOffsetSize, 0, defaultOffsetSizeHalf)); //top cubePoints.Add(new Vector3Class(defaultOffsetSize, -defaultOffsetSize, defaultOffsetSizeHalf)); //top cubePoints.Add(new Vector3Class(defaultSize, -defaultOffsetSize, defaultOffsetSizeHalf)); //top cubePoints.Add(new Vector3Class(defaultSize, 0, defaultOffsetSizeHalf)); //top cubePoints.Add(new Vector3Class(defaultOffsetSize, -defaultOffsetSize, defaultOffsetSizeHalf)); //top cubePoints.Add(new Vector3Class(defaultOffsetSize, -defaultSize, defaultOffsetSizeHalf)); //top cubePoints.Add(new Vector3Class(defaultSize, -defaultOffsetSize, defaultOffsetSizeHalf)); //top var cubeColor = new Byte4Class((byte)(int)firstSideSelectionType, 57, 64, 69); if (firstSideSelectionType == SelectedSide) { cubeColor = new Byte4Class((byte)(int)firstSideSelectionType, 255, 0, 0); } else if (firstSideSelectionType == HighlightedSide) { cubeColor = new Byte4Class((byte)(int)firstSideSelectionType, 255, 255, 255); } var cubeIndexes = new List <short[]> { new short[] { 0, 1, 2 }, //front new short[] { 2, 3, 0 }, //front new short[] { 4, 5, 6 }, //front new short[] { 6, 7, 4 }, //front new short[] { 8, 9, 10 }, //front new short[] { 10, 11, 8 }, //front new short[] { 12, 13, 14 }, //front }; var xAngles = new List <int>() { 0, -90 }; foreach (var xAngle in xAngles) { if (xAngle == -90) { if (secondSideSelectionType != SideSelectionType.Bottom) { cubeColor = new Byte4Class((byte)(int)secondSideSelectionType, 57, 64, 69); } else { cubeColor = new Byte4Class((byte)(int)secondSideSelectionType, 128, 128, 128); } if (secondSideSelectionType == SelectedSide) { cubeColor = new Byte4Class((byte)(int)secondSideSelectionType, 255, 0, 0); } else if (secondSideSelectionType == HighlightedSide) { cubeColor = new Byte4Class((byte)(int)secondSideSelectionType, 255, 255, 255); } } var tList = new List <Triangle>(); var stlModel = new STLModel3D(); stlModel.Triangles = new TriangleInfoList(); foreach (var cubeIndex in cubeIndexes) { var triangle = new Triangle(); triangle.Vectors[0].Position = cubePoints[cubeIndex[0]]; triangle.Vectors[1].Position = cubePoints[cubeIndex[1]]; triangle.Vectors[2].Position = cubePoints[cubeIndex[2]]; triangle.Vectors[0].Color = triangle.Vectors[1].Color = triangle.Vectors[2].Color = cubeColor; triangle.CalcNormal(); tList.Add(triangle); if (xAngle == -90) { triangle.Flip(true); } } stlModel.Triangles[0].AddRange(tList); stlModel.Rotate(xAngle, 0, 0, RotationEventArgs.TypeAxis.X, updateFaceColor: false); if (xAngle == -90) { stlModel.MoveModelWithTranslationZ(new Vector3Class(0, -(2 * defaultOffsetSizeHalf), 0)); } result.Triangles[0].AddRange(stlModel.Triangles[0]); } var tList2 = new List <Triangle>(); var stlModel2 = new STLModel3D(); stlModel2.Triangles = new TriangleInfoList(); cubeColor = new Byte4Class((byte)(int)thirdSideSelectionType, 57, 64, 69); if (thirdSideSelectionType == SelectedSide) { cubeColor = new Byte4Class((byte)(int)thirdSideSelectionType, 255, 0, 0); } else if (thirdSideSelectionType == HighlightedSide) { cubeColor = new Byte4Class((byte)(int)thirdSideSelectionType, 255, 255, 255); } foreach (var cubeIndex in cubeIndexes) { var triangle = new Triangle(); triangle.Vectors[0].Position = cubePoints[cubeIndex[0]]; triangle.Vectors[1].Position = cubePoints[cubeIndex[1]]; triangle.Vectors[2].Position = cubePoints[cubeIndex[2]]; triangle.Vectors[0].Color = triangle.Vectors[1].Color = triangle.Vectors[2].Color = cubeColor; triangle.Flip(true); tList2.Add(triangle); } stlModel2.Triangles[0].AddRange(tList2); stlModel2.Rotate(0, -90, 0, RotationEventArgs.TypeAxis.Y, updateFaceColor: false); stlModel2.MoveModelWithTranslationZ(new Vector3Class((2 * defaultOffsetSizeHalf), 0, 0)); result.Triangles[0].AddRange(stlModel2.Triangles[0]); //highlight parts var highlightParts = new List <Vector3Class>(); highlightParts.Add(new Vector3Class(0, -defaultSize, defaultOffsetSizeHalf)); highlightParts.Add(new Vector3Class(0, -defaultOffsetSizeHalf, defaultSize)); highlightParts.Add(new Vector3Class(defaultOffsetSize, -defaultOffsetSizeHalf, defaultSize)); highlightParts.Add(new Vector3Class(defaultOffsetSize, -defaultOffsetSizeHalf, defaultSize)); highlightParts.Add(new Vector3Class(defaultOffsetSize, -defaultSize, defaultOffsetSizeHalf)); highlightParts.Add(new Vector3Class(0, -defaultSize, defaultOffsetSizeHalf)); highlightParts.Add(new Vector3Class(defaultSize, -defaultOffsetSize, defaultOffsetSizeHalf)); highlightParts.Add(new Vector3Class(defaultOffsetSizeHalf, -defaultOffsetSize, defaultSize)); highlightParts.Add(new Vector3Class(defaultOffsetSizeHalf, 0f, defaultSize)); highlightParts.Add(new Vector3Class(defaultSize, -defaultOffsetSize, defaultOffsetSizeHalf)); highlightParts.Add(new Vector3Class(defaultOffsetSizeHalf, 0f, defaultSize)); highlightParts.Add(new Vector3Class(defaultSize, 0, defaultOffsetSizeHalf)); highlightParts.Add(new Vector3Class(defaultSize, -defaultOffsetSizeHalf, defaultOffsetSize)); highlightParts.Add(new Vector3Class(defaultSize, -defaultOffsetSizeHalf, 0f)); highlightParts.Add(new Vector3Class(defaultOffsetSizeHalf, -defaultSize, 0f)); highlightParts.Add(new Vector3Class(defaultOffsetSizeHalf, -defaultSize, 0f)); highlightParts.Add(new Vector3Class(defaultOffsetSizeHalf, -defaultSize, defaultOffsetSize)); highlightParts.Add(new Vector3Class(defaultSize, -defaultOffsetSizeHalf, defaultOffsetSize)); highlightParts.Add(new Vector3Class(defaultOffsetSize, -defaultSize, defaultOffsetSizeHalf)); highlightParts.Add(new Vector3Class(defaultOffsetSize, -defaultOffsetSizeHalf, defaultSize)); highlightParts.Add(new Vector3Class(defaultSize, -defaultOffsetSizeHalf, defaultOffsetSize)); highlightParts.Add(new Vector3Class(defaultOffsetSize, -defaultSize, defaultOffsetSizeHalf)); highlightParts.Add(new Vector3Class(defaultSize, -defaultOffsetSizeHalf, defaultOffsetSize)); highlightParts.Add(new Vector3Class(defaultSize, -defaultOffsetSize, defaultOffsetSizeHalf)); highlightParts.Add(new Vector3Class(defaultSize, -defaultOffsetSize, defaultOffsetSizeHalf)); highlightParts.Add(new Vector3Class(defaultSize, -defaultOffsetSizeHalf, defaultOffsetSize)); highlightParts.Add(new Vector3Class(defaultOffsetSizeHalf, -defaultOffsetSize, defaultSize)); highlightParts.Add(new Vector3Class(defaultSize, -defaultOffsetSizeHalf, defaultOffsetSize)); highlightParts.Add(new Vector3Class(defaultOffsetSizeHalf, -defaultSize, defaultOffsetSize)); highlightParts.Add(new Vector3Class(defaultOffsetSizeHalf, -defaultOffsetSize, defaultSize)); var highlightColor = new Byte4Class((byte)(int)cornerSelectionType, 0, 0, 0); if (cornerSelectionType == SelectedSide) { highlightColor = new Byte4Class((byte)(int)cornerSelectionType, 255, 0, 0); } else if (cornerSelectionType == HighlightedSide) { highlightColor = new Byte4Class((byte)(int)cornerSelectionType, 255, 255, 255); } for (var highlightIndex = 0; highlightIndex < highlightParts.Count; highlightIndex += 3) { var triangle = new Triangle(); triangle.Vectors[0].Position = highlightParts[highlightIndex]; triangle.Vectors[1].Position = highlightParts[highlightIndex + 1]; triangle.Vectors[2].Position = highlightParts[highlightIndex + 2]; triangle.Vectors[0].Color = triangle.Vectors[1].Color = triangle.Vectors[2].Color = highlightColor; triangle.CalcNormal(); result.Triangles[0].Add(triangle); } return(result); }
internal void UpdatAngle(float innerRadius, float outerRadius, int torusSegmentCount, int torusSegmentBandCount, float angle, RotationEventArgs.TypeAxis rotationAxis) { //var selectionTorusOverlay = new Torus(innerRadius, outerRadius, torusSegmentCount, torusSegmentBandCount, angle); var selectionTorusOverlayColor = new Byte4Class(128, Properties.Settings.Default.RotationGizmoAngleSelectionOverlay.R, Properties.Settings.Default.RotationGizmoAngleSelectionOverlay.G, Properties.Settings.Default.RotationGizmoAngleSelectionOverlay.B); //foreach (var triangle in selectionTorusOverlay.Triangles[0]) //{ // triangle.Vectors[0].Color = selectionTorusOverlayColor; // triangle.Vectors[1].Color = selectionTorusOverlayColor; // triangle.Vectors[2].Color = selectionTorusOverlayColor; //} //if (angle < 0) //{ // foreach (var triangle in selectionTorusOverlay.Triangles[0]) // { // triangle.Flip(); // } //} //prepare angle infill var rotationAngleOutlinePoints = VectorHelper.GetCircleOutlinePoints(0, innerRadius, torusSegmentCount, new Vector3Class(), angle); //convert outlinepoints to triangles var rotationAngleModel = new STLModel3D(); var rotationAngleModelMirror = new STLModel3D(); rotationAngleModel.Triangles = new TriangleInfoList(); rotationAngleModelMirror.Triangles = new TriangleInfoList(); for (var rotationAngleOutlinePointIndex = 0; rotationAngleOutlinePointIndex < rotationAngleOutlinePoints.Count - 1; rotationAngleOutlinePointIndex++) { var triangle = new Triangle(); triangle.Vectors[0].Position = new Vector3Class(); triangle.Vectors[0].Color = selectionTorusOverlayColor; triangle.Vectors[1].Color = selectionTorusOverlayColor; triangle.Vectors[1].Position = rotationAngleOutlinePoints[rotationAngleOutlinePointIndex]; triangle.Vectors[2].Color = selectionTorusOverlayColor; if (rotationAngleOutlinePointIndex == rotationAngleOutlinePoints.Count - 1) { triangle.Vectors[2].Position = rotationAngleOutlinePoints[0]; } else { triangle.Vectors[2].Position = rotationAngleOutlinePoints[rotationAngleOutlinePointIndex + 1]; } triangle.CalcNormal(); rotationAngleModel.Triangles[0].Add(triangle); var flipClone = (Triangle)triangle.Clone(); flipClone.Flip(); rotationAngleModelMirror.Triangles[0].Add(flipClone); } //switch (rotationAxis) //{ // case RotationEventArgs.TypeAxis.X: // selectionTorusOverlay.Rotate(90, 0, 0, RotationEventArgs.TypeAxis.X, false, false); // selectionTorusOverlay.Rotate(0, 0, 90, RotationEventArgs.TypeAxis.Z, false, false); // break; // case RotationEventArgs.TypeAxis.Y: // selectionTorusOverlay.Rotate(90, 0, 0, RotationEventArgs.TypeAxis.X, false, false); // break; //} switch (rotationAxis) { case RotationEventArgs.TypeAxis.X: // selectionTorusOverlay.Rotate(90, 0, 0, RotationEventArgs.TypeAxis.X, false, false); // selectionTorusOverlay.Rotate(0, 0, 90, RotationEventArgs.TypeAxis.Z, false, false); rotationAngleModel.Rotate(90, 0, 0, RotationEventArgs.TypeAxis.X, false, false); rotationAngleModel.Rotate(0, 0, 90, RotationEventArgs.TypeAxis.Z, false, false); rotationAngleModelMirror.Rotate(90, 0, 0, RotationEventArgs.TypeAxis.X, false, false); rotationAngleModelMirror.Rotate(0, 0, 90, RotationEventArgs.TypeAxis.Z, false, false); break; case RotationEventArgs.TypeAxis.Y: // selectionTorusOverlay.Rotate(90, 0, 0, RotationEventArgs.TypeAxis.X, false, false); rotationAngleModel.Rotate(90, 0, 0, RotationEventArgs.TypeAxis.X, false, false); rotationAngleModelMirror.Rotate(90, 0, 0, RotationEventArgs.TypeAxis.X, false, false); break; } // this.Triangles = selectionTorusOverlay.Triangles; //remove last torus triangles this.Triangles = new TriangleInfoList(); //this.Triangles[0].RemoveRange(0, torusSegmentBandCount * 2); this.Triangles[0].AddRange(rotationAngleModel.Triangles[0]); this.Triangles[0].AddRange(rotationAngleModelMirror.Triangles[0]); ////add end tag //var startTag = new Box(outerRadius * 4, 0.05f, outerRadius * 2, true); //var endTag = new Box(outerRadius * 4, 0.05f, outerRadius * 2, true); //var selectionTagColor = new Byte4Class(255,255,255,255); //var startPosition = this.Triangles[0][0].Points[2]; //var endPosition = this.Triangles[0][3560].Points[0]; //switch (rotationAxis) //{ // case RotationEventArgs.TypeAxis.X: // endTag.Rotate(90, 0, 0, RotationEventArgs.TypeAxis.X, false, false); // endTag.Rotate(0, 0, 90, RotationEventArgs.TypeAxis.Z, false, false); // endTag.UpdateDefaultCenter(); // endTag.Rotate(angle + 90, 0, 0, RotationEventArgs.TypeAxis.X, false, false); // startTag.Rotate(90, 0, 0, RotationEventArgs.TypeAxis.X, false, false); // startTag.UpdateDefaultCenter(); // startTag.Rotate(0, 0, 90, RotationEventArgs.TypeAxis.Z, false, false); // endPosition.X -= (outerRadius); // startPosition.X = endPosition.X; // break; // case RotationEventArgs.TypeAxis.Y: // endTag.Rotate(90, 0, 0, RotationEventArgs.TypeAxis.X, false, false); // endTag.Rotate(0, -angle, 0, RotationEventArgs.TypeAxis.Y, false, false); // startPosition.X -= outerRadius; // endPosition.Y += (2 * outerRadius); // startPosition.Y = endPosition.Y; // startTag.Rotate(90, 0, 0, RotationEventArgs.TypeAxis.X, false, false); // break; // case RotationEventArgs.TypeAxis.Z: // startPosition.Z = -endTag.Height / 2; // foreach (var triangle in endTag.Triangles[0]) // { // triangle.Vectors[0].Position -= new Vector3Class(0, 0, endTag.Height); // triangle.Vectors[1].Position -= new Vector3Class(0, 0, endTag.Height); // triangle.Vectors[2].Position -= new Vector3Class(0, 0, endTag.Height); // } // endTag.Rotate(0, 0, angle, RotationEventArgs.TypeAxis.Z, false, false); // break; //} //foreach (var triangle in endTag.Triangles[0]) //{ // triangle.Vectors[0].Position += endPosition; // triangle.Vectors[0].Color = selectionTagColor; // triangle.Vectors[1].Position += endPosition; // triangle.Vectors[1].Color = selectionTagColor; // triangle.Vectors[2].Position += endPosition; // triangle.Vectors[2].Color = selectionTagColor; //} //this.Triangles[0].AddRange(endTag.Triangles[0]); ////add start tag //foreach (var triangle in startTag.Triangles[0]) //{ // triangle.Vectors[0].Position += startPosition; // triangle.Vectors[0].Color = selectionTagColor; // triangle.Vectors[1].Position += startPosition; // triangle.Vectors[1].Color = selectionTagColor; // triangle.Vectors[2].Position += startPosition; // triangle.Vectors[2].Color = selectionTagColor; //} //this.Triangles[0].AddRange(startTag.Triangles[0]); //////textline ////var textLineVector = new Box(10f, 0.05f, 0.05f, false); //////textLineVector.Rotate(0, 0, angle - 30, Events.RotationEventArgs.TypeAxis.Z, true, false); ////var textLineOffsetVector = new Vector3(endTag.Triangles[0][1].Points[2].X, endTag.Triangles[0][1].Points[2].Y, 0); ////textLineOffsetVector.Scale(new Vector3(1.1f)); ////foreach (var triangle in textLineVector.Triangles[0]) ////{ //// triangle.Vectors[0].Position += new Vector3(textLineOffsetVector.X, textLineOffsetVector.Y, -outerRadius); //// triangle.Vectors[0].Color = selectionTagColor; //// triangle.Vectors[1].Position += new Vector3(textLineOffsetVector.X, textLineOffsetVector.Y, -outerRadius); //// triangle.Vectors[1].Color = selectionTagColor; //// triangle.Vectors[2].Position += new Vector3(textLineOffsetVector.X, textLineOffsetVector.Y, -outerRadius); //// triangle.Vectors[2].Color = selectionTagColor; ////} ////this.Triangles[0].AddRange(textLineVector.Triangles[0]); //////angle text ////var fontSize = 5.7f; ////var textAsTriangles = FontTessellationEngine.ConvertStringToTriangles(angle.ToString(), FontStyle.Regular, fontSize); ////var textColor = new Byte4(new[] { (byte)0, (byte)Properties.Settings.Default.SceneControlFontColor.R, (byte)Properties.Settings.Default.SceneControlFontColor.G, (byte)Properties.Settings.Default.SceneControlFontColor.B }); ////foreach (var textTriangle in textAsTriangles[0]) ////{ //// textTriangle.Vectors[0].Position += new Vector3(textLineOffsetVector.X, textLineOffsetVector.Y, -outerRadius); //// textTriangle.Vectors[0].Color = selectionTagColor; //// textTriangle.Vectors[1].Position += new Vector3(textLineOffsetVector.X, textLineOffsetVector.Y, -outerRadius); //// textTriangle.Vectors[1].Color = selectionTagColor; //// textTriangle.Vectors[2].Position += new Vector3(textLineOffsetVector.X, textLineOffsetVector.Y, -outerRadius); //// textTriangle.Vectors[2].Color = selectionTagColor; ////} ////this.Triangles[0].AddRange(textAsTriangles[0]); if (this.VBOIndexes == null) { this.BindModel(); } else { this.UpdateBinding(); } }