public override bool Run(FeatureContext context) { TopoShape box = GlobalInstance.BrepTools.MakeBox(Vector3.ZERO, Vector3.UNIT_Z, new Vector3(10, 10, 10)); RenderableEntity entity = GlobalInstance.TopoShapeConvert.ToEntity(box, 0); for (int ii = 0; ii < 10; ++ii) { EntitySceneNode node = new EntitySceneNode(); node.SetEntity(entity); Matrix4 trf = GlobalInstance.MatrixBuilder.MakeTranslate(new Vector3(11 * ii, 0, 0)); node.SetTransform(trf); context.ShowSceneNode(node); } context.RequestDraw(); SceneNodeIterator itr = context.RenderView.SceneManager.NewSceneNodeIterator(); String msg = "Node Ids: "; while (itr.More()) { SceneNode node = itr.Next(); msg += String.Format(" {0}", node.GetId().AsInt()); } MessageBox.Show(msg); return(true); }
public override bool Run(FeatureContext context) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "IGES File (*.igs;*.iges)|*.igs;*.iges||"; if (DialogResult.OK != dlg.ShowDialog()) { return(true); } var shape = GlobalInstance.BrepTools.LoadFile(new Path(dlg.FileName)); var size = shape.GetBBox().Size(); var entity = GlobalInstance.TopoShapeConvert.ToEntity(shape, 1); for (int ii = 0; ii < 7; ++ii) { for (int jj = 0; jj < 7; ++jj) { var node = new EntitySceneNode(); node.SetEntity(entity); var trf = GlobalInstance.MatrixBuilder.MakeTranslate(new Vector3(size.X * ii, size.Y * jj, 0)); node.SetTransform(trf); context.ShowSceneNode(node); } } return(true); }
public override bool Run(FeatureContext context) { Text3dNode textNode = new Text3dNode(); textNode.SetFontName("FangSong (TrueType)"); textNode.SetText("1234565\nabcdefg\n我爱CAD"); textNode.SetLineSpace(10); Coordinate3 coord = new Coordinate3(); coord.Origion = new Vector3(100, 100, 0); coord.X = new Vector3(1, 1, 0); coord.X.Normalize(); coord.Y = coord.Z.CrossProduct(coord.X); Matrix4 trf = GlobalInstance.MatrixBuilder.ToWorldMatrix(coord); textNode.SetTransform(trf); textNode.Update(); context.ShowSceneNode(textNode); return(true); }
public override bool Run(FeatureContext context) { ArrowWidget arrow = new ArrowWidget(); arrow.SetFixedSize(true); context.ShowSceneNode(arrow); return(true); }
public override bool Run(FeatureContext context) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "STL File (*.stl)|*.stl||"; if(DialogResult.OK != dlg.ShowDialog()) return true; ModelReader reader = new ModelReader(); GroupSceneNode node = reader.LoadFile(new Path(dlg.FileName)); context.ShowSceneNode(node); return true; }
public override bool Run(FeatureContext context) { AxesWidget node = new AxesWidget(); node.SetArrowText((int)EnumAxesDirection.Axes_X, ""); node.SetArrowText((int)EnumAxesDirection.Axes_Y, ""); node.SetArrowText((int)EnumAxesDirection.Axes_Z, ""); context.ShowSceneNode(node); return(true); }
public override bool Run(FeatureContext context) { TopoShape oCircle1 = GlobalInstance.BrepTools.MakeCircle(Vector3.ZERO, 20, Vector3.UNIT_Z); TopoShape Pipe01_Surf = GlobalInstance.BrepTools.Extrude(oCircle1, 100, Vector3.UNIT_Z); context.ShowGeometry(Pipe01_Surf); TopoShape oCircle2 = GlobalInstance.BrepTools.MakeCircle(new Vector3(0.0f, 0.0f, 50.0f), 10, Vector3.UNIT_Y); TopoShape Pipe02_Surf = GlobalInstance.BrepTools.Extrude(oCircle2, 80, Vector3.UNIT_Y); { SceneNode node2 = context.ShowGeometry(Pipe02_Surf); FaceStyle fs = new FaceStyle(); fs.SetColor(new ColorValue(0.5f, 0.5f, 0.5f, 0.5f)); fs.SetTransparent(true); node2.SetFaceStyle(fs); } // Compute the intersection curve TopoShape Inters1 = GlobalInstance.BrepTools.SurfaceSection(Pipe01_Surf, Pipe02_Surf); if (Inters1 != null) { SceneNode node = context.ShowGeometry(Inters1); LineStyle ls = new LineStyle(); ls.SetLineWidth(3); ls.SetColor(ColorValue.RED); node.SetLineStyle(ls); // Get the curve parameters GeomCurve curve = new GeomCurve(); if (curve.Initialize(Inters1)) { LineStyle ls2 = new LineStyle(); ls2.SetColor(ColorValue.GREEN); double start = curve.FirstParameter(); double end = curve.LastParameter(); for (double ii = start; ii <= end; ii += 0.1) { List <Vector3> rt = curve.D1(ii); LineNode ln = new LineNode(); ln.SetLineStyle(ls2); ln.Set(rt[0], rt[0] + rt[1]); context.ShowSceneNode(ln); } } } return(true); }
public override bool Run(FeatureContext context) { const float len = 100.0f; const int nDim = 50; float[] pointBuffer = new float[nDim * nDim * nDim * 3]; float[] colorBuffer = new float[nDim * nDim * nDim * 3]; int idx = -1; for (int ii = 0; ii < nDim; ++ii) { for (int jj = 0; jj < nDim; ++jj) { for (int kk = 0; kk < nDim; ++kk) { ++idx; pointBuffer[idx * 3] = ii * len; pointBuffer[idx * 3 + 1] = jj * len; pointBuffer[idx * 3 + 2] = kk * len; colorBuffer[idx * 3] = ((float)ii) / ((float)nDim); colorBuffer[idx * 3 + 1] = ((float)jj) / ((float)nDim); colorBuffer[idx * 3 + 2] = ((float)kk) / ((float)nDim); } } } PointStyle pointStyle = new PointStyle(); //pointStyle.SetPointSize(4.0f); pointStyle.SetMarker("cross"); PointCloudNode pcn = new PointCloudNode(); pcn.SetPointStyle(pointStyle); pcn.SetPoints(pointBuffer); pcn.SetColors(colorBuffer); pcn.ComputeBBox(); AABox bbox = pcn.GetBBox(); Vector3 pt = bbox.MinPt; context.ShowSceneNode(pcn); return(true); }
public override bool Run(FeatureContext context) { if (m_Object == null) { TopoShape sphere = GlobalInstance.BrepTools.MakeSphere(Vector3.ZERO, 10); fs = new FaceStyle(); m_Object = context.ShowGeometry(sphere); m_Object.SetFaceStyle(fs); } else { context.ShowSceneNode(m_Object); } m_RenderView = context.RenderView; m_RenderView.RenderTick += new AnyCAD.Presentation.RenderEventHandler(DancingBall_RenderTick); return(false); }
public override bool Run(FeatureContext context) { { ArrowWidget arrow = new ArrowWidget(); context.ShowSceneNode(arrow); context.RenderView.FitAll(); context.RequestDraw(); } ElementId id = context.CurrentId; MessageBox.Show("Remove Node"); SceneManager sceneMgr = context.RenderView.SceneManager; SceneNode node = sceneMgr.FindNode(id); if (node != null) { sceneMgr.RemoveNode(node); } return(true); }
public override bool Run(FeatureContext context) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "Deformation File (*.txt)|*.txt||"; if (DialogResult.OK != dlg.ShowDialog()) { return(true); } String fileName = dlg.FileName; StreamReader sr = new StreamReader(fileName, Encoding.Default); String line = sr.ReadLine(); List <DeformationNode> nodes = new List <DeformationNode>(); float maxValue = float.NegativeInfinity; float minValue = float.PositiveInfinity; while ((line = sr.ReadLine()) != null) { String[] items = line.Split('\t'); DeformationNode node = new DeformationNode(); node.Id = int.Parse(items[0]); node.X = float.Parse(items[1]); node.Y = float.Parse(items[2]); node.Z = float.Parse(items[3]); node.Data = float.Parse(items[4]); nodes.Add(node); if (node.Data > maxValue) { maxValue = node.Data; } if (node.Data < minValue) { minValue = node.Data; } } float[] pointBuffer = new float[nodes.Count * 3]; float[] colorBuffer = new float[nodes.Count * 3]; float range = maxValue - minValue; List <ColorValue> colorTables = new List <ColorValue>(); colorTables.Add(new ColorValue(0, 0, 1.0f)); colorTables.Add(new ColorValue(0, 108.0f / 255.0f, 1.0f)); colorTables.Add(new ColorValue(0, 197.0f / 255.0f, 1.0f)); colorTables.Add(new ColorValue(0, 243 / 255.0f, 1.0f)); colorTables.Add(new ColorValue(0, 1.0f, 219.0f / 255.0f)); colorTables.Add(new ColorValue(0, 1.0f, 165.0f / 255.0f)); colorTables.Add(new ColorValue(0, 1.0f, 54.0f / 255.0f)); colorTables.Add(new ColorValue(54.0f / 255.0f, 1.0f, 0)); colorTables.Add(new ColorValue(219.0f / 255.0f, 1.0f, 0)); //colorTables.Add(new ColorValue(238.0f / 255.0f, 249.0f/255.0f, 0)); colorTables.Add(new ColorValue(238.0f / 255.0f, 249.0f / 255.0f, 0)); colorTables.Add(new ColorValue(255.0f / 255.0f, 197.0f / 255.0f, 0)); colorTables.Add(new ColorValue(251.0f / 255.0f, 102.0f / 255.0f, 17.0f / 255.0f)); colorTables.Add(new ColorValue(1.0f, 0.0f, 0.0f)); float segment = range / (colorTables.Count); int ii = -1; foreach (DeformationNode node in nodes) { int idx = (int)(node.Data / segment); if (idx >= colorTables.Count) { idx -= 1; } ColorValue clr = colorTables.ElementAt(idx); pointBuffer[++ii] = node.X; colorBuffer[ii] = clr.R; pointBuffer[++ii] = node.Y; colorBuffer[ii] = clr.G; pointBuffer[++ii] = node.Z; colorBuffer[ii] = clr.B; } PointCloudNode pcn = new PointCloudNode(); pcn.SetPoints(pointBuffer); pcn.SetColors(colorBuffer); pcn.ComputeBBox(); context.ShowSceneNode(pcn); return(true); }
public override bool Run(FeatureContext context) { TopoShape circle = GlobalInstance.BrepTools.MakeCircle(Vector3.ZERO, 100, Vector3.UNIT_Z); TopoShape face = GlobalInstance.BrepTools.MakeFace(circle); FaceTriangulation ft = new FaceTriangulation(); ft.SetTolerance(5); ft.Perform(face); float[] points = ft.GetVertexBuffer(); int pointCount = points.Length / 3; uint[] indexBuffer = ft.GetIndexBuffer(); int faceCount = indexBuffer.Length / 3; float[] normals = ft.GetNormalBuffer(); float[] colorBuffer = new float[pointCount * 4]; Random num = new Random(); for (int ii = 0; ii < pointCount; ++ii) { int idx = ii * 4; colorBuffer[idx] = num.Next(0, 256) / 256.0f; colorBuffer[idx + 1] = num.Next(0, 256) / 256.0f; colorBuffer[idx + 2] = num.Next(0, 256) / 256.0f; colorBuffer[idx + 3] = 1; } RenderableEntity entity = GlobalInstance.TopoShapeConvert.CreateColoredFaceEntity(points, indexBuffer, normals, colorBuffer, face.GetBBox()); EntitySceneNode node = new EntitySceneNode(); node.SetEntity(entity); context.ShowSceneNode(node); ////////////////////////////////////////////////////////////////////////// // Code to get the mesh /* * for (int ii = 0; ii < faceCount; ++ii) * { * int p0 = (int)indexBuffer[ii * 3]; * int p1 = (int)indexBuffer[ii * 3 + 1]; * int p2 = (int)indexBuffer[ii * 3 + 2]; * * Vector3 pt0 = new Vector3(points[p0 * 3], points[p0 * 3 + 1], points[p0 * 3 + 2]); * Vector3 pt1 = new Vector3(points[p1 * 3], points[p1 * 3 + 1], points[p1 * 3 + 2]); * Vector3 pt2 = new Vector3(points[p2 * 3], points[p2 * 3 + 1], points[p2 * 3 + 2]); * * // .... * // use the same way to get the normal data for each point. * } * */ return(true); }
public override bool Run(FeatureContext context) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "Deformation File (*.xls)|*.xls||"; if (DialogResult.OK != dlg.ShowDialog()) { return(true); } String fileName = dlg.FileName; StreamReader sr = new StreamReader(fileName, Encoding.Default); String line = sr.ReadLine(); Dictionary <uint, HexNode> nodes = new Dictionary <uint, HexNode>(); float maxValue = float.NegativeInfinity; float minValue = float.PositiveInfinity; while ((line = sr.ReadLine()) != null) { String[] items = line.Split('\t'); HexNode node = new HexNode(); node.Id = uint.Parse(items[0]) - 1; node.Value.X = float.Parse(items[1]); node.Value.Y = float.Parse(items[2]); node.Value.Z = float.Parse(items[3]); node.Data = float.Parse(items[4]); nodes[node.Id] = node; if (node.Data > maxValue) { maxValue = node.Data; } if (node.Data < minValue) { minValue = node.Data; } } float[] pointBuffer = new float[nodes.Count * 3]; float[] colorBuffer = new float[nodes.Count * 3]; float range = maxValue - minValue; List <ColorValue> colorTables = new List <ColorValue>(); colorTables.Add(new ColorValue(0, 0, 1.0f)); colorTables.Add(new ColorValue(0, 108.0f / 255.0f, 1.0f)); colorTables.Add(new ColorValue(0, 197.0f / 255.0f, 1.0f)); colorTables.Add(new ColorValue(0, 243 / 255.0f, 1.0f)); colorTables.Add(new ColorValue(0, 1.0f, 219.0f / 255.0f)); colorTables.Add(new ColorValue(0, 1.0f, 165.0f / 255.0f)); colorTables.Add(new ColorValue(0, 1.0f, 54.0f / 255.0f)); colorTables.Add(new ColorValue(54.0f / 255.0f, 1.0f, 0)); colorTables.Add(new ColorValue(219.0f / 255.0f, 1.0f, 0)); //colorTables.Add(new ColorValue(238.0f / 255.0f, 249.0f/255.0f, 0)); colorTables.Add(new ColorValue(238.0f / 255.0f, 249.0f / 255.0f, 0)); colorTables.Add(new ColorValue(255.0f / 255.0f, 197.0f / 255.0f, 0)); colorTables.Add(new ColorValue(251.0f / 255.0f, 102.0f / 255.0f, 17.0f / 255.0f)); colorTables.Add(new ColorValue(1.0f, 0.0f, 0.0f)); float segment = range / (colorTables.Count); //int ii=-1; //foreach(HexNode node in nodes) //{ // int idx = (int)(node.Data / segment); // if (idx >= colorTables.Count) // idx -= 1; // ColorValue clr = colorTables.ElementAt(idx); // pointBuffer[++ii] = node.X; // colorBuffer[ii] = clr.R; // pointBuffer[++ii] = node.Y; // colorBuffer[ii] = clr.G; // pointBuffer[++ii] = node.Z; // colorBuffer[ii] = clr.B; //} dlg = new OpenFileDialog(); dlg.Filter = "Hex20 File (*.xls)|*.xls||"; if (DialogResult.OK != dlg.ShowDialog()) { return(true); } fileName = dlg.FileName; sr = new StreamReader(fileName, Encoding.Default); line = sr.ReadLine(); List <Hex20> hex20s = new List <Hex20>(); while ((line = sr.ReadLine()) != null) { String[] items = line.Split('\t'); Hex20 hex = new Hex20(); hex.Id = uint.Parse(items[0]) - 1; for (int ii = 0; ii < 20; ++ii) { hex.NodeIds[ii] = uint.Parse(items[ii + 2]) - 1; } hex20s.Add(hex); } //Hex20 hexItem = hex20s[0]; //for(int ii=0; ii<20; ++ii) //{ // HexNode n = nodes[hexItem.NodeIds[ii]]; // PointNode node = new PointNode(); // node.SetName(n.Id.ToString()); // node.SetShowText(true); // node.SetPoint(new Vector3(n.X, n.Y, n.Z)); // context.ShowSceneNode(node); //} //GlobalInstance.TopoShapeConvert. List <uint> ib = new List <uint>(); for (int ii = 0; ii < hex20s.Count; ++ii) { Hex20 hexItem = hex20s[ii]; // TOP ib.Add(hexItem.NodeIds[0]); ib.Add(hexItem.NodeIds[8]); ib.Add(hexItem.NodeIds[11]); ib.Add(hexItem.NodeIds[8]); ib.Add(hexItem.NodeIds[1]); ib.Add(hexItem.NodeIds[9]); ib.Add(hexItem.NodeIds[9]); ib.Add(hexItem.NodeIds[2]); ib.Add(hexItem.NodeIds[10]); ib.Add(hexItem.NodeIds[10]); ib.Add(hexItem.NodeIds[3]); ib.Add(hexItem.NodeIds[11]); ib.Add(hexItem.NodeIds[8]); ib.Add(hexItem.NodeIds[10]); ib.Add(hexItem.NodeIds[11]); ib.Add(hexItem.NodeIds[8]); ib.Add(hexItem.NodeIds[9]); ib.Add(hexItem.NodeIds[10]); // BOTTOM ib.Add(hexItem.NodeIds[4]); ib.Add(hexItem.NodeIds[12]); ib.Add(hexItem.NodeIds[15]); ib.Add(hexItem.NodeIds[12]); ib.Add(hexItem.NodeIds[5]); ib.Add(hexItem.NodeIds[13]); ib.Add(hexItem.NodeIds[13]); ib.Add(hexItem.NodeIds[6]); ib.Add(hexItem.NodeIds[14]); ib.Add(hexItem.NodeIds[14]); ib.Add(hexItem.NodeIds[7]); ib.Add(hexItem.NodeIds[15]); ib.Add(hexItem.NodeIds[12]); ib.Add(hexItem.NodeIds[14]); ib.Add(hexItem.NodeIds[15]); ib.Add(hexItem.NodeIds[12]); ib.Add(hexItem.NodeIds[13]); ib.Add(hexItem.NodeIds[14]); // FRONT ib.Add(hexItem.NodeIds[1]); ib.Add(hexItem.NodeIds[9]); ib.Add(hexItem.NodeIds[17]); ib.Add(hexItem.NodeIds[9]); ib.Add(hexItem.NodeIds[2]); ib.Add(hexItem.NodeIds[18]); ib.Add(hexItem.NodeIds[18]); ib.Add(hexItem.NodeIds[6]); ib.Add(hexItem.NodeIds[13]); ib.Add(hexItem.NodeIds[13]); ib.Add(hexItem.NodeIds[5]); ib.Add(hexItem.NodeIds[17]); ib.Add(hexItem.NodeIds[9]); ib.Add(hexItem.NodeIds[18]); ib.Add(hexItem.NodeIds[17]); ib.Add(hexItem.NodeIds[18]); ib.Add(hexItem.NodeIds[13]); ib.Add(hexItem.NodeIds[17]); // BACK ib.Add(hexItem.NodeIds[0]); ib.Add(hexItem.NodeIds[11]); ib.Add(hexItem.NodeIds[16]); ib.Add(hexItem.NodeIds[11]); ib.Add(hexItem.NodeIds[3]); ib.Add(hexItem.NodeIds[19]); ib.Add(hexItem.NodeIds[19]); ib.Add(hexItem.NodeIds[7]); ib.Add(hexItem.NodeIds[15]); ib.Add(hexItem.NodeIds[15]); ib.Add(hexItem.NodeIds[4]); ib.Add(hexItem.NodeIds[16]); ib.Add(hexItem.NodeIds[11]); ib.Add(hexItem.NodeIds[19]); ib.Add(hexItem.NodeIds[16]); ib.Add(hexItem.NodeIds[19]); ib.Add(hexItem.NodeIds[15]); ib.Add(hexItem.NodeIds[16]); // LEFT ib.Add(hexItem.NodeIds[1]); ib.Add(hexItem.NodeIds[17]); ib.Add(hexItem.NodeIds[8]); ib.Add(hexItem.NodeIds[17]); ib.Add(hexItem.NodeIds[5]); ib.Add(hexItem.NodeIds[12]); ib.Add(hexItem.NodeIds[12]); ib.Add(hexItem.NodeIds[4]); ib.Add(hexItem.NodeIds[16]); ib.Add(hexItem.NodeIds[16]); ib.Add(hexItem.NodeIds[0]); ib.Add(hexItem.NodeIds[8]); ib.Add(hexItem.NodeIds[8]); ib.Add(hexItem.NodeIds[17]); ib.Add(hexItem.NodeIds[12]); ib.Add(hexItem.NodeIds[12]); ib.Add(hexItem.NodeIds[16]); ib.Add(hexItem.NodeIds[8]); // RIGHT ib.Add(hexItem.NodeIds[2]); ib.Add(hexItem.NodeIds[10]); ib.Add(hexItem.NodeIds[18]); ib.Add(hexItem.NodeIds[10]); ib.Add(hexItem.NodeIds[3]); ib.Add(hexItem.NodeIds[19]); ib.Add(hexItem.NodeIds[19]); ib.Add(hexItem.NodeIds[7]); ib.Add(hexItem.NodeIds[14]); ib.Add(hexItem.NodeIds[14]); ib.Add(hexItem.NodeIds[6]); ib.Add(hexItem.NodeIds[18]); ib.Add(hexItem.NodeIds[10]); ib.Add(hexItem.NodeIds[14]); ib.Add(hexItem.NodeIds[18]); ib.Add(hexItem.NodeIds[10]); ib.Add(hexItem.NodeIds[19]); ib.Add(hexItem.NodeIds[14]); } Vector3[] normals = new Vector3[nodes.Count]; for (int ii = 0; ii < ib.Count / 3; ++ii) { uint a = ib[ii * 3]; uint b = ib[ii * 3 + 1]; uint c = ib[ii * 3 + 2]; Vector3 p1 = nodes[a].Value; Vector3 p2 = nodes[b].Value; Vector3 p3 = nodes[c].Value; Vector3 normal = (p2 - p1).CrossProduct(p3 - p1); if (normals[a] == null) { normals[a] = Vector3.ZERO; } if (normals[b] == null) { normals[b] = Vector3.ZERO; } if (normals[c] == null) { normals[c] = Vector3.ZERO; } normals[a] += normal; normals[b] += normal; normals[c] += normal; } float[] vb = new float[nodes.Count * 3]; float[] nb = new float[nodes.Count * 3]; float[] cb = new float[nodes.Count * 3]; AABox bbox = new AABox(); for (uint ii = 0; ii < nodes.Count; ++ii) { var nd = nodes[ii]; bbox.Merge(new AABox(nd.Value, nd.Value)); vb[ii * 3] = (float)nd.Value.X; vb[ii * 3 + 1] = (float)nd.Value.Y; vb[ii * 3 + 2] = (float)nd.Value.Z; var normal = normals[ii]; normal.Normalize(); nb[ii * 3] = (float)normal.X; nb[ii * 3 + 1] = (float)normal.Y; nb[ii * 3 + 2] = (float)normal.Z; int idx = (int)((nd.Data - minValue) / segment); if (idx >= colorTables.Count) { idx = colorTables.Count - 1; } ColorValue clr = colorTables.ElementAt(idx); cb[ii * 3] = clr.R; cb[ii * 3 + 1] = clr.G; cb[ii * 3 + 2] = clr.B; } var pEntity = GlobalInstance.TopoShapeConvert.CreateColoredFaceEntity(vb, ib.ToArray(), nb, cb, bbox); var nEntityNode = new EntitySceneNode(); nEntityNode.SetEntity(pEntity); context.ShowSceneNode(nEntityNode); return(true); }