public void MoveIfStationary(Model model) { if (DrawnLight != null && Light.Stationary) { DeletePrevious(model); // gets world direction float[] direction, position; Light.GetLightDirection(ModelOriginal.Camera.ModelViewMatrix, out direction, out position); Vector3D newDirection = new Vector3D((double)direction[0], (double)direction[1], (double)direction[2]); newDirection.Negate(); // gets start point of the new drawn light Point3D startNewPoint = (Point3D)CenterScene.Clone(); startNewPoint.TransformBy(new Translation(newDirection * (-Radius))); // draws new direction like an arrow DrawnLight = Mesh.CreateArrow(startNewPoint, newDirection, 0.2, 5, 0.6, 3, 10, Mesh.natureType.Smooth, Mesh.edgeStyleType.Free); DrawnLight.ColorMethod = colorMethodType.byEntity; DrawnLight.Color = Color.FromArgb(220, Color.Yellow); // draws name label LightName = new LeaderAndText(startNewPoint, "Light " + NumLight, new Font("Tahoma", 8.25f), Color.White, new Vector2D(0, 15)); model.Entities.Add(DrawnLight, LayerName); model.Labels.Add(LightName); } }
private void DrawSpot(out Entity drawnLight, out LeaderAndText lightName) { double distance, kl, kc, kq; kl = Light.LinearAttenuation; kc = Light.ConstantAttenuation; kq = Light.QuadraticAttenuation; // sets distance considering attenuation values of the light if (kq.CompareTo(0.0) != 0) { distance = (-kl + Math.Sqrt(kl * kl - 4 * kq * kc)) / (2 * kq); } else { distance = ((1 / 0.6) - kc) / kl; } // draws spot light like a cone drawnLight = Mesh.CreateCone(Math.Tan(Light.SpotHalfAngle) * distance, 0, distance, 10); drawnLight.ColorMethod = colorMethodType.byEntity; // Aligns the direction of spot to the light direction Transformation t = new Align3D(Plane.XY, new Plane(Light.Direction * -1)); drawnLight.Translate(0, 0, -distance); drawnLight.TransformBy(t); // translates the light spot to choosen position drawnLight.Translate(Light.Position.X, Light.Position.Y, Light.Position.Z); // draws name label lightName = new LeaderAndText(Light.Position, "Light " + NumLight, new Font("Tahoma", 8.25f), Color.White, new Vector2D(0, 15)); }
void AddDimension(Point3D pnt1, Point3D pnt2, string layer) { //////var vnormal = new Vector3D(pnt1.X - pnt2.X, pnt1.Y - pnt2.Y, pnt1.Z - pnt2.Z); ////var vnormal = new Vector3D(0, 0, pnt1.Z - pnt2.Z); ////var tplane = new Plane(vnormal); ////tplane.Origin = pnt1; //////tplane.Rotate(Math.PI / 2, vnormal); ////var textPos = new Point3D((pnt1.X + pnt2.X) / 2, (pnt1.Y + pnt2.Y) / 2, (pnt1.Z + pnt2.Z) / 2 + 10); //////OrdinateDim ad = new OrdinateDim(tplane, new Point3D(pnt1.X, pnt1.Y, pnt1.Z + 10), new Point3D(pnt2.X, pnt2.Y, pnt2.Z + 10),false, 3); ////LinearDim ad = new LinearDim(tplane, new Point3D(pnt1.X, pnt1.Y, pnt1.Z + 1), new Point3D(pnt2.X, pnt2.Y, pnt2.Z + 10), textPos, 3); //////LinearDim ad = new LinearDim(tplane, pnt1, pnt2, textPos, 3); ////model1.Entities.Add(new PlanarEntity( tplane)); ////ad.TextSuffix = " mm"; ////model1.Entities.Add(ad, layer); var line = new Line(pnt1, pnt2); line.LineWeightMethod = colorMethodType.byEntity; line.LineWeight = configs.LineWeight; model1.Entities.Add(line, layer); var textPos = new Point3D((pnt1.X + pnt2.X) / 2, (pnt1.Y + pnt2.Y) / 2, (pnt1.Z + pnt2.Z) / 2); var distance = Math.Round(Math.Sqrt(Math.Pow(pnt1.X - pnt2.X, 2) + Math.Pow(pnt1.Y - pnt2.Y, 2) + Math.Pow(pnt1.Z - pnt2.Z, 2))); LeaderAndText lbl = new LeaderAndText(textPos, distance + " mm", new Font("Tahoma", 8.25f), Color.White, new Vector2D(0, 10)); lbl.FillColor = Color.Black; lbl.Visible = false; labels.Add(lbl); //model1.Labels.Add(lbl); model1.Labels = labels; }
private void DrawPoint(out Entity drawnLight, out LeaderAndText lightName) { // draws point light like a Joint drawnLight = new Joint(Light.Position.X, Light.Position.Y, Light.Position.Z, 1, 1); drawnLight.ColorMethod = colorMethodType.byEntity; // draws name label lightName = new LeaderAndText(Light.Position + new Vector3D(0, 0, 1), "Light " + NumLight, new Font("Tahoma", 8.25f), Color.White, new Vector2D(0, 15)); }
private void DrawDirectional(out Entity drawnLight, out LeaderAndText lightName) { // sets start position of the drawn light Point3D startPoint = (Point3D)CenterScene.Clone(); startPoint.TransformBy(new Translation(Light.Direction * (-Radius))); // draws directional light like an arrow drawnLight = Mesh.CreateArrow(startPoint, Light.Direction, 0.2, 5, 0.6, 3, 10, Mesh.natureType.Smooth, Mesh.edgeStyleType.Free); drawnLight.ColorMethod = colorMethodType.byEntity; // draws name label lightName = new LeaderAndText(startPoint + new Vector3D(0, 0, 0.2), "Light " + NumLight, new Font("Tahoma", 8.25f), Color.White, new Vector2D(0, 15)); }
void AddDimension(Point3D pnt1, Point3D pnt2, string layer) { var line = new Line(pnt1, pnt2); line.LineWeightMethod = colorMethodType.byEntity; line.LineWeight = configs.LineWeight; ViewModel.Entities.Add(line, layer); var textPos = new Point3D((pnt1.X + pnt2.X) / 2, (pnt1.Y + pnt2.Y) / 2, (pnt1.Z + pnt2.Z) / 2); var distance = Math.Round(Math.Sqrt(Math.Pow(pnt1.X - pnt2.X, 2) + Math.Pow(pnt1.Y - pnt2.Y, 2) + Math.Pow(pnt1.Z - pnt2.Z, 2))); LeaderAndText lbl = new LeaderAndText(textPos, distance + " mm", new Font("Tahoma", 8.25f), Color.White, new Vector2D(0, 10)); lbl.FillColor = Color.Black; labels.Add(lbl); }
protected override void OnContentRendered(EventArgs e) { model1.AutoHideLabels = true; model1.GetGrid().AutoSize = true; model1.GetGrid().Step = 100; string concreteMatName = "Concrete"; string steelMatName = "Blue steel"; model1.Materials.Add(new Material(concreteMatName, System.Drawing.Color.FromArgb(25, 25, 25), System.Drawing.Color.LightGray, System.Drawing.Color.FromArgb(31, 31, 31), .05f, 0)); model1.Materials.Add(new Material(steelMatName, System.Drawing.Color.RoyalBlue)); // square column block Block b = new Block("squareCol"); // creates a gray box Mesh m1 = Mesh.CreateBox(30, 30, 270); m1.ColorMethod = colorMethodType.byEntity; m1.Color = System.Drawing.Color.Gray; m1.MaterialName = concreteMatName; // adds it to the block b.Entities.Add(m1); // creates a new black polyline LinearPath steel = new LinearPath(); steel.Vertices = new Point3D[8]; steel.Vertices[0] = new Point3D(4, 4, -20); steel.Vertices[1] = new Point3D(4, 4, 290); steel.Vertices[2] = new Point3D(4, 26, 290); steel.Vertices[3] = new Point3D(4, 26, -20); steel.Vertices[4] = new Point3D(26, 26, -20); steel.Vertices[5] = new Point3D(26, 26, 290); steel.Vertices[6] = new Point3D(26, 4, 290); steel.Vertices[7] = new Point3D(26, 4, -20); steel.ColorMethod = colorMethodType.byEntity; steel.Color = System.Drawing.Color.Black; // adds it to the block b.Entities.Add(steel); // creates a price tag devDept.Eyeshot.Entities.Attribute at = new devDept.Eyeshot.Entities.Attribute(new Point3D(0, -15), "Price", "$25,000", 10); // adds it to the block b.Entities.Add(at); // adds the block to the master block dictionary model1.Blocks.Add(b); // inserts the "SquareCol" block many times: this is a HUGE memory and graphic resources saving for big models BlockReference reference; for (int k = 0; k < 4; k++) { for (int j = 0; j < 5; j++) { for (int i = 0; i < 5; i++) { if (i < 2 && j < 2) { System.Diagnostics.Debug.WriteLine("No columns here"); } else { reference = new BlockReference(i * 500, j * 400, k * 300, "squareCol", 1, 1, 1, 0); // defines a different price for each one reference.Attributes.Add("Price", "$" + i + ",000"); model1.Entities.Add(reference); } } } } // again as above b = new Block("floor"); double width = 2030; double depth = 1630; double dimA = 1000; double dimB = 800; Point2D[] outerPoints = new Point2D[7]; outerPoints[0] = new Point2D(0, dimB); outerPoints[1] = new Point2D(dimA, dimB); outerPoints[2] = new Point2D(dimA, 0); outerPoints[3] = new Point2D(width, 0); outerPoints[4] = new Point2D(width, depth); outerPoints[5] = new Point2D(0, depth); outerPoints[6] = (Point2D)outerPoints[0].Clone(); LinearPath outer = new LinearPath(Plane.XY, outerPoints); Point2D[] innerPoints = new Point2D[5]; innerPoints[0] = new Point2D(1530, 800); innerPoints[1] = new Point2D(1530, 950); innerPoints[2] = new Point2D(1650, 950); innerPoints[3] = new Point2D(1650, 800); innerPoints[4] = (Point2D)innerPoints[0].Clone(); LinearPath inner = new LinearPath(Plane.XY, innerPoints); devDept.Eyeshot.Entities.Region reg = new devDept.Eyeshot.Entities.Region(outer, inner); Mesh m2 = reg.ExtrudeAsMesh(30, 0.1, Mesh.natureType.Plain); m2.ColorMethod = colorMethodType.byEntity; m2.Color = System.Drawing.Color.White; m2.MaterialName = concreteMatName; b.Entities.Add(m2); model1.Blocks.Add(b); for (int i = 0; i < 4; i++) { reference = new BlockReference(0, 0, 270 + i * 300, "floor", 1, 1, 1, 0); model1.Entities.Add(reference); } string brickMatName = "Wall bricks"; model1.Materials.Add(new Material(brickMatName, new Bitmap("../../../../../../dataset/Assets/Textures/Bricks.jpg"))); b = new Block("brickWall"); Mesh rm = Mesh.CreateBox(470, 30, 270, Mesh.natureType.RichPlain); rm.ApplyMaterial(brickMatName, textureMappingType.Cubic, 1.5, 1.5); rm.ColorMethod = colorMethodType.byEntity; rm.Color = System.Drawing.Color.Chocolate; b.Entities.Add(rm); model1.Blocks.Add(b); for (int j = 1; j < 4; j++) { for (int i = 0; i < 2; i++) { reference = new BlockReference(1030 + i * 500, 0, j * 300, "brickWall", 1, 1, 1, 0); model1.Entities.Add(reference); } } // Cylindrical column b = new Block("CylindricalCol"); Mesh m3 = Mesh.CreateCylinder(20, 270, 32, Mesh.natureType.Smooth); m3.ColorMethod = colorMethodType.byEntity; m3.Color = System.Drawing.Color.RoyalBlue; m3.MaterialName = steelMatName; b.Entities.Add(m3); model1.Blocks.Add(b); for (int j = 0; j < 2; j++) { for (int i = 0; i < 3; i++) { reference = new BlockReference(100 + i * 400, 115 + j * 200, 0, "CylindricalCol", 1, 1, 1, 0); model1.Entities.Add(reference); } } // Roof (not a block this time) Mesh roof = Mesh.CreateBox(880, 280, 30); // Edits vertices to add a slope roof.Vertices[4].Z = 15; roof.Vertices[7].Z = 15; roof.Translate(60, 75, 270); model1.Entities.Add(roof, System.Drawing.Color.DimGray); // Labels LeaderAndText lat = new LeaderAndText(new Point3D(0, 800, 1200), "Height = 12 m", new System.Drawing.Font("Tahoma", 8.25f), System.Drawing.Color.White, new Vector2D(0, 20)); lat.FillColor = System.Drawing.Color.Black; model1.Labels.Add(lat); LeaderAndText ff; ff = new LeaderAndText(new Point3D(1000, 1000, 300), "First floor", new System.Drawing.Font("Tahoma", 8.25f), System.Drawing.Color.White, new Vector2D(0, 10)); ff.FillColor = System.Drawing.Color.Red; ff.Alignment = System.Drawing.ContentAlignment.BottomCenter; model1.Labels.Add(ff); // fits the model in the viewport model1.ZoomFit(); // refresh the viewport model1.Invalidate(); base.OnContentRendered(e); }
private void RebuildChair() { string currentMatName = (currentFrameMaterial == materialEnum.Cherry) ? cherryMatName : mapleMatName; model1.Entities.Clear(); model1.Labels.Clear(); double legDepth = 3; double legWidth = 3; double legHeight = 56.5; double seatDepth = 29; double seatWidth = sizeTrackBar.Value; double seatHeight = 1.6; double seatY = 27.4; // // Build the legs // Mesh leg1 = MakeBox(legWidth, legDepth, legHeight); Mesh leg4 = (Mesh)leg1.Clone(); Mesh leg2 = MakeBox(legWidth, legDepth, seatY); Mesh leg3 = (Mesh)leg2.Clone(); leg2.Translate(seatDepth - legDepth, 0, 0); leg3.Translate(seatDepth - legDepth, seatWidth - legWidth, 0); leg4.Translate(0, seatWidth - legWidth, 0); AddEntityWithMaterial(ref leg1, currentMatName); AddEntityWithMaterial(ref leg2, currentMatName); AddEntityWithMaterial(ref leg3, currentMatName); AddEntityWithMaterial(ref leg4, currentMatName); // // Build the seat // double dx = 0.3; double dy = 0.2; double delta = 0.1; double seatPartDepth = 4.5; double seatPartOffset = 0.5; Point3D[] seatFirstPartPoints = { new Point3D(legDepth + delta, 0, 0), new Point3D(seatPartDepth, 0, 0), new Point3D(seatPartDepth, seatWidth, 0), new Point3D(legDepth + delta, seatWidth, 0), new Point3D(legDepth + delta, seatWidth - legWidth + dy, 0), new Point3D(-dx, seatWidth - legWidth, 0), new Point3D(-dx, legWidth, 0), new Point3D(legDepth + delta, legWidth + dy, 0), new Point3D(legDepth + delta, 0, 0) }; Region seatFirstPart = new Region(new LinearPath(seatFirstPartPoints)); Mesh seatPart0 = seatFirstPart.ExtrudeAsMesh(new Vector3D(0, 0, seatHeight), 0.01, Mesh.natureType.Smooth); seatPart0.Translate(0, -dy, seatY); Mesh seatPart1 = MakeBox(seatWidth + 2 * dx, seatPartDepth, seatHeight); seatPart1.Translate(seatPartDepth + seatPartOffset, -dy, seatY); Mesh seatPart2 = (Mesh)seatPart1.Clone(); seatPart2.Translate(seatPartDepth + seatPartOffset, 0, 0); Mesh seatPart3 = (Mesh)seatPart2.Clone(); seatPart3.Translate(seatPartDepth + seatPartOffset, 0, 0); Mesh seatPart4 = (Mesh)seatPart3.Clone(); seatPart4.Translate(seatPartDepth + seatPartOffset, 0, 0); Mesh seatPart5 = (Mesh)seatPart4.Clone(); seatPart5.Translate(seatPartDepth + seatPartOffset, 0, 0); model1.Entities.Add(seatPart0, plasticMatName); model1.Entities.Add(seatPart1, plasticMatName); model1.Entities.Add(seatPart2, plasticMatName); model1.Entities.Add(seatPart3, plasticMatName); model1.Entities.Add(seatPart4, plasticMatName); model1.Entities.Add(seatPart5, plasticMatName); // // Build the bars under the seat // double underSeatXBarWidth = legWidth * 0.8; double underSeatXBarDepth = seatDepth - 2 * legDepth; double underSeatXBarHeight = 5.0; double underSeatYBarWidth = seatWidth - 2 * legWidth; double underSeatYBarDepth = legDepth * 0.8; double underSeatYBarHeight = underSeatXBarHeight; Mesh barUnderSeatLeft = MakeBox(underSeatXBarWidth, underSeatXBarDepth, underSeatXBarHeight); barUnderSeatLeft.Translate(legDepth, (legWidth - underSeatXBarWidth) / 2, seatY - underSeatXBarHeight); Mesh barUnderSeatRight = (Mesh)barUnderSeatLeft.Clone(); barUnderSeatRight.Translate(0, seatWidth - legWidth, 0); Mesh barUnderSeatBack = MakeBox(seatWidth - 2 * legWidth, legDepth * 0.8, underSeatYBarHeight); barUnderSeatBack.Translate((legDepth - underSeatYBarDepth) / 2, legWidth, seatY - underSeatYBarHeight); Mesh barUnderSeatFront = (Mesh)barUnderSeatBack.Clone(); barUnderSeatFront.Translate(seatDepth - legDepth, 0, 0); AddEntityWithMaterial(ref barUnderSeatLeft, currentMatName); AddEntityWithMaterial(ref barUnderSeatRight, currentMatName); AddEntityWithMaterial(ref barUnderSeatFront, currentMatName); AddEntityWithMaterial(ref barUnderSeatBack, currentMatName); // // Build the two cylinders on the sides // double CylinderRadius = legWidth / 3; double cylinderY = 14.5; Mesh leftCylinder = MakeCylinder(CylinderRadius, seatDepth - 2 * legDepth, 16); leftCylinder.ApplyMaterial(currentMatName, textureMappingType.Cylindrical, .25, 1); leftCylinder.Rotate(Math.PI / 2, new Vector3D(0, 1, 0)); leftCylinder.Translate(legDepth, legWidth / 2, cylinderY); model1.Entities.Add(leftCylinder); Mesh rightCylinder = (Mesh)leftCylinder.Clone(); rightCylinder.Translate(0, seatWidth - legWidth, 0); model1.Entities.Add(rightCylinder); // // Build the chair back // double chairBackHorizHeight = 4; double chairBackHorizDepth = 2; double horizHeight1 = seatY + seatHeight + 7; Mesh chairBackHorizontal1 = MakeBox(seatWidth - 2 * legWidth, chairBackHorizDepth, chairBackHorizHeight); chairBackHorizontal1.Translate((legDepth - chairBackHorizDepth) / 2.0, legWidth, horizHeight1); double cylinderHeight = 12; double horizHeight2 = cylinderHeight + chairBackHorizHeight; Mesh chairBackHorizontal2 = (Mesh)chairBackHorizontal1.Clone(); chairBackHorizontal2.Translate(0, 0, horizHeight2); AddEntityWithMaterial(ref chairBackHorizontal1, currentMatName); AddEntityWithMaterial(ref chairBackHorizontal2, currentMatName); double chairBackCylinderRadius = chairBackHorizDepth / 4.0; double chairBackCylinderHeight = horizHeight2 - chairBackHorizHeight; Mesh chairBackCylinder = MakeCylinder(chairBackCylinderRadius, chairBackCylinderHeight, 16); chairBackCylinder.Translate(legDepth / 2.0, legWidth, horizHeight1 + chairBackHorizHeight); double chairBackWidth = seatWidth - 2 * legWidth; double cylinderOffset = 7; int nCylinders = (int)(chairBackWidth / cylinderOffset); double offset = (chairBackWidth - (nCylinders + 1) * cylinderOffset) / 2.0; offset += cylinderOffset; for (int i = 0; i < nCylinders; i++, offset += cylinderOffset) { Mesh cyl = (Mesh)chairBackCylinder.Clone(); cyl.ApplyMaterial(currentMatName, textureMappingType.Cylindrical, .25, 1); cyl.Translate(0, offset, 0); model1.Entities.Add(cyl); } // // Add the linear dimension // Point3D dimCorner = new Point3D(0, 0, legHeight); Plane myPlane = Plane.YZ; myPlane.Origin = dimCorner; LinearDim ad = new LinearDim(myPlane, new Point3D(0, 0, legHeight + 1), new Point3D(0, seatWidth, legHeight + 1), new Point3D(seatDepth + 10, seatWidth / 2, legHeight + 10), 3); ad.TextSuffix = " cm"; model1.Entities.Add(ad); model1.Entities.UpdateBoundingBox(); // // Update extents // widthTextBox.Text = model1.Entities.BoxSize.X.ToString("f2") + " cm"; depthTextBox.Text = model1.Entities.BoxSize.Y.ToString("f2") + " cm"; heightTextBox.Text = model1.Entities.BoxSize.Z.ToString("f2") + " cm"; // // Update weight // double totalWeight = CalcWeight(); weightTextBox.Text = totalWeight.ToString("f2") + " kg"; // // Product ID label // devDept.Eyeshot.Labels.LeaderAndText prodIdLabel = new LeaderAndText(seatDepth / 2, seatWidth, 25, "Product ID goes here", new Font("Tahoma", 8.25f), System.Drawing.Color.Black, new Vector2D(20, 0)); model1.Labels.Add(prodIdLabel); }