static void Main(string[] args) { Rhino.Compute.ComputeServer.AuthToken = "Set Your AuthToken"; var model = new Rhino.FileIO.File3dm(); // Create a couple Circles using a Local copy of rhino3dmIO var c1 = new Circle(new Point3d(0, 0, 0), 100); var c2 = new Circle(new Point3d(30, 30, 0), 70); model.Objects.AddCircle(c1); model.Objects.AddCircle(c2); // call compute to perform a curve boolean operation var intersectionCurves = Rhino.Compute.CurveCompute.CreateBooleanIntersection(c1.ToNurbsCurve(), c2.ToNurbsCurve()); Mesh[] intersectionMeshes = null; if (intersectionCurves != null) { // use local Rhino3dmIO to Create a Brep from curves var brep = Brep.CreateTrimmedPlane(c1.Plane, intersectionCurves); // call compute to mesh the Brep intersectionMeshes = Rhino.Compute.MeshCompute.CreateFromBrep(brep, MeshingParameters.FastRenderMesh); for (int i = 0; i < intersectionMeshes.Length; i++) { model.Objects.AddMesh(intersectionMeshes[i]); } } // just some helper routines to create on SVG files of the results so we can see what was generated string path = "circle_intersection.svg"; WriteSvgFiles(path, c1, c2, intersectionMeshes); System.Diagnostics.Process.Start(path); // Output Rhino 3dm file var path_3dm = System.IO.Directory.GetCurrentDirectory() + "/Outputs/circle_intersection.3dm"; model.Write(path_3dm, 5); Console.WriteLine("press any key to exit"); Console.ReadKey(); }
public bool WorldDraw(WorldDraw wd) { if (_geometry is Rhino.Geometry.Mesh mesh) { var faces = mesh.Faces.ToHost(); var points = new Point3dCollection(mesh.Vertices.ToHost()); var vertexData = new VertexData(); vertexData.SetNormalVectors(mesh.Normals.ToHost()); bool hasVertColor = mesh.VertexColors.Count != 0; vertexData.SetTrueColors(hasVertColor ? mesh.VertexColors.ToHost() : null); wd.Geometry.Shell(points, faces, null, null, vertexData, false); } else if (_geometry is Rhino.Geometry.Curve curve) { double deviation = System.Math.Max(wd.Deviation(DeviationType.MaxDevForCurve, curve.PointAtStart.ToHost()), 0.01 * curve.GetLength()); var polyline = curve.ToPolyline(10E+4 * Convert.VertexTolerance, Convert.AngleTolerance, deviation, 0.0); if (polyline != null) { var giPoly = new Polyline(); giPoly.Points = new Point3dCollection(polyline.ToPolyline().ToArray().ToHost()); wd.Geometry.Polyline(giPoly); } #if DEBUG else { var tmpFile = new Rhino.FileIO.File3dm(); tmpFile.Objects.AddCurve(curve); tmpFile.Write(System.IO.Path.Combine(System.IO.Path.GetTempPath(), "BricsCAD", "CurveFail.3dm"), new Rhino.FileIO.File3dmWriteOptions()); } #endif } else if (_geometry is Rhino.Geometry.Point) { return(false); } return(true); }
private void OnGUI() { GUI.Label(new Rect(10f, 10f, 90, 20), "Height"); height = GUI.HorizontalSlider(new Rect(100, 15, 100, 20), height, 1f, 20f); GUI.Label(new Rect(10f, 30f, 90, 20), "Radius"); pipeRad = GUI.HorizontalSlider(new Rect(100, 35, 100, 20), pipeRad, 0.5f, 5f); GUI.Label(new Rect(10f, 50f, 90, 20), "Angle"); angle = GUI.HorizontalSlider(new Rect(100, 55, 100, 20), angle, 0, 90f); GUI.Label(new Rect(10f, 70f, 90, 20), "Segments"); segments = (int)GUI.HorizontalSlider(new Rect(100, 75, 100, 20), segments, 3, 8); if (GUI.Button(new Rect(10f, 100f, 50, 20), "Save")) { if (model != null) { var path = Application.dataPath + "/../model.3dm"; model.Write(path, 5); } } }
public static void OptToRhino(OptFile opt, string rhinoPath, bool scale) { if (opt == null) { throw new ArgumentNullException("opt"); } string rhinoDirectory = Path.GetDirectoryName(rhinoPath); string rhinoName = Path.GetFileNameWithoutExtension(rhinoPath); var distances = opt.Meshes .SelectMany(t => t.Lods) .Select(t => t.Distance) .Distinct() .OrderByDescending(t => t) .ToArray(); for (int distance = 0; distance < distances.Length; distance++) { using (var file = new Rhino.FileIO.File3dm()) { file.Settings.ModelUnitSystem = Rhino.UnitSystem.Meters; int objectsIndex = 0; List <string> textureNames = new List <string>(); foreach (var mesh in opt.Meshes) { var lod = mesh.Lods.FirstOrDefault(t => t.Distance <= distances[distance]); if (lod == null) { continue; } foreach (var textureName in lod.FaceGroups .Where(t => t.Textures.Count > 0) .Select(t => t.Textures[0])) { if (!textureNames.Contains(textureName)) { textureNames.Add(textureName); } } string meshName = string.Format(CultureInfo.InvariantCulture, "{0}.{1:D3}", mesh.Descriptor.MeshType, objectsIndex); using (var layer = new Rhino.DocObjects.Layer()) { layer.Name = meshName; file.Layers.Add(layer); } foreach (var faceGroup in lod.FaceGroups) { using (var rhinoMesh = new Rhino.Geometry.Mesh()) using (var rhinoAttributes = new Rhino.DocObjects.ObjectAttributes()) { rhinoAttributes.Name = meshName; rhinoAttributes.LayerIndex = objectsIndex; if (faceGroup.Textures.Count > 0) { rhinoAttributes.MaterialIndex = textureNames.IndexOf(faceGroup.Textures[0]); } Action <Vector> addVertex; if (scale) { addVertex = vertex => rhinoMesh.Vertices.Add(vertex.X * OptFile.ScaleFactor, vertex.Y * OptFile.ScaleFactor, vertex.Z * OptFile.ScaleFactor); } else { addVertex = vertex => rhinoMesh.Vertices.Add(vertex.X, vertex.Y, vertex.Z); } Action <TextureCoordinates> addTexCoords = texCoords => rhinoMesh.TextureCoordinates.Add(texCoords.U, -texCoords.V); Action <Vector> addNormal = normal => rhinoMesh.Normals.Add(normal.X, normal.Y, normal.Z); int facesIndex = 0; foreach (var face in faceGroup.Faces) { var verticesIndex = face.VerticesIndex; var texCoordsIndex = face.TextureCoordinatesIndex; var normalsIndex = face.VertexNormalsIndex; addVertex(mesh.Vertices[verticesIndex.A]); addTexCoords(mesh.TextureCoordinates[texCoordsIndex.A]); addNormal(mesh.VertexNormals[normalsIndex.A]); facesIndex++; addVertex(mesh.Vertices[verticesIndex.B]); addTexCoords(mesh.TextureCoordinates[texCoordsIndex.B]); addNormal(mesh.VertexNormals[normalsIndex.B]); facesIndex++; addVertex(mesh.Vertices[verticesIndex.C]); addTexCoords(mesh.TextureCoordinates[texCoordsIndex.C]); addNormal(mesh.VertexNormals[normalsIndex.C]); facesIndex++; if (verticesIndex.D >= 0) { addVertex(mesh.Vertices[verticesIndex.D]); addTexCoords(mesh.TextureCoordinates[texCoordsIndex.D]); addNormal(mesh.VertexNormals[normalsIndex.D]); facesIndex++; } if (verticesIndex.D < 0) { rhinoMesh.Faces.AddFace(facesIndex - 1, facesIndex - 2, facesIndex - 3); } else { rhinoMesh.Faces.AddFace(facesIndex - 1, facesIndex - 2, facesIndex - 3, facesIndex - 4); } } rhinoMesh.Compact(); file.Objects.AddMesh(rhinoMesh, rhinoAttributes); } } objectsIndex++; } foreach (var textureName in textureNames) { Texture texture; opt.Textures.TryGetValue(textureName, out texture); using (var material = new Rhino.DocObjects.Material()) { material.Name = textureName; if (texture == null) { material.DiffuseColor = System.Drawing.Color.White; } else { texture.Save(Path.Combine(rhinoDirectory, textureName + ".png")); material.SetBitmapTexture(textureName + ".png"); if (texture.HasAlpha) { texture.SaveAlphaMap(Path.Combine(rhinoDirectory, textureName + "_alpha.png")); material.SetTransparencyTexture(textureName + "_alpha.png"); } } file.Materials.Add(material); } } file.Write(Path.Combine(rhinoDirectory, string.Format(CultureInfo.InvariantCulture, "{0}_{1}.3dm", rhinoName, distance)), 4); } } }
public static void OptToRhino(OptFile opt, string rhinoPath, bool scale) { if (opt == null) { throw new ArgumentNullException("opt"); } string rhinoDirectory = Path.GetDirectoryName(rhinoPath); string rhinoName = Path.GetFileNameWithoutExtension(rhinoPath); var distances = opt.Meshes .SelectMany(t => t.Lods) .Select(t => t.Distance) .Distinct() .OrderByDescending(t => t) .ToArray(); for (int distance = 0; distance < distances.Length; distance++) { using (var file = new Rhino.FileIO.File3dm()) { file.Settings.ModelUnitSystem = Rhino.UnitSystem.Meters; int objectsIndex = 0; List<string> textureNames = new List<string>(); foreach (var mesh in opt.Meshes) { var lod = mesh.Lods.FirstOrDefault(t => t.Distance <= distances[distance]); if (lod == null) { continue; } foreach (var textureName in lod.FaceGroups .Where(t => t.Textures.Count > 0) .Select(t => t.Textures[0])) { if (!textureNames.Contains(textureName)) { textureNames.Add(textureName); } } string meshName = string.Format(CultureInfo.InvariantCulture, "{0}.{1:D3}", mesh.Descriptor.MeshType, objectsIndex); using (var layer = new Rhino.DocObjects.Layer()) { layer.Name = meshName; file.Layers.Add(layer); } foreach (var faceGroup in lod.FaceGroups) { using (var rhinoMesh = new Rhino.Geometry.Mesh()) using (var rhinoAttributes = new Rhino.DocObjects.ObjectAttributes()) { rhinoAttributes.Name = meshName; rhinoAttributes.LayerIndex = objectsIndex; if (faceGroup.Textures.Count > 0) { rhinoAttributes.MaterialIndex = textureNames.IndexOf(faceGroup.Textures[0]); } Action<Vector> addVertex; if (scale) { addVertex = vertex => rhinoMesh.Vertices.Add(vertex.X * OptFile.ScaleFactor, vertex.Y * OptFile.ScaleFactor, vertex.Z * OptFile.ScaleFactor); } else { addVertex = vertex => rhinoMesh.Vertices.Add(vertex.X, vertex.Y, vertex.Z); } Action<TextureCoordinates> addTexCoords = texCoords => rhinoMesh.TextureCoordinates.Add(texCoords.U, -texCoords.V); Action<Vector> addNormal = normal => rhinoMesh.Normals.Add(normal.X, normal.Y, normal.Z); int facesIndex = 0; foreach (var face in faceGroup.Faces) { var verticesIndex = face.VerticesIndex; var texCoordsIndex = face.TextureCoordinatesIndex; var normalsIndex = face.VertexNormalsIndex; addVertex(mesh.Vertices[verticesIndex.A]); addTexCoords(mesh.TextureCoordinates[texCoordsIndex.A]); addNormal(mesh.VertexNormals[normalsIndex.A]); facesIndex++; addVertex(mesh.Vertices[verticesIndex.B]); addTexCoords(mesh.TextureCoordinates[texCoordsIndex.B]); addNormal(mesh.VertexNormals[normalsIndex.B]); facesIndex++; addVertex(mesh.Vertices[verticesIndex.C]); addTexCoords(mesh.TextureCoordinates[texCoordsIndex.C]); addNormal(mesh.VertexNormals[normalsIndex.C]); facesIndex++; if (verticesIndex.D >= 0) { addVertex(mesh.Vertices[verticesIndex.D]); addTexCoords(mesh.TextureCoordinates[texCoordsIndex.D]); addNormal(mesh.VertexNormals[normalsIndex.D]); facesIndex++; } if (verticesIndex.D < 0) { rhinoMesh.Faces.AddFace(facesIndex - 1, facesIndex - 2, facesIndex - 3); } else { rhinoMesh.Faces.AddFace(facesIndex - 1, facesIndex - 2, facesIndex - 3, facesIndex - 4); } } rhinoMesh.Compact(); file.Objects.AddMesh(rhinoMesh, rhinoAttributes); } } objectsIndex++; } foreach (var textureName in textureNames) { Texture texture; opt.Textures.TryGetValue(textureName, out texture); using (var material = new Rhino.DocObjects.Material()) { material.Name = textureName; if (texture == null) { material.DiffuseColor = System.Drawing.Color.White; } else { texture.Save(Path.Combine(rhinoDirectory, textureName + ".png")); material.SetBitmapTexture(textureName + ".png"); if (texture.HasAlpha) { texture.SaveAlphaMap(Path.Combine(rhinoDirectory, textureName + "_alpha.png")); material.SetTransparencyTexture(textureName + "_alpha.png"); } } file.Materials.Add(material); } } file.Write(Path.Combine(rhinoDirectory, string.Format(CultureInfo.InvariantCulture, "{0}_{1}.3dm", rhinoName, distance)), 4); } } }
// Start is called before the first frame update void Start() { ComputeServer.AuthToken = authToken; var model = new Rhino.FileIO.File3dm(); var curves = new List <Rhino.Geometry.NurbsCurve>(); for (int i = 0; i < 20; i++) { var s = 10f; var pt = new Rhino.Geometry.Point3d(Random.Range(-s, s), Random.Range(-s, s), 0); // model.Objects.AddPoint(pt); var r = Random.Range(1f, 3f); var circle = new Rhino.Geometry.Circle(pt, r); var curve = circle.ToNurbsCurve(); curves.Add(curve); } var unionCrvsC = CurveCompute.CreateBooleanUnion(curves); var height = Random.Range(1f, 5f); var extrusions = new List <Rhino.Geometry.Extrusion>(); foreach (var unionCrvC in unionCrvsC) { var extrusion = Rhino.Geometry.Extrusion.Create(unionCrvC, height, true); model.Objects.AddExtrusion(extrusion); extrusions.Add(extrusion); } var meshList = new List <Rhino.Geometry.Mesh>(); foreach (var extrusion in extrusions) { var brep = extrusion.ToBrep(); var meshes = MeshCompute.CreateFromBrep(brep); meshList.AddRange(meshes.ToList()); } foreach (var mesh in meshList) { Mesh meshObj = new Mesh(); var vertices = new List <Vector3>(); // mesh.RebuildNormals(); foreach (var meshVertex in mesh.Vertices) { var vertex = new Vector3(meshVertex.X, meshVertex.Z, meshVertex.Y); vertices.Add(vertex); } var triangles = new List <int>(); foreach (var meshFace in mesh.Faces) { if (meshFace.IsTriangle) { triangles.Add(meshFace.C); triangles.Add(meshFace.B); triangles.Add(meshFace.A); } else if (meshFace.IsQuad) { triangles.Add(meshFace.C); triangles.Add(meshFace.B); triangles.Add(meshFace.A); triangles.Add(meshFace.D); triangles.Add(meshFace.C); triangles.Add(meshFace.A); } } meshObj.vertices = vertices.ToArray(); meshObj.triangles = triangles.ToArray(); meshObj.RecalculateNormals(); GameObject gb = new GameObject(); gb.AddComponent <MeshFilter>().mesh = meshObj; gb.AddComponent <MeshRenderer>().material = mat; } var path = Application.dataPath + "/../Outputs/model.3dm"; model.Write(path, 5); }
private void GenerateGeo() { model = new Rhino.FileIO.File3dm(); int num = 10; float outerRad = 2f; var curves = new List <Rhino.Geometry.Curve>(); for (int i = 0; i < num; i++) { var pt = new Rhino.Geometry.Point3d(0, 0, height / (num - 1) * i); var circle = new Rhino.Geometry.Circle(pt, pipeRad); var polygon = Rhino.Geometry.Polyline.CreateInscribedPolygon(circle, segments); var curve = polygon.ToNurbsCurve(); curve.Rotate(i * Mathf.Deg2Rad * angle, new Rhino.Geometry.Vector3d(0, 0, 1), new Rhino.Geometry.Point3d(0, 0, 0)); curve.Translate(new Rhino.Geometry.Vector3d(Mathf.Cos(Mathf.Deg2Rad * angle * i), Mathf.Sin(Mathf.Deg2Rad * angle * i), 0) * outerRad); curves.Add(curve); //model.Objects.AddCurve(curve); } var breps = BrepCompute.CreateFromLoft(curves, Rhino.Geometry.Point3d.Unset, Rhino.Geometry.Point3d.Unset, Rhino.Geometry.LoftType.Normal, false); var meshList = new List <Rhino.Geometry.Mesh>(); foreach (var brep in breps) { model.Objects.AddBrep(brep); var brep2 = brep.CapPlanarHoles(0.001); var meshes = MeshCompute.CreateFromBrep(brep2); meshList.AddRange(meshes); } //convert rhino mesh into unity mesh foreach (var mesh in meshList) { Mesh meshObj = new Mesh(); var vertices = new List <Vector3>(); var triangles = new List <int>(); var normals = new List <Vector3>(); foreach (var meshVertex in mesh.Vertices) { var vertex = new Vector3(meshVertex.X, meshVertex.Z, meshVertex.Y); vertices.Add(vertex); } foreach (var meshFace in mesh.Faces) { if (meshFace.IsTriangle) { triangles.Add(meshFace.C); triangles.Add(meshFace.B); triangles.Add(meshFace.A); //incase for the backward } else if (meshFace.IsQuad) //two triangles to see quad { triangles.Add(meshFace.C); triangles.Add(meshFace.B); triangles.Add(meshFace.A); triangles.Add(meshFace.D); triangles.Add(meshFace.C); triangles.Add(meshFace.A); } } foreach (var meshNormal in mesh.Normals) { normals.Add(new Vector3(meshNormal.X, meshNormal.Z, meshNormal.Y)); } meshObj.vertices = vertices.ToArray(); meshObj.triangles = triangles.ToArray(); meshObj.normals = normals.ToArray(); GameObject gb = new GameObject(); gb.AddComponent <MeshFilter>().mesh = meshObj; gb.AddComponent <MeshRenderer>().material = mat; } string path = Application.dataPath + "/../model.3dm"; model.Write(path, 6); }
public void Write(string path) { if (!System.IO.Directory.Exists(path)) { throw new Exception("Path does not exist."); } if (g == null || beam == null) { throw new Exception("Must add Glulam and Beam geometry!"); } Rhino.FileIO.File3dm file = new Rhino.FileIO.File3dm(); // Setup layers Layer lRoot = new Layer(); lRoot.Name = "tas"; file.AllLayers.Add(lRoot); lRoot = file.AllLayers.Last(); Layer lNC = new Layer(); lNC.Name = "NC"; lNC.IsVisible = false; lNC.IsLocked = true; file.AllLayers.Add(lNC); lNC = file.AllLayers.Last(); lNC.ParentLayerId = lRoot.Id; Layer lBL = new Layer(); lBL.Name = "BL"; lBL.IsLocked = true; file.AllLayers.Add(lBL); lBL = file.AllLayers.Last(); lBL.ParentLayerId = lRoot.Id; Layer lBE = new Layer(); lBE.Name = "BE"; lBE.IsLocked = true; file.AllLayers.Add(lBE); lBE = file.AllLayers.Last(); lBE.ParentLayerId = lRoot.Id; Layer lBL_Centreline = new Layer(); lBL_Centreline.Name = "BL_Centreline"; lBL_Centreline.Index = 1; lBL_Centreline.Color = Color.FromArgb(0, 0, 255); lBL_Centreline.ParentLayerId = lBL.Id; file.AllLayers.Add(lBL_Centreline); lBL_Centreline = file.AllLayers.Last(); Layer lBL_Geometry = new Layer(); lBL_Geometry.Name = "BL_Geometry"; lBL_Geometry.Color = Color.FromArgb(125, 200, 125); lBL_Geometry.ParentLayerId = lBL.Id; file.AllLayers.Add(lBL_Geometry); lBL_Geometry = file.AllLayers.Last(); Layer lBL_Safety = new Layer(); lBL_Safety.Name = "BL_Safety"; lBL_Safety.IsVisible = false; lBL_Safety.Color = Color.FromArgb(200, 200, 200); lBL_Safety.ParentLayerId = lBL.Id; file.AllLayers.Add(lBL_Safety); lBL_Safety = file.AllLayers.Last(); Layer lBE_Geometry = new Layer(); lBE_Geometry.Name = "BE_Geometry"; lBE_Geometry.Color = Color.FromArgb(100, 100, 100); lBE_Geometry.ParentLayerId = lBE.Id; file.AllLayers.Add(lBE_Geometry); lBE_Geometry = file.AllLayers.Last(); Layer lNC_Surface = new Layer(); lNC_Surface.Name = "NC_Surface"; lNC_Surface.Color = Color.FromArgb(255, 0, 255); lNC_Surface.ParentLayerId = lNC.Id; file.AllLayers.Add(lNC_Surface); lNC_Surface = file.AllLayers.Last(); Layer lNC_Normals = new Layer(); lNC_Normals.Name = "NC_SurfaceNormals"; lNC_Normals.Color = Color.FromArgb(255, 0, 150); lNC_Normals.ParentLayerId = lNC.Id; file.AllLayers.Add(lNC_Normals); lNC_Normals = file.AllLayers.Last(); Layer lNC_GlueFace = new Layer(); lNC_GlueFace.Name = "NC_GlueFace"; lNC_GlueFace.Color = Color.FromArgb(255, 0, 255); lNC_GlueFace.ParentLayerId = lNC.Id; file.AllLayers.Add(lNC_GlueFace); lNC_GlueFace = file.AllLayers.Last(); Layer lNC_Joints = new Layer(); lNC_Joints.Name = "NC_Joints"; lNC_Joints.Color = Color.FromArgb(255, 0, 255); lNC_Joints.ParentLayerId = lNC.Id; file.AllLayers.Add(lNC_Joints); lNC_Joints = file.AllLayers.Last(); Layer lNC_Drill = new Layer(); lNC_Drill.Name = "NC_Drill"; lNC_Drill.Color = Color.FromArgb(255, 0, 0); lNC_Drill.ParentLayerId = lNC.Id; file.AllLayers.Add(lNC_Drill); lNC_Drill = file.AllLayers.Last(); // Add objects ObjectAttributes oa; oa = new ObjectAttributes(); oa.LayerIndex = lBL_Centreline.Index; oa.Name = "Glulam_Centreline"; file.Objects.AddCurve(g.Centreline, oa); oa.LayerIndex = lBL_Geometry.Index; oa.UserDictionary.Set("LamWidth", g.Data.LamWidth); oa.UserDictionary.Set("LamHeight", g.Data.LamHeight); oa.UserDictionary.Set("NumWidth", g.Data.NumWidth); oa.UserDictionary.Set("NumHeight", g.Data.NumHeight); oa.Name = "Glulam_BoundingMesh"; Guid blank_id = file.Objects.AddBrep(g.GetBoundingBrep(), oa); oa.LayerIndex = lBE_Geometry.Index; oa.UserDictionary.Clear(); oa.Name = "Beam_Geometry"; file.Objects.AddBrep(beam, oa); oa.LayerIndex = lBL_Safety.Index; oa.Name = "Glulam_Safety"; Brep blank_safety = g.GetBoundingBrep(50.0); if (blank_safety != null) { file.Objects.AddBrep(blank_safety, oa); } for (int i = 0; i < Cuts_Surface.Count; ++i) { oa.LayerIndex = lNC_Surface.Index; oa.Name = string.Format("Machining_Surface_{0:00}", i); file.Objects.AddBrep(Cuts_Surface[i], oa); oa.LayerIndex = lNC_Normals.Index; oa.Name = string.Format("Machining_Surface_Normal_{0:00}", i); BrepFace bf = Cuts_Surface[i].Faces[0]; Vector3d normal = bf.NormalAt(bf.Domain(0).Mid, bf.Domain(1).Mid); Point3d point = bf.PointAt(bf.Domain(0).Mid, bf.Domain(1).Mid); file.Objects.AddTextDot(string.Format("NC_Srf_{0:00}", i), point + normal * 100.0, oa); file.Objects.AddLine(new Line(point, point + normal * 100.0), oa); } for (int i = 0; i < Cuts_GlueSurface.Count; ++i) { oa.LayerIndex = lNC_Surface.Index; oa.Name = string.Format("Glue_Surface_{0:00}", i); file.Objects.AddBrep(Cuts_GlueSurface[i], oa); oa.LayerIndex = lNC_Normals.Index; oa.Name = string.Format("Glue_Surface_Normal_{0:00}", i); BrepFace bf = Cuts_GlueSurface[i].Faces[0]; Vector3d normal = bf.NormalAt(bf.Domain(0).Mid, bf.Domain(1).Mid); Point3d point = bf.PointAt(bf.Domain(0).Mid, bf.Domain(1).Mid); file.Objects.AddTextDot(string.Format("NC_Glu_{0:00}", i), point + normal * 100.0, oa); file.Objects.AddLine(new Line(point, point + normal * 100.0), oa); } for (int i = 0; i < Cuts_Joint.Count; ++i) { oa.LayerIndex = lNC_Joints.Index; oa.Name = string.Format("Joint_Surface_{0:00}", i); file.Objects.AddBrep(Cuts_Joint[i], oa); oa.LayerIndex = lNC_Normals.Index; oa.Name = string.Format("Joint_Surface_Normal_{0:00}", i); BrepFace bf = Cuts_Joint[i].Faces[0]; Vector3d normal = bf.NormalAt(bf.Domain(0).Mid, bf.Domain(1).Mid); Point3d point = bf.PointAt(bf.Domain(0).Mid, bf.Domain(1).Mid); file.Objects.AddTextDot(string.Format("NC_Jnt_{0:00}", i), point + normal * 100.0, oa); file.Objects.AddLine(new Line(point, point + normal * 100.0), oa); } for (int i = 0; i < Drills_Joint.Count; ++i) { oa.LayerIndex = lNC_Drill.Index; oa.Name = string.Format("Joint_Drill_{0:00}", i); Vector3d dir = Drills_Joint[i].Direction; dir.Unitize(); file.Objects.AddTextDot(string.Format("NC_Drill_{0:00}", i), Drills_Joint[i].From - dir * 40.0, oa); file.Objects.AddLine(Drills_Joint[i], oa); } // Write notes and data string notes = ""; notes += "This file was created with tasTools (Tom Svilans, 2017).\n\n"; notes += "Blank data:\n\n"; notes += string.Format("LamWidth\n{0}\n", g.Data.LamWidth); notes += string.Format("LamHeight\n{0}\n", g.Data.LamHeight); notes += string.Format("NumWidth\n{0}\n", g.Data.NumWidth); notes += string.Format("NumHeight\n{0}\n", g.Data.NumHeight); notes += string.Format("Length\n{0}\n", g.Centreline.GetLength()); file.Notes.Notes = notes; file.Settings.ModelUnitSystem = UnitSystem.Millimeters; file.Write(path + "\\" + Name + ".3dm", 5); }